| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "chrome/browser/invalidation/ticl_invalidation_service.h" | 5 #include "chrome/browser/invalidation/ticl_invalidation_service.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "chrome/browser/invalidation/gcm_invalidation_bridge.h" | 9 #include "chrome/browser/invalidation/gcm_invalidation_bridge.h" |
| 10 #include "chrome/common/chrome_content_client.h" | 10 #include "chrome/common/chrome_content_client.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 settings_provider_(settings_provider.Pass()), | 62 settings_provider_(settings_provider.Pass()), |
| 63 invalidator_registrar_(new syncer::InvalidatorRegistrar()), | 63 invalidator_registrar_(new syncer::InvalidatorRegistrar()), |
| 64 request_access_token_backoff_(&kRequestAccessTokenBackoffPolicy), | 64 request_access_token_backoff_(&kRequestAccessTokenBackoffPolicy), |
| 65 network_channel_type_(PUSH_CLIENT_CHANNEL), | 65 network_channel_type_(PUSH_CLIENT_CHANNEL), |
| 66 gcm_driver_(gcm_driver), | 66 gcm_driver_(gcm_driver), |
| 67 request_context_(request_context), | 67 request_context_(request_context), |
| 68 logger_() {} | 68 logger_() {} |
| 69 | 69 |
| 70 TiclInvalidationService::~TiclInvalidationService() { | 70 TiclInvalidationService::~TiclInvalidationService() { |
| 71 DCHECK(CalledOnValidThread()); | 71 DCHECK(CalledOnValidThread()); |
| 72 settings_provider_->RemoveObserver(this); |
| 73 identity_provider_->RemoveActiveAccountRefreshTokenObserver(this); |
| 74 identity_provider_->RemoveObserver(this); |
| 75 if (IsStarted()) { |
| 76 StopInvalidator(); |
| 77 } |
| 72 } | 78 } |
| 73 | 79 |
| 74 void TiclInvalidationService::Init( | 80 void TiclInvalidationService::Init( |
| 75 scoped_ptr<syncer::InvalidationStateTracker> invalidation_state_tracker) { | 81 scoped_ptr<syncer::InvalidationStateTracker> invalidation_state_tracker) { |
| 76 DCHECK(CalledOnValidThread()); | 82 DCHECK(CalledOnValidThread()); |
| 77 invalidation_state_tracker_ = invalidation_state_tracker.Pass(); | 83 invalidation_state_tracker_ = invalidation_state_tracker.Pass(); |
| 78 | 84 |
| 79 if (invalidation_state_tracker_->GetInvalidatorClientId().empty()) { | 85 if (invalidation_state_tracker_->GetInvalidatorClientId().empty()) { |
| 80 invalidation_state_tracker_->ClearAndSetNewClientId( | 86 invalidation_state_tracker_->ClearAndSetNewClientId( |
| 81 GenerateInvalidatorClientId()); | 87 GenerateInvalidatorClientId()); |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 | 300 |
| 295 void TiclInvalidationService::OnIncomingInvalidation( | 301 void TiclInvalidationService::OnIncomingInvalidation( |
| 296 const syncer::ObjectIdInvalidationMap& invalidation_map) { | 302 const syncer::ObjectIdInvalidationMap& invalidation_map) { |
| 297 invalidator_registrar_->DispatchInvalidationsToHandlers(invalidation_map); | 303 invalidator_registrar_->DispatchInvalidationsToHandlers(invalidation_map); |
| 298 | 304 |
| 299 logger_.OnInvalidation(invalidation_map); | 305 logger_.OnInvalidation(invalidation_map); |
| 300 } | 306 } |
| 301 | 307 |
| 302 std::string TiclInvalidationService::GetOwnerName() const { return "TICL"; } | 308 std::string TiclInvalidationService::GetOwnerName() const { return "TICL"; } |
| 303 | 309 |
| 304 void TiclInvalidationService::Shutdown() { | |
| 305 DCHECK(CalledOnValidThread()); | |
| 306 settings_provider_->RemoveObserver(this); | |
| 307 identity_provider_->RemoveActiveAccountRefreshTokenObserver(this); | |
| 308 identity_provider_->RemoveObserver(this); | |
| 309 if (IsStarted()) { | |
| 310 StopInvalidator(); | |
| 311 } | |
| 312 invalidation_state_tracker_.reset(); | |
| 313 invalidator_registrar_.reset(); | |
| 314 } | |
| 315 | |
| 316 bool TiclInvalidationService::IsReadyToStart() { | 310 bool TiclInvalidationService::IsReadyToStart() { |
| 317 if (identity_provider_->GetActiveAccountId().empty()) { | 311 if (identity_provider_->GetActiveAccountId().empty()) { |
| 318 DVLOG(2) << "Not starting TiclInvalidationService: User is not signed in."; | 312 DVLOG(2) << "Not starting TiclInvalidationService: User is not signed in."; |
| 319 return false; | 313 return false; |
| 320 } | 314 } |
| 321 | 315 |
| 322 OAuth2TokenService* token_service = identity_provider_->GetTokenService(); | 316 OAuth2TokenService* token_service = identity_provider_->GetTokenService(); |
| 323 if (!token_service) { | 317 if (!token_service) { |
| 324 DVLOG(2) | 318 DVLOG(2) |
| 325 << "Not starting TiclInvalidationService: " | 319 << "Not starting TiclInvalidationService: " |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 } | 426 } |
| 433 | 427 |
| 434 void TiclInvalidationService::StopInvalidator() { | 428 void TiclInvalidationService::StopInvalidator() { |
| 435 DCHECK(invalidator_); | 429 DCHECK(invalidator_); |
| 436 gcm_invalidation_bridge_.reset(); | 430 gcm_invalidation_bridge_.reset(); |
| 437 invalidator_->UnregisterHandler(this); | 431 invalidator_->UnregisterHandler(this); |
| 438 invalidator_.reset(); | 432 invalidator_.reset(); |
| 439 } | 433 } |
| 440 | 434 |
| 441 } // namespace invalidation | 435 } // namespace invalidation |
| OLD | NEW |