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

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

Issue 1575153004: [Sync] Simplify sync startup behavior. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@setup
Patch Set: Better comment + tests. Created 4 years, 10 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 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 } 243 }
244 244
245 bool ProfileSyncService::CanSyncStart() const { 245 bool ProfileSyncService::CanSyncStart() const {
246 return IsSyncAllowed() && IsSyncRequested() && IsSignedIn(); 246 return IsSyncAllowed() && IsSyncRequested() && IsSignedIn();
247 } 247 }
248 248
249 void ProfileSyncService::Initialize() { 249 void ProfileSyncService::Initialize() {
250 sync_client_->Initialize(); 250 sync_client_->Initialize();
251 251
252 startup_controller_.reset(new browser_sync::StartupController( 252 startup_controller_.reset(new browser_sync::StartupController(
253 start_behavior_, oauth2_token_service_, &sync_prefs_, signin_.get(), 253 oauth2_token_service_, &sync_prefs_, signin_.get(),
254 base::Bind(&ProfileSyncService::StartUpSlowBackendComponents, 254 base::Bind(&ProfileSyncService::StartUpSlowBackendComponents,
255 startup_controller_weak_factory_.GetWeakPtr()))); 255 startup_controller_weak_factory_.GetWeakPtr())));
256 scoped_ptr<browser_sync::LocalSessionEventRouter> router( 256 scoped_ptr<browser_sync::LocalSessionEventRouter> router(
257 sync_client_->GetSyncSessionsClient()->GetLocalSessionEventRouter()); 257 sync_client_->GetSyncSessionsClient()->GetLocalSessionEventRouter());
258 local_device_ = sync_client_->GetSyncApiComponentFactory() 258 local_device_ = sync_client_->GetSyncApiComponentFactory()
259 ->CreateLocalDeviceInfoProvider(); 259 ->CreateLocalDeviceInfoProvider();
260 sync_stopped_reporter_.reset(new browser_sync::SyncStoppedReporter( 260 sync_stopped_reporter_.reset(new browser_sync::SyncStoppedReporter(
261 sync_service_url_, local_device_->GetSyncUserAgent(), 261 sync_service_url_, local_device_->GetSyncUserAgent(),
262 url_request_context_, 262 url_request_context_,
263 browser_sync::SyncStoppedReporter::ResultCallback())); 263 browser_sync::SyncStoppedReporter::ResultCallback()));
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after
808 break; 808 break;
809 } 809 }
810 } 810 }
811 811
812 bool ProfileSyncService::IsFirstSetupComplete() const { 812 bool ProfileSyncService::IsFirstSetupComplete() const {
813 return sync_prefs_.IsFirstSetupComplete(); 813 return sync_prefs_.IsFirstSetupComplete();
814 } 814 }
815 815
816 void ProfileSyncService::SetFirstSetupComplete() { 816 void ProfileSyncService::SetFirstSetupComplete() {
817 sync_prefs_.SetFirstSetupComplete(); 817 sync_prefs_.SetFirstSetupComplete();
818 if (IsBackendInitialized()) {
819 ReconfigureDatatypeManager();
820 }
818 } 821 }
819 822
820 void ProfileSyncService::UpdateLastSyncedTime() { 823 void ProfileSyncService::UpdateLastSyncedTime() {
821 sync_prefs_.SetLastSyncedTime(base::Time::Now()); 824 sync_prefs_.SetLastSyncedTime(base::Time::Now());
822 } 825 }
823 826
824 void ProfileSyncService::NotifyObservers() { 827 void ProfileSyncService::NotifyObservers() {
825 FOR_EACH_OBSERVER(sync_driver::SyncServiceObserver, observers_, 828 FOR_EACH_OBSERVER(sync_driver::SyncServiceObserver, observers_,
826 OnStateChanged()); 829 OnStateChanged());
827 } 830 }
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
925 // case this operation affects the "passphrase required" status. 928 // case this operation affects the "passphrase required" status.
926 ConsumeCachedPassphraseIfPossible(); 929 ConsumeCachedPassphraseIfPossible();
927 930
928 // The very first time the backend initializes is effectively the first time 931 // The very first time the backend initializes is effectively the first time
929 // we can say we successfully "synced". LastSyncedTime will only be null in 932 // we can say we successfully "synced". LastSyncedTime will only be null in
930 // this case, because the pref wasn't restored on StartUp. 933 // this case, because the pref wasn't restored on StartUp.
931 if (sync_prefs_.GetLastSyncedTime().is_null()) { 934 if (sync_prefs_.GetLastSyncedTime().is_null()) {
932 UpdateLastSyncedTime(); 935 UpdateLastSyncedTime();
933 } 936 }
934 937
935 if (startup_controller_->auto_start_enabled() && !IsFirstSetupInProgress()) { 938 // Auto-start means IsFirstSetupComplete gets set automatically.
936 // Backend is initialized but we're not in sync setup, so this must be an 939 if (start_behavior_ == browser_sync::AUTO_START && !IsFirstSetupComplete()) {
937 // autostart - mark our sync setup as completed and we'll start syncing 940 // This will trigger a configure if it completes setup.
938 // below.
939 SetFirstSetupComplete(); 941 SetFirstSetupComplete();
Nicolas Zea 2016/02/29 21:21:55 Could we just have IsFirstSetupComplete encapsulat
maxbogue 2016/03/09 02:00:59 I think that's a bad idea because it's possible to
Nicolas Zea 2016/03/09 19:49:45 Acknowledged.
940 } 942 } else if (IsSetupComplete()) {
941
942 // Check IsFirstSetupComplete() before NotifyObservers() to avoid spurious
943 // data type configuration because observer may flag setup as complete and
944 // trigger data type configuration.
945 if (IsFirstSetupComplete()) {
946 ConfigureDataTypeManager(); 943 ConfigureDataTypeManager();
947 } else {
948 DCHECK(IsFirstSetupInProgress());
949 } 944 }
950 945
951 NotifyObservers(); 946 NotifyObservers();
952 } 947 }
953 948
954 void ProfileSyncService::OnBackendInitialized( 949 void ProfileSyncService::OnBackendInitialized(
955 const syncer::WeakHandle<syncer::JsBackend>& js_backend, 950 const syncer::WeakHandle<syncer::JsBackend>& js_backend,
956 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& 951 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>&
957 debug_info_listener, 952 debug_info_listener,
958 const std::string& cache_guid, 953 const std::string& cache_guid,
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
1230 last_actionable_error_.error_description, 1225 last_actionable_error_.error_description,
1231 true, 1226 true,
1232 ERROR_REASON_ACTIONABLE_ERROR); 1227 ERROR_REASON_ACTIONABLE_ERROR);
1233 break; 1228 break;
1234 case syncer::DISABLE_SYNC_ON_CLIENT: 1229 case syncer::DISABLE_SYNC_ON_CLIENT:
1235 if (error.error_type == syncer::NOT_MY_BIRTHDAY) { 1230 if (error.error_type == syncer::NOT_MY_BIRTHDAY) {
1236 UMA_HISTOGRAM_ENUMERATION("Sync.StopSource", syncer::BIRTHDAY_ERROR, 1231 UMA_HISTOGRAM_ENUMERATION("Sync.StopSource", syncer::BIRTHDAY_ERROR,
1237 syncer::STOP_SOURCE_LIMIT); 1232 syncer::STOP_SOURCE_LIMIT);
1238 } 1233 }
1239 RequestStop(CLEAR_DATA); 1234 RequestStop(CLEAR_DATA);
1240 #if !defined(OS_CHROMEOS) 1235 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
Nicolas Zea 2016/02/29 21:21:55 I'd like to move away from ifdefs as much as possi
maxbogue 2016/03/09 02:00:59 I changed it this way because this behavior doesn'
Nicolas Zea 2016/03/09 19:49:45 Hmm, interesting. I guess I could see that. Maybe
maxbogue 2016/03/10 18:48:15 Done.
1241 // On desktop Chrome, sign out the user after a dashboard clear. 1236 // On desktop Chrome, sign out the user after a dashboard clear.
1242 // Skip sign out on ChromeOS/Android. 1237 static_cast<SigninManager*>(signin_->GetOriginal())->SignOut(
1243 if (!startup_controller_->auto_start_enabled()) { 1238 signin_metrics::SERVER_FORCED_DISABLE,
1244 SigninManager* signin_manager = 1239 signin_metrics::SignoutDelete::IGNORE_METRIC);
1245 static_cast<SigninManager*>(signin_->GetOriginal());
1246 signin_manager->SignOut(signin_metrics::SERVER_FORCED_DISABLE,
1247 signin_metrics::SignoutDelete::IGNORE_METRIC);
1248 }
1249 #endif 1240 #endif
1250 break; 1241 break;
1251 case syncer::STOP_SYNC_FOR_DISABLED_ACCOUNT: 1242 case syncer::STOP_SYNC_FOR_DISABLED_ACCOUNT:
1252 // Sync disabled by domain admin. we should stop syncing until next 1243 // Sync disabled by domain admin. we should stop syncing until next
1253 // restart. 1244 // restart.
1254 sync_disabled_by_admin_ = true; 1245 sync_disabled_by_admin_ = true;
1255 ShutdownImpl(syncer::DISABLE_SYNC); 1246 ShutdownImpl(syncer::DISABLE_SYNC);
1256 break; 1247 break;
1257 case syncer::RESET_LOCAL_SYNC_DATA: 1248 case syncer::RESET_LOCAL_SYNC_DATA:
1258 ShutdownImpl(syncer::DISABLE_SYNC); 1249 ShutdownImpl(syncer::DISABLE_SYNC);
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
1448 return "Sync service initialized"; 1439 return "Sync service initialized";
1449 default: 1440 default:
1450 return "Status unknown: Internal error?"; 1441 return "Status unknown: Internal error?";
1451 } 1442 }
1452 } 1443 }
1453 1444
1454 std::string ProfileSyncService::GetBackendInitializationStateString() const { 1445 std::string ProfileSyncService::GetBackendInitializationStateString() const {
1455 return startup_controller_->GetBackendInitializationStateString(); 1446 return startup_controller_->GetBackendInitializationStateString();
1456 } 1447 }
1457 1448
1458 bool ProfileSyncService::auto_start_enabled() const {
1459 return startup_controller_->auto_start_enabled();
1460 }
1461
1462 bool ProfileSyncService::IsSetupInProgress() const { 1449 bool ProfileSyncService::IsSetupInProgress() const {
1463 return startup_controller_->IsSetupInProgress(); 1450 return startup_controller_->IsSetupInProgress();
1464 } 1451 }
1465 1452
1466 bool ProfileSyncService::QueryDetailedSyncStatus( 1453 bool ProfileSyncService::QueryDetailedSyncStatus(
1467 SyncBackendHost::Status* result) { 1454 SyncBackendHost::Status* result) {
1468 if (backend_.get() && backend_initialized_) { 1455 if (backend_.get() && backend_initialized_) {
1469 *result = backend_->GetDetailedStatus(); 1456 *result = backend_->GetDetailedStatus();
1470 return true; 1457 return true;
1471 } else { 1458 } else {
1472 SyncBackendHost::Status status; 1459 SyncBackendHost::Status status;
1473 status.sync_protocol_error = last_actionable_error_; 1460 status.sync_protocol_error = last_actionable_error_;
1474 *result = status; 1461 *result = status;
1475 return false; 1462 return false;
1476 } 1463 }
1477 } 1464 }
1478 1465
1479 const AuthError& ProfileSyncService::GetAuthError() const { 1466 const AuthError& ProfileSyncService::GetAuthError() const {
1480 return last_auth_error_; 1467 return last_auth_error_;
1481 } 1468 }
1482 1469
1470 bool ProfileSyncService::IsSetupComplete() const {
1471 return IsFirstSetupComplete() && !IsSetupInProgress();
1472 }
1473
1483 bool ProfileSyncService::IsFirstSetupInProgress() const { 1474 bool ProfileSyncService::IsFirstSetupInProgress() const {
1484 return !IsFirstSetupComplete() && startup_controller_->IsSetupInProgress(); 1475 return !IsFirstSetupComplete() && startup_controller_->IsSetupInProgress();
1485 } 1476 }
1486 1477
1487 void ProfileSyncService::SetSetupInProgress(bool setup_in_progress) { 1478 void ProfileSyncService::SetSetupInProgress(bool setup_in_progress) {
1488 // This method is a no-op if |setup_in_progress_| remains unchanged. 1479 // This method is a no-op if |setup_in_progress_| remains unchanged.
1489 if (startup_controller_->IsSetupInProgress() == setup_in_progress) 1480 if (startup_controller_->IsSetupInProgress() == setup_in_progress)
1490 return; 1481 return;
1491 1482
1492 startup_controller_->set_setup_in_progress(setup_in_progress); 1483 startup_controller_->set_setup_in_progress(setup_in_progress);
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
1731 const PlatformSyncAllowedProvider& platform_sync_allowed_provider) { 1722 const PlatformSyncAllowedProvider& platform_sync_allowed_provider) {
1732 platform_sync_allowed_provider_ = platform_sync_allowed_provider; 1723 platform_sync_allowed_provider_ = platform_sync_allowed_provider;
1733 } 1724 }
1734 1725
1735 void ProfileSyncService::ConfigureDataTypeManager() { 1726 void ProfileSyncService::ConfigureDataTypeManager() {
1736 // Don't configure datatypes if the setup UI is still on the screen - this 1727 // Don't configure datatypes if the setup UI is still on the screen - this
1737 // is to help multi-screen setting UIs (like iOS) where they don't want to 1728 // is to help multi-screen setting UIs (like iOS) where they don't want to
1738 // start syncing data until the user is done configuring encryption options, 1729 // start syncing data until the user is done configuring encryption options,
1739 // etc. ReconfigureDatatypeManager() will get called again once the UI calls 1730 // etc. ReconfigureDatatypeManager() will get called again once the UI calls
1740 // SetSetupInProgress(false). 1731 // SetSetupInProgress(false).
1741 if (startup_controller_->IsSetupInProgress()) 1732 if (!IsSetupComplete())
1742 return; 1733 return;
1743 1734
1744 bool restart = false; 1735 bool restart = false;
1745 if (!data_type_manager_) { 1736 if (!data_type_manager_) {
1746 restart = true; 1737 restart = true;
1747 data_type_manager_.reset( 1738 data_type_manager_.reset(
1748 sync_client_->GetSyncApiComponentFactory()->CreateDataTypeManager( 1739 sync_client_->GetSyncApiComponentFactory()->CreateDataTypeManager(
1749 debug_info_listener_, &data_type_controllers_, this, backend_.get(), 1740 debug_info_listener_, &data_type_controllers_, this, backend_.get(),
1750 this)); 1741 this));
1751 1742
(...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after
2459 } 2450 }
2460 2451
2461 std::string ProfileSyncService::unrecoverable_error_message() const { 2452 std::string ProfileSyncService::unrecoverable_error_message() const {
2462 return unrecoverable_error_message_; 2453 return unrecoverable_error_message_;
2463 } 2454 }
2464 2455
2465 tracked_objects::Location ProfileSyncService::unrecoverable_error_location() 2456 tracked_objects::Location ProfileSyncService::unrecoverable_error_location()
2466 const { 2457 const {
2467 return unrecoverable_error_location_; 2458 return unrecoverable_error_location_;
2468 } 2459 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698