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

Side by Side Diff: components/browser_sync/browser/profile_sync_service.cc

Issue 2159453002: [Sync] Don't start up sync when FirstSetupCompleted is false and no setup in progress (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Self review Created 4 years, 5 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 "components/browser_sync/browser/profile_sync_service.h" 5 #include "components/browser_sync/browser/profile_sync_service.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <cstddef> 8 #include <cstddef>
9 #include <map> 9 #include <map>
10 #include <utility> 10 #include <utility>
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 DCHECK(sync_error_controller_ == NULL) 374 DCHECK(sync_error_controller_ == NULL)
375 << "Initialize() called more than once."; 375 << "Initialize() called more than once.";
376 sync_error_controller_.reset(new SyncErrorController(this)); 376 sync_error_controller_.reset(new SyncErrorController(this));
377 AddObserver(sync_error_controller_.get()); 377 AddObserver(sync_error_controller_.get());
378 #endif 378 #endif
379 379
380 memory_pressure_listener_.reset(new base::MemoryPressureListener( 380 memory_pressure_listener_.reset(new base::MemoryPressureListener(
381 base::Bind(&ProfileSyncService::OnMemoryPressure, 381 base::Bind(&ProfileSyncService::OnMemoryPressure,
382 sync_enabled_weak_factory_.GetWeakPtr()))); 382 sync_enabled_weak_factory_.GetWeakPtr())));
383 startup_controller_->Reset(GetRegisteredDataTypes()); 383 startup_controller_->Reset(GetRegisteredDataTypes());
384 startup_controller_->TryStart(); 384
385 // Auto-start means IsFirstSetupComplete gets set automatically, and the
386 // first startup should be immediate, not deferred.
387 if (start_behavior_ == AUTO_START && !IsFirstSetupComplete()) {
388 SetFirstSetupComplete();
389 startup_controller_->TryStart(true);
390 } else {
391 startup_controller_->TryStart(false);
392 }
385 } 393 }
386 394
387 void ProfileSyncService::StartSyncingWithServer() { 395 void ProfileSyncService::StartSyncingWithServer() {
388 DCHECK(thread_checker_.CalledOnValidThread()); 396 DCHECK(thread_checker_.CalledOnValidThread());
389 397
390 if (base::FeatureList::IsEnabled( 398 if (base::FeatureList::IsEnabled(
391 switches::kSyncClearDataOnPassphraseEncryption) && 399 switches::kSyncClearDataOnPassphraseEncryption) &&
392 sync_prefs_.GetPassphraseEncryptionTransitionInProgress()) { 400 sync_prefs_.GetPassphraseEncryptionTransitionInProgress()) {
393 BeginConfigureCatchUpBeforeClear(); 401 BeginConfigureCatchUpBeforeClear();
394 return; 402 return;
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 token_receive_time_ = base::Time::Now(); 627 token_receive_time_ = base::Time::Now();
620 last_get_token_error_ = GoogleServiceAuthError::AuthErrorNone(); 628 last_get_token_error_ = GoogleServiceAuthError::AuthErrorNone();
621 629
622 if (sync_prefs_.SyncHasAuthError()) { 630 if (sync_prefs_.SyncHasAuthError()) {
623 sync_prefs_.SetSyncAuthError(false); 631 sync_prefs_.SetSyncAuthError(false);
624 } 632 }
625 633
626 if (HasSyncingBackend()) 634 if (HasSyncingBackend())
627 backend_->UpdateCredentials(GetCredentials()); 635 backend_->UpdateCredentials(GetCredentials());
628 else 636 else
629 startup_controller_->TryStart(); 637 startup_controller_->TryStart(false);
630 } 638 }
631 639
632 void ProfileSyncService::OnGetTokenFailure( 640 void ProfileSyncService::OnGetTokenFailure(
633 const OAuth2TokenService::Request* request, 641 const OAuth2TokenService::Request* request,
634 const GoogleServiceAuthError& error) { 642 const GoogleServiceAuthError& error) {
635 DCHECK_EQ(access_token_request_.get(), request); 643 DCHECK_EQ(access_token_request_.get(), request);
636 DCHECK_NE(error.state(), GoogleServiceAuthError::NONE); 644 DCHECK_NE(error.state(), GoogleServiceAuthError::NONE);
637 access_token_request_.reset(); 645 access_token_request_.reset();
638 last_get_token_error_ = error; 646 last_get_token_error_ = error;
639 switch (error.state()) { 647 switch (error.state()) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 702
695 void ProfileSyncService::OnRefreshTokensLoaded() { 703 void ProfileSyncService::OnRefreshTokensLoaded() {
696 // This notification gets fired when OAuth2TokenService loads the tokens 704 // This notification gets fired when OAuth2TokenService loads the tokens
697 // from storage. 705 // from storage.
698 // Initialize the backend if sync is enabled. If the sync token was 706 // Initialize the backend if sync is enabled. If the sync token was
699 // not loaded, GetCredentials() will generate invalid credentials to 707 // not loaded, GetCredentials() will generate invalid credentials to
700 // cause the backend to generate an auth error (crbug.com/121755). 708 // cause the backend to generate an auth error (crbug.com/121755).
701 if (HasSyncingBackend()) { 709 if (HasSyncingBackend()) {
702 RequestAccessToken(); 710 RequestAccessToken();
703 } else { 711 } else {
704 startup_controller_->TryStart(); 712 startup_controller_->TryStart(false);
705 } 713 }
706 } 714 }
707 715
708 void ProfileSyncService::Shutdown() { 716 void ProfileSyncService::Shutdown() {
709 UnregisterAuthNotifications(); 717 UnregisterAuthNotifications();
710 718
711 ShutdownImpl(syncer::BROWSER_SHUTDOWN); 719 ShutdownImpl(syncer::BROWSER_SHUTDOWN);
712 if (sync_error_controller_) { 720 if (sync_error_controller_) {
713 // Destroy the SyncErrorController when the service shuts down for good. 721 // Destroy the SyncErrorController when the service shuts down for good.
714 RemoveObserver(sync_error_controller_.get()); 722 RemoveObserver(sync_error_controller_.get());
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
941 // case this operation affects the "passphrase required" status. 949 // case this operation affects the "passphrase required" status.
942 ConsumeCachedPassphraseIfPossible(); 950 ConsumeCachedPassphraseIfPossible();
943 951
944 // The very first time the backend initializes is effectively the first time 952 // The very first time the backend initializes is effectively the first time
945 // we can say we successfully "synced". LastSyncedTime will only be null in 953 // we can say we successfully "synced". LastSyncedTime will only be null in
946 // this case, because the pref wasn't restored on StartUp. 954 // this case, because the pref wasn't restored on StartUp.
947 if (sync_prefs_.GetLastSyncedTime().is_null()) { 955 if (sync_prefs_.GetLastSyncedTime().is_null()) {
948 UpdateLastSyncedTime(); 956 UpdateLastSyncedTime();
949 } 957 }
950 958
951 // Auto-start means IsFirstSetupComplete gets set automatically. 959 if (CanConfigureDataTypes())
952 if (start_behavior_ == AUTO_START && !IsFirstSetupComplete()) {
953 // This will trigger a configure if it completes setup.
954 SetFirstSetupComplete();
955 } else if (CanConfigureDataTypes()) {
956 ConfigureDataTypeManager(); 960 ConfigureDataTypeManager();
957 }
958 961
959 // Check for a cookie jar mismatch. 962 // Check for a cookie jar mismatch.
960 std::vector<gaia::ListedAccount> accounts; 963 std::vector<gaia::ListedAccount> accounts;
961 std::vector<gaia::ListedAccount> signed_out_accounts; 964 std::vector<gaia::ListedAccount> signed_out_accounts;
962 GoogleServiceAuthError error(GoogleServiceAuthError::NONE); 965 GoogleServiceAuthError error(GoogleServiceAuthError::NONE);
963 if (gaia_cookie_manager_service_ && 966 if (gaia_cookie_manager_service_ &&
964 gaia_cookie_manager_service_->ListAccounts( 967 gaia_cookie_manager_service_->ListAccounts(
965 &accounts, &signed_out_accounts)) { 968 &accounts, &signed_out_accounts)) {
966 OnGaiaAccountsInCookieUpdated(accounts, signed_out_accounts, error); 969 OnGaiaAccountsInCookieUpdated(accounts, signed_out_accounts, error);
967 } 970 }
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
1258 #endif 1261 #endif
1259 break; 1262 break;
1260 case syncer::STOP_SYNC_FOR_DISABLED_ACCOUNT: 1263 case syncer::STOP_SYNC_FOR_DISABLED_ACCOUNT:
1261 // Sync disabled by domain admin. we should stop syncing until next 1264 // Sync disabled by domain admin. we should stop syncing until next
1262 // restart. 1265 // restart.
1263 sync_disabled_by_admin_ = true; 1266 sync_disabled_by_admin_ = true;
1264 ShutdownImpl(syncer::DISABLE_SYNC); 1267 ShutdownImpl(syncer::DISABLE_SYNC);
1265 break; 1268 break;
1266 case syncer::RESET_LOCAL_SYNC_DATA: 1269 case syncer::RESET_LOCAL_SYNC_DATA:
1267 ShutdownImpl(syncer::DISABLE_SYNC); 1270 ShutdownImpl(syncer::DISABLE_SYNC);
1268 startup_controller_->TryStart(); 1271 startup_controller_->TryStart(false);
1269 break; 1272 break;
1270 default: 1273 default:
1271 NOTREACHED(); 1274 NOTREACHED();
1272 } 1275 }
1273 NotifyObservers(); 1276 NotifyObservers();
1274 } 1277 }
1275 1278
1276 void ProfileSyncService::OnLocalSetPassphraseEncryption( 1279 void ProfileSyncService::OnLocalSetPassphraseEncryption(
1277 const syncer::SyncEncryptionHandler::NigoriState& nigori_state) { 1280 const syncer::SyncEncryptionHandler::NigoriState& nigori_state) {
1278 DCHECK(thread_checker_.CalledOnValidThread()); 1281 DCHECK(thread_checker_.CalledOnValidThread());
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1310 DCHECK(sync_prefs_.GetPassphraseEncryptionTransitionInProgress()); 1313 DCHECK(sync_prefs_.GetPassphraseEncryptionTransitionInProgress());
1311 sync_prefs_.SetPassphraseEncryptionTransitionInProgress(false); 1314 sync_prefs_.SetPassphraseEncryptionTransitionInProgress(false);
1312 1315
1313 // Call to ClearServerData generates new keystore key on the server. This 1316 // Call to ClearServerData generates new keystore key on the server. This
1314 // makes keystore bootstrap token invalid. Let's clear it from preferences. 1317 // makes keystore bootstrap token invalid. Let's clear it from preferences.
1315 sync_prefs_.SetKeystoreEncryptionBootstrapToken(std::string()); 1318 sync_prefs_.SetKeystoreEncryptionBootstrapToken(std::string());
1316 1319
1317 // Shutdown sync, delete the Directory, then restart, restoring the cached 1320 // Shutdown sync, delete the Directory, then restart, restoring the cached
1318 // nigori state. 1321 // nigori state.
1319 ShutdownImpl(syncer::DISABLE_SYNC); 1322 ShutdownImpl(syncer::DISABLE_SYNC);
1320 startup_controller_->TryStart(); 1323 startup_controller_->TryStart(true);
1321 } 1324 }
1322 1325
1323 void ProfileSyncService::OnConfigureDone( 1326 void ProfileSyncService::OnConfigureDone(
1324 const DataTypeManager::ConfigureResult& result) { 1327 const DataTypeManager::ConfigureResult& result) {
1325 configure_status_ = result.status; 1328 configure_status_ = result.status;
1326 data_type_status_table_ = result.data_type_status_table; 1329 data_type_status_table_ = result.data_type_status_table;
1327 1330
1328 // We should have cleared our cached passphrase before we get here (in 1331 // We should have cleared our cached passphrase before we get here (in
1329 // OnBackendInitialized()). 1332 // OnBackendInitialized()).
1330 DCHECK(cached_passphrase_.empty()); 1333 DCHECK(cached_passphrase_.empty());
(...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after
2057 // We may be called during the setup process before we're 2060 // We may be called during the setup process before we're
2058 // initialized. In this case, we default to the sensitive types. 2061 // initialized. In this case, we default to the sensitive types.
2059 return encrypted_types_; 2062 return encrypted_types_;
2060 } 2063 }
2061 2064
2062 void ProfileSyncService::OnSyncManagedPrefChange(bool is_sync_managed) { 2065 void ProfileSyncService::OnSyncManagedPrefChange(bool is_sync_managed) {
2063 if (is_sync_managed) { 2066 if (is_sync_managed) {
2064 StopImpl(CLEAR_DATA); 2067 StopImpl(CLEAR_DATA);
2065 } else { 2068 } else {
2066 // Sync is no longer disabled by policy. Try starting it up if appropriate. 2069 // Sync is no longer disabled by policy. Try starting it up if appropriate.
2067 startup_controller_->TryStart(); 2070 startup_controller_->TryStart(true);
2068 } 2071 }
2069 } 2072 }
2070 2073
2071 void ProfileSyncService::GoogleSigninSucceeded(const std::string& account_id, 2074 void ProfileSyncService::GoogleSigninSucceeded(const std::string& account_id,
2072 const std::string& username, 2075 const std::string& username,
2073 const std::string& password) { 2076 const std::string& password) {
2074 if (IsSyncRequested() && !password.empty()) { 2077 if (IsSyncRequested() && !password.empty()) {
2075 cached_passphrase_ = password; 2078 cached_passphrase_ = password;
2076 // Try to consume the passphrase we just cached. If the sync backend 2079 // Try to consume the passphrase we just cached. If the sync backend
2077 // is not running yet, the passphrase will remain cached until the 2080 // is not running yet, the passphrase will remain cached until the
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
2328 void ProfileSyncService::RequestStart() { 2331 void ProfileSyncService::RequestStart() {
2329 if (!IsSyncAllowed()) { 2332 if (!IsSyncAllowed()) {
2330 // Sync cannot be requested if it's not allowed. 2333 // Sync cannot be requested if it's not allowed.
2331 return; 2334 return;
2332 } 2335 }
2333 DCHECK(sync_client_); 2336 DCHECK(sync_client_);
2334 if (!IsSyncRequested()) { 2337 if (!IsSyncRequested()) {
2335 sync_prefs_.SetSyncRequested(true); 2338 sync_prefs_.SetSyncRequested(true);
2336 NotifyObservers(); 2339 NotifyObservers();
2337 } 2340 }
2338 startup_controller_->TryStart(); 2341 startup_controller_->TryStart(true);
2339 } 2342 }
2340 2343
2341 void ProfileSyncService::ReconfigureDatatypeManager() { 2344 void ProfileSyncService::ReconfigureDatatypeManager() {
2342 // If we haven't initialized yet, don't configure the DTM as it could cause 2345 // If we haven't initialized yet, don't configure the DTM as it could cause
2343 // association to start before a Directory has even been created. 2346 // association to start before a Directory has even been created.
2344 if (backend_initialized_) { 2347 if (backend_initialized_) {
2345 DCHECK(backend_.get()); 2348 DCHECK(backend_.get());
2346 ConfigureDataTypeManager(); 2349 ConfigureDataTypeManager();
2347 } else if (HasUnrecoverableError()) { 2350 } else if (HasUnrecoverableError()) {
2348 // There is nothing more to configure. So inform the listeners, 2351 // There is nothing more to configure. So inform the listeners,
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
2526 if (--outstanding_setup_in_progress_handles_ != 0) 2529 if (--outstanding_setup_in_progress_handles_ != 0)
2527 return; 2530 return;
2528 2531
2529 DCHECK(startup_controller_->IsSetupInProgress()); 2532 DCHECK(startup_controller_->IsSetupInProgress());
2530 startup_controller_->SetSetupInProgress(false); 2533 startup_controller_->SetSetupInProgress(false);
2531 2534
2532 if (IsBackendInitialized()) 2535 if (IsBackendInitialized())
2533 ReconfigureDatatypeManager(); 2536 ReconfigureDatatypeManager();
2534 NotifyObservers(); 2537 NotifyObservers();
2535 } 2538 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698