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

Unified Diff: sync/notifier/sync_notifier_helper.h

Issue 10702074: Refactor sync-specific parts out of SyncNotifier/SyncNotifierObserver (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Now with tests Created 8 years, 5 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_helper.h
diff --git a/sync/notifier/sync_notifier_helper.h b/sync/notifier/sync_notifier_helper.h
new file mode 100644
index 0000000000000000000000000000000000000000..24814194d402d98bf3bdce768e027d6003b5e8f5
--- /dev/null
+++ b/sync/notifier/sync_notifier_helper.h
@@ -0,0 +1,52 @@
+// 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_HELPER_H_
+#define SYNC_NOTIFIER_SYNC_NOTIFIER_HELPER_H_
+
+#include <map>
+
+#include "base/basictypes.h"
+#include "base/observer_list.h"
+#include "sync/notifier/invalidation_util.h"
+#include "sync/notifier/object_id_payload_map.h"
+#include "sync/notifier/sync_notifier_observer.h"
+
+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.
+class SyncNotifierHelper {
+ public:
+ 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);
+
+ // Helper that sorts incoming invalidations into a bucket for each handler
+ // and then dispatches the batched invalidations to the corresponding handler.
+ void DispatchInvalidationsToHandlers(const ObjectIdPayloadMap& id_payloads,
+ IncomingNotificationSource source);
+
+ void OnNotificationsEnabled();
akalin 2012/07/20 19:01:40 rename to EmitOn...
akalin 2012/07/20 19:01:40 Add comment like: // Calls the given handler meth
dcheng 2012/07/21 00:09:54 Done.
dcheng 2012/07/21 00:09:54 Done.
+ void OnNotificationsDisabled(NotificationsDisabledReason reason);
akalin 2012/07/20 19:01:40 rename to EmitOn...
dcheng 2012/07/21 00:09:54 Done.
+
+ private:
+ typedef std::map<invalidation::ObjectId,
+ SyncNotifierObserver*,
+ ObjectIdLessThan> ObjectIdObserverMap;
+ ObserverList<SyncNotifierObserver> handlers_;
+ ObjectIdObserverMap id_to_handler_map_;
+
+ DISALLOW_COPY_AND_ASSIGN(SyncNotifierHelper);
+};
+
+} // namespace syncer
+
+#endif // SYNC_NOTIFIER_SYNC_NOTIFIER_HELPER_H_

Powered by Google App Engine
This is Rietveld 408576698