| 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 "components/browser_sync/profile_sync_service.h" | 5 #include "components/browser_sync/profile_sync_service.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <cstddef> | 9 #include <cstddef> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 syncer::GetSyncServiceURL(*base::CommandLine::ForCurrentProcess(), | 196 syncer::GetSyncServiceURL(*base::CommandLine::ForCurrentProcess(), |
| 197 init_params.channel)), | 197 init_params.channel)), |
| 198 network_time_update_callback_( | 198 network_time_update_callback_( |
| 199 std::move(init_params.network_time_update_callback)), | 199 std::move(init_params.network_time_update_callback)), |
| 200 base_directory_(init_params.base_directory), | 200 base_directory_(init_params.base_directory), |
| 201 url_request_context_(init_params.url_request_context), | 201 url_request_context_(init_params.url_request_context), |
| 202 debug_identifier_(std::move(init_params.debug_identifier)), | 202 debug_identifier_(std::move(init_params.debug_identifier)), |
| 203 channel_(init_params.channel), | 203 channel_(init_params.channel), |
| 204 blocking_pool_(init_params.blocking_pool), | 204 blocking_pool_(init_params.blocking_pool), |
| 205 is_first_time_sync_configure_(false), | 205 is_first_time_sync_configure_(false), |
| 206 backend_initialized_(false), | 206 engine_initialized_(false), |
| 207 sync_disabled_by_admin_(false), | 207 sync_disabled_by_admin_(false), |
| 208 is_auth_in_progress_(false), | 208 is_auth_in_progress_(false), |
| 209 signin_(std::move(init_params.signin_wrapper)), | 209 signin_(std::move(init_params.signin_wrapper)), |
| 210 unrecoverable_error_reason_(ERROR_REASON_UNSET), | 210 unrecoverable_error_reason_(ERROR_REASON_UNSET), |
| 211 expect_sync_configuration_aborted_(false), | 211 expect_sync_configuration_aborted_(false), |
| 212 encrypted_types_(syncer::SyncEncryptionHandler::SensitiveTypes()), | 212 encrypted_types_(syncer::SyncEncryptionHandler::SensitiveTypes()), |
| 213 encrypt_everything_allowed_(true), | 213 encrypt_everything_allowed_(true), |
| 214 encrypt_everything_(false), | 214 encrypt_everything_(false), |
| 215 encryption_pending_(false), | 215 encryption_pending_(false), |
| 216 configure_status_(DataTypeManager::UNKNOWN), | 216 configure_status_(DataTypeManager::UNKNOWN), |
| (...skipping 23 matching lines...) Expand all Loading... |
| 240 passphrase_prompt_triggered_by_version_ = true; | 240 passphrase_prompt_triggered_by_version_ = true; |
| 241 } | 241 } |
| 242 } | 242 } |
| 243 | 243 |
| 244 ProfileSyncService::~ProfileSyncService() { | 244 ProfileSyncService::~ProfileSyncService() { |
| 245 DCHECK(thread_checker_.CalledOnValidThread()); | 245 DCHECK(thread_checker_.CalledOnValidThread()); |
| 246 if (gaia_cookie_manager_service_) | 246 if (gaia_cookie_manager_service_) |
| 247 gaia_cookie_manager_service_->RemoveObserver(this); | 247 gaia_cookie_manager_service_->RemoveObserver(this); |
| 248 sync_prefs_.RemoveSyncPrefObserver(this); | 248 sync_prefs_.RemoveSyncPrefObserver(this); |
| 249 // Shutdown() should have been called before destruction. | 249 // Shutdown() should have been called before destruction. |
| 250 CHECK(!backend_initialized_); | 250 CHECK(!engine_initialized_); |
| 251 } | 251 } |
| 252 | 252 |
| 253 bool ProfileSyncService::CanSyncStart() const { | 253 bool ProfileSyncService::CanSyncStart() const { |
| 254 DCHECK(thread_checker_.CalledOnValidThread()); | 254 DCHECK(thread_checker_.CalledOnValidThread()); |
| 255 return IsSyncAllowed() && IsSyncRequested() && IsSignedIn(); | 255 return IsSyncAllowed() && IsSyncRequested() && IsSignedIn(); |
| 256 } | 256 } |
| 257 | 257 |
| 258 void ProfileSyncService::Initialize() { | 258 void ProfileSyncService::Initialize() { |
| 259 DCHECK(thread_checker_.CalledOnValidThread()); | 259 DCHECK(thread_checker_.CalledOnValidThread()); |
| 260 sync_client_->Initialize(); | 260 sync_client_->Initialize(); |
| 261 | 261 |
| 262 // We don't pass StartupController an Unretained reference to future-proof | 262 // We don't pass StartupController an Unretained reference to future-proof |
| 263 // against the controller impl changing to post tasks. | 263 // against the controller impl changing to post tasks. |
| 264 startup_controller_ = base::MakeUnique<syncer::StartupController>( | 264 startup_controller_ = base::MakeUnique<syncer::StartupController>( |
| 265 &sync_prefs_, | 265 &sync_prefs_, |
| 266 base::Bind(&ProfileSyncService::CanBackendStart, base::Unretained(this)), | 266 base::Bind(&ProfileSyncService::CanEngineStart, base::Unretained(this)), |
| 267 base::Bind(&ProfileSyncService::StartUpSlowBackendComponents, | 267 base::Bind(&ProfileSyncService::StartUpSlowEngineComponents, |
| 268 weak_factory_.GetWeakPtr())); | 268 weak_factory_.GetWeakPtr())); |
| 269 std::unique_ptr<sync_sessions::LocalSessionEventRouter> router( | 269 std::unique_ptr<sync_sessions::LocalSessionEventRouter> router( |
| 270 sync_client_->GetSyncSessionsClient()->GetLocalSessionEventRouter()); | 270 sync_client_->GetSyncSessionsClient()->GetLocalSessionEventRouter()); |
| 271 local_device_ = sync_client_->GetSyncApiComponentFactory() | 271 local_device_ = sync_client_->GetSyncApiComponentFactory() |
| 272 ->CreateLocalDeviceInfoProvider(); | 272 ->CreateLocalDeviceInfoProvider(); |
| 273 sync_stopped_reporter_ = base::MakeUnique<syncer::SyncStoppedReporter>( | 273 sync_stopped_reporter_ = base::MakeUnique<syncer::SyncStoppedReporter>( |
| 274 sync_service_url_, local_device_->GetSyncUserAgent(), | 274 sync_service_url_, local_device_->GetSyncUserAgent(), |
| 275 url_request_context_, syncer::SyncStoppedReporter::ResultCallback()); | 275 url_request_context_, syncer::SyncStoppedReporter::ResultCallback()); |
| 276 sessions_sync_manager_ = base::MakeUnique<SessionsSyncManager>( | 276 sessions_sync_manager_ = base::MakeUnique<SessionsSyncManager>( |
| 277 sync_client_->GetSyncSessionsClient(), &sync_prefs_, local_device_.get(), | 277 sync_client_->GetSyncSessionsClient(), &sync_prefs_, local_device_.get(), |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 } | 384 } |
| 385 | 385 |
| 386 void ProfileSyncService::StartSyncingWithServer() { | 386 void ProfileSyncService::StartSyncingWithServer() { |
| 387 if (base::FeatureList::IsEnabled( | 387 if (base::FeatureList::IsEnabled( |
| 388 switches::kSyncClearDataOnPassphraseEncryption) && | 388 switches::kSyncClearDataOnPassphraseEncryption) && |
| 389 sync_prefs_.GetPassphraseEncryptionTransitionInProgress()) { | 389 sync_prefs_.GetPassphraseEncryptionTransitionInProgress()) { |
| 390 BeginConfigureCatchUpBeforeClear(); | 390 BeginConfigureCatchUpBeforeClear(); |
| 391 return; | 391 return; |
| 392 } | 392 } |
| 393 | 393 |
| 394 if (backend_) | 394 if (engine_) |
| 395 backend_->StartSyncingWithServer(); | 395 engine_->StartSyncingWithServer(); |
| 396 } | 396 } |
| 397 | 397 |
| 398 void ProfileSyncService::RegisterAuthNotifications() { | 398 void ProfileSyncService::RegisterAuthNotifications() { |
| 399 DCHECK(thread_checker_.CalledOnValidThread()); | 399 DCHECK(thread_checker_.CalledOnValidThread()); |
| 400 oauth2_token_service_->AddObserver(this); | 400 oauth2_token_service_->AddObserver(this); |
| 401 if (signin()) | 401 if (signin()) |
| 402 signin()->AddObserver(this); | 402 signin()->AddObserver(this); |
| 403 } | 403 } |
| 404 | 404 |
| 405 void ProfileSyncService::UnregisterAuthNotifications() { | 405 void ProfileSyncService::UnregisterAuthNotifications() { |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 | 492 |
| 493 credentials.scope_set.insert(signin_->GetSyncScopeToUse()); | 493 credentials.scope_set.insert(signin_->GetSyncScopeToUse()); |
| 494 | 494 |
| 495 return credentials; | 495 return credentials; |
| 496 } | 496 } |
| 497 | 497 |
| 498 bool ProfileSyncService::ShouldDeleteSyncFolder() { | 498 bool ProfileSyncService::ShouldDeleteSyncFolder() { |
| 499 return !IsFirstSetupComplete(); | 499 return !IsFirstSetupComplete(); |
| 500 } | 500 } |
| 501 | 501 |
| 502 void ProfileSyncService::InitializeBackend(bool delete_stale_data) { | 502 void ProfileSyncService::InitializeEngine(bool delete_stale_data) { |
| 503 if (!backend_) { | 503 if (!engine_) { |
| 504 NOTREACHED(); | 504 NOTREACHED(); |
| 505 return; | 505 return; |
| 506 } | 506 } |
| 507 | 507 |
| 508 if (!sync_thread_) { | 508 if (!sync_thread_) { |
| 509 sync_thread_ = base::MakeUnique<base::Thread>("Chrome_SyncThread"); | 509 sync_thread_ = base::MakeUnique<base::Thread>("Chrome_SyncThread"); |
| 510 base::Thread::Options options; | 510 base::Thread::Options options; |
| 511 options.timer_slack = base::TIMER_SLACK_MAXIMUM; | 511 options.timer_slack = base::TIMER_SLACK_MAXIMUM; |
| 512 CHECK(sync_thread_->StartWithOptions(options)); | 512 CHECK(sync_thread_->StartWithOptions(options)); |
| 513 } | 513 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 540 local_sync_backend_folder.Append(base_directory_.BaseName()); | 540 local_sync_backend_folder.Append(base_directory_.BaseName()); |
| 541 local_sync_backend_folder = | 541 local_sync_backend_folder = |
| 542 local_sync_backend_folder.Append(kLoopbackServerBackendFilename); | 542 local_sync_backend_folder.Append(kLoopbackServerBackendFilename); |
| 543 #endif // defined(OS_WIN) | 543 #endif // defined(OS_WIN) |
| 544 | 544 |
| 545 SyncEngine::HttpPostProviderFactoryGetter http_post_provider_factory_getter = | 545 SyncEngine::HttpPostProviderFactoryGetter http_post_provider_factory_getter = |
| 546 base::Bind(&syncer::NetworkResources::GetHttpPostProviderFactory, | 546 base::Bind(&syncer::NetworkResources::GetHttpPostProviderFactory, |
| 547 base::Unretained(network_resources_.get()), | 547 base::Unretained(network_resources_.get()), |
| 548 url_request_context_, network_time_update_callback_); | 548 url_request_context_, network_time_update_callback_); |
| 549 | 549 |
| 550 backend_->Initialize( | 550 engine_->Initialize( |
| 551 this, sync_thread_->task_runner(), GetJsEventHandler(), sync_service_url_, | 551 this, sync_thread_->task_runner(), GetJsEventHandler(), sync_service_url_, |
| 552 local_device_->GetSyncUserAgent(), credentials, delete_stale_data, | 552 local_device_->GetSyncUserAgent(), credentials, delete_stale_data, |
| 553 enable_local_sync_backend, local_sync_backend_folder, | 553 enable_local_sync_backend, local_sync_backend_folder, |
| 554 base::MakeUnique<syncer::SyncManagerFactory>(), | 554 base::MakeUnique<syncer::SyncManagerFactory>(), |
| 555 MakeWeakHandle(sync_enabled_weak_factory_.GetWeakPtr()), | 555 MakeWeakHandle(sync_enabled_weak_factory_.GetWeakPtr()), |
| 556 base::Bind(syncer::ReportUnrecoverableError, channel_), | 556 base::Bind(syncer::ReportUnrecoverableError, channel_), |
| 557 http_post_provider_factory_getter, std::move(saved_nigori_state_)); | 557 http_post_provider_factory_getter, std::move(saved_nigori_state_)); |
| 558 } | 558 } |
| 559 | 559 |
| 560 bool ProfileSyncService::IsEncryptedDatatypeEnabled() const { | 560 bool ProfileSyncService::IsEncryptedDatatypeEnabled() const { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 611 // If this is a data type change after a major version update, reset the | 611 // If this is a data type change after a major version update, reset the |
| 612 // passphrase prompted state and notify observers. | 612 // passphrase prompted state and notify observers. |
| 613 if (IsPassphraseRequired() && passphrase_prompt_triggered_by_version_) { | 613 if (IsPassphraseRequired() && passphrase_prompt_triggered_by_version_) { |
| 614 // The major version has changed and a local syncable change was made. | 614 // The major version has changed and a local syncable change was made. |
| 615 // Reset the passphrase prompt state. | 615 // Reset the passphrase prompt state. |
| 616 passphrase_prompt_triggered_by_version_ = false; | 616 passphrase_prompt_triggered_by_version_ = false; |
| 617 sync_prefs_.SetPassphrasePrompted(false); | 617 sync_prefs_.SetPassphrasePrompted(false); |
| 618 NotifyObservers(); | 618 NotifyObservers(); |
| 619 } | 619 } |
| 620 | 620 |
| 621 if (backend_.get()) { | 621 if (engine_) { |
| 622 DVLOG(1) << "A data type requested sync startup, but it looks like " | 622 DVLOG(1) << "A data type requested sync startup, but it looks like " |
| 623 "something else beat it to the punch."; | 623 "something else beat it to the punch."; |
| 624 return; | 624 return; |
| 625 } | 625 } |
| 626 | 626 |
| 627 startup_controller_->OnDataTypeRequestsSyncStartup(type); | 627 startup_controller_->OnDataTypeRequestsSyncStartup(type); |
| 628 } | 628 } |
| 629 | 629 |
| 630 void ProfileSyncService::StartUpSlowBackendComponents() { | 630 void ProfileSyncService::StartUpSlowEngineComponents() { |
| 631 invalidation::InvalidationService* invalidator = | 631 invalidation::InvalidationService* invalidator = |
| 632 sync_client_->GetInvalidationService(); | 632 sync_client_->GetInvalidationService(); |
| 633 | 633 |
| 634 backend_.reset(sync_client_->GetSyncApiComponentFactory()->CreateSyncEngine( | 634 engine_.reset(sync_client_->GetSyncApiComponentFactory()->CreateSyncEngine( |
| 635 debug_identifier_, invalidator, sync_prefs_.AsWeakPtr(), | 635 debug_identifier_, invalidator, sync_prefs_.AsWeakPtr(), |
| 636 directory_path_)); | 636 directory_path_)); |
| 637 | 637 |
| 638 // Initialize the backend. Every time we start up a new SyncEngine, we'll want | 638 // Initialize the engine. Every time we start up a new SyncEngine, we'll want |
| 639 // to start from a fresh SyncDB, so delete any old one that might be there. | 639 // to start from a fresh SyncDB, so delete any old one that might be there. |
| 640 InitializeBackend(ShouldDeleteSyncFolder()); | 640 InitializeEngine(ShouldDeleteSyncFolder()); |
| 641 | 641 |
| 642 UpdateFirstSyncTimePref(); | 642 UpdateFirstSyncTimePref(); |
| 643 | 643 |
| 644 ReportPreviousSessionMemoryWarningCount(); | 644 ReportPreviousSessionMemoryWarningCount(); |
| 645 } | 645 } |
| 646 | 646 |
| 647 void ProfileSyncService::OnGetTokenSuccess( | 647 void ProfileSyncService::OnGetTokenSuccess( |
| 648 const OAuth2TokenService::Request* request, | 648 const OAuth2TokenService::Request* request, |
| 649 const std::string& access_token, | 649 const std::string& access_token, |
| 650 const base::Time& expiration_time) { | 650 const base::Time& expiration_time) { |
| 651 DCHECK(thread_checker_.CalledOnValidThread()); | 651 DCHECK(thread_checker_.CalledOnValidThread()); |
| 652 DCHECK_EQ(access_token_request_.get(), request); | 652 DCHECK_EQ(access_token_request_.get(), request); |
| 653 access_token_request_.reset(); | 653 access_token_request_.reset(); |
| 654 access_token_ = access_token; | 654 access_token_ = access_token; |
| 655 token_receive_time_ = base::Time::Now(); | 655 token_receive_time_ = base::Time::Now(); |
| 656 last_get_token_error_ = GoogleServiceAuthError::AuthErrorNone(); | 656 last_get_token_error_ = GoogleServiceAuthError::AuthErrorNone(); |
| 657 | 657 |
| 658 if (sync_prefs_.SyncHasAuthError()) { | 658 if (sync_prefs_.SyncHasAuthError()) { |
| 659 sync_prefs_.SetSyncAuthError(false); | 659 sync_prefs_.SetSyncAuthError(false); |
| 660 } | 660 } |
| 661 | 661 |
| 662 if (HasSyncingBackend()) | 662 if (HasSyncingEngine()) |
| 663 backend_->UpdateCredentials(GetCredentials()); | 663 engine_->UpdateCredentials(GetCredentials()); |
| 664 else | 664 else |
| 665 startup_controller_->TryStart(); | 665 startup_controller_->TryStart(); |
| 666 } | 666 } |
| 667 | 667 |
| 668 void ProfileSyncService::OnGetTokenFailure( | 668 void ProfileSyncService::OnGetTokenFailure( |
| 669 const OAuth2TokenService::Request* request, | 669 const OAuth2TokenService::Request* request, |
| 670 const GoogleServiceAuthError& error) { | 670 const GoogleServiceAuthError& error) { |
| 671 DCHECK(thread_checker_.CalledOnValidThread()); | 671 DCHECK(thread_checker_.CalledOnValidThread()); |
| 672 DCHECK_EQ(access_token_request_.get(), request); | 672 DCHECK_EQ(access_token_request_.get(), request); |
| 673 DCHECK_NE(error.state(), GoogleServiceAuthError::NONE); | 673 DCHECK_NE(error.state(), GoogleServiceAuthError::NONE); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 725 DCHECK(thread_checker_.CalledOnValidThread()); | 725 DCHECK(thread_checker_.CalledOnValidThread()); |
| 726 if (account_id == signin_->GetAccountIdToUse()) { | 726 if (account_id == signin_->GetAccountIdToUse()) { |
| 727 access_token_.clear(); | 727 access_token_.clear(); |
| 728 UpdateAuthErrorState( | 728 UpdateAuthErrorState( |
| 729 GoogleServiceAuthError(GoogleServiceAuthError::REQUEST_CANCELED)); | 729 GoogleServiceAuthError(GoogleServiceAuthError::REQUEST_CANCELED)); |
| 730 } | 730 } |
| 731 } | 731 } |
| 732 | 732 |
| 733 void ProfileSyncService::OnRefreshTokensLoaded() { | 733 void ProfileSyncService::OnRefreshTokensLoaded() { |
| 734 DCHECK(thread_checker_.CalledOnValidThread()); | 734 DCHECK(thread_checker_.CalledOnValidThread()); |
| 735 // This notification gets fired when OAuth2TokenService loads the tokens | 735 // This notification gets fired when OAuth2TokenService loads the tokens from |
| 736 // from storage. | 736 // storage. Initialize the engine if sync is enabled. If the sync token was |
| 737 // Initialize the backend if sync is enabled. If the sync token was | 737 // not loaded, GetCredentials() will generate invalid credentials to cause the |
| 738 // not loaded, GetCredentials() will generate invalid credentials to | 738 // engine to generate an auth error (crbug.com/121755). |
| 739 // cause the backend to generate an auth error (crbug.com/121755). | 739 if (HasSyncingEngine()) { |
| 740 if (HasSyncingBackend()) { | |
| 741 RequestAccessToken(); | 740 RequestAccessToken(); |
| 742 } else { | 741 } else { |
| 743 startup_controller_->TryStart(); | 742 startup_controller_->TryStart(); |
| 744 } | 743 } |
| 745 } | 744 } |
| 746 | 745 |
| 747 void ProfileSyncService::Shutdown() { | 746 void ProfileSyncService::Shutdown() { |
| 748 DCHECK(thread_checker_.CalledOnValidThread()); | 747 DCHECK(thread_checker_.CalledOnValidThread()); |
| 749 UnregisterAuthNotifications(); | 748 UnregisterAuthNotifications(); |
| 750 | 749 |
| 751 ShutdownImpl(syncer::BROWSER_SHUTDOWN); | 750 ShutdownImpl(syncer::BROWSER_SHUTDOWN); |
| 752 if (sync_error_controller_) { | 751 if (sync_error_controller_) { |
| 753 // Destroy the SyncErrorController when the service shuts down for good. | 752 // Destroy the SyncErrorController when the service shuts down for good. |
| 754 RemoveObserver(sync_error_controller_.get()); | 753 RemoveObserver(sync_error_controller_.get()); |
| 755 sync_error_controller_.reset(); | 754 sync_error_controller_.reset(); |
| 756 } | 755 } |
| 757 | 756 |
| 758 if (sync_thread_) | 757 if (sync_thread_) |
| 759 sync_thread_->Stop(); | 758 sync_thread_->Stop(); |
| 760 } | 759 } |
| 761 | 760 |
| 762 void ProfileSyncService::ShutdownImpl(syncer::ShutdownReason reason) { | 761 void ProfileSyncService::ShutdownImpl(syncer::ShutdownReason reason) { |
| 763 if (!backend_) { | 762 if (!engine_) { |
| 764 if (reason == syncer::ShutdownReason::DISABLE_SYNC && sync_thread_) { | 763 if (reason == syncer::ShutdownReason::DISABLE_SYNC && sync_thread_) { |
| 765 // If the backend is already shut down when a DISABLE_SYNC happens, | 764 // If the engine is already shut down when a DISABLE_SYNC happens, |
| 766 // the data directory needs to be cleaned up here. | 765 // the data directory needs to be cleaned up here. |
| 767 sync_thread_->task_runner()->PostTask( | 766 sync_thread_->task_runner()->PostTask( |
| 768 FROM_HERE, base::Bind(&DeleteSyncDataFolder, directory_path_)); | 767 FROM_HERE, base::Bind(&DeleteSyncDataFolder, directory_path_)); |
| 769 } | 768 } |
| 770 return; | 769 return; |
| 771 } | 770 } |
| 772 | 771 |
| 773 if (reason == syncer::ShutdownReason::STOP_SYNC || | 772 if (reason == syncer::ShutdownReason::STOP_SYNC || |
| 774 reason == syncer::ShutdownReason::DISABLE_SYNC) { | 773 reason == syncer::ShutdownReason::DISABLE_SYNC) { |
| 775 RemoveClientFromServer(); | 774 RemoveClientFromServer(); |
| 776 } | 775 } |
| 777 | 776 |
| 778 // First, we spin down the backend to stop change processing as soon as | 777 // First, we spin down the engine to stop change processing as soon as |
| 779 // possible. | 778 // possible. |
| 780 base::Time shutdown_start_time = base::Time::Now(); | 779 base::Time shutdown_start_time = base::Time::Now(); |
| 781 backend_->StopSyncingForShutdown(); | 780 engine_->StopSyncingForShutdown(); |
| 782 | 781 |
| 783 // Stop all data type controllers, if needed. Note that until Stop | 782 // Stop all data type controllers, if needed. Note that until Stop completes, |
| 784 // completes, it is possible in theory to have a ChangeProcessor apply a | 783 // it is possible in theory to have a ChangeProcessor apply a change from a |
| 785 // change from a native model. In that case, it will get applied to the sync | 784 // native model. In that case, it will get applied to the sync database (which |
| 786 // database (which doesn't get destroyed until we destroy the backend below) | 785 // doesn't get destroyed until we destroy the engine below) as an unsynced |
| 787 // as an unsynced change. That will be persisted, and committed on restart. | 786 // change. That will be persisted, and committed on restart. |
| 788 if (data_type_manager_) { | 787 if (data_type_manager_) { |
| 789 if (data_type_manager_->state() != DataTypeManager::STOPPED) { | 788 if (data_type_manager_->state() != DataTypeManager::STOPPED) { |
| 790 // When aborting as part of shutdown, we should expect an aborted sync | 789 // When aborting as part of shutdown, we should expect an aborted sync |
| 791 // configure result, else we'll dcheck when we try to read the sync error. | 790 // configure result, else we'll dcheck when we try to read the sync error. |
| 792 expect_sync_configuration_aborted_ = true; | 791 expect_sync_configuration_aborted_ = true; |
| 793 data_type_manager_->Stop(); | 792 data_type_manager_->Stop(); |
| 794 } | 793 } |
| 795 data_type_manager_.reset(); | 794 data_type_manager_.reset(); |
| 796 } | 795 } |
| 797 | 796 |
| 798 // Shutdown the migrator before the backend to ensure it doesn't pull a null | 797 // Shutdown the migrator before the engine to ensure it doesn't pull a null |
| 799 // snapshot. | 798 // snapshot. |
| 800 migrator_.reset(); | 799 migrator_.reset(); |
| 801 sync_js_controller_.AttachJsBackend(WeakHandle<syncer::JsBackend>()); | 800 sync_js_controller_.AttachJsBackend(WeakHandle<syncer::JsBackend>()); |
| 802 | 801 |
| 803 backend_->Shutdown(reason); | 802 engine_->Shutdown(reason); |
| 804 backend_.reset(); | 803 engine_.reset(); |
| 805 | 804 |
| 806 base::TimeDelta shutdown_time = base::Time::Now() - shutdown_start_time; | 805 base::TimeDelta shutdown_time = base::Time::Now() - shutdown_start_time; |
| 807 UMA_HISTOGRAM_TIMES("Sync.Shutdown.BackendDestroyedTime", shutdown_time); | 806 UMA_HISTOGRAM_TIMES("Sync.Shutdown.BackendDestroyedTime", shutdown_time); |
| 808 | 807 |
| 809 sync_enabled_weak_factory_.InvalidateWeakPtrs(); | 808 sync_enabled_weak_factory_.InvalidateWeakPtrs(); |
| 810 | 809 |
| 811 startup_controller_->Reset(GetRegisteredDataTypes()); | 810 startup_controller_->Reset(GetRegisteredDataTypes()); |
| 812 | 811 |
| 813 // If the sync DB is getting destroyed, the local DeviceInfo is no longer | 812 // If the sync DB is getting destroyed, the local DeviceInfo is no longer |
| 814 // valid and should be cleared from the cache. | 813 // valid and should be cleared from the cache. |
| 815 if (reason == syncer::ShutdownReason::DISABLE_SYNC) { | 814 if (reason == syncer::ShutdownReason::DISABLE_SYNC) { |
| 816 local_device_->Clear(); | 815 local_device_->Clear(); |
| 817 } | 816 } |
| 818 | 817 |
| 819 // Clear various flags. | 818 // Clear various flags. |
| 820 expect_sync_configuration_aborted_ = false; | 819 expect_sync_configuration_aborted_ = false; |
| 821 is_auth_in_progress_ = false; | 820 is_auth_in_progress_ = false; |
| 822 backend_initialized_ = false; | 821 engine_initialized_ = false; |
| 823 cached_passphrase_.clear(); | 822 cached_passphrase_.clear(); |
| 824 encryption_pending_ = false; | 823 encryption_pending_ = false; |
| 825 encrypt_everything_ = false; | 824 encrypt_everything_ = false; |
| 826 encrypted_types_ = syncer::SyncEncryptionHandler::SensitiveTypes(); | 825 encrypted_types_ = syncer::SyncEncryptionHandler::SensitiveTypes(); |
| 827 passphrase_required_reason_ = syncer::REASON_PASSPHRASE_NOT_REQUIRED; | 826 passphrase_required_reason_ = syncer::REASON_PASSPHRASE_NOT_REQUIRED; |
| 828 catch_up_configure_in_progress_ = false; | 827 catch_up_configure_in_progress_ = false; |
| 829 access_token_.clear(); | 828 access_token_.clear(); |
| 830 request_access_token_retry_timer_.Stop(); | 829 request_access_token_retry_timer_.Stop(); |
| 831 // Revert to "no auth error". | 830 // Revert to "no auth error". |
| 832 if (last_auth_error_.state() != GoogleServiceAuthError::NONE) | 831 if (last_auth_error_.state() != GoogleServiceAuthError::NONE) |
| 833 UpdateAuthErrorState(GoogleServiceAuthError::AuthErrorNone()); | 832 UpdateAuthErrorState(GoogleServiceAuthError::AuthErrorNone()); |
| 834 | 833 |
| 835 NotifyObservers(); | 834 NotifyObservers(); |
| 836 | 835 |
| 837 // Mark this as a clean shutdown(without crash). | 836 // Mark this as a clean shutdown(without crash). |
| 838 sync_prefs_.SetCleanShutdown(true); | 837 sync_prefs_.SetCleanShutdown(true); |
| 839 } | 838 } |
| 840 | 839 |
| 841 void ProfileSyncService::StopImpl(SyncStopDataFate data_fate) { | 840 void ProfileSyncService::StopImpl(SyncStopDataFate data_fate) { |
| 842 switch (data_fate) { | 841 switch (data_fate) { |
| 843 case KEEP_DATA: | 842 case KEEP_DATA: |
| 844 // TODO(maxbogue): Investigate whether this logic can/should be moved | 843 // TODO(maxbogue): Investigate whether this logic can/should be moved |
| 845 // into ShutdownImpl or the sync engine itself. | 844 // into ShutdownImpl or the sync engine itself. |
| 846 if (HasSyncingBackend()) { | 845 if (HasSyncingEngine()) { |
| 847 backend_->UnregisterInvalidationIds(); | 846 engine_->UnregisterInvalidationIds(); |
| 848 } | 847 } |
| 849 ShutdownImpl(syncer::STOP_SYNC); | 848 ShutdownImpl(syncer::STOP_SYNC); |
| 850 break; | 849 break; |
| 851 case CLEAR_DATA: | 850 case CLEAR_DATA: |
| 852 // Clear prefs (including SyncSetupHasCompleted) before shutting down so | 851 // Clear prefs (including SyncSetupHasCompleted) before shutting down so |
| 853 // PSS clients don't think we're set up while we're shutting down. | 852 // PSS clients don't think we're set up while we're shutting down. |
| 854 sync_prefs_.ClearPreferences(); | 853 sync_prefs_.ClearPreferences(); |
| 855 ClearUnrecoverableError(); | 854 ClearUnrecoverableError(); |
| 856 ShutdownImpl(syncer::DISABLE_SYNC); | 855 ShutdownImpl(syncer::DISABLE_SYNC); |
| 857 break; | 856 break; |
| 858 } | 857 } |
| 859 } | 858 } |
| 860 | 859 |
| 861 bool ProfileSyncService::IsFirstSetupComplete() const { | 860 bool ProfileSyncService::IsFirstSetupComplete() const { |
| 862 DCHECK(thread_checker_.CalledOnValidThread()); | 861 DCHECK(thread_checker_.CalledOnValidThread()); |
| 863 return sync_prefs_.IsFirstSetupComplete(); | 862 return sync_prefs_.IsFirstSetupComplete(); |
| 864 } | 863 } |
| 865 | 864 |
| 866 void ProfileSyncService::SetFirstSetupComplete() { | 865 void ProfileSyncService::SetFirstSetupComplete() { |
| 867 DCHECK(thread_checker_.CalledOnValidThread()); | 866 DCHECK(thread_checker_.CalledOnValidThread()); |
| 868 sync_prefs_.SetFirstSetupComplete(); | 867 sync_prefs_.SetFirstSetupComplete(); |
| 869 if (IsBackendInitialized()) { | 868 if (IsEngineInitialized()) { |
| 870 ReconfigureDatatypeManager(); | 869 ReconfigureDatatypeManager(); |
| 871 } | 870 } |
| 872 } | 871 } |
| 873 | 872 |
| 874 void ProfileSyncService::UpdateLastSyncedTime() { | 873 void ProfileSyncService::UpdateLastSyncedTime() { |
| 875 sync_prefs_.SetLastSyncedTime(base::Time::Now()); | 874 sync_prefs_.SetLastSyncedTime(base::Time::Now()); |
| 876 } | 875 } |
| 877 | 876 |
| 878 void ProfileSyncService::NotifyObservers() { | 877 void ProfileSyncService::NotifyObservers() { |
| 879 for (auto& observer : observers_) | 878 for (auto& observer : observers_) |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 934 // Shut all data types down. | 933 // Shut all data types down. |
| 935 base::ThreadTaskRunnerHandle::Get()->PostTask( | 934 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 936 FROM_HERE, base::Bind(&ProfileSyncService::ShutdownImpl, | 935 FROM_HERE, base::Bind(&ProfileSyncService::ShutdownImpl, |
| 937 sync_enabled_weak_factory_.GetWeakPtr(), | 936 sync_enabled_weak_factory_.GetWeakPtr(), |
| 938 delete_sync_database ? syncer::DISABLE_SYNC | 937 delete_sync_database ? syncer::DISABLE_SYNC |
| 939 : syncer::STOP_SYNC)); | 938 : syncer::STOP_SYNC)); |
| 940 } | 939 } |
| 941 | 940 |
| 942 void ProfileSyncService::ReenableDatatype(syncer::ModelType type) { | 941 void ProfileSyncService::ReenableDatatype(syncer::ModelType type) { |
| 943 DCHECK(thread_checker_.CalledOnValidThread()); | 942 DCHECK(thread_checker_.CalledOnValidThread()); |
| 944 if (!backend_initialized_ || !data_type_manager_) | 943 if (!engine_initialized_ || !data_type_manager_) |
| 945 return; | 944 return; |
| 946 data_type_manager_->ReenableType(type); | 945 data_type_manager_->ReenableType(type); |
| 947 } | 946 } |
| 948 | 947 |
| 949 void ProfileSyncService::UpdateBackendInitUMA(bool success) { | 948 void ProfileSyncService::UpdateEngineInitUMA(bool success) { |
| 950 is_first_time_sync_configure_ = !IsFirstSetupComplete(); | 949 is_first_time_sync_configure_ = !IsFirstSetupComplete(); |
| 951 | 950 |
| 952 if (is_first_time_sync_configure_) { | 951 if (is_first_time_sync_configure_) { |
| 953 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeFirstTimeSuccess", success); | 952 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeFirstTimeSuccess", success); |
| 954 } else { | 953 } else { |
| 955 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeRestoreSuccess", success); | 954 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeRestoreSuccess", success); |
| 956 } | 955 } |
| 957 | 956 |
| 958 base::Time on_backend_initialized_time = base::Time::Now(); | 957 base::Time on_engine_initialized_time = base::Time::Now(); |
| 959 base::TimeDelta delta = | 958 base::TimeDelta delta = |
| 960 on_backend_initialized_time - startup_controller_->start_engine_time(); | 959 on_engine_initialized_time - startup_controller_->start_engine_time(); |
| 961 if (is_first_time_sync_configure_) { | 960 if (is_first_time_sync_configure_) { |
| 962 UMA_HISTOGRAM_LONG_TIMES("Sync.BackendInitializeFirstTime", delta); | 961 UMA_HISTOGRAM_LONG_TIMES("Sync.BackendInitializeFirstTime", delta); |
| 963 } else { | 962 } else { |
| 964 UMA_HISTOGRAM_LONG_TIMES("Sync.BackendInitializeRestoreTime", delta); | 963 UMA_HISTOGRAM_LONG_TIMES("Sync.BackendInitializeRestoreTime", delta); |
| 965 } | 964 } |
| 966 } | 965 } |
| 967 | 966 |
| 968 void ProfileSyncService::PostBackendInitialization() { | 967 void ProfileSyncService::PostEngineInitialization() { |
| 969 if (protocol_event_observers_.might_have_observers()) { | 968 if (protocol_event_observers_.might_have_observers()) { |
| 970 backend_->RequestBufferedProtocolEventsAndEnableForwarding(); | 969 engine_->RequestBufferedProtocolEventsAndEnableForwarding(); |
| 971 } | 970 } |
| 972 | 971 |
| 973 if (type_debug_info_observers_.might_have_observers()) { | 972 if (type_debug_info_observers_.might_have_observers()) { |
| 974 backend_->EnableDirectoryTypeDebugInfoForwarding(); | 973 engine_->EnableDirectoryTypeDebugInfoForwarding(); |
| 975 } | 974 } |
| 976 | 975 |
| 977 // If we have a cached passphrase use it to decrypt/encrypt data now that the | 976 // If we have a cached passphrase use it to decrypt/encrypt data now that the |
| 978 // backend is initialized. We want to call this before notifying observers in | 977 // engine is initialized. We want to call this before notifying observers in |
| 979 // case this operation affects the "passphrase required" status. | 978 // case this operation affects the "passphrase required" status. |
| 980 ConsumeCachedPassphraseIfPossible(); | 979 ConsumeCachedPassphraseIfPossible(); |
| 981 | 980 |
| 982 // The very first time the backend initializes is effectively the first time | 981 // The very first time the engine initializes is effectively the first time |
| 983 // we can say we successfully "synced". LastSyncedTime will only be null in | 982 // we can say we successfully "synced". LastSyncedTime will only be null in |
| 984 // this case, because the pref wasn't restored on StartUp. | 983 // this case, because the pref wasn't restored on StartUp. |
| 985 if (sync_prefs_.GetLastSyncedTime().is_null()) { | 984 if (sync_prefs_.GetLastSyncedTime().is_null()) { |
| 986 UpdateLastSyncedTime(); | 985 UpdateLastSyncedTime(); |
| 987 } | 986 } |
| 988 | 987 |
| 989 // Auto-start means IsFirstSetupComplete gets set automatically. | 988 // Auto-start means IsFirstSetupComplete gets set automatically. |
| 990 if (start_behavior_ == AUTO_START && !IsFirstSetupComplete()) { | 989 if (start_behavior_ == AUTO_START && !IsFirstSetupComplete()) { |
| 991 // This will trigger a configure if it completes setup. | 990 // This will trigger a configure if it completes setup. |
| 992 SetFirstSetupComplete(); | 991 SetFirstSetupComplete(); |
| 993 } else if (CanConfigureDataTypes()) { | 992 } else if (CanConfigureDataTypes()) { |
| 994 ConfigureDataTypeManager(); | 993 ConfigureDataTypeManager(); |
| 995 } | 994 } |
| 996 | 995 |
| 997 // Check for a cookie jar mismatch. | 996 // Check for a cookie jar mismatch. |
| 998 std::vector<gaia::ListedAccount> accounts; | 997 std::vector<gaia::ListedAccount> accounts; |
| 999 std::vector<gaia::ListedAccount> signed_out_accounts; | 998 std::vector<gaia::ListedAccount> signed_out_accounts; |
| 1000 GoogleServiceAuthError error(GoogleServiceAuthError::NONE); | 999 GoogleServiceAuthError error(GoogleServiceAuthError::NONE); |
| 1001 if (gaia_cookie_manager_service_ && | 1000 if (gaia_cookie_manager_service_ && |
| 1002 gaia_cookie_manager_service_->ListAccounts( | 1001 gaia_cookie_manager_service_->ListAccounts( |
| 1003 &accounts, &signed_out_accounts, "ChromiumProfileSyncService")) { | 1002 &accounts, &signed_out_accounts, "ChromiumProfileSyncService")) { |
| 1004 OnGaiaAccountsInCookieUpdated(accounts, signed_out_accounts, error); | 1003 OnGaiaAccountsInCookieUpdated(accounts, signed_out_accounts, error); |
| 1005 } | 1004 } |
| 1006 | 1005 |
| 1007 NotifyObservers(); | 1006 NotifyObservers(); |
| 1008 } | 1007 } |
| 1009 | 1008 |
| 1010 void ProfileSyncService::OnBackendInitialized( | 1009 void ProfileSyncService::OnEngineInitialized( |
| 1011 const syncer::WeakHandle<syncer::JsBackend>& js_backend, | 1010 const syncer::WeakHandle<syncer::JsBackend>& js_backend, |
| 1012 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& | 1011 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& |
| 1013 debug_info_listener, | 1012 debug_info_listener, |
| 1014 const std::string& cache_guid, | 1013 const std::string& cache_guid, |
| 1015 bool success) { | 1014 bool success) { |
| 1016 DCHECK(thread_checker_.CalledOnValidThread()); | 1015 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1017 UpdateBackendInitUMA(success); | 1016 UpdateEngineInitUMA(success); |
| 1018 | 1017 |
| 1019 if (!success) { | 1018 if (!success) { |
| 1020 // Something went unexpectedly wrong. Play it safe: stop syncing at once | 1019 // Something went unexpectedly wrong. Play it safe: stop syncing at once |
| 1021 // and surface error UI to alert the user sync has stopped. | 1020 // and surface error UI to alert the user sync has stopped. |
| 1022 // Keep the directory around for now so that on restart we will retry | 1021 // Keep the directory around for now so that on restart we will retry |
| 1023 // again and potentially succeed in presence of transient file IO failures | 1022 // again and potentially succeed in presence of transient file IO failures |
| 1024 // or permissions issues, etc. | 1023 // or permissions issues, etc. |
| 1025 // | 1024 // |
| 1026 // TODO(rlarocque): Consider making this UnrecoverableError less special. | 1025 // TODO(rlarocque): Consider making this UnrecoverableError less special. |
| 1027 // Unlike every other UnrecoverableError, it does not delete our sync data. | 1026 // Unlike every other UnrecoverableError, it does not delete our sync data. |
| 1028 // This exception made sense at the time it was implemented, but our new | 1027 // This exception made sense at the time it was implemented, but our new |
| 1029 // directory corruption recovery mechanism makes it obsolete. By the time | 1028 // directory corruption recovery mechanism makes it obsolete. By the time |
| 1030 // we get here, we will have already tried and failed to delete the | 1029 // we get here, we will have already tried and failed to delete the |
| 1031 // directory. It would be no big deal if we tried to delete it again. | 1030 // directory. It would be no big deal if we tried to delete it again. |
| 1032 OnInternalUnrecoverableError(FROM_HERE, "BackendInitialize failure", false, | 1031 OnInternalUnrecoverableError(FROM_HERE, "BackendInitialize failure", false, |
| 1033 ERROR_REASON_BACKEND_INIT_FAILURE); | 1032 ERROR_REASON_ENGINE_INIT_FAILURE); |
| 1034 return; | 1033 return; |
| 1035 } | 1034 } |
| 1036 | 1035 |
| 1037 backend_initialized_ = true; | 1036 engine_initialized_ = true; |
| 1038 | 1037 |
| 1039 sync_js_controller_.AttachJsBackend(js_backend); | 1038 sync_js_controller_.AttachJsBackend(js_backend); |
| 1040 debug_info_listener_ = debug_info_listener; | 1039 debug_info_listener_ = debug_info_listener; |
| 1041 | 1040 |
| 1042 SigninClient* signin_client = signin_->GetOriginal()->signin_client(); | 1041 SigninClient* signin_client = signin_->GetOriginal()->signin_client(); |
| 1043 DCHECK(signin_client); | 1042 DCHECK(signin_client); |
| 1044 std::string signin_scoped_device_id = | 1043 std::string signin_scoped_device_id = |
| 1045 signin_client->GetSigninScopedDeviceId(); | 1044 signin_client->GetSigninScopedDeviceId(); |
| 1046 | 1045 |
| 1047 // Initialize local device info. | 1046 // Initialize local device info. |
| 1048 local_device_->Initialize(cache_guid, signin_scoped_device_id, | 1047 local_device_->Initialize(cache_guid, signin_scoped_device_id, |
| 1049 blocking_pool_); | 1048 blocking_pool_); |
| 1050 | 1049 |
| 1051 PostBackendInitialization(); | 1050 PostEngineInitialization(); |
| 1052 } | 1051 } |
| 1053 | 1052 |
| 1054 void ProfileSyncService::OnSyncCycleCompleted() { | 1053 void ProfileSyncService::OnSyncCycleCompleted() { |
| 1055 DCHECK(thread_checker_.CalledOnValidThread()); | 1054 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1056 UpdateLastSyncedTime(); | 1055 UpdateLastSyncedTime(); |
| 1057 const syncer::SyncCycleSnapshot snapshot = GetLastCycleSnapshot(); | 1056 const syncer::SyncCycleSnapshot snapshot = GetLastCycleSnapshot(); |
| 1058 if (IsDataTypeControllerRunning(syncer::SESSIONS) && | 1057 if (IsDataTypeControllerRunning(syncer::SESSIONS) && |
| 1059 snapshot.model_neutral_state().get_updates_request_types.Has( | 1058 snapshot.model_neutral_state().get_updates_request_types.Has( |
| 1060 syncer::SESSIONS) && | 1059 syncer::SESSIONS) && |
| 1061 !syncer::HasSyncerError(snapshot.model_neutral_state())) { | 1060 !syncer::HasSyncerError(snapshot.model_neutral_state())) { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1132 // attempting a token/sync request in between, thus crank up request delay | 1131 // attempting a token/sync request in between, thus crank up request delay |
| 1133 // unnecessary. This is because we won't make a sync request if we hit an | 1132 // unnecessary. This is because we won't make a sync request if we hit an |
| 1134 // error until GAIA succeeds at sending a new token, and we won't request | 1133 // error until GAIA succeeds at sending a new token, and we won't request |
| 1135 // a new token unless sync reports a token failure. But to be safe, don't | 1134 // a new token unless sync reports a token failure. But to be safe, don't |
| 1136 // schedule request if this happens. | 1135 // schedule request if this happens. |
| 1137 if (request_access_token_retry_timer_.IsRunning()) { | 1136 if (request_access_token_retry_timer_.IsRunning()) { |
| 1138 // The timer to perform a request later is already running; nothing | 1137 // The timer to perform a request later is already running; nothing |
| 1139 // further needs to be done at this point. | 1138 // further needs to be done at this point. |
| 1140 } else if (request_access_token_backoff_.failure_count() == 0) { | 1139 } else if (request_access_token_backoff_.failure_count() == 0) { |
| 1141 // First time request without delay. Currently invalid token is used | 1140 // First time request without delay. Currently invalid token is used |
| 1142 // to initialize sync backend and we'll always end up here. We don't | 1141 // to initialize sync engine and we'll always end up here. We don't |
| 1143 // want to delay initialization. | 1142 // want to delay initialization. |
| 1144 request_access_token_backoff_.InformOfRequest(false); | 1143 request_access_token_backoff_.InformOfRequest(false); |
| 1145 RequestAccessToken(); | 1144 RequestAccessToken(); |
| 1146 } else { | 1145 } else { |
| 1147 request_access_token_backoff_.InformOfRequest(false); | 1146 request_access_token_backoff_.InformOfRequest(false); |
| 1148 request_access_token_retry_timer_.Start( | 1147 request_access_token_retry_timer_.Start( |
| 1149 FROM_HERE, request_access_token_backoff_.GetTimeUntilRelease(), | 1148 FROM_HERE, request_access_token_backoff_.GetTimeUntilRelease(), |
| 1150 base::Bind(&ProfileSyncService::RequestAccessToken, | 1149 base::Bind(&ProfileSyncService::RequestAccessToken, |
| 1151 sync_enabled_weak_factory_.GetWeakPtr())); | 1150 sync_enabled_weak_factory_.GetWeakPtr())); |
| 1152 } | 1151 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1166 ConnectionStatusToAuthError(status); | 1165 ConnectionStatusToAuthError(status); |
| 1167 DVLOG(1) << "Connection status change: " << auth_error.ToString(); | 1166 DVLOG(1) << "Connection status change: " << auth_error.ToString(); |
| 1168 UpdateAuthErrorState(auth_error); | 1167 UpdateAuthErrorState(auth_error); |
| 1169 } | 1168 } |
| 1170 } | 1169 } |
| 1171 | 1170 |
| 1172 void ProfileSyncService::OnPassphraseRequired( | 1171 void ProfileSyncService::OnPassphraseRequired( |
| 1173 syncer::PassphraseRequiredReason reason, | 1172 syncer::PassphraseRequiredReason reason, |
| 1174 const sync_pb::EncryptedData& pending_keys) { | 1173 const sync_pb::EncryptedData& pending_keys) { |
| 1175 DCHECK(thread_checker_.CalledOnValidThread()); | 1174 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1176 DCHECK(backend_.get()); | 1175 DCHECK(engine_); |
| 1177 DCHECK(backend_->IsNigoriEnabled()); | 1176 DCHECK(engine_->IsNigoriEnabled()); |
| 1178 | 1177 |
| 1179 // TODO(lipalani) : add this check to other locations as well. | 1178 // TODO(lipalani) : add this check to other locations as well. |
| 1180 if (HasUnrecoverableError()) { | 1179 if (HasUnrecoverableError()) { |
| 1181 // When unrecoverable error is detected we post a task to shutdown the | 1180 // When unrecoverable error is detected we post a task to shutdown the |
| 1182 // backend. The task might not have executed yet. | 1181 // engine. The task might not have executed yet. |
| 1183 return; | 1182 return; |
| 1184 } | 1183 } |
| 1185 | 1184 |
| 1186 DVLOG(1) << "Passphrase required with reason: " | 1185 DVLOG(1) << "Passphrase required with reason: " |
| 1187 << syncer::PassphraseRequiredReasonToString(reason); | 1186 << syncer::PassphraseRequiredReasonToString(reason); |
| 1188 passphrase_required_reason_ = reason; | 1187 passphrase_required_reason_ = reason; |
| 1189 | 1188 |
| 1190 const syncer::ModelTypeSet types = GetPreferredDataTypes(); | 1189 const syncer::ModelTypeSet types = GetPreferredDataTypes(); |
| 1191 if (data_type_manager_) { | 1190 if (data_type_manager_) { |
| 1192 // Reconfigure without the encrypted types (excluded implicitly via the | 1191 // Reconfigure without the encrypted types (excluded implicitly via the |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1244 if (encryption_pending_ && encrypt_everything_) { | 1243 if (encryption_pending_ && encrypt_everything_) { |
| 1245 encryption_pending_ = false; | 1244 encryption_pending_ = false; |
| 1246 // This is to nudge the integration tests when encryption is | 1245 // This is to nudge the integration tests when encryption is |
| 1247 // finished. | 1246 // finished. |
| 1248 NotifyObservers(); | 1247 NotifyObservers(); |
| 1249 } | 1248 } |
| 1250 } | 1249 } |
| 1251 | 1250 |
| 1252 void ProfileSyncService::OnMigrationNeededForTypes(syncer::ModelTypeSet types) { | 1251 void ProfileSyncService::OnMigrationNeededForTypes(syncer::ModelTypeSet types) { |
| 1253 DCHECK(thread_checker_.CalledOnValidThread()); | 1252 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1254 DCHECK(backend_initialized_); | 1253 DCHECK(engine_initialized_); |
| 1255 DCHECK(data_type_manager_.get()); | 1254 DCHECK(data_type_manager_); |
| 1256 | 1255 |
| 1257 // Migrator must be valid, because we don't sync until it is created and this | 1256 // Migrator must be valid, because we don't sync until it is created and this |
| 1258 // callback originates from a sync cycle. | 1257 // callback originates from a sync cycle. |
| 1259 migrator_->MigrateTypes(types); | 1258 migrator_->MigrateTypes(types); |
| 1260 } | 1259 } |
| 1261 | 1260 |
| 1262 void ProfileSyncService::OnActionableError(const SyncProtocolError& error) { | 1261 void ProfileSyncService::OnActionableError(const SyncProtocolError& error) { |
| 1263 DCHECK(thread_checker_.CalledOnValidThread()); | 1262 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1264 last_actionable_error_ = error; | 1263 last_actionable_error_ = error; |
| 1265 DCHECK_NE(last_actionable_error_.action, syncer::UNKNOWN_ACTION); | 1264 DCHECK_NE(last_actionable_error_.action, syncer::UNKNOWN_ACTION); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1332 saved_nigori_state_ = | 1331 saved_nigori_state_ = |
| 1333 base::MakeUnique<syncer::SyncEncryptionHandler::NigoriState>(); | 1332 base::MakeUnique<syncer::SyncEncryptionHandler::NigoriState>(); |
| 1334 sync_prefs_.GetNigoriSpecificsForPassphraseTransition( | 1333 sync_prefs_.GetNigoriSpecificsForPassphraseTransition( |
| 1335 &saved_nigori_state_->nigori_specifics); | 1334 &saved_nigori_state_->nigori_specifics); |
| 1336 const syncer::ModelTypeSet types = GetActiveDataTypes(); | 1335 const syncer::ModelTypeSet types = GetActiveDataTypes(); |
| 1337 catch_up_configure_in_progress_ = true; | 1336 catch_up_configure_in_progress_ = true; |
| 1338 data_type_manager_->Configure(types, syncer::CONFIGURE_REASON_CATCH_UP); | 1337 data_type_manager_->Configure(types, syncer::CONFIGURE_REASON_CATCH_UP); |
| 1339 } | 1338 } |
| 1340 | 1339 |
| 1341 void ProfileSyncService::ClearAndRestartSyncForPassphraseEncryption() { | 1340 void ProfileSyncService::ClearAndRestartSyncForPassphraseEncryption() { |
| 1342 backend_->ClearServerData( | 1341 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1342 engine_->ClearServerData( |
| 1343 base::Bind(&ProfileSyncService::OnClearServerDataDone, | 1343 base::Bind(&ProfileSyncService::OnClearServerDataDone, |
| 1344 sync_enabled_weak_factory_.GetWeakPtr())); | 1344 sync_enabled_weak_factory_.GetWeakPtr())); |
| 1345 } | 1345 } |
| 1346 | 1346 |
| 1347 void ProfileSyncService::OnClearServerDataDone() { | 1347 void ProfileSyncService::OnClearServerDataDone() { |
| 1348 DCHECK(sync_prefs_.GetPassphraseEncryptionTransitionInProgress()); | 1348 DCHECK(sync_prefs_.GetPassphraseEncryptionTransitionInProgress()); |
| 1349 sync_prefs_.SetPassphraseEncryptionTransitionInProgress(false); | 1349 sync_prefs_.SetPassphraseEncryptionTransitionInProgress(false); |
| 1350 | 1350 |
| 1351 // Call to ClearServerData generates new keystore key on the server. This | 1351 // Call to ClearServerData generates new keystore key on the server. This |
| 1352 // makes keystore bootstrap token invalid. Let's clear it from preferences. | 1352 // makes keystore bootstrap token invalid. Let's clear it from preferences. |
| 1353 sync_prefs_.SetKeystoreEncryptionBootstrapToken(std::string()); | 1353 sync_prefs_.SetKeystoreEncryptionBootstrapToken(std::string()); |
| 1354 | 1354 |
| 1355 // Shutdown sync, delete the Directory, then restart, restoring the cached | 1355 // Shutdown sync, delete the Directory, then restart, restoring the cached |
| 1356 // nigori state. | 1356 // nigori state. |
| 1357 ShutdownImpl(syncer::DISABLE_SYNC); | 1357 ShutdownImpl(syncer::DISABLE_SYNC); |
| 1358 startup_controller_->TryStart(); | 1358 startup_controller_->TryStart(); |
| 1359 } | 1359 } |
| 1360 | 1360 |
| 1361 void ProfileSyncService::OnConfigureDone( | 1361 void ProfileSyncService::OnConfigureDone( |
| 1362 const DataTypeManager::ConfigureResult& result) { | 1362 const DataTypeManager::ConfigureResult& result) { |
| 1363 DCHECK(thread_checker_.CalledOnValidThread()); | 1363 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1364 configure_status_ = result.status; | 1364 configure_status_ = result.status; |
| 1365 data_type_status_table_ = result.data_type_status_table; | 1365 data_type_status_table_ = result.data_type_status_table; |
| 1366 | 1366 |
| 1367 // We should have cleared our cached passphrase before we get here (in | 1367 // We should have cleared our cached passphrase before we get here (in |
| 1368 // OnBackendInitialized()). | 1368 // OnEngineInitialized()). |
| 1369 DCHECK(cached_passphrase_.empty()); | 1369 DCHECK(cached_passphrase_.empty()); |
| 1370 | 1370 |
| 1371 if (!sync_configure_start_time_.is_null()) { | 1371 if (!sync_configure_start_time_.is_null()) { |
| 1372 if (result.status == DataTypeManager::OK) { | 1372 if (result.status == DataTypeManager::OK) { |
| 1373 base::Time sync_configure_stop_time = base::Time::Now(); | 1373 base::Time sync_configure_stop_time = base::Time::Now(); |
| 1374 base::TimeDelta delta = | 1374 base::TimeDelta delta = |
| 1375 sync_configure_stop_time - sync_configure_start_time_; | 1375 sync_configure_stop_time - sync_configure_start_time_; |
| 1376 if (is_first_time_sync_configure_) { | 1376 if (is_first_time_sync_configure_) { |
| 1377 UMA_HISTOGRAM_LONG_TIMES("Sync.ServiceInitialConfigureTime", delta); | 1377 UMA_HISTOGRAM_LONG_TIMES("Sync.ServiceInitialConfigureTime", delta); |
| 1378 } else { | 1378 } else { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1423 DCHECK_EQ(DataTypeManager::OK, configure_status_); | 1423 DCHECK_EQ(DataTypeManager::OK, configure_status_); |
| 1424 | 1424 |
| 1425 // We should never get in a state where we have no encrypted datatypes | 1425 // We should never get in a state where we have no encrypted datatypes |
| 1426 // enabled, and yet we still think we require a passphrase for decryption. | 1426 // enabled, and yet we still think we require a passphrase for decryption. |
| 1427 DCHECK( | 1427 DCHECK( |
| 1428 !(IsPassphraseRequiredForDecryption() && !IsEncryptedDatatypeEnabled())); | 1428 !(IsPassphraseRequiredForDecryption() && !IsEncryptedDatatypeEnabled())); |
| 1429 | 1429 |
| 1430 // This must be done before we start syncing with the server to avoid | 1430 // This must be done before we start syncing with the server to avoid |
| 1431 // sending unencrypted data up on a first time sync. | 1431 // sending unencrypted data up on a first time sync. |
| 1432 if (encryption_pending_) | 1432 if (encryption_pending_) |
| 1433 backend_->EnableEncryptEverything(); | 1433 engine_->EnableEncryptEverything(); |
| 1434 NotifyObservers(); | 1434 NotifyObservers(); |
| 1435 | 1435 |
| 1436 if (migrator_.get() && migrator_->state() != BackendMigrator::IDLE) { | 1436 if (migrator_.get() && migrator_->state() != BackendMigrator::IDLE) { |
| 1437 // Migration in progress. Let the migrator know we just finished | 1437 // Migration in progress. Let the migrator know we just finished |
| 1438 // configuring something. It will be up to the migrator to call | 1438 // configuring something. It will be up to the migrator to call |
| 1439 // StartSyncingWithServer() if migration is now finished. | 1439 // StartSyncingWithServer() if migration is now finished. |
| 1440 migrator_->OnConfigureDone(result); | 1440 migrator_->OnConfigureDone(result); |
| 1441 return; | 1441 return; |
| 1442 } | 1442 } |
| 1443 | 1443 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1454 DCHECK(thread_checker_.CalledOnValidThread()); | 1454 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1455 sync_configure_start_time_ = base::Time::Now(); | 1455 sync_configure_start_time_ = base::Time::Now(); |
| 1456 NotifyObservers(); | 1456 NotifyObservers(); |
| 1457 } | 1457 } |
| 1458 | 1458 |
| 1459 ProfileSyncService::SyncStatusSummary | 1459 ProfileSyncService::SyncStatusSummary |
| 1460 ProfileSyncService::QuerySyncStatusSummary() { | 1460 ProfileSyncService::QuerySyncStatusSummary() { |
| 1461 DCHECK(thread_checker_.CalledOnValidThread()); | 1461 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1462 if (HasUnrecoverableError()) { | 1462 if (HasUnrecoverableError()) { |
| 1463 return UNRECOVERABLE_ERROR; | 1463 return UNRECOVERABLE_ERROR; |
| 1464 } else if (!backend_) { | 1464 } else if (!engine_) { |
| 1465 return NOT_ENABLED; | 1465 return NOT_ENABLED; |
| 1466 } else if (backend_.get() && !IsFirstSetupComplete()) { | 1466 } else if (engine_ && !IsFirstSetupComplete()) { |
| 1467 return SETUP_INCOMPLETE; | 1467 return SETUP_INCOMPLETE; |
| 1468 } else if (backend_ && IsFirstSetupComplete() && data_type_manager_ && | 1468 } else if (engine_ && IsFirstSetupComplete() && data_type_manager_ && |
| 1469 data_type_manager_->state() == DataTypeManager::STOPPED) { | 1469 data_type_manager_->state() == DataTypeManager::STOPPED) { |
| 1470 return DATATYPES_NOT_INITIALIZED; | 1470 return DATATYPES_NOT_INITIALIZED; |
| 1471 } else if (IsSyncActive()) { | 1471 } else if (IsSyncActive()) { |
| 1472 return INITIALIZED; | 1472 return INITIALIZED; |
| 1473 } | 1473 } |
| 1474 return UNKNOWN_ERROR; | 1474 return UNKNOWN_ERROR; |
| 1475 } | 1475 } |
| 1476 | 1476 |
| 1477 std::string ProfileSyncService::QuerySyncStatusSummaryString() { | 1477 std::string ProfileSyncService::QuerySyncStatusSummaryString() { |
| 1478 DCHECK(thread_checker_.CalledOnValidThread()); | 1478 DCHECK(thread_checker_.CalledOnValidThread()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1492 return "First time sync setup incomplete"; | 1492 return "First time sync setup incomplete"; |
| 1493 case DATATYPES_NOT_INITIALIZED: | 1493 case DATATYPES_NOT_INITIALIZED: |
| 1494 return "Datatypes not fully initialized"; | 1494 return "Datatypes not fully initialized"; |
| 1495 case INITIALIZED: | 1495 case INITIALIZED: |
| 1496 return "Sync service initialized"; | 1496 return "Sync service initialized"; |
| 1497 default: | 1497 default: |
| 1498 return "Status unknown: Internal error?"; | 1498 return "Status unknown: Internal error?"; |
| 1499 } | 1499 } |
| 1500 } | 1500 } |
| 1501 | 1501 |
| 1502 std::string ProfileSyncService::GetBackendInitializationStateString() const { | 1502 std::string ProfileSyncService::GetEngineInitializationStateString() const { |
| 1503 DCHECK(thread_checker_.CalledOnValidThread()); | 1503 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1504 return startup_controller_->GetEngineInitializationStateString(); | 1504 return startup_controller_->GetEngineInitializationStateString(); |
| 1505 } | 1505 } |
| 1506 | 1506 |
| 1507 bool ProfileSyncService::IsSetupInProgress() const { | 1507 bool ProfileSyncService::IsSetupInProgress() const { |
| 1508 DCHECK(thread_checker_.CalledOnValidThread()); | 1508 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1509 return startup_controller_->IsSetupInProgress(); | 1509 return startup_controller_->IsSetupInProgress(); |
| 1510 } | 1510 } |
| 1511 | 1511 |
| 1512 bool ProfileSyncService::QueryDetailedSyncStatus(SyncEngine::Status* result) { | 1512 bool ProfileSyncService::QueryDetailedSyncStatus(SyncEngine::Status* result) { |
| 1513 DCHECK(thread_checker_.CalledOnValidThread()); | 1513 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1514 if (backend_.get() && backend_initialized_) { | 1514 if (engine_ && engine_initialized_) { |
| 1515 *result = backend_->GetDetailedStatus(); | 1515 *result = engine_->GetDetailedStatus(); |
| 1516 return true; | 1516 return true; |
| 1517 } else { | 1517 } else { |
| 1518 SyncEngine::Status status; | 1518 SyncEngine::Status status; |
| 1519 status.sync_protocol_error = last_actionable_error_; | 1519 status.sync_protocol_error = last_actionable_error_; |
| 1520 *result = status; | 1520 *result = status; |
| 1521 return false; | 1521 return false; |
| 1522 } | 1522 } |
| 1523 } | 1523 } |
| 1524 | 1524 |
| 1525 const AuthError& ProfileSyncService::GetAuthError() const { | 1525 const AuthError& ProfileSyncService::GetAuthError() const { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1552 weak_factory_.GetWeakPtr()))); | 1552 weak_factory_.GetWeakPtr()))); |
| 1553 } | 1553 } |
| 1554 | 1554 |
| 1555 bool ProfileSyncService::IsSyncAllowed() const { | 1555 bool ProfileSyncService::IsSyncAllowed() const { |
| 1556 DCHECK(thread_checker_.CalledOnValidThread()); | 1556 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1557 return IsSyncAllowedByFlag() && !IsManaged() && IsSyncAllowedByPlatform(); | 1557 return IsSyncAllowedByFlag() && !IsManaged() && IsSyncAllowedByPlatform(); |
| 1558 } | 1558 } |
| 1559 | 1559 |
| 1560 bool ProfileSyncService::IsSyncActive() const { | 1560 bool ProfileSyncService::IsSyncActive() const { |
| 1561 DCHECK(thread_checker_.CalledOnValidThread()); | 1561 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1562 return backend_initialized_ && data_type_manager_ && | 1562 return engine_initialized_ && data_type_manager_ && |
| 1563 data_type_manager_->state() != DataTypeManager::STOPPED; | 1563 data_type_manager_->state() != DataTypeManager::STOPPED; |
| 1564 } | 1564 } |
| 1565 | 1565 |
| 1566 void ProfileSyncService::TriggerRefresh(const syncer::ModelTypeSet& types) { | 1566 void ProfileSyncService::TriggerRefresh(const syncer::ModelTypeSet& types) { |
| 1567 DCHECK(thread_checker_.CalledOnValidThread()); | 1567 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1568 if (backend_initialized_) | 1568 if (engine_initialized_) |
| 1569 backend_->TriggerRefresh(types); | 1569 engine_->TriggerRefresh(types); |
| 1570 } | 1570 } |
| 1571 | 1571 |
| 1572 bool ProfileSyncService::IsSignedIn() const { | 1572 bool ProfileSyncService::IsSignedIn() const { |
| 1573 // Sync is logged in if there is a non-empty effective account id. | 1573 // Sync is logged in if there is a non-empty effective account id. |
| 1574 return !signin_->GetAccountIdToUse().empty(); | 1574 return !signin_->GetAccountIdToUse().empty(); |
| 1575 } | 1575 } |
| 1576 | 1576 |
| 1577 bool ProfileSyncService::CanBackendStart() const { | 1577 bool ProfileSyncService::CanEngineStart() const { |
| 1578 return CanSyncStart() && oauth2_token_service_ && | 1578 return CanSyncStart() && oauth2_token_service_ && |
| 1579 oauth2_token_service_->RefreshTokenIsAvailable( | 1579 oauth2_token_service_->RefreshTokenIsAvailable( |
| 1580 signin_->GetAccountIdToUse()); | 1580 signin_->GetAccountIdToUse()); |
| 1581 } | 1581 } |
| 1582 | 1582 |
| 1583 bool ProfileSyncService::IsBackendInitialized() const { | 1583 bool ProfileSyncService::IsEngineInitialized() const { |
| 1584 DCHECK(thread_checker_.CalledOnValidThread()); | 1584 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1585 return backend_initialized_; | 1585 return engine_initialized_; |
| 1586 } | 1586 } |
| 1587 | 1587 |
| 1588 bool ProfileSyncService::ConfigurationDone() const { | 1588 bool ProfileSyncService::ConfigurationDone() const { |
| 1589 DCHECK(thread_checker_.CalledOnValidThread()); | 1589 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1590 return data_type_manager_ && | 1590 return data_type_manager_ && |
| 1591 data_type_manager_->state() == DataTypeManager::CONFIGURED; | 1591 data_type_manager_->state() == DataTypeManager::CONFIGURED; |
| 1592 } | 1592 } |
| 1593 | 1593 |
| 1594 bool ProfileSyncService::waiting_for_auth() const { | 1594 bool ProfileSyncService::waiting_for_auth() const { |
| 1595 DCHECK(thread_checker_.CalledOnValidThread()); | 1595 DCHECK(thread_checker_.CalledOnValidThread()); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1700 sync_prefs_.SetSpareBootstrapToken(bootstrap_token); | 1700 sync_prefs_.SetSpareBootstrapToken(bootstrap_token); |
| 1701 } | 1701 } |
| 1702 #endif | 1702 #endif |
| 1703 | 1703 |
| 1704 void ProfileSyncService::OnUserChoseDatatypes( | 1704 void ProfileSyncService::OnUserChoseDatatypes( |
| 1705 bool sync_everything, | 1705 bool sync_everything, |
| 1706 syncer::ModelTypeSet chosen_types) { | 1706 syncer::ModelTypeSet chosen_types) { |
| 1707 DCHECK(thread_checker_.CalledOnValidThread()); | 1707 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1708 DCHECK(syncer::UserSelectableTypes().HasAll(chosen_types)); | 1708 DCHECK(syncer::UserSelectableTypes().HasAll(chosen_types)); |
| 1709 | 1709 |
| 1710 if (!backend_.get() && !HasUnrecoverableError()) { | 1710 if (!engine_ && !HasUnrecoverableError()) { |
| 1711 NOTREACHED(); | 1711 NOTREACHED(); |
| 1712 return; | 1712 return; |
| 1713 } | 1713 } |
| 1714 | 1714 |
| 1715 UpdateSelectedTypesHistogram(sync_everything, chosen_types); | 1715 UpdateSelectedTypesHistogram(sync_everything, chosen_types); |
| 1716 sync_prefs_.SetKeepEverythingSynced(sync_everything); | 1716 sync_prefs_.SetKeepEverythingSynced(sync_everything); |
| 1717 | 1717 |
| 1718 if (data_type_manager_) | 1718 if (data_type_manager_) |
| 1719 data_type_manager_->ResetDataTypeErrors(); | 1719 data_type_manager_->ResetDataTypeErrors(); |
| 1720 ChangePreferredDataTypes(chosen_types); | 1720 ChangePreferredDataTypes(chosen_types); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1790 std::string ProfileSyncService::GetCustomPassphraseKey() const { | 1790 std::string ProfileSyncService::GetCustomPassphraseKey() const { |
| 1791 DCHECK(thread_checker_.CalledOnValidThread()); | 1791 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1792 syncer::SystemEncryptor encryptor; | 1792 syncer::SystemEncryptor encryptor; |
| 1793 syncer::Cryptographer cryptographer(&encryptor); | 1793 syncer::Cryptographer cryptographer(&encryptor); |
| 1794 cryptographer.Bootstrap(sync_prefs_.GetEncryptionBootstrapToken()); | 1794 cryptographer.Bootstrap(sync_prefs_.GetEncryptionBootstrapToken()); |
| 1795 return cryptographer.GetDefaultNigoriKeyData(); | 1795 return cryptographer.GetDefaultNigoriKeyData(); |
| 1796 } | 1796 } |
| 1797 | 1797 |
| 1798 syncer::PassphraseType ProfileSyncService::GetPassphraseType() const { | 1798 syncer::PassphraseType ProfileSyncService::GetPassphraseType() const { |
| 1799 DCHECK(thread_checker_.CalledOnValidThread()); | 1799 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1800 return backend_->GetPassphraseType(); | 1800 return engine_->GetPassphraseType(); |
| 1801 } | 1801 } |
| 1802 | 1802 |
| 1803 base::Time ProfileSyncService::GetExplicitPassphraseTime() const { | 1803 base::Time ProfileSyncService::GetExplicitPassphraseTime() const { |
| 1804 DCHECK(thread_checker_.CalledOnValidThread()); | 1804 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1805 return backend_->GetExplicitPassphraseTime(); | 1805 return engine_->GetExplicitPassphraseTime(); |
| 1806 } | 1806 } |
| 1807 | 1807 |
| 1808 bool ProfileSyncService::IsCryptographerReady( | 1808 bool ProfileSyncService::IsCryptographerReady( |
| 1809 const syncer::BaseTransaction* trans) const { | 1809 const syncer::BaseTransaction* trans) const { |
| 1810 DCHECK(thread_checker_.CalledOnValidThread()); | 1810 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1811 return backend_.get() && backend_->IsCryptographerReady(trans); | 1811 return engine_ && engine_->IsCryptographerReady(trans); |
| 1812 } | 1812 } |
| 1813 | 1813 |
| 1814 void ProfileSyncService::SetPlatformSyncAllowedProvider( | 1814 void ProfileSyncService::SetPlatformSyncAllowedProvider( |
| 1815 const PlatformSyncAllowedProvider& platform_sync_allowed_provider) { | 1815 const PlatformSyncAllowedProvider& platform_sync_allowed_provider) { |
| 1816 DCHECK(thread_checker_.CalledOnValidThread()); | 1816 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1817 platform_sync_allowed_provider_ = platform_sync_allowed_provider; | 1817 platform_sync_allowed_provider_ = platform_sync_allowed_provider; |
| 1818 } | 1818 } |
| 1819 | 1819 |
| 1820 void ProfileSyncService::ConfigureDataTypeManager() { | 1820 void ProfileSyncService::ConfigureDataTypeManager() { |
| 1821 // Don't configure datatypes if the setup UI is still on the screen - this | 1821 // Don't configure datatypes if the setup UI is still on the screen - this |
| 1822 // is to help multi-screen setting UIs (like iOS) where they don't want to | 1822 // is to help multi-screen setting UIs (like iOS) where they don't want to |
| 1823 // start syncing data until the user is done configuring encryption options, | 1823 // start syncing data until the user is done configuring encryption options, |
| 1824 // etc. ReconfigureDatatypeManager() will get called again once the UI calls | 1824 // etc. ReconfigureDatatypeManager() will get called again once the UI calls |
| 1825 // SetSetupInProgress(false). | 1825 // SetSetupInProgress(false). |
| 1826 if (!CanConfigureDataTypes()) { | 1826 if (!CanConfigureDataTypes()) { |
| 1827 // If we can't configure the data type manager yet, we should still notify | 1827 // If we can't configure the data type manager yet, we should still notify |
| 1828 // observers. This is to support multiple setup UIs being open at once. | 1828 // observers. This is to support multiple setup UIs being open at once. |
| 1829 NotifyObservers(); | 1829 NotifyObservers(); |
| 1830 return; | 1830 return; |
| 1831 } | 1831 } |
| 1832 | 1832 |
| 1833 bool restart = false; | 1833 bool restart = false; |
| 1834 if (!data_type_manager_) { | 1834 if (!data_type_manager_) { |
| 1835 restart = true; | 1835 restart = true; |
| 1836 data_type_manager_.reset( | 1836 data_type_manager_.reset( |
| 1837 sync_client_->GetSyncApiComponentFactory()->CreateDataTypeManager( | 1837 sync_client_->GetSyncApiComponentFactory()->CreateDataTypeManager( |
| 1838 debug_info_listener_, &data_type_controllers_, this, backend_.get(), | 1838 debug_info_listener_, &data_type_controllers_, this, engine_.get(), |
| 1839 this)); | 1839 this)); |
| 1840 | 1840 |
| 1841 // We create the migrator at the same time. | 1841 // We create the migrator at the same time. |
| 1842 migrator_ = base::MakeUnique<BackendMigrator>( | 1842 migrator_ = base::MakeUnique<BackendMigrator>( |
| 1843 debug_identifier_, GetUserShare(), this, data_type_manager_.get(), | 1843 debug_identifier_, GetUserShare(), this, data_type_manager_.get(), |
| 1844 base::Bind(&ProfileSyncService::StartSyncingWithServer, | 1844 base::Bind(&ProfileSyncService::StartSyncingWithServer, |
| 1845 base::Unretained(this))); | 1845 base::Unretained(this))); |
| 1846 } | 1846 } |
| 1847 | 1847 |
| 1848 syncer::ModelTypeSet types; | 1848 syncer::ModelTypeSet types; |
| 1849 syncer::ConfigureReason reason = syncer::CONFIGURE_REASON_UNKNOWN; | 1849 syncer::ConfigureReason reason = syncer::CONFIGURE_REASON_UNKNOWN; |
| 1850 types = GetPreferredDataTypes(); | 1850 types = GetPreferredDataTypes(); |
| 1851 if (restart) { | 1851 if (restart) { |
| 1852 // Datatype downloads on restart are generally due to newly supported | 1852 // Datatype downloads on restart are generally due to newly supported |
| 1853 // datatypes (although it's also possible we're picking up where a failed | 1853 // datatypes (although it's also possible we're picking up where a failed |
| 1854 // previous configuration left off). | 1854 // previous configuration left off). |
| 1855 // TODO(sync): consider detecting configuration recovery and setting | 1855 // TODO(sync): consider detecting configuration recovery and setting |
| 1856 // the reason here appropriately. | 1856 // the reason here appropriately. |
| 1857 reason = syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE; | 1857 reason = syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE; |
| 1858 } else { | 1858 } else { |
| 1859 // The user initiated a reconfiguration (either to add or remove types). | 1859 // The user initiated a reconfiguration (either to add or remove types). |
| 1860 reason = syncer::CONFIGURE_REASON_RECONFIGURATION; | 1860 reason = syncer::CONFIGURE_REASON_RECONFIGURATION; |
| 1861 } | 1861 } |
| 1862 | 1862 |
| 1863 data_type_manager_->Configure(types, reason); | 1863 data_type_manager_->Configure(types, reason); |
| 1864 } | 1864 } |
| 1865 | 1865 |
| 1866 syncer::UserShare* ProfileSyncService::GetUserShare() const { | 1866 syncer::UserShare* ProfileSyncService::GetUserShare() const { |
| 1867 DCHECK(thread_checker_.CalledOnValidThread()); | 1867 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1868 if (backend_.get() && backend_initialized_) { | 1868 if (engine_ && engine_initialized_) { |
| 1869 return backend_->GetUserShare(); | 1869 return engine_->GetUserShare(); |
| 1870 } | 1870 } |
| 1871 NOTREACHED(); | 1871 NOTREACHED(); |
| 1872 return nullptr; | 1872 return nullptr; |
| 1873 } | 1873 } |
| 1874 | 1874 |
| 1875 syncer::SyncCycleSnapshot ProfileSyncService::GetLastCycleSnapshot() const { | 1875 syncer::SyncCycleSnapshot ProfileSyncService::GetLastCycleSnapshot() const { |
| 1876 DCHECK(thread_checker_.CalledOnValidThread()); | 1876 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1877 if (backend_) | 1877 if (engine_) |
| 1878 return backend_->GetLastCycleSnapshot(); | 1878 return engine_->GetLastCycleSnapshot(); |
| 1879 return syncer::SyncCycleSnapshot(); | 1879 return syncer::SyncCycleSnapshot(); |
| 1880 } | 1880 } |
| 1881 | 1881 |
| 1882 bool ProfileSyncService::HasUnsyncedItems() const { | 1882 bool ProfileSyncService::HasUnsyncedItems() const { |
| 1883 DCHECK(thread_checker_.CalledOnValidThread()); | 1883 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1884 if (HasSyncingBackend() && backend_initialized_) { | 1884 if (HasSyncingEngine() && engine_initialized_) { |
| 1885 return backend_->HasUnsyncedItems(); | 1885 return engine_->HasUnsyncedItems(); |
| 1886 } | 1886 } |
| 1887 NOTREACHED(); | 1887 NOTREACHED(); |
| 1888 return false; | 1888 return false; |
| 1889 } | 1889 } |
| 1890 | 1890 |
| 1891 BackendMigrator* ProfileSyncService::GetBackendMigratorForTest() { | 1891 BackendMigrator* ProfileSyncService::GetBackendMigratorForTest() { |
| 1892 DCHECK(thread_checker_.CalledOnValidThread()); | 1892 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1893 return migrator_.get(); | 1893 return migrator_.get(); |
| 1894 } | 1894 } |
| 1895 | 1895 |
| 1896 void ProfileSyncService::GetModelSafeRoutingInfo( | 1896 void ProfileSyncService::GetModelSafeRoutingInfo( |
| 1897 syncer::ModelSafeRoutingInfo* out) const { | 1897 syncer::ModelSafeRoutingInfo* out) const { |
| 1898 DCHECK(thread_checker_.CalledOnValidThread()); | 1898 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1899 if (backend_.get() && backend_initialized_) { | 1899 if (engine_ && engine_initialized_) { |
| 1900 backend_->GetModelSafeRoutingInfo(out); | 1900 engine_->GetModelSafeRoutingInfo(out); |
| 1901 } else { | 1901 } else { |
| 1902 NOTREACHED(); | 1902 NOTREACHED(); |
| 1903 } | 1903 } |
| 1904 } | 1904 } |
| 1905 | 1905 |
| 1906 std::unique_ptr<base::Value> ProfileSyncService::GetTypeStatusMap() { | 1906 std::unique_ptr<base::Value> ProfileSyncService::GetTypeStatusMap() { |
| 1907 DCHECK(thread_checker_.CalledOnValidThread()); | 1907 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1908 auto result = base::MakeUnique<base::ListValue>(); | 1908 auto result = base::MakeUnique<base::ListValue>(); |
| 1909 | 1909 |
| 1910 if (!backend_.get() || !backend_initialized_) { | 1910 if (!engine_ || !engine_initialized_) { |
| 1911 return std::move(result); | 1911 return std::move(result); |
| 1912 } | 1912 } |
| 1913 | 1913 |
| 1914 DataTypeStatusTable::TypeErrorMap error_map = | 1914 DataTypeStatusTable::TypeErrorMap error_map = |
| 1915 data_type_status_table_.GetAllErrors(); | 1915 data_type_status_table_.GetAllErrors(); |
| 1916 ModelTypeSet active_types; | 1916 ModelTypeSet active_types; |
| 1917 ModelTypeSet passive_types; | 1917 ModelTypeSet passive_types; |
| 1918 ModelSafeRoutingInfo routing_info; | 1918 ModelSafeRoutingInfo routing_info; |
| 1919 backend_->GetModelSafeRoutingInfo(&routing_info); | 1919 engine_->GetModelSafeRoutingInfo(&routing_info); |
| 1920 for (ModelSafeRoutingInfo::const_iterator it = routing_info.begin(); | 1920 for (ModelSafeRoutingInfo::const_iterator it = routing_info.begin(); |
| 1921 it != routing_info.end(); ++it) { | 1921 it != routing_info.end(); ++it) { |
| 1922 if (it->second == syncer::GROUP_PASSIVE) { | 1922 if (it->second == syncer::GROUP_PASSIVE) { |
| 1923 passive_types.Put(it->first); | 1923 passive_types.Put(it->first); |
| 1924 } else { | 1924 } else { |
| 1925 active_types.Put(it->first); | 1925 active_types.Put(it->first); |
| 1926 } | 1926 } |
| 1927 } | 1927 } |
| 1928 | 1928 |
| 1929 SyncEngine::Status detailed_status = backend_->GetDetailedStatus(); | 1929 SyncEngine::Status detailed_status = engine_->GetDetailedStatus(); |
| 1930 ModelTypeSet& throttled_types(detailed_status.throttled_types); | 1930 ModelTypeSet& throttled_types(detailed_status.throttled_types); |
| 1931 ModelTypeSet& backed_off_types(detailed_status.backed_off_types); | 1931 ModelTypeSet& backed_off_types(detailed_status.backed_off_types); |
| 1932 ModelTypeSet registered = GetRegisteredDataTypes(); | 1932 ModelTypeSet registered = GetRegisteredDataTypes(); |
| 1933 std::unique_ptr<base::DictionaryValue> type_status_header( | 1933 std::unique_ptr<base::DictionaryValue> type_status_header( |
| 1934 new base::DictionaryValue()); | 1934 new base::DictionaryValue()); |
| 1935 | 1935 |
| 1936 type_status_header->SetString("name", "Model Type"); | 1936 type_status_header->SetString("name", "Model Type"); |
| 1937 type_status_header->SetString("status", "header"); | 1937 type_status_header->SetString("status", "header"); |
| 1938 type_status_header->SetString("value", "Group Type"); | 1938 type_status_header->SetString("value", "Group Type"); |
| 1939 type_status_header->SetString("num_entries", "Total Entries"); | 1939 type_status_header->SetString("num_entries", "Total Entries"); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2003 base::Bind(&ProfileSyncService::OnDatatypeStatusCounterUpdated, | 2003 base::Bind(&ProfileSyncService::OnDatatypeStatusCounterUpdated, |
| 2004 base::Unretained(this)))); | 2004 base::Unretained(this)))); |
| 2005 } | 2005 } |
| 2006 | 2006 |
| 2007 result->Append(std::move(type_status)); | 2007 result->Append(std::move(type_status)); |
| 2008 } | 2008 } |
| 2009 return std::move(result); | 2009 return std::move(result); |
| 2010 } | 2010 } |
| 2011 | 2011 |
| 2012 void ProfileSyncService::ConsumeCachedPassphraseIfPossible() { | 2012 void ProfileSyncService::ConsumeCachedPassphraseIfPossible() { |
| 2013 // If no cached passphrase, or sync backend hasn't started up yet, just exit. | 2013 // If no cached passphrase, or sync engine hasn't started up yet, just exit. |
| 2014 // If the backend isn't running yet, OnBackendInitialized() will call this | 2014 // If the engine isn't running yet, OnEngineInitialized() will call this |
| 2015 // method again after the backend starts up. | 2015 // method again after the engine starts up. |
| 2016 if (cached_passphrase_.empty() || !IsBackendInitialized()) | 2016 if (cached_passphrase_.empty() || !IsEngineInitialized()) |
| 2017 return; | 2017 return; |
| 2018 | 2018 |
| 2019 // Backend is up and running, so we can consume the cached passphrase. | 2019 // Engine is up and running, so we can consume the cached passphrase. |
| 2020 std::string passphrase = cached_passphrase_; | 2020 std::string passphrase = cached_passphrase_; |
| 2021 cached_passphrase_.clear(); | 2021 cached_passphrase_.clear(); |
| 2022 | 2022 |
| 2023 // If we need a passphrase to decrypt data, try the cached passphrase. | 2023 // If we need a passphrase to decrypt data, try the cached passphrase. |
| 2024 if (passphrase_required_reason() == syncer::REASON_DECRYPTION) { | 2024 if (passphrase_required_reason() == syncer::REASON_DECRYPTION) { |
| 2025 if (SetDecryptionPassphrase(passphrase)) { | 2025 if (SetDecryptionPassphrase(passphrase)) { |
| 2026 DVLOG(1) << "Cached passphrase successfully decrypted pending keys"; | 2026 DVLOG(1) << "Cached passphrase successfully decrypted pending keys"; |
| 2027 return; | 2027 return; |
| 2028 } | 2028 } |
| 2029 } | 2029 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 2056 token_request_time_ = base::Time::Now(); | 2056 token_request_time_ = base::Time::Now(); |
| 2057 token_receive_time_ = base::Time(); | 2057 token_receive_time_ = base::Time(); |
| 2058 next_token_request_time_ = base::Time(); | 2058 next_token_request_time_ = base::Time(); |
| 2059 access_token_request_ = | 2059 access_token_request_ = |
| 2060 oauth2_token_service_->StartRequest(account_id, oauth2_scopes, this); | 2060 oauth2_token_service_->StartRequest(account_id, oauth2_scopes, this); |
| 2061 } | 2061 } |
| 2062 | 2062 |
| 2063 void ProfileSyncService::SetEncryptionPassphrase(const std::string& passphrase, | 2063 void ProfileSyncService::SetEncryptionPassphrase(const std::string& passphrase, |
| 2064 PassphraseType type) { | 2064 PassphraseType type) { |
| 2065 DCHECK(thread_checker_.CalledOnValidThread()); | 2065 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2066 // This should only be called when the backend has been initialized. | 2066 // This should only be called when the engine has been initialized. |
| 2067 DCHECK(IsBackendInitialized()); | 2067 DCHECK(IsEngineInitialized()); |
| 2068 DCHECK(!(type == IMPLICIT && IsUsingSecondaryPassphrase())) | 2068 DCHECK(!(type == IMPLICIT && IsUsingSecondaryPassphrase())) |
| 2069 << "Data is already encrypted using an explicit passphrase"; | 2069 << "Data is already encrypted using an explicit passphrase"; |
| 2070 DCHECK(!(type == EXPLICIT && | 2070 DCHECK(!(type == EXPLICIT && |
| 2071 passphrase_required_reason_ == syncer::REASON_DECRYPTION)) | 2071 passphrase_required_reason_ == syncer::REASON_DECRYPTION)) |
| 2072 << "Can not set explicit passphrase when decryption is needed."; | 2072 << "Can not set explicit passphrase when decryption is needed."; |
| 2073 | 2073 |
| 2074 DVLOG(1) << "Setting " << (type == EXPLICIT ? "explicit" : "implicit") | 2074 DVLOG(1) << "Setting " << (type == EXPLICIT ? "explicit" : "implicit") |
| 2075 << " passphrase for encryption."; | 2075 << " passphrase for encryption."; |
| 2076 if (passphrase_required_reason_ == syncer::REASON_ENCRYPTION) { | 2076 if (passphrase_required_reason_ == syncer::REASON_ENCRYPTION) { |
| 2077 // REASON_ENCRYPTION implies that the cryptographer does not have pending | 2077 // REASON_ENCRYPTION implies that the cryptographer does not have pending |
| 2078 // keys. Hence, as long as we're not trying to do an invalid passphrase | 2078 // keys. Hence, as long as we're not trying to do an invalid passphrase |
| 2079 // change (e.g. explicit -> explicit or explicit -> implicit), we know this | 2079 // change (e.g. explicit -> explicit or explicit -> implicit), we know this |
| 2080 // will succeed. If for some reason a new encryption key arrives via | 2080 // will succeed. If for some reason a new encryption key arrives via |
| 2081 // sync later, the SBH will trigger another OnPassphraseRequired(). | 2081 // sync later, the SBH will trigger another OnPassphraseRequired(). |
| 2082 passphrase_required_reason_ = syncer::REASON_PASSPHRASE_NOT_REQUIRED; | 2082 passphrase_required_reason_ = syncer::REASON_PASSPHRASE_NOT_REQUIRED; |
| 2083 NotifyObservers(); | 2083 NotifyObservers(); |
| 2084 } | 2084 } |
| 2085 backend_->SetEncryptionPassphrase(passphrase, type == EXPLICIT); | 2085 engine_->SetEncryptionPassphrase(passphrase, type == EXPLICIT); |
| 2086 } | 2086 } |
| 2087 | 2087 |
| 2088 bool ProfileSyncService::SetDecryptionPassphrase( | 2088 bool ProfileSyncService::SetDecryptionPassphrase( |
| 2089 const std::string& passphrase) { | 2089 const std::string& passphrase) { |
| 2090 DCHECK(thread_checker_.CalledOnValidThread()); | 2090 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2091 if (IsPassphraseRequired()) { | 2091 if (IsPassphraseRequired()) { |
| 2092 DVLOG(1) << "Setting passphrase for decryption."; | 2092 DVLOG(1) << "Setting passphrase for decryption."; |
| 2093 bool result = backend_->SetDecryptionPassphrase(passphrase); | 2093 bool result = engine_->SetDecryptionPassphrase(passphrase); |
| 2094 UMA_HISTOGRAM_BOOLEAN("Sync.PassphraseDecryptionSucceeded", result); | 2094 UMA_HISTOGRAM_BOOLEAN("Sync.PassphraseDecryptionSucceeded", result); |
| 2095 return result; | 2095 return result; |
| 2096 } else { | 2096 } else { |
| 2097 NOTREACHED() << "SetDecryptionPassphrase must not be called when " | 2097 NOTREACHED() << "SetDecryptionPassphrase must not be called when " |
| 2098 "IsPassphraseRequired() is false."; | 2098 "IsPassphraseRequired() is false."; |
| 2099 return false; | 2099 return false; |
| 2100 } | 2100 } |
| 2101 } | 2101 } |
| 2102 | 2102 |
| 2103 bool ProfileSyncService::IsEncryptEverythingAllowed() const { | 2103 bool ProfileSyncService::IsEncryptEverythingAllowed() const { |
| 2104 DCHECK(thread_checker_.CalledOnValidThread()); | 2104 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2105 return encrypt_everything_allowed_; | 2105 return encrypt_everything_allowed_; |
| 2106 } | 2106 } |
| 2107 | 2107 |
| 2108 void ProfileSyncService::SetEncryptEverythingAllowed(bool allowed) { | 2108 void ProfileSyncService::SetEncryptEverythingAllowed(bool allowed) { |
| 2109 DCHECK(thread_checker_.CalledOnValidThread()); | 2109 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2110 DCHECK(allowed || !IsBackendInitialized() || !IsEncryptEverythingEnabled()); | 2110 DCHECK(allowed || !IsEngineInitialized() || !IsEncryptEverythingEnabled()); |
| 2111 encrypt_everything_allowed_ = allowed; | 2111 encrypt_everything_allowed_ = allowed; |
| 2112 } | 2112 } |
| 2113 | 2113 |
| 2114 void ProfileSyncService::EnableEncryptEverything() { | 2114 void ProfileSyncService::EnableEncryptEverything() { |
| 2115 DCHECK(thread_checker_.CalledOnValidThread()); | 2115 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2116 DCHECK(IsEncryptEverythingAllowed()); | 2116 DCHECK(IsEncryptEverythingAllowed()); |
| 2117 | 2117 |
| 2118 // Tests override IsBackendInitialized() to always return true, so we | 2118 // Tests override IsEngineInitialized() to always return true, so we |
| 2119 // must check that instead of |backend_initialized_|. | 2119 // must check that instead of |engine_initialized_|. |
| 2120 // TODO(akalin): Fix the above. :/ | 2120 // TODO(akalin): Fix the above. :/ |
| 2121 DCHECK(IsBackendInitialized()); | 2121 DCHECK(IsEngineInitialized()); |
| 2122 // TODO(atwilson): Persist the encryption_pending_ flag to address the various | 2122 // TODO(atwilson): Persist the encryption_pending_ flag to address the various |
| 2123 // problems around cancelling encryption in the background (crbug.com/119649). | 2123 // problems around cancelling encryption in the background (crbug.com/119649). |
| 2124 if (!encrypt_everything_) | 2124 if (!encrypt_everything_) |
| 2125 encryption_pending_ = true; | 2125 encryption_pending_ = true; |
| 2126 } | 2126 } |
| 2127 | 2127 |
| 2128 bool ProfileSyncService::encryption_pending() const { | 2128 bool ProfileSyncService::encryption_pending() const { |
| 2129 DCHECK(thread_checker_.CalledOnValidThread()); | 2129 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2130 // We may be called during the setup process before we're | 2130 // We may be called during the setup process before we're |
| 2131 // initialized (via IsEncryptedDatatypeEnabled and | 2131 // initialized (via IsEncryptedDatatypeEnabled and |
| 2132 // IsPassphraseRequiredForDecryption). | 2132 // IsPassphraseRequiredForDecryption). |
| 2133 return encryption_pending_; | 2133 return encryption_pending_; |
| 2134 } | 2134 } |
| 2135 | 2135 |
| 2136 bool ProfileSyncService::IsEncryptEverythingEnabled() const { | 2136 bool ProfileSyncService::IsEncryptEverythingEnabled() const { |
| 2137 DCHECK(thread_checker_.CalledOnValidThread()); | 2137 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2138 DCHECK(backend_initialized_); | 2138 DCHECK(engine_initialized_); |
| 2139 return encrypt_everything_ || encryption_pending_; | 2139 return encrypt_everything_ || encryption_pending_; |
| 2140 } | 2140 } |
| 2141 | 2141 |
| 2142 syncer::ModelTypeSet ProfileSyncService::GetEncryptedDataTypes() const { | 2142 syncer::ModelTypeSet ProfileSyncService::GetEncryptedDataTypes() const { |
| 2143 DCHECK(thread_checker_.CalledOnValidThread()); | 2143 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2144 DCHECK(encrypted_types_.Has(syncer::PASSWORDS)); | 2144 DCHECK(encrypted_types_.Has(syncer::PASSWORDS)); |
| 2145 // We may be called during the setup process before we're | 2145 // We may be called during the setup process before we're |
| 2146 // initialized. In this case, we default to the sensitive types. | 2146 // initialized. In this case, we default to the sensitive types. |
| 2147 return encrypted_types_; | 2147 return encrypted_types_; |
| 2148 } | 2148 } |
| 2149 | 2149 |
| 2150 void ProfileSyncService::OnSyncManagedPrefChange(bool is_sync_managed) { | 2150 void ProfileSyncService::OnSyncManagedPrefChange(bool is_sync_managed) { |
| 2151 DCHECK(thread_checker_.CalledOnValidThread()); | 2151 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2152 if (is_sync_managed) { | 2152 if (is_sync_managed) { |
| 2153 StopImpl(CLEAR_DATA); | 2153 StopImpl(CLEAR_DATA); |
| 2154 } else { | 2154 } else { |
| 2155 // Sync is no longer disabled by policy. Try starting it up if appropriate. | 2155 // Sync is no longer disabled by policy. Try starting it up if appropriate. |
| 2156 startup_controller_->TryStart(); | 2156 startup_controller_->TryStart(); |
| 2157 } | 2157 } |
| 2158 } | 2158 } |
| 2159 | 2159 |
| 2160 void ProfileSyncService::GoogleSigninSucceeded(const std::string& account_id, | 2160 void ProfileSyncService::GoogleSigninSucceeded(const std::string& account_id, |
| 2161 const std::string& username, | 2161 const std::string& username, |
| 2162 const std::string& password) { | 2162 const std::string& password) { |
| 2163 DCHECK(thread_checker_.CalledOnValidThread()); | 2163 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2164 if (IsSyncRequested() && !password.empty()) { | 2164 if (IsSyncRequested() && !password.empty()) { |
| 2165 cached_passphrase_ = password; | 2165 cached_passphrase_ = password; |
| 2166 // Try to consume the passphrase we just cached. If the sync backend | 2166 // Try to consume the passphrase we just cached. If the sync engine |
| 2167 // is not running yet, the passphrase will remain cached until the | 2167 // is not running yet, the passphrase will remain cached until the |
| 2168 // backend starts up. | 2168 // engine starts up. |
| 2169 ConsumeCachedPassphraseIfPossible(); | 2169 ConsumeCachedPassphraseIfPossible(); |
| 2170 } | 2170 } |
| 2171 #if defined(OS_CHROMEOS) | 2171 #if defined(OS_CHROMEOS) |
| 2172 RefreshSpareBootstrapToken(password); | 2172 RefreshSpareBootstrapToken(password); |
| 2173 #endif | 2173 #endif |
| 2174 if (!IsBackendInitialized() || GetAuthError().state() != AuthError::NONE) { | 2174 if (!IsEngineInitialized() || GetAuthError().state() != AuthError::NONE) { |
| 2175 // Track the fact that we're still waiting for auth to complete. | 2175 // Track the fact that we're still waiting for auth to complete. |
| 2176 is_auth_in_progress_ = true; | 2176 is_auth_in_progress_ = true; |
| 2177 } | 2177 } |
| 2178 } | 2178 } |
| 2179 | 2179 |
| 2180 void ProfileSyncService::GoogleSignedOut(const std::string& account_id, | 2180 void ProfileSyncService::GoogleSignedOut(const std::string& account_id, |
| 2181 const std::string& username) { | 2181 const std::string& username) { |
| 2182 DCHECK(thread_checker_.CalledOnValidThread()); | 2182 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2183 sync_disabled_by_admin_ = false; | 2183 sync_disabled_by_admin_ = false; |
| 2184 UMA_HISTOGRAM_ENUMERATION("Sync.StopSource", syncer::SIGN_OUT, | 2184 UMA_HISTOGRAM_ENUMERATION("Sync.StopSource", syncer::SIGN_OUT, |
| 2185 syncer::STOP_SOURCE_LIMIT); | 2185 syncer::STOP_SOURCE_LIMIT); |
| 2186 RequestStop(CLEAR_DATA); | 2186 RequestStop(CLEAR_DATA); |
| 2187 } | 2187 } |
| 2188 | 2188 |
| 2189 void ProfileSyncService::OnGaiaAccountsInCookieUpdated( | 2189 void ProfileSyncService::OnGaiaAccountsInCookieUpdated( |
| 2190 const std::vector<gaia::ListedAccount>& accounts, | 2190 const std::vector<gaia::ListedAccount>& accounts, |
| 2191 const std::vector<gaia::ListedAccount>& signed_out_accounts, | 2191 const std::vector<gaia::ListedAccount>& signed_out_accounts, |
| 2192 const GoogleServiceAuthError& error) { | 2192 const GoogleServiceAuthError& error) { |
| 2193 DCHECK(thread_checker_.CalledOnValidThread()); | 2193 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2194 if (!IsBackendInitialized()) | 2194 if (!IsEngineInitialized()) |
| 2195 return; | 2195 return; |
| 2196 | 2196 |
| 2197 bool cookie_jar_mismatch = true; | 2197 bool cookie_jar_mismatch = true; |
| 2198 bool cookie_jar_empty = accounts.size() == 0; | 2198 bool cookie_jar_empty = accounts.size() == 0; |
| 2199 std::string account_id = signin_->GetAccountIdToUse(); | 2199 std::string account_id = signin_->GetAccountIdToUse(); |
| 2200 | 2200 |
| 2201 // Iterate through list of accounts, looking for current sync account. | 2201 // Iterate through list of accounts, looking for current sync account. |
| 2202 for (const auto& account : accounts) { | 2202 for (const auto& account : accounts) { |
| 2203 if (account.id == account_id) { | 2203 if (account.id == account_id) { |
| 2204 cookie_jar_mismatch = false; | 2204 cookie_jar_mismatch = false; |
| 2205 break; | 2205 break; |
| 2206 } | 2206 } |
| 2207 } | 2207 } |
| 2208 | 2208 |
| 2209 DVLOG(1) << "Cookie jar mismatch: " << cookie_jar_mismatch; | 2209 DVLOG(1) << "Cookie jar mismatch: " << cookie_jar_mismatch; |
| 2210 DVLOG(1) << "Cookie jar empty: " << cookie_jar_empty; | 2210 DVLOG(1) << "Cookie jar empty: " << cookie_jar_empty; |
| 2211 backend_->OnCookieJarChanged(cookie_jar_mismatch, cookie_jar_empty); | 2211 engine_->OnCookieJarChanged(cookie_jar_mismatch, cookie_jar_empty); |
| 2212 } | 2212 } |
| 2213 | 2213 |
| 2214 void ProfileSyncService::AddObserver(syncer::SyncServiceObserver* observer) { | 2214 void ProfileSyncService::AddObserver(syncer::SyncServiceObserver* observer) { |
| 2215 DCHECK(thread_checker_.CalledOnValidThread()); | 2215 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2216 observers_.AddObserver(observer); | 2216 observers_.AddObserver(observer); |
| 2217 } | 2217 } |
| 2218 | 2218 |
| 2219 void ProfileSyncService::RemoveObserver(syncer::SyncServiceObserver* observer) { | 2219 void ProfileSyncService::RemoveObserver(syncer::SyncServiceObserver* observer) { |
| 2220 DCHECK(thread_checker_.CalledOnValidThread()); | 2220 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2221 observers_.RemoveObserver(observer); | 2221 observers_.RemoveObserver(observer); |
| 2222 } | 2222 } |
| 2223 | 2223 |
| 2224 void ProfileSyncService::AddProtocolEventObserver( | 2224 void ProfileSyncService::AddProtocolEventObserver( |
| 2225 ProtocolEventObserver* observer) { | 2225 ProtocolEventObserver* observer) { |
| 2226 DCHECK(thread_checker_.CalledOnValidThread()); | 2226 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2227 protocol_event_observers_.AddObserver(observer); | 2227 protocol_event_observers_.AddObserver(observer); |
| 2228 if (HasSyncingBackend()) { | 2228 if (HasSyncingEngine()) { |
| 2229 backend_->RequestBufferedProtocolEventsAndEnableForwarding(); | 2229 engine_->RequestBufferedProtocolEventsAndEnableForwarding(); |
| 2230 } | 2230 } |
| 2231 } | 2231 } |
| 2232 | 2232 |
| 2233 void ProfileSyncService::RemoveProtocolEventObserver( | 2233 void ProfileSyncService::RemoveProtocolEventObserver( |
| 2234 ProtocolEventObserver* observer) { | 2234 ProtocolEventObserver* observer) { |
| 2235 DCHECK(thread_checker_.CalledOnValidThread()); | 2235 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2236 protocol_event_observers_.RemoveObserver(observer); | 2236 protocol_event_observers_.RemoveObserver(observer); |
| 2237 if (HasSyncingBackend() && | 2237 if (HasSyncingEngine() && !protocol_event_observers_.might_have_observers()) { |
| 2238 !protocol_event_observers_.might_have_observers()) { | 2238 engine_->DisableProtocolEventForwarding(); |
| 2239 backend_->DisableProtocolEventForwarding(); | |
| 2240 } | 2239 } |
| 2241 } | 2240 } |
| 2242 | 2241 |
| 2243 void ProfileSyncService::AddTypeDebugInfoObserver( | 2242 void ProfileSyncService::AddTypeDebugInfoObserver( |
| 2244 syncer::TypeDebugInfoObserver* type_debug_info_observer) { | 2243 syncer::TypeDebugInfoObserver* type_debug_info_observer) { |
| 2245 DCHECK(thread_checker_.CalledOnValidThread()); | 2244 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2246 type_debug_info_observers_.AddObserver(type_debug_info_observer); | 2245 type_debug_info_observers_.AddObserver(type_debug_info_observer); |
| 2247 if (type_debug_info_observers_.might_have_observers() && | 2246 if (type_debug_info_observers_.might_have_observers() && |
| 2248 backend_initialized_) { | 2247 engine_initialized_) { |
| 2249 backend_->EnableDirectoryTypeDebugInfoForwarding(); | 2248 engine_->EnableDirectoryTypeDebugInfoForwarding(); |
| 2250 } | 2249 } |
| 2251 } | 2250 } |
| 2252 | 2251 |
| 2253 void ProfileSyncService::RemoveTypeDebugInfoObserver( | 2252 void ProfileSyncService::RemoveTypeDebugInfoObserver( |
| 2254 syncer::TypeDebugInfoObserver* type_debug_info_observer) { | 2253 syncer::TypeDebugInfoObserver* type_debug_info_observer) { |
| 2255 DCHECK(thread_checker_.CalledOnValidThread()); | 2254 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2256 type_debug_info_observers_.RemoveObserver(type_debug_info_observer); | 2255 type_debug_info_observers_.RemoveObserver(type_debug_info_observer); |
| 2257 if (!type_debug_info_observers_.might_have_observers() && | 2256 if (!type_debug_info_observers_.might_have_observers() && |
| 2258 backend_initialized_) { | 2257 engine_initialized_) { |
| 2259 backend_->DisableDirectoryTypeDebugInfoForwarding(); | 2258 engine_->DisableDirectoryTypeDebugInfoForwarding(); |
| 2260 } | 2259 } |
| 2261 } | 2260 } |
| 2262 | 2261 |
| 2263 void ProfileSyncService::AddPreferenceProvider( | 2262 void ProfileSyncService::AddPreferenceProvider( |
| 2264 syncer::SyncTypePreferenceProvider* provider) { | 2263 syncer::SyncTypePreferenceProvider* provider) { |
| 2265 DCHECK(thread_checker_.CalledOnValidThread()); | 2264 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2266 DCHECK(!HasPreferenceProvider(provider)) | 2265 DCHECK(!HasPreferenceProvider(provider)) |
| 2267 << "Providers may only be added once!"; | 2266 << "Providers may only be added once!"; |
| 2268 preference_providers_.insert(provider); | 2267 preference_providers_.insert(provider); |
| 2269 } | 2268 } |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2342 } // namespace | 2341 } // namespace |
| 2343 | 2342 |
| 2344 void ProfileSyncService::GetAllNodes( | 2343 void ProfileSyncService::GetAllNodes( |
| 2345 const base::Callback<void(std::unique_ptr<base::ListValue>)>& callback) { | 2344 const base::Callback<void(std::unique_ptr<base::ListValue>)>& callback) { |
| 2346 DCHECK(thread_checker_.CalledOnValidThread()); | 2345 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2347 ModelTypeSet all_types = GetActiveDataTypes(); | 2346 ModelTypeSet all_types = GetActiveDataTypes(); |
| 2348 all_types.PutAll(syncer::ControlTypes()); | 2347 all_types.PutAll(syncer::ControlTypes()); |
| 2349 scoped_refptr<GetAllNodesRequestHelper> helper = | 2348 scoped_refptr<GetAllNodesRequestHelper> helper = |
| 2350 new GetAllNodesRequestHelper(all_types, callback); | 2349 new GetAllNodesRequestHelper(all_types, callback); |
| 2351 | 2350 |
| 2352 if (!backend_initialized_) { | 2351 if (!engine_initialized_) { |
| 2353 // If there's no backend available to fulfill the request, handle it here. | 2352 // If there's no engine available to fulfill the request, handle it here. |
| 2354 for (ModelTypeSet::Iterator it = all_types.First(); it.Good(); it.Inc()) { | 2353 for (ModelTypeSet::Iterator it = all_types.First(); it.Good(); it.Inc()) { |
| 2355 helper->OnReceivedNodesForType(it.Get(), | 2354 helper->OnReceivedNodesForType(it.Get(), |
| 2356 base::MakeUnique<base::ListValue>()); | 2355 base::MakeUnique<base::ListValue>()); |
| 2357 } | 2356 } |
| 2358 return; | 2357 return; |
| 2359 } | 2358 } |
| 2360 | 2359 |
| 2361 for (ModelTypeSet::Iterator it = all_types.First(); it.Good(); it.Inc()) { | 2360 for (ModelTypeSet::Iterator it = all_types.First(); it.Good(); it.Inc()) { |
| 2362 const auto& dtc_iter = data_type_controllers_.find(it.Get()); | 2361 const auto& dtc_iter = data_type_controllers_.find(it.Get()); |
| 2363 if (dtc_iter != data_type_controllers_.end()) { | 2362 if (dtc_iter != data_type_controllers_.end()) { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2435 sync_prefs_.SetSyncRequested(true); | 2434 sync_prefs_.SetSyncRequested(true); |
| 2436 NotifyObservers(); | 2435 NotifyObservers(); |
| 2437 } | 2436 } |
| 2438 startup_controller_->TryStartImmediately(); | 2437 startup_controller_->TryStartImmediately(); |
| 2439 } | 2438 } |
| 2440 | 2439 |
| 2441 void ProfileSyncService::ReconfigureDatatypeManager() { | 2440 void ProfileSyncService::ReconfigureDatatypeManager() { |
| 2442 DCHECK(thread_checker_.CalledOnValidThread()); | 2441 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2443 // If we haven't initialized yet, don't configure the DTM as it could cause | 2442 // If we haven't initialized yet, don't configure the DTM as it could cause |
| 2444 // association to start before a Directory has even been created. | 2443 // association to start before a Directory has even been created. |
| 2445 if (backend_initialized_) { | 2444 if (engine_initialized_) { |
| 2446 DCHECK(backend_.get()); | 2445 DCHECK(engine_); |
| 2447 ConfigureDataTypeManager(); | 2446 ConfigureDataTypeManager(); |
| 2448 } else if (HasUnrecoverableError()) { | 2447 } else if (HasUnrecoverableError()) { |
| 2449 // There is nothing more to configure. So inform the listeners, | 2448 // There is nothing more to configure. So inform the listeners, |
| 2450 NotifyObservers(); | 2449 NotifyObservers(); |
| 2451 | 2450 |
| 2452 DVLOG(1) << "ConfigureDataTypeManager not invoked because of an " | 2451 DVLOG(1) << "ConfigureDataTypeManager not invoked because of an " |
| 2453 << "Unrecoverable error."; | 2452 << "Unrecoverable error."; |
| 2454 } else { | 2453 } else { |
| 2455 DVLOG(0) << "ConfigureDataTypeManager not invoked because backend is not " | 2454 DVLOG(0) << "ConfigureDataTypeManager not invoked because engine is not " |
| 2456 << "initialized"; | 2455 << "initialized"; |
| 2457 } | 2456 } |
| 2458 } | 2457 } |
| 2459 | 2458 |
| 2460 syncer::ModelTypeSet ProfileSyncService::GetDataTypesFromPreferenceProviders() | 2459 syncer::ModelTypeSet ProfileSyncService::GetDataTypesFromPreferenceProviders() |
| 2461 const { | 2460 const { |
| 2462 syncer::ModelTypeSet types; | 2461 syncer::ModelTypeSet types; |
| 2463 for (std::set<syncer::SyncTypePreferenceProvider*>::const_iterator it = | 2462 for (std::set<syncer::SyncTypePreferenceProvider*>::const_iterator it = |
| 2464 preference_providers_.begin(); | 2463 preference_providers_.begin(); |
| 2465 it != preference_providers_.end(); ++it) { | 2464 it != preference_providers_.end(); ++it) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2525 status.next_token_request_time = next_token_request_time_; | 2524 status.next_token_request_time = next_token_request_time_; |
| 2526 return status; | 2525 return status; |
| 2527 } | 2526 } |
| 2528 | 2527 |
| 2529 void ProfileSyncService::OverrideNetworkResourcesForTest( | 2528 void ProfileSyncService::OverrideNetworkResourcesForTest( |
| 2530 std::unique_ptr<syncer::NetworkResources> network_resources) { | 2529 std::unique_ptr<syncer::NetworkResources> network_resources) { |
| 2531 DCHECK(thread_checker_.CalledOnValidThread()); | 2530 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2532 network_resources_ = std::move(network_resources); | 2531 network_resources_ = std::move(network_resources); |
| 2533 } | 2532 } |
| 2534 | 2533 |
| 2535 bool ProfileSyncService::HasSyncingBackend() const { | 2534 bool ProfileSyncService::HasSyncingEngine() const { |
| 2536 return backend_ != nullptr; | 2535 return engine_ != nullptr; |
| 2537 } | 2536 } |
| 2538 | 2537 |
| 2539 void ProfileSyncService::UpdateFirstSyncTimePref() { | 2538 void ProfileSyncService::UpdateFirstSyncTimePref() { |
| 2540 if (!IsSignedIn()) { | 2539 if (!IsSignedIn()) { |
| 2541 sync_prefs_.ClearFirstSyncTime(); | 2540 sync_prefs_.ClearFirstSyncTime(); |
| 2542 } else if (sync_prefs_.GetFirstSyncTime().is_null()) { | 2541 } else if (sync_prefs_.GetFirstSyncTime().is_null()) { |
| 2543 // Set if not set before and it's syncing now. | 2542 // Set if not set before and it's syncing now. |
| 2544 sync_prefs_.SetFirstSyncTime(base::Time::Now()); | 2543 sync_prefs_.SetFirstSyncTime(base::Time::Now()); |
| 2545 } | 2544 } |
| 2546 } | 2545 } |
| 2547 | 2546 |
| 2548 void ProfileSyncService::FlushDirectory() const { | 2547 void ProfileSyncService::FlushDirectory() const { |
| 2549 DCHECK(thread_checker_.CalledOnValidThread()); | 2548 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2550 // backend_initialized_ implies backend_ isn't null and the manager exists. | 2549 // engine_initialized_ implies engine_ isn't null and the manager exists. |
| 2551 // If sync is not initialized yet, we fail silently. | 2550 // If sync is not initialized yet, we fail silently. |
| 2552 if (backend_initialized_) | 2551 if (engine_initialized_) |
| 2553 backend_->FlushDirectory(); | 2552 engine_->FlushDirectory(); |
| 2554 } | 2553 } |
| 2555 | 2554 |
| 2556 base::FilePath ProfileSyncService::GetDirectoryPathForTest() const { | 2555 base::FilePath ProfileSyncService::GetDirectoryPathForTest() const { |
| 2557 DCHECK(thread_checker_.CalledOnValidThread()); | 2556 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2558 return directory_path_; | 2557 return directory_path_; |
| 2559 } | 2558 } |
| 2560 | 2559 |
| 2561 base::MessageLoop* ProfileSyncService::GetSyncLoopForTest() const { | 2560 base::MessageLoop* ProfileSyncService::GetSyncLoopForTest() const { |
| 2562 DCHECK(thread_checker_.CalledOnValidThread()); | 2561 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2563 if (sync_thread_) { | 2562 if (sync_thread_) { |
| 2564 return sync_thread_->message_loop(); | 2563 return sync_thread_->message_loop(); |
| 2565 } else { | 2564 } else { |
| 2566 return nullptr; | 2565 return nullptr; |
| 2567 } | 2566 } |
| 2568 } | 2567 } |
| 2569 | 2568 |
| 2570 void ProfileSyncService::RefreshTypesForTest(syncer::ModelTypeSet types) { | 2569 void ProfileSyncService::RefreshTypesForTest(syncer::ModelTypeSet types) { |
| 2571 DCHECK(thread_checker_.CalledOnValidThread()); | 2570 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2572 if (backend_initialized_) | 2571 if (engine_initialized_) |
| 2573 backend_->RefreshTypesForTest(types); | 2572 engine_->RefreshTypesForTest(types); |
| 2574 } | 2573 } |
| 2575 | 2574 |
| 2576 void ProfileSyncService::RemoveClientFromServer() const { | 2575 void ProfileSyncService::RemoveClientFromServer() const { |
| 2577 if (!backend_initialized_) | 2576 if (!engine_initialized_) |
| 2578 return; | 2577 return; |
| 2579 const std::string cache_guid = local_device_->GetLocalSyncCacheGUID(); | 2578 const std::string cache_guid = local_device_->GetLocalSyncCacheGUID(); |
| 2580 std::string birthday; | 2579 std::string birthday; |
| 2581 syncer::UserShare* user_share = GetUserShare(); | 2580 syncer::UserShare* user_share = GetUserShare(); |
| 2582 if (user_share && user_share->directory.get()) { | 2581 if (user_share && user_share->directory.get()) { |
| 2583 birthday = user_share->directory->store_birthday(); | 2582 birthday = user_share->directory->store_birthday(); |
| 2584 } | 2583 } |
| 2585 if (!access_token_.empty() && !cache_guid.empty() && !birthday.empty()) { | 2584 if (!access_token_.empty() && !cache_guid.empty() && !birthday.empty()) { |
| 2586 sync_stopped_reporter_->ReportSyncStopped(access_token_, cache_guid, | 2585 sync_stopped_reporter_->ReportSyncStopped(access_token_, cache_guid, |
| 2587 birthday); | 2586 birthday); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2635 void ProfileSyncService::OnSetupInProgressHandleDestroyed() { | 2634 void ProfileSyncService::OnSetupInProgressHandleDestroyed() { |
| 2636 DCHECK_GT(outstanding_setup_in_progress_handles_, 0); | 2635 DCHECK_GT(outstanding_setup_in_progress_handles_, 0); |
| 2637 | 2636 |
| 2638 // Don't re-start Sync until all outstanding handles are destroyed. | 2637 // Don't re-start Sync until all outstanding handles are destroyed. |
| 2639 if (--outstanding_setup_in_progress_handles_ != 0) | 2638 if (--outstanding_setup_in_progress_handles_ != 0) |
| 2640 return; | 2639 return; |
| 2641 | 2640 |
| 2642 DCHECK(startup_controller_->IsSetupInProgress()); | 2641 DCHECK(startup_controller_->IsSetupInProgress()); |
| 2643 startup_controller_->SetSetupInProgress(false); | 2642 startup_controller_->SetSetupInProgress(false); |
| 2644 | 2643 |
| 2645 if (IsBackendInitialized()) | 2644 if (IsEngineInitialized()) |
| 2646 ReconfigureDatatypeManager(); | 2645 ReconfigureDatatypeManager(); |
| 2647 NotifyObservers(); | 2646 NotifyObservers(); |
| 2648 } | 2647 } |
| 2649 | 2648 |
| 2650 } // namespace browser_sync | 2649 } // namespace browser_sync |
| OLD | NEW |