diff options
author | maxbogue <maxbogue@chromium.org> | 2015-10-11 14:46:36 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-10-11 21:47:27 +0000 |
commit | d2337388e8915577637c0a20e58330af69e6948f (patch) | |
tree | 06484bae554f3cd6860211404d6ba642d5c7d59e | |
parent | 5cf706c93a7d93df435f9f50ab6bec072cc4465e (diff) | |
download | chromium_src-d2337388e8915577637c0a20e58330af69e6948f.zip chromium_src-d2337388e8915577637c0a20e58330af69e6948f.tar.gz chromium_src-d2337388e8915577637c0a20e58330af69e6948f.tar.bz2 |
[Sync] Componentize SearchEngineDataTypeController.
BUG=512054
Review URL: https://codereview.chromium.org/1379823003
Cr-Commit-Position: refs/heads/master@{#353478}
-rw-r--r-- | chrome/browser/sync/glue/search_engine_data_type_controller.h | 48 | ||||
-rw-r--r-- | chrome/browser/sync/glue/search_engine_data_type_controller_unittest.cc | 9 | ||||
-rw-r--r-- | chrome/browser/sync/profile_sync_components_factory_impl.cc | 7 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 2 | ||||
-rw-r--r-- | components/search_engines.gypi | 3 | ||||
-rw-r--r-- | components/search_engines/BUILD.gn | 3 | ||||
-rw-r--r-- | components/search_engines/DEPS | 1 | ||||
-rw-r--r-- | components/search_engines/search_engine_data_type_controller.cc (renamed from chrome/browser/sync/glue/search_engine_data_type_controller.cc) | 46 | ||||
-rw-r--r-- | components/search_engines/search_engine_data_type_controller.h | 55 |
9 files changed, 92 insertions, 82 deletions
diff --git a/chrome/browser/sync/glue/search_engine_data_type_controller.h b/chrome/browser/sync/glue/search_engine_data_type_controller.h deleted file mode 100644 index 2165ad4..0000000 --- a/chrome/browser/sync/glue/search_engine_data_type_controller.h +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_SYNC_GLUE_SEARCH_ENGINE_DATA_TYPE_CONTROLLER_H__ -#define CHROME_BROWSER_SYNC_GLUE_SEARCH_ENGINE_DATA_TYPE_CONTROLLER_H__ - -#include <string> - -#include "base/compiler_specific.h" -#include "base/memory/scoped_ptr.h" -#include "components/search_engines/template_url_service.h" -#include "components/sync_driver/generic_change_processor.h" -#include "components/sync_driver/ui_data_type_controller.h" -#include "content/public/browser/notification_observer.h" -#include "content/public/browser/notification_registrar.h" - -class Profile; - -namespace browser_sync { - -class SearchEngineDataTypeController - : public sync_driver::UIDataTypeController { - public: - SearchEngineDataTypeController(const base::Closure& error_callback, - sync_driver::SyncClient* sync_client, - Profile* profile); - - TemplateURLService::Subscription* GetSubscriptionForTesting(); - - private: - ~SearchEngineDataTypeController() override; - - // FrontendDataTypeController implementations. - bool StartModels() override; - void StopModels() override; - - void OnTemplateURLServiceLoaded(); - - scoped_ptr<TemplateURLService::Subscription> template_url_subscription_; - Profile* const profile_; - - DISALLOW_COPY_AND_ASSIGN(SearchEngineDataTypeController); -}; - -} // namespace browser_sync - -#endif // CHROME_BROWSER_SYNC_GLUE_SEARCH_ENGINE_DATA_TYPE_CONTROLLER_H__ diff --git a/chrome/browser/sync/glue/search_engine_data_type_controller_unittest.cc b/chrome/browser/sync/glue/search_engine_data_type_controller_unittest.cc index 005e1fc..6997214 100644 --- a/chrome/browser/sync/glue/search_engine_data_type_controller_unittest.cc +++ b/chrome/browser/sync/glue/search_engine_data_type_controller_unittest.cc @@ -7,20 +7,23 @@ #include "base/callback.h" #include "base/memory/scoped_ptr.h" #include "base/run_loop.h" +#include "base/single_thread_task_runner.h" #include "base/tracked_objects.h" #include "chrome/browser/search_engines/template_url_service_factory.h" #include "chrome/browser/search_engines/template_url_service_factory_test_util.h" -#include "chrome/browser/sync/glue/search_engine_data_type_controller.h" #include "chrome/browser/sync/profile_sync_service_mock.h" #include "chrome/test/base/profile_mock.h" +#include "components/search_engines/search_engine_data_type_controller.h" #include "components/sync_driver/data_type_controller_mock.h" #include "components/sync_driver/fake_generic_change_processor.h" #include "components/sync_driver/fake_sync_client.h" #include "components/sync_driver/sync_api_component_factory_mock.h" +#include "content/public/browser/browser_thread.h" #include "content/public/test/test_browser_thread_bundle.h" #include "sync/api/fake_syncable_service.h" #include "testing/gtest/include/gtest/gtest.h" +using content::BrowserThread; using testing::_; using testing::DoAll; using testing::InvokeWithoutArgs; @@ -49,7 +52,9 @@ class SyncSearchEngineDataTypeControllerTest // Feed the DTC the profile so it is reused later. // This allows us to control the associated TemplateURLService. search_engine_dtc_ = new SearchEngineDataTypeController( - base::Bind(&base::DoNothing), this, &profile_); + BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), + base::Bind(&base::DoNothing), this, + TemplateURLServiceFactory::GetForProfile(&profile_)); } void TearDown() override { diff --git a/chrome/browser/sync/profile_sync_components_factory_impl.cc b/chrome/browser/sync/profile_sync_components_factory_impl.cc index efba56d..a0eecba 100644 --- a/chrome/browser/sync/profile_sync_components_factory_impl.cc +++ b/chrome/browser/sync/profile_sync_components_factory_impl.cc @@ -9,12 +9,12 @@ #include "build/build_config.h" #include "chrome/browser/bookmarks/bookmark_model_factory.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/search_engines/template_url_service_factory.h" #include "chrome/browser/sync/glue/autofill_data_type_controller.h" #include "chrome/browser/sync/glue/autofill_profile_data_type_controller.h" #include "chrome/browser/sync/glue/history_delete_directives_data_type_controller.h" #include "chrome/browser/sync/glue/local_device_info_provider_impl.h" #include "chrome/browser/sync/glue/password_data_type_controller.h" -#include "chrome/browser/sync/glue/search_engine_data_type_controller.h" #include "chrome/browser/sync/glue/sync_backend_host.h" #include "chrome/browser/sync/glue/sync_backend_host_impl.h" #include "chrome/browser/sync/glue/theme_data_type_controller.h" @@ -29,6 +29,7 @@ #include "components/autofill/core/common/autofill_pref_names.h" #include "components/autofill/core/common/autofill_switches.h" #include "components/dom_distiller/core/dom_distiller_features.h" +#include "components/search_engines/search_engine_data_type_controller.h" #include "components/sync_bookmarks/bookmark_change_processor.h" #include "components/sync_bookmarks/bookmark_data_type_controller.h" #include "components/sync_bookmarks/bookmark_model_associator.h" @@ -337,7 +338,9 @@ void ProfileSyncComponentsFactoryImpl::RegisterDesktopDataTypes( // disabled. if (!disabled_types.Has(syncer::SEARCH_ENGINES)) { sync_service->RegisterDataTypeController(new SearchEngineDataTypeController( - error_callback, sync_client, profile_)); + BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), + error_callback, sync_client, + TemplateURLServiceFactory::GetForProfile(profile_))); } #if defined(ENABLE_EXTENSIONS) diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 5b8e787..b4558dd 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -2865,8 +2865,6 @@ 'browser/sync/glue/local_device_info_provider_impl.h', 'browser/sync/glue/password_data_type_controller.cc', 'browser/sync/glue/password_data_type_controller.h', - 'browser/sync/glue/search_engine_data_type_controller.cc', - 'browser/sync/glue/search_engine_data_type_controller.h', 'browser/sync/glue/sync_backend_host.cc', 'browser/sync/glue/sync_backend_host.h', 'browser/sync/glue/sync_backend_host_core.cc', diff --git a/components/search_engines.gypi b/components/search_engines.gypi index 1ed485e..d1a34df 100644 --- a/components/search_engines.gypi +++ b/components/search_engines.gypi @@ -26,6 +26,7 @@ 'pref_registry', 'rappor', 'search_engines/prepopulated_engines.gyp:prepopulated_engines', + 'sync_driver', 'url_formatter/url_formatter.gyp:url_formatter', 'webdata_common', ], @@ -47,6 +48,8 @@ 'search_engines/keyword_table.h', 'search_engines/keyword_web_data_service.cc', 'search_engines/keyword_web_data_service.h', + 'search_engines/search_engine_data_type_controller.cc', + 'search_engines/search_engine_data_type_controller.h', 'search_engines/search_engine_type.h', 'search_engines/search_engines_pref_names.cc', 'search_engines/search_engines_pref_names.h', diff --git a/components/search_engines/BUILD.gn b/components/search_engines/BUILD.gn index 1c2638f..478b1e7 100644 --- a/components/search_engines/BUILD.gn +++ b/components/search_engines/BUILD.gn @@ -15,6 +15,8 @@ static_library("search_engines") { "keyword_table.h", "keyword_web_data_service.cc", "keyword_web_data_service.h", + "search_engine_data_type_controller.cc", + "search_engine_data_type_controller.h", "search_engine_type.h", "search_engines_pref_names.cc", "search_engines_pref_names.h", @@ -56,6 +58,7 @@ static_library("search_engines") { "//components/metrics/proto", "//components/pref_registry", "//components/rappor", + "//components/sync_driver", "//components/strings", "//components/url_formatter", "//components/webdata/common", diff --git a/components/search_engines/DEPS b/components/search_engines/DEPS index 14d2fa2..91a1059 100644 --- a/components/search_engines/DEPS +++ b/components/search_engines/DEPS @@ -6,6 +6,7 @@ include_rules = [ "+components/policy/core", "+components/pref_registry", "+components/rappor", + "+components/sync_driver", "+components/url_formatter", "+components/webdata", "+google_apis", diff --git a/chrome/browser/sync/glue/search_engine_data_type_controller.cc b/components/search_engines/search_engine_data_type_controller.cc index d96d3a2..6492095 100644 --- a/chrome/browser/sync/glue/search_engine_data_type_controller.cc +++ b/components/search_engines/search_engine_data_type_controller.cc @@ -1,30 +1,22 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/sync/glue/search_engine_data_type_controller.h" - -#include "base/metrics/histogram.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/search_engines/template_url_service_factory.h" -#include "chrome/browser/sync/profile_sync_service.h" -#include "content/public/browser/browser_thread.h" -#include "sync/api/syncable_service.h" - -using content::BrowserThread; +#include "components/search_engines/search_engine_data_type_controller.h" namespace browser_sync { SearchEngineDataTypeController::SearchEngineDataTypeController( + const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread, const base::Closure& error_callback, sync_driver::SyncClient* sync_client, - Profile* profile) - : UIDataTypeController( - BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), - error_callback, - syncer::SEARCH_ENGINES, - sync_client), - profile_(profile) {} + TemplateURLService* template_url_service) + : UIDataTypeController(ui_thread, + error_callback, + syncer::SEARCH_ENGINES, + sync_client), + ui_thread_(ui_thread), + template_url_service_(template_url_service) {} TemplateURLService::Subscription* SearchEngineDataTypeController::GetSubscriptionForTesting() { @@ -38,18 +30,16 @@ bool SearchEngineDataTypeController::StartModels() { // If the TemplateURLService is loaded, continue with association. We force // a load here to prevent the rest of Sync from waiting on // TemplateURLService's lazy load. - TemplateURLService* turl_service = - TemplateURLServiceFactory::GetForProfile(profile_); - DCHECK(turl_service); - turl_service->Load(); - if (turl_service->loaded()) { + DCHECK(template_url_service_); + template_url_service_->Load(); + if (template_url_service_->loaded()) { return true; // Continue to Associate(). } // Register a callback and continue when the TemplateURLService is loaded. - template_url_subscription_ = turl_service->RegisterOnLoadedCallback( - base::Bind(&SearchEngineDataTypeController::OnTemplateURLServiceLoaded, - this)); + template_url_subscription_ = + template_url_service_->RegisterOnLoadedCallback(base::Bind( + &SearchEngineDataTypeController::OnTemplateURLServiceLoaded, this)); return false; // Don't continue Start. } @@ -59,8 +49,8 @@ void SearchEngineDataTypeController::StopModels() { } void SearchEngineDataTypeController::OnTemplateURLServiceLoaded() { - DCHECK_CURRENTLY_ON(BrowserThread::UI); - DCHECK_EQ(state_, MODEL_STARTING); + DCHECK(ui_thread_->BelongsToCurrentThread()); + DCHECK_EQ(MODEL_STARTING, state_); template_url_subscription_.reset(); OnModelLoaded(); } diff --git a/components/search_engines/search_engine_data_type_controller.h b/components/search_engines/search_engine_data_type_controller.h new file mode 100644 index 0000000..60a9da3 --- /dev/null +++ b/components/search_engines/search_engine_data_type_controller.h @@ -0,0 +1,55 @@ +// Copyright 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef COMPONENTS_SEARCH_ENGINES_SEARCH_ENGINE_DATA_TYPE_CONTROLLER_H__ +#define COMPONENTS_SEARCH_ENGINES_SEARCH_ENGINE_DATA_TYPE_CONTROLLER_H__ + +#include <string> + +#include "base/memory/scoped_ptr.h" +#include "components/search_engines/template_url_service.h" +#include "components/sync_driver/ui_data_type_controller.h" + +class Profile; + +namespace browser_sync { + +// Controller for the SEARCH_ENGINES sync data type. This class tells sync +// how to load the model for this data type, and the superclasses manage +// controlling the rest of the state of the datatype with regards to sync. +class SearchEngineDataTypeController + : public sync_driver::UIDataTypeController { + public: + SearchEngineDataTypeController( + const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread, + const base::Closure& error_callback, + sync_driver::SyncClient* sync_client, + TemplateURLService* template_url_service); + + TemplateURLService::Subscription* GetSubscriptionForTesting(); + + private: + ~SearchEngineDataTypeController() override; + + // FrontendDataTypeController: + bool StartModels() override; + void StopModels() override; + + void OnTemplateURLServiceLoaded(); + + // A reference to the UI thread's task runner. + const scoped_refptr<base::SingleThreadTaskRunner> ui_thread_; + + // A pointer to the template URL service that this data type will use. + TemplateURLService* template_url_service_; + + // A subscription to the OnLoadedCallback so it can be cleared if necessary. + scoped_ptr<TemplateURLService::Subscription> template_url_subscription_; + + DISALLOW_COPY_AND_ASSIGN(SearchEngineDataTypeController); +}; + +} // namespace browser_sync + +#endif // COMPONENTS_SEARCH_ENGINES_SEARCH_ENGINE_DATA_TYPE_CONTROLLER_H__ |