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 10 matching lines...) Expand all Loading... | |
| 21 #include "base/string16.h" | 21 #include "base/string16.h" |
| 22 #include "base/stringprintf.h" | 22 #include "base/stringprintf.h" |
| 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/profile_oauth2_token_service.h" | |
| 32 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | |
| 31 #include "chrome/browser/signin/signin_manager.h" | 33 #include "chrome/browser/signin/signin_manager.h" |
| 32 #include "chrome/browser/signin/signin_manager_factory.h" | 34 #include "chrome/browser/signin/signin_manager_factory.h" |
| 33 #include "chrome/browser/signin/token_service.h" | 35 #include "chrome/browser/signin/token_service.h" |
| 34 #include "chrome/browser/signin/token_service_factory.h" | 36 #include "chrome/browser/signin/token_service_factory.h" |
|
Andrew T Wilson (Slow)
2013/05/24 14:10:15
Can we remove our direct dependency on TokenServic
pavely
2013/05/30 07:42:12
There are two places where TokenService is still u
| |
| 35 #include "chrome/browser/sync/backend_migrator.h" | 37 #include "chrome/browser/sync/backend_migrator.h" |
| 36 #include "chrome/browser/sync/glue/change_processor.h" | 38 #include "chrome/browser/sync/glue/change_processor.h" |
| 37 #include "chrome/browser/sync/glue/chrome_encryptor.h" | 39 #include "chrome/browser/sync/glue/chrome_encryptor.h" |
| 38 #include "chrome/browser/sync/glue/chrome_report_unrecoverable_error.h" | 40 #include "chrome/browser/sync/glue/chrome_report_unrecoverable_error.h" |
| 39 #include "chrome/browser/sync/glue/data_type_controller.h" | 41 #include "chrome/browser/sync/glue/data_type_controller.h" |
| 40 #include "chrome/browser/sync/glue/device_info.h" | 42 #include "chrome/browser/sync/glue/device_info.h" |
| 41 #include "chrome/browser/sync/glue/session_data_type_controller.h" | 43 #include "chrome/browser/sync/glue/session_data_type_controller.h" |
| 42 #include "chrome/browser/sync/glue/session_model_associator.h" | 44 #include "chrome/browser/sync/glue/session_model_associator.h" |
| 43 #include "chrome/browser/sync/glue/synced_device_tracker.h" | 45 #include "chrome/browser/sync/glue/synced_device_tracker.h" |
| 44 #include "chrome/browser/sync/glue/typed_url_data_type_controller.h" | 46 #include "chrome/browser/sync/glue/typed_url_data_type_controller.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 97 typedef GoogleServiceAuthError AuthError; | 99 typedef GoogleServiceAuthError AuthError; |
| 98 | 100 |
| 99 const char* ProfileSyncService::kSyncServerUrl = | 101 const char* ProfileSyncService::kSyncServerUrl = |
| 100 "https://clients4.google.com/chrome-sync"; | 102 "https://clients4.google.com/chrome-sync"; |
| 101 | 103 |
| 102 const char* ProfileSyncService::kDevServerUrl = | 104 const char* ProfileSyncService::kDevServerUrl = |
| 103 "https://clients4.google.com/chrome-sync/dev"; | 105 "https://clients4.google.com/chrome-sync/dev"; |
| 104 | 106 |
| 105 static const int kSyncClearDataTimeoutInSeconds = 60; // 1 minute. | 107 static const int kSyncClearDataTimeoutInSeconds = 60; // 1 minute. |
| 106 | 108 |
| 107 static const char* kRelevantTokenServices[] = { | 109 static const char* kOAuth2Scopes[] = { |
|
tim (not reviewing)
2013/05/23 19:03:41
These belong in google_apis / GaiaConstants.
pavely
2013/05/30 07:42:12
Done.
Andrew T Wilson (Slow)
2013/05/31 12:57:28
That's too bad - I guess we need to move a little
| |
| 108 GaiaConstants::kSyncService | 110 "https://www.googleapis.com/auth/chromesync", |
| 111 "https://www.googleapis.com/auth/googletalk" | |
|
Andrew T Wilson (Slow)
2013/05/31 12:57:28
So, this means we *cannot* sync if the user has th
pavely
2013/06/04 00:49:59
Currently if notifications server returns auth err
| |
| 109 }; | 112 }; |
| 110 static const int kRelevantTokenServicesCount = | 113 |
| 111 arraysize(kRelevantTokenServices); | |
| 112 | 114 |
| 113 static const char* kSyncUnrecoverableErrorHistogram = | 115 static const char* kSyncUnrecoverableErrorHistogram = |
| 114 "Sync.UnrecoverableErrors"; | 116 "Sync.UnrecoverableErrors"; |
| 115 | 117 |
| 116 // Helper to check if the given token service is relevant for sync. | |
| 117 static bool IsTokenServiceRelevant(const std::string& service) { | |
| 118 for (int i = 0; i < kRelevantTokenServicesCount; ++i) { | |
| 119 if (service == kRelevantTokenServices[i]) | |
| 120 return true; | |
| 121 } | |
| 122 return false; | |
| 123 } | |
| 124 | |
| 125 bool ShouldShowActionOnUI( | 118 bool ShouldShowActionOnUI( |
| 126 const syncer::SyncProtocolError& error) { | 119 const syncer::SyncProtocolError& error) { |
| 127 return (error.action != syncer::UNKNOWN_ACTION && | 120 return (error.action != syncer::UNKNOWN_ACTION && |
| 128 error.action != syncer::DISABLE_SYNC_ON_CLIENT); | 121 error.action != syncer::DISABLE_SYNC_ON_CLIENT); |
| 129 } | 122 } |
| 130 | 123 |
| 131 ProfileSyncService::ProfileSyncService(ProfileSyncComponentsFactory* factory, | 124 ProfileSyncService::ProfileSyncService(ProfileSyncComponentsFactory* factory, |
| 132 Profile* profile, | 125 Profile* profile, |
| 133 SigninManagerBase* signin_manager, | 126 SigninManagerBase* signin_manager, |
| 134 StartBehavior start_behavior) | 127 StartBehavior start_behavior) |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 147 unrecoverable_error_reason_(ERROR_REASON_UNSET), | 140 unrecoverable_error_reason_(ERROR_REASON_UNSET), |
| 148 weak_factory_(this), | 141 weak_factory_(this), |
| 149 expect_sync_configuration_aborted_(false), | 142 expect_sync_configuration_aborted_(false), |
| 150 encrypted_types_(syncer::SyncEncryptionHandler::SensitiveTypes()), | 143 encrypted_types_(syncer::SyncEncryptionHandler::SensitiveTypes()), |
| 151 encrypt_everything_(false), | 144 encrypt_everything_(false), |
| 152 encryption_pending_(false), | 145 encryption_pending_(false), |
| 153 auto_start_enabled_(start_behavior == AUTO_START), | 146 auto_start_enabled_(start_behavior == AUTO_START), |
| 154 failed_datatypes_handler_(this), | 147 failed_datatypes_handler_(this), |
| 155 configure_status_(DataTypeManager::UNKNOWN), | 148 configure_status_(DataTypeManager::UNKNOWN), |
| 156 setup_in_progress_(false), | 149 setup_in_progress_(false), |
| 157 invalidator_state_(syncer::DEFAULT_INVALIDATION_ERROR) { | 150 invalidator_state_(syncer::DEFAULT_INVALIDATION_ERROR), |
| 151 access_token_(), | |
|
tim (not reviewing)
2013/05/23 19:03:41
Remove these two initializers as they are not nece
pavely
2013/05/30 07:42:12
Done.
| |
| 152 access_token_request_() { | |
| 158 // By default, dev, canary, and unbranded Chromium users will go to the | 153 // By default, dev, canary, and unbranded Chromium users will go to the |
| 159 // development servers. Development servers have more features than standard | 154 // development servers. Development servers have more features than standard |
| 160 // sync servers. Users with officially-branded Chrome stable and beta builds | 155 // sync servers. Users with officially-branded Chrome stable and beta builds |
| 161 // will go to the standard sync servers. | 156 // will go to the standard sync servers. |
| 162 // | 157 // |
| 163 // GetChannel hits the registry on Windows. See http://crbug.com/70380. | 158 // GetChannel hits the registry on Windows. See http://crbug.com/70380. |
| 164 base::ThreadRestrictions::ScopedAllowIO allow_io; | 159 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 165 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); | 160 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); |
| 166 if (channel == chrome::VersionInfo::CHANNEL_STABLE || | 161 if (channel == chrome::VersionInfo::CHANNEL_STABLE || |
| 167 channel == chrome::VersionInfo::CHANNEL_BETA) { | 162 channel == chrome::VersionInfo::CHANNEL_BETA) { |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 179 | 174 |
| 180 bool ProfileSyncService::IsSyncEnabledAndLoggedIn() { | 175 bool ProfileSyncService::IsSyncEnabledAndLoggedIn() { |
| 181 // Exit if sync is disabled. | 176 // Exit if sync is disabled. |
| 182 if (IsManaged() || sync_prefs_.IsStartSuppressed()) | 177 if (IsManaged() || sync_prefs_.IsStartSuppressed()) |
| 183 return false; | 178 return false; |
| 184 | 179 |
| 185 // Sync is logged in if there is a non-empty authenticated username. | 180 // Sync is logged in if there is a non-empty authenticated username. |
| 186 return !signin_->GetAuthenticatedUsername().empty(); | 181 return !signin_->GetAuthenticatedUsername().empty(); |
| 187 } | 182 } |
| 188 | 183 |
| 189 bool ProfileSyncService::IsSyncTokenAvailable() { | 184 bool ProfileSyncService::IsSyncTokenAvailable() { |
|
tim (not reviewing)
2013/05/23 19:03:41
This function should either be removed or renamed
pavely
2013/05/30 07:42:12
Done.
| |
| 190 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); | 185 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); |
| 191 if (!token_service) | 186 if (!token_service) |
| 192 return false; | 187 return false; |
| 193 return token_service->HasTokenForService(GaiaConstants::kSyncService); | 188 return token_service->HasOAuthLoginToken(); |
|
tim (not reviewing)
2013/05/23 19:03:41
Is there a better name than just "OAuthLoginToken"
Andrew T Wilson (Slow)
2013/05/24 14:10:15
I wonder if it's better to call OAuth2TokenService
pavely
2013/05/30 07:42:12
Done.
| |
| 194 } | 189 } |
| 195 #if defined(OS_ANDROID) | 190 #if defined(OS_ANDROID) |
| 196 bool ProfileSyncService::ShouldEnablePasswordSyncForAndroid() const { | 191 bool ProfileSyncService::ShouldEnablePasswordSyncForAndroid() const { |
| 197 const syncer::ModelTypeSet registered_types = GetRegisteredDataTypes(); | 192 const syncer::ModelTypeSet registered_types = GetRegisteredDataTypes(); |
| 198 const syncer::ModelTypeSet preferred_types = | 193 const syncer::ModelTypeSet preferred_types = |
| 199 sync_prefs_.GetPreferredDataTypes(registered_types); | 194 sync_prefs_.GetPreferredDataTypes(registered_types); |
| 200 if (!preferred_types.Has(syncer::PASSWORDS)) | 195 if (!preferred_types.Has(syncer::PASSWORDS)) |
| 201 return false; | 196 return false; |
| 202 // If backend has not completed initializing we cannot check if the | 197 // If backend has not completed initializing we cannot check if the |
| 203 // cryptographer is ready. | 198 // cryptographer is ready. |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 231 | 226 |
| 232 RegisterAuthNotifications(); | 227 RegisterAuthNotifications(); |
| 233 | 228 |
| 234 if (!HasSyncSetupCompleted() || signin_->GetAuthenticatedUsername().empty()) { | 229 if (!HasSyncSetupCompleted() || signin_->GetAuthenticatedUsername().empty()) { |
| 235 // Clean up in case of previous crash / setup abort / signout. | 230 // Clean up in case of previous crash / setup abort / signout. |
| 236 DisableForUser(); | 231 DisableForUser(); |
| 237 } | 232 } |
| 238 | 233 |
| 239 TrySyncDatatypePrefRecovery(); | 234 TrySyncDatatypePrefRecovery(); |
| 240 | 235 |
| 236 if (IsSyncTokenAvailable()) { | |
| 237 // Tell token service to pre-request access token. We likely don't need it | |
| 238 // right away but it will be available when we decide to initialize backend. | |
| 239 RequestAccessToken(false, false); | |
| 240 } | |
| 241 | |
| 241 TryStart(); | 242 TryStart(); |
| 242 } | 243 } |
| 243 | 244 |
| 244 void ProfileSyncService::TrySyncDatatypePrefRecovery() { | 245 void ProfileSyncService::TrySyncDatatypePrefRecovery() { |
| 245 DCHECK(!sync_initialized()); | 246 DCHECK(!sync_initialized()); |
| 246 if (!HasSyncSetupCompleted()) | 247 if (!HasSyncSetupCompleted()) |
| 247 return; | 248 return; |
| 248 | 249 |
| 249 // There was a bug where OnUserChoseDatatypes was not properly called on | 250 // There was a bug where OnUserChoseDatatypes was not properly called on |
| 250 // configuration (see crbug.com/154940). We detect this by checking whether | 251 // configuration (see crbug.com/154940). We detect this by checking whether |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 407 << "is invalid: " << value; | 408 << "is invalid: " << value; |
| 408 } | 409 } |
| 409 } | 410 } |
| 410 } | 411 } |
| 411 } | 412 } |
| 412 | 413 |
| 413 SyncCredentials ProfileSyncService::GetCredentials() { | 414 SyncCredentials ProfileSyncService::GetCredentials() { |
| 414 SyncCredentials credentials; | 415 SyncCredentials credentials; |
| 415 credentials.email = signin_->GetAuthenticatedUsername(); | 416 credentials.email = signin_->GetAuthenticatedUsername(); |
| 416 DCHECK(!credentials.email.empty()); | 417 DCHECK(!credentials.email.empty()); |
| 417 TokenService* service = TokenServiceFactory::GetForProfile(profile_); | 418 if (!access_token_.empty()) { |
|
tim (not reviewing)
2013/05/23 19:03:41
Can you explain the semantics here in a comment if
Andrew T Wilson (Slow)
2013/05/24 14:10:15
Note the varying UMAs being logged. I do wonder if
pavely
2013/05/30 07:42:12
Like it was before if access token is empty then s
pavely
2013/05/30 07:42:12
Let me explain cases that you listed:
- In tempora
Andrew T Wilson (Slow)
2013/05/31 12:57:28
Is this true? I thought that sync would generate a
| |
| 418 if (service->HasTokenForService(GaiaConstants::kSyncService)) { | 419 credentials.sync_token = access_token_; |
| 419 credentials.sync_token = service->GetTokenForService( | |
| 420 GaiaConstants::kSyncService); | |
| 421 UMA_HISTOGRAM_BOOLEAN("Sync.CredentialsLost", false); | 420 UMA_HISTOGRAM_BOOLEAN("Sync.CredentialsLost", false); |
| 422 } else { | 421 } else { |
| 423 // We've lost our sync credentials (crbug.com/121755), so just make up some | 422 // We've lost our sync credentials (crbug.com/121755), so just make up some |
| 424 // invalid credentials so the backend will generate an auth error. | 423 // invalid credentials so the backend will generate an auth error. |
| 425 UMA_HISTOGRAM_BOOLEAN("Sync.CredentialsLost", true); | 424 UMA_HISTOGRAM_BOOLEAN("Sync.CredentialsLost", true); |
| 426 credentials.sync_token = "credentials_lost"; | 425 credentials.sync_token = "credentials_lost"; |
| 427 } | 426 } |
| 428 return credentials; | 427 return credentials; |
| 429 } | 428 } |
| 430 | 429 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 492 | 491 |
| 493 void ProfileSyncService::StartUp(StartUpDeferredOption deferred_option) { | 492 void ProfileSyncService::StartUp(StartUpDeferredOption deferred_option) { |
| 494 // Don't start up multiple times. | 493 // Don't start up multiple times. |
| 495 if (backend_) { | 494 if (backend_) { |
| 496 DVLOG(1) << "Skipping bringing up backend host."; | 495 DVLOG(1) << "Skipping bringing up backend host."; |
| 497 return; | 496 return; |
| 498 } | 497 } |
| 499 | 498 |
| 500 DCHECK(IsSyncEnabledAndLoggedIn()); | 499 DCHECK(IsSyncEnabledAndLoggedIn()); |
| 501 | 500 |
| 501 if (access_token_.empty()) { | |
|
tim (not reviewing)
2013/05/23 19:03:41
The relationship between TryStart and StartUp is t
pavely
2013/05/30 07:42:12
TryStart gathers all local information to decide i
| |
| 502 RequestAccessToken(false, true); | |
|
Andrew T Wilson (Slow)
2013/05/31 12:57:28
Should we only do this if deferred_option = STARTU
| |
| 503 return; | |
| 504 } | |
| 505 | |
| 502 last_synced_time_ = sync_prefs_.GetLastSyncedTime(); | 506 last_synced_time_ = sync_prefs_.GetLastSyncedTime(); |
| 503 | 507 |
| 504 DCHECK(start_up_time_.is_null()); | 508 DCHECK(start_up_time_.is_null()); |
| 505 start_up_time_ = base::Time::Now(); | 509 start_up_time_ = base::Time::Now(); |
| 506 | 510 |
| 507 #if defined(OS_CHROMEOS) | 511 #if defined(OS_CHROMEOS) |
| 508 std::string bootstrap_token = sync_prefs_.GetEncryptionBootstrapToken(); | 512 std::string bootstrap_token = sync_prefs_.GetEncryptionBootstrapToken(); |
| 509 if (bootstrap_token.empty()) { | 513 if (bootstrap_token.empty()) { |
| 510 sync_prefs_.SetEncryptionBootstrapToken( | 514 sync_prefs_.SetEncryptionBootstrapToken( |
| 511 sync_prefs_.GetSpareBootstrapToken()); | 515 sync_prefs_.GetSpareBootstrapToken()); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 600 // If |backend_| is NULL, save the acknowledgements to replay when | 604 // If |backend_| is NULL, save the acknowledgements to replay when |
| 601 // it's created and initialized. | 605 // it's created and initialized. |
| 602 ack_replay_queue_.push_back(std::make_pair(id, ack_handle)); | 606 ack_replay_queue_.push_back(std::make_pair(id, ack_handle)); |
| 603 } | 607 } |
| 604 } | 608 } |
| 605 | 609 |
| 606 syncer::InvalidatorState ProfileSyncService::GetInvalidatorState() const { | 610 syncer::InvalidatorState ProfileSyncService::GetInvalidatorState() const { |
| 607 return invalidator_registrar_->GetInvalidatorState(); | 611 return invalidator_registrar_->GetInvalidatorState(); |
| 608 } | 612 } |
| 609 | 613 |
| 614 void ProfileSyncService::OnGetTokenSuccess( | |
| 615 const OAuth2TokenService::Request* request, | |
| 616 const std::string& access_token, | |
| 617 const base::Time& expiration_time) { | |
| 618 access_token_request_.reset(); | |
|
tim (not reviewing)
2013/05/23 19:03:42
DCHECK(access_token_request_.get()) in both these
Andrew T Wilson (Slow)
2013/05/24 14:10:15
Actually, I think you should do DCHECK_EQ(access_t
pavely
2013/05/30 07:42:12
Done.
| |
| 619 access_token_ = access_token; | |
| 620 if (backend_) | |
| 621 backend_->UpdateCredentials(GetCredentials()); | |
| 622 else | |
| 623 TryStart(); | |
| 624 } | |
| 625 | |
| 626 void ProfileSyncService::OnGetTokenFailure( | |
| 627 const OAuth2TokenService::Request* request, | |
| 628 const GoogleServiceAuthError& error) { | |
| 629 access_token_request_.reset(); | |
| 630 UpdateAuthErrorState(error); | |
| 631 } | |
| 632 | |
| 610 void ProfileSyncService::EmitInvalidationForTest( | 633 void ProfileSyncService::EmitInvalidationForTest( |
| 611 const invalidation::ObjectId& id, | 634 const invalidation::ObjectId& id, |
| 612 const std::string& payload) { | 635 const std::string& payload) { |
| 613 syncer::ObjectIdSet notify_ids; | 636 syncer::ObjectIdSet notify_ids; |
| 614 notify_ids.insert(id); | 637 notify_ids.insert(id); |
| 615 | 638 |
| 616 const syncer::ObjectIdInvalidationMap& invalidation_map = | 639 const syncer::ObjectIdInvalidationMap& invalidation_map = |
| 617 ObjectIdSetToInvalidationMap(notify_ids, payload); | 640 ObjectIdSetToInvalidationMap(notify_ids, payload); |
| 618 OnIncomingInvalidation(invalidation_map); | 641 OnIncomingInvalidation(invalidation_map); |
| 619 } | 642 } |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1022 default: | 1045 default: |
| 1023 NOTREACHED(); | 1046 NOTREACHED(); |
| 1024 return AuthError(AuthError::CONNECTION_FAILED); | 1047 return AuthError(AuthError::CONNECTION_FAILED); |
| 1025 } | 1048 } |
| 1026 } | 1049 } |
| 1027 | 1050 |
| 1028 } // namespace | 1051 } // namespace |
| 1029 | 1052 |
| 1030 void ProfileSyncService::OnConnectionStatusChange( | 1053 void ProfileSyncService::OnConnectionStatusChange( |
| 1031 syncer::ConnectionStatus status) { | 1054 syncer::ConnectionStatus status) { |
| 1032 const GoogleServiceAuthError auth_error = | 1055 if (status == syncer::CONNECTION_AUTH_ERROR) { |
|
tim (not reviewing)
2013/05/23 19:03:42
Comment this - is this known to be a transient acc
pavely
2013/05/30 07:42:12
Done.
| |
| 1033 ConnectionStatusToAuthError(status); | 1056 RequestAccessToken(true, true); |
| 1034 DVLOG(1) << "Connection status change: " << auth_error.ToString(); | 1057 } else { |
| 1035 UpdateAuthErrorState(auth_error); | 1058 const GoogleServiceAuthError auth_error = |
| 1059 ConnectionStatusToAuthError(status); | |
| 1060 DVLOG(1) << "Connection status change: " << auth_error.ToString(); | |
| 1061 UpdateAuthErrorState(auth_error); | |
| 1062 } | |
| 1036 } | 1063 } |
| 1037 | 1064 |
| 1038 void ProfileSyncService::OnStopSyncingPermanently() { | 1065 void ProfileSyncService::OnStopSyncingPermanently() { |
| 1039 UpdateAuthErrorState(AuthError(AuthError::SERVICE_UNAVAILABLE)); | 1066 UpdateAuthErrorState(AuthError(AuthError::SERVICE_UNAVAILABLE)); |
| 1040 sync_prefs_.SetStartSuppressed(true); | 1067 sync_prefs_.SetStartSuppressed(true); |
| 1041 DisableForUser(); | 1068 DisableForUser(); |
| 1042 // If signout is allowed, signout the user on a dashboard clear. | 1069 // If signout is allowed, signout the user on a dashboard clear. |
| 1043 if (!auto_start_enabled_) // Skip signout on ChromeOS/Android. | 1070 if (!auto_start_enabled_) // Skip signout on ChromeOS/Android. |
| 1044 signin_->SignOut(); | 1071 signin_->SignOut(); |
| 1045 } | 1072 } |
| (...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1770 } | 1797 } |
| 1771 } | 1798 } |
| 1772 | 1799 |
| 1773 // If we get here, we don't have pending keys (or at least, the passphrase | 1800 // If we get here, we don't have pending keys (or at least, the passphrase |
| 1774 // doesn't decrypt them) - just try to re-encrypt using the encryption | 1801 // doesn't decrypt them) - just try to re-encrypt using the encryption |
| 1775 // passphrase. | 1802 // passphrase. |
| 1776 if (!IsUsingSecondaryPassphrase()) | 1803 if (!IsUsingSecondaryPassphrase()) |
| 1777 SetEncryptionPassphrase(passphrase, IMPLICIT); | 1804 SetEncryptionPassphrase(passphrase, IMPLICIT); |
| 1778 } | 1805 } |
| 1779 | 1806 |
| 1807 void ProfileSyncService::RequestAccessToken( | |
| 1808 bool invalidate_previous_token, | |
| 1809 bool invoke_callback) | |
| 1810 { | |
|
tim (not reviewing)
2013/05/23 19:03:42
nit: { on previous line.
pavely
2013/05/30 07:42:12
Done.
| |
| 1811 // Only one active request at a time. | |
| 1812 if (access_token_request_ != NULL) | |
|
tim (not reviewing)
2013/05/23 19:03:42
Think this should be a DCHECK?
Andrew T Wilson (Slow)
2013/05/24 14:10:15
I think this can happen in practice - there's noth
pavely
2013/05/30 07:42:12
Yes, there could be multiple calls to RequestAcces
| |
| 1813 return; | |
| 1814 OAuth2TokenService::ScopeSet oauth2_scopes; | |
| 1815 for (size_t i = 0; i < arraysize(kOAuth2Scopes); i++) | |
| 1816 oauth2_scopes.insert(kOAuth2Scopes[i]); | |
| 1817 OAuth2TokenService* token_service = | |
| 1818 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); | |
| 1819 if (invalidate_previous_token) { | |
| 1820 // Invalidate previous token, othervise token service will return the same | |
| 1821 // token again | |
| 1822 token_service->InvalidateToken(oauth2_scopes, access_token_); | |
| 1823 access_token_ = std::string(); | |
|
tim (not reviewing)
2013/05/23 19:03:42
use access_token_.clear()
pavely
2013/05/30 07:42:12
Done.
| |
| 1824 } | |
| 1825 access_token_request_ = token_service->StartRequest(oauth2_scopes, this); | |
| 1826 if (!invoke_callback) { | |
| 1827 // Deleting request will not cancel RPC but callbacks won't be invoked. | |
| 1828 access_token_request_.reset(); | |
|
Andrew T Wilson (Slow)
2013/05/24 14:10:15
I am confused by this - on startup, won't this cau
pavely
2013/05/30 07:42:12
I discussed this with Tim, the question was whenev
Andrew T Wilson (Slow)
2013/05/31 12:57:28
Is this a real concern? I didn't think we were tha
| |
| 1829 } | |
| 1830 } | |
| 1831 | |
| 1780 void ProfileSyncService::SetEncryptionPassphrase(const std::string& passphrase, | 1832 void ProfileSyncService::SetEncryptionPassphrase(const std::string& passphrase, |
| 1781 PassphraseType type) { | 1833 PassphraseType type) { |
| 1782 // This should only be called when the backend has been initialized. | 1834 // This should only be called when the backend has been initialized. |
| 1783 DCHECK(sync_initialized()); | 1835 DCHECK(sync_initialized()); |
| 1784 DCHECK(!(type == IMPLICIT && IsUsingSecondaryPassphrase())) << | 1836 DCHECK(!(type == IMPLICIT && IsUsingSecondaryPassphrase())) << |
| 1785 "Data is already encrypted using an explicit passphrase"; | 1837 "Data is already encrypted using an explicit passphrase"; |
| 1786 DCHECK(!(type == EXPLICIT && | 1838 DCHECK(!(type == EXPLICIT && |
| 1787 passphrase_required_reason_ == syncer::REASON_DECRYPTION)) << | 1839 passphrase_required_reason_ == syncer::REASON_DECRYPTION)) << |
| 1788 "Can not set explicit passphrase when decryption is needed."; | 1840 "Can not set explicit passphrase when decryption is needed."; |
| 1789 | 1841 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1876 GetAuthError().state() != AuthError::NONE) { | 1928 GetAuthError().state() != AuthError::NONE) { |
| 1877 // Track the fact that we're still waiting for auth to complete. | 1929 // Track the fact that we're still waiting for auth to complete. |
| 1878 is_auth_in_progress_ = true; | 1930 is_auth_in_progress_ = true; |
| 1879 } | 1931 } |
| 1880 break; | 1932 break; |
| 1881 } | 1933 } |
| 1882 case chrome::NOTIFICATION_TOKEN_REQUEST_FAILED: { | 1934 case chrome::NOTIFICATION_TOKEN_REQUEST_FAILED: { |
| 1883 const TokenService::TokenRequestFailedDetails& token_details = | 1935 const TokenService::TokenRequestFailedDetails& token_details = |
| 1884 *(content::Details<const TokenService::TokenRequestFailedDetails>( | 1936 *(content::Details<const TokenService::TokenRequestFailedDetails>( |
| 1885 details).ptr()); | 1937 details).ptr()); |
| 1886 if (IsTokenServiceRelevant(token_details.service()) && | 1938 if (token_details.service() == |
| 1939 GaiaConstants::kGaiaOAuth2LoginRefreshToken && | |
|
Andrew T Wilson (Slow)
2013/05/24 14:10:15
I'd really like to see us get out of the "listen f
pavely
2013/05/30 07:42:12
Done.
| |
| 1887 !IsSyncTokenAvailable()) { | 1940 !IsSyncTokenAvailable()) { |
| 1888 // The additional check around IsSyncTokenAvailable() above prevents us | 1941 // The additional check around IsSyncTokenAvailable() above prevents us |
| 1889 // sounding the alarm if we actually have a valid token but a refresh | 1942 // sounding the alarm if we actually have a valid token but a refresh |
| 1890 // attempt by TokenService failed for any variety of reasons (e.g. flaky | 1943 // attempt by TokenService failed for any variety of reasons (e.g. flaky |
| 1891 // network). It's possible the token we do have is also invalid, but in | 1944 // network). It's possible the token we do have is also invalid, but in |
| 1892 // that case we should already have (or can expect) an auth error sent | 1945 // that case we should already have (or can expect) an auth error sent |
| 1893 // from the sync backend. | 1946 // from the sync backend. |
| 1894 AuthError error(AuthError::INVALID_GAIA_CREDENTIALS); | 1947 AuthError error(AuthError::INVALID_GAIA_CREDENTIALS); |
| 1895 UpdateAuthErrorState(error); | 1948 UpdateAuthErrorState(error); |
| 1896 } | 1949 } |
| 1897 break; | 1950 break; |
| 1898 } | 1951 } |
| 1899 case chrome::NOTIFICATION_TOKEN_AVAILABLE: { | 1952 case chrome::NOTIFICATION_TOKEN_AVAILABLE: { |
| 1900 const TokenService::TokenAvailableDetails& token_details = | 1953 const TokenService::TokenAvailableDetails& token_details = |
| 1901 *(content::Details<const TokenService::TokenAvailableDetails>( | 1954 *(content::Details<const TokenService::TokenAvailableDetails>( |
| 1902 details).ptr()); | 1955 details).ptr()); |
| 1903 if (!IsTokenServiceRelevant(token_details.service())) | 1956 if (token_details.service() != |
| 1957 GaiaConstants::kGaiaOAuth2LoginRefreshToken) | |
|
Andrew T Wilson (Slow)
2013/05/24 14:10:15
We should really move NOTIFICATION_TOKEN_AVAILABLE
pavely
2013/05/30 07:42:12
Done.
| |
| 1904 break; | 1958 break; |
| 1905 } // Fall through. | 1959 } // Fall through. |
| 1906 case chrome::NOTIFICATION_TOKEN_LOADING_FINISHED: { | 1960 case chrome::NOTIFICATION_TOKEN_LOADING_FINISHED: { |
| 1907 // This notification gets fired when TokenService loads the tokens | 1961 // This notification gets fired when TokenService loads the tokens |
| 1908 // from storage. | 1962 // from storage. |
| 1909 // Initialize the backend if sync is enabled. If the sync token was | 1963 // Initialize the backend if sync is enabled. If the sync token was |
| 1910 // not loaded, GetCredentials() will generate invalid credentials to | 1964 // not loaded, GetCredentials() will generate invalid credentials to |
| 1911 // cause the backend to generate an auth error (crbug.com/121755). | 1965 // cause the backend to generate an auth error (crbug.com/121755). |
| 1912 if (backend_) | 1966 if (backend_) |
| 1913 backend_->UpdateCredentials(GetCredentials()); | 1967 RequestAccessToken(true, true); |
| 1914 else | 1968 else |
| 1969 RequestAccessToken(true, false); | |
| 1915 TryStart(); | 1970 TryStart(); |
| 1916 break; | 1971 break; |
| 1917 } | 1972 } |
| 1918 case chrome::NOTIFICATION_TOKENS_CLEARED: { | 1973 case chrome::NOTIFICATION_TOKENS_CLEARED: { |
| 1919 // GetCredentials() will generate invalid credentials to cause the backend | 1974 // GetCredentials() will generate invalid credentials to cause the backend |
| 1920 // to generate an auth error. | 1975 // to generate an auth error. |
| 1976 access_token_ = std::string(); | |
|
tim (not reviewing)
2013/05/23 19:03:42
use .clear()
pavely
2013/05/30 07:42:12
Done.
| |
| 1921 if (backend_) | 1977 if (backend_) |
| 1922 backend_->UpdateCredentials(GetCredentials()); | 1978 backend_->UpdateCredentials(GetCredentials()); |
| 1923 break; | 1979 break; |
| 1924 } | 1980 } |
| 1925 case chrome::NOTIFICATION_GOOGLE_SIGNED_OUT: | 1981 case chrome::NOTIFICATION_GOOGLE_SIGNED_OUT: |
| 1926 // Disable sync if the user is signed out. | 1982 // Disable sync if the user is signed out. |
| 1927 DisableForUser(); | 1983 DisableForUser(); |
| 1928 break; | 1984 break; |
| 1929 default: { | 1985 default: { |
| 1930 NOTREACHED(); | 1986 NOTREACHED(); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2058 // See http://stackoverflow.com/questions/6224121/is-new-this-myclass-undefine d-behaviour-after-directly-calling-the-destru. | 2114 // See http://stackoverflow.com/questions/6224121/is-new-this-myclass-undefine d-behaviour-after-directly-calling-the-destru. |
| 2059 ProfileSyncService* old_this = this; | 2115 ProfileSyncService* old_this = this; |
| 2060 this->~ProfileSyncService(); | 2116 this->~ProfileSyncService(); |
| 2061 new(old_this) ProfileSyncService( | 2117 new(old_this) ProfileSyncService( |
| 2062 new ProfileSyncComponentsFactoryImpl(profile, | 2118 new ProfileSyncComponentsFactoryImpl(profile, |
| 2063 CommandLine::ForCurrentProcess()), | 2119 CommandLine::ForCurrentProcess()), |
| 2064 profile, | 2120 profile, |
| 2065 signin, | 2121 signin, |
| 2066 behavior); | 2122 behavior); |
| 2067 } | 2123 } |
| OLD | NEW |