michael@0: // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: michael@0: // This file defines the type used to provide sources for NotificationService michael@0: // notifications. michael@0: michael@0: #ifndef CHROME_COMMON_NOTIFICATION_SOURCE_H__ michael@0: #define CHROME_COMMON_NOTIFICATION_SOURCE_H__ michael@0: michael@0: #include "base/basictypes.h" michael@0: michael@0: // Do not declare a NotificationSource directly--use either michael@0: // "Source(sourceclasspointer)" or michael@0: // NotificationService::AllSources(). michael@0: class NotificationSource { michael@0: public: michael@0: NotificationSource(const NotificationSource& other) : ptr_(other.ptr_) { } michael@0: ~NotificationSource() {} michael@0: michael@0: // NotificationSource can be used as the index for a map; this method michael@0: // returns the pointer to the current source as an identifier, for use as a michael@0: // map index. michael@0: uintptr_t map_key() const { return reinterpret_cast(ptr_); } michael@0: michael@0: bool operator!=(const NotificationSource& other) const { michael@0: return ptr_ != other.ptr_; michael@0: } michael@0: bool operator==(const NotificationSource& other) const { michael@0: return ptr_ == other.ptr_; michael@0: } michael@0: michael@0: protected: michael@0: NotificationSource(void* ptr) : ptr_(ptr) {} michael@0: michael@0: void* ptr_; michael@0: }; michael@0: michael@0: template michael@0: class Source : public NotificationSource { michael@0: public: michael@0: Source(T* ptr) : NotificationSource(ptr) {} michael@0: michael@0: Source(const NotificationSource& other) michael@0: : NotificationSource(other) {} michael@0: michael@0: T* operator->() const { return ptr(); } michael@0: T* ptr() const { return static_cast(ptr_); } michael@0: }; michael@0: michael@0: #endif // CHROME_COMMON_NOTIFICATION_SOURCE_H__