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 14312e58e9aa3bfc0bb48bf6130569684a01f269..93b3147ab4ef5e3e0518782de55d44afdae5b7e3 100644 |
--- a/chrome/browser/sync/profile_sync_service.cc |
+++ b/chrome/browser/sync/profile_sync_service.cc |
@@ -140,6 +140,7 @@ ProfileSyncService::ProfileSyncService(ProfileSyncComponentsFactory* factory, |
sync_prefs_(profile_ ? profile_->GetPrefs() : NULL), |
invalidator_storage_(profile_ ? profile_->GetPrefs(): NULL), |
sync_service_url_(kDevServerUrl), |
+ data_type_requested_sync_startup_(false), |
is_first_time_sync_configure_(false), |
backend_initialized_(false), |
is_auth_in_progress_(false), |
@@ -305,7 +306,12 @@ void ProfileSyncService::TryStart() { |
// 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); |
+ if (!data_type_requested_sync_startup_) |
+ StartUp(STARTUP_BACKEND_DEFERRED); |
+ else if (start_up_time_.is_null()) |
+ StartUp(STARTUP_IMMEDIATE); |
+ else |
+ StartUpSlowBackendComponents(); |
} 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. |
@@ -527,21 +533,48 @@ void ProfileSyncService::StartUp(StartUpDeferredOption deferred_option) { |
return; |
} |
- StartUpSlowBackendComponents(STARTUP_IMMEDIATE); |
+ StartUpSlowBackendComponents(); |
} |
-void ProfileSyncService::StartUpSlowBackendComponents( |
- StartUpDeferredOption deferred_option) { |
- // Don't start up multiple times. |
+void ProfileSyncService::OnDataTypeRequestsSyncStartup( |
+ syncer::ModelType type) { |
+ DCHECK(syncer::UserTypes().Has(type)); |
haitaol1
2013/04/25 19:18:18
Should you check whether sync for this type is ena
tim (not reviewing)
2013/05/01 21:19:47
Good catch. A disabled type shouldn't trigger sync
|
if (backend_.get()) { |
- DVLOG(1) << "Skipping bringing up backend host."; |
+ DVLOG(1) << "A data type requested sync startup, but it looks like " |
+ "something else beat it to the punch."; |
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); |
+ if (CommandLine::ForCurrentProcess()->HasSwitch( |
+ switches::kSyncEnableDeferredStartup)) { |
+ DVLOG(2) << "Data type requesting sync startup: " |
+ << syncer::ModelTypeToString(type); |
+ // Measure the time spent waiting for init and the type that triggered it. |
+ // We could measure the time spent deferred on a per-datatype basis, but |
+ // for now this is probably sufficient. |
+ if (!start_up_time_.is_null()) { |
+ // TODO(tim): Cache |type| and move this tracking to StartUp. I'd like |
+ // to pull all the complicated init logic and state out of |
+ // ProfileSyncService and have only a StartUp method, though. One step |
+ // at a time. Bug 80149. |
+ base::TimeDelta time_deferred = base::Time::Now() - start_up_time_; |
+ UMA_HISTOGRAM_TIMES("Sync.Startup.TimeDeferred", time_deferred); |
+ UMA_HISTOGRAM_ENUMERATION("Sync.Startup.TypeTriggeringInit", |
+ type, |
+ syncer::MODEL_TYPE_COUNT); |
+ } |
+ data_type_requested_sync_startup_ = true; |
+ TryStart(); |
+ } |
+ DVLOG(2) << "Ignoring data type request for sync startup: " |
+ << syncer::ModelTypeToString(type); |
+} |
+ |
+void ProfileSyncService::StartUpSlowBackendComponents() { |
+ // Don't start up multiple times. |
+ if (backend_.get()) { |
+ DVLOG(1) << "Skipping bringing up backend host."; |
+ return; |
} |
DCHECK(IsSyncEnabledAndLoggedIn()); |