Chromium Code Reviews| Index: sync/notifier/sync_notifier_helper.h |
| diff --git a/sync/notifier/sync_notifier_helper.h b/sync/notifier/sync_notifier_helper.h |
| index 28ff187e6798228ec63f046a9176a02e49b9479e..e880fbbf50070ad07fed1c034c7c852a0ee3262d 100644 |
| --- a/sync/notifier/sync_notifier_helper.h |
| +++ b/sync/notifier/sync_notifier_helper.h |
| @@ -6,46 +6,75 @@ |
| #define SYNC_NOTIFIER_SYNC_NOTIFIER_HELPER_H_ |
| #include <map> |
| +#include <string> |
| #include "base/basictypes.h" |
| #include "base/observer_list.h" |
| +#include "base/threading/thread_checker.h" |
| #include "sync/notifier/invalidation_util.h" |
| #include "sync/notifier/object_id_payload_map.h" |
| #include "sync/notifier/sync_notifier_observer.h" |
| +namespace invalidation { |
| +class ObjectId; |
| +} // namespace invalidation |
| + |
| namespace syncer { |
| -// A helper class for classes that want to implement the SyncNotifier interface. |
| -// It helps keep track of registered handlers and which object ID registrations |
| -// are associated with which handlers, so implementors can just reuse the logic |
| -// here to dispatch invalidations and other interesting notifications. |
| +// A helper class for classes that want to implement the SyncNotifier |
|
msw
2012/08/03 23:30:46
nit: line breaks, this looks worse to me.
akalin
2012/08/07 07:25:19
Done.
|
| +// interface. It helps keep track of registered handlers and which |
| +// object ID registrations are associated with which handlers, so |
| +// implementors can just reuse the logic here to dispatch |
| +// invalidations and other interesting notifications. |
| class SyncNotifierHelper { |
| public: |
| SyncNotifierHelper(); |
| ~SyncNotifierHelper(); |
| - // Updates the set of ObjectIds associated with a given |handler|. Passing an |
| - // empty ObjectIdSet will unregister |handler|. The return value is an |
| - // ObjectIdSet containing values for all existing handlers. |
| - ObjectIdSet UpdateRegisteredIds(SyncNotifierObserver* handler, |
| - const ObjectIdSet& ids); |
| + // Sets the handler for the given name. Pass in NULL for |handler| |
|
msw
2012/08/03 23:30:46
nit: line breaks :)
akalin
2012/08/07 07:25:19
Done.
|
| + // if you want to remove the handler for the given name. (This |
| + // doesn't unregister the IDs for the given name, though.) A |
| + // handler must be set for at most one name. |
| + void SetHandler(const std::string& handler_name, |
| + SyncNotifierObserver* handler); |
| + |
| + // Updates the set of ObjectIds associated with a given handler (via |
| + // its name). An ID must be registered for at most one handler. |
| + void UpdateRegisteredIds(const std::string& handler_name, |
| + const ObjectIdSet& ids); |
| + |
| + // Returns the set of IDs that are registered to a handler. |
| + ObjectIdSet GetAllRegisteredIds() const; |
| - // Helper that sorts incoming invalidations into a bucket for each handler |
| - // and then dispatches the batched invalidations to the corresponding handler. |
| + // Helper that sorts incoming invalidations into a bucket for each |
|
msw
2012/08/03 23:30:46
nit: line breaks :)
akalin
2012/08/07 07:25:19
Done.
|
| + // handler and then dispatches the batched invalidations to the |
| + // corresponding handler. |
| void DispatchInvalidationsToHandlers(const ObjectIdPayloadMap& id_payloads, |
| IncomingNotificationSource source); |
| - // Calls the given handler method for each handler that has registered IDs. |
| + // Calls the given handler method for each handler that has |
|
msw
2012/08/03 23:30:46
nit: line breaks, why did you change this?
akalin
2012/08/07 07:25:19
Done.
|
| + // registered IDs. |
| void EmitOnNotificationsEnabled(); |
| void EmitOnNotificationsDisabled(NotificationsDisabledReason reason); |
| + // Needed for death tests. |
| + void DetachFromThreadForTest(); |
| + |
| private: |
| - typedef std::map<invalidation::ObjectId, |
| - SyncNotifierObserver*, |
| - ObjectIdLessThan> ObjectIdHandlerMap; |
| + typedef std::map<invalidation::ObjectId, std::string, ObjectIdLessThan> |
| + ObjectIdNameMap; |
| + typedef std::map<std::string, SyncNotifierObserver*> NameHandlerMap; |
| + |
| + SyncNotifierObserver* HandlerNameToHandler( |
| + const std::string& handler_name) const; |
| + |
| + SyncNotifierObserver* ObjectIdToHandler( |
| + const invalidation::ObjectId& id) const; |
| + base::ThreadChecker thread_checker_; |
| ObserverList<SyncNotifierObserver> handlers_; |
| - ObjectIdHandlerMap id_to_handler_map_; |
| + ObjectIdNameMap id_to_name_map_; |
| + NameHandlerMap name_to_handler_map_; |
| DISALLOW_COPY_AND_ASSIGN(SyncNotifierHelper); |
| }; |