| Index: chrome/browser/invalidation/ticl_invalidation_service.cc
|
| diff --git a/chrome/browser/invalidation/ticl_invalidation_service.cc b/chrome/browser/invalidation/ticl_invalidation_service.cc
|
| index 55f901278e99470d084861a10145ebae89083af9..c16b81ac8d42d00e9dfdf4ad56a39ec1148829e9 100644
|
| --- a/chrome/browser/invalidation/ticl_invalidation_service.cc
|
| +++ b/chrome/browser/invalidation/ticl_invalidation_service.cc
|
| @@ -7,13 +7,11 @@
|
| #include "base/command_line.h"
|
| #include "base/metrics/histogram.h"
|
| #include "chrome/browser/invalidation/gcm_invalidation_bridge.h"
|
| +#include "chrome/browser/invalidation/invalidation_auth_provider.h"
|
| #include "chrome/browser/invalidation/invalidation_logger.h"
|
| #include "chrome/browser/invalidation/invalidation_service_util.h"
|
| #include "chrome/browser/profiles/profile.h"
|
| -#include "chrome/browser/signin/about_signin_internals.h"
|
| -#include "chrome/browser/signin/about_signin_internals_factory.h"
|
| -#include "chrome/browser/signin/profile_oauth2_token_service.h"
|
| -#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
|
| +#include "chrome/browser/services/gcm/gcm_profile_service_factory.h"
|
| #include "google_apis/gaia/gaia_constants.h"
|
| #include "sync/notifier/gcm_network_channel_delegate.h"
|
| #include "sync/notifier/invalidation_util.h"
|
| @@ -57,13 +55,11 @@ static const net::BackoffEntry::Policy kRequestAccessTokenBackoffPolicy = {
|
| namespace invalidation {
|
|
|
| TiclInvalidationService::TiclInvalidationService(
|
| - SigninManagerBase* signin,
|
| - ProfileOAuth2TokenService* oauth2_token_service,
|
| + scoped_ptr<InvalidationAuthProvider> auth_provider,
|
| Profile* profile)
|
| : OAuth2TokenService::Consumer("ticl_invalidation"),
|
| profile_(profile),
|
| - signin_manager_(signin),
|
| - oauth2_token_service_(oauth2_token_service),
|
| + auth_provider_(auth_provider.Pass()),
|
| invalidator_registrar_(new syncer::InvalidatorRegistrar()),
|
| request_access_token_backoff_(&kRequestAccessTokenBackoffPolicy),
|
| logger_() {}
|
| @@ -86,11 +82,8 @@ void TiclInvalidationService::Init() {
|
| StartInvalidator(PUSH_CLIENT_CHANNEL);
|
| }
|
|
|
| - SigninManagerBase* signin_manager =
|
| - SigninManagerFactory::GetForProfile(profile_);
|
| - signin_manager->AddObserver(this);
|
| -
|
| - oauth2_token_service_->AddObserver(this);
|
| + auth_provider_->AddObserver(this);
|
| + auth_provider_->GetTokenService()->AddObserver(this);
|
| }
|
|
|
| void TiclInvalidationService::InitForTest(syncer::Invalidator* invalidator) {
|
| @@ -161,9 +154,9 @@ InvalidationLogger* TiclInvalidationService::GetInvalidationLogger() {
|
| return &logger_;
|
| }
|
|
|
| -void TiclInvalidationService::GoogleSignedOut(const std::string& username) {
|
| - DCHECK(CalledOnValidThread());
|
| - Logout();
|
| +InvalidationAuthProvider*
|
| +TiclInvalidationService::GetInvalidationAuthProvider() {
|
| + return auth_provider_.get();
|
| }
|
|
|
| void TiclInvalidationService::RequestAccessToken() {
|
| @@ -176,14 +169,12 @@ void TiclInvalidationService::RequestAccessToken() {
|
| oauth2_scopes.insert(kOAuth2Scopes[i]);
|
| // Invalidate previous token, otherwise token service will return the same
|
| // token again.
|
| - const std::string& account_id = signin_manager_->GetAuthenticatedAccountId();
|
| - oauth2_token_service_->InvalidateToken(account_id,
|
| - oauth2_scopes,
|
| - access_token_);
|
| + const std::string& account_id = auth_provider_->GetAccountId();
|
| + OAuth2TokenService* token_service = auth_provider_->GetTokenService();
|
| + token_service->InvalidateToken(account_id, oauth2_scopes, access_token_);
|
| access_token_.clear();
|
| - access_token_request_ = oauth2_token_service_->StartRequest(account_id,
|
| - oauth2_scopes,
|
| - this);
|
| + access_token_request_ =
|
| + token_service->StartRequest(account_id, oauth2_scopes, this);
|
| }
|
|
|
| void TiclInvalidationService::OnGetTokenSuccess(
|
| @@ -234,7 +225,7 @@ void TiclInvalidationService::OnGetTokenFailure(
|
|
|
| void TiclInvalidationService::OnRefreshTokenAvailable(
|
| const std::string& account_id) {
|
| - if (signin_manager_->GetAuthenticatedAccountId() == account_id) {
|
| + if (auth_provider_->GetAccountId() == account_id) {
|
| if (!IsStarted() && IsReadyToStart()) {
|
| StartInvalidator(PUSH_CLIENT_CHANNEL);
|
| }
|
| @@ -243,7 +234,7 @@ void TiclInvalidationService::OnRefreshTokenAvailable(
|
|
|
| void TiclInvalidationService::OnRefreshTokenRevoked(
|
| const std::string& account_id) {
|
| - if (signin_manager_->GetAuthenticatedAccountId() == account_id) {
|
| + if (auth_provider_->GetAccountId() == account_id) {
|
| access_token_.clear();
|
| if (IsStarted()) {
|
| UpdateInvalidatorCredentials();
|
| @@ -251,6 +242,21 @@ void TiclInvalidationService::OnRefreshTokenRevoked(
|
| }
|
| }
|
|
|
| +void TiclInvalidationService::OnInvalidationAuthLogout() {
|
| + access_token_request_.reset();
|
| + request_access_token_retry_timer_.Stop();
|
| +
|
| + if (IsStarted()) {
|
| + StopInvalidator();
|
| + }
|
| +
|
| + // This service always expects to have a valid invalidator storage.
|
| + // So we must not only clear the old one, but also start a new one.
|
| + invalidator_storage_->Clear();
|
| + invalidator_storage_.reset(new InvalidatorStorage(profile_->GetPrefs()));
|
| + invalidator_storage_->SetInvalidatorClientId(GenerateInvalidatorClientId());
|
| +}
|
| +
|
| void TiclInvalidationService::OnInvalidatorStateChange(
|
| syncer::InvalidatorState state) {
|
| if (state == syncer::INVALIDATION_CREDENTIALS_REJECTED) {
|
| @@ -284,10 +290,8 @@ std::string TiclInvalidationService::GetOwnerName() const { return "TICL"; }
|
|
|
| void TiclInvalidationService::Shutdown() {
|
| DCHECK(CalledOnValidThread());
|
| - SigninManagerBase* signin_manager =
|
| - SigninManagerFactory::GetForProfile(profile_);
|
| - signin_manager->RemoveObserver(this);
|
| - oauth2_token_service_->RemoveObserver(this);
|
| + auth_provider_->GetTokenService()->RemoveObserver(this);
|
| + auth_provider_->RemoveObserver(this);
|
| if (IsStarted()) {
|
| StopInvalidator();
|
| }
|
| @@ -301,20 +305,20 @@ bool TiclInvalidationService::IsReadyToStart() {
|
| return false;
|
| }
|
|
|
| - if (signin_manager_->GetAuthenticatedUsername().empty()) {
|
| + if (auth_provider_->GetAccountId().empty()) {
|
| DVLOG(2) << "Not starting TiclInvalidationService: User is not signed in.";
|
| return false;
|
| }
|
|
|
| - if (!oauth2_token_service_) {
|
| + OAuth2TokenService* token_service = auth_provider_->GetTokenService();
|
| + if (!token_service) {
|
| DVLOG(2)
|
| << "Not starting TiclInvalidationService: "
|
| << "OAuth2TokenService unavailable.";
|
| return false;
|
| }
|
|
|
| - if (!oauth2_token_service_->RefreshTokenIsAvailable(
|
| - signin_manager_->GetAuthenticatedAccountId())) {
|
| + if (!token_service->RefreshTokenIsAvailable(auth_provider_->GetAccountId())) {
|
| DVLOG(2)
|
| << "Not starting TiclInvalidationServce: Waiting for refresh token.";
|
| return false;
|
| @@ -356,7 +360,10 @@ void TiclInvalidationService::StartInvalidator(
|
| break;
|
| }
|
| case GCM_NETWORK_CHANNEL: {
|
| - gcm_invalidation_bridge_.reset(new GCMInvalidationBridge(profile_));
|
| + gcm::GCMProfileService* gcm_profile_service =
|
| + gcm::GCMProfileServiceFactory::GetForProfile(profile_);
|
| + gcm_invalidation_bridge_.reset(
|
| + new GCMInvalidationBridge(gcm_profile_service, auth_provider_.get()));
|
| network_channel_creator =
|
| syncer::NonBlockingInvalidator::MakeGCMNetworkChannelCreator(
|
| profile_->GetRequestContext(),
|
| @@ -387,7 +394,7 @@ void TiclInvalidationService::StartInvalidator(
|
| }
|
|
|
| void TiclInvalidationService::UpdateInvalidatorCredentials() {
|
| - std::string email = signin_manager_->GetAuthenticatedUsername();
|
| + std::string email = auth_provider_->GetAccountId();
|
|
|
| DCHECK(!email.empty()) << "Expected user to be signed in.";
|
|
|
| @@ -402,19 +409,4 @@ void TiclInvalidationService::StopInvalidator() {
|
| invalidator_.reset();
|
| }
|
|
|
| -void TiclInvalidationService::Logout() {
|
| - access_token_request_.reset();
|
| - request_access_token_retry_timer_.Stop();
|
| -
|
| - if (IsStarted()) {
|
| - StopInvalidator();
|
| - }
|
| -
|
| - // This service always expects to have a valid invalidator storage.
|
| - // So we must not only clear the old one, but also start a new one.
|
| - invalidator_storage_->Clear();
|
| - invalidator_storage_.reset(new InvalidatorStorage(profile_->GetPrefs()));
|
| - invalidator_storage_->SetInvalidatorClientId(GenerateInvalidatorClientId());
|
| -}
|
| -
|
| } // namespace invalidation
|
|
|