diff options
Diffstat (limited to 'chrome')
4 files changed, 89 insertions, 10 deletions
diff --git a/chrome/browser/sync/glue/fake_data_type_controller.cc b/chrome/browser/sync/glue/fake_data_type_controller.cc index 20f64a2..da41997 100644 --- a/chrome/browser/sync/glue/fake_data_type_controller.cc +++ b/chrome/browser/sync/glue/fake_data_type_controller.cc @@ -74,6 +74,13 @@ void FakeDataTypeController::FinishStart(StartResult result) { // * -> NOT_RUNNING void FakeDataTypeController::Stop() { state_ = NOT_RUNNING; + if (!model_load_callback_.is_null()) { + // Real data type controllers run the callback and specify "ABORTED" as an + // error. We should probably find a way to use the real code and mock out + // unnecessary pieces. + SimulateModelLoadFinishing(); + } + // The DTM still expects |last_start_callback_| to be called back. if (!last_start_callback_.is_null()) { SyncError error(FROM_HERE, "Fake error", type_); diff --git a/chrome/browser/sync/glue/model_association_manager.cc b/chrome/browser/sync/glue/model_association_manager.cc index 40e6f34..add2f70 100644 --- a/chrome/browser/sync/glue/model_association_manager.cc +++ b/chrome/browser/sync/glue/model_association_manager.cc @@ -101,12 +101,11 @@ ModelAssociationManager::~ModelAssociationManager() { void ModelAssociationManager::Initialize( syncable::ModelTypeSet desired_types) { - DCHECK_EQ(state_, IDLE); needs_start_.clear(); needs_stop_.clear(); failed_datatypes_info_.clear(); desired_types_ = desired_types; - state_ = INITIAILIZED_TO_CONFIGURE; + state_ = INITIALIZED_TO_CONFIGURE; DVLOG(1) << "ModelAssociationManager: Initializing"; @@ -154,14 +153,14 @@ void ModelAssociationManager::Initialize( } void ModelAssociationManager::StartAssociationAsync() { - DCHECK_EQ(state_, INITIAILIZED_TO_CONFIGURE); + DCHECK_EQ(state_, INITIALIZED_TO_CONFIGURE); state_ = CONFIGURING; DVLOG(1) << "ModelAssociationManager: Going to start model association"; LoadModelForNextType(); } void ModelAssociationManager::ResetForReconfiguration() { - DCHECK_EQ(state_, INITIAILIZED_TO_CONFIGURE); + DCHECK_EQ(state_, INITIALIZED_TO_CONFIGURE); state_ = IDLE; DVLOG(1) << "ModelAssociationManager: Reseting for reconfiguration"; needs_start_.clear(); @@ -170,7 +169,7 @@ void ModelAssociationManager::ResetForReconfiguration() { } void ModelAssociationManager::StopDisabledTypes() { - DCHECK_EQ(state_, INITIAILIZED_TO_CONFIGURE); + DCHECK_EQ(state_, INITIALIZED_TO_CONFIGURE); DVLOG(1) << "ModelAssociationManager: Stopping disabled types."; // Stop requested data types. for (size_t i = 0; i < needs_stop_.size(); ++i) { @@ -211,7 +210,7 @@ void ModelAssociationManager::Stop() { // Now continue stopping any types that have already started. DCHECK(state_ == IDLE || - state_ == INITIAILIZED_TO_CONFIGURE); + state_ == INITIALIZED_TO_CONFIGURE); for (DataTypeController::TypeMap::const_iterator it = controllers_->begin(); it != controllers_->end(); ++it) { DataTypeController* dtc = (*it).second; @@ -416,13 +415,18 @@ void ModelAssociationManager::ModelLoadCallback( } NOTREACHED(); return; - } else { + } else if (state_ == IDLE) { DVLOG(1) << "ModelAssociationManager: Models loaded after configure cycle" << "Informing DTM"; // This datatype finished loading after the deadline imposed by the // originating configuration cycle. Inform the DataTypeManager that the // type has loaded, so that association may begin. result_processor_->OnTypesLoaded(); + } else { + // If we're not IDLE or CONFIGURING, we're being invoked as part of an abort + // process (possibly a reconfiguration, or disabling of a broken data type). + DVLOG(1) << "ModelAssociationManager: ModelLoadCallback occurred while " + << "not IDLE or CONFIGURING. Doing nothing."; } } @@ -502,4 +506,3 @@ base::OneShotTimer<ModelAssociationManager>* } } // namespace browser_sync - diff --git a/chrome/browser/sync/glue/model_association_manager.h b/chrome/browser/sync/glue/model_association_manager.h index 07b7933..5858bae 100644 --- a/chrome/browser/sync/glue/model_association_manager.h +++ b/chrome/browser/sync/glue/model_association_manager.h @@ -80,7 +80,7 @@ class ModelAssociationManager { private: enum State { // This is the state after |Initialize| is called. - INITIAILIZED_TO_CONFIGURE, + INITIALIZED_TO_CONFIGURE, // Starting a new configuration. CONFIGURING, // A stop command was issued. diff --git a/chrome/browser/sync/glue/model_association_manager_unittest.cc b/chrome/browser/sync/glue/model_association_manager_unittest.cc index 25e9fa3..c320d1d 100644 --- a/chrome/browser/sync/glue/model_association_manager_unittest.cc +++ b/chrome/browser/sync/glue/model_association_manager_unittest.cc @@ -211,6 +211,76 @@ TEST_F(ModelAssociationManagerTest, TypeReturnUnrecoverableError) { DataTypeController::UNRECOVERABLE_ERROR); } +TEST_F(ModelAssociationManagerTest, InitializeAbortsLoad) { + controllers_[syncable::BOOKMARKS] = + new FakeDataTypeController(syncable::BOOKMARKS); + controllers_[syncable::THEMES] = + new FakeDataTypeController(syncable::THEMES); + + GetController(controllers_, syncable::BOOKMARKS)->SetDelayModelLoad(); + ModelAssociationManager model_association_manager(&controllers_, + &result_processor_); + syncable::ModelTypeSet types(syncable::BOOKMARKS, syncable::THEMES); + + syncable::ModelTypeSet expected_types_waiting_to_load; + expected_types_waiting_to_load.Put(syncable::BOOKMARKS); + DataTypeManager::ConfigureResult expected_result_partially_done( + DataTypeManager::PARTIAL_SUCCESS, + types, + std::list<SyncError>(), + expected_types_waiting_to_load); + + model_association_manager.Initialize(types); + model_association_manager.StopDisabledTypes(); + + model_association_manager.StartAssociationAsync(); + + EXPECT_CALL(result_processor_, OnModelAssociationDone(_)). + WillOnce(VerifyResult(expected_result_partially_done)); + + base::OneShotTimer<ModelAssociationManager>* timer = + model_association_manager.GetTimerForTesting(); + + base::Closure task = timer->user_task(); + timer->Stop(); + task.Run(); // Bookmark load times out here. + + // Apps finishes associating here. + GetController(controllers_, syncable::THEMES)->FinishStart( + DataTypeController::OK); + + // At this point, BOOKMARKS is still waiting to load (as evidenced by + // expected_result_partially_done). If we schedule another Initialize (which + // could happen in practice due to reconfiguration), this should abort + // BOOKMARKS. Aborting will call ModelLoadCallback, but the + // ModelAssociationManager should be smart enough to know that this is not due + // to the type having completed loading. + EXPECT_CALL(result_processor_, OnTypesLoaded()).Times(0); + + EXPECT_EQ(GetController(controllers_, syncable::BOOKMARKS)->state(), + DataTypeController::MODEL_STARTING); + + model_association_manager.Initialize(types); + EXPECT_EQ(GetController(controllers_, syncable::BOOKMARKS)->state(), + DataTypeController::NOT_RUNNING); + + DataTypeManager::ConfigureResult expected_result_done( + DataTypeManager::OK, + types, + std::list<SyncError>(), + syncable::ModelTypeSet()); + EXPECT_CALL(result_processor_, OnModelAssociationDone(_)). + WillOnce(VerifyResult(expected_result_done)); + + model_association_manager.StopDisabledTypes(); + model_association_manager.StartAssociationAsync(); + + GetController(controllers_, + syncable::BOOKMARKS)->SimulateModelLoadFinishing(); + GetController(controllers_, syncable::BOOKMARKS)->FinishStart( + DataTypeController::OK); +} + // Start 2 types. One of which timeout loading. Ensure that type is // fully configured eventually. TEST_F(ModelAssociationManagerTest, ModelStartWithSlowLoadingType) { @@ -281,4 +351,3 @@ TEST_F(ModelAssociationManagerTest, ModelStartWithSlowLoadingType) { } // namespace browser_sync - |
