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 12 matching lines...) Expand all Loading... | |
23 #include "base/threading/thread_restrictions.h" | 23 #include "base/threading/thread_restrictions.h" |
24 #include "build/build_config.h" | 24 #include "build/build_config.h" |
25 #include "chrome/browser/about_flags.h" | 25 #include "chrome/browser/about_flags.h" |
26 #include "chrome/browser/browser_process.h" | 26 #include "chrome/browser/browser_process.h" |
27 #include "chrome/browser/defaults.h" | 27 #include "chrome/browser/defaults.h" |
28 #include "chrome/browser/net/chrome_cookie_notification_details.h" | 28 #include "chrome/browser/net/chrome_cookie_notification_details.h" |
29 #include "chrome/browser/prefs/pref_service_syncable.h" | 29 #include "chrome/browser/prefs/pref_service_syncable.h" |
30 #include "chrome/browser/profiles/profile.h" | 30 #include "chrome/browser/profiles/profile.h" |
31 #include "chrome/browser/signin/about_signin_internals.h" | 31 #include "chrome/browser/signin/about_signin_internals.h" |
32 #include "chrome/browser/signin/about_signin_internals_factory.h" | 32 #include "chrome/browser/signin/about_signin_internals_factory.h" |
33 #include "chrome/browser/signin/profile_oauth2_token_service.h" | |
34 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | |
33 #include "chrome/browser/signin/signin_manager.h" | 35 #include "chrome/browser/signin/signin_manager.h" |
34 #include "chrome/browser/signin/signin_manager_factory.h" | 36 #include "chrome/browser/signin/signin_manager_factory.h" |
35 #include "chrome/browser/signin/token_service.h" | 37 #include "chrome/browser/signin/token_service.h" |
36 #include "chrome/browser/signin/token_service_factory.h" | 38 #include "chrome/browser/signin/token_service_factory.h" |
37 #include "chrome/browser/sync/backend_migrator.h" | 39 #include "chrome/browser/sync/backend_migrator.h" |
38 #include "chrome/browser/sync/glue/change_processor.h" | 40 #include "chrome/browser/sync/glue/change_processor.h" |
39 #include "chrome/browser/sync/glue/chrome_encryptor.h" | 41 #include "chrome/browser/sync/glue/chrome_encryptor.h" |
40 #include "chrome/browser/sync/glue/chrome_report_unrecoverable_error.h" | 42 #include "chrome/browser/sync/glue/chrome_report_unrecoverable_error.h" |
41 #include "chrome/browser/sync/glue/data_type_controller.h" | 43 #include "chrome/browser/sync/glue/data_type_controller.h" |
42 #include "chrome/browser/sync/glue/device_info.h" | 44 #include "chrome/browser/sync/glue/device_info.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
103 typedef GoogleServiceAuthError AuthError; | 105 typedef GoogleServiceAuthError AuthError; |
104 | 106 |
105 const char* ProfileSyncService::kSyncServerUrl = | 107 const char* ProfileSyncService::kSyncServerUrl = |
106 "https://clients4.google.com/chrome-sync"; | 108 "https://clients4.google.com/chrome-sync"; |
107 | 109 |
108 const char* ProfileSyncService::kDevServerUrl = | 110 const char* ProfileSyncService::kDevServerUrl = |
109 "https://clients4.google.com/chrome-sync/dev"; | 111 "https://clients4.google.com/chrome-sync/dev"; |
110 | 112 |
111 static const int kSyncClearDataTimeoutInSeconds = 60; // 1 minute. | 113 static const int kSyncClearDataTimeoutInSeconds = 60; // 1 minute. |
112 | 114 |
113 static const char* kRelevantTokenServices[] = { | 115 static const char* kOAuth2Scopes[] = { |
114 GaiaConstants::kSyncService | 116 GaiaConstants::kChromeSyncOAuth2Scope, |
117 // GoogleTalk scope is needed for notifications | |
Andrew T Wilson (Slow)
2013/05/31 12:57:28
nit: add period at the end for sentence punctuatio
pavely
2013/06/04 00:49:59
Done.
| |
118 GaiaConstants::kGoogleTalkOAuth2Scope | |
115 }; | 119 }; |
116 static const int kRelevantTokenServicesCount = | 120 |
117 arraysize(kRelevantTokenServices); | |
118 | 121 |
119 static const char* kSyncUnrecoverableErrorHistogram = | 122 static const char* kSyncUnrecoverableErrorHistogram = |
120 "Sync.UnrecoverableErrors"; | 123 "Sync.UnrecoverableErrors"; |
121 | 124 |
122 // Helper to check if the given token service is relevant for sync. | |
123 static bool IsTokenServiceRelevant(const std::string& service) { | |
124 for (int i = 0; i < kRelevantTokenServicesCount; ++i) { | |
125 if (service == kRelevantTokenServices[i]) | |
126 return true; | |
127 } | |
128 return false; | |
129 } | |
130 | |
131 bool ShouldShowActionOnUI( | 125 bool ShouldShowActionOnUI( |
132 const syncer::SyncProtocolError& error) { | 126 const syncer::SyncProtocolError& error) { |
133 return (error.action != syncer::UNKNOWN_ACTION && | 127 return (error.action != syncer::UNKNOWN_ACTION && |
134 error.action != syncer::DISABLE_SYNC_ON_CLIENT); | 128 error.action != syncer::DISABLE_SYNC_ON_CLIENT); |
135 } | 129 } |
136 | 130 |
137 ProfileSyncService::ProfileSyncService(ProfileSyncComponentsFactory* factory, | 131 ProfileSyncService::ProfileSyncService(ProfileSyncComponentsFactory* factory, |
138 Profile* profile, | 132 Profile* profile, |
139 SigninManagerBase* signin_manager, | 133 SigninManagerBase* signin_manager, |
140 StartBehavior start_behavior) | 134 StartBehavior start_behavior) |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
186 | 180 |
187 bool ProfileSyncService::IsSyncEnabledAndLoggedIn() { | 181 bool ProfileSyncService::IsSyncEnabledAndLoggedIn() { |
188 // Exit if sync is disabled. | 182 // Exit if sync is disabled. |
189 if (IsManaged() || sync_prefs_.IsStartSuppressed()) | 183 if (IsManaged() || sync_prefs_.IsStartSuppressed()) |
190 return false; | 184 return false; |
191 | 185 |
192 // Sync is logged in if there is a non-empty effective username. | 186 // Sync is logged in if there is a non-empty effective username. |
193 return !GetEffectiveUsername().empty(); | 187 return !GetEffectiveUsername().empty(); |
194 } | 188 } |
195 | 189 |
196 bool ProfileSyncService::IsSyncTokenAvailable() { | 190 bool ProfileSyncService::IsOAuthRefreshTokenAvailable() { |
197 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); | 191 ProfileOAuth2TokenService* token_service = |
192 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); | |
198 if (!token_service) | 193 if (!token_service) |
199 return false; | 194 return false; |
200 return token_service->HasTokenForService(GaiaConstants::kSyncService); | 195 return token_service->RefreshTokenIsAvailable(); |
201 } | 196 } |
202 #if defined(OS_ANDROID) | 197 #if defined(OS_ANDROID) |
203 bool ProfileSyncService::ShouldEnablePasswordSyncForAndroid() const { | 198 bool ProfileSyncService::ShouldEnablePasswordSyncForAndroid() const { |
204 const syncer::ModelTypeSet registered_types = GetRegisteredDataTypes(); | 199 const syncer::ModelTypeSet registered_types = GetRegisteredDataTypes(); |
205 const syncer::ModelTypeSet preferred_types = | 200 const syncer::ModelTypeSet preferred_types = |
206 sync_prefs_.GetPreferredDataTypes(registered_types); | 201 sync_prefs_.GetPreferredDataTypes(registered_types); |
207 if (!preferred_types.Has(syncer::PASSWORDS)) | 202 if (!preferred_types.Has(syncer::PASSWORDS)) |
208 return false; | 203 return false; |
209 // If backend has not completed initializing we cannot check if the | 204 // If backend has not completed initializing we cannot check if the |
210 // cryptographer is ready. | 205 // cryptographer is ready. |
(...skipping 27 matching lines...) Expand all Loading... | |
238 | 233 |
239 RegisterAuthNotifications(); | 234 RegisterAuthNotifications(); |
240 | 235 |
241 if (!HasSyncSetupCompleted() || GetEffectiveUsername().empty()) { | 236 if (!HasSyncSetupCompleted() || GetEffectiveUsername().empty()) { |
242 // Clean up in case of previous crash / setup abort / signout. | 237 // Clean up in case of previous crash / setup abort / signout. |
243 DisableForUser(); | 238 DisableForUser(); |
244 } | 239 } |
245 | 240 |
246 TrySyncDatatypePrefRecovery(); | 241 TrySyncDatatypePrefRecovery(); |
247 | 242 |
243 if (IsOAuthRefreshTokenAvailable()) { | |
244 // Tell token service to pre-request access token. We likely don't need it | |
245 // right away but it will be available when we decide to initialize backend. | |
246 RequestAccessToken(false, false); | |
247 } | |
248 | |
248 TryStart(); | 249 TryStart(); |
249 } | 250 } |
250 | 251 |
251 void ProfileSyncService::TrySyncDatatypePrefRecovery() { | 252 void ProfileSyncService::TrySyncDatatypePrefRecovery() { |
252 DCHECK(!sync_initialized()); | 253 DCHECK(!sync_initialized()); |
253 if (!HasSyncSetupCompleted()) | 254 if (!HasSyncSetupCompleted()) |
254 return; | 255 return; |
255 | 256 |
256 // There was a bug where OnUserChoseDatatypes was not properly called on | 257 // There was a bug where OnUserChoseDatatypes was not properly called on |
257 // configuration (see crbug.com/154940). We detect this by checking whether | 258 // configuration (see crbug.com/154940). We detect this by checking whether |
(...skipping 27 matching lines...) Expand all Loading... | |
285 return; | 286 return; |
286 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); | 287 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); |
287 if (!token_service) | 288 if (!token_service) |
288 return; | 289 return; |
289 // Don't start the backend if the token service hasn't finished loading tokens | 290 // Don't start the backend if the token service hasn't finished loading tokens |
290 // yet. Note if the backend is started before the sync token has been loaded, | 291 // yet. Note if the backend is started before the sync token has been loaded, |
291 // GetCredentials() will return bogus credentials. On auto_start platforms | 292 // GetCredentials() will return bogus credentials. On auto_start platforms |
292 // (like ChromeOS) we don't start sync until tokens are loaded, because the | 293 // (like ChromeOS) we don't start sync until tokens are loaded, because the |
293 // user can be "signed in" on those platforms long before the tokens get | 294 // user can be "signed in" on those platforms long before the tokens get |
294 // loaded, and we don't want to generate spurious auth errors. | 295 // loaded, and we don't want to generate spurious auth errors. |
295 if (!IsSyncTokenAvailable() && | 296 if (!IsOAuthRefreshTokenAvailable() && |
296 !(!auto_start_enabled_ && token_service->TokensLoadedFromDB())) { | 297 !(!auto_start_enabled_ && token_service->TokensLoadedFromDB())) { |
297 return; | 298 return; |
298 } | 299 } |
299 | 300 |
300 // If sync setup has completed we always start the backend. If the user is in | 301 // If sync setup has completed we always start the backend. If the user is in |
301 // the process of setting up now, we should start the backend to download | 302 // the process of setting up now, we should start the backend to download |
302 // account control state / encryption information). If autostart is enabled, | 303 // account control state / encryption information). If autostart is enabled, |
303 // but we haven't completed sync setup, we try to start sync anyway, since | 304 // but we haven't completed sync setup, we try to start sync anyway, since |
304 // it's possible we crashed/shutdown after logging in but before the backend | 305 // it's possible we crashed/shutdown after logging in but before the backend |
305 // finished initializing the last time. | 306 // finished initializing the last time. |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
419 << "is invalid: " << value; | 420 << "is invalid: " << value; |
420 } | 421 } |
421 } | 422 } |
422 } | 423 } |
423 } | 424 } |
424 | 425 |
425 SyncCredentials ProfileSyncService::GetCredentials() { | 426 SyncCredentials ProfileSyncService::GetCredentials() { |
426 SyncCredentials credentials; | 427 SyncCredentials credentials; |
427 credentials.email = GetEffectiveUsername(); | 428 credentials.email = GetEffectiveUsername(); |
428 DCHECK(!credentials.email.empty()); | 429 DCHECK(!credentials.email.empty()); |
429 TokenService* service = TokenServiceFactory::GetForProfile(profile_); | 430 if (!access_token_.empty()) { |
430 if (service->HasTokenForService(GaiaConstants::kSyncService)) { | 431 credentials.sync_token = access_token_; |
431 credentials.sync_token = service->GetTokenForService( | |
432 GaiaConstants::kSyncService); | |
433 credentials.sync_token_time = | 432 credentials.sync_token_time = |
434 AboutSigninInternalsFactory::GetForProfile(profile_)-> | 433 AboutSigninInternalsFactory::GetForProfile(profile_)-> |
435 GetTokenTime(GaiaConstants::kSyncService); | 434 GetTokenTime(GaiaConstants::kGaiaOAuth2LoginRefreshToken); |
436 UMA_HISTOGRAM_BOOLEAN("Sync.CredentialsLost", false); | 435 UMA_HISTOGRAM_BOOLEAN("Sync.CredentialsLost", false); |
437 } else { | 436 } else { |
438 // We've lost our sync credentials (crbug.com/121755), so just make up some | 437 // We've lost our sync credentials (crbug.com/121755), so just make up some |
439 // invalid credentials so the backend will generate an auth error. | 438 // invalid credentials so the backend will generate an auth error. |
440 UMA_HISTOGRAM_BOOLEAN("Sync.CredentialsLost", true); | 439 UMA_HISTOGRAM_BOOLEAN("Sync.CredentialsLost", true); |
441 credentials.sync_token = "credentials_lost"; | 440 credentials.sync_token = "credentials_lost"; |
442 } | 441 } |
443 return credentials; | 442 return credentials; |
444 } | 443 } |
445 | 444 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
507 | 506 |
508 void ProfileSyncService::StartUp(StartUpDeferredOption deferred_option) { | 507 void ProfileSyncService::StartUp(StartUpDeferredOption deferred_option) { |
509 // Don't start up multiple times. | 508 // Don't start up multiple times. |
510 if (backend_) { | 509 if (backend_) { |
511 DVLOG(1) << "Skipping bringing up backend host."; | 510 DVLOG(1) << "Skipping bringing up backend host."; |
512 return; | 511 return; |
513 } | 512 } |
514 | 513 |
515 DCHECK(IsSyncEnabledAndLoggedIn()); | 514 DCHECK(IsSyncEnabledAndLoggedIn()); |
516 | 515 |
516 if (access_token_.empty()) { | |
517 RequestAccessToken(false, true); | |
518 return; | |
519 } | |
520 | |
517 if (start_up_time_.is_null()) { | 521 if (start_up_time_.is_null()) { |
518 start_up_time_ = base::Time::Now(); | 522 start_up_time_ = base::Time::Now(); |
519 last_synced_time_ = sync_prefs_.GetLastSyncedTime(); | 523 last_synced_time_ = sync_prefs_.GetLastSyncedTime(); |
520 | 524 |
521 #if defined(OS_CHROMEOS) | 525 #if defined(OS_CHROMEOS) |
522 std::string bootstrap_token = sync_prefs_.GetEncryptionBootstrapToken(); | 526 std::string bootstrap_token = sync_prefs_.GetEncryptionBootstrapToken(); |
523 if (bootstrap_token.empty()) { | 527 if (bootstrap_token.empty()) { |
524 sync_prefs_.SetEncryptionBootstrapToken( | 528 sync_prefs_.SetEncryptionBootstrapToken( |
525 sync_prefs_.GetSpareBootstrapToken()); | 529 sync_prefs_.GetSpareBootstrapToken()); |
526 } | 530 } |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
654 // If |backend_| is NULL, save the acknowledgements to replay when | 658 // If |backend_| is NULL, save the acknowledgements to replay when |
655 // it's created and initialized. | 659 // it's created and initialized. |
656 ack_replay_queue_.push_back(std::make_pair(id, ack_handle)); | 660 ack_replay_queue_.push_back(std::make_pair(id, ack_handle)); |
657 } | 661 } |
658 } | 662 } |
659 | 663 |
660 syncer::InvalidatorState ProfileSyncService::GetInvalidatorState() const { | 664 syncer::InvalidatorState ProfileSyncService::GetInvalidatorState() const { |
661 return invalidator_registrar_->GetInvalidatorState(); | 665 return invalidator_registrar_->GetInvalidatorState(); |
662 } | 666 } |
663 | 667 |
668 void ProfileSyncService::OnGetTokenSuccess( | |
669 const OAuth2TokenService::Request* request, | |
670 const std::string& access_token, | |
671 const base::Time& expiration_time) { | |
672 DCHECK_EQ(access_token_request_, request); | |
673 access_token_request_.reset(); | |
674 access_token_ = access_token; | |
675 if (backend_) | |
676 backend_->UpdateCredentials(GetCredentials()); | |
677 else | |
678 TryStart(); | |
679 } | |
680 | |
681 void ProfileSyncService::OnGetTokenFailure( | |
682 const OAuth2TokenService::Request* request, | |
683 const GoogleServiceAuthError& error) { | |
684 DCHECK_EQ(access_token_request_, request); | |
685 access_token_request_.reset(); | |
686 UpdateAuthErrorState(error); | |
687 } | |
688 | |
664 void ProfileSyncService::EmitInvalidationForTest( | 689 void ProfileSyncService::EmitInvalidationForTest( |
665 const invalidation::ObjectId& id, | 690 const invalidation::ObjectId& id, |
666 const std::string& payload) { | 691 const std::string& payload) { |
667 syncer::ObjectIdSet notify_ids; | 692 syncer::ObjectIdSet notify_ids; |
668 notify_ids.insert(id); | 693 notify_ids.insert(id); |
669 | 694 |
670 const syncer::ObjectIdInvalidationMap& invalidation_map = | 695 const syncer::ObjectIdInvalidationMap& invalidation_map = |
671 ObjectIdSetToInvalidationMap(notify_ids, payload); | 696 ObjectIdSetToInvalidationMap(notify_ids, payload); |
672 OnIncomingInvalidation(invalidation_map); | 697 OnIncomingInvalidation(invalidation_map); |
673 } | 698 } |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1080 default: | 1105 default: |
1081 NOTREACHED(); | 1106 NOTREACHED(); |
1082 return AuthError(AuthError::CONNECTION_FAILED); | 1107 return AuthError(AuthError::CONNECTION_FAILED); |
1083 } | 1108 } |
1084 } | 1109 } |
1085 | 1110 |
1086 } // namespace | 1111 } // namespace |
1087 | 1112 |
1088 void ProfileSyncService::OnConnectionStatusChange( | 1113 void ProfileSyncService::OnConnectionStatusChange( |
1089 syncer::ConnectionStatus status) { | 1114 syncer::ConnectionStatus status) { |
1090 const GoogleServiceAuthError auth_error = | 1115 if (status == syncer::CONNECTION_AUTH_ERROR) { |
1091 ConnectionStatusToAuthError(status); | 1116 // Sync or Tango server returned error indicating that access token is |
1092 DVLOG(1) << "Connection status change: " << auth_error.ToString(); | 1117 // invalid. It could be either expired or access is revoked. Let's request |
1093 UpdateAuthErrorState(auth_error); | 1118 // another access token and if access is revoked then request for token will |
1119 // fail with corresponding error. | |
1120 RequestAccessToken(true, true); | |
1121 } else { | |
1122 const GoogleServiceAuthError auth_error = | |
1123 ConnectionStatusToAuthError(status); | |
1124 DVLOG(1) << "Connection status change: " << auth_error.ToString(); | |
1125 UpdateAuthErrorState(auth_error); | |
1126 } | |
1094 } | 1127 } |
1095 | 1128 |
1096 void ProfileSyncService::OnStopSyncingPermanently() { | 1129 void ProfileSyncService::OnStopSyncingPermanently() { |
1097 sync_prefs_.SetStartSuppressed(true); | 1130 sync_prefs_.SetStartSuppressed(true); |
1098 DisableForUser(); | 1131 DisableForUser(); |
1099 } | 1132 } |
1100 | 1133 |
1101 void ProfileSyncService::OnPassphraseRequired( | 1134 void ProfileSyncService::OnPassphraseRequired( |
1102 syncer::PassphraseRequiredReason reason, | 1135 syncer::PassphraseRequiredReason reason, |
1103 const sync_pb::EncryptedData& pending_keys) { | 1136 const sync_pb::EncryptedData& pending_keys) { |
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1826 } | 1859 } |
1827 } | 1860 } |
1828 | 1861 |
1829 // If we get here, we don't have pending keys (or at least, the passphrase | 1862 // If we get here, we don't have pending keys (or at least, the passphrase |
1830 // doesn't decrypt them) - just try to re-encrypt using the encryption | 1863 // doesn't decrypt them) - just try to re-encrypt using the encryption |
1831 // passphrase. | 1864 // passphrase. |
1832 if (!IsUsingSecondaryPassphrase()) | 1865 if (!IsUsingSecondaryPassphrase()) |
1833 SetEncryptionPassphrase(passphrase, IMPLICIT); | 1866 SetEncryptionPassphrase(passphrase, IMPLICIT); |
1834 } | 1867 } |
1835 | 1868 |
1869 void ProfileSyncService::RequestAccessToken( | |
1870 bool invalidate_previous_token, | |
1871 bool invoke_callback) { | |
1872 // Only one active request at a time. | |
1873 if (access_token_request_ != NULL) | |
1874 return; | |
1875 OAuth2TokenService::ScopeSet oauth2_scopes; | |
1876 for (size_t i = 0; i < arraysize(kOAuth2Scopes); i++) | |
1877 oauth2_scopes.insert(kOAuth2Scopes[i]); | |
1878 OAuth2TokenService* token_service = | |
1879 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); | |
1880 if (invalidate_previous_token) { | |
1881 // Invalidate previous token, othervise token service will return the same | |
Andrew T Wilson (Slow)
2013/05/31 12:57:28
nit:othervise->otherwise. Also add a period at the
pavely
2013/06/04 00:49:59
Done.
| |
1882 // token again | |
1883 token_service->InvalidateToken(oauth2_scopes, access_token_); | |
1884 access_token_.clear(); | |
1885 } | |
1886 access_token_request_ = token_service->StartRequest(oauth2_scopes, this); | |
1887 if (!invoke_callback) { | |
1888 // Deleting request will not cancel RPC but callbacks won't be invoked. | |
1889 access_token_request_.reset(); | |
1890 } | |
1891 } | |
1892 | |
1836 void ProfileSyncService::SetEncryptionPassphrase(const std::string& passphrase, | 1893 void ProfileSyncService::SetEncryptionPassphrase(const std::string& passphrase, |
1837 PassphraseType type) { | 1894 PassphraseType type) { |
1838 // This should only be called when the backend has been initialized. | 1895 // This should only be called when the backend has been initialized. |
1839 DCHECK(sync_initialized()); | 1896 DCHECK(sync_initialized()); |
1840 DCHECK(!(type == IMPLICIT && IsUsingSecondaryPassphrase())) << | 1897 DCHECK(!(type == IMPLICIT && IsUsingSecondaryPassphrase())) << |
1841 "Data is already encrypted using an explicit passphrase"; | 1898 "Data is already encrypted using an explicit passphrase"; |
1842 DCHECK(!(type == EXPLICIT && | 1899 DCHECK(!(type == EXPLICIT && |
1843 passphrase_required_reason_ == syncer::REASON_DECRYPTION)) << | 1900 passphrase_required_reason_ == syncer::REASON_DECRYPTION)) << |
1844 "Can not set explicit passphrase when decryption is needed."; | 1901 "Can not set explicit passphrase when decryption is needed."; |
1845 | 1902 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1929 RefreshSpareBootstrapToken(successful->password); | 1986 RefreshSpareBootstrapToken(successful->password); |
1930 #endif | 1987 #endif |
1931 if (!sync_initialized() || | 1988 if (!sync_initialized() || |
1932 GetAuthError().state() != AuthError::NONE) { | 1989 GetAuthError().state() != AuthError::NONE) { |
1933 // Track the fact that we're still waiting for auth to complete. | 1990 // Track the fact that we're still waiting for auth to complete. |
1934 is_auth_in_progress_ = true; | 1991 is_auth_in_progress_ = true; |
1935 } | 1992 } |
1936 break; | 1993 break; |
1937 } | 1994 } |
1938 case chrome::NOTIFICATION_TOKEN_REQUEST_FAILED: { | 1995 case chrome::NOTIFICATION_TOKEN_REQUEST_FAILED: { |
1996 // TODO(atwilson): sync shouldn't report refresh token request failures. | |
1997 // TokenService should do that instead. | |
1939 const TokenService::TokenRequestFailedDetails& token_details = | 1998 const TokenService::TokenRequestFailedDetails& token_details = |
1940 *(content::Details<const TokenService::TokenRequestFailedDetails>( | 1999 *(content::Details<const TokenService::TokenRequestFailedDetails>( |
1941 details).ptr()); | 2000 details).ptr()); |
1942 if (IsTokenServiceRelevant(token_details.service()) && | 2001 if (token_details.service() == |
1943 !IsSyncTokenAvailable()) { | 2002 GaiaConstants::kGaiaOAuth2LoginRefreshToken && |
1944 // The additional check around IsSyncTokenAvailable() above prevents us | 2003 !IsOAuthRefreshTokenAvailable()) { |
1945 // sounding the alarm if we actually have a valid token but a refresh | 2004 // The additional check around IsOAuthRefreshTokenAvailable() above |
1946 // attempt by TokenService failed for any variety of reasons (e.g. flaky | 2005 // prevents us sounding the alarm if we actually have a valid token but |
1947 // network). It's possible the token we do have is also invalid, but in | 2006 // a refresh attempt by TokenService failed for any variety of reasons |
1948 // that case we should already have (or can expect) an auth error sent | 2007 // (e.g. flaky network). It's possible the token we do have is also |
1949 // from the sync backend. | 2008 // invalid, but in that case we should already have (or can expect) an |
2009 // auth error sent from the sync backend. | |
1950 AuthError error(AuthError::INVALID_GAIA_CREDENTIALS); | 2010 AuthError error(AuthError::INVALID_GAIA_CREDENTIALS); |
1951 UpdateAuthErrorState(error); | 2011 UpdateAuthErrorState(error); |
1952 } | 2012 } |
1953 break; | 2013 break; |
1954 } | 2014 } |
1955 case chrome::NOTIFICATION_TOKEN_AVAILABLE: { | 2015 case chrome::NOTIFICATION_TOKEN_AVAILABLE: { |
2016 // TODO(atwilson): Listen for notifications on OAuth2TokenService | |
2017 // (crbug.com/243737) | |
1956 const TokenService::TokenAvailableDetails& token_details = | 2018 const TokenService::TokenAvailableDetails& token_details = |
1957 *(content::Details<const TokenService::TokenAvailableDetails>( | 2019 *(content::Details<const TokenService::TokenAvailableDetails>( |
1958 details).ptr()); | 2020 details).ptr()); |
1959 if (!IsTokenServiceRelevant(token_details.service())) | 2021 if (token_details.service() != |
2022 GaiaConstants::kGaiaOAuth2LoginRefreshToken) | |
1960 break; | 2023 break; |
1961 } // Fall through. | 2024 } // Fall through. |
1962 case chrome::NOTIFICATION_TOKEN_LOADING_FINISHED: { | 2025 case chrome::NOTIFICATION_TOKEN_LOADING_FINISHED: { |
1963 // This notification gets fired when TokenService loads the tokens | 2026 // This notification gets fired when TokenService loads the tokens |
1964 // from storage. | 2027 // from storage. |
1965 // Initialize the backend if sync is enabled. If the sync token was | 2028 // Initialize the backend if sync is enabled. If the sync token was |
1966 // not loaded, GetCredentials() will generate invalid credentials to | 2029 // not loaded, GetCredentials() will generate invalid credentials to |
1967 // cause the backend to generate an auth error (crbug.com/121755). | 2030 // cause the backend to generate an auth error (crbug.com/121755). |
1968 if (backend_) | 2031 if (backend_) |
1969 backend_->UpdateCredentials(GetCredentials()); | 2032 RequestAccessToken(true, true); |
1970 else | 2033 else |
2034 RequestAccessToken(true, false); | |
Andrew T Wilson (Slow)
2013/05/31 12:57:28
Doesn't this fetch a token on every startup even i
| |
1971 TryStart(); | 2035 TryStart(); |
1972 break; | 2036 break; |
1973 } | 2037 } |
1974 case chrome::NOTIFICATION_TOKENS_CLEARED: { | 2038 case chrome::NOTIFICATION_TOKENS_CLEARED: { |
1975 // GetCredentials() will generate invalid credentials to cause the backend | 2039 // GetCredentials() will generate invalid credentials to cause the backend |
1976 // to generate an auth error. | 2040 // to generate an auth error. |
2041 access_token_.clear(); | |
1977 if (backend_) | 2042 if (backend_) |
1978 backend_->UpdateCredentials(GetCredentials()); | 2043 backend_->UpdateCredentials(GetCredentials()); |
1979 break; | 2044 break; |
1980 } | 2045 } |
1981 case chrome::NOTIFICATION_GOOGLE_SIGNED_OUT: | 2046 case chrome::NOTIFICATION_GOOGLE_SIGNED_OUT: |
1982 // Disable sync if the user is signed out. | 2047 // Disable sync if the user is signed out. |
1983 DisableForUser(); | 2048 DisableForUser(); |
1984 break; | 2049 break; |
1985 default: { | 2050 default: { |
1986 NOTREACHED(); | 2051 NOTREACHED(); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2103 std::string ProfileSyncService::GetEffectiveUsername() { | 2168 std::string ProfileSyncService::GetEffectiveUsername() { |
2104 #if defined(ENABLE_MANAGED_USERS) | 2169 #if defined(ENABLE_MANAGED_USERS) |
2105 if (ManagedUserService::ProfileIsManaged(profile_)) { | 2170 if (ManagedUserService::ProfileIsManaged(profile_)) { |
2106 DCHECK_EQ(std::string(), signin_->GetAuthenticatedUsername()); | 2171 DCHECK_EQ(std::string(), signin_->GetAuthenticatedUsername()); |
2107 return ManagedUserService::GetManagedUserPseudoEmail(); | 2172 return ManagedUserService::GetManagedUserPseudoEmail(); |
2108 } | 2173 } |
2109 #endif | 2174 #endif |
2110 | 2175 |
2111 return signin_->GetAuthenticatedUsername(); | 2176 return signin_->GetAuthenticatedUsername(); |
2112 } | 2177 } |
2113 | |
OLD | NEW |