| 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 "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "chrome/browser/invalidation/gcm_invalidation_bridge.h" | 10 #include "chrome/browser/invalidation/gcm_invalidation_bridge.h" |
| 11 #include "chrome/browser/invalidation/invalidation_auth_provider.h" | 11 #include "chrome/browser/invalidation/invalidation_auth_provider.h" |
| 12 #include "chrome/browser/invalidation/invalidation_logger.h" | 12 #include "chrome/browser/invalidation/invalidation_logger.h" |
| 13 #include "chrome/browser/invalidation/invalidation_service_util.h" | 13 #include "chrome/browser/invalidation/invalidation_service_util.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/services/gcm/gcm_profile_service.h" | 15 #include "chrome/browser/services/gcm/gcm_profile_service.h" |
| 16 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" | 16 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" |
| 17 #include "chrome/common/chrome_content_client.h" | 17 #include "chrome/common/chrome_content_client.h" |
| 18 #include "chrome/common/chrome_switches.h" |
| 18 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
| 19 #include "components/signin/core/profile_oauth2_token_service.h" | 20 #include "components/signin/core/profile_oauth2_token_service.h" |
| 20 #include "google_apis/gaia/gaia_constants.h" | 21 #include "google_apis/gaia/gaia_constants.h" |
| 21 #include "sync/notifier/gcm_network_channel_delegate.h" | 22 #include "sync/notifier/gcm_network_channel_delegate.h" |
| 22 #include "sync/notifier/invalidation_util.h" | 23 #include "sync/notifier/invalidation_util.h" |
| 23 #include "sync/notifier/invalidator.h" | 24 #include "sync/notifier/invalidator.h" |
| 24 #include "sync/notifier/invalidator_state.h" | 25 #include "sync/notifier/invalidator_state.h" |
| 25 #include "sync/notifier/non_blocking_invalidator.h" | 26 #include "sync/notifier/non_blocking_invalidator.h" |
| 26 #include "sync/notifier/object_id_invalidation_map.h" | 27 #include "sync/notifier/object_id_invalidation_map.h" |
| 27 | 28 |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 invalidator_->RegisterHandler(this); | 424 invalidator_->RegisterHandler(this); |
| 424 invalidator_->UpdateRegisteredIds( | 425 invalidator_->UpdateRegisteredIds( |
| 425 this, | 426 this, |
| 426 invalidator_registrar_->GetAllRegisteredIds()); | 427 invalidator_registrar_->GetAllRegisteredIds()); |
| 427 } | 428 } |
| 428 | 429 |
| 429 void TiclInvalidationService::UpdateInvalidationNetworkChannel() { | 430 void TiclInvalidationService::UpdateInvalidationNetworkChannel() { |
| 430 InvalidationNetworkChannel network_channel_type = PUSH_CLIENT_CHANNEL; | 431 InvalidationNetworkChannel network_channel_type = PUSH_CLIENT_CHANNEL; |
| 431 // For now don't use GCM on iOS. | 432 // For now don't use GCM on iOS. |
| 432 #if !defined(OS_IOS) | 433 #if !defined(OS_IOS) |
| 433 if (profile_->GetPrefs()->GetBoolean( | 434 if (gcm::GCMProfileService::GetGCMEnabledState(profile_) == |
| 434 prefs::kInvalidationServiceUseGCMChannel) && | 435 gcm::GCMProfileService::ALWAYS_ENABLED && |
| 435 gcm::GCMProfileService::GetGCMEnabledState(profile_) == | 436 (profile_->GetPrefs()->GetBoolean( |
| 436 gcm::GCMProfileService::ALWAYS_ENABLED) { | 437 prefs::kInvalidationServiceUseGCMChannel) || |
| 438 CommandLine::ForCurrentProcess()->HasSwitch( |
| 439 switches::kInvalidationUseGCMChannel))) { |
| 437 network_channel_type = GCM_NETWORK_CHANNEL; | 440 network_channel_type = GCM_NETWORK_CHANNEL; |
| 438 } | 441 } |
| 439 #endif | 442 #endif |
| 440 if (network_channel_type_ == network_channel_type) | 443 if (network_channel_type_ == network_channel_type) |
| 441 return; | 444 return; |
| 442 network_channel_type_ = network_channel_type; | 445 network_channel_type_ = network_channel_type; |
| 443 if (IsStarted()) { | 446 if (IsStarted()) { |
| 444 StopInvalidator(); | 447 StopInvalidator(); |
| 445 StartInvalidator(network_channel_type_); | 448 StartInvalidator(network_channel_type_); |
| 446 } | 449 } |
| 447 } | 450 } |
| 448 | 451 |
| 449 void TiclInvalidationService::UpdateInvalidatorCredentials() { | 452 void TiclInvalidationService::UpdateInvalidatorCredentials() { |
| 450 std::string email = auth_provider_->GetAccountId(); | 453 std::string email = auth_provider_->GetAccountId(); |
| 451 | 454 |
| 452 DCHECK(!email.empty()) << "Expected user to be signed in."; | 455 DCHECK(!email.empty()) << "Expected user to be signed in."; |
| 453 | 456 |
| 454 DVLOG(2) << "UpdateCredentials: " << email; | 457 DVLOG(2) << "UpdateCredentials: " << email; |
| 455 invalidator_->UpdateCredentials(email, access_token_); | 458 invalidator_->UpdateCredentials(email, access_token_); |
| 456 } | 459 } |
| 457 | 460 |
| 458 void TiclInvalidationService::StopInvalidator() { | 461 void TiclInvalidationService::StopInvalidator() { |
| 459 DCHECK(invalidator_); | 462 DCHECK(invalidator_); |
| 460 gcm_invalidation_bridge_.reset(); | 463 gcm_invalidation_bridge_.reset(); |
| 461 invalidator_->UnregisterHandler(this); | 464 invalidator_->UnregisterHandler(this); |
| 462 invalidator_.reset(); | 465 invalidator_.reset(); |
| 463 } | 466 } |
| 464 | 467 |
| 465 } // namespace invalidation | 468 } // namespace invalidation |
| OLD | NEW |