ipc/chromium/src/chrome/common/notification_source.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
michael@0 2 // Use of this source code is governed by a BSD-style license that can be
michael@0 3 // found in the LICENSE file.
michael@0 4
michael@0 5 // This file defines the type used to provide sources for NotificationService
michael@0 6 // notifications.
michael@0 7
michael@0 8 #ifndef CHROME_COMMON_NOTIFICATION_SOURCE_H__
michael@0 9 #define CHROME_COMMON_NOTIFICATION_SOURCE_H__
michael@0 10
michael@0 11 #include "base/basictypes.h"
michael@0 12
michael@0 13 // Do not declare a NotificationSource directly--use either
michael@0 14 // "Source<sourceclassname>(sourceclasspointer)" or
michael@0 15 // NotificationService::AllSources().
michael@0 16 class NotificationSource {
michael@0 17 public:
michael@0 18 NotificationSource(const NotificationSource& other) : ptr_(other.ptr_) { }
michael@0 19 ~NotificationSource() {}
michael@0 20
michael@0 21 // NotificationSource can be used as the index for a map; this method
michael@0 22 // returns the pointer to the current source as an identifier, for use as a
michael@0 23 // map index.
michael@0 24 uintptr_t map_key() const { return reinterpret_cast<uintptr_t>(ptr_); }
michael@0 25
michael@0 26 bool operator!=(const NotificationSource& other) const {
michael@0 27 return ptr_ != other.ptr_;
michael@0 28 }
michael@0 29 bool operator==(const NotificationSource& other) const {
michael@0 30 return ptr_ == other.ptr_;
michael@0 31 }
michael@0 32
michael@0 33 protected:
michael@0 34 NotificationSource(void* ptr) : ptr_(ptr) {}
michael@0 35
michael@0 36 void* ptr_;
michael@0 37 };
michael@0 38
michael@0 39 template <class T>
michael@0 40 class Source : public NotificationSource {
michael@0 41 public:
michael@0 42 Source(T* ptr) : NotificationSource(ptr) {}
michael@0 43
michael@0 44 Source(const NotificationSource& other)
michael@0 45 : NotificationSource(other) {}
michael@0 46
michael@0 47 T* operator->() const { return ptr(); }
michael@0 48 T* ptr() const { return static_cast<T*>(ptr_); }
michael@0 49 };
michael@0 50
michael@0 51 #endif // CHROME_COMMON_NOTIFICATION_SOURCE_H__

mercurial