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 | |
akalin
2012/07/21 00:16:29
clang is complaining saying that you need an expli
dcheng
2012/07/21 00:20:15
Done.
| |
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 // Calls the given handler method for each handler that has registered IDs. | |
38 void EmitOnNotificationsEnabled(); | |
39 void EmitOnNotificationsDisabled(NotificationsDisabledReason reason); | |
40 | |
41 private: | |
42 typedef std::map<invalidation::ObjectId, | |
43 SyncNotifierObserver*, | |
44 ObjectIdLessThan> ObjectIdHandlerMap; | |
45 ObserverList<SyncNotifierObserver> handlers_; | |
46 ObjectIdHandlerMap id_to_handler_map_; | |
47 | |
48 DISALLOW_COPY_AND_ASSIGN(SyncNotifierHelper); | |
49 }; | |
50 | |
51 } // namespace syncer | |
52 | |
53 #endif // SYNC_NOTIFIER_SYNC_NOTIFIER_HELPER_H_ | |
OLD | NEW |