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

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: Address comments 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef SYNC_NOTIFIER_SYNC_NOTIFIER_HELPER_H_ 5 #ifndef SYNC_NOTIFIER_SYNC_NOTIFIER_HELPER_H_
6 #define SYNC_NOTIFIER_SYNC_NOTIFIER_HELPER_H_ 6 #define SYNC_NOTIFIER_SYNC_NOTIFIER_HELPER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string>
9 10
10 #include "base/basictypes.h" 11 #include "base/basictypes.h"
11 #include "base/observer_list.h" 12 #include "base/observer_list.h"
13 #include "base/threading/thread_checker.h"
12 #include "sync/notifier/invalidation_util.h" 14 #include "sync/notifier/invalidation_util.h"
13 #include "sync/notifier/object_id_payload_map.h" 15 #include "sync/notifier/object_id_payload_map.h"
14 #include "sync/notifier/sync_notifier_observer.h" 16 #include "sync/notifier/sync_notifier_observer.h"
15 17
18 namespace invalidation {
19 class ObjectId;
20 } // namespace invalidation
21
16 namespace syncer { 22 namespace syncer {
17 23
18 // A helper class for classes that want to implement the SyncNotifier interface. 24 // A helper class for classes that want to implement the SyncNotifier
msw 2012/08/03 23:30:46 nit: line breaks, this looks worse to me.
akalin 2012/08/07 07:25:19 Done.
19 // It helps keep track of registered handlers and which object ID registrations 25 // interface. It helps keep track of registered handlers and which
20 // are associated with which handlers, so implementors can just reuse the logic 26 // object ID registrations are associated with which handlers, so
21 // here to dispatch invalidations and other interesting notifications. 27 // implementors can just reuse the logic here to dispatch
28 // invalidations and other interesting notifications.
22 class SyncNotifierHelper { 29 class SyncNotifierHelper {
23 public: 30 public:
24 SyncNotifierHelper(); 31 SyncNotifierHelper();
25 ~SyncNotifierHelper(); 32 ~SyncNotifierHelper();
26 33
27 // Updates the set of ObjectIds associated with a given |handler|. Passing an 34 // Sets the handler for the given name. Pass in NULL for |handler|
msw 2012/08/03 23:30:46 nit: line breaks :)
akalin 2012/08/07 07:25:19 Done.
28 // empty ObjectIdSet will unregister |handler|. The return value is an 35 // if you want to remove the handler for the given name. (This
29 // ObjectIdSet containing values for all existing handlers. 36 // doesn't unregister the IDs for the given name, though.) A
30 ObjectIdSet UpdateRegisteredIds(SyncNotifierObserver* handler, 37 // handler must be set for at most one name.
31 const ObjectIdSet& ids); 38 void SetHandler(const std::string& handler_name,
39 SyncNotifierObserver* handler);
32 40
33 // Helper that sorts incoming invalidations into a bucket for each handler 41 // Updates the set of ObjectIds associated with a given handler (via
34 // and then dispatches the batched invalidations to the corresponding handler. 42 // its name). An ID must be registered for at most one handler.
43 void UpdateRegisteredIds(const std::string& handler_name,
44 const ObjectIdSet& ids);
45
46 // Returns the set of IDs that are registered to a handler.
47 ObjectIdSet GetAllRegisteredIds() const;
48
49 // Helper that sorts incoming invalidations into a bucket for each
msw 2012/08/03 23:30:46 nit: line breaks :)
akalin 2012/08/07 07:25:19 Done.
50 // handler and then dispatches the batched invalidations to the
51 // corresponding handler.
35 void DispatchInvalidationsToHandlers(const ObjectIdPayloadMap& id_payloads, 52 void DispatchInvalidationsToHandlers(const ObjectIdPayloadMap& id_payloads,
36 IncomingNotificationSource source); 53 IncomingNotificationSource source);
37 54
38 // Calls the given handler method for each handler that has registered IDs. 55 // Calls the given handler method for each handler that has
msw 2012/08/03 23:30:46 nit: line breaks, why did you change this?
akalin 2012/08/07 07:25:19 Done.
56 // registered IDs.
39 void EmitOnNotificationsEnabled(); 57 void EmitOnNotificationsEnabled();
40 void EmitOnNotificationsDisabled(NotificationsDisabledReason reason); 58 void EmitOnNotificationsDisabled(NotificationsDisabledReason reason);
41 59
60 // Needed for death tests.
61 void DetachFromThreadForTest();
62
42 private: 63 private:
43 typedef std::map<invalidation::ObjectId, 64 typedef std::map<invalidation::ObjectId, std::string, ObjectIdLessThan>
44 SyncNotifierObserver*, 65 ObjectIdNameMap;
45 ObjectIdLessThan> ObjectIdHandlerMap; 66 typedef std::map<std::string, SyncNotifierObserver*> NameHandlerMap;
46 67
68 SyncNotifierObserver* HandlerNameToHandler(
69 const std::string& handler_name) const;
70
71 SyncNotifierObserver* ObjectIdToHandler(
72 const invalidation::ObjectId& id) const;
73
74 base::ThreadChecker thread_checker_;
47 ObserverList<SyncNotifierObserver> handlers_; 75 ObserverList<SyncNotifierObserver> handlers_;
48 ObjectIdHandlerMap id_to_handler_map_; 76 ObjectIdNameMap id_to_name_map_;
77 NameHandlerMap name_to_handler_map_;
49 78
50 DISALLOW_COPY_AND_ASSIGN(SyncNotifierHelper); 79 DISALLOW_COPY_AND_ASSIGN(SyncNotifierHelper);
51 }; 80 };
52 81
53 } // namespace syncer 82 } // namespace syncer
54 83
55 #endif // SYNC_NOTIFIER_SYNC_NOTIFIER_HELPER_H_ 84 #endif // SYNC_NOTIFIER_SYNC_NOTIFIER_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698