OLD | NEW |
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_invalidator.h" | 5 #include "sync/notifier/non_blocking_invalidator.h" |
6 | 6 |
7 #include <cstddef> | 7 #include <cstddef> |
8 | 8 |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 const WeakHandle<InvalidationStateTracker>& invalidation_state_tracker, | 35 const WeakHandle<InvalidationStateTracker>& invalidation_state_tracker, |
36 const std::string& client_info); | 36 const std::string& client_info); |
37 void Teardown(); | 37 void Teardown(); |
38 void UpdateRegisteredIds(const ObjectIdSet& ids); | 38 void UpdateRegisteredIds(const ObjectIdSet& ids); |
39 void SetUniqueId(const std::string& unique_id); | 39 void SetUniqueId(const std::string& unique_id); |
40 void SetStateDeprecated(const std::string& state); | 40 void SetStateDeprecated(const std::string& state); |
41 void UpdateCredentials(const std::string& email, const std::string& token); | 41 void UpdateCredentials(const std::string& email, const std::string& token); |
42 | 42 |
43 // InvalidationHandler implementation (all called on I/O thread by | 43 // InvalidationHandler implementation (all called on I/O thread by |
44 // InvalidationNotifier). | 44 // InvalidationNotifier). |
45 virtual void OnNotificationsEnabled() OVERRIDE; | 45 virtual void OnInvalidatorStateChange(InvalidatorState reason) OVERRIDE; |
46 virtual void OnNotificationsDisabled( | 46 virtual void OnIncomingInvalidation( |
47 NotificationsDisabledReason reason) OVERRIDE; | |
48 virtual void OnIncomingNotification( | |
49 const ObjectIdStateMap& id_state_map, | 47 const ObjectIdStateMap& id_state_map, |
50 IncomingNotificationSource source) OVERRIDE; | 48 IncomingInvalidationSource source) OVERRIDE; |
51 | 49 |
52 private: | 50 private: |
53 friend class | 51 friend class |
54 base::RefCountedThreadSafe<NonBlockingInvalidator::Core>; | 52 base::RefCountedThreadSafe<NonBlockingInvalidator::Core>; |
55 // Called on parent or I/O thread. | 53 // Called on parent or I/O thread. |
56 ~Core(); | 54 ~Core(); |
57 | 55 |
58 // The variables below should be used only on the I/O thread. | 56 // The variables below should be used only on the I/O thread. |
59 const WeakHandle<InvalidationHandler> delegate_observer_; | 57 const WeakHandle<InvalidationHandler> delegate_observer_; |
60 scoped_ptr<InvalidationNotifier> invalidation_notifier_; | 58 scoped_ptr<InvalidationNotifier> invalidation_notifier_; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 114 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
117 invalidation_notifier_->SetStateDeprecated(state); | 115 invalidation_notifier_->SetStateDeprecated(state); |
118 } | 116 } |
119 | 117 |
120 void NonBlockingInvalidator::Core::UpdateCredentials(const std::string& email, | 118 void NonBlockingInvalidator::Core::UpdateCredentials(const std::string& email, |
121 const std::string& token) { | 119 const std::string& token) { |
122 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 120 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
123 invalidation_notifier_->UpdateCredentials(email, token); | 121 invalidation_notifier_->UpdateCredentials(email, token); |
124 } | 122 } |
125 | 123 |
126 void NonBlockingInvalidator::Core::OnNotificationsEnabled() { | 124 void NonBlockingInvalidator::Core::OnInvalidatorStateChange( |
| 125 InvalidatorState reason) { |
| 126 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
| 127 delegate_observer_.Call( |
| 128 FROM_HERE, &InvalidationHandler::OnInvalidatorStateChange, reason); |
| 129 } |
| 130 |
| 131 void NonBlockingInvalidator::Core::OnIncomingInvalidation( |
| 132 const ObjectIdStateMap& id_state_map, IncomingInvalidationSource source) { |
127 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 133 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
128 delegate_observer_.Call(FROM_HERE, | 134 delegate_observer_.Call(FROM_HERE, |
129 &InvalidationHandler::OnNotificationsEnabled); | 135 &InvalidationHandler::OnIncomingInvalidation, |
130 } | |
131 | |
132 void NonBlockingInvalidator::Core::OnNotificationsDisabled( | |
133 NotificationsDisabledReason reason) { | |
134 DCHECK(network_task_runner_->BelongsToCurrentThread()); | |
135 delegate_observer_.Call( | |
136 FROM_HERE, &InvalidationHandler::OnNotificationsDisabled, reason); | |
137 } | |
138 | |
139 void NonBlockingInvalidator::Core::OnIncomingNotification( | |
140 const ObjectIdStateMap& id_state_map, IncomingNotificationSource source) { | |
141 DCHECK(network_task_runner_->BelongsToCurrentThread()); | |
142 delegate_observer_.Call(FROM_HERE, | |
143 &InvalidationHandler::OnIncomingNotification, | |
144 id_state_map, | 136 id_state_map, |
145 source); | 137 source); |
146 } | 138 } |
147 | 139 |
148 NonBlockingInvalidator::NonBlockingInvalidator( | 140 NonBlockingInvalidator::NonBlockingInvalidator( |
149 const notifier::NotifierOptions& notifier_options, | 141 const notifier::NotifierOptions& notifier_options, |
150 const InvalidationVersionMap& initial_max_invalidation_versions, | 142 const InvalidationVersionMap& initial_max_invalidation_versions, |
151 const std::string& initial_invalidation_state, | 143 const std::string& initial_invalidation_state, |
152 const WeakHandle<InvalidationStateTracker>& | 144 const WeakHandle<InvalidationStateTracker>& |
153 invalidation_state_tracker, | 145 invalidation_state_tracker, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 registrar_.GetAllRegisteredIds()))) { | 192 registrar_.GetAllRegisteredIds()))) { |
201 NOTREACHED(); | 193 NOTREACHED(); |
202 } | 194 } |
203 } | 195 } |
204 | 196 |
205 void NonBlockingInvalidator::UnregisterHandler(InvalidationHandler* handler) { | 197 void NonBlockingInvalidator::UnregisterHandler(InvalidationHandler* handler) { |
206 DCHECK(parent_task_runner_->BelongsToCurrentThread()); | 198 DCHECK(parent_task_runner_->BelongsToCurrentThread()); |
207 registrar_.UnregisterHandler(handler); | 199 registrar_.UnregisterHandler(handler); |
208 } | 200 } |
209 | 201 |
| 202 InvalidatorState NonBlockingInvalidator::GetInvalidatorState() const { |
| 203 DCHECK(parent_task_runner_->BelongsToCurrentThread()); |
| 204 return registrar_.GetInvalidatorState(); |
| 205 } |
| 206 |
210 void NonBlockingInvalidator::SetUniqueId(const std::string& unique_id) { | 207 void NonBlockingInvalidator::SetUniqueId(const std::string& unique_id) { |
211 DCHECK(parent_task_runner_->BelongsToCurrentThread()); | 208 DCHECK(parent_task_runner_->BelongsToCurrentThread()); |
212 if (!network_task_runner_->PostTask( | 209 if (!network_task_runner_->PostTask( |
213 FROM_HERE, | 210 FROM_HERE, |
214 base::Bind(&NonBlockingInvalidator::Core::SetUniqueId, | 211 base::Bind(&NonBlockingInvalidator::Core::SetUniqueId, |
215 core_.get(), unique_id))) { | 212 core_.get(), unique_id))) { |
216 NOTREACHED(); | 213 NOTREACHED(); |
217 } | 214 } |
218 } | 215 } |
219 | 216 |
(...skipping 12 matching lines...) Expand all Loading... |
232 const std::string& token) { | 229 const std::string& token) { |
233 DCHECK(parent_task_runner_->BelongsToCurrentThread()); | 230 DCHECK(parent_task_runner_->BelongsToCurrentThread()); |
234 if (!network_task_runner_->PostTask( | 231 if (!network_task_runner_->PostTask( |
235 FROM_HERE, | 232 FROM_HERE, |
236 base::Bind(&NonBlockingInvalidator::Core::UpdateCredentials, | 233 base::Bind(&NonBlockingInvalidator::Core::UpdateCredentials, |
237 core_.get(), email, token))) { | 234 core_.get(), email, token))) { |
238 NOTREACHED(); | 235 NOTREACHED(); |
239 } | 236 } |
240 } | 237 } |
241 | 238 |
242 void NonBlockingInvalidator::SendNotification( | 239 void NonBlockingInvalidator::SendInvalidation( |
243 const ObjectIdStateMap& id_state_map) { | 240 const ObjectIdStateMap& id_state_map) { |
244 DCHECK(parent_task_runner_->BelongsToCurrentThread()); | 241 DCHECK(parent_task_runner_->BelongsToCurrentThread()); |
245 // InvalidationClient doesn't implement SendNotification(), so no | 242 // InvalidationClient doesn't implement SendInvalidation(), so no |
246 // need to forward on the call. | 243 // need to forward on the call. |
247 } | 244 } |
248 | 245 |
249 void NonBlockingInvalidator::OnNotificationsEnabled() { | 246 void NonBlockingInvalidator::OnInvalidatorStateChange(InvalidatorState state) { |
250 DCHECK(parent_task_runner_->BelongsToCurrentThread()); | 247 DCHECK(parent_task_runner_->BelongsToCurrentThread()); |
251 registrar_.EmitOnNotificationsEnabled(); | 248 registrar_.UpdateInvalidatorState(state); |
252 } | 249 } |
253 | 250 |
254 void NonBlockingInvalidator::OnNotificationsDisabled( | 251 void NonBlockingInvalidator::OnIncomingInvalidation( |
255 NotificationsDisabledReason reason) { | |
256 DCHECK(parent_task_runner_->BelongsToCurrentThread()); | |
257 registrar_.EmitOnNotificationsDisabled(reason); | |
258 } | |
259 | |
260 void NonBlockingInvalidator::OnIncomingNotification( | |
261 const ObjectIdStateMap& id_state_map, | 252 const ObjectIdStateMap& id_state_map, |
262 IncomingNotificationSource source) { | 253 IncomingInvalidationSource source) { |
263 DCHECK(parent_task_runner_->BelongsToCurrentThread()); | 254 DCHECK(parent_task_runner_->BelongsToCurrentThread()); |
264 registrar_.DispatchInvalidationsToHandlers(id_state_map, source); | 255 registrar_.DispatchInvalidationsToHandlers(id_state_map, source); |
265 } | 256 } |
266 | 257 |
267 } // namespace syncer | 258 } // namespace syncer |
OLD | NEW |