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

Side by Side Diff: content/common/notification_service.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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // This file describes a central switchboard for notifications that might 5 // This file describes a central switchboard for notifications that might
6 // happen in various parts of the application, and allows users to register 6 // happen in various parts of the application, and allows users to register
7 // observers for various classes of events that they're interested in. 7 // observers for various classes of events that they're interested in.
8 8
9 #ifndef CONTENT_COMMON_NOTIFICATION_SERVICE_H_ 9 #ifndef CONTENT_COMMON_NOTIFICATION_SERVICE_H_
10 #define CONTENT_COMMON_NOTIFICATION_SERVICE_H_ 10 #define CONTENT_COMMON_NOTIFICATION_SERVICE_H_
11 #pragma once 11 #pragma once
12 12
13 #include <map> 13 #include <map>
14 #include <vector>
darin (slow to review) 2011/07/07 22:54:56 nit: looks like this include is not needed.
14 15
15 #include "base/observer_list.h" 16 #include "base/observer_list.h"
16 #include "content/common/notification_details.h" 17 #include "content/common/notification_details.h"
17 #include "content/common/notification_source.h" 18 #include "content/common/notification_source.h"
18 #include "content/common/notification_type.h" 19 #include "content/common/notification_type.h"
19 20
20 class NotificationObserver; 21 class NotificationObserver;
21 22
22 class NotificationService { 23 class NotificationService {
23 public: 24 public:
(...skipping 24 matching lines...) Expand all
48 49
49 // Returns a NotificationDetails object that represents a lack of details 50 // Returns a NotificationDetails object that represents a lack of details
50 // associated with a notification. (This is effectively a null pointer.) 51 // associated with a notification. (This is effectively a null pointer.)
51 static Details<void> NoDetails() { return Details<void>(NULL); } 52 static Details<void> NoDetails() { return Details<void>(NULL); }
52 53
53 private: 54 private:
54 friend class NotificationRegistrar; 55 friend class NotificationRegistrar;
55 56
56 typedef ObserverList<NotificationObserver> NotificationObserverList; 57 typedef ObserverList<NotificationObserver> NotificationObserverList;
57 typedef std::map<uintptr_t, NotificationObserverList*> NotificationSourceMap; 58 typedef std::map<uintptr_t, NotificationObserverList*> NotificationSourceMap;
59 typedef std::map<int, NotificationSourceMap> NotificationObserverMap;
60 typedef std::map<int, int> NotificationObserverCount;
58 61
59 // Convenience function to determine whether a source has a 62 // Convenience function to determine whether a source has a
60 // NotificationObserverList in the given map; 63 // NotificationObserverList in the given map;
61 static bool HasKey(const NotificationSourceMap& map, 64 static bool HasKey(const NotificationSourceMap& map,
62 const NotificationSource& source); 65 const NotificationSource& source);
63 66
64 // NOTE: Rather than using this directly, you should use a 67 // NOTE: Rather than using this directly, you should use a
65 // NotificationRegistrar. 68 // NotificationRegistrar.
66 // 69 //
67 // Registers a NotificationObserver to be called whenever a matching 70 // Registers a NotificationObserver to be called whenever a matching
(...skipping 19 matching lines...) Expand all
87 // 90 //
88 // Removes the object pointed to by observer from receiving notifications 91 // Removes the object pointed to by observer from receiving notifications
89 // that match type and source. If no object matching the parameters is 92 // that match type and source. If no object matching the parameters is
90 // currently registered, this method is a no-op. 93 // currently registered, this method is a no-op.
91 void RemoveObserver(NotificationObserver* observer, 94 void RemoveObserver(NotificationObserver* observer,
92 NotificationType type, const NotificationSource& source); 95 NotificationType type, const NotificationSource& source);
93 96
94 // Keeps track of the observers for each type of notification. 97 // Keeps track of the observers for each type of notification.
95 // Until we get a prohibitively large number of notification types, 98 // Until we get a prohibitively large number of notification types,
96 // a simple array is probably the fastest way to dispatch. 99 // a simple array is probably the fastest way to dispatch.
97 NotificationSourceMap observers_[NotificationType::NOTIFICATION_TYPE_COUNT]; 100 NotificationObserverMap observers_;
98 101
99 #ifndef NDEBUG 102 #ifndef NDEBUG
100 // Used to check to see that AddObserver and RemoveObserver calls are 103 // Used to check to see that AddObserver and RemoveObserver calls are
101 // balanced. 104 // balanced.
102 int observer_counts_[NotificationType::NOTIFICATION_TYPE_COUNT]; 105 NotificationObserverCount observer_counts_;
103 #endif 106 #endif
104 107
105 DISALLOW_COPY_AND_ASSIGN(NotificationService); 108 DISALLOW_COPY_AND_ASSIGN(NotificationService);
106 }; 109 };
107 110
108 #endif // CONTENT_COMMON_NOTIFICATION_SERVICE_H_ 111 #endif // CONTENT_COMMON_NOTIFICATION_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698