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

Side by Side Diff: sync/notifier/sync_notifier_helper.h

Issue 10824161: [Sync] Avoid unregistering object IDs on shutdown (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Work around brittle unit test 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sync/notifier/sync_notifier_factory_unittest.cc ('k') | sync/notifier/sync_notifier_helper.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef SYNC_NOTIFIER_SYNC_NOTIFIER_HELPER_H_
6 #define SYNC_NOTIFIER_SYNC_NOTIFIER_HELPER_H_
7
8 #include <map>
9
10 #include "base/basictypes.h"
11 #include "base/observer_list.h"
12 #include "sync/notifier/invalidation_util.h"
13 #include "sync/notifier/object_id_payload_map.h"
14 #include "sync/notifier/sync_notifier_observer.h"
15
16 namespace syncer {
17
18 // A helper class for classes that want to implement the SyncNotifier interface.
19 // It helps keep track of registered handlers and which object ID registrations
20 // are associated with which handlers, so implementors can just reuse the logic
21 // here to dispatch invalidations and other interesting notifications.
22 class SyncNotifierHelper {
23 public:
24 SyncNotifierHelper();
25 ~SyncNotifierHelper();
26
27 // Updates the set of ObjectIds associated with a given |handler|. Passing an
28 // empty ObjectIdSet will unregister |handler|. The return value is an
29 // ObjectIdSet containing values for all existing handlers.
30 ObjectIdSet UpdateRegisteredIds(SyncNotifierObserver* handler,
31 const ObjectIdSet& ids);
32
33 // Helper that sorts incoming invalidations into a bucket for each handler
34 // and then dispatches the batched invalidations to the corresponding handler.
35 void DispatchInvalidationsToHandlers(const ObjectIdPayloadMap& id_payloads,
36 IncomingNotificationSource source);
37
38 // Calls the given handler method for each handler that has registered IDs.
39 void EmitOnNotificationsEnabled();
40 void EmitOnNotificationsDisabled(NotificationsDisabledReason reason);
41
42 private:
43 typedef std::map<invalidation::ObjectId,
44 SyncNotifierObserver*,
45 ObjectIdLessThan> ObjectIdHandlerMap;
46
47 ObserverList<SyncNotifierObserver> handlers_;
48 ObjectIdHandlerMap id_to_handler_map_;
49
50 DISALLOW_COPY_AND_ASSIGN(SyncNotifierHelper);
51 };
52
53 } // namespace syncer
54
55 #endif // SYNC_NOTIFIER_SYNC_NOTIFIER_HELPER_H_
OLDNEW
« no previous file with comments | « sync/notifier/sync_notifier_factory_unittest.cc ('k') | sync/notifier/sync_notifier_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698