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_REGISTRAR_H_ | |
6 #define SYNC_NOTIFIER_SYNC_NOTIFIER_REGISTRAR_H_ | |
7 | |
8 #include <map> | |
9 | |
10 #include "base/basictypes.h" | |
11 #include "base/observer_list.h" | |
12 #include "base/threading/thread_checker.h" | |
13 #include "sync/notifier/invalidation_util.h" | |
14 #include "sync/notifier/object_id_payload_map.h" | |
15 #include "sync/notifier/sync_notifier_observer.h" | |
16 | |
17 namespace invalidation { | |
18 class ObjectId; | |
19 } // namespace invalidation | |
20 | |
21 namespace syncer { | |
22 | |
23 // A helper class for implementations of the SyncNotifier interface. It helps | |
24 // keep track of registered handlers and which object ID registrations are | |
25 // associated with which handlers, so implementors can just reuse the logic | |
26 // here to dispatch invalidations and other interesting notifications. | |
27 class SyncNotifierRegistrar { | |
28 public: | |
29 SyncNotifierRegistrar(); | |
30 ~SyncNotifierRegistrar(); | |
31 | |
32 // Starts sending notifications to |handler|. |handler| must not be NULL, | |
33 // and it must not already have been added. | |
34 void RegisterHandler(SyncNotifierObserver* handler); | |
35 | |
36 // Updates the set of ObjectIds associated with |handler|. |handler| must | |
37 // not be NULL, and must have already been added. An ID must be registered | |
msw
2012/08/09 05:20:26
nit: s/added/registered/
akalin
2012/08/10 01:28:08
Done.
| |
38 // for at most one handler. | |
39 void UpdateRegisteredIds(SyncNotifierObserver* handler, | |
40 const ObjectIdSet& ids); | |
41 | |
42 // Stops sending notifications to |handler|. |handler| must not be NULL, and | |
43 // it must have been previously added. Note that this doesn't unregister the | |
44 // IDs associated with |handler|. | |
45 void UnregisterHandler(SyncNotifierObserver* handler); | |
46 | |
47 // Returns the set of all IDs that are registered to some handler (even | |
48 // unregistered ones). | |
msw
2012/08/09 05:20:26
nit: s/ones/handlers/
akalin
2012/08/10 01:28:08
Done.
| |
49 ObjectIdSet GetAllRegisteredIds() const; | |
50 | |
51 // Sorts incoming invalidations into a bucket for each handler and then | |
52 // dispatches the batched invalidations to the corresponding handler. | |
53 // Invalidations for IDs with no corresponding handler are dropped, as are | |
54 // invalidations for handlers that are not added. | |
55 void DispatchInvalidationsToHandlers(const ObjectIdPayloadMap& id_payloads, | |
56 IncomingNotificationSource source); | |
57 | |
58 // Calls the given handler method for each handler that has registered IDs. | |
59 void EmitOnNotificationsEnabled(); | |
60 void EmitOnNotificationsDisabled(NotificationsDisabledReason reason); | |
61 | |
62 // Needed for death tests. | |
63 void DetachFromThreadForTest(); | |
64 | |
65 private: | |
66 typedef std::map<invalidation::ObjectId, SyncNotifierObserver*, | |
67 ObjectIdLessThan> | |
68 IdHandlerMap; | |
69 | |
70 SyncNotifierObserver* ObjectIdToHandler(const invalidation::ObjectId& id); | |
71 | |
72 base::ThreadChecker thread_checker_; | |
73 ObserverList<SyncNotifierObserver> handlers_; | |
74 IdHandlerMap id_to_handler_map_; | |
75 | |
76 DISALLOW_COPY_AND_ASSIGN(SyncNotifierRegistrar); | |
77 }; | |
78 | |
79 } // namespace syncer | |
80 | |
81 #endif // SYNC_NOTIFIER_SYNC_NOTIFIER_REGISTRAR_H_ | |
OLD | NEW |