Commit 92b21f8a authored by zea's avatar zea Committed by Commit bot

[Sync] Have configuration specify which datatypes are ready to sync

In preparation for performing model association while other types are downloading,
the BackendDataTypeConfigurer::ConfigureDataTypes method will now return those
types that are ready to sync without further intervention from sync. These are the
types that were already syncing previously, and therefore don't need to be
downloaded or purged.

A followup patch will add the association logic and tests.

BUG=477063

Review URL: https://codereview.chromium.org/1081413003

Cr-Commit-Position: refs/heads/master@{#325582}
parent 5e41d3df
...@@ -133,7 +133,10 @@ class SyncBackendHost : public sync_driver::BackendDataTypeConfigurer { ...@@ -133,7 +133,10 @@ class SyncBackendHost : public sync_driver::BackendDataTypeConfigurer {
// The ready_task will be run when configuration is done with the // The ready_task will be run when configuration is done with the
// set of all types that failed configuration (i.e., if its argument // set of all types that failed configuration (i.e., if its argument
// is non-empty, then an error was encountered). // is non-empty, then an error was encountered).
void ConfigureDataTypes( // Returns the set of types that are ready to start without needing any
// further sync activity.
// BackendDataTypeConfigurer implementation.
syncer::ModelTypeSet ConfigureDataTypes(
syncer::ConfigureReason reason, syncer::ConfigureReason reason,
const DataTypeConfigStateMap& config_state_map, const DataTypeConfigStateMap& config_state_map,
const base::Callback<void(syncer::ModelTypeSet, syncer::ModelTypeSet)>& const base::Callback<void(syncer::ModelTypeSet, syncer::ModelTypeSet)>&
......
...@@ -324,11 +324,11 @@ void SyncBackendHostImpl::UnregisterInvalidationIds() { ...@@ -324,11 +324,11 @@ void SyncBackendHostImpl::UnregisterInvalidationIds() {
} }
} }
void SyncBackendHostImpl::ConfigureDataTypes( syncer::ModelTypeSet SyncBackendHostImpl::ConfigureDataTypes(
syncer::ConfigureReason reason, syncer::ConfigureReason reason,
const DataTypeConfigStateMap& config_state_map, const DataTypeConfigStateMap& config_state_map,
const base::Callback<void(syncer::ModelTypeSet, const base::Callback<void(syncer::ModelTypeSet, syncer::ModelTypeSet)>&
syncer::ModelTypeSet)>& ready_task, ready_task,
const base::Callback<void()>& retry_callback) { const base::Callback<void()>& retry_callback) {
// Only one configure is allowed at a time. This is guaranteed by our // Only one configure is allowed at a time. This is guaranteed by our
// callers. The SyncBackendHostImpl requests one configure as the backend is // callers. The SyncBackendHostImpl requests one configure as the backend is
...@@ -445,6 +445,12 @@ void SyncBackendHostImpl::ConfigureDataTypes( ...@@ -445,6 +445,12 @@ void SyncBackendHostImpl::ConfigureDataTypes(
routing_info, routing_info,
ready_task, ready_task,
retry_callback); retry_callback);
DCHECK(syncer::Intersection(active_types, types_to_purge).Empty());
DCHECK(syncer::Intersection(active_types, fatal_types).Empty());
DCHECK(syncer::Intersection(active_types, unapply_types).Empty());
DCHECK(syncer::Intersection(active_types, inactive_types).Empty());
return syncer::Difference(active_types, types_to_download);
} }
void SyncBackendHostImpl::EnableEncryptEverything() { void SyncBackendHostImpl::EnableEncryptEverything() {
......
...@@ -100,7 +100,7 @@ class SyncBackendHostImpl ...@@ -100,7 +100,7 @@ class SyncBackendHostImpl
void StopSyncingForShutdown() override; void StopSyncingForShutdown() override;
scoped_ptr<base::Thread> Shutdown(syncer::ShutdownReason reason) override; scoped_ptr<base::Thread> Shutdown(syncer::ShutdownReason reason) override;
void UnregisterInvalidationIds() override; void UnregisterInvalidationIds() override;
void ConfigureDataTypes( syncer::ModelTypeSet ConfigureDataTypes(
syncer::ConfigureReason reason, syncer::ConfigureReason reason,
const DataTypeConfigStateMap& config_state_map, const DataTypeConfigStateMap& config_state_map,
const base::Callback<void(syncer::ModelTypeSet, syncer::ModelTypeSet)>& const base::Callback<void(syncer::ModelTypeSet, syncer::ModelTypeSet)>&
......
...@@ -176,13 +176,10 @@ class SyncBackendHostTest : public testing::Test { ...@@ -176,13 +176,10 @@ class SyncBackendHostTest : public testing::Test {
// NOTE: We can't include Passwords or Typed URLs due to the Sync Backend // NOTE: We can't include Passwords or Typed URLs due to the Sync Backend
// Registrar removing them if it can't find their model workers. // Registrar removing them if it can't find their model workers.
enabled_types_.Put(syncer::BOOKMARKS); enabled_types_.Put(syncer::BOOKMARKS);
enabled_types_.Put(syncer::NIGORI);
enabled_types_.Put(syncer::DEVICE_INFO);
enabled_types_.Put(syncer::PREFERENCES); enabled_types_.Put(syncer::PREFERENCES);
enabled_types_.Put(syncer::SESSIONS); enabled_types_.Put(syncer::SESSIONS);
enabled_types_.Put(syncer::SEARCH_ENGINES); enabled_types_.Put(syncer::SEARCH_ENGINES);
enabled_types_.Put(syncer::AUTOFILL); enabled_types_.Put(syncer::AUTOFILL);
enabled_types_.Put(syncer::EXPERIMENTS);
network_resources_.reset(new syncer::HttpBridgeNetworkResources()); network_resources_.reset(new syncer::HttpBridgeNetworkResources());
} }
...@@ -231,9 +228,10 @@ class SyncBackendHostTest : public testing::Test { ...@@ -231,9 +228,10 @@ class SyncBackendHostTest : public testing::Test {
} }
// Synchronously configures the backend's datatypes. // Synchronously configures the backend's datatypes.
void ConfigureDataTypes(syncer::ModelTypeSet types_to_add, syncer::ModelTypeSet ConfigureDataTypes(
syncer::ModelTypeSet types_to_remove, syncer::ModelTypeSet types_to_add,
syncer::ModelTypeSet types_to_unapply) { syncer::ModelTypeSet types_to_remove,
syncer::ModelTypeSet types_to_unapply) {
sync_driver::BackendDataTypeConfigurer::DataTypeConfigStateMap sync_driver::BackendDataTypeConfigurer::DataTypeConfigStateMap
config_state_map; config_state_map;
sync_driver::BackendDataTypeConfigurer::SetDataTypesState( sync_driver::BackendDataTypeConfigurer::SetDataTypesState(
...@@ -248,11 +246,9 @@ class SyncBackendHostTest : public testing::Test { ...@@ -248,11 +246,9 @@ class SyncBackendHostTest : public testing::Test {
types_to_unapply, &config_state_map); types_to_unapply, &config_state_map);
types_to_add.PutAll(syncer::ControlTypes()); types_to_add.PutAll(syncer::ControlTypes());
backend_->ConfigureDataTypes( syncer::ModelTypeSet ready_types = backend_->ConfigureDataTypes(
syncer::CONFIGURE_REASON_RECONFIGURATION, syncer::CONFIGURE_REASON_RECONFIGURATION, config_state_map,
config_state_map, base::Bind(&SyncBackendHostTest::DownloadReady, base::Unretained(this)),
base::Bind(&SyncBackendHostTest::DownloadReady,
base::Unretained(this)),
base::Bind(&SyncBackendHostTest::OnDownloadRetry, base::Bind(&SyncBackendHostTest::OnDownloadRetry,
base::Unretained(this))); base::Unretained(this)));
base::RunLoop run_loop; base::RunLoop run_loop;
...@@ -260,6 +256,7 @@ class SyncBackendHostTest : public testing::Test { ...@@ -260,6 +256,7 @@ class SyncBackendHostTest : public testing::Test {
run_loop.QuitClosure(), run_loop.QuitClosure(),
TestTimeouts::action_timeout()); TestTimeouts::action_timeout());
run_loop.Run(); run_loop.Run();
return ready_types;
} }
void IssueRefreshRequest(syncer::ModelTypeSet types) { void IssueRefreshRequest(syncer::ModelTypeSet types) {
...@@ -316,10 +313,13 @@ TEST_F(SyncBackendHostTest, FirstTimeSync) { ...@@ -316,10 +313,13 @@ TEST_F(SyncBackendHostTest, FirstTimeSync) {
EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken(
syncer::ControlTypes()).Empty()); syncer::ControlTypes()).Empty());
ConfigureDataTypes(enabled_types_, syncer::ModelTypeSet ready_types = ConfigureDataTypes(
Difference(syncer::ModelTypeSet::All(), enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_),
enabled_types_), syncer::ModelTypeSet());
syncer::ModelTypeSet()); // Nigori is always downloaded so won't be ready.
EXPECT_TRUE(ready_types.Equals(syncer::Difference(
syncer::ControlTypes(),
syncer::ModelTypeSet(syncer::NIGORI))));
EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().HasAll( EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().HasAll(
Difference(enabled_types_, syncer::ControlTypes()))); Difference(enabled_types_, syncer::ControlTypes())));
EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals(enabled_types_)); EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals(enabled_types_));
...@@ -343,10 +343,10 @@ TEST_F(SyncBackendHostTest, Restart) { ...@@ -343,10 +343,10 @@ TEST_F(SyncBackendHostTest, Restart) {
EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken(
enabled_types_).Empty()); enabled_types_).Empty());
ConfigureDataTypes(enabled_types_, syncer::ModelTypeSet ready_types = ConfigureDataTypes(
Difference(syncer::ModelTypeSet::All(), enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_),
enabled_types_), syncer::ModelTypeSet());
syncer::ModelTypeSet()); EXPECT_TRUE(ready_types.Equals(enabled_types_));
EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Empty()); EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Empty());
EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(), EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(),
enabled_types_).Empty()); enabled_types_).Empty());
...@@ -381,10 +381,10 @@ TEST_F(SyncBackendHostTest, PartialTypes) { ...@@ -381,10 +381,10 @@ TEST_F(SyncBackendHostTest, PartialTypes) {
Difference(partial_types, syncer::ModelTypeSet(syncer::NIGORI)))); Difference(partial_types, syncer::ModelTypeSet(syncer::NIGORI))));
// Now do the actual configuration, which should download and apply bookmarks. // Now do the actual configuration, which should download and apply bookmarks.
ConfigureDataTypes(enabled_types_, syncer::ModelTypeSet ready_types = ConfigureDataTypes(
Difference(syncer::ModelTypeSet::All(), enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_),
enabled_types_), syncer::ModelTypeSet());
syncer::ModelTypeSet()); EXPECT_TRUE(ready_types.Equals(full_types));
EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(), EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(),
enabled_types_).Empty()); enabled_types_).Empty());
EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Equals( EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Equals(
...@@ -415,10 +415,13 @@ TEST_F(SyncBackendHostTest, LostDB) { ...@@ -415,10 +415,13 @@ TEST_F(SyncBackendHostTest, LostDB) {
fake_manager_->GetAndResetCleanedTypes(); fake_manager_->GetAndResetCleanedTypes();
// The actual configuration should redownload and apply all the enabled types. // The actual configuration should redownload and apply all the enabled types.
ConfigureDataTypes(enabled_types_, syncer::ModelTypeSet ready_types = ConfigureDataTypes(
Difference(syncer::ModelTypeSet::All(), enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_),
enabled_types_), syncer::ModelTypeSet());
syncer::ModelTypeSet()); // Nigori is always downloaded so won't be ready.
EXPECT_TRUE(ready_types.Equals(syncer::Difference(
syncer::ControlTypes(),
syncer::ModelTypeSet(syncer::NIGORI))));
EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().HasAll( EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().HasAll(
Difference(enabled_types_, syncer::ControlTypes()))); Difference(enabled_types_, syncer::ControlTypes())));
EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(), EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(),
...@@ -433,10 +436,13 @@ TEST_F(SyncBackendHostTest, DisableTypes) { ...@@ -433,10 +436,13 @@ TEST_F(SyncBackendHostTest, DisableTypes) {
// Simulate first time sync. // Simulate first time sync.
InitializeBackend(true); InitializeBackend(true);
fake_manager_->GetAndResetCleanedTypes(); fake_manager_->GetAndResetCleanedTypes();
ConfigureDataTypes(enabled_types_, syncer::ModelTypeSet ready_types = ConfigureDataTypes(
Difference(syncer::ModelTypeSet::All(), enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_),
enabled_types_), syncer::ModelTypeSet());
syncer::ModelTypeSet()); // Nigori is always downloaded so won't be ready.
EXPECT_TRUE(ready_types.Equals(syncer::Difference(
syncer::ControlTypes(),
syncer::ModelTypeSet(syncer::NIGORI))));
EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Equals( EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Equals(
enabled_types_)); enabled_types_));
EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(), EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(),
...@@ -450,13 +456,13 @@ TEST_F(SyncBackendHostTest, DisableTypes) { ...@@ -450,13 +456,13 @@ TEST_F(SyncBackendHostTest, DisableTypes) {
syncer::SEARCH_ENGINES); syncer::SEARCH_ENGINES);
syncer::ModelTypeSet old_types = enabled_types_; syncer::ModelTypeSet old_types = enabled_types_;
enabled_types_.RemoveAll(disabled_types); enabled_types_.RemoveAll(disabled_types);
ConfigureDataTypes(enabled_types_, ready_types = ConfigureDataTypes(
Difference(syncer::ModelTypeSet::All(), enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_),
enabled_types_), syncer::ModelTypeSet());
syncer::ModelTypeSet());
// Only those datatypes disabled should be cleaned. Nothing should be // Only those datatypes disabled should be cleaned. Nothing should be
// downloaded. // downloaded.
EXPECT_TRUE(ready_types.Equals(enabled_types_));
EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Empty()); EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Empty());
EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(), EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(),
old_types).Equals(disabled_types)); old_types).Equals(disabled_types));
...@@ -470,10 +476,13 @@ TEST_F(SyncBackendHostTest, AddTypes) { ...@@ -470,10 +476,13 @@ TEST_F(SyncBackendHostTest, AddTypes) {
// Simulate first time sync. // Simulate first time sync.
InitializeBackend(true); InitializeBackend(true);
fake_manager_->GetAndResetCleanedTypes(); fake_manager_->GetAndResetCleanedTypes();
ConfigureDataTypes(enabled_types_, syncer::ModelTypeSet ready_types = ConfigureDataTypes(
Difference(syncer::ModelTypeSet::All(), enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_),
enabled_types_), syncer::ModelTypeSet());
syncer::ModelTypeSet()); // Nigori is always downloaded so won't be ready.
EXPECT_TRUE(ready_types.Equals(syncer::Difference(
syncer::ControlTypes(),
syncer::ModelTypeSet(syncer::NIGORI))));
EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Equals( EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Equals(
enabled_types_)); enabled_types_));
EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(), EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(),
...@@ -486,15 +495,16 @@ TEST_F(SyncBackendHostTest, AddTypes) { ...@@ -486,15 +495,16 @@ TEST_F(SyncBackendHostTest, AddTypes) {
syncer::ModelTypeSet new_types(syncer::EXTENSIONS, syncer::ModelTypeSet new_types(syncer::EXTENSIONS,
syncer::APPS); syncer::APPS);
enabled_types_.PutAll(new_types); enabled_types_.PutAll(new_types);
ConfigureDataTypes(enabled_types_, ready_types = ConfigureDataTypes(
Difference(syncer::ModelTypeSet::All(), enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_),
enabled_types_), syncer::ModelTypeSet());
syncer::ModelTypeSet());
// Only those datatypes added should be downloaded (plus nigori). Nothing // Only those datatypes added should be downloaded (plus nigori). Nothing
// should be cleaned aside from the disabled types. // should be cleaned aside from the disabled types.
EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Equals( new_types.Put(syncer::NIGORI);
Union(new_types, syncer::ModelTypeSet(syncer::NIGORI)))); EXPECT_TRUE(
ready_types.Equals(syncer::Difference(enabled_types_, new_types)));
EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Equals(new_types));
EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(), EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(),
enabled_types_).Empty()); enabled_types_).Empty());
EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals(enabled_types_)); EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals(enabled_types_));
...@@ -508,10 +518,13 @@ TEST_F(SyncBackendHostTest, AddDisableTypes) { ...@@ -508,10 +518,13 @@ TEST_F(SyncBackendHostTest, AddDisableTypes) {
// Simulate first time sync. // Simulate first time sync.
InitializeBackend(true); InitializeBackend(true);
fake_manager_->GetAndResetCleanedTypes(); fake_manager_->GetAndResetCleanedTypes();
ConfigureDataTypes(enabled_types_, syncer::ModelTypeSet ready_types = ConfigureDataTypes(
Difference(syncer::ModelTypeSet::All(), enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_),
enabled_types_), syncer::ModelTypeSet());
syncer::ModelTypeSet()); // Nigori is always downloaded so won't be ready.
EXPECT_TRUE(ready_types.Equals(syncer::Difference(
syncer::ControlTypes(),
syncer::ModelTypeSet(syncer::NIGORI))));
EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Equals( EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Equals(
enabled_types_)); enabled_types_));
EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(), EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(),
...@@ -528,15 +541,16 @@ TEST_F(SyncBackendHostTest, AddDisableTypes) { ...@@ -528,15 +541,16 @@ TEST_F(SyncBackendHostTest, AddDisableTypes) {
syncer::APPS); syncer::APPS);
enabled_types_.PutAll(new_types); enabled_types_.PutAll(new_types);
enabled_types_.RemoveAll(disabled_types); enabled_types_.RemoveAll(disabled_types);
ConfigureDataTypes(enabled_types_, ready_types = ConfigureDataTypes(
Difference(syncer::ModelTypeSet::All(), enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_),
enabled_types_), syncer::ModelTypeSet());
syncer::ModelTypeSet());
// Only those datatypes added should be downloaded (plus nigori). Nothing // Only those datatypes added should be downloaded (plus nigori). Nothing
// should be cleaned aside from the disabled types. // should be cleaned aside from the disabled types.
EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Equals( new_types.Put(syncer::NIGORI);
Union(new_types, syncer::ModelTypeSet(syncer::NIGORI)))); EXPECT_TRUE(
ready_types.Equals(syncer::Difference(enabled_types_, new_types)));
EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Equals(new_types));
EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(), EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(),
old_types).Equals(disabled_types)); old_types).Equals(disabled_types));
EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals(enabled_types_)); EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals(enabled_types_));
...@@ -567,13 +581,15 @@ TEST_F(SyncBackendHostTest, NewlySupportedTypes) { ...@@ -567,13 +581,15 @@ TEST_F(SyncBackendHostTest, NewlySupportedTypes) {
EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken(
enabled_types_).Equals(new_types)); enabled_types_).Equals(new_types));
// Downloads and applies the new types. // Downloads and applies the new types (plus nigori).
ConfigureDataTypes(enabled_types_, syncer::ModelTypeSet ready_types = ConfigureDataTypes(
Difference(syncer::ModelTypeSet::All(), enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_),
enabled_types_), syncer::ModelTypeSet());
syncer::ModelTypeSet());
EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Equals( new_types.Put(syncer::NIGORI);
Union(new_types, syncer::ModelTypeSet(syncer::NIGORI)))); EXPECT_TRUE(ready_types.Equals(
syncer::Difference(old_types, syncer::ModelTypeSet(syncer::NIGORI))));
EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Equals(new_types));
EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(), EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(),
enabled_types_).Empty()); enabled_types_).Empty());
EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals(enabled_types_)); EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals(enabled_types_));
...@@ -613,10 +629,10 @@ TEST_F(SyncBackendHostTest, NewlySupportedTypesWithPartialTypes) { ...@@ -613,10 +629,10 @@ TEST_F(SyncBackendHostTest, NewlySupportedTypesWithPartialTypes) {
// Downloads and applies the new types and partial types (which includes // Downloads and applies the new types and partial types (which includes
// nigori anyways). // nigori anyways).
ConfigureDataTypes(enabled_types_, syncer::ModelTypeSet ready_types = ConfigureDataTypes(
Difference(syncer::ModelTypeSet::All(), enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_),
enabled_types_), syncer::ModelTypeSet());
syncer::ModelTypeSet()); EXPECT_TRUE(ready_types.Equals(full_types));
EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Equals( EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Equals(
Union(new_types, partial_types))); Union(new_types, partial_types)));
EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(), EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(),
...@@ -747,25 +763,31 @@ TEST_F(SyncBackendHostTest, DisableThenPurgeType) { ...@@ -747,25 +763,31 @@ TEST_F(SyncBackendHostTest, DisableThenPurgeType) {
InitializeBackend(true); InitializeBackend(true);
// First enable the types. // First enable the types.
ConfigureDataTypes(enabled_types_, syncer::ModelTypeSet ready_types = ConfigureDataTypes(
Difference(syncer::ModelTypeSet::All(), enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_),
enabled_types_), syncer::ModelTypeSet());
syncer::ModelTypeSet());
// Nigori is always downloaded so won't be ready.
EXPECT_TRUE(ready_types.Equals(syncer::Difference(
syncer::ControlTypes(),
syncer::ModelTypeSet(syncer::NIGORI))));
// Then mark the error types as unready (disables without purging). // Then mark the error types as unready (disables without purging).
ConfigureDataTypes(enabled_types_, ready_types = ConfigureDataTypes(
Difference(syncer::ModelTypeSet::All(), enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_),
enabled_types_), error_types);
error_types); EXPECT_TRUE(
ready_types.Equals(syncer::Difference(enabled_types_, error_types)));
EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken(
error_types).Empty()); error_types).Empty());
// Lastly explicitly disable the error types, which should result in a purge. // Lastly explicitly disable the error types, which should result in a purge.
enabled_types_.RemoveAll(error_types); enabled_types_.RemoveAll(error_types);
ConfigureDataTypes(enabled_types_, ready_types = ConfigureDataTypes(
Difference(syncer::ModelTypeSet::All(), enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_),
enabled_types_), syncer::ModelTypeSet());
syncer::ModelTypeSet()); EXPECT_TRUE(
ready_types.Equals(syncer::Difference(enabled_types_, error_types)));
EXPECT_FALSE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( EXPECT_FALSE(fake_manager_->GetTypesWithEmptyProgressMarkerToken(
error_types).Empty()); error_types).Empty());
} }
......
...@@ -55,12 +55,14 @@ scoped_ptr<base::Thread> SyncBackendHostMock::Shutdown( ...@@ -55,12 +55,14 @@ scoped_ptr<base::Thread> SyncBackendHostMock::Shutdown(
void SyncBackendHostMock::UnregisterInvalidationIds() {} void SyncBackendHostMock::UnregisterInvalidationIds() {}
void SyncBackendHostMock::ConfigureDataTypes( syncer::ModelTypeSet SyncBackendHostMock::ConfigureDataTypes(
syncer::ConfigureReason reason, syncer::ConfigureReason reason,
const DataTypeConfigStateMap& config_state_map, const DataTypeConfigStateMap& config_state_map,
const base::Callback<void(syncer::ModelTypeSet, const base::Callback<void(syncer::ModelTypeSet, syncer::ModelTypeSet)>&
syncer::ModelTypeSet)>& ready_task, ready_task,
const base::Callback<void()>& retry_callback) {} const base::Callback<void()>& retry_callback) {
return syncer::ModelTypeSet();
}
void SyncBackendHostMock::EnableEncryptEverything() {} void SyncBackendHostMock::EnableEncryptEverything() {}
......
...@@ -53,7 +53,7 @@ class SyncBackendHostMock : public SyncBackendHost { ...@@ -53,7 +53,7 @@ class SyncBackendHostMock : public SyncBackendHost {
void UnregisterInvalidationIds() override; void UnregisterInvalidationIds() override;
void ConfigureDataTypes( syncer::ModelTypeSet ConfigureDataTypes(
syncer::ConfigureReason reason, syncer::ConfigureReason reason,
const DataTypeConfigStateMap& config_state_map, const DataTypeConfigStateMap& config_state_map,
const base::Callback<void(syncer::ModelTypeSet, syncer::ModelTypeSet)>& const base::Callback<void(syncer::ModelTypeSet, syncer::ModelTypeSet)>&
......
...@@ -42,17 +42,19 @@ class BackendDataTypeConfigurer { ...@@ -42,17 +42,19 @@ class BackendDataTypeConfigurer {
// is called when configuration is done with the set of data types // is called when configuration is done with the set of data types
// that succeeded/failed configuration (i.e., configuration succeeded iff // that succeeded/failed configuration (i.e., configuration succeeded iff
// the failed set is empty). // the failed set is empty).
// Returns: the set of types that are already configured and are ready to
// start.
// //
// TODO(akalin): Use a Delegate class with // TODO(akalin): Use a Delegate class with
// OnConfigureSuccess/OnConfigureFailure/OnConfigureRetry instead of // OnConfigureSuccess/OnConfigureFailure/OnConfigureRetry instead of
// a pair of callbacks. The awkward part is handling when // a pair of callbacks. The awkward part is handling when
// SyncBackendHost calls ConfigureDataTypes on itself to configure // SyncBackendHost calls ConfigureDataTypes on itself to configure
// Nigori. // Nigori.
virtual void ConfigureDataTypes( virtual syncer::ModelTypeSet ConfigureDataTypes(
syncer::ConfigureReason reason, syncer::ConfigureReason reason,
const DataTypeConfigStateMap& config_state_map, const DataTypeConfigStateMap& config_state_map,
const base::Callback<void(syncer::ModelTypeSet, const base::Callback<void(syncer::ModelTypeSet, syncer::ModelTypeSet)>&
syncer::ModelTypeSet)>& ready_task, ready_task,
const base::Callback<void()>& retry_callback) = 0; const base::Callback<void()>& retry_callback) = 0;
// Return model types in |state_map| that match |state|. // Return model types in |state_map| that match |state|.
......
...@@ -82,7 +82,7 @@ class FakeBackendDataTypeConfigurer : public BackendDataTypeConfigurer { ...@@ -82,7 +82,7 @@ class FakeBackendDataTypeConfigurer : public BackendDataTypeConfigurer {
FakeBackendDataTypeConfigurer() {} FakeBackendDataTypeConfigurer() {}
~FakeBackendDataTypeConfigurer() override {} ~FakeBackendDataTypeConfigurer() override {}
void ConfigureDataTypes( syncer::ModelTypeSet ConfigureDataTypes(
syncer::ConfigureReason reason, syncer::ConfigureReason reason,
const DataTypeConfigStateMap& config_state_map, const DataTypeConfigStateMap& config_state_map,
const base::Callback<void(ModelTypeSet, ModelTypeSet)>& ready_task, const base::Callback<void(ModelTypeSet, ModelTypeSet)>& ready_task,
...@@ -98,6 +98,7 @@ class FakeBackendDataTypeConfigurer : public BackendDataTypeConfigurer { ...@@ -98,6 +98,7 @@ class FakeBackendDataTypeConfigurer : public BackendDataTypeConfigurer {
<< ModelTypeSetToString( << ModelTypeSetToString(
GetDataTypesInState(CONFIGURE_ACTIVE, config_state_map)); GetDataTypesInState(CONFIGURE_ACTIVE, config_state_map));
} }
return syncer::ModelTypeSet();
} }
void ActivateDataType(syncer::ModelType type, void ActivateDataType(syncer::ModelType type,
......
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