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 details for NotificationService
8 #ifndef CONTENT_PUBLIC_BROWSER_NOTIFICATION_DETAILS_H_
9 #define CONTENT_PUBLIC_BROWSER_NOTIFICATION_DETAILS_H_
11 #include "base/basictypes.h"
12 #include "content/common/content_export.h"
16 // Do not declare a NotificationDetails directly--use either
17 // "Details<detailsclassname>(detailsclasspointer)" or
18 // NotificationService::NoDetails().
19 class CONTENT_EXPORT NotificationDetails
{
21 NotificationDetails() : ptr_(NULL
) {}
22 NotificationDetails(const NotificationDetails
& other
) : ptr_(other
.ptr_
) {}
23 ~NotificationDetails() {}
25 // NotificationDetails can be used as the index for a map; this method
26 // returns the pointer to the current details as an identifier, for use as a
28 uintptr_t map_key() const { return reinterpret_cast<uintptr_t>(ptr_
); }
30 bool operator!=(const NotificationDetails
& other
) const {
31 return ptr_
!= other
.ptr_
;
34 bool operator==(const NotificationDetails
& other
) const {
35 return ptr_
== other
.ptr_
;
39 explicit NotificationDetails(const void* ptr
) : ptr_(ptr
) {}
41 // Declaring this const allows Details<T> to be used with both T = Foo and
47 class Details
: public NotificationDetails
{
49 // TODO(erg): Our code hard relies on implicit conversion
50 Details(T
* ptr
) : NotificationDetails(ptr
) {} // NOLINT
51 Details(const NotificationDetails
& other
) // NOLINT
52 : NotificationDetails(other
) {}
54 T
* operator->() const { return ptr(); }
55 // The casts here allow this to compile with both T = Foo and T = const Foo.
56 T
* ptr() const { return static_cast<T
*>(const_cast<void*>(ptr_
)); }
59 } // namespace content
61 #endif // CONTENT_PUBLIC_BROWSER_NOTIFICATION_DETAILS_H_