Revert of Class for allocating a chunk of memory for RenderPass (patchset #31 id...
[chromium-blink-merge.git] / content / public / browser / notification_details.h
blob815d74804c016ba706a12840ad3a5078ce62d0d3
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
6 // notifications.
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"
14 namespace content {
16 // Do not declare a NotificationDetails directly--use either
17 // "Details<detailsclassname>(detailsclasspointer)" or
18 // NotificationService::NoDetails().
19 class CONTENT_EXPORT NotificationDetails {
20 public:
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
27 // map index.
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_;
38 protected:
39 explicit NotificationDetails(const void* ptr) : ptr_(ptr) {}
41 // Declaring this const allows Details<T> to be used with both T = Foo and
42 // T = const Foo.
43 const void* ptr_;
46 template <class T>
47 class Details : public NotificationDetails {
48 public:
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_