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

Side by Side Diff: sync/notifier/non_blocking_invalidation_notifier.cc

Issue 10451060: sync: migrate invalidation state from syncable::Directory to InvalidationStorage (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: init Created 8 years, 6 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 #include "sync/notifier/non_blocking_invalidation_notifier.h" 5 #include "sync/notifier/non_blocking_invalidation_notifier.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/threading/thread.h" 10 #include "base/threading/thread.h"
11 #include "sync/notifier/invalidation_notifier.h" 11 #include "sync/notifier/invalidation_notifier.h"
12 12
13 namespace sync_notifier { 13 namespace sync_notifier {
14 14
15 class NonBlockingInvalidationNotifier::Core 15 class NonBlockingInvalidationNotifier::Core
16 : public base::RefCountedThreadSafe<NonBlockingInvalidationNotifier::Core>, 16 : public base::RefCountedThreadSafe<NonBlockingInvalidationNotifier::Core>,
17 // SyncNotifierObserver to observe the InvalidationNotifier we create. 17 // SyncNotifierObserver to observe the InvalidationNotifier we create.
18 public SyncNotifierObserver { 18 public SyncNotifierObserver {
19 public: 19 public:
20 // Called on parent thread. |delegate_observer| should be 20 // Called on parent thread. |delegate_observer| should be
21 // initialized. 21 // initialized.
22 explicit Core( 22 explicit Core(
23 const browser_sync::WeakHandle<SyncNotifierObserver>& 23 const browser_sync::WeakHandle<SyncNotifierObserver>&
24 delegate_observer); 24 delegate_observer);
25 25
26 // Helpers called on I/O thread. 26 // Helpers called on I/O thread.
27 void Initialize( 27 void Initialize(
28 const notifier::NotifierOptions& notifier_options, 28 const notifier::NotifierOptions& notifier_options,
29 const InvalidationVersionMap& initial_max_invalidation_versions, 29 const InvalidationVersionMap& initial_max_invalidation_versions,
30 const std::string& initial_invalidation_state,
30 const browser_sync::WeakHandle<InvalidationStateTracker>& 31 const browser_sync::WeakHandle<InvalidationStateTracker>&
31 invalidation_state_tracker, 32 invalidation_state_tracker,
32 const std::string& client_info); 33 const std::string& client_info);
33 void Teardown(); 34 void Teardown();
34 void SetUniqueId(const std::string& unique_id); 35 void SetUniqueId(const std::string& unique_id);
35 void SetState(const std::string& state); 36 void SetStateDeprecated(const std::string& state);
36 void UpdateCredentials(const std::string& email, const std::string& token); 37 void UpdateCredentials(const std::string& email, const std::string& token);
37 void UpdateEnabledTypes(syncable::ModelTypeSet enabled_types); 38 void UpdateEnabledTypes(syncable::ModelTypeSet enabled_types);
38 39
39 // SyncNotifierObserver implementation (all called on I/O thread by 40 // SyncNotifierObserver implementation (all called on I/O thread by
40 // InvalidationNotifier). 41 // InvalidationNotifier).
41 virtual void OnIncomingNotification( 42 virtual void OnIncomingNotification(
42 const syncable::ModelTypePayloadMap& type_payloads, 43 const syncable::ModelTypePayloadMap& type_payloads,
43 IncomingNotificationSource source); 44 IncomingNotificationSource source);
44 virtual void OnNotificationStateChange(bool notifications_enabled); 45 virtual void OnNotificationStateChange(bool notifications_enabled);
45 virtual void StoreState(const std::string& state);
46 46
47 private: 47 private:
48 friend class 48 friend class
49 base::RefCountedThreadSafe<NonBlockingInvalidationNotifier::Core>; 49 base::RefCountedThreadSafe<NonBlockingInvalidationNotifier::Core>;
50 // Called on parent or I/O thread. 50 // Called on parent or I/O thread.
51 ~Core(); 51 ~Core();
52 52
53 // The variables below should be used only on the I/O thread. 53 // The variables below should be used only on the I/O thread.
54 const browser_sync::WeakHandle<SyncNotifierObserver> delegate_observer_; 54 const browser_sync::WeakHandle<SyncNotifierObserver> delegate_observer_;
55 scoped_ptr<InvalidationNotifier> invalidation_notifier_; 55 scoped_ptr<InvalidationNotifier> invalidation_notifier_;
56 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; 56 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_;
57 57
58 DISALLOW_COPY_AND_ASSIGN(Core); 58 DISALLOW_COPY_AND_ASSIGN(Core);
59 }; 59 };
60 60
61 NonBlockingInvalidationNotifier::Core::Core( 61 NonBlockingInvalidationNotifier::Core::Core(
62 const browser_sync::WeakHandle<SyncNotifierObserver>& 62 const browser_sync::WeakHandle<SyncNotifierObserver>&
63 delegate_observer) 63 delegate_observer)
64 : delegate_observer_(delegate_observer) { 64 : delegate_observer_(delegate_observer) {
65 DCHECK(delegate_observer_.IsInitialized()); 65 DCHECK(delegate_observer_.IsInitialized());
66 } 66 }
67 67
68 NonBlockingInvalidationNotifier::Core::~Core() { 68 NonBlockingInvalidationNotifier::Core::~Core() {
69 } 69 }
70 70
71 void NonBlockingInvalidationNotifier::Core::Initialize( 71 void NonBlockingInvalidationNotifier::Core::Initialize(
72 const notifier::NotifierOptions& notifier_options, 72 const notifier::NotifierOptions& notifier_options,
73 const InvalidationVersionMap& initial_max_invalidation_versions, 73 const InvalidationVersionMap& initial_max_invalidation_versions,
74 const std::string& initial_invalidation_state,
74 const browser_sync::WeakHandle<InvalidationStateTracker>& 75 const browser_sync::WeakHandle<InvalidationStateTracker>&
75 invalidation_state_tracker, 76 invalidation_state_tracker,
76 const std::string& client_info) { 77 const std::string& client_info) {
77 DCHECK(notifier_options.request_context_getter); 78 DCHECK(notifier_options.request_context_getter);
78 DCHECK_EQ(notifier::NOTIFICATION_SERVER, 79 DCHECK_EQ(notifier::NOTIFICATION_SERVER,
79 notifier_options.notification_method); 80 notifier_options.notification_method);
80 io_message_loop_proxy_ = notifier_options.request_context_getter-> 81 io_message_loop_proxy_ = notifier_options.request_context_getter->
81 GetIOMessageLoopProxy(); 82 GetIOMessageLoopProxy();
82 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 83 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
83 invalidation_notifier_.reset( 84 invalidation_notifier_.reset(
84 new InvalidationNotifier( 85 new InvalidationNotifier(
85 notifier_options, 86 notifier_options,
86 initial_max_invalidation_versions, 87 initial_max_invalidation_versions,
88 initial_invalidation_state,
87 invalidation_state_tracker, 89 invalidation_state_tracker,
88 client_info)); 90 client_info));
89 invalidation_notifier_->AddObserver(this); 91 invalidation_notifier_->AddObserver(this);
90 } 92 }
91 93
92 94
93 void NonBlockingInvalidationNotifier::Core::Teardown() { 95 void NonBlockingInvalidationNotifier::Core::Teardown() {
94 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 96 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
95 invalidation_notifier_->RemoveObserver(this); 97 invalidation_notifier_->RemoveObserver(this);
96 invalidation_notifier_.reset(); 98 invalidation_notifier_.reset();
97 io_message_loop_proxy_ = NULL; 99 io_message_loop_proxy_ = NULL;
98 } 100 }
99 101
100 void NonBlockingInvalidationNotifier::Core::SetUniqueId( 102 void NonBlockingInvalidationNotifier::Core::SetUniqueId(
101 const std::string& unique_id) { 103 const std::string& unique_id) {
102 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 104 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
103 invalidation_notifier_->SetUniqueId(unique_id); 105 invalidation_notifier_->SetUniqueId(unique_id);
104 } 106 }
105 107
106 void NonBlockingInvalidationNotifier::Core::SetState( 108 void NonBlockingInvalidationNotifier::Core::SetStateDeprecated(
107 const std::string& state) { 109 const std::string& state) {
108 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 110 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
109 invalidation_notifier_->SetState(state); 111 invalidation_notifier_->SetStateDeprecated(state);
110 } 112 }
111 113
112 void NonBlockingInvalidationNotifier::Core::UpdateCredentials( 114 void NonBlockingInvalidationNotifier::Core::UpdateCredentials(
113 const std::string& email, const std::string& token) { 115 const std::string& email, const std::string& token) {
114 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 116 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
115 invalidation_notifier_->UpdateCredentials(email, token); 117 invalidation_notifier_->UpdateCredentials(email, token);
116 } 118 }
117 119
118 void NonBlockingInvalidationNotifier::Core::UpdateEnabledTypes( 120 void NonBlockingInvalidationNotifier::Core::UpdateEnabledTypes(
119 syncable::ModelTypeSet enabled_types) { 121 syncable::ModelTypeSet enabled_types) {
(...skipping 12 matching lines...) Expand all
132 } 134 }
133 135
134 void NonBlockingInvalidationNotifier::Core::OnNotificationStateChange( 136 void NonBlockingInvalidationNotifier::Core::OnNotificationStateChange(
135 bool notifications_enabled) { 137 bool notifications_enabled) {
136 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 138 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
137 delegate_observer_.Call(FROM_HERE, 139 delegate_observer_.Call(FROM_HERE,
138 &SyncNotifierObserver::OnNotificationStateChange, 140 &SyncNotifierObserver::OnNotificationStateChange,
139 notifications_enabled); 141 notifications_enabled);
140 } 142 }
141 143
142 void NonBlockingInvalidationNotifier::Core::StoreState(
143 const std::string& state) {
144 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
145 delegate_observer_.Call(FROM_HERE,
146 &SyncNotifierObserver::StoreState, state);
147 }
148
149 NonBlockingInvalidationNotifier::NonBlockingInvalidationNotifier( 144 NonBlockingInvalidationNotifier::NonBlockingInvalidationNotifier(
150 const notifier::NotifierOptions& notifier_options, 145 const notifier::NotifierOptions& notifier_options,
151 const InvalidationVersionMap& initial_max_invalidation_versions, 146 const InvalidationVersionMap& initial_max_invalidation_versions,
147 const std::string& initial_invalidation_state,
152 const browser_sync::WeakHandle<InvalidationStateTracker>& 148 const browser_sync::WeakHandle<InvalidationStateTracker>&
153 invalidation_state_tracker, 149 invalidation_state_tracker,
154 const std::string& client_info) 150 const std::string& client_info)
155 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 151 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
156 core_( 152 core_(
157 new Core(browser_sync::MakeWeakHandle( 153 new Core(browser_sync::MakeWeakHandle(
158 weak_ptr_factory_.GetWeakPtr()))), 154 weak_ptr_factory_.GetWeakPtr()))),
159 parent_message_loop_proxy_( 155 parent_message_loop_proxy_(
160 base::MessageLoopProxy::current()), 156 base::MessageLoopProxy::current()),
161 io_message_loop_proxy_(notifier_options.request_context_getter-> 157 io_message_loop_proxy_(notifier_options.request_context_getter->
162 GetIOMessageLoopProxy()) { 158 GetIOMessageLoopProxy()) {
163 if (!io_message_loop_proxy_->PostTask( 159 if (!io_message_loop_proxy_->PostTask(
164 FROM_HERE, 160 FROM_HERE,
165 base::Bind( 161 base::Bind(
166 &NonBlockingInvalidationNotifier::Core::Initialize, 162 &NonBlockingInvalidationNotifier::Core::Initialize,
167 core_.get(), 163 core_.get(),
168 notifier_options, 164 notifier_options,
169 initial_max_invalidation_versions, 165 initial_max_invalidation_versions,
166 initial_invalidation_state,
170 invalidation_state_tracker, 167 invalidation_state_tracker,
171 client_info))) { 168 client_info))) {
172 NOTREACHED(); 169 NOTREACHED();
173 } 170 }
174 } 171 }
175 172
176 NonBlockingInvalidationNotifier::~NonBlockingInvalidationNotifier() { 173 NonBlockingInvalidationNotifier::~NonBlockingInvalidationNotifier() {
177 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); 174 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread());
178 if (!io_message_loop_proxy_->PostTask( 175 if (!io_message_loop_proxy_->PostTask(
179 FROM_HERE, 176 FROM_HERE,
(...skipping 19 matching lines...) Expand all
199 const std::string& unique_id) { 196 const std::string& unique_id) {
200 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); 197 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread());
201 if (!io_message_loop_proxy_->PostTask( 198 if (!io_message_loop_proxy_->PostTask(
202 FROM_HERE, 199 FROM_HERE,
203 base::Bind(&NonBlockingInvalidationNotifier::Core::SetUniqueId, 200 base::Bind(&NonBlockingInvalidationNotifier::Core::SetUniqueId,
204 core_.get(), unique_id))) { 201 core_.get(), unique_id))) {
205 NOTREACHED(); 202 NOTREACHED();
206 } 203 }
207 } 204 }
208 205
209 void NonBlockingInvalidationNotifier::SetState(const std::string& state) { 206 void NonBlockingInvalidationNotifier::SetStateDeprecated(
207 const std::string& state) {
210 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); 208 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread());
211 if (!io_message_loop_proxy_->PostTask( 209 if (!io_message_loop_proxy_->PostTask(
212 FROM_HERE, 210 FROM_HERE,
213 base::Bind(&NonBlockingInvalidationNotifier::Core::SetState, 211 base::Bind(
214 core_.get(), state))) { 212 &NonBlockingInvalidationNotifier::Core::SetStateDeprecated,
213 core_.get(), state))) {
215 NOTREACHED(); 214 NOTREACHED();
216 } 215 }
217 } 216 }
218 217
219 void NonBlockingInvalidationNotifier::UpdateCredentials( 218 void NonBlockingInvalidationNotifier::UpdateCredentials(
220 const std::string& email, const std::string& token) { 219 const std::string& email, const std::string& token) {
221 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); 220 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread());
222 if (!io_message_loop_proxy_->PostTask( 221 if (!io_message_loop_proxy_->PostTask(
223 FROM_HERE, 222 FROM_HERE,
224 base::Bind(&NonBlockingInvalidationNotifier::Core::UpdateCredentials, 223 base::Bind(&NonBlockingInvalidationNotifier::Core::UpdateCredentials,
(...skipping 28 matching lines...) Expand all
253 OnIncomingNotification(type_payloads, source)); 252 OnIncomingNotification(type_payloads, source));
254 } 253 }
255 254
256 void NonBlockingInvalidationNotifier::OnNotificationStateChange( 255 void NonBlockingInvalidationNotifier::OnNotificationStateChange(
257 bool notifications_enabled) { 256 bool notifications_enabled) {
258 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); 257 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread());
259 FOR_EACH_OBSERVER(SyncNotifierObserver, observers_, 258 FOR_EACH_OBSERVER(SyncNotifierObserver, observers_,
260 OnNotificationStateChange(notifications_enabled)); 259 OnNotificationStateChange(notifications_enabled));
261 } 260 }
262 261
263 void NonBlockingInvalidationNotifier::StoreState(
264 const std::string& state) {
265 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread());
266 FOR_EACH_OBSERVER(SyncNotifierObserver, observers_,
267 StoreState(state));
268 }
269
270 } // namespace sync_notifier 262 } // namespace sync_notifier
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698