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

Side by Side Diff: chrome/browser/sync/profile_sync_service.cc

Issue 795003003: Make ProfileSyncService's WeakPtrFactory the last member (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: use scoped_ptr Created 6 years 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
« no previous file with comments | « chrome/browser/sync/profile_sync_service.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "chrome/browser/sync/profile_sync_service.h" 5 #include "chrome/browser/sync/profile_sync_service.h"
6 6
7 #include <cstddef> 7 #include <cstddef>
8 #include <map> 8 #include <map>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 signin_(signin_wrapper.Pass()), 224 signin_(signin_wrapper.Pass()),
225 unrecoverable_error_reason_(ERROR_REASON_UNSET), 225 unrecoverable_error_reason_(ERROR_REASON_UNSET),
226 expect_sync_configuration_aborted_(false), 226 expect_sync_configuration_aborted_(false),
227 encrypted_types_(syncer::SyncEncryptionHandler::SensitiveTypes()), 227 encrypted_types_(syncer::SyncEncryptionHandler::SensitiveTypes()),
228 encrypt_everything_allowed_(true), 228 encrypt_everything_allowed_(true),
229 encrypt_everything_(false), 229 encrypt_everything_(false),
230 encryption_pending_(false), 230 encryption_pending_(false),
231 configure_status_(DataTypeManager::UNKNOWN), 231 configure_status_(DataTypeManager::UNKNOWN),
232 oauth2_token_service_(oauth2_token_service), 232 oauth2_token_service_(oauth2_token_service),
233 request_access_token_backoff_(&kRequestAccessTokenBackoffPolicy), 233 request_access_token_backoff_(&kRequestAccessTokenBackoffPolicy),
234 weak_factory_(this),
235 startup_controller_weak_factory_(this),
236 connection_status_(syncer::CONNECTION_NOT_ATTEMPTED), 234 connection_status_(syncer::CONNECTION_NOT_ATTEMPTED),
237 last_get_token_error_(GoogleServiceAuthError::AuthErrorNone()), 235 last_get_token_error_(GoogleServiceAuthError::AuthErrorNone()),
238 network_resources_(new syncer::HttpBridgeNetworkResources), 236 network_resources_(new syncer::HttpBridgeNetworkResources),
239 startup_controller_(
240 start_behavior,
241 oauth2_token_service,
242 &sync_prefs_,
243 signin_.get(),
244 base::Bind(&ProfileSyncService::StartUpSlowBackendComponents,
245 startup_controller_weak_factory_.GetWeakPtr(),
246 SYNC)),
247 backup_rollback_controller_(
248 &sync_prefs_,
249 signin_.get(),
250 base::Bind(&ProfileSyncService::StartUpSlowBackendComponents,
251 startup_controller_weak_factory_.GetWeakPtr(),
252 BACKUP),
253 base::Bind(&ProfileSyncService::StartUpSlowBackendComponents,
254 startup_controller_weak_factory_.GetWeakPtr(),
255 ROLLBACK)),
256 backend_mode_(IDLE), 237 backend_mode_(IDLE),
257 need_backup_(false), 238 need_backup_(false),
258 backup_finished_(false), 239 backup_finished_(false),
259 clear_browsing_data_(base::Bind(&ClearBrowsingData)), 240 clear_browsing_data_(base::Bind(&ClearBrowsingData)),
260 browsing_data_remover_observer_(NULL) { 241 browsing_data_remover_observer_(NULL),
242 weak_factory_(this),
243 startup_controller_weak_factory_(this) {
261 DCHECK(profile); 244 DCHECK(profile);
245 startup_controller_.reset(new browser_sync::StartupController(
246 start_behavior,
247 oauth2_token_service,
248 &sync_prefs_,
249 signin_.get(),
250 base::Bind(&ProfileSyncService::StartUpSlowBackendComponents,
251 startup_controller_weak_factory_.GetWeakPtr(),
252 SYNC)));
253 backup_rollback_controller_.reset(new browser_sync::BackupRollbackController(
254 &sync_prefs_,
255 signin_.get(),
256 base::Bind(&ProfileSyncService::StartUpSlowBackendComponents,
257 startup_controller_weak_factory_.GetWeakPtr(),
258 BACKUP),
259 base::Bind(&ProfileSyncService::StartUpSlowBackendComponents,
260 startup_controller_weak_factory_.GetWeakPtr(),
261 ROLLBACK)));
262 syncer::SyncableService::StartSyncFlare flare( 262 syncer::SyncableService::StartSyncFlare flare(
263 sync_start_util::GetFlareForSyncableService(profile->GetPath())); 263 sync_start_util::GetFlareForSyncableService(profile->GetPath()));
264 scoped_ptr<browser_sync::LocalSessionEventRouter> router( 264 scoped_ptr<browser_sync::LocalSessionEventRouter> router(
265 new NotificationServiceSessionsRouter(profile, flare)); 265 new NotificationServiceSessionsRouter(profile, flare));
266 266
267 DCHECK(factory_.get()); 267 DCHECK(factory_.get());
268 local_device_ = factory_->CreateLocalDeviceInfoProvider(); 268 local_device_ = factory_->CreateLocalDeviceInfoProvider();
269 sessions_sync_manager_.reset( 269 sessions_sync_manager_.reset(
270 new SessionsSyncManager(profile, local_device_.get(), router.Pass())); 270 new SessionsSyncManager(profile, local_device_.get(), router.Pass()));
271 device_info_sync_service_.reset( 271 device_info_sync_service_.reset(
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 #endif 334 #endif
335 335
336 bool running_rollback = false; 336 bool running_rollback = false;
337 if (browser_sync::BackupRollbackController::IsBackupEnabled()) { 337 if (browser_sync::BackupRollbackController::IsBackupEnabled()) {
338 // Backup is needed if user's not signed in or signed in but previous 338 // Backup is needed if user's not signed in or signed in but previous
339 // backup didn't finish, i.e. backend didn't switch from backup to sync. 339 // backup didn't finish, i.e. backend didn't switch from backup to sync.
340 need_backup_ = signin_->GetEffectiveUsername().empty() || 340 need_backup_ = signin_->GetEffectiveUsername().empty() ||
341 sync_prefs_.GetFirstSyncTime().is_null(); 341 sync_prefs_.GetFirstSyncTime().is_null();
342 342
343 // Try to resume rollback if it didn't finish in last session. 343 // Try to resume rollback if it didn't finish in last session.
344 running_rollback = backup_rollback_controller_.StartRollback(); 344 running_rollback = backup_rollback_controller_->StartRollback();
345 } else { 345 } else {
346 need_backup_ = false; 346 need_backup_ = false;
347 } 347 }
348 348
349 #if defined(ENABLE_PRE_SYNC_BACKUP) 349 #if defined(ENABLE_PRE_SYNC_BACKUP)
350 if (!running_rollback && signin_->GetEffectiveUsername().empty()) { 350 if (!running_rollback && signin_->GetEffectiveUsername().empty()) {
351 CleanUpBackup(); 351 CleanUpBackup();
352 } 352 }
353 #else 353 #else
354 DCHECK(!running_rollback); 354 DCHECK(!running_rollback);
355 #endif 355 #endif
356 356
357 startup_controller_.Reset(GetRegisteredDataTypes()); 357 startup_controller_->Reset(GetRegisteredDataTypes());
358 startup_controller_.TryStart(); 358 startup_controller_->TryStart();
359 } 359 }
360 360
361 void ProfileSyncService::TrySyncDatatypePrefRecovery() { 361 void ProfileSyncService::TrySyncDatatypePrefRecovery() {
362 DCHECK(!backend_initialized()); 362 DCHECK(!backend_initialized());
363 if (!HasSyncSetupCompleted()) 363 if (!HasSyncSetupCompleted())
364 return; 364 return;
365 365
366 // There was a bug where OnUserChoseDatatypes was not properly called on 366 // There was a bug where OnUserChoseDatatypes was not properly called on
367 // configuration (see crbug.com/154940). We detect this by checking whether 367 // configuration (see crbug.com/154940). We detect this by checking whether
368 // kSyncKeepEverythingSynced has a default value. If so, and sync setup has 368 // kSyncKeepEverythingSynced has a default value. If so, and sync setup has
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 } 596 }
597 597
598 if (!GetPreferredDataTypes().Has(type)) { 598 if (!GetPreferredDataTypes().Has(type)) {
599 // We can get here as datatype SyncableServices are typically wired up 599 // We can get here as datatype SyncableServices are typically wired up
600 // to the native datatype even if sync isn't enabled. 600 // to the native datatype even if sync isn't enabled.
601 DVLOG(1) << "Dropping sync startup request because type " 601 DVLOG(1) << "Dropping sync startup request because type "
602 << syncer::ModelTypeToString(type) << "not enabled."; 602 << syncer::ModelTypeToString(type) << "not enabled.";
603 return; 603 return;
604 } 604 }
605 605
606 startup_controller_.OnDataTypeRequestsSyncStartup(type); 606 startup_controller_->OnDataTypeRequestsSyncStartup(type);
607 } 607 }
608 608
609 void ProfileSyncService::StartUpSlowBackendComponents( 609 void ProfileSyncService::StartUpSlowBackendComponents(
610 ProfileSyncService::BackendMode mode) { 610 ProfileSyncService::BackendMode mode) {
611 DCHECK_NE(IDLE, mode); 611 DCHECK_NE(IDLE, mode);
612 if (backend_mode_ == mode) { 612 if (backend_mode_ == mode) {
613 return; 613 return;
614 } 614 }
615 615
616 // Backend mode transition rules: 616 // Backend mode transition rules:
(...skipping 12 matching lines...) Expand all
629 } 629 }
630 630
631 if (backend_mode_ == ROLLBACK || 631 if (backend_mode_ == ROLLBACK ||
632 (backend_mode_ == BACKUP && !backup_finished_)) { 632 (backend_mode_ == BACKUP && !backup_finished_)) {
633 // Wait for rollback/backup to finish before start new backend. 633 // Wait for rollback/backup to finish before start new backend.
634 return; 634 return;
635 } 635 }
636 636
637 if (mode == SYNC && NeedBackup() && !backup_finished_) { 637 if (mode == SYNC && NeedBackup() && !backup_finished_) {
638 if (backend_mode_ != BACKUP) 638 if (backend_mode_ != BACKUP)
639 backup_rollback_controller_.StartBackup(); 639 backup_rollback_controller_->StartBackup();
640 return; 640 return;
641 } 641 }
642 642
643 DVLOG(1) << "Start backend mode: " << mode; 643 DVLOG(1) << "Start backend mode: " << mode;
644 644
645 if (backend_) { 645 if (backend_) {
646 if (mode == SYNC) 646 if (mode == SYNC)
647 ShutdownImpl(syncer::SWITCH_MODE_SYNC); 647 ShutdownImpl(syncer::SWITCH_MODE_SYNC);
648 else 648 else
649 ShutdownImpl(syncer::STOP_SYNC); 649 ShutdownImpl(syncer::STOP_SYNC);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 if (sync_prefs_.SyncHasAuthError()) { 709 if (sync_prefs_.SyncHasAuthError()) {
710 sync_prefs_.SetSyncAuthError(false); 710 sync_prefs_.SetSyncAuthError(false);
711 UMA_HISTOGRAM_ENUMERATION("Sync.SyncAuthError", 711 UMA_HISTOGRAM_ENUMERATION("Sync.SyncAuthError",
712 AUTH_ERROR_FIXED, 712 AUTH_ERROR_FIXED,
713 AUTH_ERROR_LIMIT); 713 AUTH_ERROR_LIMIT);
714 } 714 }
715 715
716 if (HasSyncingBackend()) 716 if (HasSyncingBackend())
717 backend_->UpdateCredentials(GetCredentials()); 717 backend_->UpdateCredentials(GetCredentials());
718 else 718 else
719 startup_controller_.TryStart(); 719 startup_controller_->TryStart();
720 } 720 }
721 721
722 void ProfileSyncService::OnGetTokenFailure( 722 void ProfileSyncService::OnGetTokenFailure(
723 const OAuth2TokenService::Request* request, 723 const OAuth2TokenService::Request* request,
724 const GoogleServiceAuthError& error) { 724 const GoogleServiceAuthError& error) {
725 DCHECK_EQ(access_token_request_, request); 725 DCHECK_EQ(access_token_request_, request);
726 DCHECK_NE(error.state(), GoogleServiceAuthError::NONE); 726 DCHECK_NE(error.state(), GoogleServiceAuthError::NONE);
727 access_token_request_.reset(); 727 access_token_request_.reset();
728 last_get_token_error_ = error; 728 last_get_token_error_ = error;
729 switch (error.state()) { 729 switch (error.state()) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 785
786 void ProfileSyncService::OnRefreshTokensLoaded() { 786 void ProfileSyncService::OnRefreshTokensLoaded() {
787 // This notification gets fired when OAuth2TokenService loads the tokens 787 // This notification gets fired when OAuth2TokenService loads the tokens
788 // from storage. 788 // from storage.
789 // Initialize the backend if sync is enabled. If the sync token was 789 // Initialize the backend if sync is enabled. If the sync token was
790 // not loaded, GetCredentials() will generate invalid credentials to 790 // not loaded, GetCredentials() will generate invalid credentials to
791 // cause the backend to generate an auth error (crbug.com/121755). 791 // cause the backend to generate an auth error (crbug.com/121755).
792 if (HasSyncingBackend()) { 792 if (HasSyncingBackend()) {
793 RequestAccessToken(); 793 RequestAccessToken();
794 } else { 794 } else {
795 startup_controller_.TryStart(); 795 startup_controller_->TryStart();
796 } 796 }
797 } 797 }
798 798
799 void ProfileSyncService::Shutdown() { 799 void ProfileSyncService::Shutdown() {
800 UnregisterAuthNotifications(); 800 UnregisterAuthNotifications();
801 801
802 ShutdownImpl(syncer::BROWSER_SHUTDOWN); 802 ShutdownImpl(syncer::BROWSER_SHUTDOWN);
803 if (sync_error_controller_) { 803 if (sync_error_controller_) {
804 // Destroy the SyncErrorController when the service shuts down for good. 804 // Destroy the SyncErrorController when the service shuts down for good.
805 RemoveObserver(sync_error_controller_.get()); 805 RemoveObserver(sync_error_controller_.get());
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
854 if (doomed_backend) { 854 if (doomed_backend) {
855 sync_thread_ = doomed_backend->Shutdown(reason); 855 sync_thread_ = doomed_backend->Shutdown(reason);
856 doomed_backend.reset(); 856 doomed_backend.reset();
857 } 857 }
858 base::TimeDelta shutdown_time = base::Time::Now() - shutdown_start_time; 858 base::TimeDelta shutdown_time = base::Time::Now() - shutdown_start_time;
859 UMA_HISTOGRAM_TIMES("Sync.Shutdown.BackendDestroyedTime", shutdown_time); 859 UMA_HISTOGRAM_TIMES("Sync.Shutdown.BackendDestroyedTime", shutdown_time);
860 860
861 weak_factory_.InvalidateWeakPtrs(); 861 weak_factory_.InvalidateWeakPtrs();
862 862
863 if (backend_mode_ == SYNC) 863 if (backend_mode_ == SYNC)
864 startup_controller_.Reset(GetRegisteredDataTypes()); 864 startup_controller_->Reset(GetRegisteredDataTypes());
865 865
866 // Don't let backup block sync regardless backup succeeded or not. 866 // Don't let backup block sync regardless backup succeeded or not.
867 if (backend_mode_ == BACKUP) 867 if (backend_mode_ == BACKUP)
868 backup_finished_ = true; 868 backup_finished_ = true;
869 869
870 // Sync could be blocked by rollback/backup. Post task to check whether sync 870 // Sync could be blocked by rollback/backup. Post task to check whether sync
871 // should start after shutting down rollback/backup backend. 871 // should start after shutting down rollback/backup backend.
872 if ((backend_mode_ == ROLLBACK || backend_mode_ == BACKUP) && 872 if ((backend_mode_ == ROLLBACK || backend_mode_ == BACKUP) &&
873 reason != syncer::SWITCH_MODE_SYNC && 873 reason != syncer::SWITCH_MODE_SYNC &&
874 reason != syncer::BROWSER_SHUTDOWN) { 874 reason != syncer::BROWSER_SHUTDOWN) {
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
995 is_first_time_sync_configure_ = !HasSyncSetupCompleted(); 995 is_first_time_sync_configure_ = !HasSyncSetupCompleted();
996 996
997 if (is_first_time_sync_configure_) { 997 if (is_first_time_sync_configure_) {
998 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeFirstTimeSuccess", success); 998 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeFirstTimeSuccess", success);
999 } else { 999 } else {
1000 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeRestoreSuccess", success); 1000 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeRestoreSuccess", success);
1001 } 1001 }
1002 1002
1003 base::Time on_backend_initialized_time = base::Time::Now(); 1003 base::Time on_backend_initialized_time = base::Time::Now();
1004 base::TimeDelta delta = on_backend_initialized_time - 1004 base::TimeDelta delta = on_backend_initialized_time -
1005 startup_controller_.start_backend_time(); 1005 startup_controller_->start_backend_time();
1006 if (is_first_time_sync_configure_) { 1006 if (is_first_time_sync_configure_) {
1007 UMA_HISTOGRAM_LONG_TIMES("Sync.BackendInitializeFirstTime", delta); 1007 UMA_HISTOGRAM_LONG_TIMES("Sync.BackendInitializeFirstTime", delta);
1008 } else { 1008 } else {
1009 UMA_HISTOGRAM_LONG_TIMES("Sync.BackendInitializeRestoreTime", delta); 1009 UMA_HISTOGRAM_LONG_TIMES("Sync.BackendInitializeRestoreTime", delta);
1010 } 1010 }
1011 } 1011 }
1012 1012
1013 void ProfileSyncService::PostBackendInitialization() { 1013 void ProfileSyncService::PostBackendInitialization() {
1014 // Never get here for backup / restore. 1014 // Never get here for backup / restore.
1015 DCHECK_EQ(backend_mode_, SYNC); 1015 DCHECK_EQ(backend_mode_, SYNC);
(...skipping 19 matching lines...) Expand all
1035 // case this operation affects the "passphrase required" status. 1035 // case this operation affects the "passphrase required" status.
1036 ConsumeCachedPassphraseIfPossible(); 1036 ConsumeCachedPassphraseIfPossible();
1037 1037
1038 // The very first time the backend initializes is effectively the first time 1038 // The very first time the backend initializes is effectively the first time
1039 // we can say we successfully "synced". LastSyncedTime will only be null in 1039 // we can say we successfully "synced". LastSyncedTime will only be null in
1040 // this case, because the pref wasn't restored on StartUp. 1040 // this case, because the pref wasn't restored on StartUp.
1041 if (sync_prefs_.GetLastSyncedTime().is_null()) { 1041 if (sync_prefs_.GetLastSyncedTime().is_null()) {
1042 UpdateLastSyncedTime(); 1042 UpdateLastSyncedTime();
1043 } 1043 }
1044 1044
1045 if (startup_controller_.auto_start_enabled() && !FirstSetupInProgress()) { 1045 if (startup_controller_->auto_start_enabled() && !FirstSetupInProgress()) {
1046 // Backend is initialized but we're not in sync setup, so this must be an 1046 // Backend is initialized but we're not in sync setup, so this must be an
1047 // autostart - mark our sync setup as completed and we'll start syncing 1047 // autostart - mark our sync setup as completed and we'll start syncing
1048 // below. 1048 // below.
1049 SetSyncSetupCompleted(); 1049 SetSyncSetupCompleted();
1050 } 1050 }
1051 1051
1052 // Check HasSyncSetupCompleted() before NotifyObservers() to avoid spurious 1052 // Check HasSyncSetupCompleted() before NotifyObservers() to avoid spurious
1053 // data type configuration because observer may flag setup as complete and 1053 // data type configuration because observer may flag setup as complete and
1054 // trigger data type configuration. 1054 // trigger data type configuration.
1055 if (HasSyncSetupCompleted()) { 1055 if (HasSyncSetupCompleted()) {
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
1393 DCHECK_NE(last_actionable_error_.action, 1393 DCHECK_NE(last_actionable_error_.action,
1394 syncer::UNKNOWN_ACTION); 1394 syncer::UNKNOWN_ACTION);
1395 switch (error.action) { 1395 switch (error.action) {
1396 case syncer::UPGRADE_CLIENT: 1396 case syncer::UPGRADE_CLIENT:
1397 case syncer::CLEAR_USER_DATA_AND_RESYNC: 1397 case syncer::CLEAR_USER_DATA_AND_RESYNC:
1398 case syncer::ENABLE_SYNC_ON_ACCOUNT: 1398 case syncer::ENABLE_SYNC_ON_ACCOUNT:
1399 case syncer::STOP_AND_RESTART_SYNC: 1399 case syncer::STOP_AND_RESTART_SYNC:
1400 // TODO(lipalani) : if setup in progress we want to display these 1400 // TODO(lipalani) : if setup in progress we want to display these
1401 // actions in the popup. The current experience might not be optimal for 1401 // actions in the popup. The current experience might not be optimal for
1402 // the user. We just dismiss the dialog. 1402 // the user. We just dismiss the dialog.
1403 if (startup_controller_.setup_in_progress()) { 1403 if (startup_controller_->setup_in_progress()) {
1404 StopSyncingPermanently(); 1404 StopSyncingPermanently();
1405 expect_sync_configuration_aborted_ = true; 1405 expect_sync_configuration_aborted_ = true;
1406 } 1406 }
1407 // Trigger an unrecoverable error to stop syncing. 1407 // Trigger an unrecoverable error to stop syncing.
1408 OnInternalUnrecoverableError(FROM_HERE, 1408 OnInternalUnrecoverableError(FROM_HERE,
1409 last_actionable_error_.error_description, 1409 last_actionable_error_.error_description,
1410 true, 1410 true,
1411 ERROR_REASON_ACTIONABLE_ERROR); 1411 ERROR_REASON_ACTIONABLE_ERROR);
1412 break; 1412 break;
1413 case syncer::DISABLE_SYNC_AND_ROLLBACK: 1413 case syncer::DISABLE_SYNC_AND_ROLLBACK:
1414 backup_rollback_controller_.OnRollbackReceived(); 1414 backup_rollback_controller_->OnRollbackReceived();
1415 // Fall through to shutdown backend and sign user out. 1415 // Fall through to shutdown backend and sign user out.
1416 case syncer::DISABLE_SYNC_ON_CLIENT: 1416 case syncer::DISABLE_SYNC_ON_CLIENT:
1417 StopSyncingPermanently(); 1417 StopSyncingPermanently();
1418 #if !defined(OS_CHROMEOS) 1418 #if !defined(OS_CHROMEOS)
1419 // On desktop Chrome, sign out the user after a dashboard clear. 1419 // On desktop Chrome, sign out the user after a dashboard clear.
1420 // Skip sign out on ChromeOS/Android. 1420 // Skip sign out on ChromeOS/Android.
1421 if (!startup_controller_.auto_start_enabled()) { 1421 if (!startup_controller_->auto_start_enabled()) {
1422 SigninManagerFactory::GetForProfile(profile_)->SignOut( 1422 SigninManagerFactory::GetForProfile(profile_)->SignOut(
1423 signin_metrics::SERVER_FORCED_DISABLE); 1423 signin_metrics::SERVER_FORCED_DISABLE);
1424 } 1424 }
1425 #endif 1425 #endif
1426 break; 1426 break;
1427 case syncer::ROLLBACK_DONE: 1427 case syncer::ROLLBACK_DONE:
1428 backup_rollback_controller_.OnRollbackDone(); 1428 backup_rollback_controller_->OnRollbackDone();
1429 break; 1429 break;
1430 case syncer::STOP_SYNC_FOR_DISABLED_ACCOUNT: 1430 case syncer::STOP_SYNC_FOR_DISABLED_ACCOUNT:
1431 // Sync disabled by domain admin. we should stop syncing until next 1431 // Sync disabled by domain admin. we should stop syncing until next
1432 // restart. 1432 // restart.
1433 sync_disabled_by_admin_ = true; 1433 sync_disabled_by_admin_ = true;
1434 ShutdownImpl(syncer::DISABLE_SYNC); 1434 ShutdownImpl(syncer::DISABLE_SYNC);
1435 break; 1435 break;
1436 default: 1436 default:
1437 NOTREACHED(); 1437 NOTREACHED();
1438 } 1438 }
1439 NotifyObservers(); 1439 NotifyObservers();
1440 1440
1441 if (error.action == syncer::DISABLE_SYNC_ON_CLIENT || 1441 if (error.action == syncer::DISABLE_SYNC_ON_CLIENT ||
1442 (error.action == syncer::DISABLE_SYNC_AND_ROLLBACK && 1442 (error.action == syncer::DISABLE_SYNC_AND_ROLLBACK &&
1443 !backup_rollback_controller_.StartRollback())) { 1443 !backup_rollback_controller_->StartRollback())) {
1444 // Clean up backup data for sign-out only or when rollback is disabled. 1444 // Clean up backup data for sign-out only or when rollback is disabled.
1445 CleanUpBackup(); 1445 CleanUpBackup();
1446 } else if (error.action == syncer::ROLLBACK_DONE) { 1446 } else if (error.action == syncer::ROLLBACK_DONE) {
1447 // Shut down ROLLBACK backend and delete backup DB. 1447 // Shut down ROLLBACK backend and delete backup DB.
1448 ShutdownImpl(syncer::DISABLE_SYNC); 1448 ShutdownImpl(syncer::DISABLE_SYNC);
1449 sync_prefs_.ClearFirstSyncTime(); 1449 sync_prefs_.ClearFirstSyncTime();
1450 } 1450 }
1451 } 1451 }
1452 1452
1453 void ProfileSyncService::OnConfigureDone( 1453 void ProfileSyncService::OnConfigureDone(
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
1608 case BACKUP_USER_DATA: 1608 case BACKUP_USER_DATA:
1609 return "Backing-up user data. Status: " + config_status_str; 1609 return "Backing-up user data. Status: " + config_status_str;
1610 case ROLLBACK_USER_DATA: 1610 case ROLLBACK_USER_DATA:
1611 return "Restoring user data. Status: " + config_status_str; 1611 return "Restoring user data. Status: " + config_status_str;
1612 default: 1612 default:
1613 return "Status unknown: Internal error?"; 1613 return "Status unknown: Internal error?";
1614 } 1614 }
1615 } 1615 }
1616 1616
1617 std::string ProfileSyncService::GetBackendInitializationStateString() const { 1617 std::string ProfileSyncService::GetBackendInitializationStateString() const {
1618 return startup_controller_.GetBackendInitializationStateString(); 1618 return startup_controller_->GetBackendInitializationStateString();
1619 } 1619 }
1620 1620
1621 bool ProfileSyncService::auto_start_enabled() const { 1621 bool ProfileSyncService::auto_start_enabled() const {
1622 return startup_controller_.auto_start_enabled(); 1622 return startup_controller_->auto_start_enabled();
1623 } 1623 }
1624 1624
1625 bool ProfileSyncService::setup_in_progress() const { 1625 bool ProfileSyncService::setup_in_progress() const {
1626 return startup_controller_.setup_in_progress(); 1626 return startup_controller_->setup_in_progress();
1627 } 1627 }
1628 1628
1629 bool ProfileSyncService::QueryDetailedSyncStatus( 1629 bool ProfileSyncService::QueryDetailedSyncStatus(
1630 SyncBackendHost::Status* result) { 1630 SyncBackendHost::Status* result) {
1631 if (backend_.get() && backend_initialized_) { 1631 if (backend_.get() && backend_initialized_) {
1632 *result = backend_->GetDetailedStatus(); 1632 *result = backend_->GetDetailedStatus();
1633 return true; 1633 return true;
1634 } else { 1634 } else {
1635 SyncBackendHost::Status status; 1635 SyncBackendHost::Status status;
1636 status.sync_protocol_error = last_actionable_error_; 1636 status.sync_protocol_error = last_actionable_error_;
1637 *result = status; 1637 *result = status;
1638 return false; 1638 return false;
1639 } 1639 }
1640 } 1640 }
1641 1641
1642 const AuthError& ProfileSyncService::GetAuthError() const { 1642 const AuthError& ProfileSyncService::GetAuthError() const {
1643 return last_auth_error_; 1643 return last_auth_error_;
1644 } 1644 }
1645 1645
1646 bool ProfileSyncService::FirstSetupInProgress() const { 1646 bool ProfileSyncService::FirstSetupInProgress() const {
1647 return !HasSyncSetupCompleted() && startup_controller_.setup_in_progress(); 1647 return !HasSyncSetupCompleted() && startup_controller_->setup_in_progress();
1648 } 1648 }
1649 1649
1650 void ProfileSyncService::SetSetupInProgress(bool setup_in_progress) { 1650 void ProfileSyncService::SetSetupInProgress(bool setup_in_progress) {
1651 // This method is a no-op if |setup_in_progress_| remains unchanged. 1651 // This method is a no-op if |setup_in_progress_| remains unchanged.
1652 if (startup_controller_.setup_in_progress() == setup_in_progress) 1652 if (startup_controller_->setup_in_progress() == setup_in_progress)
1653 return; 1653 return;
1654 1654
1655 startup_controller_.set_setup_in_progress(setup_in_progress); 1655 startup_controller_->set_setup_in_progress(setup_in_progress);
1656 if (!setup_in_progress && backend_initialized()) 1656 if (!setup_in_progress && backend_initialized())
1657 ReconfigureDatatypeManager(); 1657 ReconfigureDatatypeManager();
1658 NotifyObservers(); 1658 NotifyObservers();
1659 } 1659 }
1660 1660
1661 bool ProfileSyncService::SyncActive() const { 1661 bool ProfileSyncService::SyncActive() const {
1662 return backend_initialized_ && backend_mode_ == SYNC && 1662 return backend_initialized_ && backend_mode_ == SYNC &&
1663 directory_data_type_manager_ && 1663 directory_data_type_manager_ &&
1664 directory_data_type_manager_->state() != DataTypeManager::STOPPED; 1664 directory_data_type_manager_->state() != DataTypeManager::STOPPED;
1665 } 1665 }
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
1912 directory_data_type_manager_->Configure(priority_types, reason); 1912 directory_data_type_manager_->Configure(priority_types, reason);
1913 } 1913 }
1914 } 1914 }
1915 1915
1916 void ProfileSyncService::ConfigureDataTypeManager() { 1916 void ProfileSyncService::ConfigureDataTypeManager() {
1917 // Don't configure datatypes if the setup UI is still on the screen - this 1917 // Don't configure datatypes if the setup UI is still on the screen - this
1918 // is to help multi-screen setting UIs (like iOS) where they don't want to 1918 // is to help multi-screen setting UIs (like iOS) where they don't want to
1919 // start syncing data until the user is done configuring encryption options, 1919 // start syncing data until the user is done configuring encryption options,
1920 // etc. ReconfigureDatatypeManager() will get called again once the UI calls 1920 // etc. ReconfigureDatatypeManager() will get called again once the UI calls
1921 // SetSetupInProgress(false). 1921 // SetSetupInProgress(false).
1922 if (backend_mode_ == SYNC && startup_controller_.setup_in_progress()) 1922 if (backend_mode_ == SYNC && startup_controller_->setup_in_progress())
1923 return; 1923 return;
1924 1924
1925 bool restart = false; 1925 bool restart = false;
1926 if (!directory_data_type_manager_) { 1926 if (!directory_data_type_manager_) {
1927 restart = true; 1927 restart = true;
1928 directory_data_type_manager_.reset( 1928 directory_data_type_manager_.reset(
1929 factory_->CreateDataTypeManager(debug_info_listener_, 1929 factory_->CreateDataTypeManager(debug_info_listener_,
1930 &directory_data_type_controllers_, 1930 &directory_data_type_controllers_,
1931 this, 1931 this,
1932 backend_.get(), 1932 backend_.get(),
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
2233 // We may be called during the setup process before we're 2233 // We may be called during the setup process before we're
2234 // initialized. In this case, we default to the sensitive types. 2234 // initialized. In this case, we default to the sensitive types.
2235 return encrypted_types_; 2235 return encrypted_types_;
2236 } 2236 }
2237 2237
2238 void ProfileSyncService::OnSyncManagedPrefChange(bool is_sync_managed) { 2238 void ProfileSyncService::OnSyncManagedPrefChange(bool is_sync_managed) {
2239 if (is_sync_managed) { 2239 if (is_sync_managed) {
2240 DisableForUser(); 2240 DisableForUser();
2241 } else { 2241 } else {
2242 // Sync is no longer disabled by policy. Try starting it up if appropriate. 2242 // Sync is no longer disabled by policy. Try starting it up if appropriate.
2243 startup_controller_.TryStart(); 2243 startup_controller_->TryStart();
2244 } 2244 }
2245 } 2245 }
2246 2246
2247 void ProfileSyncService::GoogleSigninSucceeded(const std::string& account_id, 2247 void ProfileSyncService::GoogleSigninSucceeded(const std::string& account_id,
2248 const std::string& username, 2248 const std::string& username,
2249 const std::string& password) { 2249 const std::string& password) {
2250 if (!sync_prefs_.IsStartSuppressed() && !password.empty()) { 2250 if (!sync_prefs_.IsStartSuppressed() && !password.empty()) {
2251 cached_passphrase_ = password; 2251 cached_passphrase_ = password;
2252 // Try to consume the passphrase we just cached. If the sync backend 2252 // Try to consume the passphrase we just cached. If the sync backend
2253 // is not running yet, the passphrase will remain cached until the 2253 // is not running yet, the passphrase will remain cached until the
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
2475 SigninManagerBase* ProfileSyncService::signin() const { 2475 SigninManagerBase* ProfileSyncService::signin() const {
2476 if (!signin_) 2476 if (!signin_)
2477 return NULL; 2477 return NULL;
2478 return signin_->GetOriginal(); 2478 return signin_->GetOriginal();
2479 } 2479 }
2480 2480
2481 void ProfileSyncService::UnsuppressAndStart() { 2481 void ProfileSyncService::UnsuppressAndStart() {
2482 DCHECK(profile_); 2482 DCHECK(profile_);
2483 sync_prefs_.SetStartSuppressed(false); 2483 sync_prefs_.SetStartSuppressed(false);
2484 DCHECK(!signin_.get() || signin_->GetOriginal()->IsAuthenticated()); 2484 DCHECK(!signin_.get() || signin_->GetOriginal()->IsAuthenticated());
2485 startup_controller_.TryStart(); 2485 startup_controller_->TryStart();
2486 } 2486 }
2487 2487
2488 void ProfileSyncService::AcknowledgeSyncedTypes() { 2488 void ProfileSyncService::AcknowledgeSyncedTypes() {
2489 sync_prefs_.AcknowledgeSyncedTypes(GetRegisteredDataTypes()); 2489 sync_prefs_.AcknowledgeSyncedTypes(GetRegisteredDataTypes());
2490 } 2490 }
2491 2491
2492 void ProfileSyncService::ReconfigureDatatypeManager() { 2492 void ProfileSyncService::ReconfigureDatatypeManager() {
2493 // If we haven't initialized yet, don't configure the DTM as it could cause 2493 // If we haven't initialized yet, don't configure the DTM as it could cause
2494 // association to start before a Directory has even been created. 2494 // association to start before a Directory has even been created.
2495 if (backend_initialized_) { 2495 if (backend_initialized_) {
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
2698 } 2698 }
2699 2699
2700 void ProfileSyncService::CheckSyncBackupCallback(base::Time backup_time) { 2700 void ProfileSyncService::CheckSyncBackupCallback(base::Time backup_time) {
2701 last_backup_time_.reset(new base::Time(backup_time)); 2701 last_backup_time_.reset(new base::Time(backup_time));
2702 2702
2703 DCHECK(device_info_sync_service_); 2703 DCHECK(device_info_sync_service_);
2704 device_info_sync_service_->UpdateLocalDeviceBackupTime(*last_backup_time_); 2704 device_info_sync_service_->UpdateLocalDeviceBackupTime(*last_backup_time_);
2705 } 2705 }
2706 2706
2707 void ProfileSyncService::TryStartSyncAfterBackup() { 2707 void ProfileSyncService::TryStartSyncAfterBackup() {
2708 startup_controller_.Reset(GetRegisteredDataTypes()); 2708 startup_controller_->Reset(GetRegisteredDataTypes());
2709 startup_controller_.TryStart(); 2709 startup_controller_->TryStart();
2710 } 2710 }
2711 2711
2712 void ProfileSyncService::CleanUpBackup() { 2712 void ProfileSyncService::CleanUpBackup() {
2713 sync_prefs_.ClearFirstSyncTime(); 2713 sync_prefs_.ClearFirstSyncTime();
2714 profile_->GetIOTaskRunner()->PostTask( 2714 profile_->GetIOTaskRunner()->PostTask(
2715 FROM_HERE, 2715 FROM_HERE,
2716 base::Bind(base::IgnoreResult(base::DeleteFile), 2716 base::Bind(base::IgnoreResult(base::DeleteFile),
2717 profile_->GetPath().Append(kSyncBackupDataFolderName), 2717 profile_->GetPath().Append(kSyncBackupDataFolderName),
2718 true)); 2718 true));
2719 } 2719 }
(...skipping 19 matching lines...) Expand all
2739 2739
2740 base::MessageLoop* ProfileSyncService::GetSyncLoopForTest() const { 2740 base::MessageLoop* ProfileSyncService::GetSyncLoopForTest() const {
2741 if (sync_thread_) { 2741 if (sync_thread_) {
2742 return sync_thread_->message_loop(); 2742 return sync_thread_->message_loop();
2743 } else if (backend_) { 2743 } else if (backend_) {
2744 return backend_->GetSyncLoopForTesting(); 2744 return backend_->GetSyncLoopForTesting();
2745 } else { 2745 } else {
2746 return NULL; 2746 return NULL;
2747 } 2747 }
2748 } 2748 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/profile_sync_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698