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 ~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 | |
47 ObserverList<SyncNotifierObserver> handlers_; | |
48 ObjectIdHandlerMap id_to_handler_map_; | |
49 | |
50 DISALLOW_COPY_AND_ASSIGN(SyncNotifierHelper); | |
51 }; | |
52 | |
53 } // namespace syncer | |
54 | |
55 #endif // SYNC_NOTIFIER_SYNC_NOTIFIER_HELPER_H_ | |
OLD | NEW |