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

Unified Diff: chrome/browser/sync/profile_sync_service.cc

Issue 12288010: sync: preliminary support for deferred SyncBackendHost initialization (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review Created 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/sync/profile_sync_service.h ('k') | chrome/common/chrome_switches.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/sync/profile_sync_service.cc
diff --git a/chrome/browser/sync/profile_sync_service.cc b/chrome/browser/sync/profile_sync_service.cc
index b649c14e32d39f0e7eb634bf6dd11cba7c4b9633..0bfa94bc578e0cf5e913c70d72e67130a5438ada 100644
--- a/chrome/browser/sync/profile_sync_service.cc
+++ b/chrome/browser/sync/profile_sync_service.cc
@@ -297,11 +297,21 @@ void ProfileSyncService::TryStart() {
// but we haven't completed sync setup, we try to start sync anyway, since
// it's possible we crashed/shutdown after logging in but before the backend
// finished initializing the last time.
- if (!HasSyncSetupCompleted() && !setup_in_progress_ && !auto_start_enabled_)
- return;
-
- // All systems Go for launch.
- StartUp();
+ //
+ // However, the only time we actually need to start sync _immediately_ is if
+ // we haven't completed sync setup and the user is in the process of setting
+ // up - either they just signed in (for the first time) on an auto-start
+ // platform or they explicitly kicked off sync setup, and e.g we need to
+ // fetch account details like encryption state to populate UI. Otherwise,
+ // for performance reasons and maximizing parallelism at chrome startup, we
+ // defer the heavy lifting for sync init until things have calmed down.
+ if (HasSyncSetupCompleted()) {
+ StartUp(STARTUP_BACKEND_DEFERRED);
+ } else if (setup_in_progress_ || auto_start_enabled_) {
+ // We haven't completed sync setup. Start immediately if the user explicitly
+ // kicked this off or we're supposed to automatically start syncing.
+ StartUp(STARTUP_IMMEDIATE);
+ }
}
void ProfileSyncService::StartSyncingWithServer() {
@@ -467,8 +477,7 @@ void ProfileSyncService::OnSyncConfigureRetry() {
NotifyObservers();
}
-
-void ProfileSyncService::StartUp() {
+void ProfileSyncService::StartUp(StartUpDeferredOption deferred_option) {
// Don't start up multiple times.
if (backend_.get()) {
DVLOG(1) << "Skipping bringing up backend host.";
@@ -487,6 +496,40 @@ void ProfileSyncService::StartUp() {
sync_prefs_.GetSpareBootstrapToken());
}
#endif
+
+ if (!sync_global_error_.get()) {
+#if !defined(OS_ANDROID)
+ sync_global_error_.reset(new SyncGlobalError(this, signin()));
+#endif
+ GlobalErrorServiceFactory::GetForProfile(profile_)->AddGlobalError(
+ sync_global_error_.get());
+ AddObserver(sync_global_error_.get());
+ }
+
+ if (deferred_option == STARTUP_BACKEND_DEFERRED &&
+ CommandLine::ForCurrentProcess()->
+ HasSwitch(switches::kSyncEnableDeferredStartup)) {
+ return;
+ }
+ DCHECK_EQ(STARTUP_IMMEDIATE, deferred_option);
+ StartUpSlowBackendComponents(STARTUP_IMMEDIATE);
+}
+
+void ProfileSyncService::StartUpSlowBackendComponents(
+ StartUpDeferredOption deferred_option) {
+ // Don't start up multiple times.
+ if (backend_.get()) {
+ DVLOG(1) << "Skipping bringing up backend host.";
+ return;
+ }
+
+ DCHECK(!start_up_time_.is_null());
+ if (deferred_option == STARTUP_BACKEND_DEFERRED) {
+ base::TimeDelta time_deferred = base::Time::Now() - start_up_time_;
+ UMA_HISTOGRAM_TIMES("Sync.Startup.TimeDeferred", time_deferred);
+ }
+
+ DCHECK(IsSyncEnabledAndLoggedIn());
CreateBackend();
// Initialize the backend. Every time we start up a new SyncBackendHost,
@@ -503,15 +546,6 @@ void ProfileSyncService::StartUp() {
backend_->UpdateRegisteredInvalidationIds(
invalidator_registrar_->GetAllRegisteredIds());
}
-
- if (!sync_global_error_.get()) {
-#if !defined(OS_ANDROID)
- sync_global_error_.reset(new SyncGlobalError(this, signin()));
-#endif
- GlobalErrorServiceFactory::GetForProfile(profile_)->AddGlobalError(
- sync_global_error_.get());
- AddObserver(sync_global_error_.get());
- }
}
void ProfileSyncService::RegisterInvalidationHandler(
@@ -1240,6 +1274,15 @@ std::string ProfileSyncService::QuerySyncStatusSummary() {
}
}
+std::string ProfileSyncService::GetBackendInitializationStateString() const {
+ if (sync_initialized())
+ return "Done";
+ else if (!start_up_time_.is_null())
+ return "Deferred";
+ else
+ return "Not started";
+}
+
bool ProfileSyncService::QueryDetailedSyncStatus(
SyncBackendHost::Status* result) {
if (backend_.get() && backend_initialized_) {
« no previous file with comments | « chrome/browser/sync/profile_sync_service.h ('k') | chrome/common/chrome_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698