OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef SYNC_NOTIFIER_SYNC_NOTIFIER_REGISTRAR_H_ | 5 #ifndef SYNC_NOTIFIER_SYNC_NOTIFIER_REGISTRAR_H_ |
6 #define SYNC_NOTIFIER_SYNC_NOTIFIER_REGISTRAR_H_ | 6 #define SYNC_NOTIFIER_SYNC_NOTIFIER_REGISTRAR_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/observer_list.h" | 11 #include "base/observer_list.h" |
12 #include "base/threading/thread_checker.h" | 12 #include "base/threading/thread_checker.h" |
13 #include "sync/notifier/invalidation_util.h" | 13 #include "sync/notifier/invalidation_util.h" |
14 #include "sync/notifier/object_id_payload_map.h" | 14 #include "sync/notifier/object_id_state_map.h" |
15 #include "sync/notifier/sync_notifier_observer.h" | 15 #include "sync/notifier/sync_notifier_observer.h" |
16 | 16 |
17 namespace invalidation { | 17 namespace invalidation { |
18 class ObjectId; | 18 class ObjectId; |
19 } // namespace invalidation | 19 } // namespace invalidation |
20 | 20 |
21 namespace syncer { | 21 namespace syncer { |
22 | 22 |
23 // A helper class for implementations of the SyncNotifier interface. It helps | 23 // A helper class for implementations of the SyncNotifier interface. It helps |
24 // keep track of registered handlers and which object ID registrations are | 24 // keep track of registered handlers and which object ID registrations are |
(...skipping 21 matching lines...) Expand all Loading... |
46 void UnregisterHandler(SyncNotifierObserver* handler); | 46 void UnregisterHandler(SyncNotifierObserver* handler); |
47 | 47 |
48 // Returns the set of all IDs that are registered to some handler (even | 48 // Returns the set of all IDs that are registered to some handler (even |
49 // handlers that have been unregistered). | 49 // handlers that have been unregistered). |
50 ObjectIdSet GetAllRegisteredIds() const; | 50 ObjectIdSet GetAllRegisteredIds() const; |
51 | 51 |
52 // Sorts incoming invalidations into a bucket for each handler and then | 52 // Sorts incoming invalidations into a bucket for each handler and then |
53 // dispatches the batched invalidations to the corresponding handler. | 53 // dispatches the batched invalidations to the corresponding handler. |
54 // Invalidations for IDs with no corresponding handler are dropped, as are | 54 // Invalidations for IDs with no corresponding handler are dropped, as are |
55 // invalidations for handlers that are not added. | 55 // invalidations for handlers that are not added. |
56 void DispatchInvalidationsToHandlers(const ObjectIdPayloadMap& id_payloads, | 56 void DispatchInvalidationsToHandlers(const ObjectIdStateMap& id_state_map, |
57 IncomingNotificationSource source); | 57 IncomingNotificationSource source); |
58 | 58 |
59 // Calls the given handler method for each handler that has registered IDs. | 59 // Calls the given handler method for each handler that has registered IDs. |
60 void EmitOnNotificationsEnabled(); | 60 void EmitOnNotificationsEnabled(); |
61 void EmitOnNotificationsDisabled(NotificationsDisabledReason reason); | 61 void EmitOnNotificationsDisabled(NotificationsDisabledReason reason); |
62 | 62 |
63 // Needed for death tests. | 63 // Needed for death tests. |
64 void DetachFromThreadForTest(); | 64 void DetachFromThreadForTest(); |
65 | 65 |
66 private: | 66 private: |
67 typedef std::map<invalidation::ObjectId, SyncNotifierObserver*, | 67 typedef std::map<invalidation::ObjectId, SyncNotifierObserver*, |
68 ObjectIdLessThan> | 68 ObjectIdLessThan> |
69 IdHandlerMap; | 69 IdHandlerMap; |
70 | 70 |
71 SyncNotifierObserver* ObjectIdToHandler(const invalidation::ObjectId& id); | 71 SyncNotifierObserver* ObjectIdToHandler(const invalidation::ObjectId& id); |
72 | 72 |
73 base::ThreadChecker thread_checker_; | 73 base::ThreadChecker thread_checker_; |
74 ObserverList<SyncNotifierObserver> handlers_; | 74 ObserverList<SyncNotifierObserver> handlers_; |
75 IdHandlerMap id_to_handler_map_; | 75 IdHandlerMap id_to_handler_map_; |
76 | 76 |
77 DISALLOW_COPY_AND_ASSIGN(SyncNotifierRegistrar); | 77 DISALLOW_COPY_AND_ASSIGN(SyncNotifierRegistrar); |
78 }; | 78 }; |
79 | 79 |
80 } // namespace syncer | 80 } // namespace syncer |
81 | 81 |
82 #endif // SYNC_NOTIFIER_SYNC_NOTIFIER_REGISTRAR_H_ | 82 #endif // SYNC_NOTIFIER_SYNC_NOTIFIER_REGISTRAR_H_ |
OLD | NEW |