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

Unified Diff: components/browser_sync/profile_sync_service.cc

Issue 2494873003: [Sync] Allow sync start without sign-in if the local sync backend is on. (Closed)
Patch Set: Rebased on ToT. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 38500ff9c27cffe52130422acb03ef145575b585..d1d4f1f962c1d44f70f0cc63ff2bd7dbb8c0e3ad 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,9 @@ 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_enabled(other.local_sync_backend_enabled),
+ local_sync_backend_folder(other.local_sync_backend_folder) {}
ProfileSyncService::ProfileSyncService(InitParams init_params)
: OAuth2TokenService::Consumer("sync"),
@@ -206,6 +202,8 @@ ProfileSyncService::ProfileSyncService(InitParams init_params)
backend_initialized_(false),
sync_disabled_by_admin_(false),
is_auth_in_progress_(false),
+ local_sync_backend_enabled_(init_params.local_sync_backend_enabled),
+ 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),
@@ -250,7 +248,8 @@ ProfileSyncService::~ProfileSyncService() {
}
bool ProfileSyncService::CanSyncStart() const {
- return IsSyncAllowed() && IsSyncRequested() && IsSignedIn();
+ return (IsSyncAllowed() && IsSyncRequested() &&
+ (local_sync_backend_enabled_ || IsSignedIn()));
Nicolas Zea 2016/11/19 00:36:42 It seems like IsSyncRequested/IsSignedIn/IsSyncAll
pastarmovj 2016/11/22 12:38:08 I don't think this is the case but I might be misu
}
void ProfileSyncService::Initialize() {
@@ -316,7 +315,7 @@ void ProfileSyncService::Initialize() {
sync_prefs_.AddSyncPrefObserver(this);
SyncInitialState sync_state = CAN_START;
- if (!IsSignedIn()) {
+ if (!local_sync_backend_enabled_ && !IsSignedIn()) {
sync_state = NOT_SIGNED_IN;
} else if (IsManaged()) {
sync_state = IS_MANAGED;
@@ -343,11 +342,13 @@ void ProfileSyncService::Initialize() {
return;
}
- RegisterAuthNotifications();
+ if (!local_sync_backend_enabled_) {
+ 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)
@@ -370,8 +371,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();
@@ -403,7 +404,8 @@ void ProfileSyncService::RegisterAuthNotifications() {
void ProfileSyncService::UnregisterAuthNotifications() {
if (signin())
signin()->RemoveObserver(this);
- oauth2_token_service_->RemoveObserver(this);
+ if (oauth2_token_service_)
+ oauth2_token_service_->RemoveObserver(this);
}
void ProfileSyncService::RegisterDataTypeController(
@@ -471,6 +473,11 @@ void ProfileSyncService::OnSessionRestoreComplete() {
SyncCredentials ProfileSyncService::GetCredentials() {
SyncCredentials credentials;
+
+ // No credentials exist or are needed for the local sync backend.
+ if (local_sync_backend_enabled_)
+ return credentials;
+
credentials.account_id = signin_->GetAccountIdToUse();
DCHECK(!credentials.account_id.empty());
credentials.email = signin_->GetEffectiveUsername();
@@ -506,36 +513,6 @@ void ProfileSyncService::InitializeBackend(bool delete_stale_data) {
if (delete_stale_data)
ClearStaleErrors();
- bool enable_local_sync_backend = false;
- base::FilePath local_sync_backend_folder;
-#if defined(OS_WIN)
- enable_local_sync_backend = base::CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kEnableLocalSyncBackend);
- if (base::CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kLocalSyncBackendDir)) {
- local_sync_backend_folder =
- base::CommandLine::ForCurrentProcess()->GetSwitchValuePath(
- switches::kLocalSyncBackendDir);
- } else {
- // 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)
-
SyncBackendHost::HttpPostProviderFactoryGetter
http_post_provider_factory_getter =
base::Bind(&syncer::NetworkResources::GetHttpPostProviderFactory,
@@ -545,7 +522,7 @@ void ProfileSyncService::InitializeBackend(bool delete_stale_data) {
backend_->Initialize(
this, sync_thread_.get(), GetJsEventHandler(), sync_service_url_,
local_device_->GetSyncUserAgent(), credentials, delete_stale_data,
- enable_local_sync_backend, local_sync_backend_folder,
+ local_sync_backend_enabled_, local_sync_backend_folder_,
base::MakeUnique<syncer::SyncManagerFactory>(),
MakeWeakHandle(sync_enabled_weak_factory_.GetWeakPtr()),
base::Bind(syncer::ReportUnrecoverableError, channel_),
@@ -991,6 +968,10 @@ void ProfileSyncService::PostBackendInitialization() {
}
NotifyObservers();
+
+ // Nobody will call us to start if no sign in is going to happen.
+ if (local_sync_backend_enabled_)
+ RequestStart();
}
void ProfileSyncService::OnBackendInitialized(
@@ -1024,10 +1005,15 @@ void ProfileSyncService::OnBackendInitialized(
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 (local_sync_backend_enabled_) {
+ 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,
@@ -1542,6 +1528,8 @@ bool ProfileSyncService::IsSignedIn() const {
}
bool ProfileSyncService::CanBackendStart() const {
+ if (local_sync_backend_enabled_)
+ return true;
return CanSyncStart() && oauth2_token_service_ &&
oauth2_token_service_->RefreshTokenIsAvailable(
signin_->GetAccountIdToUse());
@@ -2437,7 +2425,7 @@ bool ProfileSyncService::HasSyncingBackend() const {
}
void ProfileSyncService::UpdateFirstSyncTimePref() {
- if (!IsSignedIn()) {
+ if (!local_sync_backend_enabled_ && !IsSignedIn()) {
sync_prefs_.ClearFirstSyncTime();
} else if (sync_prefs_.GetFirstSyncTime().is_null()) {
// Set if not set before and it's syncing now.

Powered by Google App Engine
This is Rietveld 408576698