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

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

Issue 10916131: [Invalidations] Add GetInvalidatorState() to Invalidator{,Frontend} (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix android Created 8 years, 3 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/sync_invalidation_listener.h" 5 #include "sync/notifier/sync_invalidation_listener.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 16 matching lines...) Expand all
27 namespace syncer { 27 namespace syncer {
28 28
29 SyncInvalidationListener::Delegate::~Delegate() {} 29 SyncInvalidationListener::Delegate::~Delegate() {}
30 30
31 SyncInvalidationListener::SyncInvalidationListener( 31 SyncInvalidationListener::SyncInvalidationListener(
32 scoped_ptr<notifier::PushClient> push_client) 32 scoped_ptr<notifier::PushClient> push_client)
33 : push_client_(push_client.get()), 33 : push_client_(push_client.get()),
34 sync_system_resources_(push_client.Pass(), 34 sync_system_resources_(push_client.Pass(),
35 ALLOW_THIS_IN_INITIALIZER_LIST(this)), 35 ALLOW_THIS_IN_INITIALIZER_LIST(this)),
36 delegate_(NULL), 36 delegate_(NULL),
37 ticl_state_(DEFAULT_NOTIFICATION_ERROR), 37 ticl_state_(DEFAULT_INVALIDATION_ERROR),
38 push_client_state_(DEFAULT_NOTIFICATION_ERROR) { 38 push_client_state_(DEFAULT_INVALIDATION_ERROR) {
39 DCHECK(CalledOnValidThread()); 39 DCHECK(CalledOnValidThread());
40 push_client_->AddObserver(this); 40 push_client_->AddObserver(this);
41 } 41 }
42 42
43 SyncInvalidationListener::~SyncInvalidationListener() { 43 SyncInvalidationListener::~SyncInvalidationListener() {
44 DCHECK(CalledOnValidThread()); 44 DCHECK(CalledOnValidThread());
45 push_client_->RemoveObserver(this); 45 push_client_->RemoveObserver(this);
46 Stop(); 46 Stop();
47 DCHECK(!delegate_); 47 DCHECK(!delegate_);
48 } 48 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 98
99 void SyncInvalidationListener::UpdateCredentials( 99 void SyncInvalidationListener::UpdateCredentials(
100 const std::string& email, const std::string& token) { 100 const std::string& email, const std::string& token) {
101 DCHECK(CalledOnValidThread()); 101 DCHECK(CalledOnValidThread());
102 sync_system_resources_.network()->UpdateCredentials(email, token); 102 sync_system_resources_.network()->UpdateCredentials(email, token);
103 } 103 }
104 104
105 void SyncInvalidationListener::UpdateRegisteredIds(const ObjectIdSet& ids) { 105 void SyncInvalidationListener::UpdateRegisteredIds(const ObjectIdSet& ids) {
106 DCHECK(CalledOnValidThread()); 106 DCHECK(CalledOnValidThread());
107 registered_ids_ = ids; 107 registered_ids_ = ids;
108 // |ticl_state_| can go to NO_NOTIFICATION_ERROR even without a 108 // |ticl_state_| can go to INVALIDATIONS_ENABLED even without a
109 // working XMPP connection (as observed by us), so check it instead 109 // working XMPP connection (as observed by us), so check it instead
110 // of GetState() (see http://crbug.com/139424). 110 // of GetState() (see http://crbug.com/139424).
111 if (ticl_state_ == NO_NOTIFICATION_ERROR && registration_manager_.get()) { 111 if (ticl_state_ == INVALIDATIONS_ENABLED && registration_manager_.get()) {
112 DoRegistrationUpdate(); 112 DoRegistrationUpdate();
113 } 113 }
114 } 114 }
115 115
116 void SyncInvalidationListener::Ready( 116 void SyncInvalidationListener::Ready(
117 invalidation::InvalidationClient* client) { 117 invalidation::InvalidationClient* client) {
118 DCHECK(CalledOnValidThread()); 118 DCHECK(CalledOnValidThread());
119 DCHECK_EQ(client, invalidation_client_.get()); 119 DCHECK_EQ(client, invalidation_client_.get());
120 ticl_state_ = NO_NOTIFICATION_ERROR; 120 ticl_state_ = INVALIDATIONS_ENABLED;
121 EmitStateChange(); 121 EmitStateChange();
122 DoRegistrationUpdate(); 122 DoRegistrationUpdate();
123 } 123 }
124 124
125 void SyncInvalidationListener::Invalidate( 125 void SyncInvalidationListener::Invalidate(
126 invalidation::InvalidationClient* client, 126 invalidation::InvalidationClient* client,
127 const invalidation::Invalidation& invalidation, 127 const invalidation::Invalidation& invalidation,
128 const invalidation::AckHandle& ack_handle) { 128 const invalidation::AckHandle& ack_handle) {
129 DCHECK(CalledOnValidThread()); 129 DCHECK(CalledOnValidThread());
130 DCHECK_EQ(client, invalidation_client_.get()); 130 DCHECK_EQ(client, invalidation_client_.get());
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 267
268 void SyncInvalidationListener::InformError( 268 void SyncInvalidationListener::InformError(
269 invalidation::InvalidationClient* client, 269 invalidation::InvalidationClient* client,
270 const invalidation::ErrorInfo& error_info) { 270 const invalidation::ErrorInfo& error_info) {
271 DCHECK(CalledOnValidThread()); 271 DCHECK(CalledOnValidThread());
272 DCHECK_EQ(client, invalidation_client_.get()); 272 DCHECK_EQ(client, invalidation_client_.get());
273 LOG(ERROR) << "Ticl error " << error_info.error_reason() << ": " 273 LOG(ERROR) << "Ticl error " << error_info.error_reason() << ": "
274 << error_info.error_message() 274 << error_info.error_message()
275 << " (transient = " << error_info.is_transient() << ")"; 275 << " (transient = " << error_info.is_transient() << ")";
276 if (error_info.error_reason() == invalidation::ErrorReason::AUTH_FAILURE) { 276 if (error_info.error_reason() == invalidation::ErrorReason::AUTH_FAILURE) {
277 ticl_state_ = NOTIFICATION_CREDENTIALS_REJECTED; 277 ticl_state_ = INVALIDATION_CREDENTIALS_REJECTED;
278 } else { 278 } else {
279 ticl_state_ = TRANSIENT_NOTIFICATION_ERROR; 279 ticl_state_ = TRANSIENT_INVALIDATION_ERROR;
280 } 280 }
281 EmitStateChange(); 281 EmitStateChange();
282 } 282 }
283 283
284 void SyncInvalidationListener::WriteState(const std::string& state) { 284 void SyncInvalidationListener::WriteState(const std::string& state) {
285 DCHECK(CalledOnValidThread()); 285 DCHECK(CalledOnValidThread());
286 DVLOG(1) << "WriteState"; 286 DVLOG(1) << "WriteState";
287 invalidation_state_tracker_.Call( 287 invalidation_state_tracker_.Call(
288 FROM_HERE, &InvalidationStateTracker::SetInvalidationState, state); 288 FROM_HERE, &InvalidationStateTracker::SetInvalidationState, state);
289 } 289 }
(...skipping 19 matching lines...) Expand all
309 309
310 registration_manager_.reset(); 310 registration_manager_.reset();
311 sync_system_resources_.Stop(); 311 sync_system_resources_.Stop();
312 invalidation_client_->Stop(); 312 invalidation_client_->Stop();
313 313
314 invalidation_client_.reset(); 314 invalidation_client_.reset();
315 delegate_ = NULL; 315 delegate_ = NULL;
316 316
317 invalidation_state_tracker_.Reset(); 317 invalidation_state_tracker_.Reset();
318 max_invalidation_versions_.clear(); 318 max_invalidation_versions_.clear();
319 ticl_state_ = DEFAULT_NOTIFICATION_ERROR; 319 ticl_state_ = DEFAULT_INVALIDATION_ERROR;
320 push_client_state_ = DEFAULT_NOTIFICATION_ERROR; 320 push_client_state_ = DEFAULT_INVALIDATION_ERROR;
321 } 321 }
322 322
323 NotificationsDisabledReason SyncInvalidationListener::GetState() const { 323 InvalidatorState SyncInvalidationListener::GetState() const {
324 DCHECK(CalledOnValidThread()); 324 DCHECK(CalledOnValidThread());
325 if (ticl_state_ == NOTIFICATION_CREDENTIALS_REJECTED || 325 if (ticl_state_ == INVALIDATION_CREDENTIALS_REJECTED ||
326 push_client_state_ == NOTIFICATION_CREDENTIALS_REJECTED) { 326 push_client_state_ == INVALIDATION_CREDENTIALS_REJECTED) {
327 // If either the ticl or the push client rejected our credentials, 327 // If either the ticl or the push client rejected our credentials,
328 // return NOTIFICATION_CREDENTIALS_REJECTED. 328 // return INVALIDATION_CREDENTIALS_REJECTED.
329 return NOTIFICATION_CREDENTIALS_REJECTED; 329 return INVALIDATION_CREDENTIALS_REJECTED;
330 } 330 }
331 if (ticl_state_ == NO_NOTIFICATION_ERROR && 331 if (ticl_state_ == INVALIDATIONS_ENABLED &&
332 push_client_state_ == NO_NOTIFICATION_ERROR) { 332 push_client_state_ == INVALIDATIONS_ENABLED) {
333 // If the ticl is ready and the push client notifications are 333 // If the ticl is ready and the push client notifications are
334 // enabled, return NO_NOTIFICATION_ERROR. 334 // enabled, return INVALIDATIONS_ENABLED.
335 return NO_NOTIFICATION_ERROR; 335 return INVALIDATIONS_ENABLED;
336 } 336 }
337 // Otherwise, we have a transient error. 337 // Otherwise, we have a transient error.
338 return TRANSIENT_NOTIFICATION_ERROR; 338 return TRANSIENT_INVALIDATION_ERROR;
339 } 339 }
340 340
341 void SyncInvalidationListener::EmitStateChange() { 341 void SyncInvalidationListener::EmitStateChange() {
342 DCHECK(CalledOnValidThread()); 342 DCHECK(CalledOnValidThread());
343 if (GetState() == NO_NOTIFICATION_ERROR) { 343 delegate_->OnInvalidatorStateChange(GetState());
344 delegate_->OnNotificationsEnabled();
345 } else {
346 delegate_->OnNotificationsDisabled(GetState());
347 }
348 } 344 }
349 345
350 void SyncInvalidationListener::OnNotificationsEnabled() { 346 void SyncInvalidationListener::OnNotificationsEnabled() {
351 DCHECK(CalledOnValidThread()); 347 DCHECK(CalledOnValidThread());
352 push_client_state_ = NO_NOTIFICATION_ERROR; 348 push_client_state_ = INVALIDATIONS_ENABLED;
353 EmitStateChange(); 349 EmitStateChange();
354 } 350 }
355 351
356 void SyncInvalidationListener::OnNotificationsDisabled( 352 void SyncInvalidationListener::OnNotificationsDisabled(
357 notifier::NotificationsDisabledReason reason) { 353 notifier::NotificationsDisabledReason reason) {
358 DCHECK(CalledOnValidThread()); 354 DCHECK(CalledOnValidThread());
359 push_client_state_ = FromNotifierReason(reason); 355 push_client_state_ = FromNotifierReason(reason);
360 EmitStateChange(); 356 EmitStateChange();
361 } 357 }
362 358
363 void SyncInvalidationListener::OnIncomingNotification( 359 void SyncInvalidationListener::OnIncomingNotification(
364 const notifier::Notification& notification) { 360 const notifier::Notification& notification) {
365 DCHECK(CalledOnValidThread()); 361 DCHECK(CalledOnValidThread());
366 // Do nothing, since this is already handled by |invalidation_client_|. 362 // Do nothing, since this is already handled by |invalidation_client_|.
367 } 363 }
368 364
369 } // namespace syncer 365 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/notifier/sync_invalidation_listener.h ('k') | sync/notifier/sync_invalidation_listener_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698