diff options
| author | zea <zea@chromium.org> | 2016-02-24 12:41:48 -0800 |
|---|---|---|
| committer | Commit bot <commit-bot@chromium.org> | 2016-02-24 20:42:45 +0000 |
| commit | 32a7684cf7c1173c11ab012591c8cca2d31df52a (patch) | |
| tree | 7901fd9480b2114ddbb8fed5e48ef61ddaf9bd4f | |
| parent | a03e8479b8c2e203d7306817d2f1330132000d8f (diff) | |
| download | chromium_src-32a7684cf7c1173c11ab012591c8cca2d31df52a.zip chromium_src-32a7684cf7c1173c11ab012591c8cca2d31df52a.tar.gz chromium_src-32a7684cf7c1173c11ab012591c8cca2d31df52a.tar.bz2 | |
[Sync] Remove backup/rollback logic from Sync
BUG=586596
Review URL: https://codereview.chromium.org/1703173002
Cr-Commit-Position: refs/heads/master@{#377370}
79 files changed, 68 insertions, 3483 deletions
diff --git a/chrome/browser/prefs/chrome_pref_service_factory.cc b/chrome/browser/prefs/chrome_pref_service_factory.cc index 15539f8..2472dee 100644 --- a/chrome/browser/prefs/chrome_pref_service_factory.cc +++ b/chrome/browser/prefs/chrome_pref_service_factory.cc @@ -193,12 +193,8 @@ const PrefHashFilter::TrackedPreferenceMetadata kTrackedPrefs[] = { PrefHashFilter::TRACKING_STRATEGY_ATOMIC, PrefHashFilter::VALUE_IMPERSONAL }, - { - 17, sync_driver::prefs::kSyncRemainingRollbackTries, - PrefHashFilter::ENFORCE_ON_LOAD, - PrefHashFilter::TRACKING_STRATEGY_ATOMIC, - PrefHashFilter::VALUE_IMPERSONAL - }, + // kSyncRemainingRollbackTries is deprecated and will be removed a few + // releases after M50. { 18, prefs::kSafeBrowsingIncidentsSent, PrefHashFilter::ENFORCE_ON_LOAD, diff --git a/chrome/browser/supervised_user/supervised_user_service.cc b/chrome/browser/supervised_user/supervised_user_service.cc index c0f01fb..260752f 100644 --- a/chrome/browser/supervised_user/supervised_user_service.cc +++ b/chrome/browser/supervised_user/supervised_user_service.cc @@ -674,8 +674,7 @@ void SupervisedUserService::FinishSetupSyncWhenReady() { // Continue in FinishSetupSync() once the Sync backend has been initialized. ProfileSyncService* service = ProfileSyncServiceFactory::GetForProfile(profile_); - if (service->IsBackendInitialized() && - service->backend_mode() == ProfileSyncService::SYNC) { + if (service->IsBackendInitialized()) { FinishSetupSync(); } else { service->AddObserver(this); @@ -687,7 +686,6 @@ void SupervisedUserService::FinishSetupSync() { ProfileSyncService* service = ProfileSyncServiceFactory::GetForProfile(profile_); DCHECK(service->IsBackendInitialized()); - DCHECK(service->backend_mode() == ProfileSyncService::SYNC); // Sync nothing (except types which are set via GetPreferredDataTypes). bool sync_everything = false; @@ -1023,8 +1021,7 @@ syncer::ModelTypeSet SupervisedUserService::GetPreferredDataTypes() const { void SupervisedUserService::OnStateChanged() { ProfileSyncService* service = ProfileSyncServiceFactory::GetForProfile(profile_); - if (waiting_for_sync_initialization_ && service->IsBackendInitialized() && - service->backend_mode() == ProfileSyncService::SYNC) { + if (waiting_for_sync_initialization_ && service->IsBackendInitialized()) { waiting_for_sync_initialization_ = false; service->RemoveObserver(this); FinishSetupSync(); diff --git a/chrome/browser/sync/chrome_sync_client.cc b/chrome/browser/sync/chrome_sync_client.cc index 661ca35..0327706 100644 --- a/chrome/browser/sync/chrome_sync_client.cc +++ b/chrome/browser/sync/chrome_sync_client.cc @@ -12,8 +12,6 @@ #include "build/build_config.h" #include "chrome/browser/autofill/personal_data_manager_factory.h" #include "chrome/browser/bookmarks/bookmark_model_factory.h" -#include "chrome/browser/browsing_data/browsing_data_helper.h" -#include "chrome/browser/browsing_data/browsing_data_remover_factory.h" #include "chrome/browser/dom_distiller/dom_distiller_service_factory.h" #include "chrome/browser/favicon/favicon_service_factory.h" #include "chrome/browser/history/history_service_factory.h" @@ -248,12 +246,6 @@ autofill::PersonalDataManager* ChromeSyncClient::GetPersonalDataManager() { return autofill::PersonalDataManagerFactory::GetForProfile(profile_); } -sync_driver::ClearBrowsingDataCallback -ChromeSyncClient::GetClearBrowsingDataCallback() { - return base::Bind(&ChromeSyncClient::ClearBrowsingData, - base::Unretained(this)); -} - base::Closure ChromeSyncClient::GetPasswordStateChangedCallback() { return base::Bind( &PasswordStoreFactory::OnPasswordsSyncedStatePotentiallyChanged, @@ -484,28 +476,6 @@ ChromeSyncClient::GetSyncApiComponentFactory() { return component_factory_.get(); } -void ChromeSyncClient::ClearBrowsingData(base::Time start, base::Time end) { - BrowsingDataRemover* remover = - BrowsingDataRemoverFactory::GetForBrowserContext(profile_); - remover->Remove(BrowsingDataRemover::TimeRange(start, end), - BrowsingDataRemover::REMOVE_ALL, BrowsingDataHelper::ALL); - - password_store_->RemoveLoginsSyncedBetween(start, end); -} - -void ChromeSyncClient::SetBrowsingDataRemoverObserverForTesting( - BrowsingDataRemover::Observer* observer) { - BrowsingDataRemover* remover = - BrowsingDataRemoverFactory::GetForBrowserContext(profile_); - if (browsing_data_remover_observer_) - remover->RemoveObserver(browsing_data_remover_observer_); - - if (observer) - remover->AddObserver(observer); - - browsing_data_remover_observer_ = observer; -} - void ChromeSyncClient::SetSyncApiComponentFactoryForTesting( scoped_ptr<sync_driver::SyncApiComponentFactory> component_factory) { component_factory_ = std::move(component_factory); diff --git a/chrome/browser/sync/chrome_sync_client.h b/chrome/browser/sync/chrome_sync_client.h index 4e58821..f94c669 100644 --- a/chrome/browser/sync/chrome_sync_client.h +++ b/chrome/browser/sync/chrome_sync_client.h @@ -39,8 +39,6 @@ class ChromeSyncClient : public sync_driver::SyncClient { bookmarks::BookmarkModel* GetBookmarkModel() override; favicon::FaviconService* GetFaviconService() override; history::HistoryService* GetHistoryService() override; - sync_driver::ClearBrowsingDataCallback GetClearBrowsingDataCallback() - override; base::Closure GetPasswordStateChangedCallback() override; sync_driver::SyncApiComponentFactory::RegisterDataTypesMethod GetRegisterPlatformTypesCallback() override; @@ -79,8 +77,6 @@ class ChromeSyncClient : public sync_driver::SyncClient { syncer::ModelTypeSet disabled_types, syncer::ModelTypeSet enabled_types); - void ClearBrowsingData(base::Time start, base::Time end); - Profile* const profile_; // The sync api component factory in use by this client. diff --git a/chrome/browser/sync/test/integration/profile_sync_service_harness.cc b/chrome/browser/sync/test/integration/profile_sync_service_harness.cc index f285656..7cf94c8 100644 --- a/chrome/browser/sync/test/integration/profile_sync_service_harness.cc +++ b/chrome/browser/sync/test/integration/profile_sync_service_harness.cc @@ -56,8 +56,6 @@ class BackendInitializeChecker : public SingleClientStatusChangeChecker { : SingleClientStatusChangeChecker(service) {} bool IsExitConditionSatisfied() override { - if (service()->backend_mode() != ProfileSyncService::SYNC) - return false; if (service()->IsBackendInitialized()) return true; // Backend initialization is blocked by an auth error. diff --git a/chrome/browser/sync/test/integration/single_client_backup_rollback_test.cc b/chrome/browser/sync/test/integration/single_client_backup_rollback_test.cc deleted file mode 100644 index 90f7841..0000000 --- a/chrome/browser/sync/test/integration/single_client_backup_rollback_test.cc +++ /dev/null @@ -1,451 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/command_line.h" -#include "base/files/file_util.h" -#include "base/location.h" -#include "base/macros.h" -#include "base/run_loop.h" -#include "base/single_thread_task_runner.h" -#include "base/test/test_timeouts.h" -#include "base/thread_task_runner_handle.h" -#include "chrome/browser/browsing_data/browsing_data_remover.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/sync/chrome_sync_client.h" -#include "chrome/browser/sync/test/integration/bookmarks_helper.h" -#include "chrome/browser/sync/test/integration/preferences_helper.h" -#include "chrome/browser/sync/test/integration/sync_integration_test_util.h" -#include "chrome/browser/sync/test/integration/sync_test.h" -#include "components/bookmarks/browser/bookmark_model.h" -#include "components/browser_sync/browser/profile_sync_service.h" -#include "components/prefs/pref_service.h" -#include "components/sync_driver/sync_driver_features.h" -#include "components/sync_driver/sync_driver_switches.h" -#include "sync/internal_api/public/util/sync_db_util.h" -#include "sync/test/fake_server/fake_server_verifier.h" -#include "sync/util/time.h" - -using bookmarks::BookmarkNode; -using bookmarks_helper::AddFolder; -using bookmarks_helper::AddURL; -using bookmarks_helper::GetOtherNode; -using bookmarks_helper::ModelMatchesVerifier; -using bookmarks_helper::Move; -using bookmarks_helper::Remove; -using sync_integration_test_util::AwaitCommitActivityCompletion; - -namespace { -const char kUrl1[] = "http://www.google.com"; -const char kUrl2[] = "http://map.google.com"; -const char kUrl3[] = "http://plus.google.com"; -} // anonymous namespace - -class SingleClientBackupRollbackTest : public SyncTest { - public: - SingleClientBackupRollbackTest() : SyncTest(SINGLE_CLIENT) {} - ~SingleClientBackupRollbackTest() override {} - - void DisableBackup() { - base::CommandLine::ForCurrentProcess()->AppendSwitch( - switches::kSyncDisableBackup); - } - - void DisableRollback() { - base::CommandLine::ForCurrentProcess()->AppendSwitch( - switches::kSyncDisableRollback); - } - - base::Time GetBackupDbLastModified() { - base::RunLoop run_loop; - - base::Time backup_time; - syncer::CheckSyncDbLastModifiedTime( - GetProfile(0)->GetPath().Append(FILE_PATH_LITERAL("Sync Data Backup")), - base::ThreadTaskRunnerHandle::Get(), - base::Bind(&SingleClientBackupRollbackTest::CheckDbCallback, - base::Unretained(this), &backup_time)); - base::ThreadTaskRunnerHandle::Get()->PostTask( - FROM_HERE, run_loop.QuitClosure()); - run_loop.Run(); - return backup_time; - } - - private: - void CheckDbCallback(base::Time* time_out, base::Time time_in) { - *time_out = syncer::ProtoTimeToTime(syncer::TimeToProtoTime(time_in)); - } - - DISALLOW_COPY_AND_ASSIGN(SingleClientBackupRollbackTest); -}; - -// Waits until the ProfileSyncService's backend is in IDLE mode. -class SyncBackendStoppedChecker : public sync_driver::SyncServiceObserver { - public: - explicit SyncBackendStoppedChecker(ProfileSyncService* service) - : pss_(service), - timeout_(TestTimeouts::action_max_timeout()), - done_(false) {} - - void OnStateChanged() override { - if (ProfileSyncService::IDLE == pss_->backend_mode()) { - done_ = true; - run_loop_.Quit(); - } - } - - bool Wait() { - pss_->AddObserver(this); - if (ProfileSyncService::IDLE == pss_->backend_mode()) - return true; - base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( - FROM_HERE, run_loop_.QuitClosure(), timeout_); - run_loop_.Run(); - pss_->RemoveObserver(this); - return done_; - } - - private: - - ProfileSyncService* const pss_; - const base::TimeDelta timeout_; - base::RunLoop run_loop_; - bool done_; -}; - -// Waits until a rollback finishes. -class SyncRollbackChecker : public sync_driver::SyncServiceObserver, - public BrowsingDataRemover::Observer { - public: - explicit SyncRollbackChecker(ProfileSyncService* service) - : pss_(service), - timeout_(TestTimeouts::action_max_timeout()), - rollback_started_(false), - clear_done_(false) {} - - // sync_driver::SyncServiceObserver implementation. - void OnStateChanged() override { - if (ProfileSyncService::ROLLBACK == pss_->backend_mode()) { - rollback_started_ = true; - if (clear_done_) - run_loop_.Quit(); - } - } - - // BrowsingDataRemoverObserver::Observer implementation. - void OnBrowsingDataRemoverDone() override { - // Remove ourselves as an observer. - browser_sync::ChromeSyncClient* sync_client = - static_cast<browser_sync::ChromeSyncClient*>(pss_->GetSyncClient()); - sync_client->SetBrowsingDataRemoverObserverForTesting(nullptr); - - clear_done_ = true; - if (rollback_started_) { - run_loop_.Quit(); - } - } - - bool Wait() { - pss_->AddObserver(this); - - browser_sync::ChromeSyncClient* sync_client = - static_cast<browser_sync::ChromeSyncClient*>(pss_->GetSyncClient()); - sync_client->SetBrowsingDataRemoverObserverForTesting(this); - base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( - FROM_HERE, run_loop_.QuitClosure(), timeout_); - run_loop_.Run(); - pss_->RemoveObserver(this); - return rollback_started_ && clear_done_; - } - - ProfileSyncService* const pss_; - const base::TimeDelta timeout_; - base::RunLoop run_loop_; - bool rollback_started_; - bool clear_done_; -}; - -#if BUILDFLAG(ENABLE_PRE_SYNC_BACKUP) -#define MAYBE_TestBackup TestBackup -#else -#define MAYBE_TestBackup DISABLED_TestBackup -#endif -IN_PROC_BROWSER_TEST_F(SingleClientBackupRollbackTest, - MAYBE_TestBackup) { - ASSERT_TRUE(SetupClients()) << "SetupClients() failed."; - - // Setup sync, wait for its completion, and make sure changes were synced. - ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; - ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService(0))); - ASSERT_TRUE(ModelMatchesVerifier(0)); - - // Verify backup DB is created and backup time is set on device info. - base::Time backup_time = GetBackupDbLastModified(); - ASSERT_FALSE(backup_time.is_null()); - ASSERT_EQ(backup_time, GetSyncService(0)->GetDeviceBackupTimeForTesting()); -} - -#if BUILDFLAG(ENABLE_PRE_SYNC_BACKUP) -#define MAYBE_TestBackupDisabled TestBackupDisabled -#else -#define MAYBE_TestBackupDisabled DISABLED_TestBackupDisabled -#endif -IN_PROC_BROWSER_TEST_F(SingleClientBackupRollbackTest, - MAYBE_TestBackupDisabled) { - DisableBackup(); - - // Setup sync, wait for its completion, and make sure changes were synced. - ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; - ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService(0))); - ASSERT_TRUE(ModelMatchesVerifier(0)); - - // Verify backup DB is not created and backup time is not set on device info. - ASSERT_FALSE(base::PathExists( - GetProfile(0)->GetPath().Append(FILE_PATH_LITERAL("Sync Data Backup")))); - ASSERT_TRUE(GetSyncService(0)->GetDeviceBackupTimeForTesting().is_null()); -} - -#if BUILDFLAG(ENABLE_PRE_SYNC_BACKUP) -#define MAYBE_TestRollback TestRollback -#else -#define MAYBE_TestRollback DISABLED_TestRollback -#endif -IN_PROC_BROWSER_TEST_F(SingleClientBackupRollbackTest, - MAYBE_TestRollback) { - ASSERT_TRUE(SetupClients()) << "SetupClients() failed."; - - // Starting state: - // other_node - // -> top - // -> tier1_a - // -> http://mail.google.com "tier1_a_url0" - // -> tier1_b - // -> http://www.nhl.com "tier1_b_url0" - const BookmarkNode* top = AddFolder(0, GetOtherNode(0), 0, "top"); - const BookmarkNode* tier1_a = AddFolder(0, top, 0, "tier1_a"); - const BookmarkNode* tier1_b = AddFolder(0, top, 1, "tier1_b"); - ASSERT_TRUE(AddURL(0, tier1_a, 0, "tier1_a_url0", - GURL("http://mail.google.com"))); - ASSERT_TRUE(AddURL(0, tier1_b, 0, "tier1_b_url0", - GURL("http://www.nhl.com"))); - - // Setup sync, wait for its completion, and make sure changes were synced. - ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; - ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService(0))); - ASSERT_TRUE(ModelMatchesVerifier(0)); - - // Made bookmark changes while sync is on. - Move(0, tier1_a->GetChild(0), tier1_b, 1); - Remove(0, tier1_b, 0); - ASSERT_TRUE(AddFolder(0, tier1_b, 1, "tier2_c")); - ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService(0))); - ASSERT_TRUE(ModelMatchesVerifier(0)); - - // Let server to return rollback command on next sync request. - ASSERT_TRUE(GetFakeServer()->TriggerError(sync_pb::SyncEnums::USER_ROLLBACK)); - - // Make another change to trigger downloading of rollback command. - Remove(0, tier1_b, 0); - - // Wait for rollback to finish and sync backend is completely shut down. - SyncRollbackChecker rollback_checker(GetSyncService(0)); - ASSERT_TRUE(rollback_checker.Wait()); - SyncBackendStoppedChecker shutdown_checker(GetSyncService(0)); - ASSERT_TRUE(shutdown_checker.Wait()); - - // Verify bookmarks are restored. - ASSERT_EQ(1, tier1_a->child_count()); - const BookmarkNode* url1 = tier1_a->GetChild(0); - ASSERT_EQ(GURL("http://mail.google.com"), url1->url()); - - ASSERT_EQ(1, tier1_b->child_count()); - const BookmarkNode* url2 = tier1_b->GetChild(0); - ASSERT_EQ(GURL("http://www.nhl.com"), url2->url()); -} - -#if BUILDFLAG(ENABLE_PRE_SYNC_BACKUP) -#define MAYBE_TestRollbackDisabled TestRollbackDisabled -#else -#define MAYBE_TestRollbackDisabled DISABLED_TestRollbackDisabled -#endif -IN_PROC_BROWSER_TEST_F(SingleClientBackupRollbackTest, - MAYBE_TestRollbackDisabled) { - DisableRollback(); - - ASSERT_TRUE(SetupClients()) << "SetupClients() failed."; - - // Starting state: - // other_node - // -> http://mail.google.com "url0" - // -> http://www.nhl.com "url1" - ASSERT_TRUE(AddURL(0, GetOtherNode(0), 0, "url0", - GURL("http://mail.google.com"))); - ASSERT_TRUE(AddURL(0, GetOtherNode(0), 1, "url1", - GURL("http://www.nhl.com"))); - - // Setup sync, wait for its completion, and make sure changes were synced. - ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; - ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService(0))); - ASSERT_TRUE(ModelMatchesVerifier(0)); - - // Made bookmark changes while sync is on. - Remove(0, GetOtherNode(0), 1); - ASSERT_TRUE(AddURL(0, GetOtherNode(0), 1, "url2", - GURL("http://www.yahoo.com"))); - ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0)))); - ASSERT_TRUE(ModelMatchesVerifier(0)); - - // Let server to return rollback command on next sync request. - ASSERT_TRUE(GetFakeServer()->TriggerError(sync_pb::SyncEnums::USER_ROLLBACK)); - - // Make another change to trigger downloading of rollback command. - Remove(0, GetOtherNode(0), 0); - - // Wait for sync backend is completely shut down. - SyncBackendStoppedChecker shutdown_checker(GetSyncService(0)); - ASSERT_TRUE(shutdown_checker.Wait()); - - // With rollback disabled, bookmarks in backup DB should not be restored. - // Only bookmark added during sync is present. - ASSERT_EQ(1, GetOtherNode(0)->child_count()); - ASSERT_EQ(GURL("http://www.yahoo.com"), - GetOtherNode(0)->GetChild(0)->url()); -} - -#if BUILDFLAG(ENABLE_PRE_SYNC_BACKUP) -#define MAYBE_TestSyncDisabled TestSyncDisabled -#else -#define MAYBE_TestSyncDisabled DISABLED_TestSyncDisabled -#endif -IN_PROC_BROWSER_TEST_F(SingleClientBackupRollbackTest, - MAYBE_TestSyncDisabled) { - ASSERT_TRUE(SetupClients()) << "SetupClients() failed."; - - // Starting state: - // other_node - // -> http://mail.google.com "url0" - // -> http://www.nhl.com "url1" - ASSERT_TRUE(AddURL(0, GetOtherNode(0), 0, "url0", - GURL("http://mail.google.com"))); - ASSERT_TRUE(AddURL(0, GetOtherNode(0), 1, "url1", - GURL("http://www.nhl.com"))); - - // Setup sync, wait for its completion, and make sure changes were synced. - ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; - ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService(0))); - ASSERT_TRUE(ModelMatchesVerifier(0)); - - // Made bookmark changes while sync is on. - Remove(0, GetOtherNode(0), 1); - ASSERT_TRUE(AddURL(0, GetOtherNode(0), 1, "url2", - GURL("http://www.yahoo.com"))); - ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0)))); - ASSERT_TRUE(ModelMatchesVerifier(0)); - - // Let server to return birthday error on next sync request. - ASSERT_TRUE(GetFakeServer()->TriggerError( - sync_pb::SyncEnums::NOT_MY_BIRTHDAY)); - - // Make another change to trigger downloading of rollback command. - Remove(0, GetOtherNode(0), 0); - - // Wait sync backend is completely shut down. - SyncBackendStoppedChecker shutdown_checker(GetSyncService(0)); - ASSERT_TRUE(shutdown_checker.Wait()); - - // Shouldn't restore bookmarks with sign-out only. - ASSERT_EQ(1, GetOtherNode(0)->child_count()); - ASSERT_EQ(GURL("http://www.yahoo.com"), - GetOtherNode(0)->GetChild(0)->url()); -} - -#if BUILDFLAG(ENABLE_PRE_SYNC_BACKUP) -#define MAYBE_RollbackNoBackup RollbackNoBackup -#else -#define MAYBE_RollbackNoBackup DISABLED_RollbackNoBackup -#endif -IN_PROC_BROWSER_TEST_F(SingleClientBackupRollbackTest, - MAYBE_RollbackNoBackup) { - ASSERT_TRUE(SetupClients()) << "SetupClients() failed."; - - // Starting state: - // other_node - // -> http://mail.google.com "url0" - // -> http://www.nhl.com "url1" - ASSERT_TRUE(AddURL(0, GetOtherNode(0), 0, "url0", - GURL("http://mail.google.com"))); - - // Setup sync, wait for its completion, and make sure changes were synced. - ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; - ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0)))); - ASSERT_TRUE(ModelMatchesVerifier(0)); - - ASSERT_TRUE(AddURL(0, GetOtherNode(0), 1, "url1", - GURL("http://www.nhl.com"))); - - // Delete backup DB. - base::DeleteFile( - GetProfile(0)->GetPath().Append(FILE_PATH_LITERAL("Sync Data Backup")), - true); - - // Let server to return rollback command on next sync request. - ASSERT_TRUE(GetFakeServer()->TriggerError(sync_pb::SyncEnums::USER_ROLLBACK)); - - // Make another change to trigger downloading of rollback command. - Remove(0, GetOtherNode(0), 0); - - // Wait for rollback to finish and sync backend is completely shut down. - SyncRollbackChecker rollback_checker(GetSyncService(0)); - ASSERT_TRUE(rollback_checker.Wait()); - SyncBackendStoppedChecker checker(GetSyncService(0)); - ASSERT_TRUE(checker.Wait()); - - // Without backup DB, bookmarks remain at the state when sync stops. - ASSERT_EQ(1, GetOtherNode(0)->child_count()); - ASSERT_EQ(GURL("http://www.nhl.com"), - GetOtherNode(0)->GetChild(0)->url()); -} - -#if BUILDFLAG(ENABLE_PRE_SYNC_BACKUP) -#define MAYBE_DontChangeBookmarkOrdering DontChangeBookmarkOrdering -#else -#define MAYBE_DontChangeBookmarkOrdering DISABLED_DontChangeBookmarkOrdering -#endif -IN_PROC_BROWSER_TEST_F(SingleClientBackupRollbackTest, - MAYBE_DontChangeBookmarkOrdering) { - ASSERT_TRUE(SetupClients()) << "SetupClients() failed."; - - const BookmarkNode* sub_folder = AddFolder(0, GetOtherNode(0), 0, "test"); - ASSERT_TRUE(AddURL(0, sub_folder, 0, "", GURL(kUrl1))); - ASSERT_TRUE(AddURL(0, sub_folder, 1, "", GURL(kUrl2))); - ASSERT_TRUE(AddURL(0, sub_folder, 2, "", GURL(kUrl3))); - - // Setup sync, wait for its completion, and make sure changes were synced. - ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; - ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService(0))); - ASSERT_TRUE(ModelMatchesVerifier(0)); - - // Made bookmark changes while sync is on. - Remove(0, sub_folder, 0); - Remove(0, sub_folder, 0); - ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService(0))); - ASSERT_TRUE(ModelMatchesVerifier(0)); - - // Let server to return rollback command on next sync request. - ASSERT_TRUE(GetFakeServer()->TriggerError(sync_pb::SyncEnums::USER_ROLLBACK)); - - // Make another change to trigger downloading of rollback command. - Remove(0, sub_folder, 0); - - // Wait for rollback to finish and sync backend is completely shut down. - SyncRollbackChecker rollback_checker(GetSyncService(0)); - ASSERT_TRUE(rollback_checker.Wait()); - SyncBackendStoppedChecker shutdown_checker(GetSyncService(0)); - ASSERT_TRUE(shutdown_checker.Wait()); - - // Verify bookmarks are unchanged. - ASSERT_EQ(3, sub_folder->child_count()); - ASSERT_EQ(GURL(kUrl1), sub_folder->GetChild(0)->url()); - ASSERT_EQ(GURL(kUrl2), sub_folder->GetChild(1)->url()); - ASSERT_EQ(GURL(kUrl3), sub_folder->GetChild(2)->url()); -} diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 87bfb56..c67fd7c 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -1445,7 +1445,6 @@ 'browser/sync/test/integration/migration_test.cc', 'browser/sync/test/integration/single_client_app_list_sync_test.cc', 'browser/sync/test/integration/single_client_apps_sync_test.cc', - 'browser/sync/test/integration/single_client_backup_rollback_test.cc', 'browser/sync/test/integration/single_client_bookmarks_sync_test.cc', 'browser/sync/test/integration/single_client_dictionary_sync_test.cc', 'browser/sync/test/integration/single_client_directory_sync_test.cc', diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi index 6d1fe03..491b995 100644 --- a/chrome/chrome_tests_unit.gypi +++ b/chrome/chrome_tests_unit.gypi @@ -2223,7 +2223,6 @@ 'test_support_unit', # 3) anything tests directly depend on '../components/components.gyp:generate_version_info', - '../components/components.gyp:sync_driver_features', '../courgette/courgette.gyp:courgette_lib', '../google_apis/google_apis.gyp:google_apis', '../skia/skia.gyp:skia', diff --git a/components/browser_sync.gypi b/components/browser_sync.gypi index 5c464060..b5bb383 100644 --- a/components/browser_sync.gypi +++ b/components/browser_sync.gypi @@ -31,7 +31,6 @@ 'syncable_prefs', 'sync_bookmarks', 'sync_driver', - 'sync_driver_features', 'sync_sessions', 'variations', 'version_info', diff --git a/components/browser_sync/browser/profile_sync_components_factory_impl.cc b/components/browser_sync/browser/profile_sync_components_factory_impl.cc index 9ce6b74..370c93e 100644 --- a/components/browser_sync/browser/profile_sync_components_factory_impl.cc +++ b/components/browser_sync/browser/profile_sync_components_factory_impl.cc @@ -331,7 +331,7 @@ ProfileSyncComponentsFactoryImpl::CreateAttachmentService( scoped_ptr<syncer::AttachmentDownloader> attachment_downloader; // Only construct an AttachmentUploader and AttachmentDownload if we have sync // credentials. We may not have sync credentials because there may not be a - // signed in sync user (e.g. sync is running in "backup" mode). + // signed in sync user. if (!user_share.sync_credentials.account_id.empty() && !user_share.sync_credentials.scope_set.empty()) { scoped_refptr<OAuth2TokenServiceRequest::TokenServiceProvider> diff --git a/components/browser_sync/browser/profile_sync_service.cc b/components/browser_sync/browser/profile_sync_service.cc index 1fa9242..67987b2 100644 --- a/components/browser_sync/browser/profile_sync_service.cc +++ b/components/browser_sync/browser/profile_sync_service.cc @@ -51,7 +51,6 @@ #include "components/sync_driver/signin_manager_wrapper.h" #include "components/sync_driver/sync_api_component_factory.h" #include "components/sync_driver/sync_client.h" -#include "components/sync_driver/sync_driver_features.h" #include "components/sync_driver/sync_driver_switches.h" #include "components/sync_driver/sync_error_controller.h" #include "components/sync_driver/sync_stopped_reporter.h" @@ -145,9 +144,6 @@ const net::BackoffEntry::Policy kRequestAccessTokenBackoffPolicy = { static const base::FilePath::CharType kSyncDataFolderName[] = FILE_PATH_LITERAL("Sync Data"); -static const base::FilePath::CharType kSyncBackupDataFolderName[] = - FILE_PATH_LITERAL("Sync Data Backup"); - namespace { // Perform the actual sync data folder deletion. @@ -166,8 +162,6 @@ bool ShouldShowActionOnUI( return (error.action != syncer::UNKNOWN_ACTION && error.action != syncer::DISABLE_SYNC_ON_CLIENT && error.action != syncer::STOP_SYNC_FOR_DISABLED_ACCOUNT && - error.action != syncer::DISABLE_SYNC_AND_ROLLBACK && - error.action != syncer::ROLLBACK_DONE && error.action != syncer::RESET_LOCAL_SYNC_DATA); } @@ -224,9 +218,6 @@ ProfileSyncService::ProfileSyncService(InitParams init_params) last_get_token_error_(GoogleServiceAuthError::AuthErrorNone()), network_resources_(new syncer::HttpBridgeNetworkResources), start_behavior_(init_params.start_behavior), - backend_mode_(IDLE), - need_backup_(false), - backup_finished_(false), catch_up_configure_in_progress_(false), passphrase_prompt_triggered_by_version_(false), weak_factory_(this), @@ -261,13 +252,7 @@ void ProfileSyncService::Initialize() { startup_controller_.reset(new browser_sync::StartupController( start_behavior_, oauth2_token_service_, &sync_prefs_, signin_.get(), base::Bind(&ProfileSyncService::StartUpSlowBackendComponents, - startup_controller_weak_factory_.GetWeakPtr(), SYNC))); - backup_rollback_controller_.reset(new sync_driver::BackupRollbackController( - &sync_prefs_, signin_.get(), - base::Bind(&ProfileSyncService::StartUpSlowBackendComponents, - startup_controller_weak_factory_.GetWeakPtr(), BACKUP), - base::Bind(&ProfileSyncService::StartUpSlowBackendComponents, - startup_controller_weak_factory_.GetWeakPtr(), ROLLBACK))); + startup_controller_weak_factory_.GetWeakPtr()))); scoped_ptr<browser_sync::LocalSessionEventRouter> router( sync_client_->GetSyncSessionsClient()->GetLocalSessionEventRouter()); local_device_ = sync_client_->GetSyncApiComponentFactory() @@ -352,26 +337,6 @@ void ProfileSyncService::Initialize() { AddObserver(sync_error_controller_.get()); #endif - bool running_rollback = false; - if (sync_driver::BackupRollbackController::IsBackupEnabled()) { - // Backup is needed if user's not signed in or signed in but previous - // backup didn't finish, i.e. backend didn't switch from backup to sync. - need_backup_ = !IsSignedIn() || sync_prefs_.GetFirstSyncTime().is_null(); - - // Try to resume rollback if it didn't finish in last session. - running_rollback = backup_rollback_controller_->StartRollback(); - } else { - need_backup_ = false; - } - -#if BUILDFLAG(ENABLE_PRE_SYNC_BACKUP) - if (!running_rollback && !IsSignedIn()) { - CleanUpBackup(); - } -#else - DCHECK(!running_rollback); -#endif - memory_pressure_listener_.reset(new base::MemoryPressureListener(base::Bind( &ProfileSyncService::OnMemoryPressure, weak_factory_.GetWeakPtr()))); startup_controller_->Reset(GetRegisteredDataTypes()); @@ -414,7 +379,6 @@ void ProfileSyncService::StartSyncingWithServer() { if (base::CommandLine::ForCurrentProcess()->HasSwitch( switches::kSyncEnableClearDataOnPassphraseEncryption) && - backend_mode_ == SYNC && sync_prefs_.GetPassphraseEncryptionTransitionInProgress()) { BeginConfigureCatchUpBeforeClear(); return; @@ -494,34 +458,21 @@ void ProfileSyncService::OnSessionRestoreComplete() { SyncCredentials ProfileSyncService::GetCredentials() { SyncCredentials credentials; - if (backend_mode_ == SYNC) { - credentials.account_id = signin_->GetAccountIdToUse(); - DCHECK(!credentials.account_id.empty()); - credentials.email = signin_->GetEffectiveUsername(); - credentials.sync_token = access_token_; + credentials.account_id = signin_->GetAccountIdToUse(); + DCHECK(!credentials.account_id.empty()); + credentials.email = signin_->GetEffectiveUsername(); + credentials.sync_token = access_token_; - if (credentials.sync_token.empty()) - credentials.sync_token = "credentials_lost"; + if (credentials.sync_token.empty()) + credentials.sync_token = "credentials_lost"; - credentials.scope_set.insert(signin_->GetSyncScopeToUse()); - } + credentials.scope_set.insert(signin_->GetSyncScopeToUse()); return credentials; } bool ProfileSyncService::ShouldDeleteSyncFolder() { - switch (backend_mode_) { - case SYNC: - return !IsFirstSetupComplete(); - case BACKUP: - return true; - case ROLLBACK: - return false; - case IDLE: - NOTREACHED(); - return true; - } - return true; + return !IsFirstSetupComplete(); } void ProfileSyncService::InitializeBackend(bool delete_stale_data) { @@ -532,7 +483,7 @@ void ProfileSyncService::InitializeBackend(bool delete_stale_data) { SyncCredentials credentials = GetCredentials(); - if (backend_mode_ == SYNC && delete_stale_data) + if (delete_stale_data) ClearStaleErrors(); SyncBackendHost::HttpPostProviderFactoryGetter @@ -547,7 +498,7 @@ void ProfileSyncService::InitializeBackend(bool delete_stale_data) { GetJsEventHandler(), sync_service_url_, local_device_->GetSyncUserAgent(), credentials, delete_stale_data, scoped_ptr<syncer::SyncManagerFactory>( - new syncer::SyncManagerFactory(GetManagerType())), + new syncer::SyncManagerFactory()), MakeWeakHandle(weak_factory_.GetWeakPtr()), base::Bind(browser_sync::ChromeReportUnrecoverableError, channel_), http_post_provider_factory_getter, std::move(saved_nigori_state_)); @@ -624,71 +575,11 @@ void ProfileSyncService::OnDataTypeRequestsSyncStartup( startup_controller_->OnDataTypeRequestsSyncStartup(type); } -void ProfileSyncService::StartUpSlowBackendComponents( - ProfileSyncService::BackendMode mode) { - DCHECK_NE(IDLE, mode); - if (backend_mode_ == mode) { - return; - } - - // Backend mode transition rules: - // * can transit from IDLE to any other non-IDLE mode. - // * forbidden to transit from SYNC to any other mode, i.e. SYNC backend must - // be explicitly shut down before backup/rollback starts. - // * can not transit out of ROLLBACK mode until rollback is finished - // (successfully or unsuccessfully). - // * can not transit out of BACKUP mode until backup is finished - // (successfully or unsuccessfully). - // * if backup is needed, can only transit to SYNC if backup is finished, - - if (backend_mode_ == SYNC) { - LOG(DFATAL) << "Shouldn't switch from mode SYNC to mode " << mode; - return; - } - - if (backend_mode_ == ROLLBACK || - (backend_mode_ == BACKUP && !backup_finished_)) { - // Wait for rollback/backup to finish before start new backend. - return; - } - - if (mode == SYNC && NeedBackup() && !backup_finished_) { - if (backend_mode_ != BACKUP) - backup_rollback_controller_->StartBackup(); - return; - } - - DVLOG(1) << "Start backend mode: " << mode; - - if (backend_) { - if (mode == SYNC) - ShutdownImpl(syncer::SWITCH_MODE_SYNC); - else - ShutdownImpl(syncer::STOP_SYNC); - } - - backend_mode_ = mode; - - if (backend_mode_ == BACKUP) - backup_start_time_ = base::Time::Now(); - - if (backend_mode_ == SYNC && !backup_start_time_.is_null()) { - UMA_HISTOGRAM_MEDIUM_TIMES("Sync.FirstSyncDelayByBackup", - base::Time::Now() - backup_start_time_); - backup_start_time_ = base::Time(); - } - - if (backend_mode_ == ROLLBACK) - ClearBrowsingDataSinceFirstSync(); - else if (backend_mode_ == SYNC) - CheckSyncBackupIfNeeded(); - - base::FilePath sync_folder = backend_mode_ == SYNC ? - base::FilePath(kSyncDataFolderName) : - base::FilePath(kSyncBackupDataFolderName); +void ProfileSyncService::StartUpSlowBackendComponents() { + base::FilePath sync_folder = base::FilePath(kSyncDataFolderName); invalidation::InvalidationService* invalidator = - backend_mode_ == SYNC ? sync_client_->GetInvalidationService() : nullptr; + sync_client_->GetInvalidationService(); directory_path_ = base_directory_.Append(sync_folder); @@ -874,25 +765,9 @@ void ProfileSyncService::ShutdownImpl(syncer::ShutdownReason reason) { weak_factory_.InvalidateWeakPtrs(); - if (backend_mode_ == SYNC) - startup_controller_->Reset(GetRegisteredDataTypes()); - - // Don't let backup block sync regardless backup succeeded or not. - if (backend_mode_ == BACKUP) - backup_finished_ = true; - - // Sync could be blocked by rollback/backup. Post task to check whether sync - // should start after shutting down rollback/backup backend. - if ((backend_mode_ == ROLLBACK || backend_mode_ == BACKUP) && - reason != syncer::SWITCH_MODE_SYNC && - reason != syncer::BROWSER_SHUTDOWN) { - base::ThreadTaskRunnerHandle::Get()->PostTask( - FROM_HERE, base::Bind(&ProfileSyncService::TryStartSyncAfterBackup, - startup_controller_weak_factory_.GetWeakPtr())); - } + startup_controller_->Reset(GetRegisteredDataTypes()); // Clear various flags. - backend_mode_ = IDLE; expect_sync_configuration_aborted_ = false; is_auth_in_progress_ = false; backend_initialized_ = false; @@ -1018,9 +893,6 @@ void ProfileSyncService::ReenableDatatype(syncer::ModelType type) { } void ProfileSyncService::UpdateBackendInitUMA(bool success) { - if (backend_mode_ != SYNC) - return; - is_first_time_sync_configure_ = !IsFirstSetupComplete(); if (is_first_time_sync_configure_) { @@ -1040,14 +912,6 @@ void ProfileSyncService::UpdateBackendInitUMA(bool success) { } void ProfileSyncService::PostBackendInitialization() { - // Never get here for backup / restore. - DCHECK_EQ(backend_mode_, SYNC); - - if (last_backup_time_) { - DCHECK(device_info_sync_service_); - device_info_sync_service_->UpdateLocalDeviceBackupTime(*last_backup_time_); - } - if (protocol_event_observers_.might_have_observers()) { backend_->RequestBufferedProtocolEventsAndEnableForwarding(); } @@ -1129,10 +993,7 @@ void ProfileSyncService::OnBackendInitialized( local_device_->Initialize(cache_guid, signin_scoped_device_id, blocking_pool_); - if (backend_mode_ == BACKUP || backend_mode_ == ROLLBACK) - ConfigureDataTypeManager(); - else - PostBackendInitialization(); + PostBackendInitialization(); } void ProfileSyncService::OnSyncCycleCompleted() { @@ -1370,9 +1231,6 @@ void ProfileSyncService::OnActionableError(const SyncProtocolError& error) { true, ERROR_REASON_ACTIONABLE_ERROR); break; - case syncer::DISABLE_SYNC_AND_ROLLBACK: - backup_rollback_controller_->OnRollbackReceived(); - // Fall through to shutdown backend and sign user out. case syncer::DISABLE_SYNC_ON_CLIENT: if (error.error_type == syncer::NOT_MY_BIRTHDAY) { UMA_HISTOGRAM_ENUMERATION("Sync.StopSource", syncer::BIRTHDAY_ERROR, @@ -1390,9 +1248,6 @@ void ProfileSyncService::OnActionableError(const SyncProtocolError& error) { } #endif break; - case syncer::ROLLBACK_DONE: - backup_rollback_controller_->OnRollbackDone(); - break; case syncer::STOP_SYNC_FOR_DISABLED_ACCOUNT: // Sync disabled by domain admin. we should stop syncing until next // restart. @@ -1407,17 +1262,6 @@ void ProfileSyncService::OnActionableError(const SyncProtocolError& error) { NOTREACHED(); } NotifyObservers(); - - if (error.action == syncer::DISABLE_SYNC_ON_CLIENT || - (error.action == syncer::DISABLE_SYNC_AND_ROLLBACK && - !backup_rollback_controller_->StartRollback())) { - // Clean up backup data for sign-out only or when rollback is disabled. - CleanUpBackup(); - } else if (error.action == syncer::ROLLBACK_DONE) { - // Shut down ROLLBACK backend and delete backup DB. - ShutdownImpl(syncer::DISABLE_SYNC); - sync_prefs_.ClearFirstSyncTime(); - } } void ProfileSyncService::OnLocalSetPassphraseEncryption( @@ -1437,7 +1281,6 @@ void ProfileSyncService::OnLocalSetPassphraseEncryption( } void ProfileSyncService::BeginConfigureCatchUpBeforeClear() { - DCHECK_EQ(backend_mode_, SYNC); DCHECK(data_type_manager_); DCHECK(!saved_nigori_state_); saved_nigori_state_ = @@ -1472,26 +1315,6 @@ void ProfileSyncService::OnConfigureDone( configure_status_ = result.status; data_type_status_table_ = result.data_type_status_table; - if (backend_mode_ != SYNC) { - if (configure_status_ == DataTypeManager::OK) { - StartSyncingWithServer(); - - // Backup is done after models are associated. - if (backend_mode_ == BACKUP) - backup_finished_ = true; - - // Asynchronously check whether sync needs to start. - base::ThreadTaskRunnerHandle::Get()->PostTask( - FROM_HERE, base::Bind(&ProfileSyncService::TryStartSyncAfterBackup, - startup_controller_weak_factory_.GetWeakPtr())); - } else if (!expect_sync_configuration_aborted_) { - DVLOG(1) << "Backup/rollback backend failed to configure."; - ShutdownImpl(syncer::STOP_SYNC); - } - - return; - } - // We should have cleared our cached passphrase before we get here (in // OnBackendInitialized()). DCHECK(cached_passphrase_.empty()); @@ -1594,10 +1417,6 @@ ProfileSyncService::SyncStatusSummary return UNRECOVERABLE_ERROR; } else if (!backend_) { return NOT_ENABLED; - } else if (backend_mode_ == BACKUP) { - return BACKUP_USER_DATA; - } else if (backend_mode_ == ROLLBACK) { - return ROLLBACK_USER_DATA; } else if (backend_.get() && !IsFirstSetupComplete()) { return SETUP_INCOMPLETE; } else if (backend_ && IsFirstSetupComplete() && data_type_manager_ && @@ -1627,10 +1446,6 @@ std::string ProfileSyncService::QuerySyncStatusSummaryString() { return "Datatypes not fully initialized"; case INITIALIZED: return "Sync service initialized"; - case BACKUP_USER_DATA: - return "Backing-up user data. Status: " + config_status_str; - case ROLLBACK_USER_DATA: - return "Restoring user data. Status: " + config_status_str; default: return "Status unknown: Internal error?"; } @@ -1685,7 +1500,7 @@ bool ProfileSyncService::IsSyncAllowed() const { } bool ProfileSyncService::IsSyncActive() const { - return backend_initialized_ && backend_mode_ == SYNC && data_type_manager_ && + return backend_initialized_ && data_type_manager_ && data_type_manager_->state() != DataTypeManager::STOPPED; } @@ -1703,10 +1518,6 @@ bool ProfileSyncService::IsBackendInitialized() const { return backend_initialized_; } -ProfileSyncService::BackendMode ProfileSyncService::backend_mode() const { - return backend_mode_; -} - bool ProfileSyncService::ConfigurationDone() const { return data_type_manager_ && data_type_manager_->state() == DataTypeManager::CONFIGURED; @@ -1927,7 +1738,7 @@ void ProfileSyncService::ConfigureDataTypeManager() { // start syncing data until the user is done configuring encryption options, // etc. ReconfigureDatatypeManager() will get called again once the UI calls // SetSetupInProgress(false). - if (backend_mode_ == SYNC && startup_controller_->IsSetupInProgress()) + if (startup_controller_->IsSetupInProgress()) return; bool restart = false; @@ -1947,24 +1758,19 @@ void ProfileSyncService::ConfigureDataTypeManager() { syncer::ModelTypeSet types; syncer::ConfigureReason reason = syncer::CONFIGURE_REASON_UNKNOWN; - if (backend_mode_ == BACKUP || backend_mode_ == ROLLBACK) { - types = syncer::BackupTypes(); - reason = syncer::CONFIGURE_REASON_BACKUP_ROLLBACK; + types = GetPreferredDataTypes(); + if (!IsFirstSetupComplete()) { + reason = syncer::CONFIGURE_REASON_NEW_CLIENT; + } else if (restart) { + // Datatype downloads on restart are generally due to newly supported + // datatypes (although it's also possible we're picking up where a failed + // previous configuration left off). + // TODO(sync): consider detecting configuration recovery and setting + // the reason here appropriately. + reason = syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE; } else { - types = GetPreferredDataTypes(); - if (!IsFirstSetupComplete()) { - reason = syncer::CONFIGURE_REASON_NEW_CLIENT; - } else if (restart) { - // Datatype downloads on restart are generally due to newly supported - // datatypes (although it's also possible we're picking up where a failed - // previous configuration left off). - // TODO(sync): consider detecting configuration recovery and setting - // the reason here appropriately. - reason = syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE; - } else { - // The user initiated a reconfiguration (either to add or remove types). - reason = syncer::CONFIGURE_REASON_RECONFIGURATION; - } + // The user initiated a reconfiguration (either to add or remove types). + reason = syncer::CONFIGURE_REASON_RECONFIGURATION; } data_type_manager_->Configure(types, reason); @@ -2266,11 +2072,6 @@ void ProfileSyncService::GoogleSignedOut(const std::string& account_id, UMA_HISTOGRAM_ENUMERATION("Sync.StopSource", syncer::SIGN_OUT, syncer::STOP_SOURCE_LIMIT); RequestStop(CLEAR_DATA); - - if (sync_driver::BackupRollbackController::IsBackupEnabled()) { - need_backup_ = true; - backup_finished_ = false; - } } void ProfileSyncService::AddObserver( @@ -2534,21 +2335,6 @@ void ProfileSyncService::OnInternalUnrecoverableError( OnUnrecoverableErrorImpl(from_here, message, delete_sync_database); } -syncer::SyncManagerFactory::MANAGER_TYPE -ProfileSyncService::GetManagerType() const { - switch (backend_mode_) { - case SYNC: - return syncer::SyncManagerFactory::NORMAL; - case BACKUP: - return syncer::SyncManagerFactory::BACKUP; - case ROLLBACK: - return syncer::SyncManagerFactory::ROLLBACK; - case IDLE: - NOTREACHED(); - } - return syncer::SyncManagerFactory::NORMAL; -} - bool ProfileSyncService::IsRetryingAccessTokenFetchForTest() const { return request_access_token_retry_timer_.IsRunning(); } @@ -2588,97 +2374,18 @@ void ProfileSyncService::OverrideNetworkResourcesForTest( } bool ProfileSyncService::HasSyncingBackend() const { - return backend_mode_ != SYNC ? false : backend_ != NULL; + return backend_ != NULL; } void ProfileSyncService::UpdateFirstSyncTimePref() { if (!IsSignedIn()) { - // Clear if user's not signed in and rollback is done. - if (backend_mode_ != ROLLBACK) - sync_prefs_.ClearFirstSyncTime(); - } else if (sync_prefs_.GetFirstSyncTime().is_null() && - backend_mode_ == SYNC) { + sync_prefs_.ClearFirstSyncTime(); + } else if (sync_prefs_.GetFirstSyncTime().is_null()) { // Set if not set before and it's syncing now. sync_prefs_.SetFirstSyncTime(base::Time::Now()); } } -void ProfileSyncService::ClearBrowsingDataSinceFirstSync() { - base::Time first_sync_time = sync_prefs_.GetFirstSyncTime(); - if (first_sync_time.is_null()) - return; - - sync_client_->GetClearBrowsingDataCallback().Run(first_sync_time, - base::Time::Now()); -} - -void ProfileSyncService::CheckSyncBackupIfNeeded() { - DCHECK_EQ(backend_mode_, SYNC); - -#if BUILDFLAG(ENABLE_PRE_SYNC_BACKUP) - const base::Time last_synced_time = sync_prefs_.GetLastSyncedTime(); - // Check backup once a day. - if (!last_backup_time_ && - (last_synced_time.is_null() || - base::Time::Now() - last_synced_time >= - base::TimeDelta::FromDays(1))) { - // If sync thread is set, need to serialize check on sync thread after - // closing backup DB. - if (sync_thread_) { - sync_thread_->task_runner()->PostTask( - FROM_HERE, - base::Bind(syncer::CheckSyncDbLastModifiedTime, - base_directory_.Append(kSyncBackupDataFolderName), - base::ThreadTaskRunnerHandle::Get(), - base::Bind(&ProfileSyncService::CheckSyncBackupCallback, - weak_factory_.GetWeakPtr()))); - } else { - file_thread_->PostTask( - FROM_HERE, - base::Bind(syncer::CheckSyncDbLastModifiedTime, - base_directory_.Append(kSyncBackupDataFolderName), - base::ThreadTaskRunnerHandle::Get(), - base::Bind(&ProfileSyncService::CheckSyncBackupCallback, - weak_factory_.GetWeakPtr()))); - } - } -#endif -} - -void ProfileSyncService::CheckSyncBackupCallback(base::Time backup_time) { - last_backup_time_.reset(new base::Time(backup_time)); - - DCHECK(device_info_sync_service_); - device_info_sync_service_->UpdateLocalDeviceBackupTime(*last_backup_time_); -} - -void ProfileSyncService::TryStartSyncAfterBackup() { - startup_controller_->Reset(GetRegisteredDataTypes()); - startup_controller_->TryStart(); -} - -void ProfileSyncService::CleanUpBackup() { - sync_prefs_.ClearFirstSyncTime(); - - // Use the client's base directory to get the blocking task runner to use in - // order to ensure ordering between the tasks posted by different invocations - // of this method. - scoped_refptr<base::SequencedTaskRunner> blocking_task_runner = - JsonPrefStore::GetTaskRunnerForFile(base_directory_, blocking_pool_); - blocking_task_runner->PostTask( - FROM_HERE, - base::Bind(base::IgnoreResult(base::DeleteFile), - base_directory_.Append(kSyncBackupDataFolderName), true)); -} - -bool ProfileSyncService::NeedBackup() const { - return need_backup_; -} - -base::Time ProfileSyncService::GetDeviceBackupTimeForTesting() const { - return device_info_sync_service_->GetLocalDeviceBackupTime(); -} - void ProfileSyncService::FlushDirectory() const { // backend_initialized_ implies backend_ isn't NULL and the manager exists. // If sync is not initialized yet, we fail silently. diff --git a/components/browser_sync/browser/profile_sync_service.h b/components/browser_sync/browser/profile_sync_service.h index ada1731..df981bc 100644 --- a/components/browser_sync/browser/profile_sync_service.h +++ b/components/browser_sync/browser/profile_sync_service.h @@ -25,7 +25,6 @@ #include "build/build_config.h" #include "components/keyed_service/core/keyed_service.h" #include "components/signin/core/browser/signin_manager_base.h" -#include "components/sync_driver/backup_rollback_controller.h" #include "components/sync_driver/data_type_controller.h" #include "components/sync_driver/data_type_manager.h" #include "components/sync_driver/data_type_manager_observer.h" @@ -219,18 +218,9 @@ class ProfileSyncService : public sync_driver::SyncService, SETUP_INCOMPLETE, DATATYPES_NOT_INITIALIZED, INITIALIZED, - BACKUP_USER_DATA, - ROLLBACK_USER_DATA, UNKNOWN_ERROR, }; - enum BackendMode { - IDLE, // No backend. - SYNC, // Backend for syncing. - BACKUP, // Backend for backup. - ROLLBACK // Backend for rollback. - }; - // Bundles the arguments for ProfileSyncService construction. This is a // movable struct. Because of the non-POD data members, it needs out-of-line // constructors, so in particular the move constructor needs to be @@ -567,11 +557,6 @@ class ProfileSyncService : public sync_driver::SyncService, virtual bool IsDataTypeControllerRunning(syncer::ModelType type) const; - // Returns the current mode the backend is in. - BackendMode backend_mode() const; - - base::Time GetDeviceBackupTimeForTesting() const; - // This triggers a Directory::SaveChanges() call on the sync thread. // It should be used to persist data to disk when the process might be // killed in the near future. @@ -623,8 +608,6 @@ class ProfileSyncService : public sync_driver::SyncService, const std::string& message, bool delete_sync_database); - virtual bool NeedBackup() const; - // This is a cache of the last authentication response we received from the // sync server. The UI queries this to display appropriate messaging to the // user. @@ -733,9 +716,8 @@ class ProfileSyncService : public sync_driver::SyncService, void ClearUnrecoverableError(); - // Starts up the backend sync components. |mode| specifies the kind of - // backend to start, one of SYNC, BACKUP or ROLLBACK. - virtual void StartUpSlowBackendComponents(BackendMode mode); + // Starts up the backend sync components. + virtual void StartUpSlowBackendComponents(); // Collects preferred sync data types from |preference_providers_|. syncer::ModelTypeSet GetDataTypesFromPreferenceProviders() const; @@ -759,9 +741,6 @@ class ProfileSyncService : public sync_driver::SyncService, bool delete_sync_database, UnrecoverableErrorReason reason); - // Returns the type of manager to use according to |backend_mode_|. - syncer::SyncManagerFactory::MANAGER_TYPE GetManagerType() const; - // Update UMA for syncing backend. void UpdateBackendInitUMA(bool success); @@ -777,22 +756,6 @@ class ProfileSyncService : public sync_driver::SyncService, // Update first sync time stored in preferences void UpdateFirstSyncTimePref(); - // Clear browsing data since first sync during rollback. - void ClearBrowsingDataSinceFirstSync(); - - // Post background task to check sync backup DB state if needed. - void CheckSyncBackupIfNeeded(); - - // Callback to receive backup DB check result. - void CheckSyncBackupCallback(base::Time backup_time); - - // Callback function to call |startup_controller_|.TryStart() after - // backup/rollback finishes; - void TryStartSyncAfterBackup(); - - // Clean up prefs and backup DB when rollback is not needed. - void CleanUpBackup(); - // Tell the sync server that this client has disabled sync. void RemoveClientFromServer() const; @@ -987,23 +950,6 @@ class ProfileSyncService : public sync_driver::SyncService, browser_sync::ProfileSyncServiceStartBehavior start_behavior_; scoped_ptr<browser_sync::StartupController> startup_controller_; - scoped_ptr<sync_driver::BackupRollbackController> backup_rollback_controller_; - - // Mode of current backend. - BackendMode backend_mode_; - - // Whether backup is needed before sync starts. - bool need_backup_; - - // Whether backup is finished. - bool backup_finished_; - - base::Time backup_start_time_; - - // Last time when pre-sync data was saved. NULL pointer means backup data - // state is unknown. If time value is null, backup data doesn't exist. - scoped_ptr<base::Time> last_backup_time_; - // The full path to the sync data directory. base::FilePath directory_path_; diff --git a/components/browser_sync/browser/profile_sync_service_mock.h b/components/browser_sync/browser/profile_sync_service_mock.h index 41df3ea..255aa2f 100644 --- a/components/browser_sync/browser/profile_sync_service_mock.h +++ b/components/browser_sync/browser/profile_sync_service_mock.h @@ -96,8 +96,6 @@ class ProfileSyncServiceMock : public ProfileSyncService { MOCK_METHOD1(SetDecryptionPassphrase, bool(const std::string& passphrase)); MOCK_METHOD2(SetEncryptionPassphrase, void(const std::string& passphrase, PassphraseType type)); - - MOCK_METHOD1(StartUpSlowBackendComponents, void(BackendMode)); }; #endif // COMPONENTS_BROWSER_SYNC_BROWSER_PROFILE_SYNC_SERVICE_MOCK_H_ diff --git a/components/browser_sync/browser/profile_sync_service_startup_unittest.cc b/components/browser_sync/browser/profile_sync_service_startup_unittest.cc index 122fb32..206ce89 100644 --- a/components/browser_sync/browser/profile_sync_service_startup_unittest.cc +++ b/components/browser_sync/browser/profile_sync_service_startup_unittest.cc @@ -74,16 +74,6 @@ ACTION_P3(InvokeOnConfigureDone, sync_service, error_callback, result) { sync_service->OnConfigureDone(configure_result); } -class TestProfileSyncServiceNoBackup : public ProfileSyncService { - public: - explicit TestProfileSyncServiceNoBackup( - ProfileSyncService::InitParams init_params) - : ProfileSyncService(std::move(init_params)) {} - - protected: - bool NeedBackup() const override { return false; } -}; - class ProfileSyncServiceStartupTest : public testing::Test { public: ProfileSyncServiceStartupTest() { @@ -105,8 +95,7 @@ class ProfileSyncServiceStartupTest : public testing::Test { profile_sync_service_bundle_.CreateBasicInitParams(start_behavior, builder.Build()); - sync_service_.reset( - new TestProfileSyncServiceNoBackup(std::move(init_params))); + sync_service_.reset(new ProfileSyncService(std::move(init_params))); sync_service_->RegisterDataTypeController( new sync_driver::FakeDataTypeController(syncer::BOOKMARKS)); sync_service_->AddObserver(&observer_); diff --git a/components/browser_sync/browser/profile_sync_service_unittest.cc b/components/browser_sync/browser/profile_sync_service_unittest.cc index 69df103..b348ffa 100644 --- a/components/browser_sync/browser/profile_sync_service_unittest.cc +++ b/components/browser_sync/browser/profile_sync_service_unittest.cc @@ -32,7 +32,6 @@ #include "components/sync_driver/glue/sync_backend_host_mock.h" #include "components/sync_driver/pref_names.h" #include "components/sync_driver/sync_api_component_factory_mock.h" -#include "components/sync_driver/sync_driver_features.h" #include "components/sync_driver/sync_driver_switches.h" #include "components/sync_driver/sync_prefs.h" #include "components/sync_driver/sync_service_observer.h" @@ -240,9 +239,6 @@ class ProfileSyncServiceTest : public ::testing::Test { component_factory_ = profile_sync_service_bundle_.component_factory(); ProfileSyncServiceBundle::SyncClientBuilder builder( &profile_sync_service_bundle_); - builder.SetClearBrowsingDataCallback( - base::Bind(&ProfileSyncServiceTest::ClearBrowsingDataCallback, - base::Unretained(this))); ProfileSyncService::InitParams init_params = profile_sync_service_bundle_.CreateBasicInitParams(behavior, builder.Build()); @@ -268,8 +264,7 @@ class ProfileSyncServiceTest : public ::testing::Test { } void InitializeForNthSync() { - // Set first sync time before initialize to disable backup and simulate - // a complete sync setup. + // Set first sync time before initialize to simulate a complete sync setup. sync_driver::SyncPrefs sync_prefs( service_->GetSyncClient()->GetPrefService()); sync_prefs.SetFirstSyncTime(base::Time::Now()); @@ -378,10 +373,6 @@ class ProfileSyncServiceTest : public ::testing::Test { return component_factory_; } - void ClearBrowsingDataCallback(base::Time start, base::Time end) { - clear_browsing_date_start_ = start; - } - protected: void PumpLoop() { base::RunLoop run_loop; @@ -390,9 +381,6 @@ class ProfileSyncServiceTest : public ::testing::Test { run_loop.Run(); } - // The requested start time when ClearBrowsingDataCallback is called. - base::Time clear_browsing_date_start_; - private: base::MessageLoop message_loop_; browser_sync::ProfileSyncServiceBundle profile_sync_service_bundle_; @@ -423,7 +411,6 @@ TEST_F(ProfileSyncServiceTest, SuccessfulInitialization) { InitializeForNthSync(); EXPECT_FALSE(service()->IsManaged()); EXPECT_TRUE(service()->IsSyncActive()); - EXPECT_EQ(ProfileSyncService::SYNC, service()->backend_mode()); } // Verify that the SetSetupInProgress function call updates state @@ -639,107 +626,6 @@ TEST_F(ProfileSyncServiceTest, SignOutRevokeAccessToken) { } #endif -#if BUILDFLAG(ENABLE_PRE_SYNC_BACKUP) -TEST_F(ProfileSyncServiceTest, DontStartBackupOnBrowserStart) { - CreateServiceWithoutSignIn(); - InitializeForFirstSync(); - PumpLoop(); - EXPECT_EQ(ProfileSyncService::IDLE, service()->backend_mode()); -} - -TEST_F(ProfileSyncServiceTest, BackupBeforeFirstSync) { - CreateServiceWithoutSignIn(); - ExpectDataTypeManagerCreation(2, GetDefaultConfigureCalledCallback()); - std::vector<bool> delete_dir_param; - ExpectSyncBackendHostCreationCollectDeleteDir(2, &delete_dir_param); - InitializeForFirstSync(); - - signin_manager()->SetAuthenticatedAccountInfo(kGaiaId, kEmail); - IssueTestTokens(); - PumpLoop(); - - // At this time, backup is finished. Task is posted to start sync again. - EXPECT_EQ(ProfileSyncService::BACKUP, service()->backend_mode()); - EXPECT_FALSE(service()->IsSyncActive()); - EXPECT_EQ(1u, delete_dir_param.size()); - EXPECT_TRUE(delete_dir_param[0]); - - // Pump loop to start sync. - PumpLoop(); - EXPECT_EQ(ProfileSyncService::SYNC, service()->backend_mode()); - EXPECT_TRUE(service()->IsSyncActive()); - EXPECT_EQ(2u, delete_dir_param.size()); - EXPECT_TRUE(delete_dir_param[0]); -} - -// Test backup is done again on browser start if user signed in last session -// but backup didn't finish when last session was closed. -TEST_F(ProfileSyncServiceTest, ResumeBackupIfAborted) { - IssueTestTokens(); - CreateService(AUTO_START); - ExpectDataTypeManagerCreation(2, GetDefaultConfigureCalledCallback()); - std::vector<bool> delete_dir_param; - ExpectSyncBackendHostCreationCollectDeleteDir(2, &delete_dir_param); - InitializeForFirstSync(); - PumpLoop(); - - // At this time, backup is finished. Task is posted to start sync again. - EXPECT_EQ(ProfileSyncService::BACKUP, service()->backend_mode()); - EXPECT_FALSE(service()->IsSyncActive()); - EXPECT_EQ(1u, delete_dir_param.size()); - EXPECT_TRUE(delete_dir_param[0]); - - // Pump loop to start sync. - PumpLoop(); - EXPECT_EQ(ProfileSyncService::SYNC, service()->backend_mode()); - EXPECT_TRUE(service()->IsSyncActive()); - EXPECT_EQ(2u, delete_dir_param.size()); - EXPECT_TRUE(delete_dir_param[0]); -} - -TEST_F(ProfileSyncServiceTest, Rollback) { - CreateService(browser_sync::MANUAL_START); - service()->SetFirstSetupComplete(); - ExpectDataTypeManagerCreation(2, GetDefaultConfigureCalledCallback()); - std::vector<bool> delete_dir_param; - ExpectSyncBackendHostCreationCollectDeleteDir(2, &delete_dir_param); - IssueTestTokens(); - InitializeForNthSync(); - EXPECT_TRUE(service()->IsSyncActive()); - EXPECT_EQ(ProfileSyncService::SYNC, service()->backend_mode()); - - // First sync time should be recorded. - sync_driver::SyncPrefs sync_prefs( - service()->GetSyncClient()->GetPrefService()); - base::Time first_sync_time = sync_prefs.GetFirstSyncTime(); - EXPECT_FALSE(first_sync_time.is_null()); - - syncer::SyncProtocolError client_cmd; - client_cmd.action = syncer::DISABLE_SYNC_AND_ROLLBACK; - service()->OnActionableError(client_cmd); - EXPECT_EQ(ProfileSyncService::IDLE, service()->backend_mode()); - - // Pump loop to run rollback. - PumpLoop(); - EXPECT_EQ(ProfileSyncService::ROLLBACK, service()->backend_mode()); - - // Browser data should be cleared during rollback. - EXPECT_EQ(first_sync_time, clear_browsing_date_start_); - - client_cmd.action = syncer::ROLLBACK_DONE; - service()->OnActionableError(client_cmd); - EXPECT_EQ(ProfileSyncService::IDLE, service()->backend_mode()); - - // First sync time is erased after rollback is done. - EXPECT_TRUE(sync_prefs.GetFirstSyncTime().is_null()); - - EXPECT_EQ(2u, delete_dir_param.size()); - EXPECT_FALSE(delete_dir_param[0]); - EXPECT_FALSE(delete_dir_param[1]); -} - -#endif // ENABLE_PRE_SYNC_BACKUP - // Verify that LastSyncedTime is cleared when the user signs out. TEST_F(ProfileSyncServiceTest, ClearLastSyncedTimeOnSignOut) { IssueTestTokens(); @@ -834,7 +720,6 @@ TEST_F(ProfileSyncServiceTest, OnLocalSetPassphraseEncryption) { 1, GetRecordingConfigureCalledCallback(&configure_reason)); InitializeForNthSync(); EXPECT_TRUE(service()->IsSyncActive()); - EXPECT_EQ(ProfileSyncService::SYNC, service()->backend_mode()); testing::Mock::VerifyAndClearExpectations(component_factory()); EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, configure_reason); sync_driver::DataTypeManager::ConfigureResult result; @@ -878,7 +763,6 @@ TEST_F(ProfileSyncServiceTest, ExpectDataTypeManagerCreation( 1, GetRecordingConfigureCalledCallback(&configure_reason)); InitializeForNthSync(); - EXPECT_EQ(ProfileSyncService::SYNC, service()->backend_mode()); testing::Mock::VerifyAndClearExpectations(component_factory()); EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, configure_reason); sync_driver::DataTypeManager::ConfigureResult result; @@ -933,7 +817,6 @@ TEST_F(ProfileSyncServiceTest, ExpectSyncBackendHostCreationCaptureClearServerData(&captured_callback); ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback()); InitializeForNthSync(); - EXPECT_EQ(ProfileSyncService::SYNC, service()->backend_mode()); testing::Mock::VerifyAndClearExpectations(component_factory()); // Simulate user entering encryption passphrase. @@ -1018,7 +901,6 @@ TEST_F(ProfileSyncServiceTest, ResetSyncData) { syncer::SyncProtocolError client_cmd; client_cmd.action = syncer::RESET_LOCAL_SYNC_DATA; service()->OnActionableError(client_cmd); - EXPECT_EQ(ProfileSyncService::SYNC, service()->backend_mode()); } // Regression test for crbug/555434. The issue is that check for sessions DTC in diff --git a/components/browser_sync/browser/profile_sync_test_util.cc b/components/browser_sync/browser/profile_sync_test_util.cc index c0c678f..1f1ecd8 100644 --- a/components/browser_sync/browser/profile_sync_test_util.cc +++ b/components/browser_sync/browser/profile_sync_test_util.cc @@ -15,8 +15,6 @@ #include "net/url_request/url_request_test_util.h" #include "sync/internal_api/public/engine/passive_model_worker.h" -using sync_driver::ClearBrowsingDataCallback; - namespace browser_sync { namespace { @@ -26,7 +24,6 @@ class BundleSyncClient : public sync_driver::FakeSyncClient { BundleSyncClient( sync_driver::SyncApiComponentFactory* factory, PrefService* pref_service, - const ClearBrowsingDataCallback& clear_browsing_data_callback, sync_sessions::SyncSessionsClient* sync_sessions_client, autofill::PersonalDataManager* personal_data_manager, const base::Callback<base::WeakPtr<syncer::SyncableService>( @@ -42,7 +39,6 @@ class BundleSyncClient : public sync_driver::FakeSyncClient { ~BundleSyncClient() override; PrefService* GetPrefService() override; - ClearBrowsingDataCallback GetClearBrowsingDataCallback() override; sync_sessions::SyncSessionsClient* GetSyncSessionsClient() override; autofill::PersonalDataManager* GetPersonalDataManager() override; base::WeakPtr<syncer::SyncableService> GetSyncableServiceForType( @@ -56,7 +52,6 @@ class BundleSyncClient : public sync_driver::FakeSyncClient { private: PrefService* const pref_service_; - const ClearBrowsingDataCallback clear_browsing_data_callback_; sync_sessions::SyncSessionsClient* const sync_sessions_client_; autofill::PersonalDataManager* const personal_data_manager_; const base::Callback<base::WeakPtr<syncer::SyncableService>( @@ -75,7 +70,6 @@ class BundleSyncClient : public sync_driver::FakeSyncClient { BundleSyncClient::BundleSyncClient( sync_driver::SyncApiComponentFactory* factory, PrefService* pref_service, - const ClearBrowsingDataCallback& clear_browsing_data_callback, sync_sessions::SyncSessionsClient* sync_sessions_client, autofill::PersonalDataManager* personal_data_manager, const base::Callback<base::WeakPtr<syncer::SyncableService>( @@ -89,7 +83,6 @@ BundleSyncClient::BundleSyncClient( history::HistoryService* history_service) : sync_driver::FakeSyncClient(factory), pref_service_(pref_service), - clear_browsing_data_callback_(clear_browsing_data_callback), sync_sessions_client_(sync_sessions_client), personal_data_manager_(personal_data_manager), get_syncable_service_callback_(get_syncable_service_callback), @@ -107,10 +100,6 @@ PrefService* BundleSyncClient::GetPrefService() { return pref_service_; } -ClearBrowsingDataCallback BundleSyncClient::GetClearBrowsingDataCallback() { - return clear_browsing_data_callback_; -} - sync_sessions::SyncSessionsClient* BundleSyncClient::GetSyncSessionsClient() { return sync_sessions_client_; } @@ -195,11 +184,6 @@ ProfileSyncServiceBundle::SyncClientBuilder::SyncClientBuilder( ProfileSyncServiceBundle* bundle) : bundle_(bundle) {} -void ProfileSyncServiceBundle::SyncClientBuilder::SetClearBrowsingDataCallback( - ClearBrowsingDataCallback clear_browsing_data_callback) { - clear_browsing_data_callback_ = clear_browsing_data_callback; -} - void ProfileSyncServiceBundle::SyncClientBuilder::SetPersonalDataManager( autofill::PersonalDataManager* personal_data_manager) { personal_data_manager_ = personal_data_manager; @@ -234,9 +218,9 @@ scoped_ptr<sync_driver::FakeSyncClient> ProfileSyncServiceBundle::SyncClientBuilder::Build() { return make_scoped_ptr(new BundleSyncClient( bundle_->component_factory(), bundle_->pref_service(), - clear_browsing_data_callback_, bundle_->sync_sessions_client(), - personal_data_manager_, get_syncable_service_callback_, - get_sync_service_callback_, get_bookmark_model_callback_, + bundle_->sync_sessions_client(), personal_data_manager_, + get_syncable_service_callback_, get_sync_service_callback_, + get_bookmark_model_callback_, activate_model_creation_ ? bundle_->db_thread() : nullptr, activate_model_creation_ ? base::ThreadTaskRunnerHandle::Get() : nullptr, history_service_)); diff --git a/components/browser_sync/browser/profile_sync_test_util.h b/components/browser_sync/browser/profile_sync_test_util.h index b5bea3a..0953ffb 100644 --- a/components/browser_sync/browser/profile_sync_test_util.h +++ b/components/browser_sync/browser/profile_sync_test_util.h @@ -79,10 +79,6 @@ class ProfileSyncServiceBundle { ~SyncClientBuilder(); - // Setters for the various additional data for the client to return. - void SetClearBrowsingDataCallback( - sync_driver::ClearBrowsingDataCallback clear_browsing_data_callback); - void SetPersonalDataManager( autofill::PersonalDataManager* personal_data_manager); @@ -111,7 +107,6 @@ class ProfileSyncServiceBundle { // Associated bundle to source objects from. ProfileSyncServiceBundle* const bundle_; - sync_driver::ClearBrowsingDataCallback clear_browsing_data_callback_; autofill::PersonalDataManager* personal_data_manager_; base::Callback<base::WeakPtr<syncer::SyncableService>( syncer::ModelType type)> diff --git a/components/browser_sync/browser/test_profile_sync_service.cc b/components/browser_sync/browser/test_profile_sync_service.cc index 092fdfe..48ede52 100644 --- a/components/browser_sync/browser/test_profile_sync_service.cc +++ b/components/browser_sync/browser/test_profile_sync_service.cc @@ -30,7 +30,3 @@ void TestProfileSyncService::OnConfigureDone( syncer::UserShare* TestProfileSyncService::GetUserShare() const { return backend_->GetUserShare(); } - -bool TestProfileSyncService::NeedBackup() const { - return false; -} diff --git a/components/browser_sync/browser/test_profile_sync_service.h b/components/browser_sync/browser/test_profile_sync_service.h index 54b0c37..abd82aa 100644 --- a/components/browser_sync/browser/test_profile_sync_service.h +++ b/components/browser_sync/browser/test_profile_sync_service.h @@ -41,8 +41,6 @@ class TestProfileSyncService : public ProfileSyncService { // and cause memory leak in test. syncer::WeakHandle<syncer::JsEventHandler> GetJsEventHandler() override; - bool NeedBackup() const override; - private: syncer::TestIdFactory id_factory_; diff --git a/components/components_tests.gyp b/components/components_tests.gyp index 0a0e078..46f7e81 100644 --- a/components/components_tests.gyp +++ b/components/components_tests.gyp @@ -742,7 +742,6 @@ 'sync_driver_unittest_sources': [ 'sync_driver/about_sync_util_unittest.cc', 'sync_driver/backend_migrator_unittest.cc', - 'sync_driver/backup_rollback_controller_unittest.cc', 'sync_driver/data_type_manager_impl_unittest.cc', 'sync_driver/device_info_data_type_controller_unittest.cc', 'sync_driver/device_info_service_unittest.cc', @@ -1115,7 +1114,6 @@ 'components.gyp:suggestions', 'components.gyp:sync_bookmarks', 'components.gyp:sync_driver', - 'components.gyp:sync_driver_features', 'components.gyp:sync_driver_test_support', 'components.gyp:sync_sessions', 'components.gyp:sync_sessions_test_support', diff --git a/components/sync_driver.gypi b/components/sync_driver.gypi index 0a4310b9a..ab98660 100644 --- a/components/sync_driver.gypi +++ b/components/sync_driver.gypi @@ -18,7 +18,6 @@ 'invalidation_public', 'os_crypt', 'signin_core_browser', - 'sync_driver_features', 'version_info', ], 'export_dependent_settings': [ @@ -35,8 +34,6 @@ 'sync_driver/backend_data_type_configurer.h', 'sync_driver/backend_migrator.cc', 'sync_driver/backend_migrator.h', - 'sync_driver/backup_rollback_controller.cc', - 'sync_driver/backup_rollback_controller.h', 'sync_driver/change_processor.cc', 'sync_driver/change_processor.h', 'sync_driver/data_type_controller.cc', @@ -156,26 +153,6 @@ ], }, { - # GN version: //components/sync_driver:features - 'target_name': 'sync_driver_features', - 'includes': [ '../build/buildflag_header.gypi' ], - 'variables': { - 'buildflag_header_path': 'components/sync_driver/sync_driver_features.h', - 'variables': { - 'conditions': [ - ['OS=="win" or OS=="mac" or (OS=="linux" and chromeos==0)', { - 'enable_pre_sync_backup%': 1, - }, { - 'enable_pre_sync_backup%': 0, - }], - ], - }, - 'buildflag_flags': [ - "ENABLE_PRE_SYNC_BACKUP=<(enable_pre_sync_backup)", - ], - }, - }, - { 'target_name': 'sync_driver_test_support', 'type': 'static_library', 'dependencies': [ diff --git a/components/sync_driver/BUILD.gn b/components/sync_driver/BUILD.gn index b20c8bc..9ea51d5 100644 --- a/components/sync_driver/BUILD.gn +++ b/components/sync_driver/BUILD.gn @@ -13,8 +13,6 @@ source_set("sync_driver") { "backend_data_type_configurer.h", "backend_migrator.cc", "backend_migrator.h", - "backup_rollback_controller.cc", - "backup_rollback_controller.h", "change_processor.cc", "change_processor.h", "data_type_controller.cc", @@ -122,7 +120,6 @@ source_set("sync_driver") { ] public_deps = [ - ":features", "//third_party/cacheinvalidation", ] deps = [ @@ -205,7 +202,6 @@ source_set("unit_tests") { sources = [ "about_sync_util_unittest.cc", "backend_migrator_unittest.cc", - "backup_rollback_controller_unittest.cc", "data_type_manager_impl_unittest.cc", "device_info_data_type_controller_unittest.cc", "device_info_service_unittest.cc", @@ -257,12 +253,3 @@ source_set("unit_tests") { ] } } - -buildflag_header("features") { - header = "sync_driver_features.h" - - # Whether to back up data before sync. - enable_pre_sync_backup = is_win || is_mac || (is_linux && !is_chromeos) - - flags = [ "ENABLE_PRE_SYNC_BACKUP=$enable_pre_sync_backup" ] -} diff --git a/components/sync_driver/backup_rollback_controller.cc b/components/sync_driver/backup_rollback_controller.cc deleted file mode 100644 index 3629973..0000000 --- a/components/sync_driver/backup_rollback_controller.cc +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "components/sync_driver/backup_rollback_controller.h" - -#include <string> - -#include "base/command_line.h" -#include "base/location.h" -#include "base/metrics/field_trial.h" -#include "base/single_thread_task_runner.h" -#include "base/thread_task_runner_handle.h" -#include "components/sync_driver/signin_manager_wrapper.h" -#include "components/sync_driver/sync_driver_features.h" -#include "components/sync_driver/sync_driver_switches.h" -#include "components/sync_driver/sync_prefs.h" - -namespace sync_driver { - -#if BUILDFLAG(ENABLE_PRE_SYNC_BACKUP) -// Number of rollback attempts to try before giving up. -static const int kRollbackLimits = 3; - -// Finch experiment name and group. -static char kSyncBackupFinchName[] = "SyncBackup"; -static char kSyncBackupFinchDisabled[] = "disabled"; -#endif - -BackupRollbackController::BackupRollbackController( - sync_driver::SyncPrefs* sync_prefs, - const SigninManagerWrapper* signin, - base::Closure start_backup, - base::Closure start_rollback) - : sync_prefs_(sync_prefs), - signin_(signin), - start_backup_(start_backup), - start_rollback_(start_rollback) {} - -BackupRollbackController::~BackupRollbackController() {} - -bool BackupRollbackController::StartBackup() { - if (!IsBackupEnabled()) - return false; - - // Disable rollback to previous backup DB because it will be overwritten by - // new backup. - sync_prefs_->SetRemainingRollbackTries(0); - base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, start_backup_); - return true; -} - -bool BackupRollbackController::StartRollback() { - if (!IsBackupEnabled()) - return false; - - // Don't roll back if disabled or user is signed in. - if (base::CommandLine::ForCurrentProcess()->HasSwitch( - switches::kSyncDisableRollback) || - !signin_->GetEffectiveUsername().empty()) { - sync_prefs_->SetRemainingRollbackTries(0); - return false; - } - - int rollback_tries = sync_prefs_->GetRemainingRollbackTries(); - if (rollback_tries <= 0) - return false; // No pending rollback. - - sync_prefs_->SetRemainingRollbackTries(rollback_tries - 1); - base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, start_rollback_); - return true; -} - -void BackupRollbackController::OnRollbackReceived() { -#if BUILDFLAG(ENABLE_PRE_SYNC_BACKUP) - sync_prefs_->SetRemainingRollbackTries(kRollbackLimits); -#endif -} - -void BackupRollbackController::OnRollbackDone() { -#if BUILDFLAG(ENABLE_PRE_SYNC_BACKUP) - sync_prefs_->SetRemainingRollbackTries(0); -#endif -} - -// static -bool BackupRollbackController::IsBackupEnabled() { -#if BUILDFLAG(ENABLE_PRE_SYNC_BACKUP) - const std::string group_name = - base::FieldTrialList::FindFullName(kSyncBackupFinchName); - - if (base::CommandLine::ForCurrentProcess()->HasSwitch( - switches::kSyncDisableBackup) || - group_name == kSyncBackupFinchDisabled) { - return false; - } - return true; -#else - return false; -#endif -} - -} // namespace sync_driver diff --git a/components/sync_driver/backup_rollback_controller.h b/components/sync_driver/backup_rollback_controller.h deleted file mode 100644 index f8b6b26..0000000 --- a/components/sync_driver/backup_rollback_controller.h +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef COMPONENTS_SYNC_DRIVER_BACKUP_ROLLBACK_CONTROLLER_H_ -#define COMPONENTS_SYNC_DRIVER_BACKUP_ROLLBACK_CONTROLLER_H_ - -#include "base/callback.h" -#include "base/macros.h" -#include "base/memory/weak_ptr.h" - -class SigninManagerWrapper; - -namespace sync_driver { - -class SyncPrefs; - -// BackupRollbackController takes two closures for starting backup/rollback -// process. It calls the closures according to user's signin status or -// received rollback command. Backup is not run when user signed in, even when -// sync is not running. -class BackupRollbackController { - public: - BackupRollbackController(sync_driver::SyncPrefs* sync_prefs, - const SigninManagerWrapper* signin, - base::Closure start_backup, - base::Closure start_rollback); - ~BackupRollbackController(); - - // Post task to run |start_backup_| if conditions are met. Return true if - // task is posted, false otherwise. - bool StartBackup(); - - // Post task to run |start_rollback_| if conditions are met. Return true if - // task is posted, false otherwise. - bool StartRollback(); - - // Update rollback preference to indicate rollback is needed. - void OnRollbackReceived(); - - // Update rollback preference to indicate rollback is finished. - void OnRollbackDone(); - - // Return true if platform supports backup and backup is enabled. - static bool IsBackupEnabled(); - - private: - sync_driver::SyncPrefs* sync_prefs_; - - // Use SigninManagerWrapper instead of SigninManagerBase so that - // supervised users are treated like regular signed-in users. - const SigninManagerWrapper* signin_; - - base::Closure start_backup_; - base::Closure start_rollback_; - - DISALLOW_COPY_AND_ASSIGN(BackupRollbackController); -}; - -} // namespace sync_driver - -#endif // COMPONENTS_SYNC_DRIVER_BACKUP_ROLLBACK_CONTROLLER_H_ diff --git a/components/sync_driver/backup_rollback_controller_unittest.cc b/components/sync_driver/backup_rollback_controller_unittest.cc deleted file mode 100644 index 7d5f9b6..0000000 --- a/components/sync_driver/backup_rollback_controller_unittest.cc +++ /dev/null @@ -1,148 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "components/sync_driver/backup_rollback_controller.h" - -#include <string> - -#include "base/command_line.h" -#include "base/location.h" -#include "base/memory/scoped_ptr.h" -#include "base/run_loop.h" -#include "base/single_thread_task_runner.h" -#include "components/sync_driver/signin_manager_wrapper.h" -#include "components/sync_driver/sync_driver_features.h" -#include "components/sync_driver/sync_driver_switches.h" -#include "components/sync_driver/sync_prefs.h" -#include "testing/gmock/include/gmock/gmock.h" -#include "testing/gtest/include/gtest/gtest.h" - -using ::testing::Return; - -namespace { - -#if BUILDFLAG(ENABLE_PRE_SYNC_BACKUP) - -class MockSigninManagerWrapper : public SigninManagerWrapper { - public: - MockSigninManagerWrapper() : SigninManagerWrapper(NULL) {} - - MOCK_CONST_METHOD0(GetEffectiveUsername, std::string()); -}; - -class FakeSyncPrefs : public sync_driver::SyncPrefs { - public: - FakeSyncPrefs() : rollback_tries_left_(0) {} - - int GetRemainingRollbackTries() const override { - return rollback_tries_left_; - } - - void SetRemainingRollbackTries(int v) override { rollback_tries_left_ = v; } - - private: - int rollback_tries_left_; -}; - -class BackupRollbackControllerTest : public testing::Test { - public: - void ControllerCallback(bool start_backup) { - if (start_backup) - backup_started_ = true; - else - rollback_started_ = true; - } - - protected: - void SetUp() override { - backup_started_ = false; - rollback_started_ = false; - - EXPECT_CALL(signin_wrapper_, GetEffectiveUsername()) - .WillRepeatedly(Return("")); - - controller_.reset(new sync_driver::BackupRollbackController( - &fake_prefs_, &signin_wrapper_, - base::Bind(&BackupRollbackControllerTest::ControllerCallback, - base::Unretained(this), true), - base::Bind(&BackupRollbackControllerTest::ControllerCallback, - base::Unretained(this), false))); - } - - void PumpLoop() { - base::RunLoop run_loop; - loop_.task_runner()->PostTask(FROM_HERE, run_loop.QuitClosure()); - run_loop.Run(); - } - - MockSigninManagerWrapper signin_wrapper_; - FakeSyncPrefs fake_prefs_; - scoped_ptr<sync_driver::BackupRollbackController> controller_; - bool backup_started_; - bool rollback_started_; - base::MessageLoop loop_; -}; - -TEST_F(BackupRollbackControllerTest, StartBackup) { - EXPECT_TRUE(controller_->StartBackup()); - PumpLoop(); - EXPECT_TRUE(backup_started_); -} - -TEST_F(BackupRollbackControllerTest, NoBackupIfDisabled) { - base::CommandLine::ForCurrentProcess()->AppendSwitch( - switches::kSyncDisableBackup); - - base::RunLoop run_loop; - EXPECT_FALSE(controller_->StartBackup()); - loop_.task_runner()->PostTask(FROM_HERE, run_loop.QuitClosure()); - run_loop.Run(); - EXPECT_FALSE(backup_started_); -} - -TEST_F(BackupRollbackControllerTest, StartRollback) { - fake_prefs_.SetRemainingRollbackTries(1); - - EXPECT_TRUE(controller_->StartRollback()); - PumpLoop(); - EXPECT_TRUE(rollback_started_); - EXPECT_EQ(0, fake_prefs_.GetRemainingRollbackTries()); -} - -TEST_F(BackupRollbackControllerTest, NoRollbackIfOutOfTries) { - fake_prefs_.SetRemainingRollbackTries(0); - - EXPECT_FALSE(controller_->StartRollback()); - PumpLoop(); - EXPECT_FALSE(rollback_started_); -} - -TEST_F(BackupRollbackControllerTest, NoRollbackIfUserSignedIn) { - fake_prefs_.SetRemainingRollbackTries(1); - EXPECT_CALL(signin_wrapper_, GetEffectiveUsername()) - .Times(1) - .WillOnce(Return("test")); - EXPECT_FALSE(controller_->StartRollback()); - EXPECT_EQ(0, fake_prefs_.GetRemainingRollbackTries()); - - PumpLoop(); - EXPECT_FALSE(backup_started_); - EXPECT_FALSE(rollback_started_); -} - -TEST_F(BackupRollbackControllerTest, NoRollbackIfDisabled) { - fake_prefs_.SetRemainingRollbackTries(1); - - base::CommandLine::ForCurrentProcess()->AppendSwitch( - switches::kSyncDisableRollback); - EXPECT_FALSE(controller_->StartRollback()); - EXPECT_EQ(0, fake_prefs_.GetRemainingRollbackTries()); - - PumpLoop(); - EXPECT_FALSE(rollback_started_); -} - -#endif - -} // anonymous namespace diff --git a/components/sync_driver/data_type_manager_impl.cc b/components/sync_driver/data_type_manager_impl.cc index 4450bec..b739611 100644 --- a/components/sync_driver/data_type_manager_impl.cc +++ b/components/sync_driver/data_type_manager_impl.cc @@ -76,10 +76,7 @@ void DataTypeManagerImpl::Configure(syncer::ModelTypeSet desired_types, if (reason == syncer::CONFIGURE_REASON_CATCH_UP) catch_up_in_progress_ = true; - if (reason == syncer::CONFIGURE_REASON_BACKUP_ROLLBACK) - desired_types.PutAll(syncer::ControlTypes()); - else - desired_types.PutAll(syncer::CoreTypes()); + desired_types.PutAll(syncer::CoreTypes()); // Only allow control types and types that have controllers. syncer::ModelTypeSet filtered_desired_types; diff --git a/components/sync_driver/data_type_manager_impl_unittest.cc b/components/sync_driver/data_type_manager_impl_unittest.cc index 0374618..7f0b2d5 100644 --- a/components/sync_driver/data_type_manager_impl_unittest.cc +++ b/components/sync_driver/data_type_manager_impl_unittest.cc @@ -1286,21 +1286,6 @@ TEST_F(SyncDataTypeManagerImplTest, FilterDesiredTypes) { EXPECT_EQ(DataTypeManager::STOPPED, dtm_->state()); } -TEST_F(SyncDataTypeManagerImplTest, ConfigureForBackupRollback) { - AddController(BOOKMARKS); - - SetConfigureStartExpectation(); - - ModelTypeSet expected_types = syncer::ControlTypes(); - expected_types.Put(BOOKMARKS); - configurer_.set_expected_configure_types( - BackendDataTypeConfigurer::CONFIGURE_ACTIVE, expected_types); - dtm_->set_priority_types(expected_types); - - dtm_->Configure(ModelTypeSet(BOOKMARKS), - syncer::CONFIGURE_REASON_BACKUP_ROLLBACK); -} - TEST_F(SyncDataTypeManagerImplTest, ReenableAfterDataTypeError) { AddController(PREFERENCES); // Will succeed. AddController(BOOKMARKS); // Will be disabled due to datatype error. diff --git a/components/sync_driver/device_info_service_unittest.cc b/components/sync_driver/device_info_service_unittest.cc index d9c89cf..7556519 100644 --- a/components/sync_driver/device_info_service_unittest.cc +++ b/components/sync_driver/device_info_service_unittest.cc @@ -55,7 +55,6 @@ void AssertEqual(const DeviceInfoSpecifics& s1, const DeviceInfoSpecifics& s2) { ASSERT_EQ(s1.device_type(), s2.device_type()); ASSERT_EQ(s1.sync_user_agent(), s2.sync_user_agent()); ASSERT_EQ(s1.chrome_version(), s2.chrome_version()); - ASSERT_EQ(s1.backup_timestamp(), s2.backup_timestamp()); ASSERT_EQ(s1.signin_scoped_device_id(), s2.signin_scoped_device_id()); } @@ -189,7 +188,6 @@ class DeviceInfoServiceTest : public testing::Test, base::StringPrintf("sync user agent %d", label)); specifics.set_chrome_version( base::StringPrintf("chrome version %d", label)); - specifics.set_backup_timestamp(label); specifics.set_signin_scoped_device_id( base::StringPrintf("signin scoped device id %d", label)); return specifics; @@ -275,7 +273,6 @@ TEST_F(DeviceInfoServiceTest, NonEmptyStoreLoad) { scoped_ptr<WriteBatch> batch = store()->CreateWriteBatch(); DeviceInfoSpecifics specifics(GenerateTestSpecifics()); - specifics.set_backup_timestamp(6); store()->WriteData(batch.get(), "tag", specifics.SerializeAsString()); store()->CommitWriteBatch(std::move(batch), base::Bind(&AssertResultIsSuccess)); diff --git a/components/sync_driver/device_info_sync_service.cc b/components/sync_driver/device_info_sync_service.cc index 77eaed4..009f6aa 100644 --- a/components/sync_driver/device_info_sync_service.cc +++ b/components/sync_driver/device_info_sync_service.cc @@ -59,8 +59,7 @@ void RecordDeviceIdChangedHistogram(const std::string& device_id_from_sync, DeviceInfoSyncService::DeviceInfoSyncService( LocalDeviceInfoProvider* local_device_info_provider) - : local_device_backup_time_(-1), - local_device_info_provider_(local_device_info_provider) { + : local_device_info_provider_(local_device_info_provider) { DCHECK(local_device_info_provider); } @@ -108,19 +107,6 @@ SyncMergeResult DeviceInfoSyncService::MergeDataAndStartSyncing( scoped_ptr<DeviceInfo> synced_local_device_info = make_scoped_ptr(CreateDeviceInfo(*iter)); - // Retrieve local device backup timestamp value from the sync data. - bool has_synced_backup_time = - iter->GetSpecifics().device_info().has_backup_timestamp(); - int64_t synced_backup_time = - has_synced_backup_time - ? iter->GetSpecifics().device_info().backup_timestamp() - : -1; - - // Overwrite |local_device_backup_time_| with this value if it - // hasn't been set yet. - if (!has_local_device_backup_time() && has_synced_backup_time) { - set_local_device_backup_time(synced_backup_time); - } // TODO(pavely): Remove histogram once device_id mismatch is understood // (crbug/481596). if (synced_local_device_info->signin_scoped_device_id() != @@ -130,12 +116,11 @@ SyncMergeResult DeviceInfoSyncService::MergeDataAndStartSyncing( local_device_info->signin_scoped_device_id()); } - // Store the synced device info for the local device only + // Store the synced device info for the local device only if // it is the same as the local info. Otherwise store the local // device info and issue a change further below after finishing // processing the |initial_sync_data|. - if (synced_local_device_info->Equals(*local_device_info) && - synced_backup_time == local_device_backup_time()) { + if (synced_local_device_info->Equals(*local_device_info)) { change_type = SyncChange::ACTION_INVALID; } else { num_items_updated++; @@ -185,7 +170,6 @@ void DeviceInfoSyncService::StopSyncing(syncer::ModelType type) { all_data_.clear(); sync_processor_.reset(); error_handler_.reset(); - clear_local_device_backup_time(); if (was_syncing) { NotifyObservers(); @@ -284,56 +268,6 @@ void DeviceInfoSyncService::NotifyObservers() { FOR_EACH_OBSERVER(Observer, observers_, OnDeviceInfoChange()); } -void DeviceInfoSyncService::UpdateLocalDeviceBackupTime( - base::Time backup_time) { - set_local_device_backup_time(syncer::TimeToProtoTime(backup_time)); - - if (sync_processor_.get()) { - // Local device info must be available in advance - DCHECK(local_device_info_provider_->GetLocalDeviceInfo()); - const std::string& local_id = - local_device_info_provider_->GetLocalDeviceInfo()->guid(); - - SyncDataMap::iterator iter = all_data_.find(local_id); - DCHECK(iter != all_data_.end()); - - syncer::SyncData& data = iter->second; - if (UpdateBackupTime(&data)) { - // Local device backup time has changed. - // Push changes to the server via the |sync_processor_|. - SyncChangeList change_list; - change_list.push_back(SyncChange( - FROM_HERE, syncer::SyncChange::ACTION_UPDATE, data)); - sync_processor_->ProcessSyncChanges(FROM_HERE, change_list); - } - } -} - -bool DeviceInfoSyncService::UpdateBackupTime(syncer::SyncData* sync_data) { - DCHECK(has_local_device_backup_time()); - DCHECK(sync_data->GetSpecifics().has_device_info()); - const sync_pb::DeviceInfoSpecifics& source_specifics = - sync_data->GetSpecifics().device_info(); - - if (!source_specifics.has_backup_timestamp() || - source_specifics.backup_timestamp() != local_device_backup_time()) { - sync_pb::EntitySpecifics entity(sync_data->GetSpecifics()); - entity.mutable_device_info()->set_backup_timestamp( - local_device_backup_time()); - *sync_data = CreateLocalData(entity); - - return true; - } - - return false; -} - -base::Time DeviceInfoSyncService::GetLocalDeviceBackupTime() const { - return has_local_device_backup_time() - ? syncer::ProtoTimeToTime(local_device_backup_time()) - : base::Time(); -} - SyncData DeviceInfoSyncService::CreateLocalData(const DeviceInfo* info) { sync_pb::EntitySpecifics entity; sync_pb::DeviceInfoSpecifics& specifics = *entity.mutable_device_info(); @@ -345,10 +279,6 @@ SyncData DeviceInfoSyncService::CreateLocalData(const DeviceInfo* info) { specifics.set_device_type(info->device_type()); specifics.set_signin_scoped_device_id(info->signin_scoped_device_id()); - if (has_local_device_backup_time()) { - specifics.set_backup_timestamp(local_device_backup_time()); - } - return CreateLocalData(entity); } diff --git a/components/sync_driver/device_info_sync_service.h b/components/sync_driver/device_info_sync_service.h index 7d529bb..6c82a12 100644 --- a/components/sync_driver/device_info_sync_service.h +++ b/components/sync_driver/device_info_sync_service.h @@ -52,13 +52,8 @@ class DeviceInfoSyncService : public syncer::SyncableService, void AddObserver(Observer* observer) override; void RemoveObserver(Observer* observer) override; - // Called to update local device backup time. - void UpdateLocalDeviceBackupTime(base::Time backup_time); - // Gets the most recently set local device backup time. - base::Time GetLocalDeviceBackupTime() const; - private: - // Create SyncData from local DeviceInfo and |local_device_backup_time_|. + // Create SyncData from local DeviceInfo. syncer::SyncData CreateLocalData(const DeviceInfo* info); // Create SyncData from EntitySpecifics. static syncer::SyncData CreateLocalData( @@ -74,25 +69,6 @@ class DeviceInfoSyncService : public syncer::SyncableService, // Notify all registered observers. void NotifyObservers(); - // Updates backup time in place in |sync_data| if it is different than - // the one stored in |local_device_backup_time_|. - // Returns true if backup time was updated. - bool UpdateBackupTime(syncer::SyncData* sync_data); - - // |local_device_backup_time_| accessors. - int64_t local_device_backup_time() const { return local_device_backup_time_; } - bool has_local_device_backup_time() const { - return local_device_backup_time_ >= 0; - } - void set_local_device_backup_time(int64_t value) { - local_device_backup_time_ = value; - } - void clear_local_device_backup_time() { local_device_backup_time_ = -1; } - - // Local device last set backup time (in proto format). - // -1 if the value hasn't been specified - int64_t local_device_backup_time_; - // |local_device_info_provider_| isn't owned. const LocalDeviceInfoProvider* const local_device_info_provider_; diff --git a/components/sync_driver/device_info_sync_service_unittest.cc b/components/sync_driver/device_info_sync_service_unittest.cc index 9592b71..2dffcbe 100644 --- a/components/sync_driver/device_info_sync_service_unittest.cc +++ b/components/sync_driver/device_info_sync_service_unittest.cc @@ -124,10 +124,6 @@ class DeviceInfoSyncServiceTest : public testing::Test, specifics.set_device_type(sync_pb::SyncEnums_DeviceType_TYPE_LINUX); specifics.set_signin_scoped_device_id("device_id"); - if (backup_timestamp != 0) { - specifics.set_backup_timestamp(backup_timestamp); - } - return SyncData::CreateRemoteData(1, entity, base::Time(), @@ -418,152 +414,6 @@ TEST_F(DeviceInfoSyncServiceTest, ProcessChangesAfterUnsubscribing) { EXPECT_EQ(0, num_device_info_changed_callbacks_); } -// Verifies setting backup timestamp after the initial sync. -TEST_F(DeviceInfoSyncServiceTest, UpdateLocalDeviceBackupTime) { - // Shouldn't have backuptime initially. - base::Time backup_time = sync_service_->GetLocalDeviceBackupTime(); - EXPECT_TRUE(backup_time.is_null()); - - // Perform the initial sync with empty data. - SyncMergeResult merge_result = - sync_service_->MergeDataAndStartSyncing(syncer::DEVICE_INFO, - SyncDataList(), - PassProcessor(), - CreateAndPassSyncErrorFactory()); - - // Should have local device after the initial sync. - EXPECT_EQ(1U, sync_processor_->change_list_size()); - EXPECT_EQ(SyncChange::ACTION_ADD, sync_processor_->change_type_at(0)); - - // Shouldn't have backup time initially. - EXPECT_EQ("guid_1", sync_processor_->cache_guid_at(0)); - EXPECT_FALSE(sync_processor_->device_info_at(0).has_backup_timestamp()); - - sync_service_->UpdateLocalDeviceBackupTime(base::Time::FromTimeT(1000)); - - // Should have local device info updated with the specified backup timestamp. - EXPECT_EQ(1U, sync_processor_->change_list_size()); - EXPECT_EQ(SyncChange::ACTION_UPDATE, sync_processor_->change_type_at(0)); - EXPECT_EQ("guid_1", sync_processor_->cache_guid_at(0)); - EXPECT_TRUE(sync_processor_->device_info_at(0).has_backup_timestamp()); - - backup_time = syncer::ProtoTimeToTime( - sync_processor_->device_info_at(0).backup_timestamp()); - EXPECT_EQ(1000, backup_time.ToTimeT()); - - // Also verify that we get the same backup time directly from the service. - backup_time = sync_service_->GetLocalDeviceBackupTime(); - EXPECT_EQ(1000, backup_time.ToTimeT()); -} - -// Verifies setting backup timestamp prior to the initial sync. -TEST_F(DeviceInfoSyncServiceTest, UpdateLocalDeviceBackupTimeBeforeSync) { - // Set the backup timestamp. - sync_service_->UpdateLocalDeviceBackupTime(base::Time::FromTimeT(2000)); - // Verify that we get it back. - base::Time backup_time = sync_service_->GetLocalDeviceBackupTime(); - EXPECT_EQ(2000, backup_time.ToTimeT()); - - // Now perform the initial sync with empty data. - SyncMergeResult merge_result = - sync_service_->MergeDataAndStartSyncing(syncer::DEVICE_INFO, - SyncDataList(), - PassProcessor(), - CreateAndPassSyncErrorFactory()); - - // Should have local device after the initial sync. - // Should have the backup timestamp set. - EXPECT_EQ(1U, sync_processor_->change_list_size()); - EXPECT_EQ(SyncChange::ACTION_ADD, sync_processor_->change_type_at(0)); - EXPECT_EQ("guid_1", sync_processor_->cache_guid_at(0)); - EXPECT_TRUE(sync_processor_->device_info_at(0).has_backup_timestamp()); - - backup_time = syncer::ProtoTimeToTime( - sync_processor_->device_info_at(0).backup_timestamp()); - EXPECT_EQ(2000, backup_time.ToTimeT()); -} - -// Verifies that the backup timestamp that comes in the intial sync data -// gets preserved when there are no changes to the local device. -TEST_F(DeviceInfoSyncServiceTest, PreserveBackupTimeWithMatchingLocalDevice) { - base::Time backup_time = base::Time::FromTimeT(3000); - SyncDataList sync_data; - sync_data.push_back(CreateRemoteData( - "guid_1", "client_1", syncer::TimeToProtoTime(backup_time))); - - SyncMergeResult merge_result = - sync_service_->MergeDataAndStartSyncing(syncer::DEVICE_INFO, - sync_data, - PassProcessor(), - CreateAndPassSyncErrorFactory()); - - // Everything is matching so there should be no updates. - EXPECT_EQ(0U, sync_processor_->change_list_size()); - - // Verify that we get back the same time. - backup_time = sync_service_->GetLocalDeviceBackupTime(); - EXPECT_EQ(3000, backup_time.ToTimeT()); -} - -// Verifies that the backup timestamp that comes in the intial sync data -// gets merged with the local device data. -TEST_F(DeviceInfoSyncServiceTest, MergeBackupTimeWithMatchingLocalDevice) { - base::Time backup_time = base::Time::FromTimeT(4000); - SyncDataList sync_data; - sync_data.push_back(CreateRemoteData( - "guid_1", "foo_1", syncer::TimeToProtoTime(backup_time))); - - SyncMergeResult merge_result = - sync_service_->MergeDataAndStartSyncing(syncer::DEVICE_INFO, - sync_data, - PassProcessor(), - CreateAndPassSyncErrorFactory()); - - // Should be one change because of the client name mismatch. - // However the backup time passed in the initial data should be merged into - // the change. - EXPECT_EQ(1U, sync_processor_->change_list_size()); - - EXPECT_EQ(SyncChange::ACTION_UPDATE, sync_processor_->change_type_at(0)); - EXPECT_EQ("guid_1", sync_processor_->cache_guid_at(0)); - EXPECT_EQ("client_1", sync_processor_->client_name_at(0)); - - backup_time = syncer::ProtoTimeToTime( - sync_processor_->device_info_at(0).backup_timestamp()); - EXPECT_EQ(4000, backup_time.ToTimeT()); -} - -// Verifies that mismatching backup timestamp generates an update even -// when the rest of local device data is matching. -TEST_F(DeviceInfoSyncServiceTest, - MergeMismatchingBackupTimeWithMatchingLocalDevice) { - base::Time backup_time = base::Time::FromTimeT(5000); - SyncDataList sync_data; - sync_data.push_back(CreateRemoteData( - "guid_1", "client_1", syncer::TimeToProtoTime(backup_time))); - - // Set the backup timestamp different than the one in the sync data. - sync_service_->UpdateLocalDeviceBackupTime(base::Time::FromTimeT(6000)); - - SyncMergeResult merge_result = - sync_service_->MergeDataAndStartSyncing(syncer::DEVICE_INFO, - sync_data, - PassProcessor(), - CreateAndPassSyncErrorFactory()); - - // Should generate and update due to timestamp mismatch. - // The locally set timestamp wins. - EXPECT_EQ(1U, sync_processor_->change_list_size()); - - EXPECT_EQ(SyncChange::ACTION_UPDATE, sync_processor_->change_type_at(0)); - EXPECT_EQ("guid_1", sync_processor_->cache_guid_at(0)); - EXPECT_EQ("client_1", sync_processor_->client_name_at(0)); - - backup_time = syncer::ProtoTimeToTime( - sync_processor_->device_info_at(0).backup_timestamp()); - EXPECT_EQ(6000, backup_time.ToTimeT()); -} - } // namespace } // namespace sync_driver diff --git a/components/sync_driver/fake_sync_client.cc b/components/sync_driver/fake_sync_client.cc index 2b65860..2dce0ce 100644 --- a/components/sync_driver/fake_sync_client.cc +++ b/components/sync_driver/fake_sync_client.cc @@ -12,8 +12,6 @@ namespace sync_driver { namespace { -void DummyClearBrowsingDataCallback(base::Time start, base::Time end) {} - void DummyRegisterPlatformTypesCallback(SyncService* sync_service, syncer::ModelTypeSet, syncer::ModelTypeSet) {} @@ -52,10 +50,6 @@ history::HistoryService* FakeSyncClient::GetHistoryService() { return nullptr; } -ClearBrowsingDataCallback FakeSyncClient::GetClearBrowsingDataCallback() { - return base::Bind(&DummyClearBrowsingDataCallback); -} - base::Closure FakeSyncClient::GetPasswordStateChangedCallback() { return base::Bind(&base::DoNothing); } diff --git a/components/sync_driver/fake_sync_client.h b/components/sync_driver/fake_sync_client.h index f394b6d..7aa7251 100644 --- a/components/sync_driver/fake_sync_client.h +++ b/components/sync_driver/fake_sync_client.h @@ -25,7 +25,6 @@ class FakeSyncClient : public SyncClient { bookmarks::BookmarkModel* GetBookmarkModel() override; favicon::FaviconService* GetFaviconService() override; history::HistoryService* GetHistoryService() override; - ClearBrowsingDataCallback GetClearBrowsingDataCallback() override; base::Closure GetPasswordStateChangedCallback() override; sync_driver::SyncApiComponentFactory::RegisterDataTypesMethod GetRegisterPlatformTypesCallback() override; diff --git a/components/sync_driver/glue/sync_backend_host_impl_unittest.cc b/components/sync_driver/glue/sync_backend_host_impl_unittest.cc index 1968558..f01f740 100644 --- a/components/sync_driver/glue/sync_backend_host_impl_unittest.cc +++ b/components/sync_driver/glue/sync_backend_host_impl_unittest.cc @@ -120,8 +120,7 @@ class MockSyncFrontend : public sync_driver::SyncFrontend { class FakeSyncManagerFactory : public syncer::SyncManagerFactory { public: explicit FakeSyncManagerFactory(FakeSyncManager** fake_manager) - : SyncManagerFactory(NORMAL), - fake_manager_(fake_manager) { + : fake_manager_(fake_manager) { *fake_manager_ = NULL; } ~FakeSyncManagerFactory() override {} diff --git a/components/sync_driver/pref_names.cc b/components/sync_driver/pref_names.cc index 550b927..ef7ab29 100644 --- a/components/sync_driver/pref_names.cc +++ b/components/sync_driver/pref_names.cc @@ -91,9 +91,6 @@ const char kSyncSessionsGUID[] = "sync.session_sync_guid"; const char kSyncSpareBootstrapToken[] = "sync.spare_bootstrap_token"; #endif // defined(OS_CHROMEOS) -// Stores how many times to try rollback before giving up. -const char kSyncRemainingRollbackTries[] = "sync.remaining_rollback_tries"; - // Stores the timestamp of first sync. const char kSyncFirstSyncTime[] = "sync.first_sync_time"; diff --git a/components/sync_driver/pref_names.h b/components/sync_driver/pref_names.h index 3209780..d3ecf97 100644 --- a/components/sync_driver/pref_names.h +++ b/components/sync_driver/pref_names.h @@ -64,7 +64,6 @@ extern const char kSyncSessionsGUID[]; extern const char kSyncSpareBootstrapToken[]; #endif // defined(OS_CHROMEOS) -extern const char kSyncRemainingRollbackTries[]; extern const char kSyncFirstSyncTime[]; extern const char kSyncPassphrasePrompted[]; diff --git a/components/sync_driver/startup_controller.cc b/components/sync_driver/startup_controller.cc index f22f31f..4db2bb2 100644 --- a/components/sync_driver/startup_controller.cc +++ b/components/sync_driver/startup_controller.cc @@ -159,10 +159,7 @@ bool StartupController::TryStart() { // defer the heavy lifting for sync init until things have calmed down. if (sync_prefs_->IsFirstSetupComplete()) { // For first time, defer start if data type hasn't requested sync to avoid - // stressing browser start. If |first_start_| is false, most likely the - // first attempt to start is intercepted by backup. When backup finishes, - // TryStart() is called again and we should start immediately to avoid - // unnecessary delay. + // stressing browser start. if (!received_start_request_ && first_start_) return StartUp(STARTUP_BACKEND_DEFERRED); else diff --git a/components/sync_driver/sync_client.h b/components/sync_driver/sync_client.h index a2e0558..2982a4d 100644 --- a/components/sync_driver/sync_client.h +++ b/components/sync_driver/sync_client.h @@ -9,7 +9,6 @@ #include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/memory/weak_ptr.h" -#include "base/time/time.h" #include "components/sync_driver/sync_api_component_factory.h" #include "sync/internal_api/public/base/model_type.h" #include "sync/internal_api/public/engine/model_safe_worker.h" @@ -52,8 +51,6 @@ namespace sync_driver { class SyncService; -typedef base::Callback<void(base::Time, base::Time)> ClearBrowsingDataCallback; - // Interface for clients of the Sync API to plumb through necessary dependent // components. This interface is purely for abstracting dependencies, and // should not contain any non-trivial functional logic. @@ -79,10 +76,6 @@ class SyncClient { virtual favicon::FaviconService* GetFaviconService() = 0; virtual history::HistoryService* GetHistoryService() = 0; - // Returns a callback that will be invoked when the sync service wishes to - // have browsing data cleared. - virtual ClearBrowsingDataCallback GetClearBrowsingDataCallback() = 0; - // Returns a callback that will register the types specific to the current // platform. virtual sync_driver::SyncApiComponentFactory::RegisterDataTypesMethod diff --git a/components/sync_driver/sync_driver_switches.cc b/components/sync_driver/sync_driver_switches.cc index 15cde97..498a82b 100644 --- a/components/sync_driver/sync_driver_switches.cc +++ b/components/sync_driver/sync_driver_switches.cc @@ -10,16 +10,10 @@ namespace switches { const char kSyncDeferredStartupTimeoutSeconds[] = "sync-deferred-startup-timeout-seconds"; -// Disable data backup when user's not signed in. -const char kSyncDisableBackup[] = "disable-sync-backup"; - // Enables deferring sync backend initialization until user initiated changes // occur. const char kSyncDisableDeferredStartup[] = "sync-disable-deferred-startup"; -// Disable sync rollback. -const char kSyncDisableRollback[] = "disable-sync-rollback"; - // Enables clearing of sync data when a user enables passphrase encryption. const char kSyncEnableClearDataOnPassphraseEncryption[] = "enable-clear-sync-data-on-passphrase-encryption"; diff --git a/components/sync_driver/sync_driver_switches.h b/components/sync_driver/sync_driver_switches.h index caeb038..9528aa6 100644 --- a/components/sync_driver/sync_driver_switches.h +++ b/components/sync_driver/sync_driver_switches.h @@ -12,9 +12,7 @@ namespace switches { // All switches in alphabetical order. The switches should be documented // alongside the definition of their values in the .cc file. extern const char kSyncDeferredStartupTimeoutSeconds[]; -extern const char kSyncDisableBackup[]; extern const char kSyncDisableDeferredStartup[]; -extern const char kSyncDisableRollback[]; extern const char kSyncEnableClearDataOnPassphraseEncryption[]; extern const char kSyncEnableGetUpdateAvoidance[]; extern const char kSyncEnableUSSDeviceInfo[]; diff --git a/components/sync_driver/sync_prefs.cc b/components/sync_driver/sync_prefs.cc index e029142..185a122 100644 --- a/components/sync_driver/sync_prefs.cc +++ b/components/sync_driver/sync_prefs.cc @@ -79,7 +79,6 @@ void SyncPrefs::RegisterProfilePrefs( registry->RegisterBooleanPref(prefs::kSyncHasAuthError, false); registry->RegisterStringPref(prefs::kSyncSessionsGUID, std::string()); - registry->RegisterIntegerPref(prefs::kSyncRemainingRollbackTries, 0); registry->RegisterBooleanPref(prefs::kSyncPassphrasePrompted, false); registry->RegisterIntegerPref(prefs::kSyncMemoryPressureWarningCount, -1); registry->RegisterBooleanPref(prefs::kSyncShutdownCleanly, false); @@ -337,14 +336,6 @@ void SyncPrefs::SetSpareBootstrapToken(const std::string& token) { } #endif -int SyncPrefs::GetRemainingRollbackTries() const { - return pref_service_->GetInteger(prefs::kSyncRemainingRollbackTries); -} - -void SyncPrefs::SetRemainingRollbackTries(int times) { - pref_service_->SetInteger(prefs::kSyncRemainingRollbackTries, times); -} - void SyncPrefs::OnSyncManagedPrefChanged() { DCHECK(CalledOnValidThread()); FOR_EACH_OBSERVER(SyncPrefObserver, diff --git a/components/sync_driver/sync_prefs.h b/components/sync_driver/sync_prefs.h index 96f1a8e..4f2c65e 100644 --- a/components/sync_driver/sync_prefs.h +++ b/components/sync_driver/sync_prefs.h @@ -133,10 +133,6 @@ class SyncPrefs : NON_EXPORTED_BASE(public base::NonThreadSafe), void SetSpareBootstrapToken(const std::string& token); #endif - // Get/Set number of rollback attempts allowed. - virtual int GetRemainingRollbackTries() const; - virtual void SetRemainingRollbackTries(int times); - // Get/set/clear first sync time of current user. Used to roll back browsing // data later when user signs out. base::Time GetFirstSyncTime() const; diff --git a/components/sync_driver/sync_service.h b/components/sync_driver/sync_service.h index e722444..76efc25 100644 --- a/components/sync_driver/sync_service.h +++ b/components/sync_driver/sync_service.h @@ -99,8 +99,6 @@ class SyncService : public DataTypeEncryptionHandler { // an initial configuration has successfully completed, although there may // be datatype specific, auth, or other transient errors. To see which // datetypes are actually syncing, see GetActiveTypes() below. - // Note that if sync is in backup or rollback mode, IsSyncActive() will be - // false. virtual bool IsSyncActive() const = 0; // Triggers a GetUpdates call for the specified |types|, pulling any new data diff --git a/components/user_prefs/tracked/pref_hash_filter.cc b/components/user_prefs/tracked/pref_hash_filter.cc index 6d8e628..a9b4183 100644 --- a/components/user_prefs/tracked/pref_hash_filter.cc +++ b/components/user_prefs/tracked/pref_hash_filter.cc @@ -36,6 +36,8 @@ void CleanupDeprecatedTrackedPreferences( "safebrowsing.incident_report_sent", // TODO(mad): Remove in M48+. "software_reporter.prompt_reason", + // TODO(zea): Remove in M52+, + "sync.remaining_rollback_tries" }; for (size_t i = 0; i < arraysize(kDeprecatedTrackedPreferences); ++i) { diff --git a/ios/chrome/browser/sync/ios_chrome_sync_client.h b/ios/chrome/browser/sync/ios_chrome_sync_client.h index d1535f8..a398c71 100644 --- a/ios/chrome/browser/sync/ios_chrome_sync_client.h +++ b/ios/chrome/browser/sync/ios_chrome_sync_client.h @@ -38,8 +38,6 @@ class IOSChromeSyncClient : public sync_driver::SyncClient { bookmarks::BookmarkModel* GetBookmarkModel() override; favicon::FaviconService* GetFaviconService() override; history::HistoryService* GetHistoryService() override; - sync_driver::ClearBrowsingDataCallback GetClearBrowsingDataCallback() - override; base::Closure GetPasswordStateChangedCallback() override; sync_driver::SyncApiComponentFactory::RegisterDataTypesMethod GetRegisterPlatformTypesCallback() override; diff --git a/ios/chrome/browser/sync/ios_chrome_sync_client.mm b/ios/chrome/browser/sync/ios_chrome_sync_client.mm index dc5b80e..89007d3 100644 --- a/ios/chrome/browser/sync/ios_chrome_sync_client.mm +++ b/ios/chrome/browser/sync/ios_chrome_sync_client.mm @@ -199,12 +199,6 @@ autofill::PersonalDataManager* IOSChromeSyncClient::GetPersonalDataManager() { return PersonalDataManagerFactory::GetForBrowserState(browser_state_); } -sync_driver::ClearBrowsingDataCallback -IOSChromeSyncClient::GetClearBrowsingDataCallback() { - return base::Bind(&IOSChromeSyncClient::ClearBrowsingData, - base::Unretained(this)); -} - base::Closure IOSChromeSyncClient::GetPasswordStateChangedCallback() { return base::Bind( &IOSChromePasswordStoreFactory::OnPasswordsSyncedStatePotentiallyChanged, @@ -384,11 +378,6 @@ IOSChromeSyncClient::GetSyncApiComponentFactory() { return component_factory_.get(); } -void IOSChromeSyncClient::ClearBrowsingData(base::Time start, base::Time end) { - // This method should never be called on iOS. - NOTREACHED(); -} - void IOSChromeSyncClient::SetSyncApiComponentFactoryForTesting( scoped_ptr<sync_driver::SyncApiComponentFactory> component_factory) { component_factory_ = std::move(component_factory); diff --git a/sync/BUILD.gn b/sync/BUILD.gn index dfa0fae..f28fee8 100644 --- a/sync/BUILD.gn +++ b/sync/BUILD.gn @@ -297,8 +297,6 @@ source_set("sync_core") { "internal_api/read_node.cc", "internal_api/read_transaction.cc", "internal_api/shared_model_type_processor.cc", - "internal_api/sync_backup_manager.cc", - "internal_api/sync_backup_manager.h", "internal_api/sync_context.cc", "internal_api/sync_context_proxy.cc", "internal_api/sync_context_proxy_impl.cc", @@ -309,10 +307,6 @@ source_set("sync_core") { "internal_api/sync_manager_factory.cc", "internal_api/sync_manager_impl.cc", "internal_api/sync_manager_impl.h", - "internal_api/sync_rollback_manager.cc", - "internal_api/sync_rollback_manager.h", - "internal_api/sync_rollback_manager_base.cc", - "internal_api/sync_rollback_manager_base.h", "internal_api/syncapi_internal.cc", "internal_api/syncapi_internal.h", "internal_api/syncapi_server_connection_manager.cc", @@ -348,8 +342,6 @@ source_set("sync_core") { "sessions/sync_session.h", "sessions/sync_session_context.cc", "sessions/sync_session_context.h", - "syncable/deferred_on_disk_directory_backing_store.cc", - "syncable/deferred_on_disk_directory_backing_store.h", "syncable/dir_open_result.h", "syncable/directory.cc", "syncable/directory.h", @@ -666,12 +658,9 @@ test("sync_unit_tests") { "internal_api/public/util/proto_value_ptr_unittest.cc", "internal_api/public/util/weak_handle_unittest.cc", "internal_api/shared_model_type_processor_unittest.cc", - "internal_api/sync_backup_manager_unittest.cc", "internal_api/sync_context_proxy_impl_unittest.cc", "internal_api/sync_encryption_handler_impl_unittest.cc", "internal_api/sync_manager_impl_unittest.cc", - "internal_api/sync_rollback_manager_base_unittest.cc", - "internal_api/sync_rollback_manager_unittest.cc", "internal_api/syncapi_server_connection_manager_unittest.cc", "js/js_event_details_unittest.cc", "js/sync_js_controller_unittest.cc", @@ -680,7 +669,6 @@ test("sync_unit_tests") { "sessions/model_type_registry_unittest.cc", "sessions/nudge_tracker_unittest.cc", "sessions/status_controller_unittest.cc", - "syncable/deferred_on_disk_directory_backing_store_unittest.cc", "syncable/directory_backing_store_unittest.cc", "syncable/directory_unittest.cc", "syncable/directory_unittest.h", diff --git a/sync/engine/sync_scheduler_impl.cc b/sync/engine/sync_scheduler_impl.cc index f126473..cc5e4a7 100644 --- a/sync/engine/sync_scheduler_impl.cc +++ b/sync/engine/sync_scheduler_impl.cc @@ -58,7 +58,6 @@ bool ShouldRequestEarlyExit(const SyncProtocolError& error) { case CLIENT_DATA_OBSOLETE: case CLEAR_PENDING: case DISABLED_BY_ADMIN: - case USER_ROLLBACK: // If we send terminate sync early then |sync_cycle_ended| notification // would not be sent. If there were no actions then |ACTIONABLE_ERROR| // notification wouldnt be sent either. Then the UI layer would be left diff --git a/sync/engine/syncer_proto_util.cc b/sync/engine/syncer_proto_util.cc index 306137b..66c4013 100644 --- a/sync/engine/syncer_proto_util.cc +++ b/sync/engine/syncer_proto_util.cc @@ -124,8 +124,6 @@ SyncProtocolErrorType PBErrorTypeToSyncProtocolErrorType( return MIGRATION_DONE; case sync_pb::SyncEnums::DISABLED_BY_ADMIN: return DISABLED_BY_ADMIN; - case sync_pb::SyncEnums::USER_ROLLBACK: - return USER_ROLLBACK; case sync_pb::SyncEnums::PARTIAL_FAILURE: return PARTIAL_FAILURE; case sync_pb::SyncEnums::CLIENT_DATA_OBSOLETE: @@ -193,8 +191,6 @@ SyncProtocolError ErrorCodeToSyncProtocolError( error.action = RESET_LOCAL_SYNC_DATA; } else if (error_type == sync_pb::SyncEnums::DISABLED_BY_ADMIN) { error.action = STOP_SYNC_FOR_DISABLED_ACCOUNT; - } else if (error_type == sync_pb::SyncEnums::USER_ROLLBACK) { - error.action = DISABLE_SYNC_AND_ROLLBACK; } // There is no other action we can compute for legacy server. return error; } @@ -498,8 +494,6 @@ SyncerError SyncerProtoUtil::PostClientToServerMessage( return SERVER_RETURN_NOT_MY_BIRTHDAY; case DISABLED_BY_ADMIN: return SERVER_RETURN_DISABLED_BY_ADMIN; - case USER_ROLLBACK: - return SERVER_RETURN_USER_ROLLBACK; case PARTIAL_FAILURE: // This only happens when partial throttling during GetUpdates. if (!sync_protocol_error.error_data_types.Empty()) { diff --git a/sync/internal_api/internal_components_factory_impl.cc b/sync/internal_api/internal_components_factory_impl.cc index 4f2f32e..65fcfaf 100644 --- a/sync/internal_api/internal_components_factory_impl.cc +++ b/sync/internal_api/internal_components_factory_impl.cc @@ -11,7 +11,6 @@ #include "sync/engine/syncer.h" #include "sync/engine/sync_scheduler_impl.h" #include "sync/sessions/sync_session_context.h" -#include "sync/syncable/deferred_on_disk_directory_backing_store.h" #include "sync/syncable/on_disk_directory_backing_store.h" using base::TimeDelta; @@ -68,10 +67,6 @@ InternalComponentsFactoryImpl::BuildDirectoryBackingStore( if (storage == STORAGE_ON_DISK) { return scoped_ptr<syncable::DirectoryBackingStore>( new syncable::OnDiskDirectoryBackingStore(dir_name, backing_filepath)); - } else if (storage == STORAGE_ON_DISK_DEFERRED) { - return scoped_ptr<syncable::DirectoryBackingStore>( - new syncable::DeferredOnDiskDirectoryBackingStore(dir_name, - backing_filepath)); } else { NOTREACHED(); return scoped_ptr<syncable::DirectoryBackingStore>(); diff --git a/sync/internal_api/public/configure_reason.h b/sync/internal_api/public/configure_reason.h index 8fbbc4e..4d015b9 100644 --- a/sync/internal_api/public/configure_reason.h +++ b/sync/internal_api/public/configure_reason.h @@ -33,9 +33,6 @@ enum ConfigureReason { // cryptographer errors/resolutions. CONFIGURE_REASON_CRYPTO, - // Configure data types for backup/rollback. - CONFIGURE_REASON_BACKUP_ROLLBACK, - // The client is configuring because of a programmatic type enable/disable, // such as when an error is encountered/resolved. CONFIGURE_REASON_PROGRAMMATIC, diff --git a/sync/internal_api/public/internal_components_factory.h b/sync/internal_api/public/internal_components_factory.h index f077af0..fee9bec 100644 --- a/sync/internal_api/public/internal_components_factory.h +++ b/sync/internal_api/public/internal_components_factory.h @@ -80,9 +80,6 @@ class SYNC_EXPORT InternalComponentsFactory { // Use this if you want BuildDirectoryBackingStore to create/use a real // on disk store. STORAGE_ON_DISK, - // Use this to defer creating on-disk database until - // DirectoryBackingStore::SaveChanges() is called. - STORAGE_ON_DISK_DEFERRED, // Use this to test the case where a directory fails to load. STORAGE_INVALID }; diff --git a/sync/internal_api/public/shutdown_reason.h b/sync/internal_api/public/shutdown_reason.h index f913eec..604dc0e 100644 --- a/sync/internal_api/public/shutdown_reason.h +++ b/sync/internal_api/public/shutdown_reason.h @@ -14,8 +14,6 @@ enum ShutdownReason { STOP_SYNC, // Sync is asked to stop, e.g. due to scarce resource. DISABLE_SYNC, // Sync is disabled, e.g. user sign out, dashboard clear. BROWSER_SHUTDOWN, // Browser is closed. - SWITCH_MODE_SYNC, // Engine is shut down and a new engine will start in - // sync mode. }; } // namespace syncer diff --git a/sync/internal_api/public/sync_manager_factory.h b/sync/internal_api/public/sync_manager_factory.h index ef6ee6b..feb9e8b 100644 --- a/sync/internal_api/public/sync_manager_factory.h +++ b/sync/internal_api/public/sync_manager_factory.h @@ -15,22 +15,15 @@ namespace syncer { class SyncManager; -// Helper class to allow dependency injection of the SyncManager. +// Helper class to allow dependency injection of the SyncManager in tests. class SYNC_EXPORT SyncManagerFactory { public: - enum MANAGER_TYPE { - NORMAL, // Normal sync manager - BACKUP, // Backup sync manager - ROLLBACK, // Rollback sync manager - }; - - explicit SyncManagerFactory(MANAGER_TYPE type); + SyncManagerFactory(); virtual ~SyncManagerFactory(); virtual scoped_ptr<SyncManager> CreateSyncManager(const std::string& name); private: - MANAGER_TYPE type_; DISALLOW_COPY_AND_ASSIGN(SyncManagerFactory); }; diff --git a/sync/internal_api/sync_backup_manager.cc b/sync/internal_api/sync_backup_manager.cc deleted file mode 100644 index 9151e52..0000000 --- a/sync/internal_api/sync_backup_manager.cc +++ /dev/null @@ -1,151 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "sync/internal_api/sync_backup_manager.h" - -#include <stdint.h> - -#include <vector> - -#include "sync/internal_api/public/read_node.h" -#include "sync/internal_api/public/write_transaction.h" -#include "sync/syncable/directory.h" -#include "sync/syncable/mutable_entry.h" -#include "url/gurl.h" - -namespace syncer { - -SyncBackupManager::SyncBackupManager() - : in_normalization_(false) { -} - -SyncBackupManager::~SyncBackupManager() { -} - -void SyncBackupManager::Init(InitArgs* args) { - if (SyncRollbackManagerBase::InitInternal( - args->database_location, - args->internal_components_factory.get(), - InternalComponentsFactory::STORAGE_ON_DISK_DEFERRED, - args->unrecoverable_error_handler, - args->report_unrecoverable_error_function)) { - GetUserShare()->directory->CollectMetaHandleCounts( - &status_.num_entries_by_type, &status_.num_to_delete_entries_by_type); - - HideSyncPreference(PRIORITY_PREFERENCES); - HideSyncPreference(PREFERENCES); - } -} - -void SyncBackupManager::SaveChanges() { - if (initialized()) - NormalizeEntries(); -} - -SyncStatus SyncBackupManager::GetDetailedStatus() const { - return status_; -} - -ModelTypeSet SyncBackupManager::HandleTransactionEndingChangeEvent( - const syncable::ImmutableWriteTransactionInfo& write_transaction_info, - syncable::BaseTransaction* trans) { - ModelTypeSet types; - if (in_normalization_) { - // Skip if in our own WriteTransaction from NormalizeEntries(). - in_normalization_ = false; - return types; - } - - for (syncable::EntryKernelMutationMap::const_iterator it = - write_transaction_info.Get().mutations.Get().begin(); - it != write_transaction_info.Get().mutations.Get().end(); ++it) { - int64_t id = it->first; - if (unsynced_.find(id) == unsynced_.end()) { - unsynced_.insert(id); - - const syncable::EntryKernel& e = it->second.mutated; - ModelType type = e.GetModelType(); - types.Put(type); - if (!e.ref(syncable::ID).ServerKnows()) - status_.num_entries_by_type[type]++; - if (e.ref(syncable::IS_DEL)) - status_.num_to_delete_entries_by_type[type]++; - } - } - return types; -} - -void SyncBackupManager::NormalizeEntries() { - WriteTransaction trans(FROM_HERE, GetUserShare()); - in_normalization_ = true; - for (std::set<int64_t>::const_iterator it = unsynced_.begin(); - it != unsynced_.end(); ++it) { - syncable::MutableEntry entry(trans.GetWrappedWriteTrans(), - syncable::GET_BY_HANDLE, *it); - CHECK(entry.good()); - - if (!entry.GetId().ServerKnows()) - entry.PutId(syncable::Id::CreateFromServerId(entry.GetId().value())); - if (!entry.GetParentId().IsNull() && !entry.GetParentId().ServerKnows()) { - entry.PutParentIdPropertyOnly(syncable::Id::CreateFromServerId( - entry.GetParentId().value())); - } - entry.PutBaseVersion(1); - entry.PutIsUnsynced(false); - } - unsynced_.clear(); -} - -void SyncBackupManager::HideSyncPreference(ModelType type) { - WriteTransaction trans(FROM_HERE, GetUserShare()); - ReadNode pref_root(&trans); - if (BaseNode::INIT_OK != pref_root.InitTypeRoot(type)) - return; - - std::vector<int64_t> pref_ids; - pref_root.GetChildIds(&pref_ids); - for (uint32_t i = 0; i < pref_ids.size(); ++i) { - syncable::MutableEntry entry(trans.GetWrappedWriteTrans(), - syncable::GET_BY_HANDLE, pref_ids[i]); - if (entry.good()) { - // HACKY: Set IS_DEL to true to remove entry from parent-children - // index so that it's not returned when syncable service asks - // for sync data. Syncable service then creates entry for local - // model. Then the existing entry is undeleted and set to local value - // because it has the same unique client tag. - entry.PutIsDel(true); - entry.PutIsUnsynced(false); - - // Don't persist on disk so that if backup is aborted before receiving - // local preference values, values in sync DB are saved. - GetUserShare()->directory->UnmarkDirtyEntry( - trans.GetWrappedWriteTrans(), &entry); - } - } -} - -void SyncBackupManager::ShutdownOnSyncThread(ShutdownReason reason) { - if (reason == SWITCH_MODE_SYNC) { - NormalizeEntries(); - GetUserShare()->directory->SaveChanges(); - } - - SyncRollbackManagerBase::ShutdownOnSyncThread(reason); -} - -void SyncBackupManager::RegisterDirectoryTypeDebugInfoObserver( - syncer::TypeDebugInfoObserver* observer) {} - -void SyncBackupManager::UnregisterDirectoryTypeDebugInfoObserver( - syncer::TypeDebugInfoObserver* observer) {} - -bool SyncBackupManager::HasDirectoryTypeDebugInfoObserver( - syncer::TypeDebugInfoObserver* observer) { return false; } - -void SyncBackupManager::RequestEmitDebugInfo() {} - -void SyncBackupManager::ClearServerData( - const ClearServerDataCallback& callback) {} - -} // namespace syncer diff --git a/sync/internal_api/sync_backup_manager.h b/sync/internal_api/sync_backup_manager.h deleted file mode 100644 index e7e50fa..0000000 --- a/sync/internal_api/sync_backup_manager.h +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef SYNC_INTERNAL_API_SYNC_BACKUP_MANAGER_H_ -#define SYNC_INTERNAL_API_SYNC_BACKUP_MANAGER_H_ - -#include <stdint.h> - -#include <set> - -#include "base/macros.h" -#include "sync/internal_api/sync_rollback_manager_base.h" -#include "url/gurl.h" - -namespace syncer { - -// SyncBackupManager runs before user signs in to sync to back up user's data -// before sync starts. The data that's backed up can be used to restore user's -// settings to pre-sync state. -class SYNC_EXPORT SyncBackupManager : public SyncRollbackManagerBase { - public: - SyncBackupManager(); - ~SyncBackupManager() override; - - // SyncManager implementation. - void Init(InitArgs* args) override; - void SaveChanges() override; - SyncStatus GetDetailedStatus() const override; - void ShutdownOnSyncThread(ShutdownReason reason) override; - - // DirectoryChangeDelegate implementation. - ModelTypeSet HandleTransactionEndingChangeEvent( - const syncable::ImmutableWriteTransactionInfo& write_transaction_info, - syncable::BaseTransaction* trans) override; - - void RegisterDirectoryTypeDebugInfoObserver( - syncer::TypeDebugInfoObserver* observer) override; - void UnregisterDirectoryTypeDebugInfoObserver( - syncer::TypeDebugInfoObserver* observer) override; - bool HasDirectoryTypeDebugInfoObserver( - syncer::TypeDebugInfoObserver* observer) override; - void RequestEmitDebugInfo() override; - void ClearServerData(const ClearServerDataCallback& callback) override; - - private: - // Replaces local IDs with server IDs and clear unsynced bit of modified - // entries. - void NormalizeEntries(); - - // Manipulate preference nodes so that they'll be overwritten by local - // preference values during model association, i.e. local wins instead of - // server wins. This is for preventing backup from changing preferences in - // case backup DB has hijacked preferences. - void HideSyncPreference(ModelType pref_type); - - // Handles of unsynced entries caused by local model changes. - std::set<int64_t> unsynced_; - - // True if NormalizeEntries() is being called. - bool in_normalization_; - - SyncStatus status_; - - DISALLOW_COPY_AND_ASSIGN(SyncBackupManager); -}; - -} // namespace syncer - -#endif // SYNC_INTERNAL_API_SYNC_BACKUP_MANAGER_H_ diff --git a/sync/internal_api/sync_backup_manager_unittest.cc b/sync/internal_api/sync_backup_manager_unittest.cc deleted file mode 100644 index 919356d..0000000 --- a/sync/internal_api/sync_backup_manager_unittest.cc +++ /dev/null @@ -1,185 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "sync/internal_api/sync_backup_manager.h" - -#include <string> - -#include "base/files/scoped_temp_dir.h" -#include "base/run_loop.h" -#include "sync/internal_api/public/read_node.h" -#include "sync/internal_api/public/read_transaction.h" -#include "sync/internal_api/public/sessions/sync_session_snapshot.h" -#include "sync/internal_api/public/test/test_internal_components_factory.h" -#include "sync/internal_api/public/write_node.h" -#include "sync/internal_api/public/write_transaction.h" -#include "sync/syncable/entry.h" -#include "sync/test/test_directory_backing_store.h" -#include "testing/gmock/include/gmock/gmock.h" -#include "testing/gtest/include/gtest/gtest.h" -#include "url/gurl.h" - -using ::testing::_; -using ::testing::Invoke; -using ::testing::WithArgs; - -namespace syncer { - -namespace { - -void OnConfigDone(bool success) { - EXPECT_TRUE(success); -} - -class SyncBackupManagerTest : public syncer::SyncManager::Observer, - public testing::Test { - public: - MOCK_METHOD1(OnSyncCycleCompleted, - void(const sessions::SyncSessionSnapshot&)); - MOCK_METHOD1(OnConnectionStatusChange, void(ConnectionStatus)); - MOCK_METHOD1(OnActionableError, void(const SyncProtocolError&)); - MOCK_METHOD1(OnMigrationRequested, void(ModelTypeSet)); - MOCK_METHOD1(OnProtocolEvent, void(const ProtocolEvent&)); - MOCK_METHOD4(OnInitializationComplete, - void(const WeakHandle<JsBackend>&, - const WeakHandle<DataTypeDebugInfoListener>&, - bool, ModelTypeSet)); - - protected: - void SetUp() override { - CHECK(temp_dir_.CreateUniqueTempDir()); - } - - void InitManager(SyncManager* manager, - InternalComponentsFactory::StorageOption storage_option) { - manager_ = manager; - EXPECT_CALL(*this, OnInitializationComplete(_, _, _, _)) - .WillOnce(WithArgs<2>(Invoke(this, - &SyncBackupManagerTest::HandleInit))); - - manager->AddObserver(this); - - base::RunLoop run_loop; - - SyncManager::InitArgs args; - args.database_location = temp_dir_.path(); - args.event_handler = MakeWeakHandle(base::WeakPtr<JsEventHandler>()); - args.service_url = GURL("https://example.com/"); - args.post_factory = scoped_ptr<HttpPostProviderFactory>(); - args.internal_components_factory.reset(new TestInternalComponentsFactory( - InternalComponentsFactory::Switches(), storage_option, - &storage_used_)); - manager->Init(&args); - EXPECT_EQ(InternalComponentsFactory::STORAGE_ON_DISK_DEFERRED, - storage_used_); - loop_.PostTask(FROM_HERE, run_loop.QuitClosure()); - run_loop.Run(); - } - - void CreateEntry(UserShare* user_share, ModelType type, - const std::string& client_tag) { - WriteTransaction trans(FROM_HERE, user_share); - - WriteNode node(&trans); - EXPECT_EQ(WriteNode::INIT_SUCCESS, - node.InitUniqueByCreation(type, client_tag)); - } - - void ConfigureSyncer() { - manager_->ConfigureSyncer(CONFIGURE_REASON_NEW_CLIENT, - ModelTypeSet(SEARCH_ENGINES), - ModelTypeSet(), ModelTypeSet(), ModelTypeSet(), - ModelSafeRoutingInfo(), - base::Bind(&OnConfigDone, true), - base::Bind(&OnConfigDone, false)); - } - - void HandleInit(bool success) { - if (success) { - loop_.PostTask(FROM_HERE, - base::Bind(&SyncBackupManagerTest::ConfigureSyncer, - base::Unretained(this))); - } else { - manager_->ShutdownOnSyncThread(STOP_SYNC); - } - } - - base::ScopedTempDir temp_dir_; - base::MessageLoop loop_; // Needed for WeakHandle - SyncManager* manager_; - InternalComponentsFactory::StorageOption storage_used_; -}; - -TEST_F(SyncBackupManagerTest, NormalizeEntry) { - scoped_ptr<SyncBackupManager> manager(new SyncBackupManager); - InitManager(manager.get(), InternalComponentsFactory::STORAGE_IN_MEMORY); - - CreateEntry(manager->GetUserShare(), SEARCH_ENGINES, "test"); - - { - // New entry is local and unsynced at first. - ReadTransaction trans(FROM_HERE, manager->GetUserShare()); - ReadNode pref(&trans); - EXPECT_EQ(BaseNode::INIT_OK, - pref.InitByClientTagLookup(SEARCH_ENGINES, "test")); - EXPECT_FALSE(pref.GetEntry()->GetId().ServerKnows()); - EXPECT_TRUE(pref.GetEntry()->GetIsUnsynced()); - } - - manager->SaveChanges(); - - { - // New entry has server ID and unsynced bit is cleared after saving. - ReadTransaction trans(FROM_HERE, manager->GetUserShare()); - ReadNode pref(&trans); - EXPECT_EQ(BaseNode::INIT_OK, - pref.InitByClientTagLookup(SEARCH_ENGINES, "test")); - EXPECT_TRUE(pref.GetEntry()->GetId().ServerKnows()); - EXPECT_FALSE(pref.GetEntry()->GetIsUnsynced()); - } -} - -TEST_F(SyncBackupManagerTest, PersistWithSwitchToSyncShutdown) { - scoped_ptr<SyncBackupManager> manager(new SyncBackupManager); - InitManager(manager.get(), - InternalComponentsFactory::STORAGE_ON_DISK_DEFERRED); - - CreateEntry(manager->GetUserShare(), SEARCH_ENGINES, "test"); - manager->SaveChanges(); - manager->ShutdownOnSyncThread(SWITCH_MODE_SYNC); - - // Reopen db to verify entry is persisted. - manager.reset(new SyncBackupManager); - InitManager(manager.get(), InternalComponentsFactory::STORAGE_ON_DISK); - { - ReadTransaction trans(FROM_HERE, manager->GetUserShare()); - ReadNode pref(&trans); - EXPECT_EQ(BaseNode::INIT_OK, - pref.InitByClientTagLookup(SEARCH_ENGINES, "test")); - EXPECT_TRUE(pref.GetEntry()->GetId().ServerKnows()); - EXPECT_FALSE(pref.GetEntry()->GetIsUnsynced()); - } -} - -TEST_F(SyncBackupManagerTest, DontPersistWithOtherShutdown) { - scoped_ptr<SyncBackupManager> manager(new SyncBackupManager); - InitManager(manager.get(), - InternalComponentsFactory::STORAGE_ON_DISK_DEFERRED); - - CreateEntry(manager->GetUserShare(), SEARCH_ENGINES, "test"); - manager->SaveChanges(); - manager->ShutdownOnSyncThread(STOP_SYNC); - EXPECT_FALSE(base::PathExists( - temp_dir_.path().Append(syncable::Directory::kSyncDatabaseFilename))); -} - -TEST_F(SyncBackupManagerTest, FailToInitialize) { - // Test graceful shutdown on initialization failure. - scoped_ptr<SyncBackupManager> manager(new SyncBackupManager); - InitManager(manager.get(), InternalComponentsFactory::STORAGE_INVALID); -} - -} // anonymous namespace - -} // namespace syncer diff --git a/sync/internal_api/sync_manager_factory.cc b/sync/internal_api/sync_manager_factory.cc index 288b5da..48ff69d 100644 --- a/sync/internal_api/sync_manager_factory.cc +++ b/sync/internal_api/sync_manager_factory.cc @@ -4,32 +4,18 @@ #include "sync/internal_api/public/sync_manager_factory.h" -#include "sync/internal_api/sync_backup_manager.h" #include "sync/internal_api/sync_manager_impl.h" -#include "sync/internal_api/sync_rollback_manager.h" namespace syncer { -SyncManagerFactory::SyncManagerFactory(SyncManagerFactory::MANAGER_TYPE type) - : type_(type) { -} +SyncManagerFactory::SyncManagerFactory() {} SyncManagerFactory::~SyncManagerFactory() { } scoped_ptr<SyncManager> SyncManagerFactory::CreateSyncManager( const std::string& name) { - switch (type_) { - case NORMAL: - return scoped_ptr<SyncManager>(new SyncManagerImpl(name)); - case BACKUP: - return scoped_ptr<SyncManager>(new SyncBackupManager()); - case ROLLBACK: - return scoped_ptr<SyncManager>(new SyncRollbackManager()); - default: - NOTREACHED(); - return scoped_ptr<SyncManager>(new SyncManagerImpl(name)); - } + return scoped_ptr<SyncManager>(new SyncManagerImpl(name)); } } // namespace syncer diff --git a/sync/internal_api/sync_rollback_manager.cc b/sync/internal_api/sync_rollback_manager.cc deleted file mode 100644 index e2a5c84..0000000 --- a/sync/internal_api/sync_rollback_manager.cc +++ /dev/null @@ -1,128 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "sync/internal_api/sync_rollback_manager.h" - -#include <stddef.h> -#include <stdint.h> - -#include "sync/internal_api/public/base/model_type.h" -#include "sync/internal_api/public/read_node.h" -#include "sync/internal_api/public/read_transaction.h" -#include "sync/internal_api/public/util/syncer_error.h" -#include "sync/internal_api/public/write_transaction.h" -#include "sync/syncable/directory.h" -#include "sync/syncable/mutable_entry.h" -#include "url/gurl.h" - -namespace syncer { - -SyncRollbackManager::SyncRollbackManager() - : change_delegate_(NULL) { -} - -SyncRollbackManager::~SyncRollbackManager() { -} - -void SyncRollbackManager::Init(InitArgs* args) { - if (SyncRollbackManagerBase::InitInternal( - args->database_location, - args->internal_components_factory.get(), - InternalComponentsFactory::STORAGE_ON_DISK, - args->unrecoverable_error_handler, - args->report_unrecoverable_error_function)) { - change_delegate_ = args->change_delegate; - - for (size_t i = 0; i < args->workers.size(); ++i) { - ModelSafeGroup group = args->workers[i]->GetModelSafeGroup(); - CHECK(workers_.find(group) == workers_.end()); - workers_[group] = args->workers[i]; - } - - rollback_ready_types_ = GetUserShare()->directory->InitialSyncEndedTypes(); - rollback_ready_types_.RetainAll(BackupTypes()); - } -} - -void SyncRollbackManager::StartSyncingNormally( - const ModelSafeRoutingInfo& routing_info, - base::Time last_poll_time) { - if (rollback_ready_types_.Empty()) { - NotifyRollbackDone(); - return; - } - - std::map<ModelType, syncable::Directory::Metahandles> to_delete; - { - WriteTransaction trans(FROM_HERE, GetUserShare()); - syncable::Directory::Metahandles unsynced; - GetUserShare()->directory->GetUnsyncedMetaHandles(trans.GetWrappedTrans(), - &unsynced); - for (size_t i = 0; i < unsynced.size(); ++i) { - syncable::MutableEntry e(trans.GetWrappedWriteTrans(), - syncable::GET_BY_HANDLE, unsynced[i]); - if (!e.good() || e.GetIsDel() || e.GetId().ServerKnows()) - continue; - - // TODO(haitaol): roll back entries that are backed up but whose content - // is merged with local model during association. - - ModelType type = GetModelTypeFromSpecifics(e.GetSpecifics()); - if (!rollback_ready_types_.Has(type)) - continue; - - to_delete[type].push_back(unsynced[i]); - } - } - - for (std::map<ModelType, syncable::Directory::Metahandles>::iterator it = - to_delete.begin(); it != to_delete.end(); ++it) { - ModelSafeGroup group = routing_info.find(it->first)->second; - CHECK(workers_.find(group) != workers_.end()); - workers_[group]->DoWorkAndWaitUntilDone( - base::Bind(&SyncRollbackManager::DeleteOnWorkerThread, - base::Unretained(this), - it->first, it->second)); - } - - NotifyRollbackDone(); -} - -SyncerError SyncRollbackManager::DeleteOnWorkerThread( - ModelType type, - std::vector<int64_t> handles) { - CHECK(change_delegate_); - - { - ChangeRecordList deletes; - WriteTransaction trans(FROM_HERE, GetUserShare()); - for (size_t i = 0; i < handles.size(); ++i) { - syncable::MutableEntry e(trans.GetWrappedWriteTrans(), - syncable::GET_BY_HANDLE, handles[i]); - if (!e.good() || e.GetIsDel()) - continue; - - ChangeRecord del; - del.action = ChangeRecord::ACTION_DELETE; - del.id = handles[i]; - del.specifics = e.GetSpecifics(); - deletes.push_back(del); - } - - change_delegate_->OnChangesApplied(type, 1, &trans, - MakeImmutable(&deletes)); - } - - change_delegate_->OnChangesComplete(type); - return SYNCER_OK; -} - -void SyncRollbackManager::NotifyRollbackDone() { - SyncProtocolError error; - error.action = ROLLBACK_DONE; - FOR_EACH_OBSERVER(SyncManager::Observer, *GetObservers(), - OnActionableError(error)); -} - -} // namespace syncer diff --git a/sync/internal_api/sync_rollback_manager.h b/sync/internal_api/sync_rollback_manager.h deleted file mode 100644 index d41086a..0000000 --- a/sync/internal_api/sync_rollback_manager.h +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef SYNC_INTERNAL_API_SYNC_ROLLBACK_MANAGER_H_ -#define SYNC_INTERNAL_API_SYNC_ROLLBACK_MANAGER_H_ - -#include <stdint.h> - -#include <map> -#include <string> -#include <vector> - -#include "base/macros.h" -#include "sync/internal_api/sync_rollback_manager_base.h" - -class GURL; - -namespace syncer { - -// SyncRollbackManager restores user's data to pre-sync state using backup -// DB created by SyncBackupManager. -class SYNC_EXPORT SyncRollbackManager : public SyncRollbackManagerBase { - public: - SyncRollbackManager(); - ~SyncRollbackManager() override; - - // SyncManager implementation. - void Init(InitArgs* args) override; - void StartSyncingNormally(const ModelSafeRoutingInfo& routing_info, - base::Time last_poll_time) override; - - private: - // Deletes specified entries in local model. - SyncerError DeleteOnWorkerThread(ModelType type, - std::vector<int64_t> handles); - - void NotifyRollbackDone(); - - std::map<ModelSafeGroup, scoped_refptr<ModelSafeWorker> > workers_; - - SyncManager::ChangeDelegate* change_delegate_; - - // Types that can be rolled back. - ModelTypeSet rollback_ready_types_; - - DISALLOW_COPY_AND_ASSIGN(SyncRollbackManager); -}; - -} // namespace syncer - -#endif // SYNC_INTERNAL_API_SYNC_ROLLBACK_MANAGER_H_ diff --git a/sync/internal_api/sync_rollback_manager_base.cc b/sync/internal_api/sync_rollback_manager_base.cc deleted file mode 100644 index d62f354..0000000 --- a/sync/internal_api/sync_rollback_manager_base.cc +++ /dev/null @@ -1,329 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "sync/internal_api/sync_rollback_manager_base.h" - -#include <stdint.h> - -#include "sync/internal_api/public/base/model_type.h" -#include "sync/internal_api/public/read_node.h" -#include "sync/internal_api/public/read_transaction.h" -#include "sync/internal_api/public/write_transaction.h" -#include "sync/syncable/directory_backing_store.h" -#include "sync/syncable/mutable_entry.h" - -namespace { - -// Permanent bookmark folders as defined in bookmark_model_associator.cc. -// No mobile bookmarks because they only exists with sync enabled. -const char kBookmarkBarTag[] = "bookmark_bar"; -const char kOtherBookmarksTag[] = "other_bookmarks"; - -class DummyEntryptionHandler : public syncer::SyncEncryptionHandler { - void AddObserver(Observer* observer) override {} - void RemoveObserver(Observer* observer) override {} - void Init() override {} - void SetEncryptionPassphrase(const std::string& passphrase, - bool is_explicit) override {} - void SetDecryptionPassphrase(const std::string& passphrase) override {} - void EnableEncryptEverything() override {} - bool IsEncryptEverythingEnabled() const override { return false; } - syncer::PassphraseType GetPassphraseType() const override { - return syncer::KEYSTORE_PASSPHRASE; - } -}; - -} // anonymous namespace - -namespace syncer { - -SyncRollbackManagerBase::SyncRollbackManagerBase() - : dummy_handler_(new DummyEntryptionHandler), - initialized_(false), - weak_ptr_factory_(this) { -} - -SyncRollbackManagerBase::~SyncRollbackManagerBase() { -} - -bool SyncRollbackManagerBase::InitInternal( - const base::FilePath& database_location, - InternalComponentsFactory* internal_components_factory, - InternalComponentsFactory::StorageOption storage, - const WeakHandle<UnrecoverableErrorHandler>& unrecoverable_error_handler, - const base::Closure& report_unrecoverable_error_function) { - unrecoverable_error_handler_ = unrecoverable_error_handler; - report_unrecoverable_error_function_ = report_unrecoverable_error_function; - - if (!InitBackupDB(database_location, internal_components_factory, storage)) { - NotifyInitializationFailure(); - return false; - } - - initialized_ = true; - NotifyInitializationSuccess(); - return true; -} - -ModelTypeSet SyncRollbackManagerBase::InitialSyncEndedTypes() { - return share_.directory->InitialSyncEndedTypes(); -} - -ModelTypeSet SyncRollbackManagerBase::GetTypesWithEmptyProgressMarkerToken( - ModelTypeSet types) { - ModelTypeSet inited_types = share_.directory->InitialSyncEndedTypes(); - types.RemoveAll(inited_types); - return types; -} - -bool SyncRollbackManagerBase::PurgePartiallySyncedTypes() { - NOTREACHED(); - return true; -} - -void SyncRollbackManagerBase::UpdateCredentials( - const SyncCredentials& credentials) { -} - -void SyncRollbackManagerBase::StartSyncingNormally( - const ModelSafeRoutingInfo& routing_info, - base::Time last_poll_time) {} - -void SyncRollbackManagerBase::ConfigureSyncer( - ConfigureReason reason, - ModelTypeSet to_download, - ModelTypeSet to_purge, - ModelTypeSet to_journal, - ModelTypeSet to_unapply, - const ModelSafeRoutingInfo& new_routing_info, - const base::Closure& ready_task, - const base::Closure& retry_task) { - for (ModelTypeSet::Iterator type = to_download.First(); - type.Good(); type.Inc()) { - if (InitTypeRootNode(type.Get())) { - if (type.Get() == BOOKMARKS) { - InitBookmarkFolder(kBookmarkBarTag); - InitBookmarkFolder(kOtherBookmarksTag); - } - } - } - - ready_task.Run(); -} - -void SyncRollbackManagerBase::SetInvalidatorEnabled(bool invalidator_enabled) { -} - -void SyncRollbackManagerBase::OnIncomingInvalidation( - syncer::ModelType type, - scoped_ptr<InvalidationInterface> invalidation) { - NOTREACHED(); -} - -void SyncRollbackManagerBase::AddObserver(SyncManager::Observer* observer) { - observers_.AddObserver(observer); -} - -void SyncRollbackManagerBase::RemoveObserver(SyncManager::Observer* observer) { - observers_.RemoveObserver(observer); -} - -SyncStatus SyncRollbackManagerBase::GetDetailedStatus() const { - return SyncStatus(); -} - -void SyncRollbackManagerBase::SaveChanges() { -} - -void SyncRollbackManagerBase::ShutdownOnSyncThread(ShutdownReason reason) { - if (initialized_) { - share_.directory.reset(); - initialized_ = false; - } -} - -UserShare* SyncRollbackManagerBase::GetUserShare() { - return &share_; -} - -const std::string SyncRollbackManagerBase::cache_guid() { - return share_.directory->cache_guid(); -} - -bool SyncRollbackManagerBase::ReceivedExperiment(Experiments* experiments) { - return false; -} - -bool SyncRollbackManagerBase::HasUnsyncedItems() { - ReadTransaction trans(FROM_HERE, &share_); - syncable::Directory::Metahandles unsynced; - share_.directory->GetUnsyncedMetaHandles(trans.GetWrappedTrans(), &unsynced); - return !unsynced.empty(); -} - -SyncEncryptionHandler* SyncRollbackManagerBase::GetEncryptionHandler() { - return dummy_handler_.get(); -} - -void SyncRollbackManagerBase::RefreshTypes(ModelTypeSet types) { -} - -void SyncRollbackManagerBase::HandleTransactionCompleteChangeEvent( - ModelTypeSet models_with_changes) { -} - -ModelTypeSet SyncRollbackManagerBase::HandleTransactionEndingChangeEvent( - const syncable::ImmutableWriteTransactionInfo& write_transaction_info, - syncable::BaseTransaction* trans) { - return ModelTypeSet(); -} - -void SyncRollbackManagerBase::HandleCalculateChangesChangeEventFromSyncApi( - const syncable::ImmutableWriteTransactionInfo& write_transaction_info, - syncable::BaseTransaction* trans, - std::vector<int64_t>* entries_changed) {} - -void SyncRollbackManagerBase::HandleCalculateChangesChangeEventFromSyncer( - const syncable::ImmutableWriteTransactionInfo& write_transaction_info, - syncable::BaseTransaction* trans, - std::vector<int64_t>* entries_changed) {} - -void SyncRollbackManagerBase::OnTransactionWrite( - const syncable::ImmutableWriteTransactionInfo& write_transaction_info, - ModelTypeSet models_with_changes) { -} - -void SyncRollbackManagerBase::NotifyInitializationSuccess() { - FOR_EACH_OBSERVER( - SyncManager::Observer, observers_, - OnInitializationComplete( - MakeWeakHandle(base::WeakPtr<JsBackend>()), - MakeWeakHandle(base::WeakPtr<DataTypeDebugInfoListener>()), - true, InitialSyncEndedTypes())); -} - -void SyncRollbackManagerBase::NotifyInitializationFailure() { - FOR_EACH_OBSERVER( - SyncManager::Observer, observers_, - OnInitializationComplete( - MakeWeakHandle(base::WeakPtr<JsBackend>()), - MakeWeakHandle(base::WeakPtr<DataTypeDebugInfoListener>()), - false, ModelTypeSet())); -} - -syncer_v2::SyncContextProxy* SyncRollbackManagerBase::GetSyncContextProxy() { - return NULL; -} - -ScopedVector<syncer::ProtocolEvent> -SyncRollbackManagerBase::GetBufferedProtocolEvents() { - return ScopedVector<syncer::ProtocolEvent>(); -} - -scoped_ptr<base::ListValue> SyncRollbackManagerBase::GetAllNodesForType( - syncer::ModelType type) { - ReadTransaction trans(FROM_HERE, GetUserShare()); - scoped_ptr<base::ListValue> nodes( - trans.GetDirectory()->GetNodeDetailsForType(trans.GetWrappedTrans(), - type)); - return nodes; -} - -bool SyncRollbackManagerBase::InitBackupDB( - const base::FilePath& sync_folder, - InternalComponentsFactory* internal_components_factory, - InternalComponentsFactory::StorageOption storage) { - base::FilePath backup_db_path = sync_folder.Append( - syncable::Directory::kSyncDatabaseFilename); - scoped_ptr<syncable::DirectoryBackingStore> backing_store = - internal_components_factory->BuildDirectoryBackingStore(storage, "backup", - backup_db_path); - - DCHECK(backing_store.get()); - share_.directory.reset( - new syncable::Directory( - backing_store.release(), - unrecoverable_error_handler_, - report_unrecoverable_error_function_, - NULL, - NULL)); - return syncable::OPENED == - share_.directory->Open( - "backup", this, - MakeWeakHandle(weak_ptr_factory_.GetWeakPtr())); -} - -bool SyncRollbackManagerBase::InitTypeRootNode(ModelType type) { - WriteTransaction trans(FROM_HERE, &share_); - ReadNode root(&trans); - if (BaseNode::INIT_OK == root.InitTypeRoot(type)) - return true; - - syncable::MutableEntry entry(trans.GetWrappedWriteTrans(), - syncable::CREATE_NEW_UPDATE_ITEM, - syncable::Id::CreateFromServerId( - ModelTypeToString(type))); - if (!entry.good()) - return false; - - entry.PutParentId(syncable::Id::GetRoot()); - entry.PutBaseVersion(1); - entry.PutUniqueServerTag(ModelTypeToRootTag(type)); - entry.PutNonUniqueName(ModelTypeToString(type)); - entry.PutIsDel(false); - entry.PutIsDir(true); - - sync_pb::EntitySpecifics specifics; - AddDefaultFieldValue(type, &specifics); - entry.PutSpecifics(specifics); - - return true; -} - -void SyncRollbackManagerBase::InitBookmarkFolder(const std::string& folder) { - WriteTransaction trans(FROM_HERE, &share_); - syncable::Entry bookmark_root(trans.GetWrappedTrans(), - syncable::GET_TYPE_ROOT, - BOOKMARKS); - if (!bookmark_root.good()) - return; - - syncable::MutableEntry entry(trans.GetWrappedWriteTrans(), - syncable::CREATE_NEW_UPDATE_ITEM, - syncable::Id::CreateFromServerId(folder)); - if (!entry.good()) - return; - - entry.PutParentId(bookmark_root.GetId()); - entry.PutBaseVersion(1); - entry.PutUniqueServerTag(folder); - entry.PutNonUniqueName(folder); - entry.PutIsDel(false); - entry.PutIsDir(true); - - sync_pb::EntitySpecifics specifics; - AddDefaultFieldValue(BOOKMARKS, &specifics); - entry.PutSpecifics(specifics); -} - -base::ObserverList<SyncManager::Observer>* -SyncRollbackManagerBase::GetObservers() { - return &observers_; -} - -void SyncRollbackManagerBase::RegisterDirectoryTypeDebugInfoObserver( - syncer::TypeDebugInfoObserver* observer) {} - -void SyncRollbackManagerBase::UnregisterDirectoryTypeDebugInfoObserver( - syncer::TypeDebugInfoObserver* observer) {} - -bool SyncRollbackManagerBase::HasDirectoryTypeDebugInfoObserver( - syncer::TypeDebugInfoObserver* observer) { return false; } - -void SyncRollbackManagerBase::RequestEmitDebugInfo() {} - -void SyncRollbackManagerBase::ClearServerData( - const ClearServerDataCallback& callback) {} - -} // namespace syncer diff --git a/sync/internal_api/sync_rollback_manager_base.h b/sync/internal_api/sync_rollback_manager_base.h deleted file mode 100644 index ad3ad62..0000000 --- a/sync/internal_api/sync_rollback_manager_base.h +++ /dev/null @@ -1,149 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef SYNC_INTERNAL_API_SYNC_ROLLBACK_MANAGER_BASE_H_ -#define SYNC_INTERNAL_API_SYNC_ROLLBACK_MANAGER_BASE_H_ - -#include <stdint.h> - -#include <string> -#include <vector> - -#include "base/macros.h" -#include "sync/base/sync_export.h" -#include "sync/internal_api/public/http_post_provider_factory.h" -#include "sync/internal_api/public/internal_components_factory.h" -#include "sync/internal_api/public/sync_manager.h" -#include "sync/internal_api/public/user_share.h" -#include "sync/syncable/directory_change_delegate.h" -#include "sync/syncable/transaction_observer.h" - -namespace syncer { - -class WriteTransaction; - -// Base class of sync managers used for backup and rollback. Two major -// functions are: -// * Init(): load backup DB into sync directory. -// * ConfigureSyncer(): initialize permanent sync nodes (root, bookmark -// permanent folders) for configured type as needed. -// -// Most of other functions are no ops. -class SYNC_EXPORT SyncRollbackManagerBase - : public SyncManager, - public syncable::DirectoryChangeDelegate, - public syncable::TransactionObserver { - public: - SyncRollbackManagerBase(); - ~SyncRollbackManagerBase() override; - - // SyncManager implementation. - ModelTypeSet InitialSyncEndedTypes() override; - ModelTypeSet GetTypesWithEmptyProgressMarkerToken( - ModelTypeSet types) override; - bool PurgePartiallySyncedTypes() override; - void UpdateCredentials(const SyncCredentials& credentials) override; - void StartSyncingNormally(const ModelSafeRoutingInfo& routing_info, - base::Time last_poll_time) override; - void ConfigureSyncer(ConfigureReason reason, - ModelTypeSet to_download, - ModelTypeSet to_purge, - ModelTypeSet to_journal, - ModelTypeSet to_unapply, - const ModelSafeRoutingInfo& new_routing_info, - const base::Closure& ready_task, - const base::Closure& retry_task) override; - void SetInvalidatorEnabled(bool invalidator_enabled) override; - void OnIncomingInvalidation( - syncer::ModelType type, - scoped_ptr<InvalidationInterface> invalidation) override; - void AddObserver(SyncManager::Observer* observer) override; - void RemoveObserver(SyncManager::Observer* observer) override; - SyncStatus GetDetailedStatus() const override; - void SaveChanges() override; - void ShutdownOnSyncThread(ShutdownReason reason) override; - UserShare* GetUserShare() override; - const std::string cache_guid() override; - bool ReceivedExperiment(Experiments* experiments) override; - bool HasUnsyncedItems() override; - SyncEncryptionHandler* GetEncryptionHandler() override; - void RefreshTypes(ModelTypeSet types) override; - syncer_v2::SyncContextProxy* GetSyncContextProxy() override; - ScopedVector<ProtocolEvent> GetBufferedProtocolEvents() override; - scoped_ptr<base::ListValue> GetAllNodesForType( - syncer::ModelType type) override; - void ClearServerData(const ClearServerDataCallback& callback) override; - - // DirectoryChangeDelegate implementation. - void HandleTransactionCompleteChangeEvent( - ModelTypeSet models_with_changes) override; - ModelTypeSet HandleTransactionEndingChangeEvent( - const syncable::ImmutableWriteTransactionInfo& write_transaction_info, - syncable::BaseTransaction* trans) override; - void HandleCalculateChangesChangeEventFromSyncApi( - const syncable::ImmutableWriteTransactionInfo& write_transaction_info, - syncable::BaseTransaction* trans, - std::vector<int64_t>* entries_changed) override; - void HandleCalculateChangesChangeEventFromSyncer( - const syncable::ImmutableWriteTransactionInfo& write_transaction_info, - syncable::BaseTransaction* trans, - std::vector<int64_t>* entries_changed) override; - - // syncable::TransactionObserver implementation. - void OnTransactionWrite( - const syncable::ImmutableWriteTransactionInfo& write_transaction_info, - ModelTypeSet models_with_changes) override; - - protected: - base::ObserverList<SyncManager::Observer>* GetObservers(); - - // Initialize sync backup DB. - bool InitInternal( - const base::FilePath& database_location, - InternalComponentsFactory* internal_components_factory, - InternalComponentsFactory::StorageOption storage, - const WeakHandle<UnrecoverableErrorHandler>& unrecoverable_error_handler, - const base::Closure& report_unrecoverable_error_function); - - void RegisterDirectoryTypeDebugInfoObserver( - syncer::TypeDebugInfoObserver* observer) override; - void UnregisterDirectoryTypeDebugInfoObserver( - syncer::TypeDebugInfoObserver* observer) override; - bool HasDirectoryTypeDebugInfoObserver( - syncer::TypeDebugInfoObserver* observer) override; - void RequestEmitDebugInfo() override; - - bool initialized() const { - return initialized_; - } - - private: - void NotifyInitializationSuccess(); - void NotifyInitializationFailure(); - - bool InitBackupDB(const base::FilePath& sync_folder, - InternalComponentsFactory* internal_components_factory, - InternalComponentsFactory::StorageOption storage); - - bool InitTypeRootNode(ModelType type); - void InitBookmarkFolder(const std::string& folder); - - UserShare share_; - base::ObserverList<SyncManager::Observer> observers_; - - WeakHandle<UnrecoverableErrorHandler> unrecoverable_error_handler_; - base::Closure report_unrecoverable_error_function_; - - scoped_ptr<SyncEncryptionHandler> dummy_handler_; - - bool initialized_; - - base::WeakPtrFactory<SyncRollbackManagerBase> weak_ptr_factory_; - - DISALLOW_COPY_AND_ASSIGN(SyncRollbackManagerBase); -}; - -} // namespace syncer - -#endif // SYNC_INTERNAL_API_SYNC_ROLLBACK_MANAGER_BASE_H_ diff --git a/sync/internal_api/sync_rollback_manager_base_unittest.cc b/sync/internal_api/sync_rollback_manager_base_unittest.cc deleted file mode 100644 index bb5ec93..0000000 --- a/sync/internal_api/sync_rollback_manager_base_unittest.cc +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "sync/internal_api/sync_rollback_manager_base.h" - -#include "base/bind.h" -#include "sync/internal_api/public/read_node.h" -#include "sync/internal_api/public/read_transaction.h" -#include "sync/internal_api/public/test/test_internal_components_factory.h" -#include "testing/gtest/include/gtest/gtest.h" -#include "url/gurl.h" - -namespace syncer { - -namespace { - -void OnConfigDone(bool success) { - EXPECT_TRUE(success); -} - -class SyncTestRollbackManager : public SyncRollbackManagerBase { - public: - void Init(InitArgs* args) override { - SyncRollbackManagerBase::InitInternal( - args->database_location, - args->internal_components_factory.get(), - InternalComponentsFactory::STORAGE_IN_MEMORY, - args->unrecoverable_error_handler, - args->report_unrecoverable_error_function); - } -}; - -class SyncRollbackManagerBaseTest : public testing::Test { - protected: - void SetUp() override { - SyncManager::InitArgs args; - args.database_location = base::FilePath(base::FilePath::kCurrentDirectory); - args.service_url = GURL("https://example.com/"); - args.internal_components_factory.reset(new TestInternalComponentsFactory( - InternalComponentsFactory::Switches(), - InternalComponentsFactory::STORAGE_IN_MEMORY, - &storage_used_)); - manager_.Init(&args); - EXPECT_EQ(InternalComponentsFactory::STORAGE_IN_MEMORY, storage_used_); - } - - SyncTestRollbackManager manager_; - base::MessageLoop loop_; // Needed for WeakHandle - InternalComponentsFactory::StorageOption storage_used_; -}; - -TEST_F(SyncRollbackManagerBaseTest, InitTypeOnConfiguration) { - EXPECT_TRUE(manager_.InitialSyncEndedTypes().Empty()); - - manager_.ConfigureSyncer( - CONFIGURE_REASON_NEW_CLIENT, - ModelTypeSet(PREFERENCES, BOOKMARKS), - ModelTypeSet(), ModelTypeSet(), ModelTypeSet(), ModelSafeRoutingInfo(), - base::Bind(&OnConfigDone, true), - base::Bind(&OnConfigDone, false)); - - ReadTransaction trans(FROM_HERE, manager_.GetUserShare()); - ReadNode pref_root(&trans); - EXPECT_EQ(BaseNode::INIT_OK, - pref_root.InitTypeRoot(PREFERENCES)); - - ReadNode bookmark_root(&trans); - EXPECT_EQ(BaseNode::INIT_OK, - bookmark_root.InitTypeRoot(BOOKMARKS)); - ReadNode bookmark_bar(&trans); - EXPECT_EQ(BaseNode::INIT_OK, - bookmark_bar.InitByTagLookupForBookmarks("bookmark_bar")); - ReadNode bookmark_mobile(&trans); - EXPECT_EQ(BaseNode::INIT_FAILED_ENTRY_NOT_GOOD, - bookmark_mobile.InitByTagLookupForBookmarks("synced_bookmarks")); - ReadNode bookmark_other(&trans); - EXPECT_EQ(BaseNode::INIT_OK, - bookmark_other.InitByTagLookupForBookmarks("other_bookmarks")); -} - -} // anonymous namespace - -} // namespace syncer diff --git a/sync/internal_api/sync_rollback_manager_unittest.cc b/sync/internal_api/sync_rollback_manager_unittest.cc deleted file mode 100644 index 400cebc..0000000 --- a/sync/internal_api/sync_rollback_manager_unittest.cc +++ /dev/null @@ -1,269 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "sync/internal_api/sync_rollback_manager.h" - -#include <stddef.h> -#include <stdint.h> - -#include <set> - -#include "base/files/scoped_temp_dir.h" -#include "base/run_loop.h" -#include "sync/internal_api/public/read_node.h" -#include "sync/internal_api/public/read_transaction.h" -#include "sync/internal_api/public/sessions/sync_session_snapshot.h" -#include "sync/internal_api/public/test/test_internal_components_factory.h" -#include "sync/internal_api/public/write_node.h" -#include "sync/internal_api/public/write_transaction.h" -#include "sync/internal_api/sync_backup_manager.h" -#include "sync/syncable/entry.h" -#include "sync/test/engine/fake_model_worker.h" -#include "sync/test/test_directory_backing_store.h" -#include "testing/gmock/include/gmock/gmock.h" -#include "testing/gtest/include/gtest/gtest.h" -#include "url/gurl.h" - -using ::testing::_; -using ::testing::DoDefault; -using ::testing::Invoke; -using ::testing::Truly; -using ::testing::WithArgs; - -namespace syncer { - -namespace { - -class TestChangeDelegate : public SyncManager::ChangeDelegate { - public: - TestChangeDelegate() { - ON_CALL(*this, OnChangesApplied(_, _, _, _)) - .WillByDefault( - WithArgs<3>(Invoke(this, - &TestChangeDelegate::VerifyDeletes))); - } - - void add_expected_delete(int64_t v) { expected_deletes_.insert(v); } - - MOCK_METHOD4(OnChangesApplied, - void(ModelType model_type, - int64_t model_version, - const BaseTransaction* trans, - const ImmutableChangeRecordList& changes)); - MOCK_METHOD1(OnChangesComplete, void(ModelType model_type)); - - private: - void VerifyDeletes(const ImmutableChangeRecordList& changes) { - std::set<int64_t> deleted; - for (size_t i = 0; i < changes.Get().size(); ++i) { - const ChangeRecord& change = (changes.Get())[i]; - EXPECT_EQ(ChangeRecord::ACTION_DELETE, change.action); - EXPECT_TRUE(deleted.find(change.id) == deleted.end()); - deleted.insert(change.id); - } - EXPECT_TRUE(expected_deletes_ == deleted); - } - - std::set<int64_t> expected_deletes_; -}; - -class SyncRollbackManagerTest : public testing::Test, - public SyncManager::Observer { - protected: - void SetUp() override { - CHECK(temp_dir_.CreateUniqueTempDir()); - - worker_ = new FakeModelWorker(GROUP_UI); - } - - MOCK_METHOD1(OnSyncCycleCompleted, - void(const sessions::SyncSessionSnapshot&)); - MOCK_METHOD1(OnConnectionStatusChange, void(ConnectionStatus)); - MOCK_METHOD4(OnInitializationComplete, - void(const WeakHandle<JsBackend>&, - const WeakHandle<DataTypeDebugInfoListener>&, - bool, ModelTypeSet)); - MOCK_METHOD1(OnActionableError, void(const SyncProtocolError&)); - MOCK_METHOD1(OnMigrationRequested, void(ModelTypeSet)); - MOCK_METHOD1(OnProtocolEvent, void(const ProtocolEvent&)); - - void OnConfigDone(bool success) { - EXPECT_TRUE(success); - } - - int64_t CreateEntry(UserShare* user_share, - ModelType type, - const std::string& client_tag) { - WriteTransaction trans(FROM_HERE, user_share); - WriteNode node(&trans); - EXPECT_EQ(WriteNode::INIT_SUCCESS, - node.InitUniqueByCreation(type, client_tag)); - return node.GetId(); - } - - void InitManager(SyncManager* manager, ModelTypeSet types, - TestChangeDelegate* delegate, - InternalComponentsFactory::StorageOption storage_option) { - manager_ = manager; - types_ = types; - - EXPECT_CALL(*this, OnInitializationComplete(_, _, _, _)) - .WillOnce(WithArgs<2>(Invoke(this, - &SyncRollbackManagerTest::HandleInit))); - - manager->AddObserver(this); - - base::RunLoop run_loop; - SyncManager::InitArgs args; - args.database_location = temp_dir_.path(); - args.service_url = GURL("https://example.com/"); - args.workers.push_back(worker_); - args.change_delegate = delegate; - - InternalComponentsFactory::StorageOption storage_used; - args.internal_components_factory.reset(new TestInternalComponentsFactory( - InternalComponentsFactory::Switches(), storage_option, &storage_used)); - manager->Init(&args); - EXPECT_EQ(storage_option, storage_used); - loop_.PostTask(FROM_HERE, run_loop.QuitClosure()); - run_loop.Run(); - } - - // Create and persist an entry by unique tag in DB. - void PrepopulateDb(ModelType type, const std::string& client_tag) { - SyncBackupManager backup_manager; - TestChangeDelegate delegate; - InitManager(&backup_manager, ModelTypeSet(type), &delegate, - InternalComponentsFactory::STORAGE_ON_DISK_DEFERRED); - CreateEntry(backup_manager.GetUserShare(), type, client_tag); - backup_manager.ShutdownOnSyncThread(SWITCH_MODE_SYNC); - } - - // Verify entry with |client_tag| exists in sync directory. - bool VerifyEntry(UserShare* user_share, ModelType type, - const std::string& client_tag) { - ReadTransaction trans(FROM_HERE, user_share); - ReadNode node(&trans); - return BaseNode::INIT_OK == node.InitByClientTagLookup(type, client_tag); - } - - private: - void ConfigureSyncer() { - manager_->ConfigureSyncer( - CONFIGURE_REASON_NEW_CLIENT, - types_, - ModelTypeSet(), ModelTypeSet(), ModelTypeSet(), - ModelSafeRoutingInfo(), - base::Bind(&SyncRollbackManagerTest::OnConfigDone, - base::Unretained(this), true), - base::Bind(&SyncRollbackManagerTest::OnConfigDone, - base::Unretained(this), false)); - } - - void HandleInit(bool success) { - if (success) { - loop_.PostTask(FROM_HERE, - base::Bind(&SyncRollbackManagerTest::ConfigureSyncer, - base::Unretained(this))); - } else { - manager_->ShutdownOnSyncThread(STOP_SYNC); - } - } - - base::ScopedTempDir temp_dir_; - scoped_refptr<ModelSafeWorker> worker_; - base::MessageLoop loop_; // Needed for WeakHandle - SyncManager* manager_; - ModelTypeSet types_; -}; - -bool IsRollbackDoneAction(SyncProtocolError e) { - return e.action == syncer::ROLLBACK_DONE; -} - -TEST_F(SyncRollbackManagerTest, RollbackBasic) { - PrepopulateDb(PREFERENCES, "pref1"); - - TestChangeDelegate delegate; - SyncRollbackManager rollback_manager; - InitManager(&rollback_manager, ModelTypeSet(PREFERENCES), &delegate, - InternalComponentsFactory::STORAGE_ON_DISK); - - // Simulate a new entry added during type initialization. - int64_t new_pref_id = - CreateEntry(rollback_manager.GetUserShare(), PREFERENCES, "pref2"); - - delegate.add_expected_delete(new_pref_id); - EXPECT_CALL(delegate, OnChangesApplied(_, _, _, _)) - .Times(1) - .WillOnce(DoDefault()); - EXPECT_CALL(delegate, OnChangesComplete(_)).Times(1); - EXPECT_CALL(*this, OnActionableError(Truly(IsRollbackDoneAction))).Times(1); - - ModelSafeRoutingInfo routing_info; - routing_info[PREFERENCES] = GROUP_UI; - rollback_manager.StartSyncingNormally(routing_info, base::Time()); -} - -TEST_F(SyncRollbackManagerTest, NoRollbackOfTypesNotBackedUp) { - PrepopulateDb(PREFERENCES, "pref1"); - - TestChangeDelegate delegate; - SyncRollbackManager rollback_manager; - InitManager(&rollback_manager, ModelTypeSet(PREFERENCES, APPS), &delegate, - InternalComponentsFactory::STORAGE_ON_DISK); - - // Simulate new entry added during type initialization. - int64_t new_pref_id = - CreateEntry(rollback_manager.GetUserShare(), PREFERENCES, "pref2"); - CreateEntry(rollback_manager.GetUserShare(), APPS, "app1"); - - delegate.add_expected_delete(new_pref_id); - EXPECT_CALL(delegate, OnChangesApplied(_, _, _, _)) - .Times(1) - .WillOnce(DoDefault()); - EXPECT_CALL(delegate, OnChangesComplete(_)).Times(1); - - ModelSafeRoutingInfo routing_info; - routing_info[PREFERENCES] = GROUP_UI; - rollback_manager.StartSyncingNormally(routing_info, base::Time()); - - // APP entry is still valid. - EXPECT_TRUE(VerifyEntry(rollback_manager.GetUserShare(), APPS, "app1")); -} - -TEST_F(SyncRollbackManagerTest, BackupDbNotChangedOnAbort) { - PrepopulateDb(PREFERENCES, "pref1"); - - TestChangeDelegate delegate; - scoped_ptr<SyncRollbackManager> rollback_manager( - new SyncRollbackManager); - InitManager(rollback_manager.get(), ModelTypeSet(PREFERENCES), &delegate, - InternalComponentsFactory::STORAGE_ON_DISK); - - // Simulate a new entry added during type initialization. - CreateEntry(rollback_manager->GetUserShare(), PREFERENCES, "pref2"); - - // Manager was shut down before sync starts. - rollback_manager->ShutdownOnSyncThread(STOP_SYNC); - - // Verify new entry was not persisted. - rollback_manager.reset(new SyncRollbackManager); - InitManager(rollback_manager.get(), ModelTypeSet(PREFERENCES), &delegate, - InternalComponentsFactory::STORAGE_ON_DISK); - EXPECT_FALSE(VerifyEntry(rollback_manager->GetUserShare(), PREFERENCES, - "pref2")); -} - -TEST_F(SyncRollbackManagerTest, OnInitializationFailure) { - // Test graceful shutdown on initialization failure. - scoped_ptr<SyncRollbackManager> rollback_manager( - new SyncRollbackManager); - InitManager(rollback_manager.get(), ModelTypeSet(PREFERENCES), NULL, - InternalComponentsFactory::STORAGE_ON_DISK); -} - -} // anonymous namespace - -} // namespace syncer diff --git a/sync/internal_api/test/sync_manager_factory_for_profile_sync_test.cc b/sync/internal_api/test/sync_manager_factory_for_profile_sync_test.cc index ff72bcd..4c0689d 100644 --- a/sync/internal_api/test/sync_manager_factory_for_profile_sync_test.cc +++ b/sync/internal_api/test/sync_manager_factory_for_profile_sync_test.cc @@ -10,7 +10,7 @@ namespace syncer { SyncManagerFactoryForProfileSyncTest::SyncManagerFactoryForProfileSyncTest( base::Closure init_callback) - : SyncManagerFactory(SyncManagerFactory::NORMAL), + : SyncManagerFactory(), init_callback_(init_callback) { } @@ -20,9 +20,7 @@ scoped_ptr<syncer::SyncManager> SyncManagerFactoryForProfileSyncTest::CreateSyncManager( const std::string& name) { return scoped_ptr<syncer::SyncManager>( - new SyncManagerForProfileSyncTest( - name, - init_callback_)); + new SyncManagerForProfileSyncTest(name, init_callback_)); } } // namespace syncer diff --git a/sync/internal_api/test/test_internal_components_factory.cc b/sync/internal_api/test/test_internal_components_factory.cc index 1e26b4e..d6a72fa 100644 --- a/sync/internal_api/test/test_internal_components_factory.cc +++ b/sync/internal_api/test/test_internal_components_factory.cc @@ -5,7 +5,6 @@ #include "sync/internal_api/public/test/test_internal_components_factory.h" #include "sync/sessions/sync_session_context.h" -#include "sync/syncable/deferred_on_disk_directory_backing_store.h" #include "sync/syncable/in_memory_directory_backing_store.h" #include "sync/syncable/on_disk_directory_backing_store.h" #include "sync/syncable/invalid_directory_backing_store.h" @@ -69,10 +68,6 @@ TestInternalComponentsFactory::BuildDirectoryBackingStore( return scoped_ptr<syncable::DirectoryBackingStore>( new syncable::OnDiskDirectoryBackingStore(dir_name, backing_filepath)); - case STORAGE_ON_DISK_DEFERRED: - return scoped_ptr<syncable::DirectoryBackingStore>( - new syncable::DeferredOnDiskDirectoryBackingStore(dir_name, - backing_filepath)); case STORAGE_INVALID: return scoped_ptr<syncable::DirectoryBackingStore>( new syncable::InvalidDirectoryBackingStore()); diff --git a/sync/protocol/device_info_specifics.proto b/sync/protocol/device_info_specifics.proto index 99af88b..0103aa6 100644 --- a/sync/protocol/device_info_specifics.proto +++ b/sync/protocol/device_info_specifics.proto @@ -37,7 +37,8 @@ message DeviceInfoSpecifics { // Last time when pre-sync data on the device was saved. The device can be // restored to state back to this time. In millisecond since UNIX epoch. - optional int64 backup_timestamp = 6; + // DEPRECATED in M50. + optional int64 deprecated_backup_timestamp = 6 [deprecated=true]; // Device_id that is stable until user signs out. This device_id is used for // annotating login scoped refresh token. diff --git a/sync/protocol/proto_enum_conversions.cc b/sync/protocol/proto_enum_conversions.cc index 0c6cf73..84a5b03 100644 --- a/sync/protocol/proto_enum_conversions.cc +++ b/sync/protocol/proto_enum_conversions.cc @@ -164,7 +164,7 @@ const char* GetErrorTypeString(sync_pb::SyncEnums::ErrorType error_type) { ENUM_CASE(sync_pb::SyncEnums, TRANSIENT_ERROR); ENUM_CASE(sync_pb::SyncEnums, MIGRATION_DONE); ENUM_CASE(sync_pb::SyncEnums, DISABLED_BY_ADMIN); - ENUM_CASE(sync_pb::SyncEnums, USER_ROLLBACK); + ENUM_CASE(sync_pb::SyncEnums, DEPRECATED_USER_ROLLBACK); ENUM_CASE(sync_pb::SyncEnums, PARTIAL_FAILURE); ENUM_CASE(sync_pb::SyncEnums, CLIENT_DATA_OBSOLETE); ENUM_CASE(sync_pb::SyncEnums, UNKNOWN); diff --git a/sync/protocol/proto_value_conversions.cc b/sync/protocol/proto_value_conversions.cc index 4fee4ee..327723c 100644 --- a/sync/protocol/proto_value_conversions.cc +++ b/sync/protocol/proto_value_conversions.cc @@ -80,10 +80,6 @@ scoped_ptr<base::ListValue> MakeRepeatedValue(const F& fields, return list; } -base::string16 TimestampToString(int64_t tm) { - return base::TimeFormatShortDateAndTime(syncer::ProtoTimeToTime(tm)); -} - } // namespace // Helper macros to reduce the amount of boilerplate. @@ -412,7 +408,6 @@ scoped_ptr<base::DictionaryValue> DeviceInfoSpecificsToValue( SET_ENUM(device_type, GetDeviceTypeString); SET_STR(sync_user_agent); SET_STR(chrome_version); - SET_TIME_STR(backup_timestamp); SET_STR(signin_scoped_device_id); return value; } diff --git a/sync/protocol/sync_enums.proto b/sync/protocol/sync_enums.proto index bdfb45e..0e18575 100644 --- a/sync/protocol/sync_enums.proto +++ b/sync/protocol/sync_enums.proto @@ -96,7 +96,7 @@ message SyncEnums { // a server. DISABLED_BY_ADMIN = 10; // An administrator disabled sync for this // domain. - USER_ROLLBACK = 11; // Client told to stop syncing and roll back. + DEPRECATED_USER_ROLLBACK = 11; // Deprecated in M50. PARTIAL_FAILURE = 12; // Return when client want to update several // data types, but some of them failed(e.g. // throttled). diff --git a/sync/protocol/sync_protocol_error.cc b/sync/protocol/sync_protocol_error.cc index 992f6ac..c82d32e 100644 --- a/sync/protocol/sync_protocol_error.cc +++ b/sync/protocol/sync_protocol_error.cc @@ -22,7 +22,6 @@ const char* GetSyncErrorTypeString(SyncProtocolErrorType type) { ENUM_CASE(MIGRATION_DONE); ENUM_CASE(INVALID_CREDENTIAL); ENUM_CASE(DISABLED_BY_ADMIN); - ENUM_CASE(USER_ROLLBACK); ENUM_CASE(PARTIAL_FAILURE); ENUM_CASE(CLIENT_DATA_OBSOLETE); ENUM_CASE(UNKNOWN_ERROR); @@ -39,8 +38,6 @@ const char* GetClientActionString(ClientAction action) { ENUM_CASE(STOP_AND_RESTART_SYNC); ENUM_CASE(DISABLE_SYNC_ON_CLIENT); ENUM_CASE(STOP_SYNC_FOR_DISABLED_ACCOUNT); - ENUM_CASE(DISABLE_SYNC_AND_ROLLBACK); - ENUM_CASE(ROLLBACK_DONE); ENUM_CASE(RESET_LOCAL_SYNC_DATA); ENUM_CASE(UNKNOWN_ACTION); } diff --git a/sync/protocol/sync_protocol_error.h b/sync/protocol/sync_protocol_error.h index 38c5f18..7ba8d6c 100644 --- a/sync/protocol/sync_protocol_error.h +++ b/sync/protocol/sync_protocol_error.h @@ -38,9 +38,6 @@ enum SyncProtocolErrorType { // An administrator disabled sync for this domain. DISABLED_BY_ADMIN, - // Client told to stop syncing this device and roll back local data. - USER_ROLLBACK, - // Some of servers are busy. Try later with busy servers. PARTIAL_FAILURE, @@ -72,13 +69,6 @@ enum ClientAction { // settings page that account is disabled. STOP_SYNC_FOR_DISABLED_ACCOUNT, - // Disable sync and roll back local model to pre-sync state. - DISABLE_SYNC_AND_ROLLBACK, - - // Generated by SyncRollbackManager to notify ProfileSyncService that - // rollback is finished. - ROLLBACK_DONE, - // Generated in response to CLIENT_DATA_OBSOLETE error. ProfileSyncService // should stop sync engine, delete directory and restart sync engine. RESET_LOCAL_SYNC_DATA, diff --git a/sync/sync.gyp b/sync/sync.gyp index 9981376..f5303cb 100644 --- a/sync/sync.gyp +++ b/sync/sync.gyp @@ -350,8 +350,6 @@ 'internal_api/read_node.cc', 'internal_api/read_transaction.cc', 'internal_api/shared_model_type_processor.cc', - 'internal_api/sync_backup_manager.cc', - 'internal_api/sync_backup_manager.h', 'internal_api/sync_context.cc', 'internal_api/sync_context_proxy.cc', 'internal_api/sync_context_proxy_impl.cc', @@ -362,10 +360,6 @@ 'internal_api/sync_manager_factory.cc', 'internal_api/sync_manager_impl.cc', 'internal_api/sync_manager_impl.h', - 'internal_api/sync_rollback_manager.cc', - 'internal_api/sync_rollback_manager.h', - 'internal_api/sync_rollback_manager_base.cc', - 'internal_api/sync_rollback_manager_base.h', 'internal_api/syncapi_internal.cc', 'internal_api/syncapi_internal.h', 'internal_api/syncapi_server_connection_manager.cc', @@ -401,8 +395,6 @@ 'sessions/sync_session.h', 'sessions/sync_session_context.cc', 'sessions/sync_session_context.h', - 'syncable/deferred_on_disk_directory_backing_store.cc', - 'syncable/deferred_on_disk_directory_backing_store.h', 'syncable/dir_open_result.h', 'syncable/directory.cc', 'syncable/directory.h', diff --git a/sync/sync_tests.gypi b/sync/sync_tests.gypi index 122641e..bacf837 100644 --- a/sync/sync_tests.gypi +++ b/sync/sync_tests.gypi @@ -321,12 +321,9 @@ 'internal_api/public/util/proto_value_ptr_unittest.cc', 'internal_api/public/util/weak_handle_unittest.cc', 'internal_api/shared_model_type_processor_unittest.cc', - 'internal_api/sync_backup_manager_unittest.cc', 'internal_api/sync_context_proxy_impl_unittest.cc', 'internal_api/sync_encryption_handler_impl_unittest.cc', 'internal_api/sync_manager_impl_unittest.cc', - 'internal_api/sync_rollback_manager_base_unittest.cc', - 'internal_api/sync_rollback_manager_unittest.cc', 'internal_api/syncapi_server_connection_manager_unittest.cc', 'js/js_event_details_unittest.cc', 'js/sync_js_controller_unittest.cc', @@ -335,7 +332,6 @@ 'sessions/model_type_registry_unittest.cc', 'sessions/nudge_tracker_unittest.cc', 'sessions/status_controller_unittest.cc', - 'syncable/deferred_on_disk_directory_backing_store_unittest.cc', 'syncable/directory_backing_store_unittest.cc', 'syncable/directory_unittest.cc', 'syncable/directory_unittest.h', diff --git a/sync/syncable/deferred_on_disk_directory_backing_store.cc b/sync/syncable/deferred_on_disk_directory_backing_store.cc deleted file mode 100644 index 5e960d2..0000000 --- a/sync/syncable/deferred_on_disk_directory_backing_store.cc +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "sync/syncable/deferred_on_disk_directory_backing_store.h" - -#include "base/logging.h" -#include "base/metrics/histogram.h" -#include "base/stl_util.h" -#include "sync/syncable/syncable-inl.h" - -namespace syncer { -namespace syncable { - -DeferredOnDiskDirectoryBackingStore::DeferredOnDiskDirectoryBackingStore( - const std::string& dir_name, - const base::FilePath& backing_file_path) - : OnDiskDirectoryBackingStore(dir_name, backing_file_path), - created_on_disk_(false) { -} - -DeferredOnDiskDirectoryBackingStore::~DeferredOnDiskDirectoryBackingStore() {} - -bool DeferredOnDiskDirectoryBackingStore::SaveChanges( - const Directory::SaveChangesSnapshot& snapshot) { - DCHECK(CalledOnValidThread()); - - // Back out early if there is nothing to save. - if (!snapshot.HasUnsavedMetahandleChanges()) { - return true; - } - if (!created_on_disk_ && !CreateOnDisk()) - return false; - return OnDiskDirectoryBackingStore::SaveChanges(snapshot); -} - -bool DeferredOnDiskDirectoryBackingStore::CreateOnDisk() { - DCHECK(CalledOnValidThread()); - DCHECK(!created_on_disk_); - ResetAndCreateConnection(); - if (!base::DeleteFile(backing_file_path(), false)) - return false; - if (!Open(backing_file_path()) || !InitializeTables()) - return false; - created_on_disk_ = true; - return true; -} - -DirOpenResult DeferredOnDiskDirectoryBackingStore::Load( - Directory::MetahandlesMap* handles_map, - JournalIndex* delete_journals, - MetahandleSet* metahandles_to_purge, - Directory::KernelLoadInfo* kernel_load_info) { - DCHECK(CalledOnValidThread()); - // Open an in-memory database at first to create initial sync data needed by - // Directory. - CHECK(!IsOpen()); - if (!OpenInMemory()) - return FAILED_OPEN_DATABASE; - - if (!InitializeTables()) - return FAILED_OPEN_DATABASE; - if (!LoadEntries(handles_map, metahandles_to_purge)) - return FAILED_DATABASE_CORRUPT; - if (!LoadInfo(kernel_load_info)) - return FAILED_DATABASE_CORRUPT; - - return OPENED; -} - -} // namespace syncable -} // namespace syncer diff --git a/sync/syncable/deferred_on_disk_directory_backing_store.h b/sync/syncable/deferred_on_disk_directory_backing_store.h deleted file mode 100644 index 0531737..0000000 --- a/sync/syncable/deferred_on_disk_directory_backing_store.h +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef SYNC_SYNCABLE_DEFERRED_ON_DISK_DIRECTORY_BACKING_STORE_H_ -#define SYNC_SYNCABLE_DEFERRED_ON_DISK_DIRECTORY_BACKING_STORE_H_ - -#include <string> - -#include "base/files/file_path.h" -#include "base/macros.h" -#include "sync/base/sync_export.h" -#include "sync/syncable/on_disk_directory_backing_store.h" - -namespace syncer { -namespace syncable { - -// Store used for backing up user's data before first sync. It creates an -// in-memory store first and switch to on-disk store if SaveChanges() is -// called, which only happens when SyncBackupManager is shut down and a -// syncing backend is to be created. Thus we guarantee that user data is not -// persisted until user is actually going to sync. -class SYNC_EXPORT DeferredOnDiskDirectoryBackingStore - : public OnDiskDirectoryBackingStore { - public: - DeferredOnDiskDirectoryBackingStore(const std::string& dir_name, - const base::FilePath& backing_file_path); - ~DeferredOnDiskDirectoryBackingStore() override; - DirOpenResult Load(Directory::MetahandlesMap* handles_map, - JournalIndex* delete_journals, - MetahandleSet* metahandles_to_purge, - Directory::KernelLoadInfo* kernel_load_info) override; - bool SaveChanges(const Directory::SaveChangesSnapshot& snapshot) override; - - private: - // Create an on-disk directory backing store. Returns true on success, false - // on error. - bool CreateOnDisk(); - - // Whether an on-disk directory backing store has been created. - bool created_on_disk_; - - DISALLOW_COPY_AND_ASSIGN(DeferredOnDiskDirectoryBackingStore); -}; - -} // namespace syncable -} // namespace syncer - -#endif // SYNC_SYNCABLE_DEFERRED_ON_DISK_DIRECTORY_BACKING_STORE_H_ diff --git a/sync/syncable/deferred_on_disk_directory_backing_store_unittest.cc b/sync/syncable/deferred_on_disk_directory_backing_store_unittest.cc deleted file mode 100644 index a62060a..0000000 --- a/sync/syncable/deferred_on_disk_directory_backing_store_unittest.cc +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/files/scoped_temp_dir.h" -#include "base/message_loop/message_loop.h" -#include "base/stl_util.h" -#include "sync/syncable/deferred_on_disk_directory_backing_store.h" -#include "sync/syncable/directory.h" -#include "sync/syncable/entry_kernel.h" -#include "sync/syncable/on_disk_directory_backing_store.h" -#include "sync/syncable/syncable_delete_journal.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace syncer { -namespace syncable { -namespace { - -static const base::FilePath::CharType kSyncDataFolderName[] = - FILE_PATH_LITERAL("Sync Data"); - -class DeferredOnDiskDirectoryBackingStoreTest : public testing::Test { - protected: - void SetUp() override { - CHECK(temp_dir_.CreateUniqueTempDir()); - db_path_ = temp_dir_.path().Append(kSyncDataFolderName); - } - - void TearDown() override { STLDeleteValues(&handles_map_); } - - base::MessageLoop message_loop_; - base::ScopedTempDir temp_dir_; - base::FilePath db_path_; - Directory::MetahandlesMap handles_map_; - JournalIndex delete_journals_; - MetahandleSet metahandles_to_purge_; - Directory::KernelLoadInfo kernel_load_info_; -}; - -// Test initialization of root entry when calling Load(). -TEST_F(DeferredOnDiskDirectoryBackingStoreTest, Load) { - DeferredOnDiskDirectoryBackingStore store("test", db_path_); - EXPECT_EQ(OPENED, store.Load(&handles_map_, &delete_journals_, - &metahandles_to_purge_, &kernel_load_info_)); - EXPECT_TRUE(delete_journals_.empty()); - EXPECT_TRUE(metahandles_to_purge_.empty()); - ASSERT_EQ(1u, handles_map_.size()); // root node - ASSERT_TRUE(handles_map_.count(1)); - EntryKernel* root = handles_map_[1]; - EXPECT_TRUE(root->ref(ID).IsRoot()); - EXPECT_EQ(1, root->ref(META_HANDLE)); - EXPECT_TRUE(root->ref(IS_DIR)); -} - -// Test on-disk DB is not created if SaveChanges() is not called. -TEST_F(DeferredOnDiskDirectoryBackingStoreTest, - DontPersistIfSavingChangesNotCalled) { - { - // Open and close. - DeferredOnDiskDirectoryBackingStore store("test", db_path_); - EXPECT_EQ(OPENED, store.Load(&handles_map_, &delete_journals_, - &metahandles_to_purge_, &kernel_load_info_)); - } - - EXPECT_FALSE(base::PathExists(db_path_)); -} - -// Test on-disk DB is not created when there are no changes. -TEST_F(DeferredOnDiskDirectoryBackingStoreTest, - DontPersistWhenSavingNoChanges) { - { - // Open and close. - DeferredOnDiskDirectoryBackingStore store("test", db_path_); - EXPECT_EQ(OPENED, store.Load(&handles_map_, &delete_journals_, - &metahandles_to_purge_, &kernel_load_info_)); - - Directory::SaveChangesSnapshot snapshot; - store.SaveChanges(snapshot); - } - - EXPECT_FALSE(base::PathExists(db_path_)); -} - -// Test changes are persisted to disk when SaveChanges() is called. -TEST_F(DeferredOnDiskDirectoryBackingStoreTest, PersistWhenSavingValidChanges) { - { - // Open and close. - DeferredOnDiskDirectoryBackingStore store("test", db_path_); - EXPECT_EQ(OPENED, store.Load(&handles_map_, &delete_journals_, - &metahandles_to_purge_, &kernel_load_info_)); - - Directory::SaveChangesSnapshot snapshot; - EntryKernel* entry = new EntryKernel(); - entry->put(ID, Id::CreateFromClientString("test_entry")); - entry->put(META_HANDLE, 2); - entry->mark_dirty(NULL); - snapshot.dirty_metas.insert(entry); - store.SaveChanges(snapshot); - } - - STLDeleteValues(&handles_map_); - - ASSERT_TRUE(base::PathExists(db_path_)); - OnDiskDirectoryBackingStore read_store("test", db_path_); - EXPECT_EQ(OPENED, - read_store.Load(&handles_map_, &delete_journals_, - &metahandles_to_purge_, &kernel_load_info_)); - ASSERT_EQ(2u, handles_map_.size()); - ASSERT_TRUE(handles_map_.count(1)); // root node - ASSERT_TRUE(handles_map_.count(2)); - EntryKernel* entry = handles_map_[2]; - EXPECT_EQ(Id::CreateFromClientString("test_entry"), entry->ref(ID)); -} - -} // namespace -} // namespace syncable -} // namespace syncer diff --git a/sync/tools/sync_client.cc b/sync/tools/sync_client.cc index deba666..36c7561 100644 --- a/sync/tools/sync_client.cc +++ b/sync/tools/sync_client.cc @@ -396,7 +396,7 @@ int SyncClientMain(int argc, char* argv[]) { workers.push_back(passive_model_safe_worker); // Set up sync manager. - SyncManagerFactory sync_manager_factory(SyncManagerFactory::NORMAL); + SyncManagerFactory sync_manager_factory; scoped_ptr<SyncManager> sync_manager = sync_manager_factory.CreateSyncManager("sync_client manager"); LoggingJsEventHandler js_event_handler; diff --git a/tools/metrics/histograms/histograms.xml b/tools/metrics/histograms/histograms.xml index bf75c1d..96a48bc 100644 --- a/tools/metrics/histograms/histograms.xml +++ b/tools/metrics/histograms/histograms.xml @@ -50212,6 +50212,9 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries. </histogram> <histogram name="Sync.FirstSyncDelayByBackup" units="ms"> + <obsolete> + Backup logic has been removed since 02/2016. + </obsolete> <owner>haitaol@chromium.org</owner> <summary>First sync delay casued by backing up user data.</summary> </histogram> |
