Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(185)

Unified Diff: sync/notifier/sync_notifier_registrar.h

Issue 10824161: [Sync] Avoid unregistering object IDs on shutdown (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use new API Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sync/notifier/sync_notifier_registrar.h
diff --git a/sync/notifier/sync_notifier_registrar.h b/sync/notifier/sync_notifier_registrar.h
new file mode 100644
index 0000000000000000000000000000000000000000..a34fd24738470d0131d811add474a0585f9e6adb
--- /dev/null
+++ b/sync/notifier/sync_notifier_registrar.h
@@ -0,0 +1,81 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SYNC_NOTIFIER_SYNC_NOTIFIER_REGISTRAR_H_
+#define SYNC_NOTIFIER_SYNC_NOTIFIER_REGISTRAR_H_
+
+#include <map>
+
+#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 implementations of 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 SyncNotifierRegistrar {
+ public:
+ SyncNotifierRegistrar();
+ ~SyncNotifierRegistrar();
+
+ // Starts sending notifications to |handler|. |handler| must not be NULL,
+ // and it must not already have been added.
+ void RegisterHandler(SyncNotifierObserver* handler);
+
+ // Updates the set of ObjectIds associated with |handler|. |handler| must
+ // 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.
+ // for at most one handler.
+ void UpdateRegisteredIds(SyncNotifierObserver* handler,
+ const ObjectIdSet& ids);
+
+ // Stops sending notifications to |handler|. |handler| must not be NULL, and
+ // it must have been previously added. Note that this doesn't unregister the
+ // IDs associated with |handler|.
+ void UnregisterHandler(SyncNotifierObserver* handler);
+
+ // Returns the set of all IDs that are registered to some handler (even
+ // unregistered ones).
msw 2012/08/09 05:20:26 nit: s/ones/handlers/
akalin 2012/08/10 01:28:08 Done.
+ ObjectIdSet GetAllRegisteredIds() const;
+
+ // Sorts incoming invalidations into a bucket for each handler and then
+ // dispatches the batched invalidations to the corresponding handler.
+ // Invalidations for IDs with no corresponding handler are dropped, as are
+ // invalidations for handlers that are not added.
+ void DispatchInvalidationsToHandlers(const ObjectIdPayloadMap& id_payloads,
+ IncomingNotificationSource source);
+
+ // Calls the given handler method for each handler that has registered IDs.
+ void EmitOnNotificationsEnabled();
+ void EmitOnNotificationsDisabled(NotificationsDisabledReason reason);
+
+ // Needed for death tests.
+ void DetachFromThreadForTest();
+
+ private:
+ typedef std::map<invalidation::ObjectId, SyncNotifierObserver*,
+ ObjectIdLessThan>
+ IdHandlerMap;
+
+ SyncNotifierObserver* ObjectIdToHandler(const invalidation::ObjectId& id);
+
+ base::ThreadChecker thread_checker_;
+ ObserverList<SyncNotifierObserver> handlers_;
+ IdHandlerMap id_to_handler_map_;
+
+ DISALLOW_COPY_AND_ASSIGN(SyncNotifierRegistrar);
+};
+
+} // namespace syncer
+
+#endif // SYNC_NOTIFIER_SYNC_NOTIFIER_REGISTRAR_H_

Powered by Google App Engine
This is Rietveld 408576698