ipc/chromium/src/chrome/common/notification_registrar.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.

     1 // Copyright (c) 2006-2008 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 #ifndef CHROME_COMMON_NOTIFICATION_REGISTRAR_H_
     6 #define CHROME_COMMON_NOTIFICATION_REGISTRAR_H_
     8 #include <vector>
    10 #include "base/basictypes.h"
    11 #include "chrome/common/notification_observer.h"
    13 // Aids in registering for notifications and ensures that all registered
    14 // notifications are unregistered when the class is destroyed.
    15 //
    16 // The intended use is that you make a NotificationRegistrar member in your
    17 // class and use it to register your notifications instead of going through the
    18 // notification service directly. It will automatically unregister them for
    19 // you.
    20 class NotificationRegistrar {
    21  public:
    22   // This class must not be derived from (we don't have a virtual destructor so
    23   // it won't work). Instead, use it as a member in your class.
    24   NotificationRegistrar();
    25   ~NotificationRegistrar();
    27   // Wrappers around NotificationService::[Add|Remove]Observer.
    28   void Add(NotificationObserver* observer,
    29            NotificationType type,
    30            const NotificationSource& source);
    31   void Remove(NotificationObserver* observer,
    32               NotificationType type,
    33               const NotificationSource& source);
    35   // Unregisters all notifications.
    36   void RemoveAll();
    38  private:
    39   struct Record;
    41   // We keep registered notifications in a simple vector. This means we'll do
    42   // brute-force searches when removing them individually, but individual
    43   // removal is uncommon, and there will typically only be a couple of
    44   // notifications anyway.
    45   typedef std::vector<Record> RecordVector;
    47   // Lists all notifications we're currently registered for.
    48   RecordVector registered_;
    50   DISALLOW_COPY_AND_ASSIGN(NotificationRegistrar);
    51 };
    53 #endif  // CHROME_COMMON_NOTIFICATION_REGISTRAR_H_

mercurial