Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 684 } | 685 } |
| 685 default: { | 686 default: { |
| 686 // Show error to user. | 687 // Show error to user. |
| 687 UpdateAuthErrorState(error); | 688 UpdateAuthErrorState(error); |
| 688 } | 689 } |
| 689 } | 690 } |
| 690 } | 691 } |
| 691 | 692 |
| 692 void ProfileSyncService::OnRefreshTokenAvailable( | 693 void ProfileSyncService::OnRefreshTokenAvailable( |
| 693 const std::string& account_id) { | 694 const std::string& account_id) { |
| 694 OnRefreshTokensLoaded(); | 695 OnRefreshTokensLoaded(); |
|
Roger Tawa OOO till Jul 10th
2013/08/29 15:41:40
Shouldn't this happen only if |account_id| is the
fgorski
2013/08/29 23:04:14
Done.
| |
| 695 } | 696 } |
| 696 | 697 |
| 697 void ProfileSyncService::OnRefreshTokenRevoked( | 698 void ProfileSyncService::OnRefreshTokenRevoked( |
| 698 const std::string& account_id) { | 699 const std::string& account_id) { |
| 699 if (!IsOAuthRefreshTokenAvailable()) { | 700 if (!IsOAuthRefreshTokenAvailable()) { |
| 701 access_token_.clear(); | |
| 700 // The additional check around IsOAuthRefreshTokenAvailable() above | 702 // The additional check around IsOAuthRefreshTokenAvailable() above |
| 701 // prevents us sounding the alarm if we actually have a valid token but | 703 // prevents us sounding the alarm if we actually have a valid token but |
| 702 // a refresh attempt by TokenService failed for any variety of reasons | 704 // a refresh attempt by TokenService failed for any variety of reasons |
| 703 // (e.g. flaky network). It's possible the token we do have is also | 705 // (e.g. flaky network). It's possible the token we do have is also |
| 704 // invalid, but in that case we should already have (or can expect) an | 706 // invalid, but in that case we should already have (or can expect) an |
| 705 // auth error sent from the sync backend. | 707 // auth error sent from the sync backend. |
| 706 UpdateAuthErrorState( | 708 UpdateAuthErrorState( |
| 707 GoogleServiceAuthError(GoogleServiceAuthError::REQUEST_CANCELED)); | 709 GoogleServiceAuthError(GoogleServiceAuthError::REQUEST_CANCELED)); |
| 708 } | 710 } |
| 709 } | 711 } |
| 710 | 712 |
| 711 void ProfileSyncService::OnRefreshTokensLoaded() { | 713 void ProfileSyncService::OnRefreshTokensLoaded() { |
| 712 // This notification gets fired when TokenService loads the tokens | 714 // This notification gets fired when TokenService loads the tokens |
| 713 // from storage. | 715 // from storage. |
| 714 // Initialize the backend if sync is enabled. If the sync token was | 716 // Initialize the backend if sync is enabled. If the sync token was |
| 715 // not loaded, GetCredentials() will generate invalid credentials to | 717 // not loaded, GetCredentials() will generate invalid credentials to |
| 716 // cause the backend to generate an auth error (crbug.com/121755). | 718 // cause the backend to generate an auth error (crbug.com/121755). |
| 717 if (backend_) { | 719 if (backend_) { |
| 718 RequestAccessToken(); | 720 RequestAccessToken(); |
| 719 } else { | 721 } else { |
| 720 TryStart(); | 722 TryStart(); |
| 721 } | 723 } |
| 722 } | 724 } |
| 723 | 725 |
| 724 void ProfileSyncService::OnRefreshTokensCleared() { | |
| 725 access_token_.clear(); | |
| 726 } | |
| 727 | |
| 728 void ProfileSyncService::Shutdown() { | 726 void ProfileSyncService::Shutdown() { |
| 729 UnregisterAuthNotifications(); | 727 UnregisterAuthNotifications(); |
| 730 | 728 |
| 731 if (profile_) | 729 if (profile_) |
| 732 SigninGlobalError::GetForProfile(profile_)->RemoveProvider(this); | 730 SigninGlobalError::GetForProfile(profile_)->RemoveProvider(this); |
| 733 | 731 |
| 734 ShutdownImpl(browser_sync::SyncBackendHost::STOP); | 732 ShutdownImpl(browser_sync::SyncBackendHost::STOP); |
| 735 | 733 |
| 736 if (sync_thread_) | 734 if (sync_thread_) |
| 737 sync_thread_->Stop(); | 735 sync_thread_->Stop(); |
| (...skipping 1117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1855 if (access_token_request_ != NULL) | 1853 if (access_token_request_ != NULL) |
| 1856 return; | 1854 return; |
| 1857 request_access_token_retry_timer_.Stop(); | 1855 request_access_token_retry_timer_.Stop(); |
| 1858 OAuth2TokenService::ScopeSet oauth2_scopes; | 1856 OAuth2TokenService::ScopeSet oauth2_scopes; |
| 1859 if (profile_->IsManaged()) { | 1857 if (profile_->IsManaged()) { |
| 1860 oauth2_scopes.insert(GaiaConstants::kChromeSyncManagedOAuth2Scope); | 1858 oauth2_scopes.insert(GaiaConstants::kChromeSyncManagedOAuth2Scope); |
| 1861 } else { | 1859 } else { |
| 1862 oauth2_scopes.insert(GaiaConstants::kChromeSyncOAuth2Scope); | 1860 oauth2_scopes.insert(GaiaConstants::kChromeSyncOAuth2Scope); |
| 1863 } | 1861 } |
| 1864 | 1862 |
| 1865 OAuth2TokenService* token_service = | 1863 ProfileOAuth2TokenService* token_service = |
| 1866 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); | 1864 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); |
| 1867 // Invalidate previous token, otherwise token service will return the same | 1865 // Invalidate previous token, otherwise token service will return the same |
| 1868 // token again. | 1866 // token again. |
| 1869 if (!access_token_.empty()) | 1867 if (!access_token_.empty()) |
| 1870 token_service->InvalidateToken(oauth2_scopes, access_token_); | 1868 token_service->InvalidateToken(oauth2_scopes, access_token_); |
| 1871 access_token_.clear(); | 1869 access_token_.clear(); |
| 1872 access_token_request_ = token_service->StartRequest(oauth2_scopes, this); | 1870 access_token_request_ = token_service->StartRequest( |
| 1871 token_service->GetPrimaryAccountId(), oauth2_scopes, this); | |
| 1873 } | 1872 } |
| 1874 | 1873 |
| 1875 void ProfileSyncService::SetEncryptionPassphrase(const std::string& passphrase, | 1874 void ProfileSyncService::SetEncryptionPassphrase(const std::string& passphrase, |
| 1876 PassphraseType type) { | 1875 PassphraseType type) { |
| 1877 // This should only be called when the backend has been initialized. | 1876 // This should only be called when the backend has been initialized. |
| 1878 DCHECK(sync_initialized()); | 1877 DCHECK(sync_initialized()); |
| 1879 DCHECK(!(type == IMPLICIT && IsUsingSecondaryPassphrase())) << | 1878 DCHECK(!(type == IMPLICIT && IsUsingSecondaryPassphrase())) << |
| 1880 "Data is already encrypted using an explicit passphrase"; | 1879 "Data is already encrypted using an explicit passphrase"; |
| 1881 DCHECK(!(type == EXPLICIT && | 1880 DCHECK(!(type == EXPLICIT && |
| 1882 passphrase_required_reason_ == syncer::REASON_DECRYPTION)) << | 1881 passphrase_required_reason_ == syncer::REASON_DECRYPTION)) << |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2108 NOTREACHED(); | 2107 NOTREACHED(); |
| 2109 #endif | 2108 #endif |
| 2110 } | 2109 } |
| 2111 | 2110 |
| 2112 return signin_->GetAuthenticatedUsername(); | 2111 return signin_->GetAuthenticatedUsername(); |
| 2113 } | 2112 } |
| 2114 | 2113 |
| 2115 WeakHandle<syncer::JsEventHandler> ProfileSyncService::GetJsEventHandler() { | 2114 WeakHandle<syncer::JsEventHandler> ProfileSyncService::GetJsEventHandler() { |
| 2116 return MakeWeakHandle(sync_js_controller_.AsWeakPtr()); | 2115 return MakeWeakHandle(sync_js_controller_.AsWeakPtr()); |
| 2117 } | 2116 } |
| OLD | NEW |