OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 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. | |
4 | |
5 #ifndef SYNC_NOTIFIER_SYNC_NOTIFIER_HELPER_H_ | |
6 #define SYNC_NOTIFIER_SYNC_NOTIFIER_HELPER_H_ | |
7 | |
8 #include <map> | |
9 | |
10 #include "base/basictypes.h" | |
11 #include "base/observer_list.h" | |
12 #include "sync/notifier/invalidation_util.h" | |
13 #include "sync/notifier/object_id_payload_map.h" | |
14 #include "sync/notifier/sync_notifier_observer.h" | |
akalin
2012/07/21 01:09:47
can you forward-declare SyncNotifierObserver?
dcheng
2012/07/21 14:06:53
The header is needed for IncomingNotificationSourc
| |
15 | |
16 namespace syncer { | |
17 | |
18 // A helper class for classes that want to implement the SyncNotifier interface. | |
19 // It helps keep track of registered handlers and which object ID registrations | |
20 // are associated with which handlers, so implementors can just reuse the logic | |
21 // here to dispatch invalidations and other interesting notifications. | |
22 class SyncNotifierHelper { | |
23 public: | |
24 SyncNotifierHelper(); | |
25 ~SyncNotifierHelper(); | |
26 | |
27 // Updates the set of ObjectIds associated with a given |handler|. Passing an | |
28 // empty ObjectIdSet will unregister |handler|. The return value is an | |
29 // ObjectIdSet containing values for all existing handlers. | |
30 ObjectIdSet UpdateRegisteredIds(SyncNotifierObserver* handler, | |
31 const ObjectIdSet& ids); | |
32 | |
33 // Helper that sorts incoming invalidations into a bucket for each handler | |
34 // and then dispatches the batched invalidations to the corresponding handler. | |
35 void DispatchInvalidationsToHandlers(const ObjectIdPayloadMap& id_payloads, | |
36 IncomingNotificationSource source); | |
37 | |
38 // Calls the given handler method for each handler that has registered IDs. | |
39 void EmitOnNotificationsEnabled(); | |
40 void EmitOnNotificationsDisabled(NotificationsDisabledReason reason); | |
41 | |
42 private: | |
43 typedef std::map<invalidation::ObjectId, | |
44 SyncNotifierObserver*, | |
45 ObjectIdLessThan> ObjectIdHandlerMap; | |
46 ObserverList<SyncNotifierObserver> handlers_; | |
akalin
2012/07/21 01:09:47
newline after typedef
dcheng
2012/07/21 14:06:53
Done.
| |
47 ObjectIdHandlerMap id_to_handler_map_; | |
48 | |
49 DISALLOW_COPY_AND_ASSIGN(SyncNotifierHelper); | |
50 }; | |
51 | |
52 } // namespace syncer | |
53 | |
54 #endif // SYNC_NOTIFIER_SYNC_NOTIFIER_HELPER_H_ | |
OLD | NEW |