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

Side by Side Diff: chrome/browser/sync/profile_sync_service.cc

Issue 162443004: sync: final pieces to sync deferred initialization (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix test leak Created 6 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 | Annotate | Revision Log
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 "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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 91
92 #if defined(OS_ANDROID) 92 #if defined(OS_ANDROID)
93 #include "sync/internal_api/public/read_transaction.h" 93 #include "sync/internal_api/public/read_transaction.h"
94 #endif 94 #endif
95 95
96 using browser_sync::ChangeProcessor; 96 using browser_sync::ChangeProcessor;
97 using browser_sync::DataTypeController; 97 using browser_sync::DataTypeController;
98 using browser_sync::DataTypeManager; 98 using browser_sync::DataTypeManager;
99 using browser_sync::FailedDataTypesHandler; 99 using browser_sync::FailedDataTypesHandler;
100 using browser_sync::NotificationServiceSessionsRouter; 100 using browser_sync::NotificationServiceSessionsRouter;
101 using browser_sync::ProfileSyncServiceStartBehavior;
101 using browser_sync::SyncBackendHost; 102 using browser_sync::SyncBackendHost;
102 using syncer::ModelType; 103 using syncer::ModelType;
103 using syncer::ModelTypeSet; 104 using syncer::ModelTypeSet;
104 using syncer::JsBackend; 105 using syncer::JsBackend;
105 using syncer::JsController; 106 using syncer::JsController;
106 using syncer::JsEventDetails; 107 using syncer::JsEventDetails;
107 using syncer::JsEventHandler; 108 using syncer::JsEventHandler;
108 using syncer::ModelSafeRoutingInfo; 109 using syncer::ModelSafeRoutingInfo;
109 using syncer::SyncCredentials; 110 using syncer::SyncCredentials;
110 using syncer::SyncProtocolError; 111 using syncer::SyncProtocolError;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 return (error.action != syncer::UNKNOWN_ACTION && 155 return (error.action != syncer::UNKNOWN_ACTION &&
155 error.action != syncer::DISABLE_SYNC_ON_CLIENT && 156 error.action != syncer::DISABLE_SYNC_ON_CLIENT &&
156 error.action != syncer::STOP_SYNC_FOR_DISABLED_ACCOUNT); 157 error.action != syncer::STOP_SYNC_FOR_DISABLED_ACCOUNT);
157 } 158 }
158 159
159 ProfileSyncService::ProfileSyncService( 160 ProfileSyncService::ProfileSyncService(
160 ProfileSyncComponentsFactory* factory, 161 ProfileSyncComponentsFactory* factory,
161 Profile* profile, 162 Profile* profile,
162 ManagedUserSigninManagerWrapper* signin_wrapper, 163 ManagedUserSigninManagerWrapper* signin_wrapper,
163 ProfileOAuth2TokenService* oauth2_token_service, 164 ProfileOAuth2TokenService* oauth2_token_service,
164 StartBehavior start_behavior) 165 ProfileSyncServiceStartBehavior start_behavior)
165 : OAuth2TokenService::Consumer("sync"), 166 : OAuth2TokenService::Consumer("sync"),
166 last_auth_error_(AuthError::AuthErrorNone()), 167 last_auth_error_(AuthError::AuthErrorNone()),
167 passphrase_required_reason_(syncer::REASON_PASSPHRASE_NOT_REQUIRED), 168 passphrase_required_reason_(syncer::REASON_PASSPHRASE_NOT_REQUIRED),
168 factory_(factory), 169 factory_(factory),
169 profile_(profile), 170 profile_(profile),
170 sync_prefs_(profile_->GetPrefs()), 171 sync_prefs_(profile_->GetPrefs()),
171 sync_service_url_(kDevServerUrl), 172 sync_service_url_(kDevServerUrl),
172 data_type_requested_sync_startup_(false),
173 is_first_time_sync_configure_(false), 173 is_first_time_sync_configure_(false),
174 backend_initialized_(false), 174 backend_initialized_(false),
175 sync_disabled_by_admin_(false), 175 sync_disabled_by_admin_(false),
176 is_auth_in_progress_(false), 176 is_auth_in_progress_(false),
177 signin_(signin_wrapper), 177 signin_(signin_wrapper),
178 unrecoverable_error_reason_(ERROR_REASON_UNSET), 178 unrecoverable_error_reason_(ERROR_REASON_UNSET),
179 expect_sync_configuration_aborted_(false), 179 expect_sync_configuration_aborted_(false),
180 encrypted_types_(syncer::SyncEncryptionHandler::SensitiveTypes()), 180 encrypted_types_(syncer::SyncEncryptionHandler::SensitiveTypes()),
181 encrypt_everything_(false), 181 encrypt_everything_(false),
182 encryption_pending_(false), 182 encryption_pending_(false),
183 auto_start_enabled_(start_behavior == AUTO_START),
184 configure_status_(DataTypeManager::UNKNOWN), 183 configure_status_(DataTypeManager::UNKNOWN),
185 setup_in_progress_(false),
186 oauth2_token_service_(oauth2_token_service), 184 oauth2_token_service_(oauth2_token_service),
187 request_access_token_backoff_(&kRequestAccessTokenBackoffPolicy), 185 request_access_token_backoff_(&kRequestAccessTokenBackoffPolicy),
188 weak_factory_(this), 186 weak_factory_(this),
187 startup_controller_weak_factory_(this),
189 connection_status_(syncer::CONNECTION_NOT_ATTEMPTED), 188 connection_status_(syncer::CONNECTION_NOT_ATTEMPTED),
190 last_get_token_error_(GoogleServiceAuthError::AuthErrorNone()), 189 last_get_token_error_(GoogleServiceAuthError::AuthErrorNone()),
191 network_resources_(new syncer::HttpBridgeNetworkResources) { 190 network_resources_(new syncer::HttpBridgeNetworkResources),
191 startup_controller_(
192 start_behavior, oauth2_token_service, &sync_prefs_, signin_wrapper,
193 base::Bind(
194 &ProfileSyncService::StartUpSlowBackendComponents,
195 startup_controller_weak_factory_.GetWeakPtr())) {
haitaol1 2014/02/20 00:01:06 Why don't just use base::Unretained() if PSS alway
tim (not reviewing) 2014/02/20 22:52:52 See my comment in startup_controller.h. If Startu
192 DCHECK(profile); 196 DCHECK(profile);
193 // By default, dev, canary, and unbranded Chromium users will go to the 197 // By default, dev, canary, and unbranded Chromium users will go to the
194 // development servers. Development servers have more features than standard 198 // development servers. Development servers have more features than standard
195 // sync servers. Users with officially-branded Chrome stable and beta builds 199 // sync servers. Users with officially-branded Chrome stable and beta builds
196 // will go to the standard sync servers. 200 // will go to the standard sync servers.
197 // 201 //
198 // GetChannel hits the registry on Windows. See http://crbug.com/70380. 202 // GetChannel hits the registry on Windows. See http://crbug.com/70380.
199 base::ThreadRestrictions::ScopedAllowIO allow_io; 203 base::ThreadRestrictions::ScopedAllowIO allow_io;
200 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); 204 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel();
201 if (channel == chrome::VersionInfo::CHANNEL_STABLE || 205 if (channel == chrome::VersionInfo::CHANNEL_STABLE ||
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 278
275 #if !defined(OS_ANDROID) 279 #if !defined(OS_ANDROID)
276 if (!sync_global_error_) { 280 if (!sync_global_error_) {
277 sync_global_error_.reset(new SyncGlobalError(this, signin())); 281 sync_global_error_.reset(new SyncGlobalError(this, signin()));
278 GlobalErrorServiceFactory::GetForProfile(profile_)->AddGlobalError( 282 GlobalErrorServiceFactory::GetForProfile(profile_)->AddGlobalError(
279 sync_global_error_.get()); 283 sync_global_error_.get());
280 AddObserver(sync_global_error_.get()); 284 AddObserver(sync_global_error_.get());
281 } 285 }
282 #endif 286 #endif
283 287
284 TryStart(); 288 startup_controller_.TryStart();
285 } 289 }
286 290
287 void ProfileSyncService::TrySyncDatatypePrefRecovery() { 291 void ProfileSyncService::TrySyncDatatypePrefRecovery() {
288 DCHECK(!sync_initialized()); 292 DCHECK(!sync_initialized());
289 if (!HasSyncSetupCompleted()) 293 if (!HasSyncSetupCompleted())
290 return; 294 return;
291 295
292 // There was a bug where OnUserChoseDatatypes was not properly called on 296 // There was a bug where OnUserChoseDatatypes was not properly called on
293 // configuration (see crbug.com/154940). We detect this by checking whether 297 // configuration (see crbug.com/154940). We detect this by checking whether
294 // kSyncKeepEverythingSynced has a default value. If so, and sync setup has 298 // kSyncKeepEverythingSynced has a default value. If so, and sync setup has
(...skipping 14 matching lines...) Expand all
309 313
310 // kSyncKeepEverythingSynced was not properly set. Set it and the preferred 314 // kSyncKeepEverythingSynced was not properly set. Set it and the preferred
311 // types now, before we configure. 315 // types now, before we configure.
312 UMA_HISTOGRAM_COUNTS("Sync.DatatypePrefRecovery", 1); 316 UMA_HISTOGRAM_COUNTS("Sync.DatatypePrefRecovery", 1);
313 sync_prefs_.SetKeepEverythingSynced(true); 317 sync_prefs_.SetKeepEverythingSynced(true);
314 syncer::ModelTypeSet registered_types = GetRegisteredDataTypes(); 318 syncer::ModelTypeSet registered_types = GetRegisteredDataTypes();
315 sync_prefs_.SetPreferredDataTypes(registered_types, 319 sync_prefs_.SetPreferredDataTypes(registered_types,
316 registered_types); 320 registered_types);
317 } 321 }
318 322
319 void ProfileSyncService::TryStart() {
320 if (!IsSyncEnabledAndLoggedIn())
321 return;
322
323 // Don't start sync until tokens are loaded, because the user can be
324 // "signed in" long before the tokens get loaded, and we don't want to
325 // generate spurious auth errors.
326 if (!IsOAuthRefreshTokenAvailable())
327 return;
328
329 // If we got here then tokens are loaded and user logged in and sync is
330 // enabled. If OAuth refresh token is not available then something is wrong.
331 // When PSS requests access token, OAuth2TokenService will return error and
332 // PSS will show error to user asking to reauthenticate.
333 UMA_HISTOGRAM_BOOLEAN("Sync.RefreshTokenAvailable",
334 IsOAuthRefreshTokenAvailable());
335
336 // If sync setup has completed we always start the backend. If the user is in
337 // the process of setting up now, we should start the backend to download
338 // account control state / encryption information). If autostart is enabled,
339 // but we haven't completed sync setup, we try to start sync anyway, since
340 // it's possible we crashed/shutdown after logging in but before the backend
341 // finished initializing the last time.
342 //
343 // However, the only time we actually need to start sync _immediately_ is if
344 // we haven't completed sync setup and the user is in the process of setting
345 // up - either they just signed in (for the first time) on an auto-start
346 // platform or they explicitly kicked off sync setup, and e.g we need to
347 // fetch account details like encryption state to populate UI. Otherwise,
348 // for performance reasons and maximizing parallelism at chrome startup, we
349 // defer the heavy lifting for sync init until things have calmed down.
350 if (HasSyncSetupCompleted()) {
351 if (!data_type_requested_sync_startup_)
352 StartUp(STARTUP_BACKEND_DEFERRED);
353 else if (start_up_time_.is_null())
354 StartUp(STARTUP_IMMEDIATE);
355 else
356 StartUpSlowBackendComponents();
357 } else if (setup_in_progress_ || auto_start_enabled_) {
358 // We haven't completed sync setup. Start immediately if the user explicitly
359 // kicked this off or we're supposed to automatically start syncing.
360 StartUp(STARTUP_IMMEDIATE);
361 }
362 }
363
364 void ProfileSyncService::StartSyncingWithServer() { 323 void ProfileSyncService::StartSyncingWithServer() {
365 if (backend_) 324 if (backend_)
366 backend_->StartSyncingWithServer(); 325 backend_->StartSyncingWithServer();
367 } 326 }
368 327
369 void ProfileSyncService::RegisterAuthNotifications() { 328 void ProfileSyncService::RegisterAuthNotifications() {
370 oauth2_token_service_->AddObserver(this); 329 oauth2_token_service_->AddObserver(this);
371 330
372 registrar_.Add(this, 331 registrar_.Add(this,
373 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, 332 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL,
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 548
590 void ProfileSyncService::OnSyncConfigureRetry() { 549 void ProfileSyncService::OnSyncConfigureRetry() {
591 // Note: in order to handle auth failures that arise before the backend is 550 // Note: in order to handle auth failures that arise before the backend is
592 // initialized (e.g. from invalidation notifier, or downloading new control 551 // initialized (e.g. from invalidation notifier, or downloading new control
593 // types), we have to gracefully handle configuration retries at all times. 552 // types), we have to gracefully handle configuration retries at all times.
594 // At this point an auth error badge should be shown, which once resolved 553 // At this point an auth error badge should be shown, which once resolved
595 // will trigger a new sync cycle. 554 // will trigger a new sync cycle.
596 NotifyObservers(); 555 NotifyObservers();
597 } 556 }
598 557
599 void ProfileSyncService::StartUp(StartUpDeferredOption deferred_option) {
600 // Don't start up multiple times.
601 if (backend_) {
602 DVLOG(1) << "Skipping bringing up backend host.";
603 return;
604 }
605
606 DCHECK(IsSyncEnabledAndLoggedIn());
607
608 if (start_up_time_.is_null()) {
609 start_up_time_ = base::Time::Now();
610 } else {
611 // We don't care to prevent multiple calls to StartUp in deferred mode
612 // because it's fast and has no side effects.
613 DCHECK_EQ(STARTUP_BACKEND_DEFERRED, deferred_option);
614 }
615
616 if (deferred_option == STARTUP_BACKEND_DEFERRED &&
617 CommandLine::ForCurrentProcess()->
618 HasSwitch(switches::kSyncEnableDeferredStartup)) {
619 return;
620 }
621
622 StartUpSlowBackendComponents();
623 }
624
625 void ProfileSyncService::OnDataTypeRequestsSyncStartup( 558 void ProfileSyncService::OnDataTypeRequestsSyncStartup(
626 syncer::ModelType type) { 559 syncer::ModelType type) {
627 DCHECK(syncer::UserTypes().Has(type)); 560 DCHECK(syncer::UserTypes().Has(type));
628 if (backend_.get()) { 561 if (backend_.get()) {
629 DVLOG(1) << "A data type requested sync startup, but it looks like " 562 DVLOG(1) << "A data type requested sync startup, but it looks like "
630 "something else beat it to the punch."; 563 "something else beat it to the punch.";
631 return; 564 return;
632 } 565 }
633 566
634 if (!GetActiveDataTypes().Has(type)) { 567 if (!GetActiveDataTypes().Has(type)) {
635 // We can get here as datatype SyncableServices are typically wired up 568 // We can get here as datatype SyncableServices are typically wired up
636 // to the native datatype even if sync isn't enabled. 569 // to the native datatype even if sync isn't enabled.
637 DVLOG(1) << "Dropping sync startup request because type " 570 DVLOG(1) << "Dropping sync startup request because type "
638 << syncer::ModelTypeToString(type) << "not enabled."; 571 << syncer::ModelTypeToString(type) << "not enabled.";
639 return; 572 return;
640 } 573 }
641 574
642 if (CommandLine::ForCurrentProcess()->HasSwitch( 575 startup_controller_.OnDataTypeRequestsSyncStartup(type);
643 switches::kSyncEnableDeferredStartup)) {
644 DVLOG(2) << "Data type requesting sync startup: "
645 << syncer::ModelTypeToString(type);
646 // Measure the time spent waiting for init and the type that triggered it.
647 // We could measure the time spent deferred on a per-datatype basis, but
648 // for now this is probably sufficient.
649 if (!start_up_time_.is_null()) {
650 // TODO(tim): Cache |type| and move this tracking to StartUp. I'd like
651 // to pull all the complicated init logic and state out of
652 // ProfileSyncService and have only a StartUp method, though. One step
653 // at a time. Bug 80149.
654 base::TimeDelta time_deferred = base::Time::Now() - start_up_time_;
655 UMA_HISTOGRAM_TIMES("Sync.Startup.TimeDeferred", time_deferred);
656 UMA_HISTOGRAM_ENUMERATION("Sync.Startup.TypeTriggeringInit",
657 ModelTypeToHistogramInt(type),
658 syncer::MODEL_TYPE_COUNT);
659 }
660 data_type_requested_sync_startup_ = true;
661 TryStart();
662 }
663 DVLOG(2) << "Ignoring data type request for sync startup: "
664 << syncer::ModelTypeToString(type);
665 } 576 }
666 577
667 void ProfileSyncService::StartUpSlowBackendComponents() { 578 void ProfileSyncService::StartUpSlowBackendComponents() {
668 // Don't start up multiple times. 579 // Don't start up multiple times.
669 if (backend_) { 580 DCHECK(!backend_);
670 DVLOG(1) << "Skipping bringing up backend host.";
671 return;
672 }
673 581
674 DCHECK(IsSyncEnabledAndLoggedIn()); 582 DCHECK(IsSyncEnabledAndLoggedIn());
583
584 DCHECK(!sync_disabled_by_admin_);
675 backend_.reset( 585 backend_.reset(
676 factory_->CreateSyncBackendHost( 586 factory_->CreateSyncBackendHost(
677 profile_->GetDebugName(), 587 profile_->GetDebugName(),
678 profile_, 588 profile_,
679 sync_prefs_.AsWeakPtr())); 589 sync_prefs_.AsWeakPtr()));
680 590
681 // Initialize the backend. Every time we start up a new SyncBackendHost, 591 // Initialize the backend. Every time we start up a new SyncBackendHost,
682 // we'll want to start from a fresh SyncDB, so delete any old one that might 592 // we'll want to start from a fresh SyncDB, so delete any old one that might
683 // be there. 593 // be there.
684 InitializeBackend(!HasSyncSetupCompleted()); 594 InitializeBackend(!HasSyncSetupCompleted());
(...skipping 12 matching lines...) Expand all
697 if (sync_prefs_.SyncHasAuthError()) { 607 if (sync_prefs_.SyncHasAuthError()) {
698 sync_prefs_.SetSyncAuthError(false); 608 sync_prefs_.SetSyncAuthError(false);
699 UMA_HISTOGRAM_ENUMERATION("Sync.SyncAuthError", 609 UMA_HISTOGRAM_ENUMERATION("Sync.SyncAuthError",
700 AUTH_ERROR_FIXED, 610 AUTH_ERROR_FIXED,
701 AUTH_ERROR_LIMIT); 611 AUTH_ERROR_LIMIT);
702 } 612 }
703 613
704 if (backend_) 614 if (backend_)
705 backend_->UpdateCredentials(GetCredentials()); 615 backend_->UpdateCredentials(GetCredentials());
706 else 616 else
707 TryStart(); 617 startup_controller_.TryStart();
708 } 618 }
709 619
710 void ProfileSyncService::OnGetTokenFailure( 620 void ProfileSyncService::OnGetTokenFailure(
711 const OAuth2TokenService::Request* request, 621 const OAuth2TokenService::Request* request,
712 const GoogleServiceAuthError& error) { 622 const GoogleServiceAuthError& error) {
713 DCHECK_EQ(access_token_request_, request); 623 DCHECK_EQ(access_token_request_, request);
714 DCHECK_NE(error.state(), GoogleServiceAuthError::NONE); 624 DCHECK_NE(error.state(), GoogleServiceAuthError::NONE);
715 access_token_request_.reset(); 625 access_token_request_.reset();
716 last_get_token_error_ = error; 626 last_get_token_error_ = error;
717 switch (error.state()) { 627 switch (error.state()) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 679
770 void ProfileSyncService::OnRefreshTokensLoaded() { 680 void ProfileSyncService::OnRefreshTokensLoaded() {
771 // This notification gets fired when OAuth2TokenService loads the tokens 681 // This notification gets fired when OAuth2TokenService loads the tokens
772 // from storage. 682 // from storage.
773 // Initialize the backend if sync is enabled. If the sync token was 683 // Initialize the backend if sync is enabled. If the sync token was
774 // not loaded, GetCredentials() will generate invalid credentials to 684 // not loaded, GetCredentials() will generate invalid credentials to
775 // cause the backend to generate an auth error (crbug.com/121755). 685 // cause the backend to generate an auth error (crbug.com/121755).
776 if (backend_) { 686 if (backend_) {
777 RequestAccessToken(); 687 RequestAccessToken();
778 } else { 688 } else {
779 TryStart(); 689 startup_controller_.TryStart();
780 } 690 }
781 } 691 }
782 692
783 void ProfileSyncService::Shutdown() { 693 void ProfileSyncService::Shutdown() {
784 UnregisterAuthNotifications(); 694 UnregisterAuthNotifications();
785 695
786 ShutdownImpl(browser_sync::SyncBackendHost::STOP); 696 ShutdownImpl(browser_sync::SyncBackendHost::STOP);
787 697
788 if (sync_thread_) 698 if (sync_thread_)
789 sync_thread_->Stop(); 699 sync_thread_->Stop();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
831 scoped_ptr<SyncBackendHost> doomed_backend(backend_.release()); 741 scoped_ptr<SyncBackendHost> doomed_backend(backend_.release());
832 if (doomed_backend) { 742 if (doomed_backend) {
833 sync_thread_ = doomed_backend->Shutdown(option); 743 sync_thread_ = doomed_backend->Shutdown(option);
834 doomed_backend.reset(); 744 doomed_backend.reset();
835 } 745 }
836 base::TimeDelta shutdown_time = base::Time::Now() - shutdown_start_time; 746 base::TimeDelta shutdown_time = base::Time::Now() - shutdown_start_time;
837 UMA_HISTOGRAM_TIMES("Sync.Shutdown.BackendDestroyedTime", shutdown_time); 747 UMA_HISTOGRAM_TIMES("Sync.Shutdown.BackendDestroyedTime", shutdown_time);
838 748
839 weak_factory_.InvalidateWeakPtrs(); 749 weak_factory_.InvalidateWeakPtrs();
840 750
751 startup_controller_.Reset();
752
841 // Clear various flags. 753 // Clear various flags.
842 start_up_time_ = base::Time();
843 expect_sync_configuration_aborted_ = false; 754 expect_sync_configuration_aborted_ = false;
844 is_auth_in_progress_ = false; 755 is_auth_in_progress_ = false;
845 backend_initialized_ = false; 756 backend_initialized_ = false;
846 cached_passphrase_.clear(); 757 cached_passphrase_.clear();
847 access_token_.clear(); 758 access_token_.clear();
848 encryption_pending_ = false; 759 encryption_pending_ = false;
849 encrypt_everything_ = false; 760 encrypt_everything_ = false;
850 encrypted_types_ = syncer::SyncEncryptionHandler::SensitiveTypes(); 761 encrypted_types_ = syncer::SyncEncryptionHandler::SensitiveTypes();
851 passphrase_required_reason_ = syncer::REASON_PASSPHRASE_NOT_REQUIRED; 762 passphrase_required_reason_ = syncer::REASON_PASSPHRASE_NOT_REQUIRED;
852 request_access_token_retry_timer_.Stop(); 763 request_access_token_retry_timer_.Stop();
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
982 debug_info_listener, 893 debug_info_listener,
983 bool success) { 894 bool success) {
984 is_first_time_sync_configure_ = !HasSyncSetupCompleted(); 895 is_first_time_sync_configure_ = !HasSyncSetupCompleted();
985 896
986 if (is_first_time_sync_configure_) { 897 if (is_first_time_sync_configure_) {
987 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeFirstTimeSuccess", success); 898 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeFirstTimeSuccess", success);
988 } else { 899 } else {
989 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeRestoreSuccess", success); 900 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeRestoreSuccess", success);
990 } 901 }
991 902
992 DCHECK(!start_up_time_.is_null());
993 base::Time on_backend_initialized_time = base::Time::Now(); 903 base::Time on_backend_initialized_time = base::Time::Now();
994 base::TimeDelta delta = on_backend_initialized_time - start_up_time_; 904 base::TimeDelta delta = on_backend_initialized_time -
905 startup_controller_.start_backend_time();
995 if (is_first_time_sync_configure_) { 906 if (is_first_time_sync_configure_) {
996 UMA_HISTOGRAM_LONG_TIMES("Sync.BackendInitializeFirstTime", delta); 907 UMA_HISTOGRAM_LONG_TIMES("Sync.BackendInitializeFirstTime", delta);
997 } else { 908 } else {
998 UMA_HISTOGRAM_LONG_TIMES("Sync.BackendInitializeRestoreTime", delta); 909 UMA_HISTOGRAM_LONG_TIMES("Sync.BackendInitializeRestoreTime", delta);
999 } 910 }
1000 911
1001 if (!success) { 912 if (!success) {
1002 // Something went unexpectedly wrong. Play it safe: stop syncing at once 913 // Something went unexpectedly wrong. Play it safe: stop syncing at once
1003 // and surface error UI to alert the user sync has stopped. 914 // and surface error UI to alert the user sync has stopped.
1004 // Keep the directory around for now so that on restart we will retry 915 // Keep the directory around for now so that on restart we will retry
(...skipping 23 matching lines...) Expand all
1028 // case this operation affects the "passphrase required" status. 939 // case this operation affects the "passphrase required" status.
1029 ConsumeCachedPassphraseIfPossible(); 940 ConsumeCachedPassphraseIfPossible();
1030 941
1031 // The very first time the backend initializes is effectively the first time 942 // The very first time the backend initializes is effectively the first time
1032 // we can say we successfully "synced". last_synced_time_ will only be null 943 // we can say we successfully "synced". last_synced_time_ will only be null
1033 // in this case, because the pref wasn't restored on StartUp. 944 // in this case, because the pref wasn't restored on StartUp.
1034 if (last_synced_time_.is_null()) { 945 if (last_synced_time_.is_null()) {
1035 UpdateLastSyncedTime(); 946 UpdateLastSyncedTime();
1036 } 947 }
1037 948
1038 if (auto_start_enabled_ && !FirstSetupInProgress()) { 949 if (startup_controller_.auto_start_enabled() && !FirstSetupInProgress()) {
1039 // Backend is initialized but we're not in sync setup, so this must be an 950 // Backend is initialized but we're not in sync setup, so this must be an
1040 // autostart - mark our sync setup as completed and we'll start syncing 951 // autostart - mark our sync setup as completed and we'll start syncing
1041 // below. 952 // below.
1042 SetSyncSetupCompleted(); 953 SetSyncSetupCompleted();
1043 } 954 }
1044 955
1045 // Check HasSyncSetupCompleted() before NotifyObservers() to avoid spurious 956 // Check HasSyncSetupCompleted() before NotifyObservers() to avoid spurious
1046 // data type configuration because observer may flag setup as complete and 957 // data type configuration because observer may flag setup as complete and
1047 // trigger data type configuration. 958 // trigger data type configuration.
1048 if (HasSyncSetupCompleted()) { 959 if (HasSyncSetupCompleted()) {
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
1337 DCHECK_NE(last_actionable_error_.action, 1248 DCHECK_NE(last_actionable_error_.action,
1338 syncer::UNKNOWN_ACTION); 1249 syncer::UNKNOWN_ACTION);
1339 switch (error.action) { 1250 switch (error.action) {
1340 case syncer::UPGRADE_CLIENT: 1251 case syncer::UPGRADE_CLIENT:
1341 case syncer::CLEAR_USER_DATA_AND_RESYNC: 1252 case syncer::CLEAR_USER_DATA_AND_RESYNC:
1342 case syncer::ENABLE_SYNC_ON_ACCOUNT: 1253 case syncer::ENABLE_SYNC_ON_ACCOUNT:
1343 case syncer::STOP_AND_RESTART_SYNC: 1254 case syncer::STOP_AND_RESTART_SYNC:
1344 // TODO(lipalani) : if setup in progress we want to display these 1255 // TODO(lipalani) : if setup in progress we want to display these
1345 // actions in the popup. The current experience might not be optimal for 1256 // actions in the popup. The current experience might not be optimal for
1346 // the user. We just dismiss the dialog. 1257 // the user. We just dismiss the dialog.
1347 if (setup_in_progress_) { 1258 if (startup_controller_.setup_in_progress()) {
1348 StopSyncingPermanently(); 1259 StopSyncingPermanently();
1349 expect_sync_configuration_aborted_ = true; 1260 expect_sync_configuration_aborted_ = true;
1350 } 1261 }
1351 // Trigger an unrecoverable error to stop syncing. 1262 // Trigger an unrecoverable error to stop syncing.
1352 OnInternalUnrecoverableError(FROM_HERE, 1263 OnInternalUnrecoverableError(FROM_HERE,
1353 last_actionable_error_.error_description, 1264 last_actionable_error_.error_description,
1354 true, 1265 true,
1355 ERROR_REASON_ACTIONABLE_ERROR); 1266 ERROR_REASON_ACTIONABLE_ERROR);
1356 break; 1267 break;
1357 case syncer::DISABLE_SYNC_ON_CLIENT: 1268 case syncer::DISABLE_SYNC_ON_CLIENT:
1358 StopSyncingPermanently(); 1269 StopSyncingPermanently();
1359 #if !defined(OS_CHROMEOS) 1270 #if !defined(OS_CHROMEOS)
1360 // On desktop Chrome, sign out the user after a dashboard clear. 1271 // On desktop Chrome, sign out the user after a dashboard clear.
1361 // TODO(rsimha): Revisit this for M30. See http://crbug.com/252049. 1272 // Skip sign out on ChromeOS/Android.
1362 if (!auto_start_enabled_) // Skip sign out on ChromeOS/Android. 1273 if (!startup_controller_.auto_start_enabled())
1363 SigninManagerFactory::GetForProfile(profile_)->SignOut(); 1274 SigninManagerFactory::GetForProfile(profile_)->SignOut();
1364 #endif 1275 #endif
1365 break; 1276 break;
1366 case syncer::STOP_SYNC_FOR_DISABLED_ACCOUNT: 1277 case syncer::STOP_SYNC_FOR_DISABLED_ACCOUNT:
1367 // Sync disabled by domain admin. we should stop syncing until next 1278 // Sync disabled by domain admin. we should stop syncing until next
1368 // restart. 1279 // restart.
1369 sync_disabled_by_admin_ = true; 1280 sync_disabled_by_admin_ = true;
1370 ShutdownImpl(browser_sync::SyncBackendHost::DISABLE_AND_CLAIM_THREAD); 1281 ShutdownImpl(browser_sync::SyncBackendHost::DISABLE_AND_CLAIM_THREAD);
1371 break; 1282 break;
1372 default: 1283 default:
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1507 case DATATYPES_NOT_INITIALIZED: 1418 case DATATYPES_NOT_INITIALIZED:
1508 return "Datatypes not fully initialized"; 1419 return "Datatypes not fully initialized";
1509 case INITIALIZED: 1420 case INITIALIZED:
1510 return "Sync service initialized"; 1421 return "Sync service initialized";
1511 default: 1422 default:
1512 return "Status unknown: Internal error?"; 1423 return "Status unknown: Internal error?";
1513 } 1424 }
1514 } 1425 }
1515 1426
1516 std::string ProfileSyncService::GetBackendInitializationStateString() const { 1427 std::string ProfileSyncService::GetBackendInitializationStateString() const {
1517 if (sync_initialized()) 1428 return startup_controller_.GetBackendInitializationStateString();
1518 return "Done"; 1429 }
1519 else if (!start_up_time_.is_null()) 1430
1520 return "Deferred"; 1431 bool ProfileSyncService::auto_start_enabled() const {
1521 else 1432 return startup_controller_.auto_start_enabled();
1522 return "Not started"; 1433 }
1434
1435 bool ProfileSyncService::setup_in_progress() const {
1436 return startup_controller_.setup_in_progress();
1523 } 1437 }
1524 1438
1525 bool ProfileSyncService::QueryDetailedSyncStatus( 1439 bool ProfileSyncService::QueryDetailedSyncStatus(
1526 SyncBackendHost::Status* result) { 1440 SyncBackendHost::Status* result) {
1527 if (backend_.get() && backend_initialized_) { 1441 if (backend_.get() && backend_initialized_) {
1528 *result = backend_->GetDetailedStatus(); 1442 *result = backend_->GetDetailedStatus();
1529 return true; 1443 return true;
1530 } else { 1444 } else {
1531 SyncBackendHost::Status status; 1445 SyncBackendHost::Status status;
1532 status.sync_protocol_error = last_actionable_error_; 1446 status.sync_protocol_error = last_actionable_error_;
1533 *result = status; 1447 *result = status;
1534 return false; 1448 return false;
1535 } 1449 }
1536 } 1450 }
1537 1451
1538 const AuthError& ProfileSyncService::GetAuthError() const { 1452 const AuthError& ProfileSyncService::GetAuthError() const {
1539 return last_auth_error_; 1453 return last_auth_error_;
1540 } 1454 }
1541 1455
1542 bool ProfileSyncService::FirstSetupInProgress() const { 1456 bool ProfileSyncService::FirstSetupInProgress() const {
1543 return !HasSyncSetupCompleted() && setup_in_progress_; 1457 return !HasSyncSetupCompleted() && startup_controller_.setup_in_progress();
1544 } 1458 }
1545 1459
1546 void ProfileSyncService::SetSetupInProgress(bool setup_in_progress) { 1460 void ProfileSyncService::SetSetupInProgress(bool setup_in_progress) {
1547 // This method is a no-op if |setup_in_progress_| remains unchanged. 1461 // This method is a no-op if |setup_in_progress_| remains unchanged.
1548 if (setup_in_progress_ == setup_in_progress) 1462 if (startup_controller_.setup_in_progress() == setup_in_progress)
1549 return; 1463 return;
1550 1464
1551 setup_in_progress_ = setup_in_progress; 1465 startup_controller_.set_setup_in_progress(setup_in_progress);
1552 if (!setup_in_progress && sync_initialized()) 1466 if (!setup_in_progress && sync_initialized())
1553 ReconfigureDatatypeManager(); 1467 ReconfigureDatatypeManager();
1554 NotifyObservers(); 1468 NotifyObservers();
1555 } 1469 }
1556 1470
1557 bool ProfileSyncService::sync_initialized() const { 1471 bool ProfileSyncService::sync_initialized() const {
1558 return backend_initialized_; 1472 return backend_initialized_;
1559 } 1473 }
1560 1474
1561 bool ProfileSyncService::waiting_for_auth() const { 1475 bool ProfileSyncService::waiting_for_auth() const {
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
1751 data_type_manager_->Configure(priority_types, reason); 1665 data_type_manager_->Configure(priority_types, reason);
1752 } 1666 }
1753 } 1667 }
1754 1668
1755 void ProfileSyncService::ConfigureDataTypeManager() { 1669 void ProfileSyncService::ConfigureDataTypeManager() {
1756 // Don't configure datatypes if the setup UI is still on the screen - this 1670 // Don't configure datatypes if the setup UI is still on the screen - this
1757 // is to help multi-screen setting UIs (like iOS) where they don't want to 1671 // is to help multi-screen setting UIs (like iOS) where they don't want to
1758 // start syncing data until the user is done configuring encryption options, 1672 // start syncing data until the user is done configuring encryption options,
1759 // etc. ReconfigureDatatypeManager() will get called again once the UI calls 1673 // etc. ReconfigureDatatypeManager() will get called again once the UI calls
1760 // SetSetupInProgress(false). 1674 // SetSetupInProgress(false).
1761 if (setup_in_progress_) 1675 if (startup_controller_.setup_in_progress())
1762 return; 1676 return;
1763 1677
1764 bool restart = false; 1678 bool restart = false;
1765 if (!data_type_manager_) { 1679 if (!data_type_manager_) {
1766 restart = true; 1680 restart = true;
1767 data_type_manager_.reset( 1681 data_type_manager_.reset(
1768 factory_->CreateDataTypeManager(debug_info_listener_, 1682 factory_->CreateDataTypeManager(debug_info_listener_,
1769 &data_type_controllers_, 1683 &data_type_controllers_,
1770 this, 1684 this,
1771 backend_.get(), 1685 backend_.get(),
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
2055 // initialized. In this case, we default to the sensitive types. 1969 // initialized. In this case, we default to the sensitive types.
2056 return encrypted_types_; 1970 return encrypted_types_;
2057 } 1971 }
2058 1972
2059 void ProfileSyncService::OnSyncManagedPrefChange(bool is_sync_managed) { 1973 void ProfileSyncService::OnSyncManagedPrefChange(bool is_sync_managed) {
2060 NotifyObservers(); 1974 NotifyObservers();
2061 if (is_sync_managed) { 1975 if (is_sync_managed) {
2062 DisableForUser(); 1976 DisableForUser();
2063 } else { 1977 } else {
2064 // Sync is no longer disabled by policy. Try starting it up if appropriate. 1978 // Sync is no longer disabled by policy. Try starting it up if appropriate.
2065 TryStart(); 1979 startup_controller_.TryStart();
2066 } 1980 }
2067 } 1981 }
2068 1982
2069 void ProfileSyncService::Observe(int type, 1983 void ProfileSyncService::Observe(int type,
2070 const content::NotificationSource& source, 1984 const content::NotificationSource& source,
2071 const content::NotificationDetails& details) { 1985 const content::NotificationDetails& details) {
2072 switch (type) { 1986 switch (type) {
2073 case chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL: { 1987 case chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL: {
2074 const GoogleServiceSigninSuccessDetails* successful = 1988 const GoogleServiceSigninSuccessDetails* successful =
2075 content::Details<const GoogleServiceSigninSuccessDetails>( 1989 content::Details<const GoogleServiceSigninSuccessDetails>(
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
2168 void ProfileSyncService::UnsuppressAndStart() { 2082 void ProfileSyncService::UnsuppressAndStart() {
2169 DCHECK(profile_); 2083 DCHECK(profile_);
2170 sync_prefs_.SetStartSuppressed(false); 2084 sync_prefs_.SetStartSuppressed(false);
2171 // Set username in SigninManager, as SigninManager::OnGetUserInfoSuccess 2085 // Set username in SigninManager, as SigninManager::OnGetUserInfoSuccess
2172 // is never called for some clients. 2086 // is never called for some clients.
2173 if (signin_.get() && 2087 if (signin_.get() &&
2174 signin_->GetOriginal()->GetAuthenticatedUsername().empty()) { 2088 signin_->GetOriginal()->GetAuthenticatedUsername().empty()) {
2175 signin_->GetOriginal()->SetAuthenticatedUsername( 2089 signin_->GetOriginal()->SetAuthenticatedUsername(
2176 sync_prefs_.GetGoogleServicesUsername()); 2090 sync_prefs_.GetGoogleServicesUsername());
2177 } 2091 }
2178 TryStart(); 2092 startup_controller_.TryStart();
2179 } 2093 }
2180 2094
2181 void ProfileSyncService::AcknowledgeSyncedTypes() { 2095 void ProfileSyncService::AcknowledgeSyncedTypes() {
2182 sync_prefs_.AcknowledgeSyncedTypes(GetRegisteredDataTypes()); 2096 sync_prefs_.AcknowledgeSyncedTypes(GetRegisteredDataTypes());
2183 } 2097 }
2184 2098
2185 void ProfileSyncService::ReconfigureDatatypeManager() { 2099 void ProfileSyncService::ReconfigureDatatypeManager() {
2186 // If we haven't initialized yet, don't configure the DTM as it could cause 2100 // If we haven't initialized yet, don't configure the DTM as it could cause
2187 // association to start before a Directory has even been created. 2101 // association to start before a Directory has even been created.
2188 if (backend_initialized_) { 2102 if (backend_initialized_) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
2246 status.last_get_token_error = last_get_token_error_; 2160 status.last_get_token_error = last_get_token_error_;
2247 if (request_access_token_retry_timer_.IsRunning()) 2161 if (request_access_token_retry_timer_.IsRunning())
2248 status.next_token_request_time = next_token_request_time_; 2162 status.next_token_request_time = next_token_request_time_;
2249 return status; 2163 return status;
2250 } 2164 }
2251 2165
2252 void ProfileSyncService::OverrideNetworkResourcesForTest( 2166 void ProfileSyncService::OverrideNetworkResourcesForTest(
2253 scoped_ptr<syncer::NetworkResources> network_resources) { 2167 scoped_ptr<syncer::NetworkResources> network_resources) {
2254 network_resources_ = network_resources.Pass(); 2168 network_resources_ = network_resources.Pass();
2255 } 2169 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698