1
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style license that can be
3
// found in the LICENSE file.
5
// This file defines the type used to provide sources for NotificationService
8
#ifndef CONTENT_COMMON_NOTIFICATION_SOURCE_H_
9
#define CONTENT_COMMON_NOTIFICATION_SOURCE_H_
14
// Do not declare a NotificationSource directly--use either
15
// "Source<sourceclassname>(sourceclasspointer)" or
16
// NotificationService::AllSources().
17
class NotificationSource {
19
NotificationSource(const NotificationSource& other);
20
~NotificationSource();
22
// NotificationSource can be used as the index for a map; this method
23
// returns the pointer to the current source as an identifier, for use as a
25
uintptr_t map_key() const { return reinterpret_cast<uintptr_t>(ptr_); }
27
bool operator!=(const NotificationSource& other) const {
28
return ptr_ != other.ptr_;
30
bool operator==(const NotificationSource& other) const {
31
return ptr_ == other.ptr_;
35
explicit NotificationSource(const void* ptr);
37
// Declaring this const allows Source<T> to be used with both T = Foo and
43
class Source : public NotificationSource {
45
// TODO(erg): Our code hard relies on implicit conversion
46
Source(const T* ptr) : NotificationSource(ptr) {} // NOLINT
47
Source(const NotificationSource& other) // NOLINT
48
: NotificationSource(other) {}
50
T* operator->() const { return ptr(); }
51
// The casts here allow this to compile with both T = Foo and T = const Foo.
52
T* ptr() const { return static_cast<T*>(const_cast<void*>(ptr_)); }
55
#endif // CONTENT_COMMON_NOTIFICATION_SOURCE_H_