diff options
Diffstat (limited to 'chrome/browser/sync')
-rw-r--r-- | chrome/browser/sync/backend_migrator.cc | 18 | ||||
-rw-r--r-- | chrome/browser/sync/backend_migrator_unittest.cc | 48 | ||||
-rw-r--r-- | chrome/browser/sync/glue/data_type_manager.h | 4 | ||||
-rw-r--r-- | chrome/browser/sync/glue/data_type_manager_impl.cc | 14 | ||||
-rw-r--r-- | chrome/browser/sync/glue/data_type_manager_impl.h | 4 | ||||
-rw-r--r-- | chrome/browser/sync/glue/data_type_manager_impl_unittest.cc | 154 | ||||
-rw-r--r-- | chrome/browser/sync/glue/data_type_manager_mock.h | 3 | ||||
-rw-r--r-- | chrome/browser/sync/glue/sync_backend_host.cc | 2 | ||||
-rw-r--r-- | chrome/browser/sync/glue/sync_backend_host_unittest.cc | 24 | ||||
-rw-r--r-- | chrome/browser/sync/sync_prefs.cc | 14 |
10 files changed, 182 insertions, 103 deletions
diff --git a/chrome/browser/sync/backend_migrator.cc b/chrome/browser/sync/backend_migrator.cc index 72e711c..e6c5002 100644 --- a/chrome/browser/sync/backend_migrator.cc +++ b/chrome/browser/sync/backend_migrator.cc @@ -101,22 +101,10 @@ bool BackendMigrator::TryStart() { void BackendMigrator::RestartMigration() { // We'll now disable any running types that need to be migrated. ChangeState(DISABLING_TYPES); - const ModelTypeSet full_set = service_->GetPreferredDataTypes(); - const ModelTypeSet difference = Difference(full_set, to_migrate_); - bool configure_with_nigori = !to_migrate_.Has(syncer::NIGORI); SDVLOG(1) << "BackendMigrator disabling types " - << ModelTypeSetToString(to_migrate_) << "; configuring " - << ModelTypeSetToString(difference) - << (configure_with_nigori ? " with nigori" : " without nigori"); - - // Add nigori for config or not based upon if the server told us to migrate - // nigori or not. - if (configure_with_nigori) { - manager_->Configure(difference, syncer::CONFIGURE_REASON_MIGRATION); - } else { - manager_->ConfigureWithoutNigori(difference, - syncer::CONFIGURE_REASON_MIGRATION); - } + << ModelTypeSetToString(to_migrate_); + + manager_->PurgeForMigration(to_migrate_, syncer::CONFIGURE_REASON_MIGRATION); } void BackendMigrator::OnConfigureDone( diff --git a/chrome/browser/sync/backend_migrator_unittest.cc b/chrome/browser/sync/backend_migrator_unittest.cc index 7331072..bc28fcb 100644 --- a/chrome/browser/sync/backend_migrator_unittest.cc +++ b/chrome/browser/sync/backend_migrator_unittest.cc @@ -130,8 +130,12 @@ TEST_F(SyncBackendMigratorTest, Sanity) { EXPECT_CALL(*manager(), state()) .WillOnce(Return(DataTypeManager::CONFIGURED)); - EXPECT_CALL(*manager(), Configure(_, syncer::CONFIGURE_REASON_MIGRATION)) - .Times(2); + EXPECT_CALL( + *manager(), + PurgeForMigration(_, syncer::CONFIGURE_REASON_MIGRATION)).Times(1); + EXPECT_CALL( + *manager(), + Configure(_, syncer::CONFIGURE_REASON_MIGRATION)).Times(1); migrator()->MigrateTypes(to_migrate); EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state()); @@ -158,7 +162,7 @@ TEST_F(SyncBackendMigratorTest, MigrateNigori) { EXPECT_CALL(*manager(), state()) .WillOnce(Return(DataTypeManager::CONFIGURED)); - EXPECT_CALL(*manager(), ConfigureWithoutNigori(_, + EXPECT_CALL(*manager(), PurgeForMigration(_, syncer::CONFIGURE_REASON_MIGRATION)); migrator()->MigrateTypes(to_migrate); @@ -189,7 +193,8 @@ TEST_F(SyncBackendMigratorTest, WaitToStart) { Mock::VerifyAndClearExpectations(manager()); EXPECT_CALL(*manager(), state()) .WillOnce(Return(DataTypeManager::CONFIGURED)); - EXPECT_CALL(*manager(), Configure(_, syncer::CONFIGURE_REASON_MIGRATION)); + EXPECT_CALL(*manager(), + PurgeForMigration(_, syncer::CONFIGURE_REASON_MIGRATION)); SetUnsyncedTypes(syncer::ModelTypeSet()); SendConfigureDone(DataTypeManager::OK, syncer::ModelTypeSet()); @@ -208,8 +213,9 @@ TEST_F(SyncBackendMigratorTest, RestartMigration) { EXPECT_CALL(*manager(), state()) .WillOnce(Return(DataTypeManager::CONFIGURED)); - EXPECT_CALL(*manager(), Configure(_, syncer::CONFIGURE_REASON_MIGRATION)) - .Times(2); + EXPECT_CALL( + *manager(), + PurgeForMigration(_, syncer::CONFIGURE_REASON_MIGRATION)).Times(2); migrator()->MigrateTypes(to_migrate1); EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state()); @@ -219,8 +225,11 @@ TEST_F(SyncBackendMigratorTest, RestartMigration) { Difference(preferred_types(), to_migrate1); Mock::VerifyAndClearExpectations(manager()); + EXPECT_CALL( + *manager(), + PurgeForMigration(_, syncer::CONFIGURE_REASON_MIGRATION)).Times(1); EXPECT_CALL(*manager(), Configure(_, syncer::CONFIGURE_REASON_MIGRATION)) - .Times(2); + .Times(1); SetUnsyncedTypes(to_migrate1); SendConfigureDone(DataTypeManager::OK, difference1); EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state()); @@ -241,13 +250,13 @@ TEST_F(SyncBackendMigratorTest, InterruptedWhileDisablingTypes) { EXPECT_CALL(*manager(), state()) .WillOnce(Return(DataTypeManager::CONFIGURED)); - EXPECT_CALL(*manager(), Configure(HasModelTypes(difference), + EXPECT_CALL(*manager(), PurgeForMigration(HasModelTypes(to_migrate), syncer::CONFIGURE_REASON_MIGRATION)); migrator()->MigrateTypes(to_migrate); EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state()); Mock::VerifyAndClearExpectations(manager()); - EXPECT_CALL(*manager(), Configure(HasModelTypes(difference), + EXPECT_CALL(*manager(), PurgeForMigration(HasModelTypes(to_migrate), syncer::CONFIGURE_REASON_MIGRATION)); SetUnsyncedTypes(syncer::ModelTypeSet()); SendConfigureDone(DataTypeManager::OK, preferred_types()); @@ -266,8 +275,12 @@ TEST_F(SyncBackendMigratorTest, WaitingForPurge) { EXPECT_CALL(*manager(), state()) .WillOnce(Return(DataTypeManager::CONFIGURED)); - EXPECT_CALL(*manager(), Configure(_, syncer::CONFIGURE_REASON_MIGRATION)) - .Times(2); + EXPECT_CALL( + *manager(), + PurgeForMigration(_, syncer::CONFIGURE_REASON_MIGRATION)).Times(1); + EXPECT_CALL( + *manager(), + Configure(_, syncer::CONFIGURE_REASON_MIGRATION)).Times(1); migrator()->MigrateTypes(to_migrate); EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state()); @@ -292,8 +305,12 @@ TEST_F(SyncBackendMigratorTest, MigratedTypeDisabledByUserDuringMigration) { EXPECT_CALL(*manager(), state()) .WillOnce(Return(DataTypeManager::CONFIGURED)); - EXPECT_CALL(*manager(), Configure(_, syncer::CONFIGURE_REASON_MIGRATION)) - .Times(2); + EXPECT_CALL( + *manager(), + PurgeForMigration(_, syncer::CONFIGURE_REASON_MIGRATION)).Times(1); + EXPECT_CALL( + *manager(), + Configure(_, syncer::CONFIGURE_REASON_MIGRATION)).Times(1); migrator()->MigrateTypes(to_migrate); RemovePreferredType(syncer::PREFERENCES); @@ -311,8 +328,9 @@ TEST_F(SyncBackendMigratorTest, ConfigureFailure) { EXPECT_CALL(*manager(), state()) .WillOnce(Return(DataTypeManager::CONFIGURED)); - EXPECT_CALL(*manager(), Configure(_, syncer::CONFIGURE_REASON_MIGRATION)) - .Times(1); + EXPECT_CALL( + *manager(), + PurgeForMigration(_, syncer::CONFIGURE_REASON_MIGRATION)).Times(1); migrator()->MigrateTypes(to_migrate); SetUnsyncedTypes(syncer::ModelTypeSet()); SendConfigureDone(DataTypeManager::ABORTED, syncer::ModelTypeSet()); diff --git a/chrome/browser/sync/glue/data_type_manager.h b/chrome/browser/sync/glue/data_type_manager.h index 0351088..18db082 100644 --- a/chrome/browser/sync/glue/data_type_manager.h +++ b/chrome/browser/sync/glue/data_type_manager.h @@ -93,8 +93,8 @@ class DataTypeManager { virtual void Configure(TypeSet desired_types, syncer::ConfigureReason reason) = 0; - virtual void ConfigureWithoutNigori(TypeSet desired_types, - syncer::ConfigureReason reason) = 0; + virtual void PurgeForMigration(TypeSet undesired_types, + syncer::ConfigureReason reason) = 0; // Synchronously stops all registered data types. If called after // Configure() is called but before it finishes, it will abort the diff --git a/chrome/browser/sync/glue/data_type_manager_impl.cc b/chrome/browser/sync/glue/data_type_manager_impl.cc index d9e0bb4..6c81668 100644 --- a/chrome/browser/sync/glue/data_type_manager_impl.cc +++ b/chrome/browser/sync/glue/data_type_manager_impl.cc @@ -46,15 +46,15 @@ DataTypeManagerImpl::~DataTypeManagerImpl() {} void DataTypeManagerImpl::Configure(TypeSet desired_types, syncer::ConfigureReason reason) { - desired_types.Put(syncer::NIGORI); + desired_types.PutAll(syncer::ControlTypes()); ConfigureImpl(desired_types, reason); } -void DataTypeManagerImpl::ConfigureWithoutNigori( - TypeSet desired_types, +void DataTypeManagerImpl::PurgeForMigration( + TypeSet undesired_types, syncer::ConfigureReason reason) { - DCHECK(!desired_types.Has(syncer::NIGORI)); - ConfigureImpl(desired_types, reason); + TypeSet remainder = Difference(last_requested_types_, undesired_types); + ConfigureImpl(remainder, reason); } void DataTypeManagerImpl::ConfigureImpl( @@ -114,8 +114,8 @@ void DataTypeManagerImpl::Restart(syncer::ConfigureReason reason) { controllers_->begin(); it != controllers_->end(); ++it) { all_types.Put(it->first); } - // NIGORI has no controller. We must add it manually. - all_types.Put(syncer::NIGORI); + // These have no controller. We must add them manually. + all_types.PutAll(syncer::ControlTypes()); const syncer::ModelTypeSet types_to_add = last_requested_types_; // Check that types_to_add \subseteq all_types. DCHECK(all_types.HasAll(types_to_add)); diff --git a/chrome/browser/sync/glue/data_type_manager_impl.h b/chrome/browser/sync/glue/data_type_manager_impl.h index da417c0..9f38a45 100644 --- a/chrome/browser/sync/glue/data_type_manager_impl.h +++ b/chrome/browser/sync/glue/data_type_manager_impl.h @@ -36,8 +36,8 @@ class DataTypeManagerImpl : public DataTypeManager, syncer::ConfigureReason reason) OVERRIDE; // Needed only for backend migration. - virtual void ConfigureWithoutNigori( - TypeSet desired_types, + virtual void PurgeForMigration( + TypeSet undesired_types, syncer::ConfigureReason reason) OVERRIDE; virtual void Stop() OVERRIDE; diff --git a/chrome/browser/sync/glue/data_type_manager_impl_unittest.cc b/chrome/browser/sync/glue/data_type_manager_impl_unittest.cc index f15f7dd..c0a5142 100644 --- a/chrome/browser/sync/glue/data_type_manager_impl_unittest.cc +++ b/chrome/browser/sync/glue/data_type_manager_impl_unittest.cc @@ -26,15 +26,11 @@ using syncer::BOOKMARKS; using syncer::APPS; using syncer::PASSWORDS; using syncer::PREFERENCES; +using syncer::NIGORI; using testing::_; using testing::Mock; using testing::ResultOf; -enum NigoriState { - WITH_NIGORI, - WITHOUT_NIGORI -}; - // Fake BackendDataTypeConfigurer implementation that simply stores away the // callback passed into ConfigureDataTypes. class FakeBackendDataTypeConfigurer : public BackendDataTypeConfigurer { @@ -80,8 +76,7 @@ DataTypeManager::ConfigureStatus GetStatus( // The actual test harness class, parametrized on nigori state (i.e., tests are // run both configuring with nigori, and configuring without). -class SyncDataTypeManagerImplTest - : public testing::TestWithParam<NigoriState> { +class SyncDataTypeManagerImplTest : public testing::Test { public: SyncDataTypeManagerImplTest() : ui_thread_(content::BrowserThread::UI, &ui_loop_) {} @@ -93,11 +88,6 @@ class SyncDataTypeManagerImplTest virtual void SetUp() { } - // A clearer name for the param accessor. - NigoriState GetNigoriState() { - return GetParam(); - } - void SetConfigureStartExpectation() { EXPECT_CALL(observer_, OnConfigureStart()); } @@ -113,13 +103,7 @@ class SyncDataTypeManagerImplTest // Configure the given DTM with the given desired types. void Configure(DataTypeManagerImpl* dtm, const DataTypeManager::TypeSet& desired_types) { - const syncer::ConfigureReason kReason = - syncer::CONFIGURE_REASON_RECONFIGURATION; - if (GetNigoriState() == WITH_NIGORI) { - dtm->Configure(desired_types, kReason); - } else { - dtm->ConfigureWithoutNigori(desired_types, kReason); - } + dtm->Configure(desired_types, syncer::CONFIGURE_REASON_RECONFIGURATION); } // Finish downloading for the given DTM. Should be done only after @@ -159,7 +143,7 @@ class SyncDataTypeManagerImplTest // Set up a DTM with no controllers, configure it, finish downloading, // and then stop it. -TEST_P(SyncDataTypeManagerImplTest, NoControllers) { +TEST_F(SyncDataTypeManagerImplTest, NoControllers) { DataTypeManagerImpl dtm(&configurer_, &controllers_, &observer_); SetConfigureStartExpectation(); SetConfigureDoneExpectation(DataTypeManager::OK); @@ -176,7 +160,7 @@ TEST_P(SyncDataTypeManagerImplTest, NoControllers) { // Set up a DTM with a single controller, configure it, finish // downloading, finish starting the controller, and then stop the DTM. -TEST_P(SyncDataTypeManagerImplTest, ConfigureOne) { +TEST_F(SyncDataTypeManagerImplTest, ConfigureOne) { AddController(BOOKMARKS); DataTypeManagerImpl dtm(&configurer_, &controllers_, &observer_); @@ -198,7 +182,7 @@ TEST_P(SyncDataTypeManagerImplTest, ConfigureOne) { // Set up a DTM with 2 controllers. configure it. One of them finishes loading // after the timeout. Make sure eventually all are configured. -TEST_P(SyncDataTypeManagerImplTest, ConfigureSlowLoadingType) { +TEST_F(SyncDataTypeManagerImplTest, ConfigureSlowLoadingType) { AddController(BOOKMARKS); AddController(APPS); @@ -245,7 +229,7 @@ TEST_P(SyncDataTypeManagerImplTest, ConfigureSlowLoadingType) { // Set up a DTM with a single controller, configure it, but stop it // before finishing the download. It should still be safe to run the // download callback even after the DTM is stopped and destroyed. -TEST_P(SyncDataTypeManagerImplTest, ConfigureOneStopWhileDownloadPending) { +TEST_F(SyncDataTypeManagerImplTest, ConfigureOneStopWhileDownloadPending) { AddController(BOOKMARKS); { @@ -267,7 +251,7 @@ TEST_P(SyncDataTypeManagerImplTest, ConfigureOneStopWhileDownloadPending) { // downloading, but stop the DTM before the controller finishes // starting up. It should still be safe to finish starting up the // controller even after the DTM is stopped and destroyed. -TEST_P(SyncDataTypeManagerImplTest, ConfigureOneStopWhileStartingModel) { +TEST_F(SyncDataTypeManagerImplTest, ConfigureOneStopWhileStartingModel) { AddController(BOOKMARKS); { @@ -293,7 +277,7 @@ TEST_P(SyncDataTypeManagerImplTest, ConfigureOneStopWhileStartingModel) { // the controller finishes starting up. It should still be safe to // finish starting up the controller even after the DTM is stopped and // destroyed. -TEST_P(SyncDataTypeManagerImplTest, ConfigureOneStopWhileAssociating) { +TEST_F(SyncDataTypeManagerImplTest, ConfigureOneStopWhileAssociating) { AddController(BOOKMARKS); { DataTypeManagerImpl dtm(&configurer_, &controllers_, &observer_); @@ -322,7 +306,7 @@ TEST_P(SyncDataTypeManagerImplTest, ConfigureOneStopWhileAssociating) { // 5) Finish the download for step 4. // 6) Finish starting the controller successfully. // 7) Stop the DTM. -TEST_P(SyncDataTypeManagerImplTest, OneWaitingForCrypto) { +TEST_F(SyncDataTypeManagerImplTest, OneWaitingForCrypto) { AddController(PASSWORDS); DataTypeManagerImpl dtm(&configurer_, &controllers_, &observer_); @@ -372,7 +356,7 @@ TEST_P(SyncDataTypeManagerImplTest, OneWaitingForCrypto) { // 5) Finish the download for step 4. // 6) Finish starting the second controller. // 7) Stop the DTM. -TEST_P(SyncDataTypeManagerImplTest, ConfigureOneThenBoth) { +TEST_F(SyncDataTypeManagerImplTest, ConfigureOneThenBoth) { AddController(BOOKMARKS); AddController(PREFERENCES); @@ -422,7 +406,7 @@ TEST_P(SyncDataTypeManagerImplTest, ConfigureOneThenBoth) { // 5) Finish the download for step 4. // 6) Finish starting the second controller. // 7) Stop the DTM. -TEST_P(SyncDataTypeManagerImplTest, ConfigureOneThenSwitch) { +TEST_F(SyncDataTypeManagerImplTest, ConfigureOneThenSwitch) { AddController(BOOKMARKS); AddController(PREFERENCES); @@ -472,7 +456,7 @@ TEST_P(SyncDataTypeManagerImplTest, ConfigureOneThenSwitch) { // 5) Finish the download for step 3. // 6) Finish starting the second controller. // 7) Stop the DTM. -TEST_P(SyncDataTypeManagerImplTest, ConfigureWhileOneInFlight) { +TEST_F(SyncDataTypeManagerImplTest, ConfigureWhileOneInFlight) { AddController(BOOKMARKS); AddController(PREFERENCES); @@ -518,7 +502,7 @@ TEST_P(SyncDataTypeManagerImplTest, ConfigureWhileOneInFlight) { // Set up a DTM with one controller. Then configure, finish // downloading, and start the controller with an unrecoverable error. // The unrecoverable error should cause the DTM to stop. -TEST_P(SyncDataTypeManagerImplTest, OneFailingController) { +TEST_F(SyncDataTypeManagerImplTest, OneFailingController) { AddController(BOOKMARKS); DataTypeManagerImpl dtm(&configurer_, &controllers_, &observer_); @@ -544,7 +528,7 @@ TEST_P(SyncDataTypeManagerImplTest, OneFailingController) { // 4) Finish starting the second controller with an unrecoverable error. // // The failure from step 4 should cause the DTM to stop. -TEST_P(SyncDataTypeManagerImplTest, SecondControllerFails) { +TEST_F(SyncDataTypeManagerImplTest, SecondControllerFails) { AddController(BOOKMARKS); AddController(PREFERENCES); @@ -582,7 +566,7 @@ TEST_P(SyncDataTypeManagerImplTest, SecondControllerFails) { // // TODO(akalin): Check that the data type that failed association is // recorded in the CONFIGURE_DONE notification. -TEST_P(SyncDataTypeManagerImplTest, OneControllerFailsAssociation) { +TEST_F(SyncDataTypeManagerImplTest, OneControllerFailsAssociation) { AddController(BOOKMARKS); AddController(PREFERENCES); @@ -620,7 +604,7 @@ TEST_P(SyncDataTypeManagerImplTest, OneControllerFailsAssociation) { // 4) Finish the download for step 2. // 5) Finish starting both controllers. // 6) Stop the DTM. -TEST_P(SyncDataTypeManagerImplTest, ConfigureWhileDownloadPending) { +TEST_F(SyncDataTypeManagerImplTest, ConfigureWhileDownloadPending) { AddController(BOOKMARKS); AddController(PREFERENCES); @@ -672,7 +656,7 @@ TEST_P(SyncDataTypeManagerImplTest, ConfigureWhileDownloadPending) { // // The failure from step 3 should be ignored since there's a // reconfigure pending from step 2. -TEST_P(SyncDataTypeManagerImplTest, ConfigureWhileDownloadPendingWithFailure) { +TEST_F(SyncDataTypeManagerImplTest, ConfigureWhileDownloadPendingWithFailure) { AddController(BOOKMARKS); AddController(PREFERENCES); @@ -713,12 +697,102 @@ TEST_P(SyncDataTypeManagerImplTest, ConfigureWhileDownloadPendingWithFailure) { EXPECT_EQ(DataTypeManager::STOPPED, dtm.state()); } -INSTANTIATE_TEST_CASE_P( - WithoutNigori, SyncDataTypeManagerImplTest, - ::testing::Values(WITHOUT_NIGORI)); +// Tests a Purge then Configure. This is similar to the sequence of +// operations that would be invoked by the BackendMigrator. +TEST_F(SyncDataTypeManagerImplTest, MigrateAll) { + AddController(BOOKMARKS); + + DataTypeManagerImpl dtm(&configurer_, &controllers_, &observer_); + SetConfigureStartExpectation(); + SetConfigureDoneExpectation(DataTypeManager::OK); + + // Initial setup. + Configure(&dtm, ModelTypeSet(BOOKMARKS)); + FinishDownload(dtm, ModelTypeSet()); + GetController(BOOKMARKS)->FinishStart(DataTypeController::OK); + + // We've now configured bookmarks and (implicitly) the control types. + EXPECT_EQ(DataTypeManager::CONFIGURED, dtm.state()); + Mock::VerifyAndClearExpectations(&observer_); + + // Pretend we were told to migrate all types. + ModelTypeSet to_migrate; + to_migrate.Put(BOOKMARKS); + to_migrate.PutAll(syncer::ControlTypes()); -INSTANTIATE_TEST_CASE_P( - WithNigori, SyncDataTypeManagerImplTest, - ::testing::Values(WITH_NIGORI)); + SetConfigureStartExpectation(); + SetConfigureDoneExpectation(DataTypeManager::OK); + dtm.PurgeForMigration(to_migrate, + syncer::CONFIGURE_REASON_MIGRATION); + EXPECT_EQ(DataTypeManager::DOWNLOAD_PENDING, dtm.state()); + + // The DTM will call ConfigureDataTypes(), even though it is unnecessary. + FinishDownload(dtm, ModelTypeSet()); + EXPECT_EQ(DataTypeManager::CONFIGURED, dtm.state()); + Mock::VerifyAndClearExpectations(&observer_); + + // Re-enable the migrated types. + SetConfigureStartExpectation(); + SetConfigureDoneExpectation(DataTypeManager::OK); + Configure(&dtm, to_migrate); + FinishDownload(dtm, ModelTypeSet()); + GetController(BOOKMARKS)->FinishStart(DataTypeController::OK); + EXPECT_EQ(DataTypeManager::CONFIGURED, dtm.state()); +} + +// Test receipt of a Configure request while a purge is in flight. +TEST_F(SyncDataTypeManagerImplTest, ConfigureDuringPurge) { + AddController(BOOKMARKS); + AddController(PREFERENCES); + + DataTypeManagerImpl dtm(&configurer_, &controllers_, &observer_); + + // Initial configure. + SetConfigureStartExpectation(); + SetConfigureDoneExpectation(DataTypeManager::OK); + Configure(&dtm, ModelTypeSet(BOOKMARKS)); + FinishDownload(dtm, ModelTypeSet()); + GetController(BOOKMARKS)->FinishStart(DataTypeController::OK); + EXPECT_EQ(DataTypeManager::CONFIGURED, dtm.state()); + Mock::VerifyAndClearExpectations(&observer_); + + // Purge the Nigori type. + SetConfigureStartExpectation(); + dtm.PurgeForMigration(ModelTypeSet(NIGORI), + syncer::CONFIGURE_REASON_MIGRATION); + EXPECT_EQ(DataTypeManager::DOWNLOAD_PENDING, dtm.state()); + Mock::VerifyAndClearExpectations(&observer_); + + // Before the backend configuration completes, ask for a different + // set of types. This request asks for + // - BOOKMARKS: which is redundant because it was already enabled, + // - PREFERENCES: which is new and will need to be downloaded, and + // - NIGORI: (added implicitly because it is a control type) which + // the DTM is part-way through purging. + SetConfigureBlockedExpectation(); + Configure(&dtm, ModelTypeSet(BOOKMARKS, PREFERENCES)); + EXPECT_EQ(DataTypeManager::DOWNLOAD_PENDING, dtm.state()); + + // Invoke the callback we've been waiting for since we asked to purge NIGORI. + FinishDownload(dtm, ModelTypeSet()); + EXPECT_EQ(DataTypeManager::BLOCKED, dtm.state()); + Mock::VerifyAndClearExpectations(&observer_); + + SetConfigureDoneExpectation(DataTypeManager::OK); + // Pump the loop to run the posted DTMI::ConfigureImpl() task from + // DTMI::ProcessReconfigure(). + ui_loop_.RunAllPending(); + EXPECT_EQ(DataTypeManager::DOWNLOAD_PENDING, dtm.state()); + + // Now invoke the callback for the second configure request. + FinishDownload(dtm, ModelTypeSet()); + EXPECT_EQ(DataTypeManager::CONFIGURING, dtm.state()); + + // Start the preferences controller. We don't need to start controller for + // the NIGORI because it has none. We don't need to start the controller for + // the BOOKMARKS because it was never stopped. + GetController(PREFERENCES)->FinishStart(DataTypeController::OK); + EXPECT_EQ(DataTypeManager::CONFIGURED, dtm.state()); +} } // namespace browser_sync diff --git a/chrome/browser/sync/glue/data_type_manager_mock.h b/chrome/browser/sync/glue/data_type_manager_mock.h index 5f6d192..a1447b3 100644 --- a/chrome/browser/sync/glue/data_type_manager_mock.h +++ b/chrome/browser/sync/glue/data_type_manager_mock.h @@ -18,8 +18,7 @@ class DataTypeManagerMock : public DataTypeManager { virtual ~DataTypeManagerMock(); MOCK_METHOD2(Configure, void(TypeSet, syncer::ConfigureReason)); - MOCK_METHOD2(ConfigureWithoutNigori, - void(TypeSet, syncer::ConfigureReason)); + MOCK_METHOD2(PurgeForMigration, void(TypeSet, syncer::ConfigureReason)); MOCK_METHOD0(Stop, void()); MOCK_METHOD0(controllers, const DataTypeController::TypeMap&()); MOCK_CONST_METHOD0(state, State()); diff --git a/chrome/browser/sync/glue/sync_backend_host.cc b/chrome/browser/sync/glue/sync_backend_host.cc index 579a40c..7d1711d 100644 --- a/chrome/browser/sync/glue/sync_backend_host.cc +++ b/chrome/browser/sync/glue/sync_backend_host.cc @@ -1349,7 +1349,7 @@ void SyncBackendHost::HandleInitializationCompletedOnFrontendLoop( initialization_state_ = DOWNLOADING_NIGORI; ConfigureDataTypes( syncer::CONFIGURE_REASON_NEW_CLIENT, - syncer::ModelTypeSet(syncer::NIGORI), + syncer::ModelTypeSet(syncer::ControlTypes()), syncer::ModelTypeSet(), // Calls back into this function. base::Bind( diff --git a/chrome/browser/sync/glue/sync_backend_host_unittest.cc b/chrome/browser/sync/glue/sync_backend_host_unittest.cc index ec96c74..5a4ae88 100644 --- a/chrome/browser/sync/glue/sync_backend_host_unittest.cc +++ b/chrome/browser/sync/glue/sync_backend_host_unittest.cc @@ -204,7 +204,7 @@ class SyncBackendHostTest : public testing::Test { // Synchronously configures the backend's datatypes. void ConfigureDataTypes(syncer::ModelTypeSet types_to_add, syncer::ModelTypeSet types_to_remove) { - types_to_add.Put(syncer::NIGORI); + types_to_add.PutAll(syncer::ControlTypes()); backend_->ConfigureDataTypes( syncer::CONFIGURE_REASON_RECONFIGURATION, types_to_add, @@ -247,28 +247,28 @@ class SyncBackendHostTest : public testing::Test { TEST_F(SyncBackendHostTest, InitShutdown) { InitializeBackend(); EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Equals( - syncer::ModelTypeSet(syncer::NIGORI))); + syncer::ControlTypes())); EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals( - syncer::ModelTypeSet(syncer::NIGORI))); + syncer::ControlTypes())); EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( - syncer::ModelTypeSet(syncer::NIGORI)).Empty()); + syncer::ControlTypes()).Empty()); } // Test first time sync scenario. All types should be properly configured. TEST_F(SyncBackendHostTest, FirstTimeSync) { InitializeBackend(); EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Equals( - syncer::ModelTypeSet(syncer::NIGORI))); + syncer::ControlTypes())); EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals( - syncer::ModelTypeSet(syncer::NIGORI))); + syncer::ControlTypes())); EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( - syncer::ModelTypeSet(syncer::NIGORI)).Empty()); + syncer::ControlTypes()).Empty()); ConfigureDataTypes(enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_)); EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().HasAll( - enabled_types_)); + Difference(enabled_types_, syncer::ControlTypes()))); EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals(enabled_types_)); EXPECT_TRUE(fake_manager_->GetAndResetEnabledTypes().Equals(enabled_types_)); EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( @@ -348,12 +348,12 @@ TEST_F(SyncBackendHostTest, LostDB) { // left untouched. InitializeBackend(); EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Equals( - syncer::ModelTypeSet(syncer::NIGORI))); + syncer::ModelTypeSet(syncer::ControlTypes()))); EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals( - syncer::ModelTypeSet(syncer::NIGORI))); + syncer::ModelTypeSet(syncer::ControlTypes()))); EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( enabled_types_).Equals( - Difference(enabled_types_, syncer::ModelTypeSet(syncer::NIGORI)))); + Difference(enabled_types_, syncer::ControlTypes()))); // The database was empty, so any cleaning is entirely optional. We want to // reset this value before running the next part of the test, though. @@ -364,7 +364,7 @@ TEST_F(SyncBackendHostTest, LostDB) { Difference(syncer::ModelTypeSet::All(), enabled_types_)); EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().HasAll( - enabled_types_)); + Difference(enabled_types_, syncer::ControlTypes()))); EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(), enabled_types_).Empty()); EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals(enabled_types_)); diff --git a/chrome/browser/sync/sync_prefs.cc b/chrome/browser/sync/sync_prefs.cc index 2ba2dd9..1b7a92f 100644 --- a/chrome/browser/sync/sync_prefs.cc +++ b/chrome/browser/sync/sync_prefs.cc @@ -336,15 +336,15 @@ void SyncPrefs::RegisterPreferences() { enable_by_default, PrefService::UNSYNCABLE_PREF); + syncer::ModelTypeSet user_types = syncer::UserTypes(); + // Treat bookmarks specially. RegisterDataTypePreferredPref(syncer::BOOKMARKS, true); - for (int i = syncer::PREFERENCES; i < syncer::MODEL_TYPE_COUNT; ++i) { - const syncer::ModelType type = syncer::ModelTypeFromInt(i); - // Also treat nigori specially. - if (type == syncer::NIGORI) { - continue; - } - RegisterDataTypePreferredPref(type, enable_by_default); + user_types.Remove(syncer::BOOKMARKS); + + for (syncer::ModelTypeSet::Iterator it = user_types.First(); + it.Good(); it.Inc()) { + RegisterDataTypePreferredPref(it.Get(), enable_by_default); } pref_service_->RegisterBooleanPref(prefs::kSyncManaged, |