| 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 413bd42442b981ccb56408112e4ab12ade717ccc..10f328705f03236eaea60eeb1dab32d71ea92992 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"
|
| @@ -184,10 +180,10 @@ ProfileSyncService::ProfileSyncService(
|
| 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())),
|
| + sync_client_->GetChannel())),
|
| network_time_update_callback_(network_time_update_callback),
|
| is_first_time_sync_configure_(false),
|
| backend_initialized_(false),
|
| @@ -214,7 +210,7 @@ ProfileSyncService::ProfileSyncService(
|
| passphrase_prompt_triggered_by_version_(false),
|
| weak_factory_(this),
|
| startup_controller_weak_factory_(this) {
|
| - DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| DCHECK(profile);
|
| startup_controller_.reset(new browser_sync::StartupController(
|
| start_behavior,
|
| @@ -237,12 +233,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(),
|
| + sync_client_->GetURLRequestContext(),
|
| + browser_sync::SyncStoppedReporter::ResultCallback()));
|
|
|
| registrar_.Add(this, chrome::NOTIFICATION_FOREIGN_SESSION_UPDATED,
|
| content::Source<Profile>(profile));
|
| @@ -358,7 +352,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)
|
| @@ -380,7 +374,7 @@ void ProfileSyncService::TrySyncDatatypePrefRecovery() {
|
| }
|
|
|
| void ProfileSyncService::StartSyncingWithServer() {
|
| - DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
|
|
| if (base::CommandLine::ForCurrentProcess()->HasSwitch(
|
| switches::kSyncEnableClearDataOnPassphraseEncryption) &&
|
| @@ -501,23 +495,19 @@ 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(sync_client_->GetURLRequestContext()),
|
| 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,
|
| + this, sync_thread_.Pass(), sync_client_->GetDBThread(),
|
| + sync_client_->GetFileThread(), 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()),
|
| + sync_client_->GetChannel()),
|
| http_post_provider_factory_getter, saved_nigori_state_.Pass());
|
| }
|
|
|
| @@ -655,20 +645,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_ = sync_client_->GetBaseDirectory().Append(sync_folder);
|
|
|
| backend_.reset(
|
| sync_client_->GetSyncApiComponentFactory()->CreateSyncBackendHost(
|
| - profile_->GetDebugName(), sync_client_.get(), invalidator,
|
| + sync_client_->GetDebugIdentifier(), sync_client_.get(), invalidator,
|
| sync_prefs_.AsWeakPtr(), sync_folder));
|
|
|
| // Initialize the backend. Every time we start up a new SyncBackendHost,
|
| @@ -1109,7 +1093,7 @@ void ProfileSyncService::OnBackendInitialized(
|
|
|
| // Initialize local device info.
|
| local_device_->Initialize(cache_guid, signin_scoped_device_id,
|
| - content::BrowserThread::GetBlockingPool());
|
| + sync_client_->GetBlockingPool());
|
|
|
| if (backend_mode_ == BACKUP || backend_mode_ == ROLLBACK)
|
| ConfigureDataTypeManager();
|
| @@ -1137,10 +1121,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);
|
| }
|
| @@ -1394,7 +1378,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;
|
| @@ -1420,7 +1404,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()));
|
| }
|
| @@ -1900,7 +1884,7 @@ void ProfileSyncService::ConfigureDataTypeManager() {
|
|
|
| // We create the migrator at the same time.
|
| migrator_.reset(new browser_sync::BackendMigrator(
|
| - profile_->GetDebugName(), GetUserShare(), this,
|
| + sync_client_->GetDebugIdentifier(), GetUserShare(), this,
|
| data_type_manager_.get(),
|
| base::Bind(&ProfileSyncService::StartSyncingWithServer,
|
| base::Unretained(this))));
|
| @@ -2433,7 +2417,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();
|
| @@ -2582,15 +2566,17 @@ void ProfileSyncService::CheckSyncBackupIfNeeded() {
|
| sync_thread_->task_runner()->PostTask(
|
| FROM_HERE,
|
| base::Bind(syncer::CheckSyncDbLastModifiedTime,
|
| - profile_->GetPath().Append(kSyncBackupDataFolderName),
|
| + sync_client_->GetBaseDirectory().Append(
|
| + kSyncBackupDataFolderName),
|
| base::ThreadTaskRunnerHandle::Get(),
|
| base::Bind(&ProfileSyncService::CheckSyncBackupCallback,
|
| weak_factory_.GetWeakPtr())));
|
| } else {
|
| - content::BrowserThread::PostTask(
|
| - content::BrowserThread::FILE, FROM_HERE,
|
| + sync_client_->GetFileThread()->PostTask(
|
| + FROM_HERE,
|
| base::Bind(syncer::CheckSyncDbLastModifiedTime,
|
| - profile_->GetPath().Append(kSyncBackupDataFolderName),
|
| + sync_client_->GetBaseDirectory().Append(
|
| + kSyncBackupDataFolderName),
|
| base::ThreadTaskRunnerHandle::Get(),
|
| base::Bind(&ProfileSyncService::CheckSyncBackupCallback,
|
| weak_factory_.GetWeakPtr())));
|
| @@ -2613,11 +2599,18 @@ void ProfileSyncService::TryStartSyncAfterBackup() {
|
|
|
| void ProfileSyncService::CleanUpBackup() {
|
| sync_prefs_.ClearFirstSyncTime();
|
| - profile_->GetIOTaskRunner()->PostTask(
|
| - FROM_HERE,
|
| - base::Bind(base::IgnoreResult(base::DeleteFile),
|
| - profile_->GetPath().Append(kSyncBackupDataFolderName),
|
| - true));
|
| +
|
| + // 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(sync_client_->GetBaseDirectory(),
|
| + sync_client_->GetBlockingPool());
|
| + blocking_task_runner->PostTask(
|
| + FROM_HERE, base::Bind(base::IgnoreResult(base::DeleteFile),
|
| + sync_client_->GetBaseDirectory().Append(
|
| + kSyncBackupDataFolderName),
|
| + true));
|
| }
|
|
|
| bool ProfileSyncService::NeedBackup() const {
|
|
|