Index: sync/notifier/invalidation_notifier_base.h |
diff --git a/sync/notifier/invalidation_notifier_base.h b/sync/notifier/invalidation_notifier_base.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..71516e535b7db3272b5d6e055c33086913b269e6 |
--- /dev/null |
+++ b/sync/notifier/invalidation_notifier_base.h |
@@ -0,0 +1,56 @@ |
+// 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_INVALIDATION_NOTIFIER_BASE_H_ |
+#define SYNC_NOTIFIER_INVALIDATION_NOTIFIER_BASE_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.h" |
+#include "sync/notifier/sync_notifier_observer.h" |
+ |
+namespace syncer { |
+ |
+// Logic shared between InvalidationNotifier and |
+// NonBlockingInvalidationNotifier. |
+class InvalidationNotifierBase : public SyncNotifier { |
+ public: |
+ InvalidationNotifierBase(); |
+ virtual ~InvalidationNotifierBase(); |
+ |
+ virtual void AddHandler(SyncNotifierObserver* observer) OVERRIDE; |
+ virtual void RemoveHandler(SyncNotifierObserver* observer) OVERRIDE; |
+ |
+ protected: |
+ typedef std::map<invalidation::ObjectId, |
+ SyncNotifierObserver*, |
+ ObjectIdLessThan> ObjectIdObserverMap; |
+ |
+ // Updates the mapping of object IDs to observers and returns all the keys, |
+ // e.g. object IDs, that are currently in the map. |
+ ObjectIdSet UpdateObjectIdObserverMap(); |
+ |
+ // Helper that sorts incoming invalidations into a bucket for each observer |
+ // and then dispatches the batched invalidations to each respective observer. |
+ void DispatchInvalidationsToObservers(const ObjectIdPayloadMap& id_payloads, |
+ IncomingNotificationSource source); |
+ |
+ // Note that this is non-const because FOR_EACH_OBSERVER() may mutate the |
+ // original observer list. |
+ ObserverList<SyncNotifierObserver>& observers() { return observers_; } |
+ |
+ private: |
+ ObserverList<SyncNotifierObserver> observers_; |
+ ObjectIdObserverMap id_to_observer_map_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(InvalidationNotifierBase); |
+}; |
+ |
+} // namespace syncer |
+ |
+#endif // SYNC_NOTIFIER_INVALIDATION_NOTIFIER_BASE_H_ |