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

Unified Diff: chrome/browser/invalidation/ticl_invalidation_service.cc

Issue 23382008: Making OAuth2TokenService multi-login aware, updating callers, minor fixes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebasing to include the update to ProfileSyncService: r224220 Created 7 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 side-by-side diff with in-line comments
Download patch
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..b80a2d80480a9793564411aeff598d1415f556e7 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) {
@@ -88,12 +86,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 +164,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();
}
void TiclInvalidationService::RequestAccessToken() {
@@ -206,10 +178,14 @@ void TiclInvalidationService::RequestAccessToken() {
oauth2_scopes.insert(kOAuth2Scopes[i]);
// Invalidate previous token, otherwise token service will return the same
// token again.
- oauth2_token_service_->InvalidateToken(oauth2_scopes, access_token_);
+ const std::string& account_id = oauth2_token_service_->GetPrimaryAccountId();
+ oauth2_token_service_->InvalidateToken(account_id,
+ oauth2_scopes,
+ access_token_);
access_token_.clear();
- access_token_request_ =
- oauth2_token_service_->StartRequest(oauth2_scopes, this);
+ access_token_request_ = oauth2_token_service_->StartRequest(account_id,
+ oauth2_scopes,
+ this);
}
void TiclInvalidationService::OnGetTokenSuccess(
@@ -275,6 +251,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();
+ }
+ }
+}
+
void TiclInvalidationService::OnInvalidatorStateChange(
syncer::InvalidatorState state) {
if (state == syncer::INVALIDATION_CREDENTIALS_REJECTED) {
@@ -303,6 +298,7 @@ void TiclInvalidationService::OnIncomingInvalidation(
void TiclInvalidationService::Shutdown() {
DCHECK(CalledOnValidThread());
+ oauth2_token_service_->RemoveObserver(this);
if (IsStarted()) {
StopInvalidator();
}
@@ -327,7 +323,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;

Powered by Google App Engine
This is Rietveld 408576698