1 // Copyright (c) 2012 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_PUBLIC_BROWSER_NOTIFICATION_SOURCE_H_
9 #define CONTENT_PUBLIC_BROWSER_NOTIFICATION_SOURCE_H_
11 #include "base/basictypes.h"
12 #include "content/common/content_export.h"
16 // Do not declare a NotificationSource directly--use either
17 // "Source<sourceclassname>(sourceclasspointer)" or
18 // NotificationService::AllSources().
19 class CONTENT_EXPORT NotificationSource
{
21 NotificationSource(const NotificationSource
& other
) : ptr_(other
.ptr_
) {}
22 ~NotificationSource() {}
24 // NotificationSource can be used as the index for a map; this method
25 // returns the pointer to the current source as an identifier, for use as a
27 uintptr_t map_key() const { return reinterpret_cast<uintptr_t>(ptr_
); }
29 bool operator!=(const NotificationSource
& other
) const {
30 return ptr_
!= other
.ptr_
;
32 bool operator==(const NotificationSource
& other
) const {
33 return ptr_
== other
.ptr_
;
37 explicit NotificationSource(const void* ptr
) : ptr_(ptr
) {}
39 // Declaring this const allows Source<T> to be used with both T = Foo and
45 class Source
: public NotificationSource
{
47 // TODO(erg): Our code hard relies on implicit conversion
48 Source(const T
* ptr
) : NotificationSource(ptr
) {} // NOLINT
49 Source(const NotificationSource
& other
) // NOLINT
50 : NotificationSource(other
) {}
52 T
* operator->() const { return ptr(); }
53 // The casts here allow this to compile with both T = Foo and T = const Foo.
54 T
* ptr() const { return static_cast<T
*>(const_cast<void*>(ptr_
)); }
57 } // namespace content
59 #endif // CONTENT_PUBLIC_BROWSER_NOTIFICATION_SOURCE_H_