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

Side by Side 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: 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
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_REGISTRAR_H_
6 #define SYNC_NOTIFIER_SYNC_NOTIFIER_REGISTRAR_H_
7
8 #include <map>
9
10 #include "base/basictypes.h"
11 #include "base/observer_list.h"
12 #include "base/threading/thread_checker.h"
13 #include "sync/notifier/invalidation_util.h"
14 #include "sync/notifier/object_id_payload_map.h"
15 #include "sync/notifier/sync_notifier_observer.h"
16
17 namespace invalidation {
18 class ObjectId;
19 } // namespace invalidation
20
21 namespace syncer {
22
23 // A helper class for implementations of the SyncNotifier interface. It helps
24 // keep track of registered handlers and which object ID registrations are
25 // associated with which handlers, so implementors can just reuse the logic
26 // here to dispatch invalidations and other interesting notifications.
27 class SyncNotifierRegistrar {
28 public:
29 SyncNotifierRegistrar();
30 ~SyncNotifierRegistrar();
31
32 // Starts sending notifications to |handler|. |handler| must not be NULL,
33 // and it must already be registered.
34 void RegisterHandler(SyncNotifierObserver* handler);
35
36
37 // Updates the set of ObjectIds associated with |handler|. |handler| must
38 // not be NULL, and must already be registered. An ID must be registered for
39 // at most one handler.
40 void UpdateRegisteredIds(SyncNotifierObserver* handler,
41 const ObjectIdSet& ids);
42
43 // Stops sending notifications to |handler|. |handler| must not be NULL, and
44 // it must already be registered. Note that this doesn't unregister the IDs
45 // associated with |handler|.
46 void UnregisterHandler(SyncNotifierObserver* handler);
47
48 // Returns the set of all IDs that are registered to some handler (even
49 // handlers that have been unregistered).
50 ObjectIdSet GetAllRegisteredIds() const;
51
52 // Sorts incoming invalidations into a bucket for each handler and then
53 // dispatches the batched invalidations to the corresponding handler.
54 // Invalidations for IDs with no corresponding handler are dropped, as are
55 // invalidations for handlers that are not added.
56 void DispatchInvalidationsToHandlers(const ObjectIdPayloadMap& id_payloads,
57 IncomingNotificationSource source);
58
59 // Calls the given handler method for each handler that has registered IDs.
60 void EmitOnNotificationsEnabled();
61 void EmitOnNotificationsDisabled(NotificationsDisabledReason reason);
62
63 // Needed for death tests.
64 void DetachFromThreadForTest();
65
66 private:
67 typedef std::map<invalidation::ObjectId, SyncNotifierObserver*,
68 ObjectIdLessThan>
69 IdHandlerMap;
70
71 SyncNotifierObserver* ObjectIdToHandler(const invalidation::ObjectId& id);
72
73 base::ThreadChecker thread_checker_;
74 ObserverList<SyncNotifierObserver> handlers_;
75 IdHandlerMap id_to_handler_map_;
76
77 DISALLOW_COPY_AND_ASSIGN(SyncNotifierRegistrar);
78 };
79
80 } // namespace syncer
81
82 #endif // SYNC_NOTIFIER_SYNC_NOTIFIER_REGISTRAR_H_
OLDNEW
« no previous file with comments | « sync/notifier/sync_notifier_helper_unittest.cc ('k') | sync/notifier/sync_notifier_registrar.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698