Commit e80ccef9 authored by haitaol@chromium.org's avatar haitaol@chromium.org

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
parent ee02f737
...@@ -976,6 +976,7 @@ sync_pb::SyncEnums::Action GetClientToServerResponseAction( ...@@ -976,6 +976,7 @@ sync_pb::SyncEnums::Action GetClientToServerResponseAction(
return sync_pb::SyncEnums::DISABLE_SYNC_ON_CLIENT; return sync_pb::SyncEnums::DISABLE_SYNC_ON_CLIENT;
case syncer::STOP_SYNC_FOR_DISABLED_ACCOUNT: case syncer::STOP_SYNC_FOR_DISABLED_ACCOUNT:
case syncer::DISABLE_SYNC_AND_ROLLBACK: case syncer::DISABLE_SYNC_AND_ROLLBACK:
case syncer::ROLLBACK_DONE:
NOTREACHED(); // No corresponding proto action for these. Shouldn't NOTREACHED(); // No corresponding proto action for these. Shouldn't
// test. // test.
return sync_pb::SyncEnums::UNKNOWN_ACTION; return sync_pb::SyncEnums::UNKNOWN_ACTION;
......
...@@ -67,8 +67,12 @@ void SyncRollbackManager::Init( ...@@ -67,8 +67,12 @@ void SyncRollbackManager::Init(
void SyncRollbackManager::StartSyncingNormally( void SyncRollbackManager::StartSyncingNormally(
const ModelSafeRoutingInfo& routing_info){ 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()); WriteTransaction trans(FROM_HERE, GetUserShare());
syncable::Directory::Metahandles unsynced; syncable::Directory::Metahandles unsynced;
...@@ -100,6 +104,8 @@ void SyncRollbackManager::StartSyncingNormally( ...@@ -100,6 +104,8 @@ void SyncRollbackManager::StartSyncingNormally(
base::Unretained(this), base::Unretained(this),
it->first, it->second)); it->first, it->second));
} }
NotifyRollbackDone();
} }
SyncerError SyncRollbackManager::DeleteOnWorkerThread( SyncerError SyncRollbackManager::DeleteOnWorkerThread(
...@@ -130,4 +136,11 @@ SyncerError SyncRollbackManager::DeleteOnWorkerThread( ...@@ -130,4 +136,11 @@ SyncerError SyncRollbackManager::DeleteOnWorkerThread(
return SYNCER_OK; return SYNCER_OK;
} }
void SyncRollbackManager::NotifyRollbackDone() {
SyncProtocolError error;
error.action = ROLLBACK_DONE;
FOR_EACH_OBSERVER(SyncManager::Observer, *GetObservers(),
OnActionableError(error));
}
} // namespace syncer } // namespace syncer
...@@ -47,6 +47,8 @@ class SYNC_EXPORT_PRIVATE SyncRollbackManager : public SyncRollbackManagerBase { ...@@ -47,6 +47,8 @@ class SYNC_EXPORT_PRIVATE SyncRollbackManager : public SyncRollbackManagerBase {
// Deletes specified entries in local model. // Deletes specified entries in local model.
SyncerError DeleteOnWorkerThread(ModelType type, std::vector<int64> handles); SyncerError DeleteOnWorkerThread(ModelType type, std::vector<int64> handles);
void NotifyRollbackDone();
std::map<ModelSafeGroup, scoped_refptr<ModelSafeWorker> > workers_; std::map<ModelSafeGroup, scoped_refptr<ModelSafeWorker> > workers_;
SyncManager::ChangeDelegate* change_delegate_; SyncManager::ChangeDelegate* change_delegate_;
......
...@@ -332,6 +332,10 @@ void SyncRollbackManagerBase::InitBookmarkFolder(const std::string& folder) { ...@@ -332,6 +332,10 @@ void SyncRollbackManagerBase::InitBookmarkFolder(const std::string& folder) {
entry.PutSpecifics(specifics); entry.PutSpecifics(specifics);
} }
ObserverList<SyncManager::Observer>* SyncRollbackManagerBase::GetObservers() {
return &observers_;
}
void SyncRollbackManagerBase::RegisterDirectoryTypeDebugInfoObserver( void SyncRollbackManagerBase::RegisterDirectoryTypeDebugInfoObserver(
syncer::TypeDebugInfoObserver* observer) {} syncer::TypeDebugInfoObserver* observer) {}
......
...@@ -113,6 +113,9 @@ class SYNC_EXPORT_PRIVATE SyncRollbackManagerBase : ...@@ -113,6 +113,9 @@ class SYNC_EXPORT_PRIVATE SyncRollbackManagerBase :
const syncable::ImmutableWriteTransactionInfo& write_transaction_info, const syncable::ImmutableWriteTransactionInfo& write_transaction_info,
ModelTypeSet models_with_changes) OVERRIDE; ModelTypeSet models_with_changes) OVERRIDE;
protected:
ObserverList<SyncManager::Observer>* GetObservers();
virtual void RegisterDirectoryTypeDebugInfoObserver( virtual void RegisterDirectoryTypeDebugInfoObserver(
syncer::TypeDebugInfoObserver* observer) OVERRIDE; syncer::TypeDebugInfoObserver* observer) OVERRIDE;
virtual void UnregisterDirectoryTypeDebugInfoObserver( virtual void UnregisterDirectoryTypeDebugInfoObserver(
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/files/scoped_temp_dir.h" #include "base/files/scoped_temp_dir.h"
#include "sync/internal_api/public/read_node.h" #include "sync/internal_api/public/read_node.h"
#include "sync/internal_api/public/read_transaction.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/test/test_internal_components_factory.h"
#include "sync/internal_api/public/write_node.h" #include "sync/internal_api/public/write_node.h"
#include "sync/internal_api/public/write_transaction.h" #include "sync/internal_api/public/write_transaction.h"
...@@ -20,6 +21,7 @@ ...@@ -20,6 +21,7 @@
using ::testing::_; using ::testing::_;
using ::testing::DoDefault; using ::testing::DoDefault;
using ::testing::Invoke; using ::testing::Invoke;
using ::testing::Truly;
using ::testing::WithArgs; using ::testing::WithArgs;
namespace syncer { namespace syncer {
...@@ -61,7 +63,8 @@ class TestChangeDelegate : public SyncManager::ChangeDelegate { ...@@ -61,7 +63,8 @@ class TestChangeDelegate : public SyncManager::ChangeDelegate {
std::set<int64> expected_deletes_; std::set<int64> expected_deletes_;
}; };
class SyncRollbackManagerTest : public testing::Test { class SyncRollbackManagerTest : public testing::Test,
public SyncManager::Observer {
protected: protected:
virtual void SetUp() OVERRIDE { virtual void SetUp() OVERRIDE {
CHECK(temp_dir_.CreateUniqueTempDir()); CHECK(temp_dir_.CreateUniqueTempDir());
...@@ -69,6 +72,17 @@ class SyncRollbackManagerTest : public testing::Test { ...@@ -69,6 +72,17 @@ class SyncRollbackManagerTest : public testing::Test {
worker_ = new FakeModelWorker(GROUP_UI); 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) { void OnConfigDone(bool success) {
EXPECT_TRUE(success); EXPECT_TRUE(success);
} }
...@@ -88,6 +102,7 @@ class SyncRollbackManagerTest : public testing::Test { ...@@ -88,6 +102,7 @@ class SyncRollbackManagerTest : public testing::Test {
void InitManager(SyncManager* manager, ModelTypeSet types, void InitManager(SyncManager* manager, ModelTypeSet types,
TestChangeDelegate* delegate) { TestChangeDelegate* delegate) {
manager->AddObserver(this);
TestInternalComponentsFactory factory(InternalComponentsFactory::Switches(), TestInternalComponentsFactory factory(InternalComponentsFactory::Switches(),
STORAGE_ON_DISK); STORAGE_ON_DISK);
...@@ -131,6 +146,10 @@ class SyncRollbackManagerTest : public testing::Test { ...@@ -131,6 +146,10 @@ class SyncRollbackManagerTest : public testing::Test {
base::MessageLoop loop_; // Needed for WeakHandle base::MessageLoop loop_; // Needed for WeakHandle
}; };
bool IsRollbackDoneAction(SyncProtocolError e) {
return e.action == syncer::ROLLBACK_DONE;
}
TEST_F(SyncRollbackManagerTest, RollbackBasic) { TEST_F(SyncRollbackManagerTest, RollbackBasic) {
PrepopulateDb(PREFERENCES, "pref1"); PrepopulateDb(PREFERENCES, "pref1");
...@@ -147,6 +166,7 @@ TEST_F(SyncRollbackManagerTest, RollbackBasic) { ...@@ -147,6 +166,7 @@ TEST_F(SyncRollbackManagerTest, RollbackBasic) {
.Times(1) .Times(1)
.WillOnce(DoDefault()); .WillOnce(DoDefault());
EXPECT_CALL(delegate, OnChangesComplete(_)).Times(1); EXPECT_CALL(delegate, OnChangesComplete(_)).Times(1);
EXPECT_CALL(*this, OnActionableError(Truly(IsRollbackDoneAction))).Times(1);
ModelSafeRoutingInfo routing_info; ModelSafeRoutingInfo routing_info;
routing_info[PREFERENCES] = GROUP_UI; routing_info[PREFERENCES] = GROUP_UI;
......
...@@ -39,6 +39,7 @@ const char* GetClientActionString(ClientAction action) { ...@@ -39,6 +39,7 @@ const char* GetClientActionString(ClientAction action) {
ENUM_CASE(DISABLE_SYNC_ON_CLIENT); ENUM_CASE(DISABLE_SYNC_ON_CLIENT);
ENUM_CASE(STOP_SYNC_FOR_DISABLED_ACCOUNT); ENUM_CASE(STOP_SYNC_FOR_DISABLED_ACCOUNT);
ENUM_CASE(DISABLE_SYNC_AND_ROLLBACK); ENUM_CASE(DISABLE_SYNC_AND_ROLLBACK);
ENUM_CASE(ROLLBACK_DONE);
ENUM_CASE(UNKNOWN_ACTION); ENUM_CASE(UNKNOWN_ACTION);
} }
NOTREACHED(); NOTREACHED();
......
...@@ -72,6 +72,10 @@ enum ClientAction { ...@@ -72,6 +72,10 @@ enum ClientAction {
// Disable sync and roll back local model to pre-sync state. // Disable sync and roll back local model to pre-sync state.
DISABLE_SYNC_AND_ROLLBACK, DISABLE_SYNC_AND_ROLLBACK,
// Generated by SyncRollbackManager to notify ProfileSyncService that
// rollback is finished.
ROLLBACK_DONE,
// The default. No action. // The default. No action.
UNKNOWN_ACTION UNKNOWN_ACTION
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment