| Index: components/browser_sync/profile_sync_service.cc
|
| diff --git a/components/browser_sync/profile_sync_service.cc b/components/browser_sync/profile_sync_service.cc
|
| index b4a269f8b8beee2d043b5ec65da26393b5aa3480..d82f173f591f58726f092503ce2ee90093983ce0 100644
|
| --- a/components/browser_sync/profile_sync_service.cc
|
| +++ b/components/browser_sync/profile_sync_service.cc
|
| @@ -20,7 +20,6 @@
|
| #include "base/memory/ptr_util.h"
|
| #include "base/memory/ref_counted.h"
|
| #include "base/metrics/histogram.h"
|
| -#include "base/path_service.h"
|
| #include "base/profiler/scoped_tracker.h"
|
| #include "base/single_thread_task_runner.h"
|
| #include "base/strings/stringprintf.h"
|
| @@ -152,11 +151,6 @@ static const base::FilePath::CharType kSyncDataFolderName[] =
|
| static const base::FilePath::CharType kLevelDBFolderName[] =
|
| FILE_PATH_LITERAL("LevelDB");
|
|
|
| -#if defined(OS_WIN)
|
| -static const base::FilePath::CharType kLoopbackServerBackendFilename[] =
|
| - FILE_PATH_LITERAL("profile.pb");
|
| -#endif
|
| -
|
| namespace {
|
|
|
| // Perform the actual sync data folder deletion.
|
| @@ -184,7 +178,8 @@ ProfileSyncService::InitParams::InitParams(InitParams&& other) // NOLINT
|
| url_request_context(std::move(other.url_request_context)),
|
| debug_identifier(std::move(other.debug_identifier)),
|
| channel(other.channel),
|
| - blocking_pool(other.blocking_pool) {}
|
| + blocking_pool(other.blocking_pool),
|
| + local_sync_backend_folder(other.local_sync_backend_folder) {}
|
|
|
| ProfileSyncService::ProfileSyncService(InitParams init_params)
|
| : OAuth2TokenService::Consumer("sync"),
|
| @@ -206,6 +201,7 @@ ProfileSyncService::ProfileSyncService(InitParams init_params)
|
| engine_initialized_(false),
|
| sync_disabled_by_admin_(false),
|
| is_auth_in_progress_(false),
|
| + local_sync_backend_folder_(init_params.local_sync_backend_folder),
|
| signin_(std::move(init_params.signin_wrapper)),
|
| unrecoverable_error_reason_(ERROR_REASON_UNSET),
|
| expect_sync_configuration_aborted_(false),
|
| @@ -252,7 +248,8 @@ ProfileSyncService::~ProfileSyncService() {
|
|
|
| bool ProfileSyncService::CanSyncStart() const {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
| - return IsSyncAllowed() && IsSyncRequested() && IsSignedIn();
|
| + return (IsSyncAllowed() && IsSyncRequested() &&
|
| + (IsLocalSyncEnabled() || IsSignedIn()));
|
| }
|
|
|
| void ProfileSyncService::Initialize() {
|
| @@ -319,7 +316,7 @@ void ProfileSyncService::Initialize() {
|
| sync_prefs_.AddSyncPrefObserver(this);
|
|
|
| SyncInitialState sync_state = CAN_START;
|
| - if (!IsSignedIn()) {
|
| + if (!IsLocalSyncEnabled() && !IsSignedIn()) {
|
| sync_state = NOT_SIGNED_IN;
|
| } else if (IsManaged()) {
|
| sync_state = IS_MANAGED;
|
| @@ -346,11 +343,13 @@ void ProfileSyncService::Initialize() {
|
| return;
|
| }
|
|
|
| - RegisterAuthNotifications();
|
| + if (!IsLocalSyncEnabled()) {
|
| + RegisterAuthNotifications();
|
|
|
| - if (!IsSignedIn()) {
|
| - // Clean up in case of previous crash during signout.
|
| - StopImpl(CLEAR_DATA);
|
| + if (!IsSignedIn()) {
|
| + // Clean up in case of previous crash during signout.
|
| + StopImpl(CLEAR_DATA);
|
| + }
|
| }
|
|
|
| #if defined(OS_CHROMEOS)
|
| @@ -373,8 +372,8 @@ void ProfileSyncService::Initialize() {
|
| sync_enabled_weak_factory_.GetWeakPtr()));
|
| startup_controller_->Reset(GetRegisteredDataTypes());
|
|
|
| - // Auto-start means means the first time the profile starts up, sync should
|
| - // start up immediately.
|
| + // Auto-start means the first time the profile starts up, sync should start up
|
| + // immediately.
|
| if (start_behavior_ == AUTO_START && IsSyncRequested() &&
|
| !IsFirstSetupComplete()) {
|
| startup_controller_->TryStartImmediately();
|
| @@ -406,7 +405,8 @@ void ProfileSyncService::UnregisterAuthNotifications() {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
| if (signin())
|
| signin()->RemoveObserver(this);
|
| - oauth2_token_service_->RemoveObserver(this);
|
| + if (oauth2_token_service_)
|
| + oauth2_token_service_->RemoveObserver(this);
|
| }
|
|
|
| void ProfileSyncService::RegisterDataTypeController(
|
| @@ -482,6 +482,11 @@ void ProfileSyncService::OnSessionRestoreComplete() {
|
|
|
| SyncCredentials ProfileSyncService::GetCredentials() {
|
| SyncCredentials credentials;
|
| +
|
| + // No credentials exist or are needed for the local sync backend.
|
| + if (IsLocalSyncEnabled())
|
| + return credentials;
|
| +
|
| credentials.account_id = signin_->GetAccountIdToUse();
|
| DCHECK(!credentials.account_id.empty());
|
| credentials.email = signin_->GetEffectiveUsername();
|
| @@ -517,31 +522,6 @@ void ProfileSyncService::InitializeEngine(bool delete_stale_data) {
|
| if (delete_stale_data)
|
| ClearStaleErrors();
|
|
|
| - bool enable_local_sync_backend = false;
|
| - base::FilePath local_sync_backend_folder =
|
| - sync_prefs_.GetLocalSyncBackendDir();
|
| -#if defined(OS_WIN)
|
| - enable_local_sync_backend = sync_prefs_.IsLocalSyncEnabled();
|
| - if (local_sync_backend_folder.empty()) {
|
| - // TODO(pastarmovj): Add DIR_ROAMING_USER_DATA to PathService to simplify
|
| - // this code and move the logic in its right place. See crbug/657810.
|
| - CHECK(
|
| - base::PathService::Get(base::DIR_APP_DATA, &local_sync_backend_folder));
|
| - local_sync_backend_folder =
|
| - local_sync_backend_folder.Append(FILE_PATH_LITERAL("Chrome/User Data"));
|
| - }
|
| - // This code as it is now will assume the same profile order is present on all
|
| - // machines, which is not a given. It is to be defined if only the Default
|
| - // profile should get this treatment or all profile as is the case now. The
|
| - // solution for now will be to assume profiles are created in the same order
|
| - // on all machines and in the future decide if only the Default one should be
|
| - // considered roamed.
|
| - local_sync_backend_folder =
|
| - local_sync_backend_folder.Append(base_directory_.BaseName());
|
| - local_sync_backend_folder =
|
| - local_sync_backend_folder.Append(kLoopbackServerBackendFilename);
|
| -#endif // defined(OS_WIN)
|
| -
|
| SyncEngine::HttpPostProviderFactoryGetter http_post_provider_factory_getter =
|
| base::Bind(&syncer::NetworkResources::GetHttpPostProviderFactory,
|
| base::Unretained(network_resources_.get()),
|
| @@ -550,7 +530,7 @@ void ProfileSyncService::InitializeEngine(bool delete_stale_data) {
|
| engine_->Initialize(
|
| this, sync_thread_->task_runner(), GetJsEventHandler(), sync_service_url_,
|
| local_device_->GetSyncUserAgent(), credentials, delete_stale_data,
|
| - enable_local_sync_backend, local_sync_backend_folder,
|
| + IsLocalSyncEnabled(), local_sync_backend_folder_,
|
| base::MakeUnique<syncer::SyncManagerFactory>(),
|
| MakeWeakHandle(sync_enabled_weak_factory_.GetWeakPtr()),
|
| base::Bind(syncer::ReportUnrecoverableError, channel_),
|
| @@ -997,10 +977,15 @@ void ProfileSyncService::OnEngineInitialized(
|
| sync_js_controller_.AttachJsBackend(js_backend);
|
| debug_info_listener_ = debug_info_listener;
|
|
|
| - SigninClient* signin_client = signin_->GetOriginal()->signin_client();
|
| - DCHECK(signin_client);
|
| - std::string signin_scoped_device_id =
|
| - signin_client->GetSigninScopedDeviceId();
|
| + std::string signin_scoped_device_id;
|
| + if (IsLocalSyncEnabled()) {
|
| + signin_scoped_device_id = "local_device";
|
| + } else {
|
| + SigninClient* signin_client = signin_->GetOriginal()->signin_client();
|
| + DCHECK(signin_client);
|
| + std::string signin_scoped_device_id =
|
| + signin_client->GetSigninScopedDeviceId();
|
| + }
|
|
|
| // Initialize local device info.
|
| local_device_->Initialize(cache_guid, signin_scoped_device_id,
|
| @@ -1050,6 +1035,10 @@ void ProfileSyncService::OnEngineInitialized(
|
| }
|
|
|
| NotifyObservers();
|
| +
|
| + // Nobody will call us to start if no sign in is going to happen.
|
| + if (IsLocalSyncEnabled())
|
| + RequestStart();
|
| }
|
|
|
| void ProfileSyncService::OnSyncCycleCompleted() {
|
| @@ -1565,6 +1554,11 @@ bool ProfileSyncService::IsSyncActive() const {
|
| data_type_manager_->state() != DataTypeManager::STOPPED;
|
| }
|
|
|
| +bool ProfileSyncService::IsLocalSyncEnabled() const {
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| + return sync_prefs_.IsLocalSyncEnabled();
|
| +}
|
| +
|
| void ProfileSyncService::TriggerRefresh(const syncer::ModelTypeSet& types) {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
| if (engine_initialized_)
|
| @@ -1577,6 +1571,8 @@ bool ProfileSyncService::IsSignedIn() const {
|
| }
|
|
|
| bool ProfileSyncService::CanEngineStart() const {
|
| + if (IsLocalSyncEnabled())
|
| + return true;
|
| return CanSyncStart() && oauth2_token_service_ &&
|
| oauth2_token_service_->RefreshTokenIsAvailable(
|
| signin_->GetAccountIdToUse());
|
| @@ -2534,7 +2530,7 @@ bool ProfileSyncService::HasSyncingEngine() const {
|
| }
|
|
|
| void ProfileSyncService::UpdateFirstSyncTimePref() {
|
| - if (!IsSignedIn()) {
|
| + if (!IsLocalSyncEnabled() && !IsSignedIn()) {
|
| sync_prefs_.ClearFirstSyncTime();
|
| } else if (sync_prefs_.GetFirstSyncTime().is_null()) {
|
| // Set if not set before and it's syncing now.
|
|
|