| 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..0628528e94fef8427b69366b200e89e1329e44d4 100644
|
| --- a/sync/notifier/sync_notifier_helper.h
|
| +++ b/sync/notifier/sync_notifier_helper.h
|
| @@ -6,32 +6,49 @@
|
| #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
|
| +// 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| 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.
|
| + // and then dispatches the batched invalidations to the corresponding
|
| + // handler.
|
| void DispatchInvalidationsToHandlers(const ObjectIdPayloadMap& id_payloads,
|
| IncomingNotificationSource source);
|
|
|
| @@ -39,13 +56,24 @@ class SyncNotifierHelper {
|
| 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);
|
| };
|
|
|