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

Side by Side Diff: chrome/browser/sync/profile_sync_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: Created 7 years, 4 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/sync/profile_sync_service.h" 5 #include "chrome/browser/sync/profile_sync_service.h"
6 6
7 #include <cstddef> 7 #include <cstddef>
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <utility> 10 #include <utility>
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 bool ProfileSyncService::IsOAuthRefreshTokenAvailable() { 208 bool ProfileSyncService::IsOAuthRefreshTokenAvailable() {
209 // Function name doesn't reflect which token is checked. Function checks 209 // Function name doesn't reflect which token is checked. Function checks
210 // refresh token when use_oauth2_token_ is true (all platforms except android) 210 // refresh token when use_oauth2_token_ is true (all platforms except android)
211 // and sync token otherwise (for android). 211 // and sync token otherwise (for android).
212 // TODO(pavely): Remove "else" part once use_oauth2_token_ is gone. 212 // TODO(pavely): Remove "else" part once use_oauth2_token_ is gone.
213 if (use_oauth2_token_) { 213 if (use_oauth2_token_) {
214 ProfileOAuth2TokenService* token_service = 214 ProfileOAuth2TokenService* token_service =
215 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); 215 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_);
216 if (!token_service) 216 if (!token_service)
217 return false; 217 return false;
218 return token_service->RefreshTokenIsAvailable(); 218 return token_service->RefreshTokenIsAvailable(
219 token_service->GetPrimaryAccountId());
219 } else { 220 } else {
220 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); 221 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_);
221 if (!token_service) 222 if (!token_service)
222 return false; 223 return false;
223 return token_service->HasTokenForService(GaiaConstants::kSyncService); 224 return token_service->HasTokenForService(GaiaConstants::kSyncService);
224 } 225 }
225 } 226 }
226 227
227 void ProfileSyncService::Initialize() { 228 void ProfileSyncService::Initialize() {
228 if (profile_) 229 if (profile_)
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 } 693 }
693 694
694 void ProfileSyncService::OnRefreshTokenAvailable( 695 void ProfileSyncService::OnRefreshTokenAvailable(
695 const std::string& account_id) { 696 const std::string& account_id) {
696 OnRefreshTokensLoaded(); 697 OnRefreshTokensLoaded();
697 } 698 }
698 699
699 void ProfileSyncService::OnRefreshTokenRevoked( 700 void ProfileSyncService::OnRefreshTokenRevoked(
700 const std::string& account_id) { 701 const std::string& account_id) {
701 if (!IsOAuthRefreshTokenAvailable()) { 702 if (!IsOAuthRefreshTokenAvailable()) {
703 access_token_.clear();
702 // The additional check around IsOAuthRefreshTokenAvailable() above 704 // The additional check around IsOAuthRefreshTokenAvailable() above
703 // prevents us sounding the alarm if we actually have a valid token but 705 // prevents us sounding the alarm if we actually have a valid token but
704 // a refresh attempt by TokenService failed for any variety of reasons 706 // a refresh attempt by TokenService failed for any variety of reasons
705 // (e.g. flaky network). It's possible the token we do have is also 707 // (e.g. flaky network). It's possible the token we do have is also
706 // invalid, but in that case we should already have (or can expect) an 708 // invalid, but in that case we should already have (or can expect) an
707 // auth error sent from the sync backend. 709 // auth error sent from the sync backend.
708 UpdateAuthErrorState( 710 UpdateAuthErrorState(
709 GoogleServiceAuthError(GoogleServiceAuthError::REQUEST_CANCELED)); 711 GoogleServiceAuthError(GoogleServiceAuthError::REQUEST_CANCELED));
710 } 712 }
711 } 713 }
712 714
713 void ProfileSyncService::OnRefreshTokensLoaded() { 715 void ProfileSyncService::OnRefreshTokensLoaded() {
714 // This notification gets fired when TokenService loads the tokens 716 // This notification gets fired when TokenService loads the tokens
715 // from storage. 717 // from storage.
716 // Initialize the backend if sync is enabled. If the sync token was 718 // Initialize the backend if sync is enabled. If the sync token was
717 // not loaded, GetCredentials() will generate invalid credentials to 719 // not loaded, GetCredentials() will generate invalid credentials to
718 // cause the backend to generate an auth error (crbug.com/121755). 720 // cause the backend to generate an auth error (crbug.com/121755).
719 if (backend_) { 721 if (backend_) {
720 RequestAccessToken(); 722 RequestAccessToken();
721 } else { 723 } else {
722 TryStart(); 724 TryStart();
723 } 725 }
724 } 726 }
725 727
726 void ProfileSyncService::OnRefreshTokensCleared() {
727 access_token_.clear();
728 }
729
730 void ProfileSyncService::Shutdown() { 728 void ProfileSyncService::Shutdown() {
731 UnregisterAuthNotifications(); 729 UnregisterAuthNotifications();
732 730
733 if (profile_) 731 if (profile_)
734 SigninGlobalError::GetForProfile(profile_)->RemoveProvider(this); 732 SigninGlobalError::GetForProfile(profile_)->RemoveProvider(this);
735 733
736 ShutdownImpl(browser_sync::SyncBackendHost::STOP); 734 ShutdownImpl(browser_sync::SyncBackendHost::STOP);
737 735
738 if (sync_thread_) 736 if (sync_thread_)
739 sync_thread_->Stop(); 737 sync_thread_->Stop();
(...skipping 1109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1849 if (access_token_request_ != NULL) 1847 if (access_token_request_ != NULL)
1850 return; 1848 return;
1851 request_access_token_retry_timer_.Stop(); 1849 request_access_token_retry_timer_.Stop();
1852 OAuth2TokenService::ScopeSet oauth2_scopes; 1850 OAuth2TokenService::ScopeSet oauth2_scopes;
1853 if (profile_->IsManaged()) { 1851 if (profile_->IsManaged()) {
1854 oauth2_scopes.insert(GaiaConstants::kChromeSyncManagedOAuth2Scope); 1852 oauth2_scopes.insert(GaiaConstants::kChromeSyncManagedOAuth2Scope);
1855 } else { 1853 } else {
1856 oauth2_scopes.insert(GaiaConstants::kChromeSyncOAuth2Scope); 1854 oauth2_scopes.insert(GaiaConstants::kChromeSyncOAuth2Scope);
1857 } 1855 }
1858 1856
1859 OAuth2TokenService* token_service = 1857 ProfileOAuth2TokenService* token_service =
1860 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); 1858 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_);
1861 // Invalidate previous token, otherwise token service will return the same 1859 // Invalidate previous token, otherwise token service will return the same
1862 // token again. 1860 // token again.
1863 if (!access_token_.empty()) 1861 if (!access_token_.empty())
1864 token_service->InvalidateToken(oauth2_scopes, access_token_); 1862 token_service->InvalidateToken(oauth2_scopes, access_token_);
1865 access_token_.clear(); 1863 access_token_.clear();
1866 access_token_request_ = token_service->StartRequest(oauth2_scopes, this); 1864 access_token_request_ = token_service->StartRequest(
1865 token_service->GetPrimaryAccountId(), oauth2_scopes, this);
1867 } 1866 }
1868 1867
1869 void ProfileSyncService::SetEncryptionPassphrase(const std::string& passphrase, 1868 void ProfileSyncService::SetEncryptionPassphrase(const std::string& passphrase,
1870 PassphraseType type) { 1869 PassphraseType type) {
1871 // This should only be called when the backend has been initialized. 1870 // This should only be called when the backend has been initialized.
1872 DCHECK(sync_initialized()); 1871 DCHECK(sync_initialized());
1873 DCHECK(!(type == IMPLICIT && IsUsingSecondaryPassphrase())) << 1872 DCHECK(!(type == IMPLICIT && IsUsingSecondaryPassphrase())) <<
1874 "Data is already encrypted using an explicit passphrase"; 1873 "Data is already encrypted using an explicit passphrase";
1875 DCHECK(!(type == EXPLICIT && 1874 DCHECK(!(type == EXPLICIT &&
1876 passphrase_required_reason_ == syncer::REASON_DECRYPTION)) << 1875 passphrase_required_reason_ == syncer::REASON_DECRYPTION)) <<
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
2094 NOTREACHED(); 2093 NOTREACHED();
2095 #endif 2094 #endif
2096 } 2095 }
2097 2096
2098 return signin_->GetAuthenticatedUsername(); 2097 return signin_->GetAuthenticatedUsername();
2099 } 2098 }
2100 2099
2101 WeakHandle<syncer::JsEventHandler> ProfileSyncService::GetJsEventHandler() { 2100 WeakHandle<syncer::JsEventHandler> ProfileSyncService::GetJsEventHandler() {
2102 return MakeWeakHandle(sync_js_controller_.AsWeakPtr()); 2101 return MakeWeakHandle(sync_js_controller_.AsWeakPtr());
2103 } 2102 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698