Chromium Code Reviews| 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 2d11a0db5d88c9c74a351aa012844f0f90a40fd1..e9c7a4e772752ed3363b51f090cfa12bb0392e59 100644 |
| --- a/chrome/browser/invalidation/ticl_invalidation_service.cc |
| +++ b/chrome/browser/invalidation/ticl_invalidation_service.cc |
| @@ -56,12 +56,10 @@ namespace invalidation { |
| TiclInvalidationService::TiclInvalidationService( |
| SigninManagerBase* signin, |
| - TokenService* token_service, |
| - OAuth2TokenService* oauth2_token_service, |
| + ProfileOAuth2TokenService* oauth2_token_service, |
| Profile* profile) |
| : profile_(profile), |
| signin_manager_(signin), |
| - token_service_(token_service), |
| oauth2_token_service_(oauth2_token_service), |
| invalidator_registrar_(new syncer::InvalidatorRegistrar()), |
| request_access_token_backoff_(&kRequestAccessTokenBackoffPolicy) { |
| @@ -69,6 +67,7 @@ TiclInvalidationService::TiclInvalidationService( |
| TiclInvalidationService::~TiclInvalidationService() { |
| DCHECK(CalledOnValidThread()); |
| + oauth2_token_service_->RemoveObserver(this); |
| } |
| void TiclInvalidationService::Init() { |
| @@ -88,12 +87,7 @@ void TiclInvalidationService::Init() { |
| notification_registrar_.Add(this, |
| chrome::NOTIFICATION_GOOGLE_SIGNED_OUT, |
| content::Source<Profile>(profile_)); |
| - notification_registrar_.Add(this, |
| - chrome::NOTIFICATION_TOKEN_AVAILABLE, |
| - content::Source<TokenService>(token_service_)); |
| - notification_registrar_.Add(this, |
| - chrome::NOTIFICATION_TOKENS_CLEARED, |
| - content::Source<TokenService>(token_service_)); |
| + oauth2_token_service_->AddObserver(this); |
| } |
| void TiclInvalidationService::InitForTest(syncer::Invalidator* invalidator) { |
| @@ -171,29 +165,8 @@ void TiclInvalidationService::Observe( |
| const content::NotificationSource& source, |
| const content::NotificationDetails& details) { |
| DCHECK(CalledOnValidThread()); |
| - |
| - switch (type) { |
| - case chrome::NOTIFICATION_TOKEN_AVAILABLE: { |
| - if (!IsStarted() && IsReadyToStart()) { |
| - StartInvalidator(); |
| - } |
| - break; |
| - } |
| - case chrome::NOTIFICATION_TOKENS_CLEARED: { |
| - access_token_.clear(); |
| - if (IsStarted()) { |
| - UpdateInvalidatorCredentials(); |
| - } |
| - break; |
| - } |
| - case chrome::NOTIFICATION_GOOGLE_SIGNED_OUT: { |
| - Logout(); |
| - break; |
| - } |
| - default: { |
| - NOTREACHED(); |
| - } |
| - } |
| + DCHECK_EQ(type, chrome::NOTIFICATION_GOOGLE_SIGNED_OUT); |
| + Logout(); |
|
Andrew T Wilson (Slow)
2013/09/03 07:27:59
I'm fine with this, but I wonder if maybe we shoul
fgorski
2013/09/03 23:29:25
Drew, I don't know this class that well yet. I am
|
| } |
| void TiclInvalidationService::RequestAccessToken() { |
| @@ -208,8 +181,8 @@ void TiclInvalidationService::RequestAccessToken() { |
| // token again. |
| oauth2_token_service_->InvalidateToken(oauth2_scopes, access_token_); |
| access_token_.clear(); |
| - access_token_request_ = |
| - oauth2_token_service_->StartRequest(oauth2_scopes, this); |
| + access_token_request_ = oauth2_token_service_->StartRequest( |
| + oauth2_token_service_->GetPrimaryAccountId(), oauth2_scopes, this); |
| } |
| void TiclInvalidationService::OnGetTokenSuccess( |
| @@ -275,6 +248,25 @@ void TiclInvalidationService::OnGetTokenFailure( |
| } |
| } |
| +void TiclInvalidationService::OnRefreshTokenAvailable( |
| + const std::string& account_id) { |
| + if (oauth2_token_service_->GetPrimaryAccountId() == account_id) { |
| + if (!IsStarted() && IsReadyToStart()) { |
| + StartInvalidator(); |
| + } |
| + } |
| +} |
| + |
| +void TiclInvalidationService::OnRefreshTokenRevoked( |
| + const std::string& account_id) { |
| + if (oauth2_token_service_->GetPrimaryAccountId() == account_id) { |
| + access_token_.clear(); |
| + if (IsStarted()) { |
| + UpdateInvalidatorCredentials(); |
|
Andrew T Wilson (Slow)
2013/09/03 07:27:59
Why do we not Logout() here?
fgorski
2013/09/03 23:29:25
As per comment above. I am trying to recreate a lo
|
| + } |
| + } |
| +} |
| + |
| void TiclInvalidationService::OnInvalidatorStateChange( |
| syncer::InvalidatorState state) { |
| if (state == syncer::INVALIDATION_CREDENTIALS_REJECTED) { |
| @@ -327,7 +319,8 @@ bool TiclInvalidationService::IsReadyToStart() { |
| return false; |
| } |
| - if (!oauth2_token_service_->RefreshTokenIsAvailable()) { |
| + if (!oauth2_token_service_->RefreshTokenIsAvailable( |
| + oauth2_token_service_->GetPrimaryAccountId())) { |
| DVLOG(2) |
| << "Not starting TiclInvalidationServce: Waiting for refresh token."; |
| return false; |