Commit 3b11f031 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Don't create services that need a DB thread if there is no DB thread.

Right now, this CL is vacuous, since |db_thread_| is always set.

However, while changing the WebDataService to move off the DB thread, I'll be
changing ChromeSyncClient to get the correct thread from the WebDataService.  If
there is no WebDataService, then the easiest thing to do is this CL (don't
bother creating things that need a WebDataService to function, and ensure that
tests that need these created create the WebDataService first).

If we didn't do this, then one of two things would happen:
* ChromeSyncClient would pass a null db_thread_ in, which would get passed into
  the various individual datatype services here, which would then run into
  problems because at least some of them DCHECK that they have a model thread.
  These services would have to be tweaked to instead DCHECK that no one tries to
  _use_ them when there's no model thread.  I went this route first, then
  decided it made no sense to create services that weren't allowed to be used.
* ChromeSyncClient would make up a random task runner and pass it down as the
  model thread.  Again, it felt misleading to create a task runner that no one
  could run tasks on (because if someone did, it would mean they were trying to
  talk to a database that didn't exist).

So, this seemed like the clearest precursor to the future changes.

While there, I also tweaked how the conditional works for history-based services
so it would be structured similarly.

Bug: 689520
Change-Id: Ic1aaa5947e7328b322bc508e3092ab389b6f73c3
Reviewed-on: https://chromium-review.googlesource.com/578929Reviewed-by: default avatarNicolas Zea <zea@chromium.org>
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#488388}
parent 81b4f7b4
...@@ -28,6 +28,12 @@ using browser_sync::ProfileSyncService; ...@@ -28,6 +28,12 @@ using browser_sync::ProfileSyncService;
using syncer::DataTypeController; using syncer::DataTypeController;
class ProfileSyncServiceFactoryTest : public testing::Test { class ProfileSyncServiceFactoryTest : public testing::Test {
public:
void SetUp() override {
// Some services will only be created if there is a WebDataService.
profile_->CreateWebDataService();
}
protected: protected:
ProfileSyncServiceFactoryTest() : profile_(new TestingProfile()) {} ProfileSyncServiceFactoryTest() : profile_(new TestingProfile()) {}
...@@ -113,7 +119,7 @@ class ProfileSyncServiceFactoryTest : public testing::Test { ...@@ -113,7 +119,7 @@ class ProfileSyncServiceFactoryTest : public testing::Test {
private: private:
content::TestBrowserThreadBundle thread_bundle_; content::TestBrowserThreadBundle thread_bundle_;
std::unique_ptr<Profile> profile_; std::unique_ptr<TestingProfile> profile_;
}; };
// Verify that the disable sync flag disables creation of the sync service. // Verify that the disable sync flag disables creation of the sync service.
......
...@@ -154,48 +154,51 @@ void ProfileSyncComponentsFactoryImpl::RegisterCommonDataTypes( ...@@ -154,48 +154,51 @@ void ProfileSyncComponentsFactoryImpl::RegisterCommonDataTypes(
sync_service->GetLocalDeviceInfoProvider())); sync_service->GetLocalDeviceInfoProvider()));
} }
// Autocomplete sync is enabled by default. Register unless explicitly // These features are enabled only if there's a DB thread to post tasks to.
// disabled. if (db_thread_) {
if (!disabled_types.Has(syncer::AUTOFILL)) { // Autocomplete sync is enabled by default. Register unless explicitly
if (FeatureList::IsEnabled(switches::kSyncUSSAutocomplete)) { // disabled.
sync_service->RegisterDataTypeController( if (!disabled_types.Has(syncer::AUTOFILL)) {
base::MakeUnique<autofill::WebDataModelTypeController>( if (FeatureList::IsEnabled(switches::kSyncUSSAutocomplete)) {
syncer::AUTOFILL, sync_client_, db_thread_, web_data_service_, sync_service->RegisterDataTypeController(
base::Bind( base::MakeUnique<autofill::WebDataModelTypeController>(
&autofill::AutocompleteSyncBridge::FromWebDataService))); syncer::AUTOFILL, sync_client_, db_thread_, web_data_service_,
} else { base::Bind(
&autofill::AutocompleteSyncBridge::FromWebDataService)));
} else {
sync_service->RegisterDataTypeController(
base::MakeUnique<AutofillDataTypeController>(
db_thread_, error_callback, sync_client_, web_data_service_));
}
}
// Autofill sync is enabled by default. Register unless explicitly
// disabled.
if (!disabled_types.Has(syncer::AUTOFILL_PROFILE)) {
sync_service->RegisterDataTypeController( sync_service->RegisterDataTypeController(
base::MakeUnique<AutofillDataTypeController>( base::MakeUnique<AutofillProfileDataTypeController>(
db_thread_, error_callback, sync_client_, web_data_service_)); db_thread_, error_callback, sync_client_, web_data_service_));
} }
}
// Autofill sync is enabled by default. Register unless explicitly // Wallet data sync is enabled by default, but behind a syncer experiment
// disabled. // enforced by the datatype controller. Register unless explicitly disabled.
if (!disabled_types.Has(syncer::AUTOFILL_PROFILE)) { bool wallet_disabled = disabled_types.Has(syncer::AUTOFILL_WALLET_DATA);
sync_service->RegisterDataTypeController( if (!wallet_disabled) {
base::MakeUnique<AutofillProfileDataTypeController>( sync_service->RegisterDataTypeController(
db_thread_, error_callback, sync_client_, web_data_service_)); base::MakeUnique<AutofillWalletDataTypeController>(
} syncer::AUTOFILL_WALLET_DATA, db_thread_, error_callback,
sync_client_, web_data_service_));
// Wallet data sync is enabled by default, but behind a syncer experiment }
// enforced by the datatype controller. Register unless explicitly disabled.
bool wallet_disabled = disabled_types.Has(syncer::AUTOFILL_WALLET_DATA);
if (!wallet_disabled) {
sync_service->RegisterDataTypeController(
base::MakeUnique<AutofillWalletDataTypeController>(
syncer::AUTOFILL_WALLET_DATA, db_thread_, error_callback,
sync_client_, web_data_service_));
}
// Wallet metadata sync depends on Wallet data sync. Register if Wallet data // Wallet metadata sync depends on Wallet data sync. Register if Wallet data
// is syncing and metadata sync is not explicitly disabled. // is syncing and metadata sync is not explicitly disabled.
if (!wallet_disabled && if (!wallet_disabled &&
!disabled_types.Has(syncer::AUTOFILL_WALLET_METADATA)) { !disabled_types.Has(syncer::AUTOFILL_WALLET_METADATA)) {
sync_service->RegisterDataTypeController( sync_service->RegisterDataTypeController(
base::MakeUnique<AutofillWalletDataTypeController>( base::MakeUnique<AutofillWalletDataTypeController>(
syncer::AUTOFILL_WALLET_METADATA, db_thread_, error_callback, syncer::AUTOFILL_WALLET_METADATA, db_thread_, error_callback,
sync_client_, web_data_service_)); sync_client_, web_data_service_));
}
} }
// Bookmark sync is enabled by default. Register unless explicitly // Bookmark sync is enabled by default. Register unless explicitly
...@@ -206,55 +209,54 @@ void ProfileSyncComponentsFactoryImpl::RegisterCommonDataTypes( ...@@ -206,55 +209,54 @@ void ProfileSyncComponentsFactoryImpl::RegisterCommonDataTypes(
sync_client_)); sync_client_));
} }
const bool history_disabled = // These features are enabled only if history is not disabled.
sync_client_->GetPrefService()->GetBoolean(history_disabled_pref_); if (!sync_client_->GetPrefService()->GetBoolean(history_disabled_pref_)) {
// TypedUrl sync is enabled by default. Register unless explicitly disabled, // TypedUrl sync is enabled by default. Register unless explicitly
// or if saving history is disabled. // disabled.
if (!disabled_types.Has(syncer::TYPED_URLS) && !history_disabled) { if (!disabled_types.Has(syncer::TYPED_URLS)) {
if (base::FeatureList::IsEnabled(switches::kSyncUSSTypedURL)) { if (base::FeatureList::IsEnabled(switches::kSyncUSSTypedURL)) {
// TODO(gangwu): Register controller here once typed url controller // TODO(gangwu): Register controller here once typed url controller
// implemented. // implemented.
} else { } else {
sync_service->RegisterDataTypeController( sync_service->RegisterDataTypeController(
base::MakeUnique<TypedUrlDataTypeController>( base::MakeUnique<TypedUrlDataTypeController>(
error_callback, sync_client_, history_disabled_pref_)); error_callback, sync_client_, history_disabled_pref_));
}
} }
}
// Delete directive sync is enabled by default. Register unless full history // Delete directive sync is enabled by default.
// sync is disabled. if (!disabled_types.Has(syncer::HISTORY_DELETE_DIRECTIVES)) {
if (!disabled_types.Has(syncer::HISTORY_DELETE_DIRECTIVES) && sync_service->RegisterDataTypeController(
!history_disabled) { base::MakeUnique<HistoryDeleteDirectivesDataTypeController>(
sync_service->RegisterDataTypeController( error_callback, sync_client_));
base::MakeUnique<HistoryDeleteDirectivesDataTypeController>( }
error_callback, sync_client_));
}
// Session sync is enabled by default. Register unless explicitly disabled. // Session sync is enabled by default. This is disabled if history is
// This is also disabled if the browser history is disabled, because the // disabled because the tab sync data is added to the web history on the
// tab sync data is added to the web history on the server. // server.
if (!disabled_types.Has(syncer::PROXY_TABS) && !history_disabled) { if (!disabled_types.Has(syncer::PROXY_TABS)) {
sync_service->RegisterDataTypeController( sync_service->RegisterDataTypeController(
base::MakeUnique<ProxyDataTypeController>(syncer::PROXY_TABS)); base::MakeUnique<ProxyDataTypeController>(syncer::PROXY_TABS));
sync_service->RegisterDataTypeController( sync_service->RegisterDataTypeController(
base::MakeUnique<SessionDataTypeController>( base::MakeUnique<SessionDataTypeController>(
error_callback, sync_client_, error_callback, sync_client_,
sync_service->GetLocalDeviceInfoProvider(), sync_service->GetLocalDeviceInfoProvider(),
history_disabled_pref_)); history_disabled_pref_));
} }
// Favicon sync is enabled by default. Register unless explicitly disabled. // Favicon sync is enabled by default. Register unless explicitly disabled.
if (!disabled_types.Has(syncer::FAVICON_IMAGES) && if (!disabled_types.Has(syncer::FAVICON_IMAGES) &&
!disabled_types.Has(syncer::FAVICON_TRACKING) && !history_disabled) { !disabled_types.Has(syncer::FAVICON_TRACKING)) {
// crbug/384552. We disable error uploading for this data types for now. // crbug/384552. We disable error uploading for this data types for now.
sync_service->RegisterDataTypeController( sync_service->RegisterDataTypeController(
base::MakeUnique<AsyncDirectoryTypeController>( base::MakeUnique<AsyncDirectoryTypeController>(
syncer::FAVICON_IMAGES, base::Closure(), sync_client_, syncer::FAVICON_IMAGES, base::Closure(), sync_client_,
syncer::GROUP_UI, ui_thread_)); syncer::GROUP_UI, ui_thread_));
sync_service->RegisterDataTypeController( sync_service->RegisterDataTypeController(
base::MakeUnique<AsyncDirectoryTypeController>( base::MakeUnique<AsyncDirectoryTypeController>(
syncer::FAVICON_TRACKING, base::Closure(), sync_client_, syncer::FAVICON_TRACKING, base::Closure(), sync_client_,
syncer::GROUP_UI, ui_thread_)); syncer::GROUP_UI, ui_thread_));
}
} }
// Password sync is enabled by default. Register unless explicitly // Password sync is enabled by default. Register unless explicitly
......
...@@ -26,6 +26,11 @@ class IOSChromeProfileSyncServiceFactoryTest : public testing::Test { ...@@ -26,6 +26,11 @@ class IOSChromeProfileSyncServiceFactoryTest : public testing::Test {
chrome_browser_state_ = browser_state_builder.Build(); chrome_browser_state_ = browser_state_builder.Build();
} }
void SetUp() override {
// Some services will only be created if there is a WebDataService.
chrome_browser_state_->CreateWebDataService();
}
protected: protected:
// Returns the collection of default datatypes. // Returns the collection of default datatypes.
std::vector<syncer::ModelType> DefaultDatatypes() { std::vector<syncer::ModelType> DefaultDatatypes() {
......
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