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

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: rebase again 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())) {
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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
977 debug_info_listener, 888 debug_info_listener,
978 bool success) { 889 bool success) {
979 is_first_time_sync_configure_ = !HasSyncSetupCompleted(); 890 is_first_time_sync_configure_ = !HasSyncSetupCompleted();
980 891
981 if (is_first_time_sync_configure_) { 892 if (is_first_time_sync_configure_) {
982 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeFirstTimeSuccess", success); 893 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeFirstTimeSuccess", success);
983 } else { 894 } else {
984 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeRestoreSuccess", success); 895 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeRestoreSuccess", success);
985 } 896 }
986 897
987 DCHECK(!start_up_time_.is_null());
988 base::Time on_backend_initialized_time = base::Time::Now(); 898 base::Time on_backend_initialized_time = base::Time::Now();
989 base::TimeDelta delta = on_backend_initialized_time - start_up_time_; 899 base::TimeDelta delta = on_backend_initialized_time -
900 startup_controller_.start_backend_time();
990 if (is_first_time_sync_configure_) { 901 if (is_first_time_sync_configure_) {
991 UMA_HISTOGRAM_LONG_TIMES("Sync.BackendInitializeFirstTime", delta); 902 UMA_HISTOGRAM_LONG_TIMES("Sync.BackendInitializeFirstTime", delta);
992 } else { 903 } else {
993 UMA_HISTOGRAM_LONG_TIMES("Sync.BackendInitializeRestoreTime", delta); 904 UMA_HISTOGRAM_LONG_TIMES("Sync.BackendInitializeRestoreTime", delta);
994 } 905 }
995 906
996 if (!success) { 907 if (!success) {
997 // Something went unexpectedly wrong. Play it safe: stop syncing at once 908 // Something went unexpectedly wrong. Play it safe: stop syncing at once
998 // and surface error UI to alert the user sync has stopped. 909 // and surface error UI to alert the user sync has stopped.
999 // Keep the directory around for now so that on restart we will retry 910 // Keep the directory around for now so that on restart we will retry
(...skipping 23 matching lines...) Expand all
1023 // case this operation affects the "passphrase required" status. 934 // case this operation affects the "passphrase required" status.
1024 ConsumeCachedPassphraseIfPossible(); 935 ConsumeCachedPassphraseIfPossible();
1025 936
1026 // The very first time the backend initializes is effectively the first time 937 // The very first time the backend initializes is effectively the first time
1027 // we can say we successfully "synced". last_synced_time_ will only be null 938 // we can say we successfully "synced". last_synced_time_ will only be null
1028 // in this case, because the pref wasn't restored on StartUp. 939 // in this case, because the pref wasn't restored on StartUp.
1029 if (last_synced_time_.is_null()) { 940 if (last_synced_time_.is_null()) {
1030 UpdateLastSyncedTime(); 941 UpdateLastSyncedTime();
1031 } 942 }
1032 943
1033 if (auto_start_enabled_ && !FirstSetupInProgress()) { 944 if (startup_controller_.auto_start_enabled() && !FirstSetupInProgress()) {
1034 // Backend is initialized but we're not in sync setup, so this must be an 945 // Backend is initialized but we're not in sync setup, so this must be an
1035 // autostart - mark our sync setup as completed and we'll start syncing 946 // autostart - mark our sync setup as completed and we'll start syncing
1036 // below. 947 // below.
1037 SetSyncSetupCompleted(); 948 SetSyncSetupCompleted();
1038 } 949 }
1039 950
1040 // Check HasSyncSetupCompleted() before NotifyObservers() to avoid spurious 951 // Check HasSyncSetupCompleted() before NotifyObservers() to avoid spurious
1041 // data type configuration because observer may flag setup as complete and 952 // data type configuration because observer may flag setup as complete and
1042 // trigger data type configuration. 953 // trigger data type configuration.
1043 if (HasSyncSetupCompleted()) { 954 if (HasSyncSetupCompleted()) {
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
1332 DCHECK_NE(last_actionable_error_.action, 1243 DCHECK_NE(last_actionable_error_.action,
1333 syncer::UNKNOWN_ACTION); 1244 syncer::UNKNOWN_ACTION);
1334 switch (error.action) { 1245 switch (error.action) {
1335 case syncer::UPGRADE_CLIENT: 1246 case syncer::UPGRADE_CLIENT:
1336 case syncer::CLEAR_USER_DATA_AND_RESYNC: 1247 case syncer::CLEAR_USER_DATA_AND_RESYNC:
1337 case syncer::ENABLE_SYNC_ON_ACCOUNT: 1248 case syncer::ENABLE_SYNC_ON_ACCOUNT:
1338 case syncer::STOP_AND_RESTART_SYNC: 1249 case syncer::STOP_AND_RESTART_SYNC:
1339 // TODO(lipalani) : if setup in progress we want to display these 1250 // TODO(lipalani) : if setup in progress we want to display these
1340 // actions in the popup. The current experience might not be optimal for 1251 // actions in the popup. The current experience might not be optimal for
1341 // the user. We just dismiss the dialog. 1252 // the user. We just dismiss the dialog.
1342 if (setup_in_progress_) { 1253 if (startup_controller_.setup_in_progress()) {
1343 StopSyncingPermanently(); 1254 StopSyncingPermanently();
1344 expect_sync_configuration_aborted_ = true; 1255 expect_sync_configuration_aborted_ = true;
1345 } 1256 }
1346 // Trigger an unrecoverable error to stop syncing. 1257 // Trigger an unrecoverable error to stop syncing.
1347 OnInternalUnrecoverableError(FROM_HERE, 1258 OnInternalUnrecoverableError(FROM_HERE,
1348 last_actionable_error_.error_description, 1259 last_actionable_error_.error_description,
1349 true, 1260 true,
1350 ERROR_REASON_ACTIONABLE_ERROR); 1261 ERROR_REASON_ACTIONABLE_ERROR);
1351 break; 1262 break;
1352 case syncer::DISABLE_SYNC_ON_CLIENT: 1263 case syncer::DISABLE_SYNC_ON_CLIENT:
1353 StopSyncingPermanently(); 1264 StopSyncingPermanently();
1354 #if !defined(OS_CHROMEOS) 1265 #if !defined(OS_CHROMEOS)
1355 // On desktop Chrome, sign out the user after a dashboard clear. 1266 // On desktop Chrome, sign out the user after a dashboard clear.
1356 // TODO(rsimha): Revisit this for M30. See http://crbug.com/252049. 1267 // Skip sign out on ChromeOS/Android.
1357 if (!auto_start_enabled_) // Skip sign out on ChromeOS/Android. 1268 if (!startup_controller_.auto_start_enabled())
1358 SigninManagerFactory::GetForProfile(profile_)->SignOut(); 1269 SigninManagerFactory::GetForProfile(profile_)->SignOut();
1359 #endif 1270 #endif
1360 break; 1271 break;
1361 case syncer::STOP_SYNC_FOR_DISABLED_ACCOUNT: 1272 case syncer::STOP_SYNC_FOR_DISABLED_ACCOUNT:
1362 // Sync disabled by domain admin. we should stop syncing until next 1273 // Sync disabled by domain admin. we should stop syncing until next
1363 // restart. 1274 // restart.
1364 sync_disabled_by_admin_ = true; 1275 sync_disabled_by_admin_ = true;
1365 ShutdownImpl(browser_sync::SyncBackendHost::DISABLE_AND_CLAIM_THREAD); 1276 ShutdownImpl(browser_sync::SyncBackendHost::DISABLE_AND_CLAIM_THREAD);
1366 break; 1277 break;
1367 default: 1278 default:
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1502 case DATATYPES_NOT_INITIALIZED: 1413 case DATATYPES_NOT_INITIALIZED:
1503 return "Datatypes not fully initialized"; 1414 return "Datatypes not fully initialized";
1504 case INITIALIZED: 1415 case INITIALIZED:
1505 return "Sync service initialized"; 1416 return "Sync service initialized";
1506 default: 1417 default:
1507 return "Status unknown: Internal error?"; 1418 return "Status unknown: Internal error?";
1508 } 1419 }
1509 } 1420 }
1510 1421
1511 std::string ProfileSyncService::GetBackendInitializationStateString() const { 1422 std::string ProfileSyncService::GetBackendInitializationStateString() const {
1512 if (sync_initialized()) 1423 return startup_controller_.GetBackendInitializationStateString();
1513 return "Done"; 1424 }
1514 else if (!start_up_time_.is_null()) 1425
1515 return "Deferred"; 1426 bool ProfileSyncService::auto_start_enabled() const {
1516 else 1427 return startup_controller_.auto_start_enabled();
1517 return "Not started"; 1428 }
1429
1430 bool ProfileSyncService::setup_in_progress() const {
1431 return startup_controller_.setup_in_progress();
1518 } 1432 }
1519 1433
1520 bool ProfileSyncService::QueryDetailedSyncStatus( 1434 bool ProfileSyncService::QueryDetailedSyncStatus(
1521 SyncBackendHost::Status* result) { 1435 SyncBackendHost::Status* result) {
1522 if (backend_.get() && backend_initialized_) { 1436 if (backend_.get() && backend_initialized_) {
1523 *result = backend_->GetDetailedStatus(); 1437 *result = backend_->GetDetailedStatus();
1524 return true; 1438 return true;
1525 } else { 1439 } else {
1526 SyncBackendHost::Status status; 1440 SyncBackendHost::Status status;
1527 status.sync_protocol_error = last_actionable_error_; 1441 status.sync_protocol_error = last_actionable_error_;
1528 *result = status; 1442 *result = status;
1529 return false; 1443 return false;
1530 } 1444 }
1531 } 1445 }
1532 1446
1533 const AuthError& ProfileSyncService::GetAuthError() const { 1447 const AuthError& ProfileSyncService::GetAuthError() const {
1534 return last_auth_error_; 1448 return last_auth_error_;
1535 } 1449 }
1536 1450
1537 bool ProfileSyncService::FirstSetupInProgress() const { 1451 bool ProfileSyncService::FirstSetupInProgress() const {
1538 return !HasSyncSetupCompleted() && setup_in_progress_; 1452 return !HasSyncSetupCompleted() && startup_controller_.setup_in_progress();
1539 } 1453 }
1540 1454
1541 void ProfileSyncService::SetSetupInProgress(bool setup_in_progress) { 1455 void ProfileSyncService::SetSetupInProgress(bool setup_in_progress) {
1542 // This method is a no-op if |setup_in_progress_| remains unchanged. 1456 // This method is a no-op if |setup_in_progress_| remains unchanged.
1543 if (setup_in_progress_ == setup_in_progress) 1457 if (startup_controller_.setup_in_progress() == setup_in_progress)
1544 return; 1458 return;
1545 1459
1546 setup_in_progress_ = setup_in_progress; 1460 startup_controller_.set_setup_in_progress(setup_in_progress);
1547 if (!setup_in_progress && sync_initialized()) 1461 if (!setup_in_progress && sync_initialized())
1548 ReconfigureDatatypeManager(); 1462 ReconfigureDatatypeManager();
1549 NotifyObservers(); 1463 NotifyObservers();
1550 } 1464 }
1551 1465
1552 bool ProfileSyncService::sync_initialized() const { 1466 bool ProfileSyncService::sync_initialized() const {
1553 return backend_initialized_; 1467 return backend_initialized_;
1554 } 1468 }
1555 1469
1556 bool ProfileSyncService::waiting_for_auth() const { 1470 bool ProfileSyncService::waiting_for_auth() const {
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
1746 data_type_manager_->Configure(priority_types, reason); 1660 data_type_manager_->Configure(priority_types, reason);
1747 } 1661 }
1748 } 1662 }
1749 1663
1750 void ProfileSyncService::ConfigureDataTypeManager() { 1664 void ProfileSyncService::ConfigureDataTypeManager() {
1751 // Don't configure datatypes if the setup UI is still on the screen - this 1665 // Don't configure datatypes if the setup UI is still on the screen - this
1752 // is to help multi-screen setting UIs (like iOS) where they don't want to 1666 // is to help multi-screen setting UIs (like iOS) where they don't want to
1753 // start syncing data until the user is done configuring encryption options, 1667 // start syncing data until the user is done configuring encryption options,
1754 // etc. ReconfigureDatatypeManager() will get called again once the UI calls 1668 // etc. ReconfigureDatatypeManager() will get called again once the UI calls
1755 // SetSetupInProgress(false). 1669 // SetSetupInProgress(false).
1756 if (setup_in_progress_) 1670 if (startup_controller_.setup_in_progress())
1757 return; 1671 return;
1758 1672
1759 bool restart = false; 1673 bool restart = false;
1760 if (!data_type_manager_) { 1674 if (!data_type_manager_) {
1761 restart = true; 1675 restart = true;
1762 data_type_manager_.reset( 1676 data_type_manager_.reset(
1763 factory_->CreateDataTypeManager(debug_info_listener_, 1677 factory_->CreateDataTypeManager(debug_info_listener_,
1764 &data_type_controllers_, 1678 &data_type_controllers_,
1765 this, 1679 this,
1766 backend_.get(), 1680 backend_.get(),
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
2050 // initialized. In this case, we default to the sensitive types. 1964 // initialized. In this case, we default to the sensitive types.
2051 return encrypted_types_; 1965 return encrypted_types_;
2052 } 1966 }
2053 1967
2054 void ProfileSyncService::OnSyncManagedPrefChange(bool is_sync_managed) { 1968 void ProfileSyncService::OnSyncManagedPrefChange(bool is_sync_managed) {
2055 NotifyObservers(); 1969 NotifyObservers();
2056 if (is_sync_managed) { 1970 if (is_sync_managed) {
2057 DisableForUser(); 1971 DisableForUser();
2058 } else { 1972 } else {
2059 // Sync is no longer disabled by policy. Try starting it up if appropriate. 1973 // Sync is no longer disabled by policy. Try starting it up if appropriate.
2060 TryStart(); 1974 startup_controller_.TryStart();
2061 } 1975 }
2062 } 1976 }
2063 1977
2064 void ProfileSyncService::Observe(int type, 1978 void ProfileSyncService::Observe(int type,
2065 const content::NotificationSource& source, 1979 const content::NotificationSource& source,
2066 const content::NotificationDetails& details) { 1980 const content::NotificationDetails& details) {
2067 switch (type) { 1981 switch (type) {
2068 case chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL: { 1982 case chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL: {
2069 const GoogleServiceSigninSuccessDetails* successful = 1983 const GoogleServiceSigninSuccessDetails* successful =
2070 content::Details<const GoogleServiceSigninSuccessDetails>( 1984 content::Details<const GoogleServiceSigninSuccessDetails>(
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
2163 void ProfileSyncService::UnsuppressAndStart() { 2077 void ProfileSyncService::UnsuppressAndStart() {
2164 DCHECK(profile_); 2078 DCHECK(profile_);
2165 sync_prefs_.SetStartSuppressed(false); 2079 sync_prefs_.SetStartSuppressed(false);
2166 // Set username in SigninManager, as SigninManager::OnGetUserInfoSuccess 2080 // Set username in SigninManager, as SigninManager::OnGetUserInfoSuccess
2167 // is never called for some clients. 2081 // is never called for some clients.
2168 if (signin_.get() && 2082 if (signin_.get() &&
2169 signin_->GetOriginal()->GetAuthenticatedUsername().empty()) { 2083 signin_->GetOriginal()->GetAuthenticatedUsername().empty()) {
2170 signin_->GetOriginal()->SetAuthenticatedUsername( 2084 signin_->GetOriginal()->SetAuthenticatedUsername(
2171 sync_prefs_.GetGoogleServicesUsername()); 2085 sync_prefs_.GetGoogleServicesUsername());
2172 } 2086 }
2173 TryStart(); 2087 startup_controller_.TryStart();
2174 } 2088 }
2175 2089
2176 void ProfileSyncService::AcknowledgeSyncedTypes() { 2090 void ProfileSyncService::AcknowledgeSyncedTypes() {
2177 sync_prefs_.AcknowledgeSyncedTypes(GetRegisteredDataTypes()); 2091 sync_prefs_.AcknowledgeSyncedTypes(GetRegisteredDataTypes());
2178 } 2092 }
2179 2093
2180 void ProfileSyncService::ReconfigureDatatypeManager() { 2094 void ProfileSyncService::ReconfigureDatatypeManager() {
2181 // If we haven't initialized yet, don't configure the DTM as it could cause 2095 // If we haven't initialized yet, don't configure the DTM as it could cause
2182 // association to start before a Directory has even been created. 2096 // association to start before a Directory has even been created.
2183 if (backend_initialized_) { 2097 if (backend_initialized_) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
2241 status.last_get_token_error = last_get_token_error_; 2155 status.last_get_token_error = last_get_token_error_;
2242 if (request_access_token_retry_timer_.IsRunning()) 2156 if (request_access_token_retry_timer_.IsRunning())
2243 status.next_token_request_time = next_token_request_time_; 2157 status.next_token_request_time = next_token_request_time_;
2244 return status; 2158 return status;
2245 } 2159 }
2246 2160
2247 void ProfileSyncService::OverrideNetworkResourcesForTest( 2161 void ProfileSyncService::OverrideNetworkResourcesForTest(
2248 scoped_ptr<syncer::NetworkResources> network_resources) { 2162 scoped_ptr<syncer::NetworkResources> network_resources) {
2249 network_resources_ = network_resources.Pass(); 2163 network_resources_ = network_resources.Pass();
2250 } 2164 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/profile_sync_service.h ('k') | chrome/browser/sync/profile_sync_service_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698