Chromium Code Reviews| Index: chrome/browser/sync/profile_sync_service.cc |
| diff --git a/chrome/browser/sync/profile_sync_service.cc b/chrome/browser/sync/profile_sync_service.cc |
| index 8b09a5a5542d36c48eb4cf31067f369bb8aab9ef..bde176f525cf945e0b92abe2153e4bf499777a0a 100644 |
| --- a/chrome/browser/sync/profile_sync_service.cc |
| +++ b/chrome/browser/sync/profile_sync_service.cc |
| @@ -18,6 +18,7 @@ |
| #include "base/logging.h" |
| #include "base/memory/ref_counted.h" |
| #include "base/metrics/histogram.h" |
| +#include "base/prefs/json_pref_store.h" |
| #include "base/profiler/scoped_tracker.h" |
| #include "base/single_thread_task_runner.h" |
| #include "base/strings/string16.h" |
| @@ -27,18 +28,14 @@ |
| #include "base/time/time.h" |
| #include "build/build_config.h" |
| #include "chrome/browser/chrome_notification_types.h" |
| -#include "chrome/browser/invalidation/profile_invalidation_provider_factory.h" |
| -#include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/sync/glue/sync_backend_host.h" |
| #include "chrome/browser/sync/glue/sync_backend_host_impl.h" |
| #include "chrome/browser/sync/sync_type_preference_provider.h" |
| -#include "chrome/common/channel_info.h" |
| #include "chrome/common/chrome_switches.h" |
| #include "chrome/grit/generated_resources.h" |
| #include "components/autofill/core/common/autofill_pref_names.h" |
| #include "components/history/core/browser/typed_url_data_type_controller.h" |
| #include "components/invalidation/impl/invalidation_prefs.h" |
| -#include "components/invalidation/impl/profile_invalidation_provider.h" |
| #include "components/invalidation/public/invalidation_service.h" |
| #include "components/pref_registry/pref_registry_syncable.h" |
| #include "components/signin/core/browser/about_signin_internals.h" |
| @@ -64,7 +61,6 @@ |
| #include "components/sync_sessions/sync_sessions_client.h" |
| #include "components/syncable_prefs/pref_service_syncable.h" |
| #include "components/version_info/version_info_values.h" |
| -#include "content/public/browser/browser_thread.h" |
| #include "content/public/browser/notification_details.h" |
| #include "content/public/browser/notification_service.h" |
| #include "content/public/browser/notification_source.h" |
| @@ -178,17 +174,29 @@ ProfileSyncService::ProfileSyncService( |
| scoped_ptr<SigninManagerWrapper> signin_wrapper, |
| ProfileOAuth2TokenService* oauth2_token_service, |
| ProfileSyncServiceStartBehavior start_behavior, |
| - const syncer::NetworkTimeUpdateCallback& network_time_update_callback) |
| + const syncer::NetworkTimeUpdateCallback& network_time_update_callback, |
| + base::FilePath base_directory, |
| + net::URLRequestContextGetter* url_request_context, |
|
Nicolas Zea
2015/11/02 19:36:56
The url request context getter is actually RefCoun
blundell
2015/11/03 12:37:32
Done.
|
| + std::string debug_identifier, |
| + version_info::Channel channel, |
| + scoped_refptr<base::SingleThreadTaskRunner> db_thread, |
| + scoped_refptr<base::SingleThreadTaskRunner> file_thread, |
| + base::SequencedWorkerPool* blocking_pool) |
| : OAuth2TokenService::Consumer("sync"), |
| last_auth_error_(AuthError::AuthErrorNone()), |
| passphrase_required_reason_(syncer::REASON_PASSPHRASE_NOT_REQUIRED), |
| sync_client_(sync_client.Pass()), |
| - profile_(profile), |
| - sync_prefs_(profile_->GetPrefs()), |
| + sync_prefs_(sync_client_->GetPrefService()), |
| sync_service_url_( |
| - GetSyncServiceURL(*base::CommandLine::ForCurrentProcess(), |
| - chrome::GetChannel())), |
| + GetSyncServiceURL(*base::CommandLine::ForCurrentProcess(), channel)), |
| network_time_update_callback_(network_time_update_callback), |
| + base_directory_(base_directory), |
| + url_request_context_(url_request_context), |
| + debug_identifier_(debug_identifier), |
| + channel_(channel), |
| + db_thread_(db_thread), |
| + file_thread_(file_thread), |
| + blocking_pool_(blocking_pool), |
| is_first_time_sync_configure_(false), |
| backend_initialized_(false), |
| sync_disabled_by_admin_(false), |
| @@ -213,8 +221,8 @@ ProfileSyncService::ProfileSyncService( |
| passphrase_prompt_triggered_by_version_(false), |
| weak_factory_(this), |
| startup_controller_weak_factory_(this) { |
| - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| - DCHECK(profile); |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + DCHECK(sync_client_); |
| startup_controller_.reset(new browser_sync::StartupController( |
| start_behavior, |
| oauth2_token_service, |
| @@ -236,12 +244,10 @@ ProfileSyncService::ProfileSyncService( |
| sync_client_->GetSyncSessionsClient()->GetLocalSessionEventRouter()); |
| local_device_ = sync_client_->GetSyncApiComponentFactory() |
| ->CreateLocalDeviceInfoProvider(); |
| - sync_stopped_reporter_.reset( |
| - new browser_sync::SyncStoppedReporter( |
| - sync_service_url_, |
| - local_device_->GetSyncUserAgent(), |
| - profile_->GetRequestContext(), |
| - browser_sync::SyncStoppedReporter::ResultCallback())); |
| + sync_stopped_reporter_.reset(new browser_sync::SyncStoppedReporter( |
| + sync_service_url_, local_device_->GetSyncUserAgent(), |
| + url_request_context_, |
| + browser_sync::SyncStoppedReporter::ResultCallback())); |
| registrar_.Add(this, chrome::NOTIFICATION_FOREIGN_SESSION_UPDATED, |
| content::Source<Profile>(profile)); |
| @@ -357,7 +363,7 @@ void ProfileSyncService::TrySyncDatatypePrefRecovery() { |
| // kSyncKeepEverythingSynced has a default value. If so, and sync setup has |
| // completed, it means sync was not properly configured, so we manually |
| // set kSyncKeepEverythingSynced. |
| - PrefService* const pref_service = profile_->GetPrefs(); |
| + PrefService* const pref_service = sync_client_->GetPrefService(); |
| if (!pref_service) |
| return; |
| if (GetPreferredDataTypes().Size() > 1) |
| @@ -379,7 +385,7 @@ void ProfileSyncService::TrySyncDatatypePrefRecovery() { |
| } |
| void ProfileSyncService::StartSyncingWithServer() { |
| - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| switches::kSyncEnableClearDataOnPassphraseEncryption) && |
| @@ -500,23 +506,17 @@ void ProfileSyncService::InitializeBackend(bool delete_stale_data) { |
| http_post_provider_factory_getter = |
| base::Bind(&syncer::NetworkResources::GetHttpPostProviderFactory, |
| base::Unretained(network_resources_.get()), |
| - make_scoped_refptr(profile_->GetRequestContext()), |
| + make_scoped_refptr(url_request_context_), |
| network_time_update_callback_); |
| backend_->Initialize( |
| - this, sync_thread_.Pass(), |
| - content::BrowserThread::GetMessageLoopProxyForThread( |
| - content::BrowserThread::DB), |
| - content::BrowserThread::GetMessageLoopProxyForThread( |
| - content::BrowserThread::FILE), |
| - GetJsEventHandler(), sync_service_url_, local_device_->GetSyncUserAgent(), |
| - credentials, delete_stale_data, |
| - scoped_ptr<syncer::SyncManagerFactory>( |
| - new syncer::SyncManagerFactory(GetManagerType())) |
| - .Pass(), |
| + this, sync_thread_.Pass(), db_thread_, file_thread_, GetJsEventHandler(), |
| + sync_service_url_, local_device_->GetSyncUserAgent(), credentials, |
| + delete_stale_data, scoped_ptr<syncer::SyncManagerFactory>( |
| + new syncer::SyncManagerFactory(GetManagerType())) |
| + .Pass(), |
| MakeWeakHandle(weak_factory_.GetWeakPtr()), |
| - base::Bind(browser_sync::ChromeReportUnrecoverableError, |
| - chrome::GetChannel()), |
| + base::Bind(browser_sync::ChromeReportUnrecoverableError, channel_), |
| http_post_provider_factory_getter, saved_nigori_state_.Pass()); |
| } |
| @@ -654,20 +654,14 @@ void ProfileSyncService::StartUpSlowBackendComponents( |
| base::FilePath(kSyncDataFolderName) : |
| base::FilePath(kSyncBackupDataFolderName); |
| - invalidation::InvalidationService* invalidator = NULL; |
| - if (backend_mode_ == SYNC) { |
| - invalidation::ProfileInvalidationProvider* provider = |
| - invalidation::ProfileInvalidationProviderFactory::GetForProfile( |
| - profile_); |
| - if (provider) |
| - invalidator = provider->GetInvalidationService(); |
| - } |
| + invalidation::InvalidationService* invalidator = |
| + backend_mode_ == SYNC ? sync_client_->GetInvalidationService() : nullptr; |
| - directory_path_ = profile_->GetPath().Append(sync_folder); |
| + directory_path_ = base_directory_.Append(sync_folder); |
| backend_.reset( |
| sync_client_->GetSyncApiComponentFactory()->CreateSyncBackendHost( |
| - profile_->GetDebugName(), sync_client_.get(), invalidator, |
| + debug_identifier_, sync_client_.get(), invalidator, |
| sync_prefs_.AsWeakPtr(), sync_folder)); |
| // Initialize the backend. Every time we start up a new SyncBackendHost, |
| @@ -1108,7 +1102,7 @@ void ProfileSyncService::OnBackendInitialized( |
| // Initialize local device info. |
| local_device_->Initialize(cache_guid, signin_scoped_device_id, |
| - content::BrowserThread::GetBlockingPool()); |
| + blocking_pool_); |
| if (backend_mode_ == BACKUP || backend_mode_ == ROLLBACK) |
| ConfigureDataTypeManager(); |
| @@ -1136,10 +1130,10 @@ void ProfileSyncService::OnExperimentsChanged( |
| current_experiments_ = experiments; |
| - profile_->GetPrefs()->SetBoolean( |
| + sync_client_->GetPrefService()->SetBoolean( |
| invalidation::prefs::kInvalidationServiceUseGCMChannel, |
| experiments.gcm_invalidations_enabled); |
| - profile_->GetPrefs()->SetBoolean( |
| + sync_client_->GetPrefService()->SetBoolean( |
| autofill::prefs::kAutofillWalletSyncExperimentEnabled, |
| experiments.wallet_sync_enabled); |
| } |
| @@ -1393,7 +1387,7 @@ void ProfileSyncService::OnActionableError(const SyncProtocolError& error) { |
| void ProfileSyncService::OnLocalSetPassphraseEncryption( |
| const syncer::SyncEncryptionHandler::NigoriState& nigori_state) { |
| - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| switches::kSyncEnableClearDataOnPassphraseEncryption)) |
| return; |
| @@ -1419,7 +1413,7 @@ void ProfileSyncService::BeginConfigureCatchUpBeforeClear() { |
| } |
| void ProfileSyncService::ClearAndRestartSyncForPassphraseEncryption() { |
| - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| backend_->ClearServerData(base::Bind( |
| &ProfileSyncService::OnClearServerDataDone, weak_factory_.GetWeakPtr())); |
| } |
| @@ -1899,8 +1893,7 @@ void ProfileSyncService::ConfigureDataTypeManager() { |
| // We create the migrator at the same time. |
| migrator_.reset(new browser_sync::BackendMigrator( |
| - profile_->GetDebugName(), GetUserShare(), this, |
| - data_type_manager_.get(), |
| + debug_identifier_, GetUserShare(), this, data_type_manager_.get(), |
| base::Bind(&ProfileSyncService::StartSyncingWithServer, |
| base::Unretained(this)))); |
| } |
| @@ -2432,7 +2425,7 @@ SigninManagerBase* ProfileSyncService::signin() const { |
| } |
| void ProfileSyncService::RequestStart() { |
| - DCHECK(profile_); |
| + DCHECK(sync_client_); |
| sync_prefs_.SetSyncRequested(true); |
| DCHECK(!signin_.get() || signin_->GetOriginal()->IsAuthenticated()); |
| startup_controller_->TryStart(); |
| @@ -2577,15 +2570,15 @@ void ProfileSyncService::CheckSyncBackupIfNeeded() { |
| sync_thread_->task_runner()->PostTask( |
| FROM_HERE, |
| base::Bind(syncer::CheckSyncDbLastModifiedTime, |
| - profile_->GetPath().Append(kSyncBackupDataFolderName), |
| + base_directory_.Append(kSyncBackupDataFolderName), |
| base::ThreadTaskRunnerHandle::Get(), |
| base::Bind(&ProfileSyncService::CheckSyncBackupCallback, |
| weak_factory_.GetWeakPtr()))); |
| } else { |
| - content::BrowserThread::PostTask( |
| - content::BrowserThread::FILE, FROM_HERE, |
| + file_thread_->PostTask( |
| + FROM_HERE, |
| base::Bind(syncer::CheckSyncDbLastModifiedTime, |
| - profile_->GetPath().Append(kSyncBackupDataFolderName), |
| + base_directory_.Append(kSyncBackupDataFolderName), |
| base::ThreadTaskRunnerHandle::Get(), |
| base::Bind(&ProfileSyncService::CheckSyncBackupCallback, |
| weak_factory_.GetWeakPtr()))); |
| @@ -2608,11 +2601,16 @@ void ProfileSyncService::TryStartSyncAfterBackup() { |
| void ProfileSyncService::CleanUpBackup() { |
| sync_prefs_.ClearFirstSyncTime(); |
| - profile_->GetIOTaskRunner()->PostTask( |
| + |
| + // Use the client's base directory to get the blocking task runner to use in |
| + // order to ensure ordering between the tasks posted by different invocations |
| + // of this method. |
| + scoped_refptr<base::SequencedTaskRunner> blocking_task_runner = |
| + JsonPrefStore::GetTaskRunnerForFile(base_directory_, blocking_pool_); |
| + blocking_task_runner->PostTask( |
| FROM_HERE, |
| base::Bind(base::IgnoreResult(base::DeleteFile), |
| - profile_->GetPath().Append(kSyncBackupDataFolderName), |
| - true)); |
| + base_directory_.Append(kSyncBackupDataFolderName), true)); |
| } |
| bool ProfileSyncService::NeedBackup() const { |