1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/ipc/chromium/src/chrome/common/notification_source.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,51 @@ 1.4 +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1.5 +// Use of this source code is governed by a BSD-style license that can be 1.6 +// found in the LICENSE file. 1.7 + 1.8 +// This file defines the type used to provide sources for NotificationService 1.9 +// notifications. 1.10 + 1.11 +#ifndef CHROME_COMMON_NOTIFICATION_SOURCE_H__ 1.12 +#define CHROME_COMMON_NOTIFICATION_SOURCE_H__ 1.13 + 1.14 +#include "base/basictypes.h" 1.15 + 1.16 +// Do not declare a NotificationSource directly--use either 1.17 +// "Source<sourceclassname>(sourceclasspointer)" or 1.18 +// NotificationService::AllSources(). 1.19 +class NotificationSource { 1.20 + public: 1.21 + NotificationSource(const NotificationSource& other) : ptr_(other.ptr_) { } 1.22 + ~NotificationSource() {} 1.23 + 1.24 + // NotificationSource can be used as the index for a map; this method 1.25 + // returns the pointer to the current source as an identifier, for use as a 1.26 + // map index. 1.27 + uintptr_t map_key() const { return reinterpret_cast<uintptr_t>(ptr_); } 1.28 + 1.29 + bool operator!=(const NotificationSource& other) const { 1.30 + return ptr_ != other.ptr_; 1.31 + } 1.32 + bool operator==(const NotificationSource& other) const { 1.33 + return ptr_ == other.ptr_; 1.34 + } 1.35 + 1.36 + protected: 1.37 + NotificationSource(void* ptr) : ptr_(ptr) {} 1.38 + 1.39 + void* ptr_; 1.40 +}; 1.41 + 1.42 +template <class T> 1.43 +class Source : public NotificationSource { 1.44 + public: 1.45 + Source(T* ptr) : NotificationSource(ptr) {} 1.46 + 1.47 + Source(const NotificationSource& other) 1.48 + : NotificationSource(other) {} 1.49 + 1.50 + T* operator->() const { return ptr(); } 1.51 + T* ptr() const { return static_cast<T*>(ptr_); } 1.52 +}; 1.53 + 1.54 +#endif // CHROME_COMMON_NOTIFICATION_SOURCE_H__