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

Side by Side 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 unified diff | Download patch
OLDNEW
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>
11 #include <utility> 11 #include <utility>
12 12
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/bind_helpers.h" 14 #include "base/bind_helpers.h"
15 #include "base/callback.h" 15 #include "base/callback.h"
16 #include "base/command_line.h" 16 #include "base/command_line.h"
17 #include "base/feature_list.h" 17 #include "base/feature_list.h"
18 #include "base/files/file_util.h" 18 #include "base/files/file_util.h"
19 #include "base/logging.h" 19 #include "base/logging.h"
20 #include "base/memory/ptr_util.h" 20 #include "base/memory/ptr_util.h"
21 #include "base/memory/ref_counted.h" 21 #include "base/memory/ref_counted.h"
22 #include "base/metrics/histogram.h" 22 #include "base/metrics/histogram.h"
23 #include "base/path_service.h"
24 #include "base/profiler/scoped_tracker.h" 23 #include "base/profiler/scoped_tracker.h"
25 #include "base/single_thread_task_runner.h" 24 #include "base/single_thread_task_runner.h"
26 #include "base/strings/stringprintf.h" 25 #include "base/strings/stringprintf.h"
27 #include "base/threading/thread_restrictions.h" 26 #include "base/threading/thread_restrictions.h"
28 #include "base/threading/thread_task_runner_handle.h" 27 #include "base/threading/thread_task_runner_handle.h"
29 #include "components/autofill/core/common/autofill_pref_names.h" 28 #include "components/autofill/core/common/autofill_pref_names.h"
30 #include "components/browser_sync/browser_sync_switches.h" 29 #include "components/browser_sync/browser_sync_switches.h"
31 #include "components/history/core/browser/typed_url_data_type_controller.h" 30 #include "components/history/core/browser/typed_url_data_type_controller.h"
32 #include "components/invalidation/impl/invalidation_prefs.h" 31 #include "components/invalidation/impl/invalidation_prefs.h"
33 #include "components/invalidation/public/invalidation_service.h" 32 #include "components/invalidation/public/invalidation_service.h"
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 144
146 // Don't use initial delay unless the last request was an error. 145 // Don't use initial delay unless the last request was an error.
147 false, 146 false,
148 }; 147 };
149 148
150 static const base::FilePath::CharType kSyncDataFolderName[] = 149 static const base::FilePath::CharType kSyncDataFolderName[] =
151 FILE_PATH_LITERAL("Sync Data"); 150 FILE_PATH_LITERAL("Sync Data");
152 static const base::FilePath::CharType kLevelDBFolderName[] = 151 static const base::FilePath::CharType kLevelDBFolderName[] =
153 FILE_PATH_LITERAL("LevelDB"); 152 FILE_PATH_LITERAL("LevelDB");
154 153
155 #if defined(OS_WIN)
156 static const base::FilePath::CharType kLoopbackServerBackendFilename[] =
157 FILE_PATH_LITERAL("profile.pb");
158 #endif
159
160 namespace { 154 namespace {
161 155
162 // Perform the actual sync data folder deletion. 156 // Perform the actual sync data folder deletion.
163 // This should only be called on the sync thread. 157 // This should only be called on the sync thread.
164 void DeleteSyncDataFolder(const base::FilePath& directory_path) { 158 void DeleteSyncDataFolder(const base::FilePath& directory_path) {
165 if (base::DirectoryExists(directory_path)) { 159 if (base::DirectoryExists(directory_path)) {
166 if (!base::DeleteFile(directory_path, true)) 160 if (!base::DeleteFile(directory_path, true))
167 LOG(DFATAL) << "Could not delete the Sync Data folder."; 161 LOG(DFATAL) << "Could not delete the Sync Data folder.";
168 } 162 }
169 } 163 }
170 164
171 } // namespace 165 } // namespace
172 166
173 ProfileSyncService::InitParams::InitParams() = default; 167 ProfileSyncService::InitParams::InitParams() = default;
174 ProfileSyncService::InitParams::~InitParams() = default; 168 ProfileSyncService::InitParams::~InitParams() = default;
175 ProfileSyncService::InitParams::InitParams(InitParams&& other) // NOLINT 169 ProfileSyncService::InitParams::InitParams(InitParams&& other) // NOLINT
176 : sync_client(std::move(other.sync_client)), 170 : sync_client(std::move(other.sync_client)),
177 signin_wrapper(std::move(other.signin_wrapper)), 171 signin_wrapper(std::move(other.signin_wrapper)),
178 oauth2_token_service(other.oauth2_token_service), 172 oauth2_token_service(other.oauth2_token_service),
179 gaia_cookie_manager_service(other.gaia_cookie_manager_service), 173 gaia_cookie_manager_service(other.gaia_cookie_manager_service),
180 start_behavior(other.start_behavior), 174 start_behavior(other.start_behavior),
181 network_time_update_callback( 175 network_time_update_callback(
182 std::move(other.network_time_update_callback)), 176 std::move(other.network_time_update_callback)),
183 base_directory(std::move(other.base_directory)), 177 base_directory(std::move(other.base_directory)),
184 url_request_context(std::move(other.url_request_context)), 178 url_request_context(std::move(other.url_request_context)),
185 debug_identifier(std::move(other.debug_identifier)), 179 debug_identifier(std::move(other.debug_identifier)),
186 channel(other.channel), 180 channel(other.channel),
187 blocking_pool(other.blocking_pool) {} 181 blocking_pool(other.blocking_pool),
182 local_sync_backend_enabled(other.local_sync_backend_enabled),
183 local_sync_backend_folder(other.local_sync_backend_folder) {}
188 184
189 ProfileSyncService::ProfileSyncService(InitParams init_params) 185 ProfileSyncService::ProfileSyncService(InitParams init_params)
190 : OAuth2TokenService::Consumer("sync"), 186 : OAuth2TokenService::Consumer("sync"),
191 last_auth_error_(AuthError::AuthErrorNone()), 187 last_auth_error_(AuthError::AuthErrorNone()),
192 passphrase_required_reason_(syncer::REASON_PASSPHRASE_NOT_REQUIRED), 188 passphrase_required_reason_(syncer::REASON_PASSPHRASE_NOT_REQUIRED),
193 sync_client_(std::move(init_params.sync_client)), 189 sync_client_(std::move(init_params.sync_client)),
194 sync_prefs_(sync_client_->GetPrefService()), 190 sync_prefs_(sync_client_->GetPrefService()),
195 sync_service_url_( 191 sync_service_url_(
196 syncer::GetSyncServiceURL(*base::CommandLine::ForCurrentProcess(), 192 syncer::GetSyncServiceURL(*base::CommandLine::ForCurrentProcess(),
197 init_params.channel)), 193 init_params.channel)),
198 network_time_update_callback_( 194 network_time_update_callback_(
199 std::move(init_params.network_time_update_callback)), 195 std::move(init_params.network_time_update_callback)),
200 base_directory_(init_params.base_directory), 196 base_directory_(init_params.base_directory),
201 url_request_context_(init_params.url_request_context), 197 url_request_context_(init_params.url_request_context),
202 debug_identifier_(std::move(init_params.debug_identifier)), 198 debug_identifier_(std::move(init_params.debug_identifier)),
203 channel_(init_params.channel), 199 channel_(init_params.channel),
204 blocking_pool_(init_params.blocking_pool), 200 blocking_pool_(init_params.blocking_pool),
205 is_first_time_sync_configure_(false), 201 is_first_time_sync_configure_(false),
206 backend_initialized_(false), 202 backend_initialized_(false),
207 sync_disabled_by_admin_(false), 203 sync_disabled_by_admin_(false),
208 is_auth_in_progress_(false), 204 is_auth_in_progress_(false),
205 local_sync_backend_enabled_(init_params.local_sync_backend_enabled),
206 local_sync_backend_folder_(init_params.local_sync_backend_folder),
209 signin_(std::move(init_params.signin_wrapper)), 207 signin_(std::move(init_params.signin_wrapper)),
210 unrecoverable_error_reason_(ERROR_REASON_UNSET), 208 unrecoverable_error_reason_(ERROR_REASON_UNSET),
211 expect_sync_configuration_aborted_(false), 209 expect_sync_configuration_aborted_(false),
212 encrypted_types_(syncer::SyncEncryptionHandler::SensitiveTypes()), 210 encrypted_types_(syncer::SyncEncryptionHandler::SensitiveTypes()),
213 encrypt_everything_allowed_(true), 211 encrypt_everything_allowed_(true),
214 encrypt_everything_(false), 212 encrypt_everything_(false),
215 encryption_pending_(false), 213 encryption_pending_(false),
216 configure_status_(DataTypeManager::UNKNOWN), 214 configure_status_(DataTypeManager::UNKNOWN),
217 oauth2_token_service_(init_params.oauth2_token_service), 215 oauth2_token_service_(init_params.oauth2_token_service),
218 request_access_token_backoff_(&kRequestAccessTokenBackoffPolicy), 216 request_access_token_backoff_(&kRequestAccessTokenBackoffPolicy),
(...skipping 24 matching lines...) Expand all
243 241
244 ProfileSyncService::~ProfileSyncService() { 242 ProfileSyncService::~ProfileSyncService() {
245 if (gaia_cookie_manager_service_) 243 if (gaia_cookie_manager_service_)
246 gaia_cookie_manager_service_->RemoveObserver(this); 244 gaia_cookie_manager_service_->RemoveObserver(this);
247 sync_prefs_.RemoveSyncPrefObserver(this); 245 sync_prefs_.RemoveSyncPrefObserver(this);
248 // Shutdown() should have been called before destruction. 246 // Shutdown() should have been called before destruction.
249 CHECK(!backend_initialized_); 247 CHECK(!backend_initialized_);
250 } 248 }
251 249
252 bool ProfileSyncService::CanSyncStart() const { 250 bool ProfileSyncService::CanSyncStart() const {
253 return IsSyncAllowed() && IsSyncRequested() && IsSignedIn(); 251 return (IsSyncAllowed() && IsSyncRequested() &&
252 (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
254 } 253 }
255 254
256 void ProfileSyncService::Initialize() { 255 void ProfileSyncService::Initialize() {
257 sync_client_->Initialize(); 256 sync_client_->Initialize();
258 257
259 // We don't pass StartupController an Unretained reference to future-proof 258 // We don't pass StartupController an Unretained reference to future-proof
260 // against the controller impl changing to post tasks. 259 // against the controller impl changing to post tasks.
261 startup_controller_ = base::MakeUnique<syncer::StartupController>( 260 startup_controller_ = base::MakeUnique<syncer::StartupController>(
262 &sync_prefs_, 261 &sync_prefs_,
263 base::Bind(&ProfileSyncService::CanBackendStart, base::Unretained(this)), 262 base::Bind(&ProfileSyncService::CanBackendStart, base::Unretained(this)),
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 gaia_cookie_manager_service_->AddObserver(this); 308 gaia_cookie_manager_service_->AddObserver(this);
310 309
311 // We clear this here (vs Shutdown) because we want to remember that an error 310 // We clear this here (vs Shutdown) because we want to remember that an error
312 // happened on shutdown so we can display details (message, location) about it 311 // happened on shutdown so we can display details (message, location) about it
313 // in about:sync. 312 // in about:sync.
314 ClearStaleErrors(); 313 ClearStaleErrors();
315 314
316 sync_prefs_.AddSyncPrefObserver(this); 315 sync_prefs_.AddSyncPrefObserver(this);
317 316
318 SyncInitialState sync_state = CAN_START; 317 SyncInitialState sync_state = CAN_START;
319 if (!IsSignedIn()) { 318 if (!local_sync_backend_enabled_ && !IsSignedIn()) {
320 sync_state = NOT_SIGNED_IN; 319 sync_state = NOT_SIGNED_IN;
321 } else if (IsManaged()) { 320 } else if (IsManaged()) {
322 sync_state = IS_MANAGED; 321 sync_state = IS_MANAGED;
323 } else if (!IsSyncAllowedByPlatform()) { 322 } else if (!IsSyncAllowedByPlatform()) {
324 // This case should currently never be hit, as Android's master sync isn't 323 // This case should currently never be hit, as Android's master sync isn't
325 // plumbed into PSS until after this function. See http://crbug.com/568771. 324 // plumbed into PSS until after this function. See http://crbug.com/568771.
326 sync_state = NOT_ALLOWED_BY_PLATFORM; 325 sync_state = NOT_ALLOWED_BY_PLATFORM;
327 } else if (!IsSyncRequested()) { 326 } else if (!IsSyncRequested()) {
328 if (IsFirstSetupComplete()) { 327 if (IsFirstSetupComplete()) {
329 sync_state = NOT_REQUESTED; 328 sync_state = NOT_REQUESTED;
330 } else { 329 } else {
331 sync_state = NOT_REQUESTED_NOT_SETUP; 330 sync_state = NOT_REQUESTED_NOT_SETUP;
332 } 331 }
333 } else if (!IsFirstSetupComplete()) { 332 } else if (!IsFirstSetupComplete()) {
334 sync_state = NEEDS_CONFIRMATION; 333 sync_state = NEEDS_CONFIRMATION;
335 } 334 }
336 UMA_HISTOGRAM_ENUMERATION("Sync.InitialState", sync_state, 335 UMA_HISTOGRAM_ENUMERATION("Sync.InitialState", sync_state,
337 SYNC_INITIAL_STATE_LIMIT); 336 SYNC_INITIAL_STATE_LIMIT);
338 337
339 // If sync isn't allowed, the only thing to do is to turn it off. 338 // If sync isn't allowed, the only thing to do is to turn it off.
340 if (!IsSyncAllowed()) { 339 if (!IsSyncAllowed()) {
341 // Only clear data if disallowed by policy. 340 // Only clear data if disallowed by policy.
342 RequestStop(IsManaged() ? CLEAR_DATA : KEEP_DATA); 341 RequestStop(IsManaged() ? CLEAR_DATA : KEEP_DATA);
343 return; 342 return;
344 } 343 }
345 344
346 RegisterAuthNotifications(); 345 if (!local_sync_backend_enabled_) {
346 RegisterAuthNotifications();
347 347
348 if (!IsSignedIn()) { 348 if (!IsSignedIn()) {
349 // Clean up in case of previous crash during signout. 349 // Clean up in case of previous crash during signout.
350 StopImpl(CLEAR_DATA); 350 StopImpl(CLEAR_DATA);
351 }
351 } 352 }
352 353
353 #if defined(OS_CHROMEOS) 354 #if defined(OS_CHROMEOS)
354 std::string bootstrap_token = sync_prefs_.GetEncryptionBootstrapToken(); 355 std::string bootstrap_token = sync_prefs_.GetEncryptionBootstrapToken();
355 if (bootstrap_token.empty()) { 356 if (bootstrap_token.empty()) {
356 sync_prefs_.SetEncryptionBootstrapToken( 357 sync_prefs_.SetEncryptionBootstrapToken(
357 sync_prefs_.GetSpareBootstrapToken()); 358 sync_prefs_.GetSpareBootstrapToken());
358 } 359 }
359 #endif 360 #endif
360 361
361 #if !defined(OS_ANDROID) 362 #if !defined(OS_ANDROID)
362 DCHECK(sync_error_controller_ == nullptr) 363 DCHECK(sync_error_controller_ == nullptr)
363 << "Initialize() called more than once."; 364 << "Initialize() called more than once.";
364 sync_error_controller_ = base::MakeUnique<syncer::SyncErrorController>(this); 365 sync_error_controller_ = base::MakeUnique<syncer::SyncErrorController>(this);
365 AddObserver(sync_error_controller_.get()); 366 AddObserver(sync_error_controller_.get());
366 #endif 367 #endif
367 368
368 memory_pressure_listener_ = base::MakeUnique<base::MemoryPressureListener>( 369 memory_pressure_listener_ = base::MakeUnique<base::MemoryPressureListener>(
369 base::Bind(&ProfileSyncService::OnMemoryPressure, 370 base::Bind(&ProfileSyncService::OnMemoryPressure,
370 sync_enabled_weak_factory_.GetWeakPtr())); 371 sync_enabled_weak_factory_.GetWeakPtr()));
371 startup_controller_->Reset(GetRegisteredDataTypes()); 372 startup_controller_->Reset(GetRegisteredDataTypes());
372 373
373 // Auto-start means means the first time the profile starts up, sync should 374 // Auto-start means the first time the profile starts up, sync should start up
374 // start up immediately. 375 // immediately.
375 if (start_behavior_ == AUTO_START && IsSyncRequested() && 376 if (start_behavior_ == AUTO_START && IsSyncRequested() &&
376 !IsFirstSetupComplete()) { 377 !IsFirstSetupComplete()) {
377 startup_controller_->TryStartImmediately(); 378 startup_controller_->TryStartImmediately();
378 } else { 379 } else {
379 startup_controller_->TryStart(); 380 startup_controller_->TryStart();
380 } 381 }
381 } 382 }
382 383
383 void ProfileSyncService::StartSyncingWithServer() { 384 void ProfileSyncService::StartSyncingWithServer() {
384 DCHECK(thread_checker_.CalledOnValidThread()); 385 DCHECK(thread_checker_.CalledOnValidThread());
(...skipping 11 matching lines...) Expand all
396 397
397 void ProfileSyncService::RegisterAuthNotifications() { 398 void ProfileSyncService::RegisterAuthNotifications() {
398 oauth2_token_service_->AddObserver(this); 399 oauth2_token_service_->AddObserver(this);
399 if (signin()) 400 if (signin())
400 signin()->AddObserver(this); 401 signin()->AddObserver(this);
401 } 402 }
402 403
403 void ProfileSyncService::UnregisterAuthNotifications() { 404 void ProfileSyncService::UnregisterAuthNotifications() {
404 if (signin()) 405 if (signin())
405 signin()->RemoveObserver(this); 406 signin()->RemoveObserver(this);
406 oauth2_token_service_->RemoveObserver(this); 407 if (oauth2_token_service_)
408 oauth2_token_service_->RemoveObserver(this);
407 } 409 }
408 410
409 void ProfileSyncService::RegisterDataTypeController( 411 void ProfileSyncService::RegisterDataTypeController(
410 std::unique_ptr<syncer::DataTypeController> data_type_controller) { 412 std::unique_ptr<syncer::DataTypeController> data_type_controller) {
411 DCHECK_EQ(data_type_controllers_.count(data_type_controller->type()), 0U); 413 DCHECK_EQ(data_type_controllers_.count(data_type_controller->type()), 0U);
412 data_type_controllers_[data_type_controller->type()] = 414 data_type_controllers_[data_type_controller->type()] =
413 std::move(data_type_controller); 415 std::move(data_type_controller);
414 } 416 }
415 417
416 bool ProfileSyncService::IsDataTypeControllerRunning( 418 bool ProfileSyncService::IsDataTypeControllerRunning(
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 return; 466 return;
465 } 467 }
466 DCHECK(iter->second); 468 DCHECK(iter->second);
467 469
468 static_cast<sync_sessions::SessionDataTypeController*>(iter->second.get()) 470 static_cast<sync_sessions::SessionDataTypeController*>(iter->second.get())
469 ->OnSessionRestoreComplete(); 471 ->OnSessionRestoreComplete();
470 } 472 }
471 473
472 SyncCredentials ProfileSyncService::GetCredentials() { 474 SyncCredentials ProfileSyncService::GetCredentials() {
473 SyncCredentials credentials; 475 SyncCredentials credentials;
476
477 // No credentials exist or are needed for the local sync backend.
478 if (local_sync_backend_enabled_)
479 return credentials;
480
474 credentials.account_id = signin_->GetAccountIdToUse(); 481 credentials.account_id = signin_->GetAccountIdToUse();
475 DCHECK(!credentials.account_id.empty()); 482 DCHECK(!credentials.account_id.empty());
476 credentials.email = signin_->GetEffectiveUsername(); 483 credentials.email = signin_->GetEffectiveUsername();
477 credentials.sync_token = access_token_; 484 credentials.sync_token = access_token_;
478 485
479 if (credentials.sync_token.empty()) 486 if (credentials.sync_token.empty())
480 credentials.sync_token = "credentials_lost"; 487 credentials.sync_token = "credentials_lost";
481 488
482 credentials.scope_set.insert(signin_->GetSyncScopeToUse()); 489 credentials.scope_set.insert(signin_->GetSyncScopeToUse());
483 490
(...skipping 15 matching lines...) Expand all
499 base::Thread::Options options; 506 base::Thread::Options options;
500 options.timer_slack = base::TIMER_SLACK_MAXIMUM; 507 options.timer_slack = base::TIMER_SLACK_MAXIMUM;
501 CHECK(sync_thread_->StartWithOptions(options)); 508 CHECK(sync_thread_->StartWithOptions(options));
502 } 509 }
503 510
504 SyncCredentials credentials = GetCredentials(); 511 SyncCredentials credentials = GetCredentials();
505 512
506 if (delete_stale_data) 513 if (delete_stale_data)
507 ClearStaleErrors(); 514 ClearStaleErrors();
508 515
509 bool enable_local_sync_backend = false;
510 base::FilePath local_sync_backend_folder;
511 #if defined(OS_WIN)
512 enable_local_sync_backend = base::CommandLine::ForCurrentProcess()->HasSwitch(
513 switches::kEnableLocalSyncBackend);
514 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
515 switches::kLocalSyncBackendDir)) {
516 local_sync_backend_folder =
517 base::CommandLine::ForCurrentProcess()->GetSwitchValuePath(
518 switches::kLocalSyncBackendDir);
519 } else {
520 // TODO(pastarmovj): Add DIR_ROAMING_USER_DATA to PathService to simplify
521 // this code and move the logic in its right place. See crbug/657810.
522 CHECK(
523 base::PathService::Get(base::DIR_APP_DATA, &local_sync_backend_folder));
524 local_sync_backend_folder =
525 local_sync_backend_folder.Append(FILE_PATH_LITERAL("Chrome/User Data"));
526 }
527 // This code as it is now will assume the same profile order is present on all
528 // machines, which is not a given. It is to be defined if only the Default
529 // profile should get this treatment or all profile as is the case now. The
530 // solution for now will be to assume profiles are created in the same order
531 // on all machines and in the future decide if only the Default one should be
532 // considered roamed.
533 local_sync_backend_folder =
534 local_sync_backend_folder.Append(base_directory_.BaseName());
535 local_sync_backend_folder =
536 local_sync_backend_folder.Append(kLoopbackServerBackendFilename);
537 #endif // defined(OS_WIN)
538
539 SyncBackendHost::HttpPostProviderFactoryGetter 516 SyncBackendHost::HttpPostProviderFactoryGetter
540 http_post_provider_factory_getter = 517 http_post_provider_factory_getter =
541 base::Bind(&syncer::NetworkResources::GetHttpPostProviderFactory, 518 base::Bind(&syncer::NetworkResources::GetHttpPostProviderFactory,
542 base::Unretained(network_resources_.get()), 519 base::Unretained(network_resources_.get()),
543 url_request_context_, network_time_update_callback_); 520 url_request_context_, network_time_update_callback_);
544 521
545 backend_->Initialize( 522 backend_->Initialize(
546 this, sync_thread_.get(), GetJsEventHandler(), sync_service_url_, 523 this, sync_thread_.get(), GetJsEventHandler(), sync_service_url_,
547 local_device_->GetSyncUserAgent(), credentials, delete_stale_data, 524 local_device_->GetSyncUserAgent(), credentials, delete_stale_data,
548 enable_local_sync_backend, local_sync_backend_folder, 525 local_sync_backend_enabled_, local_sync_backend_folder_,
549 base::MakeUnique<syncer::SyncManagerFactory>(), 526 base::MakeUnique<syncer::SyncManagerFactory>(),
550 MakeWeakHandle(sync_enabled_weak_factory_.GetWeakPtr()), 527 MakeWeakHandle(sync_enabled_weak_factory_.GetWeakPtr()),
551 base::Bind(syncer::ReportUnrecoverableError, channel_), 528 base::Bind(syncer::ReportUnrecoverableError, channel_),
552 http_post_provider_factory_getter, std::move(saved_nigori_state_)); 529 http_post_provider_factory_getter, std::move(saved_nigori_state_));
553 } 530 }
554 531
555 bool ProfileSyncService::IsEncryptedDatatypeEnabled() const { 532 bool ProfileSyncService::IsEncryptedDatatypeEnabled() const {
556 if (encryption_pending()) 533 if (encryption_pending())
557 return true; 534 return true;
558 const syncer::ModelTypeSet preferred_types = GetPreferredDataTypes(); 535 const syncer::ModelTypeSet preferred_types = GetPreferredDataTypes();
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
984 std::vector<gaia::ListedAccount> accounts; 961 std::vector<gaia::ListedAccount> accounts;
985 std::vector<gaia::ListedAccount> signed_out_accounts; 962 std::vector<gaia::ListedAccount> signed_out_accounts;
986 GoogleServiceAuthError error(GoogleServiceAuthError::NONE); 963 GoogleServiceAuthError error(GoogleServiceAuthError::NONE);
987 if (gaia_cookie_manager_service_ && 964 if (gaia_cookie_manager_service_ &&
988 gaia_cookie_manager_service_->ListAccounts( 965 gaia_cookie_manager_service_->ListAccounts(
989 &accounts, &signed_out_accounts, "ChromiumProfileSyncService")) { 966 &accounts, &signed_out_accounts, "ChromiumProfileSyncService")) {
990 OnGaiaAccountsInCookieUpdated(accounts, signed_out_accounts, error); 967 OnGaiaAccountsInCookieUpdated(accounts, signed_out_accounts, error);
991 } 968 }
992 969
993 NotifyObservers(); 970 NotifyObservers();
971
972 // Nobody will call us to start if no sign in is going to happen.
973 if (local_sync_backend_enabled_)
974 RequestStart();
994 } 975 }
995 976
996 void ProfileSyncService::OnBackendInitialized( 977 void ProfileSyncService::OnBackendInitialized(
997 const syncer::WeakHandle<syncer::JsBackend>& js_backend, 978 const syncer::WeakHandle<syncer::JsBackend>& js_backend,
998 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& 979 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>&
999 debug_info_listener, 980 debug_info_listener,
1000 const std::string& cache_guid, 981 const std::string& cache_guid,
1001 bool success) { 982 bool success) {
1002 UpdateBackendInitUMA(success); 983 UpdateBackendInitUMA(success);
1003 984
(...skipping 13 matching lines...) Expand all
1017 OnInternalUnrecoverableError(FROM_HERE, "BackendInitialize failure", false, 998 OnInternalUnrecoverableError(FROM_HERE, "BackendInitialize failure", false,
1018 ERROR_REASON_BACKEND_INIT_FAILURE); 999 ERROR_REASON_BACKEND_INIT_FAILURE);
1019 return; 1000 return;
1020 } 1001 }
1021 1002
1022 backend_initialized_ = true; 1003 backend_initialized_ = true;
1023 1004
1024 sync_js_controller_.AttachJsBackend(js_backend); 1005 sync_js_controller_.AttachJsBackend(js_backend);
1025 debug_info_listener_ = debug_info_listener; 1006 debug_info_listener_ = debug_info_listener;
1026 1007
1027 SigninClient* signin_client = signin_->GetOriginal()->signin_client(); 1008 std::string signin_scoped_device_id;
1028 DCHECK(signin_client); 1009 if (local_sync_backend_enabled_) {
1029 std::string signin_scoped_device_id = 1010 signin_scoped_device_id = "local_device";
1030 signin_client->GetSigninScopedDeviceId(); 1011 } else {
1012 SigninClient* signin_client = signin_->GetOriginal()->signin_client();
1013 DCHECK(signin_client);
1014 std::string signin_scoped_device_id =
1015 signin_client->GetSigninScopedDeviceId();
1016 }
1031 1017
1032 // Initialize local device info. 1018 // Initialize local device info.
1033 local_device_->Initialize(cache_guid, signin_scoped_device_id, 1019 local_device_->Initialize(cache_guid, signin_scoped_device_id,
1034 blocking_pool_); 1020 blocking_pool_);
1035 1021
1036 PostBackendInitialization(); 1022 PostBackendInitialization();
1037 } 1023 }
1038 1024
1039 void ProfileSyncService::OnSyncCycleCompleted() { 1025 void ProfileSyncService::OnSyncCycleCompleted() {
1040 UpdateLastSyncedTime(); 1026 UpdateLastSyncedTime();
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
1535 if (backend_initialized_) 1521 if (backend_initialized_)
1536 backend_->TriggerRefresh(types); 1522 backend_->TriggerRefresh(types);
1537 } 1523 }
1538 1524
1539 bool ProfileSyncService::IsSignedIn() const { 1525 bool ProfileSyncService::IsSignedIn() const {
1540 // Sync is logged in if there is a non-empty effective account id. 1526 // Sync is logged in if there is a non-empty effective account id.
1541 return !signin_->GetAccountIdToUse().empty(); 1527 return !signin_->GetAccountIdToUse().empty();
1542 } 1528 }
1543 1529
1544 bool ProfileSyncService::CanBackendStart() const { 1530 bool ProfileSyncService::CanBackendStart() const {
1531 if (local_sync_backend_enabled_)
1532 return true;
1545 return CanSyncStart() && oauth2_token_service_ && 1533 return CanSyncStart() && oauth2_token_service_ &&
1546 oauth2_token_service_->RefreshTokenIsAvailable( 1534 oauth2_token_service_->RefreshTokenIsAvailable(
1547 signin_->GetAccountIdToUse()); 1535 signin_->GetAccountIdToUse());
1548 } 1536 }
1549 1537
1550 bool ProfileSyncService::IsBackendInitialized() const { 1538 bool ProfileSyncService::IsBackendInitialized() const {
1551 return backend_initialized_; 1539 return backend_initialized_;
1552 } 1540 }
1553 1541
1554 bool ProfileSyncService::ConfigurationDone() const { 1542 bool ProfileSyncService::ConfigurationDone() const {
(...skipping 875 matching lines...) Expand 10 before | Expand all | Expand 10 after
2430 void ProfileSyncService::OverrideNetworkResourcesForTest( 2418 void ProfileSyncService::OverrideNetworkResourcesForTest(
2431 std::unique_ptr<syncer::NetworkResources> network_resources) { 2419 std::unique_ptr<syncer::NetworkResources> network_resources) {
2432 network_resources_ = std::move(network_resources); 2420 network_resources_ = std::move(network_resources);
2433 } 2421 }
2434 2422
2435 bool ProfileSyncService::HasSyncingBackend() const { 2423 bool ProfileSyncService::HasSyncingBackend() const {
2436 return backend_ != nullptr; 2424 return backend_ != nullptr;
2437 } 2425 }
2438 2426
2439 void ProfileSyncService::UpdateFirstSyncTimePref() { 2427 void ProfileSyncService::UpdateFirstSyncTimePref() {
2440 if (!IsSignedIn()) { 2428 if (!local_sync_backend_enabled_ && !IsSignedIn()) {
2441 sync_prefs_.ClearFirstSyncTime(); 2429 sync_prefs_.ClearFirstSyncTime();
2442 } else if (sync_prefs_.GetFirstSyncTime().is_null()) { 2430 } else if (sync_prefs_.GetFirstSyncTime().is_null()) {
2443 // Set if not set before and it's syncing now. 2431 // Set if not set before and it's syncing now.
2444 sync_prefs_.SetFirstSyncTime(base::Time::Now()); 2432 sync_prefs_.SetFirstSyncTime(base::Time::Now());
2445 } 2433 }
2446 } 2434 }
2447 2435
2448 void ProfileSyncService::FlushDirectory() const { 2436 void ProfileSyncService::FlushDirectory() const {
2449 // backend_initialized_ implies backend_ isn't null and the manager exists. 2437 // backend_initialized_ implies backend_ isn't null and the manager exists.
2450 // If sync is not initialized yet, we fail silently. 2438 // If sync is not initialized yet, we fail silently.
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
2534 2522
2535 DCHECK(startup_controller_->IsSetupInProgress()); 2523 DCHECK(startup_controller_->IsSetupInProgress());
2536 startup_controller_->SetSetupInProgress(false); 2524 startup_controller_->SetSetupInProgress(false);
2537 2525
2538 if (IsBackendInitialized()) 2526 if (IsBackendInitialized())
2539 ReconfigureDatatypeManager(); 2527 ReconfigureDatatypeManager();
2540 NotifyObservers(); 2528 NotifyObservers();
2541 } 2529 }
2542 2530
2543 } // namespace browser_sync 2531 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698