diff options
author | haitaol@chromium.org <haitaol@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-10 19:11:51 +0000 |
---|---|---|
committer | haitaol@chromium.org <haitaol@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-10 19:11:51 +0000 |
commit | e80ccef9d9946368d44463eda0bf49e4fa1279a1 (patch) | |
tree | 577bf3bb940efa1897d367c07d5484d3b417ae59 | |
parent | ee02f7375d3de6ef6ded9c2545f240e46551fb02 (diff) | |
download | chromium_src-e80ccef9d9946368d44463eda0bf49e4fa1279a1.zip chromium_src-e80ccef9d9946368d44463eda0bf49e4fa1279a1.tar.gz chromium_src-e80ccef9d9946368d44463eda0bf49e4fa1279a1.tar.bz2 |
Add a ClientAction used by SyncRollbackManager to notify PSS that rollback is
finished.
BUG=362679
Review URL: https://codereview.chromium.org/263273002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@269615 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/sync/test/integration/sync_test.cc | 1 | ||||
-rw-r--r-- | sync/internal_api/sync_rollback_manager.cc | 15 | ||||
-rw-r--r-- | sync/internal_api/sync_rollback_manager.h | 2 | ||||
-rw-r--r-- | sync/internal_api/sync_rollback_manager_base.cc | 4 | ||||
-rw-r--r-- | sync/internal_api/sync_rollback_manager_base.h | 3 | ||||
-rw-r--r-- | sync/internal_api/sync_rollback_manager_unittest.cc | 22 | ||||
-rw-r--r-- | sync/protocol/sync_protocol_error.cc | 1 | ||||
-rw-r--r-- | sync/protocol/sync_protocol_error.h | 4 |
8 files changed, 50 insertions, 2 deletions
diff --git a/chrome/browser/sync/test/integration/sync_test.cc b/chrome/browser/sync/test/integration/sync_test.cc index 91adcf6..2cd83b1 100644 --- a/chrome/browser/sync/test/integration/sync_test.cc +++ b/chrome/browser/sync/test/integration/sync_test.cc @@ -976,6 +976,7 @@ sync_pb::SyncEnums::Action GetClientToServerResponseAction( return sync_pb::SyncEnums::DISABLE_SYNC_ON_CLIENT; case syncer::STOP_SYNC_FOR_DISABLED_ACCOUNT: case syncer::DISABLE_SYNC_AND_ROLLBACK: + case syncer::ROLLBACK_DONE: NOTREACHED(); // No corresponding proto action for these. Shouldn't // test. return sync_pb::SyncEnums::UNKNOWN_ACTION; diff --git a/sync/internal_api/sync_rollback_manager.cc b/sync/internal_api/sync_rollback_manager.cc index 240218d..84367b0 100644 --- a/sync/internal_api/sync_rollback_manager.cc +++ b/sync/internal_api/sync_rollback_manager.cc @@ -67,8 +67,12 @@ void SyncRollbackManager::Init( void SyncRollbackManager::StartSyncingNormally( const ModelSafeRoutingInfo& routing_info){ - std::map<ModelType, syncable::Directory::Metahandles> to_delete; + if (rollback_ready_types_.Empty()) { + NotifyRollbackDone(); + return; + } + std::map<ModelType, syncable::Directory::Metahandles> to_delete; { WriteTransaction trans(FROM_HERE, GetUserShare()); syncable::Directory::Metahandles unsynced; @@ -100,6 +104,8 @@ void SyncRollbackManager::StartSyncingNormally( base::Unretained(this), it->first, it->second)); } + + NotifyRollbackDone(); } SyncerError SyncRollbackManager::DeleteOnWorkerThread( @@ -130,4 +136,11 @@ SyncerError SyncRollbackManager::DeleteOnWorkerThread( 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 index c8b8719..fed4fd4 100644 --- a/sync/internal_api/sync_rollback_manager.h +++ b/sync/internal_api/sync_rollback_manager.h @@ -47,6 +47,8 @@ class SYNC_EXPORT_PRIVATE SyncRollbackManager : public SyncRollbackManagerBase { // Deletes specified entries in local model. SyncerError DeleteOnWorkerThread(ModelType type, std::vector<int64> handles); + void NotifyRollbackDone(); + std::map<ModelSafeGroup, scoped_refptr<ModelSafeWorker> > workers_; SyncManager::ChangeDelegate* change_delegate_; diff --git a/sync/internal_api/sync_rollback_manager_base.cc b/sync/internal_api/sync_rollback_manager_base.cc index e5a4779..af20341 100644 --- a/sync/internal_api/sync_rollback_manager_base.cc +++ b/sync/internal_api/sync_rollback_manager_base.cc @@ -332,6 +332,10 @@ void SyncRollbackManagerBase::InitBookmarkFolder(const std::string& folder) { entry.PutSpecifics(specifics); } +ObserverList<SyncManager::Observer>* SyncRollbackManagerBase::GetObservers() { + return &observers_; +} + void SyncRollbackManagerBase::RegisterDirectoryTypeDebugInfoObserver( syncer::TypeDebugInfoObserver* observer) {} diff --git a/sync/internal_api/sync_rollback_manager_base.h b/sync/internal_api/sync_rollback_manager_base.h index b6469da..ac91e98 100644 --- a/sync/internal_api/sync_rollback_manager_base.h +++ b/sync/internal_api/sync_rollback_manager_base.h @@ -113,6 +113,9 @@ class SYNC_EXPORT_PRIVATE SyncRollbackManagerBase : const syncable::ImmutableWriteTransactionInfo& write_transaction_info, ModelTypeSet models_with_changes) OVERRIDE; + protected: + ObserverList<SyncManager::Observer>* GetObservers(); + virtual void RegisterDirectoryTypeDebugInfoObserver( syncer::TypeDebugInfoObserver* observer) OVERRIDE; virtual void UnregisterDirectoryTypeDebugInfoObserver( diff --git a/sync/internal_api/sync_rollback_manager_unittest.cc b/sync/internal_api/sync_rollback_manager_unittest.cc index d2d00e4..925d635 100644 --- a/sync/internal_api/sync_rollback_manager_unittest.cc +++ b/sync/internal_api/sync_rollback_manager_unittest.cc @@ -7,6 +7,7 @@ #include "base/files/scoped_temp_dir.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" @@ -20,6 +21,7 @@ using ::testing::_; using ::testing::DoDefault; using ::testing::Invoke; +using ::testing::Truly; using ::testing::WithArgs; namespace syncer { @@ -61,7 +63,8 @@ class TestChangeDelegate : public SyncManager::ChangeDelegate { std::set<int64> expected_deletes_; }; -class SyncRollbackManagerTest : public testing::Test { +class SyncRollbackManagerTest : public testing::Test, + public SyncManager::Observer { protected: virtual void SetUp() OVERRIDE { CHECK(temp_dir_.CreateUniqueTempDir()); @@ -69,6 +72,17 @@ class SyncRollbackManagerTest : public testing::Test { 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); } @@ -88,6 +102,7 @@ class SyncRollbackManagerTest : public testing::Test { void InitManager(SyncManager* manager, ModelTypeSet types, TestChangeDelegate* delegate) { + manager->AddObserver(this); TestInternalComponentsFactory factory(InternalComponentsFactory::Switches(), STORAGE_ON_DISK); @@ -131,6 +146,10 @@ class SyncRollbackManagerTest : public testing::Test { base::MessageLoop loop_; // Needed for WeakHandle }; +bool IsRollbackDoneAction(SyncProtocolError e) { + return e.action == syncer::ROLLBACK_DONE; +} + TEST_F(SyncRollbackManagerTest, RollbackBasic) { PrepopulateDb(PREFERENCES, "pref1"); @@ -147,6 +166,7 @@ TEST_F(SyncRollbackManagerTest, RollbackBasic) { .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; diff --git a/sync/protocol/sync_protocol_error.cc b/sync/protocol/sync_protocol_error.cc index ac9e2fd..713137d 100644 --- a/sync/protocol/sync_protocol_error.cc +++ b/sync/protocol/sync_protocol_error.cc @@ -39,6 +39,7 @@ const char* GetClientActionString(ClientAction action) { 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(UNKNOWN_ACTION); } NOTREACHED(); diff --git a/sync/protocol/sync_protocol_error.h b/sync/protocol/sync_protocol_error.h index aef7650..0c825b7 100644 --- a/sync/protocol/sync_protocol_error.h +++ b/sync/protocol/sync_protocol_error.h @@ -72,6 +72,10 @@ enum ClientAction { // 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, + // The default. No action. UNKNOWN_ACTION }; |