| 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_INVALIDATOR_REGISTRAR_H_ |
| 6 #define SYNC_NOTIFIER_SYNC_NOTIFIER_REGISTRAR_H_ | 6 #define SYNC_NOTIFIER_INVALIDATOR_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_handler.h" |
| 13 #include "sync/notifier/invalidation_util.h" | 14 #include "sync/notifier/invalidation_util.h" |
| 14 #include "sync/notifier/object_id_state_map.h" | 15 #include "sync/notifier/object_id_state_map.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 Invalidator 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 |
| 25 // associated with which handlers, so implementors can just reuse the logic | 25 // associated with which handlers, so implementors can just reuse the logic |
| 26 // here to dispatch invalidations and other interesting notifications. | 26 // here to dispatch invalidations and other interesting notifications. |
| 27 class SyncNotifierRegistrar { | 27 class InvalidatorRegistrar { |
| 28 public: | 28 public: |
| 29 SyncNotifierRegistrar(); | 29 InvalidatorRegistrar(); |
| 30 ~SyncNotifierRegistrar(); | 30 ~InvalidatorRegistrar(); |
| 31 | 31 |
| 32 // Starts sending notifications to |handler|. |handler| must not be NULL, | 32 // Starts sending notifications to |handler|. |handler| must not be NULL, |
| 33 // and it must already be registered. | 33 // and it must already be registered. |
| 34 void RegisterHandler(SyncNotifierObserver* handler); | 34 void RegisterHandler(InvalidationHandler* handler); |
| 35 | |
| 36 | 35 |
| 37 // Updates the set of ObjectIds associated with |handler|. |handler| must | 36 // Updates the set of ObjectIds associated with |handler|. |handler| must |
| 38 // not be NULL, and must already be registered. An ID must be registered for | 37 // not be NULL, and must already be registered. An ID must be registered for |
| 39 // at most one handler. | 38 // at most one handler. |
| 40 void UpdateRegisteredIds(SyncNotifierObserver* handler, | 39 void UpdateRegisteredIds(InvalidationHandler* handler, |
| 41 const ObjectIdSet& ids); | 40 const ObjectIdSet& ids); |
| 42 | 41 |
| 43 // Stops sending notifications to |handler|. |handler| must not be NULL, and | 42 // Stops sending notifications to |handler|. |handler| must not be NULL, and |
| 44 // it must already be registered. Note that this doesn't unregister the IDs | 43 // it must already be registered. Note that this doesn't unregister the IDs |
| 45 // associated with |handler|. | 44 // associated with |handler|. |
| 46 void UnregisterHandler(SyncNotifierObserver* handler); | 45 void UnregisterHandler(InvalidationHandler* handler); |
| 47 | 46 |
| 48 // Returns the set of all IDs that are registered to some handler (even | 47 // Returns the set of all IDs that are registered to some handler (even |
| 49 // handlers that have been unregistered). | 48 // handlers that have been unregistered). |
| 50 ObjectIdSet GetAllRegisteredIds() const; | 49 ObjectIdSet GetAllRegisteredIds() const; |
| 51 | 50 |
| 52 // Sorts incoming invalidations into a bucket for each handler and then | 51 // Sorts incoming invalidations into a bucket for each handler and then |
| 53 // dispatches the batched invalidations to the corresponding handler. | 52 // dispatches the batched invalidations to the corresponding handler. |
| 54 // Invalidations for IDs with no corresponding handler are dropped, as are | 53 // Invalidations for IDs with no corresponding handler are dropped, as are |
| 55 // invalidations for handlers that are not added. | 54 // invalidations for handlers that are not added. |
| 56 void DispatchInvalidationsToHandlers(const ObjectIdStateMap& id_state_map, | 55 void DispatchInvalidationsToHandlers(const ObjectIdStateMap& id_state_map, |
| 57 IncomingNotificationSource source); | 56 IncomingNotificationSource source); |
| 58 | 57 |
| 59 // Calls the given handler method for each handler that has registered IDs. | 58 // Calls the given handler method for each handler that has registered IDs. |
| 60 void EmitOnNotificationsEnabled(); | 59 void EmitOnNotificationsEnabled(); |
| 61 void EmitOnNotificationsDisabled(NotificationsDisabledReason reason); | 60 void EmitOnNotificationsDisabled(NotificationsDisabledReason reason); |
| 62 | 61 |
| 63 bool IsHandlerRegisteredForTest(SyncNotifierObserver* handler) const; | 62 bool IsHandlerRegisteredForTest(InvalidationHandler* handler) const; |
| 64 ObjectIdSet GetRegisteredIdsForTest(SyncNotifierObserver* handler) const; | 63 ObjectIdSet GetRegisteredIdsForTest(InvalidationHandler* handler) const; |
| 65 | 64 |
| 66 // Needed for death tests. | 65 // Needed for death tests. |
| 67 void DetachFromThreadForTest(); | 66 void DetachFromThreadForTest(); |
| 68 | 67 |
| 69 private: | 68 private: |
| 70 typedef std::map<invalidation::ObjectId, SyncNotifierObserver*, | 69 typedef std::map<invalidation::ObjectId, InvalidationHandler*, |
| 71 ObjectIdLessThan> | 70 ObjectIdLessThan> |
| 72 IdHandlerMap; | 71 IdHandlerMap; |
| 73 | 72 |
| 74 SyncNotifierObserver* ObjectIdToHandler(const invalidation::ObjectId& id); | 73 InvalidationHandler* ObjectIdToHandler(const invalidation::ObjectId& id); |
| 75 | 74 |
| 76 base::ThreadChecker thread_checker_; | 75 base::ThreadChecker thread_checker_; |
| 77 ObserverList<SyncNotifierObserver> handlers_; | 76 ObserverList<InvalidationHandler> handlers_; |
| 78 IdHandlerMap id_to_handler_map_; | 77 IdHandlerMap id_to_handler_map_; |
| 79 | 78 |
| 80 DISALLOW_COPY_AND_ASSIGN(SyncNotifierRegistrar); | 79 DISALLOW_COPY_AND_ASSIGN(InvalidatorRegistrar); |
| 81 }; | 80 }; |
| 82 | 81 |
| 83 } // namespace syncer | 82 } // namespace syncer |
| 84 | 83 |
| 85 #endif // SYNC_NOTIFIER_SYNC_NOTIFIER_REGISTRAR_H_ | 84 #endif // SYNC_NOTIFIER_INVALIDATOR_REGISTRAR_H_ |
| OLD | NEW |