Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: content/common/notification_registrar.h

Issue 7327007: Moving notification types which are chrome specific to a new header file chrome_notification_type... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/common/notification_observer_mock.h ('k') | content/common/notification_registrar.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_COMMON_NOTIFICATION_REGISTRAR_H_ 5 #ifndef CONTENT_COMMON_NOTIFICATION_REGISTRAR_H_
6 #define CONTENT_COMMON_NOTIFICATION_REGISTRAR_H_ 6 #define CONTENT_COMMON_NOTIFICATION_REGISTRAR_H_
7 #pragma once 7 #pragma once
8 8
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "content/common/notification_type.h" 12 #include "content/common/content_notification_types.h"
13 13
14 class NotificationObserver; 14 class NotificationObserver;
15 class NotificationSource; 15 class NotificationSource;
16 16
17 // Aids in registering for notifications and ensures that all registered 17 // Aids in registering for notifications and ensures that all registered
18 // notifications are unregistered when the class is destroyed. 18 // notifications are unregistered when the class is destroyed.
19 // 19 //
20 // The intended use is that you make a NotificationRegistrar member in your 20 // The intended use is that you make a NotificationRegistrar member in your
21 // class and use it to register your notifications instead of going through the 21 // class and use it to register your notifications instead of going through the
22 // notification service directly. It will automatically unregister them for 22 // notification service directly. It will automatically unregister them for
23 // you. 23 // you.
24 class NotificationRegistrar { 24 class NotificationRegistrar {
25 public: 25 public:
26 // This class must not be derived from (we don't have a virtual destructor so 26 // This class must not be derived from (we don't have a virtual destructor so
27 // it won't work). Instead, use it as a member in your class. 27 // it won't work). Instead, use it as a member in your class.
28 NotificationRegistrar(); 28 NotificationRegistrar();
29 ~NotificationRegistrar(); 29 ~NotificationRegistrar();
30 30
31 // Wrappers around NotificationService::[Add|Remove]Observer. 31 // Wrappers around NotificationService::[Add|Remove]Observer.
32 void Add(NotificationObserver* observer, 32 void Add(NotificationObserver* observer,
33 NotificationType type, 33 int type,
34 const NotificationSource& source); 34 const NotificationSource& source);
35 void Remove(NotificationObserver* observer, 35 void Remove(NotificationObserver* observer,
36 NotificationType type, 36 int type,
37 const NotificationSource& source); 37 const NotificationSource& source);
38 38
39 // Unregisters all notifications. 39 // Unregisters all notifications.
40 void RemoveAll(); 40 void RemoveAll();
41 41
42 // Returns true if no notifications are registered. 42 // Returns true if no notifications are registered.
43 bool IsEmpty() const; 43 bool IsEmpty() const;
44 44
45 // Returns true if there is already a registered notification with the 45 // Returns true if there is already a registered notification with the
46 // specified details. 46 // specified details.
47 bool IsRegistered(NotificationObserver* observer, 47 bool IsRegistered(NotificationObserver* observer,
48 NotificationType type, 48 int type,
49 const NotificationSource& source); 49 const NotificationSource& source);
50 50
51 private: 51 private:
52 struct Record; 52 struct Record;
53 53
54 // We keep registered notifications in a simple vector. This means we'll do 54 // We keep registered notifications in a simple vector. This means we'll do
55 // brute-force searches when removing them individually, but individual 55 // brute-force searches when removing them individually, but individual
56 // removal is uncommon, and there will typically only be a couple of 56 // removal is uncommon, and there will typically only be a couple of
57 // notifications anyway. 57 // notifications anyway.
58 typedef std::vector<Record> RecordVector; 58 typedef std::vector<Record> RecordVector;
59 59
60 // Lists all notifications we're currently registered for. 60 // Lists all notifications we're currently registered for.
61 RecordVector registered_; 61 RecordVector registered_;
62 62
63 DISALLOW_COPY_AND_ASSIGN(NotificationRegistrar); 63 DISALLOW_COPY_AND_ASSIGN(NotificationRegistrar);
64 }; 64 };
65 65
66 #endif // CONTENT_COMMON_NOTIFICATION_REGISTRAR_H_ 66 #endif // CONTENT_COMMON_NOTIFICATION_REGISTRAR_H_
OLDNEW
« no previous file with comments | « content/common/notification_observer_mock.h ('k') | content/common/notification_registrar.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698