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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 SigninManagerBase* signin_manager, | 133 SigninManagerBase* signin_manager, |
134 StartBehavior start_behavior) | 134 StartBehavior start_behavior) |
135 : last_auth_error_(AuthError::AuthErrorNone()), | 135 : last_auth_error_(AuthError::AuthErrorNone()), |
136 passphrase_required_reason_(syncer::REASON_PASSPHRASE_NOT_REQUIRED), | 136 passphrase_required_reason_(syncer::REASON_PASSPHRASE_NOT_REQUIRED), |
137 factory_(factory), | 137 factory_(factory), |
138 profile_(profile), | 138 profile_(profile), |
139 // |profile| may be NULL in unit tests. | 139 // |profile| may be NULL in unit tests. |
140 sync_prefs_(profile_ ? profile_->GetPrefs() : NULL), | 140 sync_prefs_(profile_ ? profile_->GetPrefs() : NULL), |
141 invalidator_storage_(profile_ ? profile_->GetPrefs(): NULL), | 141 invalidator_storage_(profile_ ? profile_->GetPrefs(): NULL), |
142 sync_service_url_(kDevServerUrl), | 142 sync_service_url_(kDevServerUrl), |
143 data_type_requested_sync_startup_(false), | |
143 is_first_time_sync_configure_(false), | 144 is_first_time_sync_configure_(false), |
144 backend_initialized_(false), | 145 backend_initialized_(false), |
145 is_auth_in_progress_(false), | 146 is_auth_in_progress_(false), |
146 signin_(signin_manager), | 147 signin_(signin_manager), |
147 unrecoverable_error_reason_(ERROR_REASON_UNSET), | 148 unrecoverable_error_reason_(ERROR_REASON_UNSET), |
148 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 149 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
149 expect_sync_configuration_aborted_(false), | 150 expect_sync_configuration_aborted_(false), |
150 encrypted_types_(syncer::SyncEncryptionHandler::SensitiveTypes()), | 151 encrypted_types_(syncer::SyncEncryptionHandler::SensitiveTypes()), |
151 encrypt_everything_(false), | 152 encrypt_everything_(false), |
152 encryption_pending_(false), | 153 encryption_pending_(false), |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
298 // finished initializing the last time. | 299 // finished initializing the last time. |
299 // | 300 // |
300 // However, the only time we actually need to start sync _immediately_ is if | 301 // However, the only time we actually need to start sync _immediately_ is if |
301 // we haven't completed sync setup and the user is in the process of setting | 302 // we haven't completed sync setup and the user is in the process of setting |
302 // up - either they just signed in (for the first time) on an auto-start | 303 // up - either they just signed in (for the first time) on an auto-start |
303 // platform or they explicitly kicked off sync setup, and e.g we need to | 304 // platform or they explicitly kicked off sync setup, and e.g we need to |
304 // fetch account details like encryption state to populate UI. Otherwise, | 305 // fetch account details like encryption state to populate UI. Otherwise, |
305 // for performance reasons and maximizing parallelism at chrome startup, we | 306 // for performance reasons and maximizing parallelism at chrome startup, we |
306 // defer the heavy lifting for sync init until things have calmed down. | 307 // defer the heavy lifting for sync init until things have calmed down. |
307 if (HasSyncSetupCompleted()) { | 308 if (HasSyncSetupCompleted()) { |
308 StartUp(STARTUP_BACKEND_DEFERRED); | 309 if (!data_type_requested_sync_startup_) |
310 StartUp(STARTUP_BACKEND_DEFERRED); | |
311 else if (start_up_time_.is_null()) | |
312 StartUp(STARTUP_IMMEDIATE); | |
313 else | |
314 StartUpSlowBackendComponents(); | |
309 } else if (setup_in_progress_ || auto_start_enabled_) { | 315 } else if (setup_in_progress_ || auto_start_enabled_) { |
310 // We haven't completed sync setup. Start immediately if the user explicitly | 316 // We haven't completed sync setup. Start immediately if the user explicitly |
311 // kicked this off or we're supposed to automatically start syncing. | 317 // kicked this off or we're supposed to automatically start syncing. |
312 StartUp(STARTUP_IMMEDIATE); | 318 StartUp(STARTUP_IMMEDIATE); |
313 } | 319 } |
314 } | 320 } |
315 | 321 |
316 void ProfileSyncService::StartSyncingWithServer() { | 322 void ProfileSyncService::StartSyncingWithServer() { |
317 if (backend_.get()) | 323 if (backend_.get()) |
318 backend_->StartSyncingWithServer(); | 324 backend_->StartSyncingWithServer(); |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
520 sync_global_error_.get()); | 526 sync_global_error_.get()); |
521 AddObserver(sync_global_error_.get()); | 527 AddObserver(sync_global_error_.get()); |
522 } | 528 } |
523 | 529 |
524 if (deferred_option == STARTUP_BACKEND_DEFERRED && | 530 if (deferred_option == STARTUP_BACKEND_DEFERRED && |
525 CommandLine::ForCurrentProcess()-> | 531 CommandLine::ForCurrentProcess()-> |
526 HasSwitch(switches::kSyncEnableDeferredStartup)) { | 532 HasSwitch(switches::kSyncEnableDeferredStartup)) { |
527 return; | 533 return; |
528 } | 534 } |
529 | 535 |
530 StartUpSlowBackendComponents(STARTUP_IMMEDIATE); | 536 StartUpSlowBackendComponents(); |
531 } | 537 } |
532 | 538 |
533 void ProfileSyncService::StartUpSlowBackendComponents( | 539 void ProfileSyncService::OnDataTypeRequestsSyncStartup( |
534 StartUpDeferredOption deferred_option) { | 540 syncer::ModelType type) { |
541 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
| |
542 if (backend_.get()) { | |
543 DVLOG(1) << "A data type requested sync startup, but it looks like " | |
544 "something else beat it to the punch."; | |
545 return; | |
546 } | |
547 | |
548 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
549 switches::kSyncEnableDeferredStartup)) { | |
550 DVLOG(2) << "Data type requesting sync startup: " | |
551 << syncer::ModelTypeToString(type); | |
552 // Measure the time spent waiting for init and the type that triggered it. | |
553 // We could measure the time spent deferred on a per-datatype basis, but | |
554 // for now this is probably sufficient. | |
555 if (!start_up_time_.is_null()) { | |
556 // TODO(tim): Cache |type| and move this tracking to StartUp. I'd like | |
557 // to pull all the complicated init logic and state out of | |
558 // ProfileSyncService and have only a StartUp method, though. One step | |
559 // at a time. Bug 80149. | |
560 base::TimeDelta time_deferred = base::Time::Now() - start_up_time_; | |
561 UMA_HISTOGRAM_TIMES("Sync.Startup.TimeDeferred", time_deferred); | |
562 UMA_HISTOGRAM_ENUMERATION("Sync.Startup.TypeTriggeringInit", | |
563 type, | |
564 syncer::MODEL_TYPE_COUNT); | |
565 } | |
566 data_type_requested_sync_startup_ = true; | |
567 TryStart(); | |
568 } | |
569 DVLOG(2) << "Ignoring data type request for sync startup: " | |
570 << syncer::ModelTypeToString(type); | |
571 } | |
572 | |
573 void ProfileSyncService::StartUpSlowBackendComponents() { | |
535 // Don't start up multiple times. | 574 // Don't start up multiple times. |
536 if (backend_.get()) { | 575 if (backend_.get()) { |
537 DVLOG(1) << "Skipping bringing up backend host."; | 576 DVLOG(1) << "Skipping bringing up backend host."; |
538 return; | 577 return; |
539 } | 578 } |
540 | 579 |
541 DCHECK(!start_up_time_.is_null()); | |
542 if (deferred_option == STARTUP_BACKEND_DEFERRED) { | |
543 base::TimeDelta time_deferred = base::Time::Now() - start_up_time_; | |
544 UMA_HISTOGRAM_TIMES("Sync.Startup.TimeDeferred", time_deferred); | |
545 } | |
546 | |
547 DCHECK(IsSyncEnabledAndLoggedIn()); | 580 DCHECK(IsSyncEnabledAndLoggedIn()); |
548 CreateBackend(); | 581 CreateBackend(); |
549 | 582 |
550 // Initialize the backend. Every time we start up a new SyncBackendHost, | 583 // Initialize the backend. Every time we start up a new SyncBackendHost, |
551 // we'll want to start from a fresh SyncDB, so delete any old one that might | 584 // we'll want to start from a fresh SyncDB, so delete any old one that might |
552 // be there. | 585 // be there. |
553 InitializeBackend(!HasSyncSetupCompleted()); | 586 InitializeBackend(!HasSyncSetupCompleted()); |
554 | 587 |
555 // |backend_| may end up being NULL here in tests (in synchronous | 588 // |backend_| may end up being NULL here in tests (in synchronous |
556 // initialization mode). | 589 // initialization mode). |
(...skipping 1507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2064 // See http://stackoverflow.com/questions/6224121/is-new-this-myclass-undefine d-behaviour-after-directly-calling-the-destru. | 2097 // See http://stackoverflow.com/questions/6224121/is-new-this-myclass-undefine d-behaviour-after-directly-calling-the-destru. |
2065 ProfileSyncService* old_this = this; | 2098 ProfileSyncService* old_this = this; |
2066 this->~ProfileSyncService(); | 2099 this->~ProfileSyncService(); |
2067 new(old_this) ProfileSyncService( | 2100 new(old_this) ProfileSyncService( |
2068 new ProfileSyncComponentsFactoryImpl(profile, | 2101 new ProfileSyncComponentsFactoryImpl(profile, |
2069 CommandLine::ForCurrentProcess()), | 2102 CommandLine::ForCurrentProcess()), |
2070 profile, | 2103 profile, |
2071 signin, | 2104 signin, |
2072 behavior); | 2105 behavior); |
2073 } | 2106 } |
OLD | NEW |