diff options
Diffstat (limited to 'chrome/browser/sync')
6 files changed, 56 insertions, 0 deletions
diff --git a/chrome/browser/sync/glue/data_type_controller.h b/chrome/browser/sync/glue/data_type_controller.h index f827e03..baece97 100644 --- a/chrome/browser/sync/glue/data_type_controller.h +++ b/chrome/browser/sync/glue/data_type_controller.h @@ -45,6 +45,8 @@ class DataTypeController ASSOCIATION_FAILED, // An error occurred during model association. ABORTED, // Start was aborted by calling Stop(). UNRECOVERABLE_ERROR, // An unrecoverable error occured. + NEEDS_CRYPTO, // The data type cannot be started yet because it + // depends on the cryptographer. MAX_START_RESULT }; diff --git a/chrome/browser/sync/glue/data_type_manager_impl.cc b/chrome/browser/sync/glue/data_type_manager_impl.cc index fd1464e..c133ca7 100644 --- a/chrome/browser/sync/glue/data_type_manager_impl.cc +++ b/chrome/browser/sync/glue/data_type_manager_impl.cc @@ -231,6 +231,14 @@ void DataTypeManagerImpl::TypeStartCallback( return; } + // If the type is waiting for the cryptographer, continue to the next type. + // Once the cryptographer is ready, we'll attempt to restart this type. + if (result == DataTypeController::NEEDS_CRYPTO) { + LOG(INFO) << "Waiting for crypto " << started_dtc->name(); + StartNextType(); + return; + } + // If the type started normally, continue to the next type. if (result == DataTypeController::OK || result == DataTypeController::OK_FIRST_RUN) { 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 64d9301..1fd017d 100644 --- a/chrome/browser/sync/glue/data_type_manager_impl_unittest.cc +++ b/chrome/browser/sync/glue/data_type_manager_impl_unittest.cc @@ -76,6 +76,14 @@ class DataTypeManagerImplTest : public testing::Test { return dtc; } + DataTypeControllerMock* MakePasswordDTC() { + DataTypeControllerMock* dtc = new DataTypeControllerMock(); + EXPECT_CALL(*dtc, enabled()).WillRepeatedly(Return(true)); + EXPECT_CALL(*dtc, type()).WillRepeatedly(Return(syncable::PASSWORDS)); + EXPECT_CALL(*dtc, name()).WillRepeatedly(Return("passwords")); + return dtc; + } + void SetStartStopExpectations(DataTypeControllerMock* mock_dtc) { InSequence seq; EXPECT_CALL(*mock_dtc, state()). @@ -151,6 +159,29 @@ TEST_F(DataTypeManagerImplTest, ConfigureOne) { EXPECT_EQ(DataTypeManager::STOPPED, dtm.state()); } +TEST_F(DataTypeManagerImplTest, OneWaitingForCrypto) { + DataTypeControllerMock* password_dtc = MakePasswordDTC(); + EXPECT_CALL(*password_dtc, state()). + WillRepeatedly(Return(DataTypeController::NOT_RUNNING)); + EXPECT_CALL(*password_dtc, Start(_)). + WillOnce(InvokeCallback((DataTypeController::NEEDS_CRYPTO))); + EXPECT_CALL(*password_dtc, state()). + WillRepeatedly(Return(DataTypeController::NOT_RUNNING)); + + controllers_[syncable::PASSWORDS] = password_dtc; + SetBackendExpectations(1); + + DataTypeManagerImpl dtm(&backend_, controllers_); + types_.insert(syncable::PASSWORDS); + SetConfigureStartExpectation(); + SetConfigureDoneExpectation(DataTypeManager::OK); + dtm.Configure(types_); + EXPECT_EQ(DataTypeManager::CONFIGURED, dtm.state()); + dtm.Stop(); + EXPECT_EQ(DataTypeManager::STOPPED, dtm.state()); +} + + TEST_F(DataTypeManagerImplTest, ConfigureOneThenAnother) { DataTypeControllerMock* bookmark_dtc = MakeBookmarkDTC(); SetStartStopExpectations(bookmark_dtc); diff --git a/chrome/browser/sync/glue/password_data_type_controller.cc b/chrome/browser/sync/glue/password_data_type_controller.cc index f198d5c..642d3f4 100644 --- a/chrome/browser/sync/glue/password_data_type_controller.cc +++ b/chrome/browser/sync/glue/password_data_type_controller.cc @@ -42,6 +42,12 @@ void PasswordDataTypeController::Start(StartCallback* start_callback) { return; } + if (!sync_service_->IsCryptographerReady()) { + start_callback->Run(NEEDS_CRYPTO); + delete start_callback; + return; + } + start_callback_.reset(start_callback); set_state(ASSOCIATING); diff --git a/chrome/browser/sync/profile_sync_service.cc b/chrome/browser/sync/profile_sync_service.cc index 3bdb5c5..26b093a 100644 --- a/chrome/browser/sync/profile_sync_service.cc +++ b/chrome/browser/sync/profile_sync_service.cc @@ -649,6 +649,11 @@ void ProfileSyncService::GetRegisteredDataTypes( } } +bool ProfileSyncService::IsCryptographerReady() const { + // TODO(albertb): Replace this once the crypto patch lands. + return true; +} + void ProfileSyncService::StartProcessingChangesIfReady() { DCHECK(backend_initialized_); diff --git a/chrome/browser/sync/profile_sync_service.h b/chrome/browser/sync/profile_sync_service.h index 54c9bc6..016b032 100644 --- a/chrome/browser/sync/profile_sync_service.h +++ b/chrome/browser/sync/profile_sync_service.h @@ -299,6 +299,10 @@ class ProfileSyncService : public browser_sync::SyncFrontend, virtual void GetRegisteredDataTypes( syncable::ModelTypeSet* registered_types) const; + // Checks whether the Cryptographer is ready to encrypt and decrypt updates + // for sensitive data types. + virtual bool IsCryptographerReady() const; + protected: // Used by ProfileSyncServiceMock only. // |