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" | |
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 | |
26 // Updates the set of ObjectIds associated with a given |handler|. Passing an | |
27 // empty ObjectIdSet will unregister |handler|. The return value is an | |
28 // ObjectIdSet containing values for all existing handlers. | |
29 ObjectIdSet UpdateRegisteredIds(SyncNotifierObserver* handler, | |
30 const ObjectIdSet& ids); | |
31 | |
32 // Helper that sorts incoming invalidations into a bucket for each handler | |
33 // and then dispatches the batched invalidations to the corresponding handler. | |
34 void DispatchInvalidationsToHandlers(const ObjectIdPayloadMap& id_payloads, | |
35 IncomingNotificationSource source); | |
36 | |
37 void OnNotificationsEnabled(); | |
akalin
2012/07/20 19:01:40
rename to EmitOn...
akalin
2012/07/20 19:01:40
Add comment like:
// Calls the given handler meth
dcheng
2012/07/21 00:09:54
Done.
dcheng
2012/07/21 00:09:54
Done.
| |
38 void OnNotificationsDisabled(NotificationsDisabledReason reason); | |
akalin
2012/07/20 19:01:40
rename to EmitOn...
dcheng
2012/07/21 00:09:54
Done.
| |
39 | |
40 private: | |
41 typedef std::map<invalidation::ObjectId, | |
42 SyncNotifierObserver*, | |
43 ObjectIdLessThan> ObjectIdObserverMap; | |
44 ObserverList<SyncNotifierObserver> handlers_; | |
45 ObjectIdObserverMap id_to_handler_map_; | |
46 | |
47 DISALLOW_COPY_AND_ASSIGN(SyncNotifierHelper); | |
48 }; | |
49 | |
50 } // namespace syncer | |
51 | |
52 #endif // SYNC_NOTIFIER_SYNC_NOTIFIER_HELPER_H_ | |
OLD | NEW |