diff options
author | nyquist@chromium.org <nyquist@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-01 19:15:29 +0000 |
---|---|---|
committer | nyquist@chromium.org <nyquist@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-01 19:15:29 +0000 |
commit | bee0beba31f00847a1b34a68b98a44ead75f6cbc (patch) | |
tree | 89d1d73f7615525ebcf55afb1419a3990bbdafdd /chrome | |
parent | ff3cad1f41f0d04322e00475e63ea5b6e523cb3b (diff) | |
download | chromium_src-bee0beba31f00847a1b34a68b98a44ead75f6cbc.zip chromium_src-bee0beba31f00847a1b34a68b98a44ead75f6cbc.tar.gz chromium_src-bee0beba31f00847a1b34a68b98a44ead75f6cbc.tar.bz2 |
Add support for temporarily disabling sync.
Adds functionality to the ProfileSyncService to temporarily disable
sync and later be able to enable it again.
This is achieved by stopping the sync backend and suppressing future
startups when sync is disabled. The flag for suppressing startup is
removed when enabling sync again, and the sync backend is started.
Contributed by nyquist@chromium.org
TEST=unit_tests
Review URL: http://codereview.chromium.org/8332023
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@108148 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/sync/profile_sync_service.cc | 39 | ||||
-rw-r--r-- | chrome/browser/sync/profile_sync_service.h | 10 | ||||
-rw-r--r-- | chrome/browser/sync/profile_sync_service_unittest.cc | 25 | ||||
-rw-r--r-- | chrome/browser/sync/sync_prefs.cc | 7 | ||||
-rw-r--r-- | chrome/browser/sync/sync_prefs.h | 2 |
5 files changed, 72 insertions, 11 deletions
diff --git a/chrome/browser/sync/profile_sync_service.cc b/chrome/browser/sync/profile_sync_service.cc index de7e1c7..a94366e 100644 --- a/chrome/browser/sync/profile_sync_service.cc +++ b/chrome/browser/sync/profile_sync_service.cc @@ -188,19 +188,20 @@ void ProfileSyncService::Initialize() { signin_->Initialize(profile_); } - if (!HasSyncSetupCompleted()) { - // If autostart is enabled, but we haven't completed sync setup, try to - // start sync anyway (it's possible we crashed/shutdown after logging in - // but before the backend finished initializing the last time). - if (auto_start_enabled_ && !sync_prefs_.IsStartSuppressed() && - AreCredentialsAvailable()) { + TryStart(); +} + +void ProfileSyncService::TryStart() { + if (!sync_prefs_.IsStartSuppressed() && AreCredentialsAvailable()) { + if (HasSyncSetupCompleted() || auto_start_enabled_) { + // If sync setup has completed we always start the backend. + // If autostart is enabled, but we haven't completed sync setup, we try to + // start sync anyway, since it's possible we crashed/shutdown after + // logging in but before the backend finished initializing the last time. + // Note that if we haven't finished setting up sync, backend bring up will + // be done by the wizard. StartUp(); } - } else if (AreCredentialsAvailable()) { - // If we have credentials and sync setup finished, autostart the backend. - // Note that if we haven't finished setting up sync, backend bring up will - // be done by the wizard. - StartUp(); } } @@ -1518,6 +1519,22 @@ bool ProfileSyncService::ShouldPushChanges() { return data_type_manager_->state() == DataTypeManager::CONFIGURED; } +void ProfileSyncService::StopAndSuppress() { + sync_prefs_.SetStartSuppressed(true); + Shutdown(false); +} + +void ProfileSyncService::UnsuppressAndStart() { + DCHECK(profile_); + sync_prefs_.SetStartSuppressed(false); + // Set username in SigninManager, as SigninManager::OnGetUserInfoSuccess + // is never called for some clients. + if (signin_->GetUsername().empty()) { + signin_->SetUsername(sync_prefs_.GetGoogleServicesUsername()); + } + TryStart(); +} + void ProfileSyncService::AcknowledgeSyncedTypes() { syncable::ModelTypeSet registered_types; GetRegisteredDataTypes(®istered_types); diff --git a/chrome/browser/sync/profile_sync_service.h b/chrome/browser/sync/profile_sync_service.h index 3405764..d160916 100644 --- a/chrome/browser/sync/profile_sync_service.h +++ b/chrome/browser/sync/profile_sync_service.h @@ -481,6 +481,12 @@ class ProfileSyncService : public browser_sync::SyncFrontend, const std::string& cros_user() const { return cros_user_; } bool auto_start_enabled() const { return auto_start_enabled_; } + // Stops the sync backend and sets the flag for suppressing sync startup. + void StopAndSuppress(); + + // Resets the flag for suppressing sync startup and starts the sync backend. + void UnsuppressAndStart(); + // Marks all currently registered types as "acknowledged" so we won't prompt // the user about them any more. void AcknowledgeSyncedTypes(); @@ -542,6 +548,10 @@ class ProfileSyncService : public browser_sync::SyncFrontend, friend class ProfileSyncServiceForWizardTest; FRIEND_TEST_ALL_PREFIXES(ProfileSyncServiceTest, InitialState); + // Starts up sync if it is not suppressed and preconditions are met. + // Called from Initialize() and UnsuppressAndStart(). + void TryStart(); + // Called when we've determined that we don't need a passphrase (either // because OnPassphraseAccepted() was called, or because we've gotten a // OnPassphraseRequired() but no data types are enabled). diff --git a/chrome/browser/sync/profile_sync_service_unittest.cc b/chrome/browser/sync/profile_sync_service_unittest.cc index e42a1b2e..e90a0e8 100644 --- a/chrome/browser/sync/profile_sync_service_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_unittest.cc @@ -155,6 +155,31 @@ TEST_F(ProfileSyncServiceTest, AbortedByShutdown) { service_.reset(); } +TEST_F(ProfileSyncServiceTest, DisableAndEnableSyncTemporarily) { + service_.reset(new TestProfileSyncService(&factory_, + profile_.get(), + "test", true, NULL)); + // Register the bookmark data type. + EXPECT_CALL(factory_, CreateDataTypeManager(_, _)). + WillRepeatedly(ReturnNewDataTypeManager()); + + profile_->GetTokenService()->IssueAuthTokenForTest( + GaiaConstants::kSyncService, "token"); + + service_->Initialize(); + EXPECT_TRUE(service_->sync_initialized()); + EXPECT_TRUE(service_->GetBackendForTest() != NULL); + EXPECT_FALSE(profile_->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart)); + + service_->StopAndSuppress(); + EXPECT_FALSE(service_->sync_initialized()); + EXPECT_TRUE(profile_->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart)); + + service_->UnsuppressAndStart(); + EXPECT_TRUE(service_->sync_initialized()); + EXPECT_FALSE(profile_->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart)); +} + TEST_F(ProfileSyncServiceTest, JsControllerHandlersBasic) { StartSyncService(); EXPECT_TRUE(service_->sync_initialized()); diff --git a/chrome/browser/sync/sync_prefs.cc b/chrome/browser/sync/sync_prefs.cc index 8987900..65c28f3 100644 --- a/chrome/browser/sync/sync_prefs.cc +++ b/chrome/browser/sync/sync_prefs.cc @@ -86,6 +86,13 @@ void SyncPrefs::SetStartSuppressed(bool is_suppressed) { pref_service_->ScheduleSavePersistentPrefs(); } +std::string SyncPrefs::GetGoogleServicesUsername() const { + DCHECK(non_thread_safe_.CalledOnValidThread()); + return + pref_service_ ? + pref_service_->GetString(prefs::kGoogleServicesUsername) : ""; +} + base::Time SyncPrefs::GetLastSyncedTime() const { DCHECK(non_thread_safe_.CalledOnValidThread()); return diff --git a/chrome/browser/sync/sync_prefs.h b/chrome/browser/sync/sync_prefs.h index 38b05c3..460633a 100644 --- a/chrome/browser/sync/sync_prefs.h +++ b/chrome/browser/sync/sync_prefs.h @@ -69,6 +69,8 @@ class SyncPrefs : public base::SupportsWeakPtr<SyncPrefs>, bool IsStartSuppressed() const; void SetStartSuppressed(bool is_suppressed); + std::string GetGoogleServicesUsername() const; + base::Time GetLastSyncedTime() const; void SetLastSyncedTime(base::Time time); |