Commit 08c8a4ef authored by Moe Ahmadi's avatar Moe Ahmadi Committed by Commit Bot

[NTP][RQ] Moves SearchProviderObserver to components/

To be used in MostVisitedSites and related services in components/

Change-Id: Icba6dbd470c4bf226726b808c671edba9838a7a2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2500521
Auto-Submit: Moe Ahmadi <mahmadi@chromium.org>
Commit-Queue: Ramya Nagarajan <ramyan@chromium.org>
Reviewed-by: default avatarRamya Nagarajan <ramyan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#821777}
parent 822895bd
...@@ -3760,8 +3760,6 @@ static_library("browser") { ...@@ -3760,8 +3760,6 @@ static_library("browser") {
"search/recipe_tasks/recipe_tasks_service_factory.h", "search/recipe_tasks/recipe_tasks_service_factory.h",
"search/search_engine_base_url_tracker.cc", "search/search_engine_base_url_tracker.cc",
"search/search_engine_base_url_tracker.h", "search/search_engine_base_url_tracker.h",
"search/search_provider_observer.cc",
"search/search_provider_observer.h",
"search/search_suggest/search_suggest_data.cc", "search/search_suggest/search_suggest_data.cc",
"search/search_suggest/search_suggest_data.h", "search/search_suggest/search_suggest_data.h",
"search/search_suggest/search_suggest_loader.h", "search/search_suggest/search_suggest_loader.h",
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/task/post_task.h" #include "base/task/post_task.h"
#include "base/task/thread_pool.h" #include "base/task/thread_pool.h"
#include "base/time/clock.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/image_fetcher/image_decoder_impl.h" #include "chrome/browser/image_fetcher/image_decoder_impl.h"
...@@ -47,7 +48,9 @@ ...@@ -47,7 +48,9 @@
#include "components/ntp_tiles/constants.h" #include "components/ntp_tiles/constants.h"
#include "components/prefs/pref_registry_simple.h" #include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/search/search_provider_observer.h"
#include "components/sync_preferences/pref_service_syncable.h" #include "components/sync_preferences/pref_service_syncable.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_service.h" #include "content/public/browser/notification_service.h"
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/search/background/ntp_background_service.h" #include "chrome/browser/search/background/ntp_background_service.h"
#include "chrome/browser/search/background/ntp_background_service_observer.h" #include "chrome/browser/search/background/ntp_background_service_observer.h"
#include "chrome/browser/search/search_provider_observer.h"
#include "components/history/core/browser/history_types.h" #include "components/history/core/browser/history_types.h"
#include "components/image_fetcher/core/image_fetcher_impl.h" #include "components/image_fetcher/core/image_fetcher_impl.h"
#include "components/keyed_service/core/keyed_service.h" #include "components/keyed_service/core/keyed_service.h"
...@@ -39,11 +38,17 @@ ...@@ -39,11 +38,17 @@
class InstantServiceObserver; class InstantServiceObserver;
class Profile; class Profile;
class SearchProviderObserver;
struct CollectionImage; struct CollectionImage;
struct InstantMostVisitedInfo; struct InstantMostVisitedInfo;
struct NtpTheme; struct NtpTheme;
namespace base {
class Clock;
} // namespace base
namespace content { namespace content {
class BrowserContext;
class RenderProcessHost; class RenderProcessHost;
} // namespace content } // namespace content
......
...@@ -37,7 +37,6 @@ ...@@ -37,7 +37,6 @@
#include "chrome/browser/search/promos/promo_data.h" #include "chrome/browser/search/promos/promo_data.h"
#include "chrome/browser/search/promos/promo_service.h" #include "chrome/browser/search/promos/promo_service.h"
#include "chrome/browser/search/promos/promo_service_factory.h" #include "chrome/browser/search/promos/promo_service_factory.h"
#include "chrome/browser/search/search.h"
#include "chrome/browser/search/search_suggest/search_suggest_data.h" #include "chrome/browser/search/search_suggest/search_suggest_data.h"
#include "chrome/browser/search/search_suggest/search_suggest_service_factory.h" #include "chrome/browser/search/search_suggest/search_suggest_service_factory.h"
#include "chrome/browser/search_engines/template_url_service_factory.h" #include "chrome/browser/search_engines/template_url_service_factory.h"
...@@ -57,6 +56,7 @@ ...@@ -57,6 +56,7 @@
#include "components/omnibox/common/omnibox_features.h" #include "components/omnibox/common/omnibox_features.h"
#include "components/prefs/pref_registry_simple.h" #include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/search/search.h"
#include "components/search_engines/search_terms_data.h" #include "components/search_engines/search_terms_data.h"
#include "components/search_engines/template_url_service.h" #include "components/search_engines/template_url_service.h"
#include "components/search_engines/template_url_service_observer.h" #include "components/search_engines/template_url_service_observer.h"
......
...@@ -239,19 +239,6 @@ bool DefaultSearchProviderIsGoogle(Profile* profile) { ...@@ -239,19 +239,6 @@ bool DefaultSearchProviderIsGoogle(Profile* profile) {
TemplateURLServiceFactory::GetForProfile(profile)); TemplateURLServiceFactory::GetForProfile(profile));
} }
bool DefaultSearchProviderIsGoogle(
const TemplateURLService* template_url_service) {
if (!template_url_service)
return false;
const TemplateURL* default_provider =
template_url_service->GetDefaultSearchProvider();
if (!default_provider)
return false;
return default_provider->GetEngineType(
template_url_service->search_terms_data()) ==
SearchEngineType::SEARCH_ENGINE_GOOGLE;
}
bool IsNTPOrRelatedURL(const GURL& url, Profile* profile) { bool IsNTPOrRelatedURL(const GURL& url, Profile* profile) {
if (!url.is_valid()) if (!url.is_valid())
return false; return false;
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
class GURL; class GURL;
class Profile; class Profile;
class TemplateURLService;
namespace content { namespace content {
class BrowserContext; class BrowserContext;
...@@ -21,8 +20,6 @@ namespace search { ...@@ -21,8 +20,6 @@ namespace search {
// Returns whether Google is selected as the default search engine. // Returns whether Google is selected as the default search engine.
bool DefaultSearchProviderIsGoogle(Profile* profile); bool DefaultSearchProviderIsGoogle(Profile* profile);
bool DefaultSearchProviderIsGoogle(
const TemplateURLService* template_url_service);
// Returns true if |url| corresponds to a New Tab page or its service worker. // Returns true if |url| corresponds to a New Tab page or its service worker.
bool IsNTPOrRelatedURL(const GURL& url, Profile* profile); bool IsNTPOrRelatedURL(const GURL& url, Profile* profile);
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "chrome/grit/new_tab_page_resources_map.h" #include "chrome/grit/new_tab_page_resources_map.h"
#include "components/favicon_base/favicon_url_parser.h" #include "components/favicon_base/favicon_url_parser.h"
#include "components/google/core/common/google_util.h" #include "components/google/core/common/google_util.h"
#include "components/search_engines/template_url_service.h"
#include "components/strings/grit/components_strings.h" #include "components/strings/grit/components_strings.h"
#include "content/public/browser/navigation_handle.h" #include "content/public/browser/navigation_handle.h"
#include "content/public/browser/url_data_source.h" #include "content/public/browser/url_data_source.h"
......
...@@ -6,6 +6,8 @@ static_library("search") { ...@@ -6,6 +6,8 @@ static_library("search") {
sources = [ sources = [
"search.cc", "search.cc",
"search.h", "search.h",
"search_provider_observer.cc",
"search_provider_observer.h",
] ]
deps = [ deps = [
......
...@@ -5,6 +5,10 @@ ...@@ -5,6 +5,10 @@
#include "components/search/search.h" #include "components/search/search.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "components/search_engines/search_engine_type.h"
#include "components/search_engines/search_terms_data.h"
#include "components/search_engines/template_url.h"
#include "components/search_engines/template_url_service.h"
namespace search { namespace search {
...@@ -16,4 +20,17 @@ bool IsInstantExtendedAPIEnabled() { ...@@ -16,4 +20,17 @@ bool IsInstantExtendedAPIEnabled() {
#endif #endif
} }
bool DefaultSearchProviderIsGoogle(
const TemplateURLService* template_url_service) {
if (!template_url_service)
return false;
const TemplateURL* default_provider =
template_url_service->GetDefaultSearchProvider();
if (!default_provider)
return false;
return default_provider->GetEngineType(
template_url_service->search_terms_data()) ==
SearchEngineType::SEARCH_ENGINE_GOOGLE;
}
} // namespace search } // namespace search
...@@ -5,12 +5,18 @@ ...@@ -5,12 +5,18 @@
#ifndef COMPONENTS_SEARCH_SEARCH_H_ #ifndef COMPONENTS_SEARCH_SEARCH_H_
#define COMPONENTS_SEARCH_SEARCH_H_ #define COMPONENTS_SEARCH_SEARCH_H_
class TemplateURLService;
namespace search { namespace search {
// Returns whether the Instant Extended API is enabled. This is always true on // Returns whether the Instant Extended API is enabled. This is always true on
// desktop and false on mobile. // desktop and false on mobile.
bool IsInstantExtendedAPIEnabled(); bool IsInstantExtendedAPIEnabled();
// Returns whether Google is selected as the default search engine.
bool DefaultSearchProviderIsGoogle(
const TemplateURLService* template_url_service);
} // namespace search } // namespace search
#endif // COMPONENTS_SEARCH_SEARCH_H_ #endif // COMPONENTS_SEARCH_SEARCH_H_
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/search/search_provider_observer.h" #include "components/search/search_provider_observer.h"
#include "components/search/search.h"
SearchProviderObserver::SearchProviderObserver(TemplateURLService* service, SearchProviderObserver::SearchProviderObserver(TemplateURLService* service,
base::RepeatingClosure callback) base::RepeatingClosure callback)
......
...@@ -2,10 +2,9 @@ ...@@ -2,10 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROME_BROWSER_SEARCH_SEARCH_PROVIDER_OBSERVER_H_ #ifndef COMPONENTS_SEARCH_SEARCH_PROVIDER_OBSERVER_H_
#define CHROME_BROWSER_SEARCH_SEARCH_PROVIDER_OBSERVER_H_ #define COMPONENTS_SEARCH_SEARCH_PROVIDER_OBSERVER_H_
#include "chrome/browser/search/search.h"
#include "components/search_engines/template_url_service.h" #include "components/search_engines/template_url_service.h"
#include "components/search_engines/template_url_service_observer.h" #include "components/search_engines/template_url_service_observer.h"
...@@ -20,6 +19,7 @@ class SearchProviderObserver : public TemplateURLServiceObserver { ...@@ -20,6 +19,7 @@ class SearchProviderObserver : public TemplateURLServiceObserver {
~SearchProviderObserver() override; ~SearchProviderObserver() override;
bool is_google() { return is_google_; } bool is_google() { return is_google_; }
TemplateURLService* template_url_service() { return service_; }
private: private:
// TemplateURLServiceObserver: // TemplateURLServiceObserver:
...@@ -31,4 +31,4 @@ class SearchProviderObserver : public TemplateURLServiceObserver { ...@@ -31,4 +31,4 @@ class SearchProviderObserver : public TemplateURLServiceObserver {
base::RepeatingClosure callback_; base::RepeatingClosure callback_;
}; };
#endif // CHROME_BROWSER_SEARCH_SEARCH_PROVIDER_OBSERVER_H_ #endif // COMPONENTS_SEARCH_SEARCH_PROVIDER_OBSERVER_H_
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