summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsdefresne <sdefresne@chromium.org>2015-08-03 07:18:13 -0700
committerCommit bot <commit-bot@chromium.org>2015-08-03 14:18:41 +0000
commit51bbec7be7014d4d75d39c1a5c27b1ba9ddc3dcd (patch)
tree912625ef3699b6c080aa3cca3340966298130333
parente52e8da071b5d27eead353a38ddbc822af9ef0fc (diff)
downloadchromium_src-51bbec7be7014d4d75d39c1a5c27b1ba9ddc3dcd.zip
chromium_src-51bbec7be7014d4d75d39c1a5c27b1ba9ddc3dcd.tar.gz
chromium_src-51bbec7be7014d4d75d39c1a5c27b1ba9ddc3dcd.tar.bz2
Partially componentize //chrome/browser/search/search.{h,cc}
Move functions from //chrome/browser/search/search.{h,cc} to the search component //components/search/search.{h,cc} so that they can be shared with iOS. Move all the code in those two files (and supporting unittests) from the "chrome" to the "search" namespace. Move unittests that do not depends on non-componentized functions into the search component. Implements GetSearchTerms() on iOS that uses a web::WebState* instead of content::WebContents and simplify the code to remove unsupported features. Directly use //components/search on iOS instead of the SearchProvider when possible. BUG=514239 TBR=sky,droger,benwells Review URL: https://codereview.chromium.org/1260033003 Cr-Commit-Position: refs/heads/master@{#341525}
-rw-r--r--chrome/browser/android/omnibox/autocomplete_controller_android.cc4
-rw-r--r--chrome/browser/android/tab_android.cc4
-rw-r--r--chrome/browser/chrome_content_browser_client.cc16
-rw-r--r--chrome/browser/extensions/api/sessions/sessions_api.cc2
-rw-r--r--chrome/browser/extensions/extension_url_rewrite_browsertest.cc2
-rw-r--r--chrome/browser/favicon/favicon_utils.cc2
-rw-r--r--chrome/browser/policy/policy_browsertest.cc3
-rw-r--r--chrome/browser/prerender/prerender_manager.cc3
-rw-r--r--chrome/browser/renderer_context_menu/render_view_context_menu.cc2
-rw-r--r--chrome/browser/search/instant_service.cc9
-rw-r--r--chrome/browser/search/instant_service_factory.cc7
-rw-r--r--chrome/browser/search/instant_unittest_base.cc3
-rw-r--r--chrome/browser/search/local_ntp_source.cc2
-rw-r--r--chrome/browser/search/search.cc126
-rw-r--r--chrome/browser/search/search.h45
-rw-r--r--chrome/browser/search/search_android_unittest.cc110
-rw-r--r--chrome/browser/search/search_unittest.cc173
-rw-r--r--chrome/browser/search_engines/ui_thread_search_terms_data.cc16
-rw-r--r--chrome/browser/sessions/session_restore.cc2
-rw-r--r--chrome/browser/thumbnails/thumbnail_service_impl.cc2
-rw-r--r--chrome/browser/ui/app_list/search/common/webservice_search_provider.cc5
-rw-r--r--chrome/browser/ui/bookmarks/bookmark_tab_helper.cc2
-rw-r--r--chrome/browser/ui/bookmarks/bookmark_utils.cc6
-rw-r--r--chrome/browser/ui/browser.cc10
-rw-r--r--chrome/browser/ui/browser_browsertest.cc2
-rw-r--r--chrome/browser/ui/browser_instant_controller.cc8
-rw-r--r--chrome/browser/ui/browser_instant_controller_unittest.cc18
-rw-r--r--chrome/browser/ui/extensions/extension_install_ui_default.cc2
-rw-r--r--chrome/browser/ui/omnibox/chrome_omnibox_client.cc12
-rw-r--r--chrome/browser/ui/search/instant_controller.cc4
-rw-r--r--chrome/browser/ui/search/instant_extended_interactive_uitest.cc7
-rw-r--r--chrome/browser/ui/search/instant_extended_manual_interactive_uitest.cc3
-rw-r--r--chrome/browser/ui/search/instant_search_prerenderer.cc5
-rw-r--r--chrome/browser/ui/search/instant_search_prerenderer_unittest.cc19
-rw-r--r--chrome/browser/ui/search/local_ntp_browsertest.cc2
-rw-r--r--chrome/browser/ui/search/new_tab_page_interceptor_service.cc8
-rw-r--r--chrome/browser/ui/search/search_ipc_router.cc11
-rw-r--r--chrome/browser/ui/search/search_ipc_router_policy_impl.cc24
-rw-r--r--chrome/browser/ui/search/search_ipc_router_unittest.cc2
-rw-r--r--chrome/browser/ui/search/search_model.cc8
-rw-r--r--chrome/browser/ui/search/search_tab_helper.cc32
-rw-r--r--chrome/browser/ui/search/search_tab_helper_unittest.cc2
-rw-r--r--chrome/browser/ui/singleton_tabs.cc3
-rw-r--r--chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.cc2
-rw-r--r--chrome/browser/ui/toolbar/toolbar_model_impl.cc4
-rw-r--r--chrome/browser/ui/toolbar/toolbar_model_impl.h2
-rw-r--r--chrome/browser/ui/toolbar/toolbar_model_unittest.cc17
-rw-r--r--chrome/browser/ui/views/omnibox/omnibox_view_views.cc3
-rw-r--r--chrome/browser/ui/views/tabs/browser_tab_strip_controller.cc2
-rw-r--r--chrome/browser/ui/webui/history_ui.cc4
-rw-r--r--chrome/chrome_tests_unit.gypi1
-rw-r--r--chrome/common/chrome_switches.cc7
-rw-r--r--chrome/common/chrome_switches.h2
-rw-r--r--chrome/renderer/searchbox/search_bouncer.h2
-rw-r--r--components/omnibox/browser/omnibox_field_trial.cc2
-rw-r--r--components/omnibox/browser/omnibox_field_trial_unittest.cc2
-rw-r--r--components/omnibox/browser/search_provider.cc2
-rw-r--r--components/search.gypi5
-rw-r--r--components/search/BUILD.gn3
-rw-r--r--components/search/DEPS2
-rw-r--r--components/search/search.cc114
-rw-r--r--components/search/search.h57
-rw-r--r--components/search/search_android_unittest.cc87
-rw-r--r--components/search/search_switches.cc11
-rw-r--r--components/search/search_switches.h5
-rw-r--r--components/search/search_unittest.cc110
-rw-r--r--extensions/browser/guest_view/web_view/web_view_guest.cc2
-rw-r--r--ios/chrome/browser/search/search_util.cc69
-rw-r--r--ios/chrome/browser/search/search_util.h42
-rw-r--r--ios/chrome/browser/search_engines/ui_thread_search_terms_data.cc24
-rw-r--r--ios/chrome/ios_chrome.gyp2
-rw-r--r--ios/ios_tests.gyp2
-rw-r--r--ios/provider/ios_provider_chrome.gyp1
-rw-r--r--ios/public/provider/chrome/browser/chrome_browser_provider.cc4
-rw-r--r--ios/public/provider/chrome/browser/chrome_browser_provider.h3
-rw-r--r--ios/public/provider/chrome/browser/search_provider.h50
-rw-r--r--ios/public/test/fake_search_provider.cc31
-rw-r--r--ios/public/test/fake_search_provider.h29
-rw-r--r--ios/public/test/test_chrome_browser_provider.h3
-rw-r--r--ios/public/test/test_chrome_browser_provider.mm8
80 files changed, 707 insertions, 737 deletions
diff --git a/chrome/browser/android/omnibox/autocomplete_controller_android.cc b/chrome/browser/android/omnibox/autocomplete_controller_android.cc
index 8606f26..098eaca 100644
--- a/chrome/browser/android/omnibox/autocomplete_controller_android.cc
+++ b/chrome/browser/android/omnibox/autocomplete_controller_android.cc
@@ -337,8 +337,8 @@ void AutocompleteControllerAndroid::OnResultChanged(
const AutocompleteResult::const_iterator default_match(
result.default_match());
if ((default_match != result.end()) && default_match_changed &&
- chrome::IsInstantExtendedAPIEnabled() &&
- chrome::ShouldPrefetchSearchResults()) {
+ search::IsInstantExtendedAPIEnabled() &&
+ search::ShouldPrefetchSearchResults()) {
InstantSuggestion prefetch_suggestion;
// If the default match should be prefetched, do that.
if (SearchProvider::ShouldPrefetch(*default_match)) {
diff --git a/chrome/browser/android/tab_android.cc b/chrome/browser/android/tab_android.cc
index 77cbeec..84184b7 100644
--- a/chrome/browser/android/tab_android.cc
+++ b/chrome/browser/android/tab_android.cc
@@ -552,7 +552,7 @@ TabAndroid::TabLoadStatus TabAndroid::LoadUrl(JNIEnv* env,
InstantSearchPrerenderer::GetForProfile(GetProfile());
if (prerenderer) {
const base::string16& search_terms =
- chrome::ExtractSearchTermsFromURL(GetProfile(), gurl);
+ search::ExtractSearchTermsFromURL(GetProfile(), gurl);
if (!search_terms.empty() &&
prerenderer->CanCommitQuery(web_contents_.get(), search_terms)) {
EmbeddedSearchRequestParams request_params(gurl);
@@ -603,7 +603,7 @@ TabAndroid::TabLoadStatus TabAndroid::LoadUrl(JNIEnv* env,
static_cast<blink::WebReferrerPolicy>(referrer_policy));
}
const base::string16 search_terms =
- chrome::ExtractSearchTermsFromURL(GetProfile(), gurl);
+ search::ExtractSearchTermsFromURL(GetProfile(), gurl);
SearchTabHelper* search_tab_helper =
SearchTabHelper::FromWebContents(web_contents_.get());
if (!search_terms.empty() && search_tab_helper &&
diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc
index 110221b..1e4392e 100644
--- a/chrome/browser/chrome_content_browser_client.cc
+++ b/chrome/browser/chrome_content_browser_client.cc
@@ -901,8 +901,8 @@ GURL ChromeContentBrowserClient::GetEffectiveURL(
// If the input |url| should be assigned to the Instant renderer, make its
// effective URL distinct from other URLs on the search provider's domain.
- if (chrome::ShouldAssignURLToInstantRenderer(url, profile))
- return chrome::GetEffectiveURLForInstant(url, profile);
+ if (search::ShouldAssignURLToInstantRenderer(url, profile))
+ return search::GetEffectiveURLForInstant(url, profile);
#if defined(ENABLE_EXTENSIONS)
return ChromeContentBrowserClientExtensionsPart::GetEffectiveURL(
@@ -923,7 +923,7 @@ bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
if (!profile)
return false;
- if (chrome::ShouldUseProcessPerSiteForInstantURL(effective_url, profile))
+ if (search::ShouldUseProcessPerSiteForInstantURL(effective_url, profile))
return true;
#if defined(ENABLE_EXTENSIONS)
@@ -1034,7 +1034,7 @@ bool ChromeContentBrowserClient::IsSuitableHost(
bool is_instant_process = instant_service->IsInstantProcess(
process_host->GetID());
bool should_be_in_instant_process =
- chrome::ShouldAssignURLToInstantRenderer(site_url, profile);
+ search::ShouldAssignURLToInstantRenderer(site_url, profile);
if (is_instant_process || should_be_in_instant_process)
return is_instant_process && should_be_in_instant_process;
}
@@ -1091,8 +1091,8 @@ void ChromeContentBrowserClient::SiteInstanceGotProcess(
// Remember the ID of the Instant process to signal the renderer process
// on startup in |AppendExtraCommandLineSwitches| below.
- if (chrome::ShouldAssignURLToInstantRenderer(
- site_instance->GetSiteURL(), profile)) {
+ if (search::ShouldAssignURLToInstantRenderer(site_instance->GetSiteURL(),
+ profile)) {
InstantService* instant_service =
InstantServiceFactory::GetForProfile(profile);
if (instant_service)
@@ -2179,8 +2179,8 @@ void ChromeContentBrowserClient::BrowserURLHandlerCreated(
BrowserURLHandler::null_handler());
#else
// Handler to rewrite chrome://newtab for InstantExtended.
- handler->AddHandlerPair(&chrome::HandleNewTabURLRewrite,
- &chrome::HandleNewTabURLReverseRewrite);
+ handler->AddHandlerPair(&search::HandleNewTabURLRewrite,
+ &search::HandleNewTabURLReverseRewrite);
#endif
// chrome: & friends.
diff --git a/chrome/browser/extensions/api/sessions/sessions_api.cc b/chrome/browser/extensions/api/sessions/sessions_api.cc
index f98aca0..35131e3 100644
--- a/chrome/browser/extensions/api/sessions/sessions_api.cc
+++ b/chrome/browser/extensions/api/sessions/sessions_api.cc
@@ -267,7 +267,7 @@ scoped_ptr<windows::Window> SessionsGetDevicesFunction::CreateWindowModel(
continue;
const sessions::SerializedNavigationEntry& current_navigation =
tab->navigations.at(tab->normalized_navigation_index());
- if (chrome::IsNTPURL(current_navigation.virtual_url(), GetProfile())) {
+ if (search::IsNTPURL(current_navigation.virtual_url(), GetProfile())) {
continue;
}
tabs_in_window.push_back(tab);
diff --git a/chrome/browser/extensions/extension_url_rewrite_browsertest.cc b/chrome/browser/extensions/extension_url_rewrite_browsertest.cc
index 2a08477..85b9db6 100644
--- a/chrome/browser/extensions/extension_url_rewrite_browsertest.cc
+++ b/chrome/browser/extensions/extension_url_rewrite_browsertest.cc
@@ -80,7 +80,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionURLRewriteBrowserTest, NewTabPageURL) {
GURL url(chrome::kChromeUINewTabURL);
TestURLNotShown(url);
// Check that the actual URL corresponds to the new tab URL.
- EXPECT_TRUE(chrome::IsNTPURL(GetNavigationEntry()->GetURL(), profile()));
+ EXPECT_TRUE(search::IsNTPURL(GetNavigationEntry()->GetURL(), profile()));
}
IN_PROC_BROWSER_TEST_F(ExtensionURLRewriteBrowserTest, NewTabPageURLOverride) {
diff --git a/chrome/browser/favicon/favicon_utils.cc b/chrome/browser/favicon/favicon_utils.cc
index 7be1942..54b4d33 100644
--- a/chrome/browser/favicon/favicon_utils.cc
+++ b/chrome/browser/favicon/favicon_utils.cc
@@ -45,7 +45,7 @@ bool ShouldDisplayFavicon(content::WebContents* web_contents) {
}
// No favicon on Instant New Tab Pages.
- if (chrome::IsInstantNTP(web_contents))
+ if (search::IsInstantNTP(web_contents))
return false;
return true;
diff --git a/chrome/browser/policy/policy_browsertest.cc b/chrome/browser/policy/policy_browsertest.cc
index fda8593..0ab38fc 100644
--- a/chrome/browser/policy/policy_browsertest.cc
+++ b/chrome/browser/policy/policy_browsertest.cc
@@ -98,6 +98,7 @@
#include "components/policy/core/common/policy_pref_names.h"
#include "components/policy/core/common/policy_service.h"
#include "components/policy/core/common/policy_service_impl.h"
+#include "components/search/search.h"
#include "components/search_engines/template_url.h"
#include "components/search_engines/template_url_service.h"
#include "components/translate/core/browser/language_state.h"
@@ -1180,7 +1181,7 @@ IN_PROC_BROWSER_TEST_F(PolicyTest, ForceSafeSearch) {
IN_PROC_BROWSER_TEST_F(PolicyTest, ReplaceSearchTerms) {
MakeRequestFail make_request_fail("search.example");
- chrome::EnableQueryExtractionForTesting();
+ search::EnableQueryExtractionForTesting();
// Verifies that a default search is made using the provider configured via
// policy. Also checks that default search can be completely disabled.
diff --git a/chrome/browser/prerender/prerender_manager.cc b/chrome/browser/prerender/prerender_manager.cc
index f06bb5b..5834940 100644
--- a/chrome/browser/prerender/prerender_manager.cc
+++ b/chrome/browser/prerender/prerender_manager.cc
@@ -39,6 +39,7 @@
#include "chrome/browser/ui/tab_contents/core_tab_helper_delegate.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/prerender_types.h"
+#include "components/search/search.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/devtools_agent_host.h"
#include "content/public/browser/navigation_controller.h"
@@ -301,7 +302,7 @@ PrerenderHandle* PrerenderManager::AddPrerenderForInstant(
const GURL& url,
content::SessionStorageNamespace* session_storage_namespace,
const gfx::Size& size) {
- DCHECK(chrome::ShouldPrefetchSearchResults());
+ DCHECK(search::ShouldPrefetchSearchResults());
return AddPrerender(ORIGIN_INSTANT, url, content::Referrer(), size,
session_storage_namespace);
}
diff --git a/chrome/browser/renderer_context_menu/render_view_context_menu.cc b/chrome/browser/renderer_context_menu/render_view_context_menu.cc
index bba338c..f079c80 100644
--- a/chrome/browser/renderer_context_menu/render_view_context_menu.cc
+++ b/chrome/browser/renderer_context_menu/render_view_context_menu.cc
@@ -1167,7 +1167,7 @@ bool RenderViewContextMenu::IsCommandIdEnabled(int id) const {
translate::TranslateDownloadManager::IsSupportedLanguage(
target_lang) &&
// Disable on the Instant Extended NTP.
- !chrome::IsInstantNTP(embedder_web_contents_);
+ !search::IsInstantNTP(embedder_web_contents_);
}
case IDC_CONTENT_CONTEXT_OPENLINKNEWTAB:
diff --git a/chrome/browser/search/instant_service.cc b/chrome/browser/search/instant_service.cc
index 5f668ef..532c30c 100644
--- a/chrome/browser/search/instant_service.cc
+++ b/chrome/browser/search/instant_service.cc
@@ -28,6 +28,7 @@
#include "components/favicon/core/large_icon_service.h"
#include "components/history/core/browser/top_sites.h"
#include "components/keyed_service/core/service_access_type.h"
+#include "components/search/search.h"
#include "components/search_engines/template_url_service.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_service.h"
@@ -52,7 +53,7 @@
InstantService::InstantService(Profile* profile)
: profile_(profile),
template_url_service_(TemplateURLServiceFactory::GetForProfile(profile_)),
- omnibox_start_margin_(chrome::kDisableStartMargin),
+ omnibox_start_margin_(search::kDisableStartMargin),
weak_ptr_factory_(this) {
// The initialization below depends on a typical set of browser threads. Skip
// it if we are running in a unit test without the full suite.
@@ -245,7 +246,7 @@ void InstantService::Observe(int type,
void InstantService::SendSearchURLsToRenderer(content::RenderProcessHost* rph) {
rph->Send(new ChromeViewMsg_SetSearchURLs(
- chrome::GetSearchURLs(profile_), chrome::GetNewTabPageURL(profile_)));
+ search::GetSearchURLs(profile_), search::GetNewTabPageURL(profile_)));
}
void InstantService::OnOmniboxStartMarginChanged(int start_margin) {
@@ -461,10 +462,10 @@ void InstantService::TopSitesChanged(history::TopSites* top_sites,
}
void InstantService::ResetInstantSearchPrerenderer() {
- if (!chrome::ShouldPrefetchSearchResults())
+ if (!search::ShouldPrefetchSearchResults())
return;
- GURL url(chrome::GetSearchResultPrefetchBaseURL(profile_));
+ GURL url(search::GetSearchResultPrefetchBaseURL(profile_));
instant_prerenderer_.reset(
url.is_valid() ? new InstantSearchPrerenderer(profile_, url) : NULL);
}
diff --git a/chrome/browser/search/instant_service_factory.cc b/chrome/browser/search/instant_service_factory.cc
index e20d92e..fc2160b 100644
--- a/chrome/browser/search/instant_service_factory.cc
+++ b/chrome/browser/search/instant_service_factory.cc
@@ -15,7 +15,7 @@
// static
InstantService* InstantServiceFactory::GetForProfile(Profile* profile) {
- if (!chrome::IsInstantExtendedAPIEnabled())
+ if (!search::IsInstantExtendedAPIEnabled())
return NULL;
return static_cast<InstantService*>(
@@ -48,6 +48,7 @@ content::BrowserContext* InstantServiceFactory::GetBrowserContextToUse(
KeyedService* InstantServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* profile) const {
- return chrome::IsInstantExtendedAPIEnabled() ?
- new InstantService(static_cast<Profile*>(profile)) : NULL;
+ return search::IsInstantExtendedAPIEnabled()
+ ? new InstantService(static_cast<Profile*>(profile))
+ : NULL;
}
diff --git a/chrome/browser/search/instant_unittest_base.cc b/chrome/browser/search/instant_unittest_base.cc
index 4e8002a..93a8b24 100644
--- a/chrome/browser/search/instant_unittest_base.cc
+++ b/chrome/browser/search/instant_unittest_base.cc
@@ -18,6 +18,7 @@
#include "chrome/test/base/ui_test_utils.h"
#include "components/google/core/browser/google_pref_names.h"
#include "components/google/core/browser/google_url_tracker.h"
+#include "components/search/search.h"
#include "components/search_engines/template_url.h"
#include "components/search_engines/template_url_service.h"
#include "components/variations/entropy_provider.h"
@@ -31,7 +32,7 @@ InstantUnitTestBase::~InstantUnitTestBase() {
}
void InstantUnitTestBase::SetUp() {
- chrome::EnableQueryExtractionForTesting();
+ search::EnableQueryExtractionForTesting();
SetUpHelper();
}
diff --git a/chrome/browser/search/local_ntp_source.cc b/chrome/browser/search/local_ntp_source.cc
index fbc48d5..d760af0 100644
--- a/chrome/browser/search/local_ntp_source.cc
+++ b/chrome/browser/search/local_ntp_source.cc
@@ -141,7 +141,7 @@ scoped_ptr<base::DictionaryValue> GetTranslatedStrings(bool is_google) {
std::string GetConfigData(Profile* profile) {
base::DictionaryValue config_data;
bool is_google = DefaultSearchProviderIsGoogle(profile) &&
- chrome::ShouldShowGoogleLocalNTP();
+ search::ShouldShowGoogleLocalNTP();
config_data.Set("translatedStrings",
GetTranslatedStrings(is_google).release());
config_data.SetBoolean("isGooglePage", is_google);
diff --git a/chrome/browser/search/search.cc b/chrome/browser/search/search.cc
index 13a52f6..02002d7 100644
--- a/chrome/browser/search/search.cc
+++ b/chrome/browser/search/search.cc
@@ -41,23 +41,14 @@
#include "chrome/browser/supervised_user/supervised_user_url_filter.h"
#endif
-namespace chrome {
+namespace search {
namespace {
const char kPrefetchSearchResultsOnSRP[] = "prefetch_results_srp";
-const char kAllowPrefetchNonDefaultMatch[] = "allow_prefetch_non_default_match";
const char kPrerenderInstantUrlOnOmniboxFocus[] =
"prerender_instant_url_on_omnibox_focus";
-#if defined(OS_ANDROID)
-const char kPrefetchSearchResultsFlagName[] = "prefetch_results";
-
-// Controls whether to reuse prerendered Instant Search base page to commit any
-// search query.
-const char kReuseInstantSearchBasePage[] = "reuse_instant_search_base_page";
-#endif
-
// Controls whether to use the alternate Instant search base URL. This allows
// experimentation of Instant search.
const char kUseAltInstantURL[] = "use_alternate_instant_url";
@@ -65,9 +56,6 @@ const char kUseSearchPathForInstant[] = "use_search_path_for_instant";
const char kAltInstantURLPath[] = "search";
const char kAltInstantURLQueryParams[] = "&qbp=1";
-#if !defined(OS_IOS) && !defined(OS_ANDROID)
-const char kEnableQueryExtractionFlagName[] = "query_extraction";
-#endif
const char kShouldShowGoogleLocalNTPFlagName[] = "google_local_ntp";
// Status of the New Tab URL for the default Search provider. NOTE: Used in a
@@ -152,33 +140,20 @@ bool MatchesAnySearchURL(const GURL& url,
const SearchTermsData& search_terms_data) {
GURL search_url = TemplateURLRefToGURL(template_url->url_ref(),
search_terms_data, false, false);
- if (search_url.is_valid() &&
- search::MatchesOriginAndPath(url, search_url))
+ if (search_url.is_valid() && MatchesOriginAndPath(url, search_url))
return true;
// "URLCount() - 1" because we already tested url_ref above.
for (size_t i = 0; i < template_url->URLCount() - 1; ++i) {
TemplateURLRef ref(template_url, i);
search_url = TemplateURLRefToGURL(ref, search_terms_data, false, false);
- if (search_url.is_valid() &&
- search::MatchesOriginAndPath(url, search_url))
+ if (search_url.is_valid() && MatchesOriginAndPath(url, search_url))
return true;
}
return false;
}
-
-
-// |url| should either have a secure scheme or have a non-HTTPS base URL that
-// the user specified using --google-base-url. (This allows testers to use
-// --google-base-url to point at non-HTTPS servers, which eases testing.)
-bool IsSuitableURLForInstant(const GURL& url, const TemplateURL* template_url) {
- return template_url->HasSearchTermsReplacementKey(url) &&
- (url.SchemeIsCryptographic() ||
- google_util::StartsWithCommandLineGoogleBaseURL(url));
-}
-
// Returns true if |url| can be used as an Instant URL for |profile|.
bool IsInstantURL(const GURL& url, Profile* profile) {
if (!IsInstantExtendedAPIEnabled())
@@ -188,8 +163,7 @@ bool IsInstantURL(const GURL& url, Profile* profile) {
return false;
const GURL new_tab_url(GetNewTabPageURL(profile));
- if (new_tab_url.is_valid() &&
- search::MatchesOriginAndPath(url, new_tab_url))
+ if (new_tab_url.is_valid() && MatchesOriginAndPath(url, new_tab_url))
return true;
TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile);
@@ -206,7 +180,7 @@ bool IsInstantURL(const GURL& url, Profile* profile) {
if (!instant_url.is_valid())
return false;
- if (search::MatchesOriginAndPath(url, instant_url))
+ if (MatchesOriginAndPath(url, instant_url))
return true;
return IsQueryExtractionEnabled() &&
@@ -311,39 +285,6 @@ struct NewTabURLDetails {
} // namespace
-// Negative start-margin values prevent the "es_sm" parameter from being used.
-const int kDisableStartMargin = -1;
-
-std::string InstantExtendedEnabledParam(bool for_search) {
- if (for_search && !chrome::IsQueryExtractionEnabled())
- return std::string();
- return std::string(google_util::kInstantExtendedAPIParam) + "=" +
- base::Uint64ToString(EmbeddedSearchPageVersion()) + "&";
-}
-
-std::string ForceInstantResultsParam(bool for_prerender) {
- return (for_prerender || !IsInstantExtendedAPIEnabled()) ?
- "ion=1&" : std::string();
-}
-
-bool IsQueryExtractionEnabled() {
-#if defined(OS_IOS) || defined(OS_ANDROID)
- return true;
-#else
- if (!IsInstantExtendedAPIEnabled())
- return false;
-
- const base::CommandLine* command_line =
- base::CommandLine::ForCurrentProcess();
- if (command_line->HasSwitch(switches::kEnableQueryExtraction))
- return true;
-
- FieldTrialFlags flags;
- return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault(
- kEnableQueryExtractionFlagName, false, flags);
-#endif // defined(OS_IOS) || defined(OS_ANDROID)
-}
-
base::string16 ExtractSearchTermsFromURL(Profile* profile, const GURL& url) {
if (url.is_valid() && url == GetSearchResultPrefetchBaseURL(profile)) {
// InstantSearchPrerenderer has the search query for the Instant search base
@@ -460,7 +401,7 @@ bool NavEntryIsInstantNTP(const content::WebContents* contents,
GURL new_tab_url(GetNewTabPageURL(profile));
return new_tab_url.is_valid() &&
- search::MatchesOriginAndPath(entry->GetURL(), new_tab_url);
+ MatchesOriginAndPath(entry->GetURL(), new_tab_url);
}
bool IsSuggestPrefEnabled(Profile* profile) {
@@ -532,33 +473,6 @@ GURL GetSearchResultPrefetchBaseURL(Profile* profile) {
return ShouldPrefetchSearchResults() ? GetInstantURL(profile, true) : GURL();
}
-bool ShouldPrefetchSearchResults() {
- if (!IsInstantExtendedAPIEnabled())
- return false;
-
-#if defined(OS_ANDROID)
- if (base::CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kPrefetchSearchResults)) {
- return true;
- }
-
- FieldTrialFlags flags;
- return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault(
- kPrefetchSearchResultsFlagName, false, flags);
-#else
- return true;
-#endif
-}
-
-bool ShouldAllowPrefetchNonDefaultMatch() {
- if (!ShouldPrefetchSearchResults())
- return false;
-
- FieldTrialFlags flags;
- return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault(
- kAllowPrefetchNonDefaultMatch, false, flags);
-}
-
bool ShouldPrerenderInstantUrlOnOmniboxFocus() {
if (!ShouldPrefetchSearchResults())
return false;
@@ -568,19 +482,6 @@ bool ShouldPrerenderInstantUrlOnOmniboxFocus() {
kPrerenderInstantUrlOnOmniboxFocus, false, flags);
}
-bool ShouldReuseInstantSearchBasePage() {
- if (!ShouldPrefetchSearchResults())
- return false;
-
-#if defined(OS_ANDROID)
- FieldTrialFlags flags;
- return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault(
- kReuseInstantSearchBasePage, false, flags);
-#else
- return true;
-#endif
-}
-
GURL GetLocalInstantURL(Profile* profile) {
return GURL(chrome::kChromeSearchLocalNtpUrl);
}
@@ -611,7 +512,7 @@ GURL GetEffectiveURLForInstant(const GURL& url, Profile* profile) {
std::string remote_ntp_host(chrome::kChromeSearchRemoteNtpHost);
NewTabURLDetails details = NewTabURLDetails::ForProfile(profile);
if (details.state == NEW_TAB_URL_VALID &&
- search::MatchesOriginAndPath(url, details.url)) {
+ MatchesOriginAndPath(url, details.url)) {
replacements.SetHost(remote_ntp_host.c_str(),
url::Component(0, remote_ntp_host.length()));
}
@@ -650,15 +551,13 @@ bool HandleNewTabURLReverseRewrite(GURL* url,
if (profile && profile->IsOffTheRecord())
return false;
- if (search::MatchesOriginAndPath(
- GURL(chrome::kChromeSearchLocalNtpUrl), *url)) {
+ if (MatchesOriginAndPath(GURL(chrome::kChromeSearchLocalNtpUrl), *url)) {
*url = GURL(chrome::kChromeUINewTabURL);
return true;
}
GURL new_tab_url(GetNewTabPageURL(profile));
- if (new_tab_url.is_valid() &&
- search::MatchesOriginAndPath(new_tab_url, *url)) {
+ if (new_tab_url.is_valid() && MatchesOriginAndPath(new_tab_url, *url)) {
*url = GURL(chrome::kChromeUINewTabURL);
return true;
}
@@ -690,11 +589,6 @@ bool ShouldPrefetchSearchResultsOnSRP() {
kPrefetchSearchResultsOnSRP, false, flags);
}
-void EnableQueryExtractionForTesting() {
- base::CommandLine* cl = base::CommandLine::ForCurrentProcess();
- cl->AppendSwitch(switches::kEnableQueryExtraction);
-}
-
bool ShouldUseAltInstantURL() {
FieldTrialFlags flags;
return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault(
@@ -707,4 +601,4 @@ bool ShouldUseSearchPathForInstant() {
kUseSearchPathForInstant, false, flags);
}
-} // namespace chrome
+} // namespace search
diff --git a/chrome/browser/search/search.h b/chrome/browser/search/search.h
index 1605f6d..5435641 100644
--- a/chrome/browser/search/search.h
+++ b/chrome/browser/search/search.h
@@ -28,7 +28,7 @@ namespace user_prefs {
class PrefRegistrySyncable;
}
-namespace chrome {
+namespace search {
// For reporting Cacheable NTP navigations.
enum CacheableNTPLoad {
@@ -47,34 +47,9 @@ enum OptInState {
INSTANT_EXTENDED_OPT_IN_STATE_ENUM_COUNT,
};
-// Use this value for "start margin" to prevent the "es_sm" parameter from
-// being used.
-extern const int kDisableStartMargin;
-
// Returns whether the suggest is enabled for the given |profile|.
bool IsSuggestPrefEnabled(Profile* profile);
-// Returns a string indicating whether InstantExtended is enabled, suitable
-// for adding as a query string param to the homepage or search requests.
-// Returns an empty string otherwise.
-//
-// |for_search| should be set to true for search requests, in which case this
-// returns a non-empty string only if query extraction is enabled.
-std::string InstantExtendedEnabledParam(bool for_search);
-
-// Returns a string that will cause the search results page to update
-// incrementally. Currently, Instant Extended passes a different param to
-// search results pages that also has this effect, so by default this function
-// returns the empty string when Instant Extended is enabled. However, when
-// doing instant search result prerendering, we still need to pass this param,
-// as Instant Extended does not cause incremental updates by default for the
-// prerender page. Callers should set |for_prerender| in this case to force
-// the returned string to be non-empty.
-std::string ForceInstantResultsParam(bool for_prerender);
-
-// Returns whether query extraction is enabled.
-bool IsQueryExtractionEnabled();
-
// Extracts and returns search terms from |url|. Does not consider
// IsQueryExtractionEnabled() and Instant support state of the page and does
// not check for a privileged process, so most callers should use
@@ -148,24 +123,11 @@ std::vector<GURL> GetSearchURLs(Profile* profile);
// trials.
GURL GetSearchResultPrefetchBaseURL(Profile* profile);
-// Returns true if 'prefetch_results' flag is set to true in field trials to
-// prefetch high-confidence search suggestions.
-bool ShouldPrefetchSearchResults();
-
-// Returns true if 'allow_prefetch_non_default_match' flag is enabled in field
-// trials to allow prefetching the suggestion marked to be prefetched by the
-// suggest server even if it is not the default match.
-bool ShouldAllowPrefetchNonDefaultMatch();
-
// Returns true if 'prerender_instant_url_on_omnibox_focus' flag is enabled in
// field trials to prerender Instant search base page when the omnibox is
// focused.
bool ShouldPrerenderInstantUrlOnOmniboxFocus();
-// Returns true if 'reuse_instant_search_base_page' flag is set to true in field
-// trials to reuse the prerendered page to commit any search query.
-bool ShouldReuseInstantSearchBasePage();
-
// Returns the Local Instant URL of the New Tab Page.
// TODO(kmadhusu): Remove this function and update the call sites.
GURL GetLocalInstantURL(Profile* profile);
@@ -220,9 +182,6 @@ bool ShouldPrefetchSearchResultsOnSRP();
// The following APIs are exposed for use in tests only.
// -----------------------------------------------------
-// Forces query in the omnibox to be on for tests.
-void EnableQueryExtractionForTesting();
-
// Returns the Cacheable New Tab Page URL for the given |profile|.
GURL GetNewTabPageURL(Profile* profile);
@@ -237,6 +196,6 @@ bool ShouldUseAltInstantURL();
// search.
bool ShouldUseSearchPathForInstant();
-} // namespace chrome
+} // namespace search
#endif // CHROME_BROWSER_SEARCH_SEARCH_H_
diff --git a/chrome/browser/search/search_android_unittest.cc b/chrome/browser/search/search_android_unittest.cc
deleted file mode 100644
index 5b8004b..0000000
--- a/chrome/browser/search/search_android_unittest.cc
+++ /dev/null
@@ -1,110 +0,0 @@
-// Copyright 2014 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/search/search.h"
-
-#include "base/command_line.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/metrics/field_trial.h"
-#include "base/metrics/statistics_recorder.h"
-#include "chrome/common/chrome_switches.h"
-#include "components/search/search.h"
-#include "components/search/search_switches.h"
-#include "components/variations/entropy_provider.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace chrome {
-
-namespace {
-
-TEST(SearchTest, QueryExtractionEnabled) {
- // Query extraction is always enabled on mobile.
- EXPECT_TRUE(IsQueryExtractionEnabled());
-}
-
-class SearchUtilTest : public testing::Test {
- protected:
- void SetUp() override {
- field_trial_list_.reset(new base::FieldTrialList(
- new metrics::SHA1EntropyProvider("42")));
- base::StatisticsRecorder::Initialize();
- }
-
- private:
- scoped_ptr<base::FieldTrialList> field_trial_list_;
-};
-
-TEST_F(SearchUtilTest, UseDefaultEmbeddedSearchPageVersion) {
- ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
- "EmbeddedSearch", "Group1 espv:-1 query_extraction:1"));
- EXPECT_TRUE(IsQueryExtractionEnabled());
- EXPECT_EQ("espv=1&", InstantExtendedEnabledParam(true));
- EXPECT_EQ("espv=1&", InstantExtendedEnabledParam(false));
-}
-
-TEST_F(SearchUtilTest, ShouldPrefetchSearchResults_InstantExtendedAPIEnabled) {
- ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
- "EmbeddedSearch",
- "Group1 espv:2 prefetch_results:1"));
- EXPECT_TRUE(ShouldPrefetchSearchResults());
- EXPECT_TRUE(IsInstantExtendedAPIEnabled());
- EXPECT_EQ(2ul, EmbeddedSearchPageVersion());
-}
-
-TEST_F(SearchUtilTest, ShouldPrefetchSearchResults_InstantExtendedAPIDisabled) {
- ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
- "EmbeddedSearch",
- "Group1 espv:1 prefetch_results:1"));
- EXPECT_FALSE(ShouldPrefetchSearchResults());
- EXPECT_FALSE(IsInstantExtendedAPIEnabled());
- EXPECT_EQ(1ul, EmbeddedSearchPageVersion());
-}
-
-TEST_F(SearchUtilTest, ShouldPrefetchSearchResults_DisabledViaFieldTrials) {
- ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
- "EmbeddedSearch",
- "Group1 espv:2 prefetch_results:0"));
- EXPECT_FALSE(ShouldPrefetchSearchResults());
- EXPECT_EQ(2ul, EmbeddedSearchPageVersion());
-}
-
-TEST_F(SearchUtilTest, ShouldPrefetchSearchResults_EnabledViaCommandLine) {
- base::CommandLine::ForCurrentProcess()->AppendSwitch(
- switches::kPrefetchSearchResults);
- // Command-line enable should override Finch.
- ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
- "EmbeddedSearch", "Group1 espv:2 prefetch_results:0"));
- EXPECT_TRUE(ShouldPrefetchSearchResults());
- EXPECT_EQ(2ul, EmbeddedSearchPageVersion());
-}
-
-TEST_F(SearchUtilTest,
- ShouldReuseInstantSearchBasePage_PrefetchResultsFlagDisabled) {
- ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
- "EmbeddedSearch",
- "Group1 espv:2 prefetch_results:0 reuse_instant_search_base_page:1"));
- EXPECT_FALSE(ShouldPrefetchSearchResults());
- EXPECT_FALSE(ShouldReuseInstantSearchBasePage());
- EXPECT_EQ(2ul, EmbeddedSearchPageVersion());
-}
-
-TEST_F(SearchUtilTest, ShouldReuseInstantSearchBasePage_EnabledViaFieldTrial) {
- ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
- "EmbeddedSearch",
- "Group1 espv:2 prefetch_results:1 reuse_instant_search_base_page:1"));
- EXPECT_TRUE(ShouldReuseInstantSearchBasePage());
- EXPECT_EQ(2ul, EmbeddedSearchPageVersion());
-}
-
-TEST_F(SearchUtilTest, ShouldReuseInstantSearchBasePage_DisabledViaFieldTrial) {
- ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
- "EmbeddedSearch",
- "Group1 espv:2 prefetch_results:1 reuse_instant_search_base_page:0"));
- EXPECT_FALSE(ShouldReuseInstantSearchBasePage());
- EXPECT_EQ(2ul, EmbeddedSearchPageVersion());
-}
-
-} // namespace
-
-} // namespace chrome
diff --git a/chrome/browser/search/search_unittest.cc b/chrome/browser/search/search_unittest.cc
index 1b33a79..c7ed494 100644
--- a/chrome/browser/search/search_unittest.cc
+++ b/chrome/browser/search/search_unittest.cc
@@ -38,7 +38,7 @@
#include "chrome/browser/supervised_user/supervised_user_url_filter.h"
#endif
-namespace chrome {
+namespace search {
class SearchTest : public BrowserWithTestWindowTest {
protected:
@@ -389,7 +389,7 @@ TEST_F(SearchTest, InstantCacheableNTPNavigationEntry) {
EXPECT_FALSE(NavEntryIsInstantNTP(contents,
controller.GetLastCommittedEntry()));
// Test Cacheable NTP
- NavigateAndCommitActiveTab(chrome::GetNewTabPageURL(profile()));
+ NavigateAndCommitActiveTab(GetNewTabPageURL(profile()));
EXPECT_TRUE(NavEntryIsInstantNTP(contents,
controller.GetLastCommittedEntry()));
}
@@ -411,7 +411,7 @@ TEST_F(SearchTest, InstantCacheableNTPNavigationEntryNewProfile) {
TEST_F(SearchTest, NoRewriteInIncognito) {
profile()->ForceIncognito(true);
- EXPECT_EQ(GURL(), chrome::GetNewTabPageURL(profile()));
+ EXPECT_EQ(GURL(), GetNewTabPageURL(profile()));
GURL new_tab_url(chrome::kChromeUINewTabURL);
EXPECT_FALSE(HandleNewTabURLRewrite(&new_tab_url, profile()));
EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), new_tab_url);
@@ -421,7 +421,7 @@ TEST_F(SearchTest, UseLocalNTPIfNTPURLIsInsecure) {
// Set an insecure new tab page URL and verify that it's ignored.
SetSearchProvider(true, true);
EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl),
- chrome::GetNewTabPageURL(profile()));
+ GetNewTabPageURL(profile()));
GURL new_tab_url(chrome::kChromeUINewTabURL);
EXPECT_TRUE(HandleNewTabURLRewrite(&new_tab_url, profile()));
EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), new_tab_url);
@@ -431,7 +431,7 @@ TEST_F(SearchTest, UseLocalNTPIfNTPURLIsNotSet) {
// Set an insecure new tab page URL and verify that it's ignored.
SetSearchProvider(false, true);
EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl),
- chrome::GetNewTabPageURL(profile()));
+ GetNewTabPageURL(profile()));
GURL new_tab_url(chrome::kChromeUINewTabURL);
EXPECT_TRUE(HandleNewTabURLRewrite(&new_tab_url, profile()));
EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), new_tab_url);
@@ -449,7 +449,7 @@ TEST_F(SearchTest, UseLocalNTPIfNTPURLIsBlockedForSupervisedUser) {
url_filter->SetManualHosts(&hosts);
EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl),
- chrome::GetNewTabPageURL(profile()));
+ GetNewTabPageURL(profile()));
GURL new_tab_url(chrome::kChromeUINewTabURL);
EXPECT_TRUE(HandleNewTabURLRewrite(&new_tab_url, profile()));
EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), new_tab_url);
@@ -554,48 +554,6 @@ TEST_F(SearchTest, CommandLineOverrides) {
EXPECT_EQ("http://www.bar.com/webhp?a=b&strk", instant_url.spec());
}
-TEST_F(SearchTest, ShouldPrefetchSearchResults_InstantExtendedAPIEnabled) {
- ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
- "EmbeddedSearch", "Group1 espv:2"));
-#if defined(OS_IOS)
- EXPECT_EQ(1ul, EmbeddedSearchPageVersion());
- EXPECT_TRUE(ShouldPrefetchSearchResults());
-#else
- EXPECT_EQ(2ul, EmbeddedSearchPageVersion());
- EXPECT_TRUE(ShouldPrefetchSearchResults());
-#endif
-}
-
-TEST_F(SearchTest, ShouldPrefetchSearchResults_Default) {
-#if defined(OS_IOS)
- EXPECT_FALSE(ShouldPrefetchSearchResults());
-#else
- EXPECT_TRUE(ShouldPrefetchSearchResults());
-#endif
-}
-
-TEST_F(SearchTest, ShouldReuseInstantSearchBasePage_Default) {
-#if defined(OS_IOS)
- EXPECT_FALSE(ShouldReuseInstantSearchBasePage());
-#else
- EXPECT_TRUE(ShouldReuseInstantSearchBasePage());
-#endif
-}
-
-TEST_F(SearchTest, ShouldAllowPrefetchNonDefaultMatch_DisabledViaFieldTrial) {
- ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
- "EmbeddedSearch", "Group1 espv:89 allow_prefetch_non_default_match:0"));
- EXPECT_FALSE(ShouldAllowPrefetchNonDefaultMatch());
- EXPECT_EQ(89ul, EmbeddedSearchPageVersion());
-}
-
-TEST_F(SearchTest, ShouldAllowPrefetchNonDefaultMatch_EnabledViaFieldTrial) {
- ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
- "EmbeddedSearch", "Group1 espv:80 allow_prefetch_non_default_match:1"));
- EXPECT_TRUE(ShouldAllowPrefetchNonDefaultMatch());
- EXPECT_EQ(80ul, EmbeddedSearchPageVersion());
-}
-
TEST_F(SearchTest, ShouldUseAltInstantURL_DisabledViaFieldTrial) {
ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
"EmbeddedSearch", "Group1 espv:8 use_alternate_instant_url:0"));
@@ -664,7 +622,7 @@ TEST_F(SearchTest, IsNTPURL) {
GURL ntp_url(chrome::kChromeUINewTabURL);
GURL local_ntp_url(GetLocalInstantURL(profile()));
- EXPECT_FALSE(chrome::IsNTPURL(invalid_url, profile()));
+ EXPECT_FALSE(IsNTPURL(invalid_url, profile()));
// No margin.
EnableQueryExtractionForTesting();
profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, true);
@@ -672,17 +630,17 @@ TEST_F(SearchTest, IsNTPURL) {
GURL search_url_with_search_terms("https://foo.com/url?strk&bar=abc");
GURL search_url_without_search_terms("https://foo.com/url?strk&bar");
- EXPECT_FALSE(chrome::IsNTPURL(ntp_url, profile()));
- EXPECT_TRUE(chrome::IsNTPURL(local_ntp_url, profile()));
- EXPECT_TRUE(chrome::IsNTPURL(remote_ntp_url, profile()));
- EXPECT_FALSE(chrome::IsNTPURL(search_url_with_search_terms, profile()));
- EXPECT_TRUE(chrome::IsNTPURL(search_url_without_search_terms, profile()));
+ EXPECT_FALSE(IsNTPURL(ntp_url, profile()));
+ EXPECT_TRUE(IsNTPURL(local_ntp_url, profile()));
+ EXPECT_TRUE(IsNTPURL(remote_ntp_url, profile()));
+ EXPECT_FALSE(IsNTPURL(search_url_with_search_terms, profile()));
+ EXPECT_TRUE(IsNTPURL(search_url_without_search_terms, profile()));
- EXPECT_FALSE(chrome::IsNTPURL(ntp_url, NULL));
- EXPECT_FALSE(chrome::IsNTPURL(local_ntp_url, NULL));
- EXPECT_FALSE(chrome::IsNTPURL(remote_ntp_url, NULL));
- EXPECT_FALSE(chrome::IsNTPURL(search_url_with_search_terms, NULL));
- EXPECT_FALSE(chrome::IsNTPURL(search_url_without_search_terms, NULL));
+ EXPECT_FALSE(IsNTPURL(ntp_url, NULL));
+ EXPECT_FALSE(IsNTPURL(local_ntp_url, NULL));
+ EXPECT_FALSE(IsNTPURL(remote_ntp_url, NULL));
+ EXPECT_FALSE(IsNTPURL(search_url_with_search_terms, NULL));
+ EXPECT_FALSE(IsNTPURL(search_url_without_search_terms, NULL));
}
TEST_F(SearchTest, GetSearchURLs) {
@@ -703,14 +661,6 @@ TEST_F(SearchTest, GetSearchResultPrefetchBaseURL) {
#endif
}
-TEST_F(SearchTest, ForceInstantResultsParam) {
- ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch",
- "Group1 espv:2"));
- EXPECT_TRUE(IsInstantExtendedAPIEnabled());
- EXPECT_EQ("ion=1&", ForceInstantResultsParam(true));
- EXPECT_EQ(std::string(), ForceInstantResultsParam(false));
-}
-
struct ExtractSearchTermsTestCase {
const char* url;
const char* expected_result;
@@ -728,11 +678,10 @@ TEST_F(SearchTest, ExtractSearchTermsFromURL) {
for (size_t i = 0; i < arraysize(kTestCases); ++i) {
const ExtractSearchTermsTestCase& test = kTestCases[i];
- EXPECT_EQ(
- test.expected_result,
- base::UTF16ToASCII(chrome::ExtractSearchTermsFromURL(profile(),
- GURL(test.url))))
- << test.url << " " << test.comment;
+ EXPECT_EQ(test.expected_result,
+ base::UTF16ToASCII(
+ ExtractSearchTermsFromURL(profile(), GURL(test.url))))
+ << test.url << " " << test.comment;
}
}
@@ -756,7 +705,7 @@ TEST_F(SearchTest, IsQueryExtractionAllowedForURL) {
for (size_t i = 0; i < arraysize(kTestCases); ++i) {
const QueryExtractionAllowedTestCase& test = kTestCases[i];
EXPECT_EQ(test.expected_result,
- chrome::IsQueryExtractionAllowedForURL(profile(), GURL(test.url)))
+ IsQueryExtractionAllowedForURL(profile(), GURL(test.url)))
<< test.url << " " << test.comment;
}
}
@@ -805,80 +754,4 @@ TEST_F(SearchURLTest, QueryExtractionDisabled) {
EXPECT_EQ("http://www.google.com/search?q=foo", result.spec());
}
-typedef SearchTest InstantExtendedEnabledParamTest;
-
-TEST_F(InstantExtendedEnabledParamTest, QueryExtractionDisabled) {
- ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch",
- "Group1 espv:12"));
- // Make sure InstantExtendedEnabledParam() returns an empty string for search
- // requests.
-#if defined(OS_IOS)
- // Query extraction is always enabled on mobile.
- EXPECT_TRUE(IsQueryExtractionEnabled());
- EXPECT_EQ("espv=12&", InstantExtendedEnabledParam(true));
-#else
- EXPECT_FALSE(IsQueryExtractionEnabled());
- EXPECT_EQ("", InstantExtendedEnabledParam(true));
-#endif
- EXPECT_EQ("espv=12&", InstantExtendedEnabledParam(false));
-}
-
-TEST_F(InstantExtendedEnabledParamTest, QueryExtractionEnabled) {
- ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
- "EmbeddedSearch", "Group1 espv:10 query_extraction:1"));
- EXPECT_TRUE(IsQueryExtractionEnabled());
- // Make sure InstantExtendedEnabledParam() returns a non-empty param string
- // for search requests.
- EXPECT_EQ("espv=10&", InstantExtendedEnabledParam(true));
- EXPECT_EQ("espv=10&", InstantExtendedEnabledParam(false));
-}
-
-TEST_F(InstantExtendedEnabledParamTest, UseDefaultEmbeddedSearchPageVersion) {
- ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
- "EmbeddedSearch", "Group1 espv:-1 query_extraction:1"));
- EXPECT_TRUE(IsQueryExtractionEnabled());
-#if defined(OS_IOS)
- EXPECT_EQ("espv=1&", InstantExtendedEnabledParam(true));
- EXPECT_EQ("espv=1&", InstantExtendedEnabledParam(false));
-#else
- EXPECT_EQ("espv=2&", InstantExtendedEnabledParam(true));
- EXPECT_EQ("espv=2&", InstantExtendedEnabledParam(false));
-#endif
-}
-
-typedef SearchTest IsQueryExtractionEnabledTest;
-
-TEST_F(IsQueryExtractionEnabledTest, NotSet) {
- ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
- "EmbeddedSearch", "Group1 espv:2"));
- EXPECT_TRUE(IsInstantExtendedAPIEnabled());
- EXPECT_FALSE(IsQueryExtractionEnabled());
- EXPECT_EQ(2ul, EmbeddedSearchPageVersion());
-}
-
-TEST_F(IsQueryExtractionEnabledTest, EnabledViaFieldTrial) {
- ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
- "EmbeddedSearch", "Group1 espv:2 query_extraction:1"));
- EXPECT_TRUE(IsInstantExtendedAPIEnabled());
- EXPECT_TRUE(IsQueryExtractionEnabled());
- EXPECT_EQ(2ul, EmbeddedSearchPageVersion());
-}
-
-TEST_F(IsQueryExtractionEnabledTest, DisabledViaFieldTrial) {
- ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
- "EmbeddedSearch", "Group1 espv:2 query_extraction:0"));
- EXPECT_TRUE(IsInstantExtendedAPIEnabled());
- EXPECT_FALSE(IsQueryExtractionEnabled());
- EXPECT_EQ(2ul, EmbeddedSearchPageVersion());
-}
-
-TEST_F(IsQueryExtractionEnabledTest, EnabledViaCommandLine) {
- EnableQueryExtractionForTesting();
- ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
- "EmbeddedSearch", "Group1 espv:2 query_extraction:0"));
- EXPECT_TRUE(IsInstantExtendedAPIEnabled());
- EXPECT_TRUE(IsQueryExtractionEnabled());
- EXPECT_EQ(2ul, EmbeddedSearchPageVersion());
-}
-
-} // namespace chrome
+} // namespace search
diff --git a/chrome/browser/search_engines/ui_thread_search_terms_data.cc b/chrome/browser/search_engines/ui_thread_search_terms_data.cc
index 773896f..ead1dc5 100644
--- a/chrome/browser/search_engines/ui_thread_search_terms_data.cc
+++ b/chrome/browser/search_engines/ui_thread_search_terms_data.cc
@@ -111,7 +111,7 @@ std::string UIThreadSearchTermsData::GetSuggestClient() const {
return ui::GetDeviceFormFactor() == ui::DEVICE_FORM_FACTOR_PHONE ?
"chrome" : "chrome-omni";
#else
- return chrome::IsInstantExtendedAPIEnabled() ? "chrome-omni" : "chrome";
+ return search::IsInstantExtendedAPIEnabled() ? "chrome-omni" : "chrome";
#endif
}
@@ -126,33 +126,33 @@ std::string UIThreadSearchTermsData::GetSuggestRequestIdentifier() const {
}
bool UIThreadSearchTermsData::IsShowingSearchTermsOnSearchResultsPages() const {
- return chrome::IsInstantExtendedAPIEnabled() &&
- chrome::IsQueryExtractionEnabled();
+ return search::IsInstantExtendedAPIEnabled() &&
+ search::IsQueryExtractionEnabled();
}
std::string UIThreadSearchTermsData::InstantExtendedEnabledParam(
bool for_search) const {
- return chrome::InstantExtendedEnabledParam(for_search);
+ return search::InstantExtendedEnabledParam(for_search);
}
std::string UIThreadSearchTermsData::ForceInstantResultsParam(
bool for_prerender) const {
- return chrome::ForceInstantResultsParam(for_prerender);
+ return search::ForceInstantResultsParam(for_prerender);
}
int UIThreadSearchTermsData::OmniboxStartMargin() const {
InstantService* instant_service =
InstantServiceFactory::GetForProfile(profile_);
// Android and iOS have no InstantService.
- return instant_service ?
- instant_service->omnibox_start_margin() : chrome::kDisableStartMargin;
+ return instant_service ? instant_service->omnibox_start_margin()
+ : search::kDisableStartMargin;
}
std::string UIThreadSearchTermsData::NTPIsThemedParam() const {
DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) ||
BrowserThread::CurrentlyOn(BrowserThread::UI));
#if defined(ENABLE_THEMES)
- if (!chrome::IsInstantExtendedAPIEnabled())
+ if (!search::IsInstantExtendedAPIEnabled())
return std::string();
// TODO(dhollowa): Determine fraction of custom themes that don't affect the
diff --git a/chrome/browser/sessions/session_restore.cc b/chrome/browser/sessions/session_restore.cc
index b1a7498..aca211c 100644
--- a/chrome/browser/sessions/session_restore.cc
+++ b/chrome/browser/sessions/session_restore.cc
@@ -780,7 +780,7 @@ void SessionRestore::RestoreSessionAfterCrash(Browser* browser) {
const content::WebContents* active_tab =
browser->tab_strip_model()->GetWebContentsAt(0);
if (active_tab->GetURL() == GURL(chrome::kChromeUINewTabURL) ||
- chrome::IsInstantNTP(active_tab)) {
+ search::IsInstantNTP(active_tab)) {
// There is only one tab and its the new tab page, make session restore
// clobber it.
behavior = SessionRestore::CLOBBER_CURRENT_TAB;
diff --git a/chrome/browser/thumbnails/thumbnail_service_impl.cc b/chrome/browser/thumbnails/thumbnail_service_impl.cc
index ee6cf7e..ae061cc 100644
--- a/chrome/browser/thumbnails/thumbnail_service_impl.cc
+++ b/chrome/browser/thumbnails/thumbnail_service_impl.cc
@@ -27,7 +27,7 @@ const int kThumbnailHeight = 142;
// True if thumbnail retargeting feature is enabled (Finch/flags).
bool IsThumbnailRetargetingEnabled() {
- if (!chrome::IsInstantExtendedAPIEnabled())
+ if (!search::IsInstantExtendedAPIEnabled())
return false;
return base::CommandLine::ForCurrentProcess()->HasSwitch(
diff --git a/chrome/browser/ui/app_list/search/common/webservice_search_provider.cc b/chrome/browser/ui/app_list/search/common/webservice_search_provider.cc
index 32e64c1..833ed43 100644
--- a/chrome/browser/ui/app_list/search/common/webservice_search_provider.cc
+++ b/chrome/browser/ui/app_list/search/common/webservice_search_provider.cc
@@ -47,9 +47,8 @@ void WebserviceSearchProvider::StartThrottledQuery(
bool WebserviceSearchProvider::IsValidQuery(const base::string16& query) {
// If |query| contains sensitive data, bail out and do not create the place
// holder "search-web-store" result.
- if (IsSensitiveInput(query) ||
- (query.size() < kMinimumQueryLength) ||
- !chrome::IsSuggestPrefEnabled(profile_)) {
+ if (IsSensitiveInput(query) || (query.size() < kMinimumQueryLength) ||
+ !search::IsSuggestPrefEnabled(profile_)) {
return false;
}
diff --git a/chrome/browser/ui/bookmarks/bookmark_tab_helper.cc b/chrome/browser/ui/bookmarks/bookmark_tab_helper.cc
index 0d390aa..074cae5 100644
--- a/chrome/browser/ui/bookmarks/bookmark_tab_helper.cc
+++ b/chrome/browser/ui/bookmarks/bookmark_tab_helper.cc
@@ -41,7 +41,7 @@ bool IsInstantNTP(content::WebContents* web_contents) {
web_contents->GetController().GetLastCommittedEntry();
if (!entry)
entry = web_contents->GetController().GetVisibleEntry();
- return chrome::NavEntryIsInstantNTP(web_contents, entry);
+ return search::NavEntryIsInstantNTP(web_contents, entry);
}
} // namespace
diff --git a/chrome/browser/ui/bookmarks/bookmark_utils.cc b/chrome/browser/ui/bookmarks/bookmark_utils.cc
index 0956cc0..f2f4bc1 100644
--- a/chrome/browser/ui/bookmarks/bookmark_utils.cc
+++ b/chrome/browser/ui/bookmarks/bookmark_utils.cc
@@ -295,8 +295,8 @@ bool HasBookmarkURLsAllowedInIncognitoMode(
GURL GetURLToBookmark(content::WebContents* web_contents) {
DCHECK(web_contents);
- return IsInstantNTP(web_contents) ?
- GURL(kChromeUINewTabURL) : web_contents->GetURL();
+ return search::IsInstantNTP(web_contents) ? GURL(kChromeUINewTabURL)
+ : web_contents->GetURL();
}
void GetURLAndTitleToBookmark(content::WebContents* web_contents,
@@ -342,7 +342,7 @@ bool IsAppsShortcutEnabled(Profile* profile,
if (host_desktop_type == chrome::HOST_DESKTOP_TYPE_ASH)
return false;
- return chrome::IsInstantExtendedAPIEnabled() && !profile->IsOffTheRecord();
+ return search::IsInstantExtendedAPIEnabled() && !profile->IsOffTheRecord();
}
bool ShouldShowAppsShortcutInBookmarkBar(
diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc
index 6278531..ac738ad 100644
--- a/chrome/browser/ui/browser.cc
+++ b/chrome/browser/ui/browser.cc
@@ -413,7 +413,7 @@ Browser::Browser(const CreateParams& params)
encoding_auto_detect_.Init(prefs::kWebKitUsesUniversalDetector,
profile_->GetPrefs());
- if (chrome::IsInstantExtendedAPIEnabled() && is_type_tabbed())
+ if (search::IsInstantExtendedAPIEnabled() && is_type_tabbed())
instant_controller_.reset(new BrowserInstantController(this));
if (extensions::HostedAppBrowserController::IsForHostedApp(this)) {
@@ -1037,7 +1037,7 @@ void Browser::ActiveTabChanged(WebContents* old_contents,
// Propagate the profile to the location bar.
UpdateToolbar((reason & CHANGE_REASON_REPLACED) == 0);
- if (chrome::IsInstantExtendedAPIEnabled())
+ if (search::IsInstantExtendedAPIEnabled())
search_delegate_->OnTabActivated(new_contents);
// Update reload/stop state.
@@ -1193,7 +1193,7 @@ bool Browser::ShouldPreserveAbortedURLs(WebContents* source) {
if (!profile || !source->GetController().GetLastCommittedEntry())
return false;
GURL committed_url(source->GetController().GetLastCommittedEntry()->GetURL());
- return chrome::IsNTPURL(committed_url, profile);
+ return search::IsNTPURL(committed_url, profile);
}
void Browser::SetFocusToLocationBar(bool select_all) {
@@ -1591,7 +1591,7 @@ bool Browser::ShouldFocusLocationBarByDefault(WebContents* source) {
}
}
- return chrome::NavEntryIsInstantNTP(source, entry);
+ return search::NavEntryIsInstantNTP(source, entry);
}
void Browser::ViewSourceForTab(WebContents* source, const GURL& page_url) {
@@ -1859,7 +1859,7 @@ gfx::Size Browser::GetSizeForNewRenderView(WebContents* web_contents) const {
const NavigationEntry* pending_entry =
web_contents->GetController().GetPendingEntry();
if (pending_entry &&
- !chrome::IsNTPURL(pending_entry->GetVirtualURL(), profile_)) {
+ !search::IsNTPURL(pending_entry->GetVirtualURL(), profile_)) {
size.Enlarge(
0, window()->GetRenderViewHeightInsetWithDetachedBookmarkBar());
}
diff --git a/chrome/browser/ui/browser_browsertest.cc b/chrome/browser/ui/browser_browsertest.cc
index 59dad6a..64a6161 100644
--- a/chrome/browser/ui/browser_browsertest.cc
+++ b/chrome/browser/ui/browser_browsertest.cc
@@ -601,7 +601,7 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, ClearPendingOnFailUnlessNTP) {
ASSERT_TRUE(test_server()->Start());
WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
- GURL ntp_url(chrome::GetNewTabPageURL(browser()->profile()));
+ GURL ntp_url(search::GetNewTabPageURL(browser()->profile()));
ui_test_utils::NavigateToURL(browser(), ntp_url);
// Navigate to a 204 URL (aborts with no content) on the NTP and make sure it
diff --git a/chrome/browser/ui/browser_instant_controller.cc b/chrome/browser/ui/browser_instant_controller.cc
index c4871ef1..8344448 100644
--- a/chrome/browser/ui/browser_instant_controller.cc
+++ b/chrome/browser/ui/browser_instant_controller.cc
@@ -75,7 +75,7 @@ bool BrowserInstantController::OpenInstant(WindowOpenDisposition disposition,
DCHECK(disposition == CURRENT_TAB) << disposition;
const base::string16& search_terms =
- chrome::ExtractSearchTermsFromURL(profile(), url);
+ search::ExtractSearchTermsFromURL(profile(), url);
EmbeddedSearchRequestParams request_params(url);
if (search_terms.empty())
return false;
@@ -95,7 +95,7 @@ bool BrowserInstantController::OpenInstant(WindowOpenDisposition disposition,
// If we will not be replacing search terms from this URL, don't send to
// InstantController.
- if (!chrome::IsQueryExtractionAllowedForURL(profile(), url))
+ if (!search::IsQueryExtractionAllowedForURL(profile(), url))
return false;
return instant_.SubmitQuery(search_terms, request_params);
}
@@ -166,8 +166,8 @@ void BrowserInstantController::DefaultSearchProviderChanged(
if (google_base_url_domain_changed &&
SearchTabHelper::FromWebContents(contents)->model()->mode().is_ntp()) {
// Replace the server NTP with the local NTP.
- content::NavigationController::LoadURLParams
- params(chrome::GetLocalInstantURL(profile()));
+ content::NavigationController::LoadURLParams params(
+ search::GetLocalInstantURL(profile()));
params.should_replace_current_entry = true;
params.referrer = content::Referrer();
params.transition_type = ui::PAGE_TRANSITION_RELOAD;
diff --git a/chrome/browser/ui/browser_instant_controller_unittest.cc b/chrome/browser/ui/browser_instant_controller_unittest.cc
index 5fcfcbd..975063a 100644
--- a/chrome/browser/ui/browser_instant_controller_unittest.cc
+++ b/chrome/browser/ui/browser_instant_controller_unittest.cc
@@ -141,11 +141,10 @@ TEST_F(BrowserInstantControllerTest, DefaultSearchProviderChanged) {
if (test.should_reload) {
// Validate final instant state.
- EXPECT_EQ(
- test.end_in_instant_process,
- chrome::ShouldAssignURLToInstantRenderer(
- observer->current_url(), profile()))
- << test.description;
+ EXPECT_EQ(test.end_in_instant_process,
+ search::ShouldAssignURLToInstantRenderer(
+ observer->current_url(), profile()))
+ << test.description;
}
// Ensure only the expected tabs(contents) reloaded.
@@ -185,11 +184,10 @@ TEST_F(BrowserInstantControllerTest, GoogleBaseURLUpdated) {
FakeWebContentsObserver* observer = observers[i];
// Validate final instant state.
- EXPECT_EQ(
- test.end_in_instant_process,
- chrome::ShouldAssignURLToInstantRenderer(
- observer->current_url(), profile()))
- << test.description;
+ EXPECT_EQ(test.end_in_instant_process,
+ search::ShouldAssignURLToInstantRenderer(observer->current_url(),
+ profile()))
+ << test.description;
// Ensure only the expected tabs(contents) reloaded.
EXPECT_EQ(test.should_reload ? 1 : 0, observer->num_reloads())
diff --git a/chrome/browser/ui/extensions/extension_install_ui_default.cc b/chrome/browser/ui/extensions/extension_install_ui_default.cc
index d240fb1..32b306b 100644
--- a/chrome/browser/ui/extensions/extension_install_ui_default.cc
+++ b/chrome/browser/ui/extensions/extension_install_ui_default.cc
@@ -229,7 +229,7 @@ void ExtensionInstallUIDefault::OpenAppInstalledUI(const std::string& app_id) {
Profile* current_profile = profile_->GetOriginalProfile();
Browser* browser = FindOrCreateVisibleBrowser(current_profile);
if (browser) {
- GURL url(chrome::IsInstantExtendedAPIEnabled()
+ GURL url(search::IsInstantExtendedAPIEnabled()
? chrome::kChromeUIAppsURL
: chrome::kChromeUINewTabURL);
chrome::NavigateParams params(
diff --git a/chrome/browser/ui/omnibox/chrome_omnibox_client.cc b/chrome/browser/ui/omnibox/chrome_omnibox_client.cc
index 7b772b7..fca37cc 100644
--- a/chrome/browser/ui/omnibox/chrome_omnibox_client.cc
+++ b/chrome/browser/ui/omnibox/chrome_omnibox_client.cc
@@ -61,7 +61,7 @@ namespace {
// shown); for other matches, we think the likelihood of the user selecting
// them is low enough that prefetching isn't worth doing.
const AutocompleteMatch* GetMatchToPrefetch(const AutocompleteResult& result) {
- if (chrome::ShouldAllowPrefetchNonDefaultMatch()) {
+ if (search::ShouldAllowPrefetchNonDefaultMatch()) {
const AutocompleteResult::const_iterator prefetch_match = std::find_if(
result.begin(), result.end(), SearchProvider::ShouldPrefetch);
return prefetch_match != result.end() ? &(*prefetch_match) : NULL;
@@ -138,7 +138,7 @@ const GURL& ChromeOmniboxClient::GetURL() const {
}
bool ChromeOmniboxClient::IsInstantNTP() const {
- return chrome::IsInstantNTP(controller_->GetWebContents());
+ return search::IsInstantNTP(controller_->GetWebContents());
}
bool ChromeOmniboxClient::IsSearchResultsPage() const {
@@ -224,9 +224,9 @@ void ChromeOmniboxClient::OnResultChanged(
const AutocompleteResult& result,
bool default_match_changed,
const base::Callback<void(const SkBitmap& bitmap)>& on_bitmap_fetched) {
- if (chrome::IsInstantExtendedAPIEnabled() &&
+ if (search::IsInstantExtendedAPIEnabled() &&
((default_match_changed && result.default_match() != result.end()) ||
- (chrome::ShouldAllowPrefetchNonDefaultMatch() && !result.empty()))) {
+ (search::ShouldAllowPrefetchNonDefaultMatch() && !result.empty()))) {
InstantSuggestion prefetch_suggestion;
const AutocompleteMatch* match_to_prefetch = GetMatchToPrefetch(result);
if (match_to_prefetch) {
@@ -405,11 +405,11 @@ void ChromeOmniboxClient::DoPreconnect(const AutocompleteMatch& match) {
void ChromeOmniboxClient::SetSuggestionToPrefetch(
const InstantSuggestion& suggestion) {
- DCHECK(chrome::IsInstantExtendedAPIEnabled());
+ DCHECK(search::IsInstantExtendedAPIEnabled());
content::WebContents* web_contents = controller_->GetWebContents();
if (web_contents &&
SearchTabHelper::FromWebContents(web_contents)->IsSearchResultsPage()) {
- if (chrome::ShouldPrefetchSearchResultsOnSRP()) {
+ if (search::ShouldPrefetchSearchResultsOnSRP()) {
SearchTabHelper::FromWebContents(web_contents)->
SetSuggestionToPrefetch(suggestion);
}
diff --git a/chrome/browser/ui/search/instant_controller.cc b/chrome/browser/ui/search/instant_controller.cc
index 26c0917..33020d5 100644
--- a/chrome/browser/ui/search/instant_controller.cc
+++ b/chrome/browser/ui/search/instant_controller.cc
@@ -47,7 +47,7 @@ void EnsureSearchTermsAreSet(content::WebContents* contents,
// If search terms are already correct or there is already a transient entry
// (there shouldn't be), bail out early.
- if (chrome::GetSearchTerms(contents) == search_terms ||
+ if (search::GetSearchTerms(contents) == search_terms ||
controller->GetTransientEntry())
return;
@@ -108,7 +108,7 @@ void InstantController::ActiveTabChanged() {
void InstantController::TabDeactivated(content::WebContents* contents) {
// If user is deactivating an NTP tab, log the number of mouseovers for this
// NTP session.
- if (chrome::IsInstantNTP(contents))
+ if (search::IsInstantNTP(contents))
InstantTab::EmitNtpStatistics(contents);
}
diff --git a/chrome/browser/ui/search/instant_extended_interactive_uitest.cc b/chrome/browser/ui/search/instant_extended_interactive_uitest.cc
index f41690b..e96ee15 100644
--- a/chrome/browser/ui/search/instant_extended_interactive_uitest.cc
+++ b/chrome/browser/ui/search/instant_extended_interactive_uitest.cc
@@ -56,6 +56,7 @@
#include "components/omnibox/browser/autocomplete_result.h"
#include "components/omnibox/browser/omnibox_field_trial.h"
#include "components/omnibox/browser/search_provider.h"
+#include "components/search/search.h"
#include "components/search_engines/template_url_service.h"
#include "components/sessions/serialized_navigation_entry.h"
#include "content/public/browser/navigation_controller.h"
@@ -140,7 +141,7 @@ class InstantExtendedTest : public InProcessBrowserTest,
}
protected:
void SetUpInProcessBrowserTestFixture() override {
- chrome::EnableQueryExtractionForTesting();
+ search::EnableQueryExtractionForTesting();
ASSERT_TRUE(https_test_server().Start());
GURL instant_url = https_test_server().GetURL(
"files/instant_extended.html?strk=1&");
@@ -255,7 +256,7 @@ class InstantExtendedPrefetchTest : public InstantExtendedTest {
}
void SetUpInProcessBrowserTestFixture() override {
- chrome::EnableQueryExtractionForTesting();
+ search::EnableQueryExtractionForTesting();
ASSERT_TRUE(https_test_server().Start());
GURL instant_url = https_test_server().GetURL(
"files/instant_extended.html?strk=1&");
@@ -750,7 +751,7 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, DISABLED_NavigateBackToNTP) {
load_stop_observer_2.Wait();
active_tab = browser()->tab_strip_model()->GetActiveWebContents();
- EXPECT_TRUE(chrome::IsInstantNTP(active_tab));
+ EXPECT_TRUE(search::IsInstantNTP(active_tab));
}
// Flaky: crbug.com/267119
diff --git a/chrome/browser/ui/search/instant_extended_manual_interactive_uitest.cc b/chrome/browser/ui/search/instant_extended_manual_interactive_uitest.cc
index d142754..48dbe06 100644
--- a/chrome/browser/ui/search/instant_extended_manual_interactive_uitest.cc
+++ b/chrome/browser/ui/search/instant_extended_manual_interactive_uitest.cc
@@ -21,6 +21,7 @@
#include "chrome/test/base/interactive_test_utils.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/omnibox/common/omnibox_focus_state.h"
+#include "components/search/search.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/notification_service.h"
@@ -73,7 +74,7 @@ class InstantExtendedManualTest : public InProcessBrowserTest,
protected:
void SetUpInProcessBrowserTestFixture() override {
- chrome::EnableQueryExtractionForTesting();
+ search::EnableQueryExtractionForTesting();
}
content::WebContents* active_tab() {
diff --git a/chrome/browser/ui/search/instant_search_prerenderer.cc b/chrome/browser/ui/search/instant_search_prerenderer.cc
index e9e4cf8..1d190c4 100644
--- a/chrome/browser/ui/search/instant_search_prerenderer.cc
+++ b/chrome/browser/ui/search/instant_search_prerenderer.cc
@@ -15,6 +15,7 @@
#include "chrome/browser/ui/browser_navigator.h"
#include "chrome/browser/ui/search/search_tab_helper.h"
#include "components/omnibox/browser/autocomplete_match.h"
+#include "components/search/search.h"
#include "components/search_engines/template_url_service.h"
namespace {
@@ -132,7 +133,7 @@ bool InstantSearchPrerenderer::UsePrerenderedPage(
const GURL& url,
chrome::NavigateParams* params) {
base::string16 search_terms =
- chrome::ExtractSearchTermsFromURL(profile_, url);
+ search::ExtractSearchTermsFromURL(profile_, url);
prerender::PrerenderManager* prerender_manager =
prerender::PrerenderManagerFactory::GetForProfile(profile_);
if (search_terms.empty() || !params->target_contents ||
@@ -191,7 +192,7 @@ content::WebContents* InstantSearchPrerenderer::prerender_contents() const {
bool InstantSearchPrerenderer::QueryMatchesPrefetch(
const base::string16& query) const {
- if (chrome::ShouldReuseInstantSearchBasePage())
+ if (search::ShouldReuseInstantSearchBasePage())
return true;
return last_instant_suggestion_.text == query;
}
diff --git a/chrome/browser/ui/search/instant_search_prerenderer_unittest.cc b/chrome/browser/ui/search/instant_search_prerenderer_unittest.cc
index 11db5ed..0f9aafc 100644
--- a/chrome/browser/ui/search/instant_search_prerenderer_unittest.cc
+++ b/chrome/browser/ui/search/instant_search_prerenderer_unittest.cc
@@ -224,17 +224,17 @@ TEST_F(InstantSearchPrerendererTest, GetSearchTermsFromPrerenderedPage) {
GURL url(GetPrerenderURL());
EXPECT_EQ(GURL("https://www.google.com/instant?ion=1&foo=foo#foo=foo&strk"),
url);
- EXPECT_EQ(base::UTF16ToASCII(prerenderer->get_last_query()),
- base::UTF16ToASCII(
- chrome::ExtractSearchTermsFromURL(profile(), url)));
+ EXPECT_EQ(
+ base::UTF16ToASCII(prerenderer->get_last_query()),
+ base::UTF16ToASCII(search::ExtractSearchTermsFromURL(profile(), url)));
// Assume the prerendered page prefetched search results for the query
// "flowers".
SetLastQuery(ASCIIToUTF16("flowers"));
EXPECT_EQ("flowers", base::UTF16ToASCII(prerenderer->get_last_query()));
- EXPECT_EQ(base::UTF16ToASCII(prerenderer->get_last_query()),
- base::UTF16ToASCII(
- chrome::ExtractSearchTermsFromURL(profile(), url)));
+ EXPECT_EQ(
+ base::UTF16ToASCII(prerenderer->get_last_query()),
+ base::UTF16ToASCII(search::ExtractSearchTermsFromURL(profile(), url)));
}
TEST_F(InstantSearchPrerendererTest, PrefetchSearchResults) {
@@ -347,9 +347,10 @@ TEST_F(InstantSearchPrerendererTest, PrerenderingAllowed) {
// used only when the underlying page doesn't support Instant.
NavigateAndCommitActiveTab(GURL("https://www.google.com/alt#quux=foo&strk"));
active_tab = GetActiveWebContents();
- EXPECT_FALSE(chrome::ExtractSearchTermsFromURL(profile(),
- active_tab->GetURL()).empty());
- EXPECT_FALSE(chrome::ShouldPrefetchSearchResultsOnSRP());
+ EXPECT_FALSE(
+ search::ExtractSearchTermsFromURL(profile(), active_tab->GetURL())
+ .empty());
+ EXPECT_FALSE(search::ShouldPrefetchSearchResultsOnSRP());
EXPECT_FALSE(prerenderer->IsAllowed(search_type_match, active_tab));
}
diff --git a/chrome/browser/ui/search/local_ntp_browsertest.cc b/chrome/browser/ui/search/local_ntp_browsertest.cc
index d889956..78af6c4 100644
--- a/chrome/browser/ui/search/local_ntp_browsertest.cc
+++ b/chrome/browser/ui/search/local_ntp_browsertest.cc
@@ -43,7 +43,7 @@ IN_PROC_BROWSER_TEST_F(LocalNTPTest, LocalNTPJavascriptTest) {
ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
content::WebContents* active_tab =
browser()->tab_strip_model()->GetActiveWebContents();
- ASSERT_TRUE(chrome::IsInstantNTP(active_tab));
+ ASSERT_TRUE(search::IsInstantNTP(active_tab));
bool success = false;
ASSERT_TRUE(GetBoolFromJS(active_tab, "!!runTests()", &success));
EXPECT_TRUE(success);
diff --git a/chrome/browser/ui/search/new_tab_page_interceptor_service.cc b/chrome/browser/ui/search/new_tab_page_interceptor_service.cc
index 0b2d4bb..1c37519 100644
--- a/chrome/browser/ui/search/new_tab_page_interceptor_service.cc
+++ b/chrome/browser/ui/search/new_tab_page_interceptor_service.cc
@@ -77,8 +77,8 @@ class NewTabPageInterceptor : public net::URLRequestInterceptor {
// Failure to load the NTP correctly; redirect to Local NTP.
UMA_HISTOGRAM_ENUMERATION("InstantExtended.CacheableNTPLoad",
- chrome::CACHEABLE_NTP_LOAD_FAILED,
- chrome::CACHEABLE_NTP_LOAD_MAX);
+ search::CACHEABLE_NTP_LOAD_FAILED,
+ search::CACHEABLE_NTP_LOAD_MAX);
return new net::URLRequestRedirectJob(
request, network_delegate, GURL(chrome::kChromeSearchLocalNtpUrl),
net::URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT,
@@ -106,7 +106,7 @@ NewTabPageInterceptorService::~NewTabPageInterceptorService() {
void NewTabPageInterceptorService::OnTemplateURLServiceChanged() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
- GURL new_tab_page_url(chrome::GetNewTabPageURL(profile_));
+ GURL new_tab_page_url(search::GetNewTabPageURL(profile_));
content::BrowserThread::PostTask(
content::BrowserThread::IO, FROM_HERE,
base::Bind(&NewTabPageInterceptor::SetNewTabPageURL, interceptor_,
@@ -117,7 +117,7 @@ scoped_ptr<net::URLRequestInterceptor>
NewTabPageInterceptorService::CreateInterceptor() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
scoped_ptr<NewTabPageInterceptor> interceptor(
- new NewTabPageInterceptor(chrome::GetNewTabPageURL(profile_)));
+ new NewTabPageInterceptor(search::GetNewTabPageURL(profile_)));
interceptor_ = interceptor->GetWeakPtr();
return interceptor.Pass();
}
diff --git a/chrome/browser/ui/search/search_ipc_router.cc b/chrome/browser/ui/search/search_ipc_router.cc
index a1b85543..72598b2 100644
--- a/chrome/browser/ui/search/search_ipc_router.cc
+++ b/chrome/browser/ui/search/search_ipc_router.cc
@@ -7,6 +7,7 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search/search.h"
#include "chrome/common/render_messages.h"
+#include "components/search/search.h"
#include "content/public/browser/navigation_details.h"
#include "content/public/browser/web_contents.h"
@@ -80,10 +81,10 @@ void SearchIPCRouter::SetDisplayInstantResults() {
if (!policy_->ShouldSendSetDisplayInstantResults())
return;
- bool is_search_results_page = !chrome::GetSearchTerms(web_contents()).empty();
- bool display_instant_results = is_search_results_page ?
- chrome::ShouldPrefetchSearchResultsOnSRP() :
- chrome::ShouldPrefetchSearchResults();
+ bool is_search_results_page = !search::GetSearchTerms(web_contents()).empty();
+ bool display_instant_results =
+ is_search_results_page ? search::ShouldPrefetchSearchResultsOnSRP()
+ : search::ShouldPrefetchSearchResults();
Send(new ChromeViewMsg_SearchBoxSetDisplayInstantResults(
routing_id(), display_instant_results));
}
@@ -165,7 +166,7 @@ bool SearchIPCRouter::OnMessageReceived(const IPC::Message& message) {
Profile* profile =
Profile::FromBrowserContext(web_contents()->GetBrowserContext());
- if (!chrome::IsRenderedInInstantProcess(web_contents(), profile))
+ if (!search::IsRenderedInInstantProcess(web_contents(), profile))
return false;
bool handled = true;
diff --git a/chrome/browser/ui/search/search_ipc_router_policy_impl.cc b/chrome/browser/ui/search/search_ipc_router_policy_impl.cc
index bbab087..4a85e2f 100644
--- a/chrome/browser/ui/search/search_ipc_router_policy_impl.cc
+++ b/chrome/browser/ui/search/search_ipc_router_policy_impl.cc
@@ -27,44 +27,44 @@ bool SearchIPCRouterPolicyImpl::ShouldProcessSetVoiceSearchSupport() {
}
bool SearchIPCRouterPolicyImpl::ShouldProcessFocusOmnibox(bool is_active_tab) {
- return is_active_tab && !is_incognito_ && chrome::IsInstantNTP(web_contents_);
+ return is_active_tab && !is_incognito_ && search::IsInstantNTP(web_contents_);
}
bool SearchIPCRouterPolicyImpl::ShouldProcessNavigateToURL(bool is_active_tab) {
- return is_active_tab && !is_incognito_ && chrome::IsInstantNTP(web_contents_);
+ return is_active_tab && !is_incognito_ && search::IsInstantNTP(web_contents_);
}
bool SearchIPCRouterPolicyImpl::ShouldProcessDeleteMostVisitedItem() {
- return !is_incognito_ && chrome::IsInstantNTP(web_contents_);
+ return !is_incognito_ && search::IsInstantNTP(web_contents_);
}
bool SearchIPCRouterPolicyImpl::ShouldProcessUndoMostVisitedDeletion() {
- return !is_incognito_ && chrome::IsInstantNTP(web_contents_);
+ return !is_incognito_ && search::IsInstantNTP(web_contents_);
}
bool SearchIPCRouterPolicyImpl::ShouldProcessUndoAllMostVisitedDeletions() {
- return !is_incognito_ && chrome::IsInstantNTP(web_contents_);
+ return !is_incognito_ && search::IsInstantNTP(web_contents_);
}
bool SearchIPCRouterPolicyImpl::ShouldProcessLogEvent() {
- return !is_incognito_ && chrome::IsInstantNTP(web_contents_);
+ return !is_incognito_ && search::IsInstantNTP(web_contents_);
}
bool SearchIPCRouterPolicyImpl::ShouldProcessPasteIntoOmnibox(
bool is_active_tab) {
- return is_active_tab && !is_incognito_ && chrome::IsInstantNTP(web_contents_);
+ return is_active_tab && !is_incognito_ && search::IsInstantNTP(web_contents_);
}
bool SearchIPCRouterPolicyImpl::ShouldProcessChromeIdentityCheck() {
- return !is_incognito_ && chrome::IsInstantNTP(web_contents_);
+ return !is_incognito_ && search::IsInstantNTP(web_contents_);
}
bool SearchIPCRouterPolicyImpl::ShouldProcessHistorySyncCheck() {
- return !is_incognito_ && chrome::IsInstantNTP(web_contents_);
+ return !is_incognito_ && search::IsInstantNTP(web_contents_);
}
bool SearchIPCRouterPolicyImpl::ShouldSendSetPromoInformation() {
- return !is_incognito_ && chrome::IsInstantNTP(web_contents_);
+ return !is_incognito_ && search::IsInstantNTP(web_contents_);
}
bool SearchIPCRouterPolicyImpl::ShouldSendSetDisplayInstantResults() {
@@ -89,11 +89,11 @@ bool SearchIPCRouterPolicyImpl::ShouldSendOmniboxFocusChanged() {
}
bool SearchIPCRouterPolicyImpl::ShouldSendMostVisitedItems() {
- return !is_incognito_ && chrome::IsInstantNTP(web_contents_);
+ return !is_incognito_ && search::IsInstantNTP(web_contents_);
}
bool SearchIPCRouterPolicyImpl::ShouldSendThemeBackgroundInfo() {
- return !is_incognito_ && chrome::IsInstantNTP(web_contents_);
+ return !is_incognito_ && search::IsInstantNTP(web_contents_);
}
bool SearchIPCRouterPolicyImpl::ShouldSendToggleVoiceSearch() {
diff --git a/chrome/browser/ui/search/search_ipc_router_unittest.cc b/chrome/browser/ui/search/search_ipc_router_unittest.cc
index c1e997f..24c3c11 100644
--- a/chrome/browser/ui/search/search_ipc_router_unittest.cc
+++ b/chrome/browser/ui/search/search_ipc_router_unittest.cc
@@ -190,7 +190,7 @@ class SearchIPCRouterTest : public BrowserWithTestWindowTest {
void OnMessageReceived(const IPC::Message& message) {
bool should_handle_message =
- chrome::IsRenderedInInstantProcess(web_contents(), profile());
+ search::IsRenderedInInstantProcess(web_contents(), profile());
bool handled = GetSearchIPCRouter().OnMessageReceived(message);
ASSERT_EQ(should_handle_message, handled);
}
diff --git a/chrome/browser/ui/search/search_model.cc b/chrome/browser/ui/search/search_model.cc
index 1d530dd..17d5a96 100644
--- a/chrome/browser/ui/search/search_model.cc
+++ b/chrome/browser/ui/search/search_model.cc
@@ -32,7 +32,7 @@ SearchModel::~SearchModel() {
}
void SearchModel::SetState(const State& new_state) {
- DCHECK(chrome::IsInstantExtendedAPIEnabled())
+ DCHECK(search::IsInstantExtendedAPIEnabled())
<< "Please do not try to set the SearchModel mode without first "
<< "checking if Search is enabled.";
@@ -47,7 +47,7 @@ void SearchModel::SetState(const State& new_state) {
}
void SearchModel::SetMode(const SearchMode& new_mode) {
- DCHECK(chrome::IsInstantExtendedAPIEnabled())
+ DCHECK(search::IsInstantExtendedAPIEnabled())
<< "Please do not try to set the SearchModel mode without first "
<< "checking if Search is enabled.";
@@ -62,7 +62,7 @@ void SearchModel::SetMode(const SearchMode& new_mode) {
}
void SearchModel::SetInstantSupportState(InstantSupportState instant_support) {
- DCHECK(chrome::IsInstantExtendedAPIEnabled())
+ DCHECK(search::IsInstantExtendedAPIEnabled())
<< "Please do not try to set the SearchModel state without first "
<< "checking if Search is enabled.";
@@ -76,7 +76,7 @@ void SearchModel::SetInstantSupportState(InstantSupportState instant_support) {
}
void SearchModel::SetVoiceSearchSupported(bool supported) {
- DCHECK(chrome::IsInstantExtendedAPIEnabled())
+ DCHECK(search::IsInstantExtendedAPIEnabled())
<< "Please do not try to set the SearchModel state without first "
<< "checking if Search is enabled.";
diff --git a/chrome/browser/ui/search/search_tab_helper.cc b/chrome/browser/ui/search/search_tab_helper.cc
index 7fce7b7..7c2daac 100644
--- a/chrome/browser/ui/search/search_tab_helper.cc
+++ b/chrome/browser/ui/search/search_tab_helper.cc
@@ -60,8 +60,8 @@ namespace {
bool IsCacheableNTP(const content::WebContents* contents) {
const content::NavigationEntry* entry =
contents->GetController().GetLastCommittedEntry();
- return chrome::NavEntryIsInstantNTP(contents, entry) &&
- entry->GetURL() != GURL(chrome::kChromeSearchLocalNtpUrl);
+ return search::NavEntryIsInstantNTP(contents, entry) &&
+ entry->GetURL() != GURL(chrome::kChromeSearchLocalNtpUrl);
}
bool IsNTP(const content::WebContents* contents) {
@@ -72,11 +72,11 @@ bool IsNTP(const content::WebContents* contents) {
if (entry && entry->GetVirtualURL() == GURL(chrome::kChromeUINewTabURL))
return true;
- return chrome::IsInstantNTP(contents);
+ return search::IsInstantNTP(contents);
}
bool IsSearchResults(const content::WebContents* contents) {
- return !chrome::GetSearchTerms(contents).empty();
+ return !search::GetSearchTerms(contents).empty();
}
bool IsLocal(const content::WebContents* contents) {
@@ -143,7 +143,7 @@ bool OmniboxHasFocus(OmniboxView* omnibox) {
SearchTabHelper::SearchTabHelper(content::WebContents* web_contents)
: WebContentsObserver(web_contents),
- is_search_enabled_(chrome::IsInstantExtendedAPIEnabled()),
+ is_search_enabled_(search::IsInstantExtendedAPIEnabled()),
web_contents_(web_contents),
ipc_router_(web_contents,
this,
@@ -194,7 +194,7 @@ void SearchTabHelper::OmniboxFocusChanged(OmniboxFocusState state,
InstantSearchPrerenderer* prerenderer =
InstantSearchPrerenderer::GetForProfile(profile());
- if (!prerenderer || !chrome::ShouldPrerenderInstantUrlOnOmniboxFocus())
+ if (!prerenderer || !search::ShouldPrerenderInstantUrlOnOmniboxFocus())
return;
if (state == OMNIBOX_FOCUS_NONE) {
@@ -229,7 +229,7 @@ void SearchTabHelper::InstantSupportChanged(bool instant_support) {
content::NavigationEntry* entry =
web_contents_->GetController().GetLastCommittedEntry();
if (entry) {
- chrome::SetInstantSupportStateInNavigationEntry(new_state, entry);
+ search::SetInstantSupportStateInNavigationEntry(new_state, entry);
if (delegate_ && !instant_support)
delegate_->OnWebContentsInstantSupportDisabled(web_contents_);
}
@@ -253,7 +253,7 @@ void SearchTabHelper::OnTabActivated() {
ipc_router_.OnTabActivated();
OmniboxView* omnibox_view = GetOmniboxView();
- if (chrome::ShouldPrerenderInstantUrlOnOmniboxFocus() &&
+ if (search::ShouldPrerenderInstantUrlOnOmniboxFocus() &&
omnibox_has_focus_fn_(omnibox_view)) {
InstantSearchPrerenderer* prerenderer =
InstantSearchPrerenderer::GetForProfile(profile());
@@ -285,7 +285,7 @@ void SearchTabHelper::RenderViewCreated(
void SearchTabHelper::DidStartNavigationToPendingEntry(
const GURL& url,
content::NavigationController::ReloadType /* reload_type */) {
- if (chrome::IsNTPURL(url, profile())) {
+ if (search::IsNTPURL(url, profile())) {
// Set the title on any pending entry corresponding to the NTP. This
// prevents any flickering of the tab title.
content::NavigationEntry* entry =
@@ -300,8 +300,8 @@ void SearchTabHelper::DidNavigateMainFrame(
const content::FrameNavigateParams& params) {
if (IsCacheableNTP(web_contents_)) {
UMA_HISTOGRAM_ENUMERATION("InstantExtended.CacheableNTPLoad",
- chrome::CACHEABLE_NTP_LOAD_SUCCEEDED,
- chrome::CACHEABLE_NTP_LOAD_MAX);
+ search::CACHEABLE_NTP_LOAD_SUCCEEDED,
+ search::CACHEABLE_NTP_LOAD_MAX);
}
// Always set the title on the new tab page to be the one from our UI
@@ -318,7 +318,7 @@ void SearchTabHelper::DidNavigateMainFrame(
web_contents_->GetController().GetLastCommittedEntry();
if (entry && entry->GetTitle().empty() &&
(entry->GetVirtualURL() == GURL(chrome::kChromeUINewTabURL) ||
- chrome::NavEntryIsInstantNTP(web_contents_, entry))) {
+ search::NavEntryIsInstantNTP(web_contents_, entry))) {
entry->SetTitle(l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE));
}
}
@@ -326,7 +326,7 @@ void SearchTabHelper::DidNavigateMainFrame(
void SearchTabHelper::DidFinishLoad(content::RenderFrameHost* render_frame_host,
const GURL& /* validated_url */) {
if (!render_frame_host->GetParent()) {
- if (chrome::IsInstantNTP(web_contents_))
+ if (search::IsInstantNTP(web_contents_))
RecordNewTabLoadTime(web_contents_);
DetermineIfPageSupportsInstant();
@@ -341,7 +341,7 @@ void SearchTabHelper::NavigationEntryCommitted(
if (!load_details.is_main_frame)
return;
- if (chrome::ShouldAssignURLToInstantRenderer(web_contents_->GetURL(),
+ if (search::ShouldAssignURLToInstantRenderer(web_contents_->GetURL(),
profile())) {
InstantService* instant_service =
InstantServiceFactory::GetForProfile(profile());
@@ -363,7 +363,7 @@ void SearchTabHelper::NavigationEntryCommitted(
// support for the navigated page. So, copy over the Instant support from
// the previous entry. If the page does not support Instant, update the
// location bar from here to turn off search terms replacement.
- chrome::SetInstantSupportStateInNavigationEntry(model_.instant_support(),
+ search::SetInstantSupportStateInNavigationEntry(model_.instant_support(),
entry);
if (delegate_ && model_.instant_support() == INSTANT_SUPPORT_NO)
delegate_->OnWebContentsInstantSupportDisabled(web_contents_);
@@ -372,7 +372,7 @@ void SearchTabHelper::NavigationEntryCommitted(
model_.SetInstantSupportState(INSTANT_SUPPORT_UNKNOWN);
model_.SetVoiceSearchSupported(false);
- chrome::SetInstantSupportStateInNavigationEntry(model_.instant_support(),
+ search::SetInstantSupportStateInNavigationEntry(model_.instant_support(),
entry);
if (InInstantProcess(profile(), web_contents_))
diff --git a/chrome/browser/ui/search/search_tab_helper_unittest.cc b/chrome/browser/ui/search/search_tab_helper_unittest.cc
index f746dfb..08bf1cd 100644
--- a/chrome/browser/ui/search/search_tab_helper_unittest.cc
+++ b/chrome/browser/ui/search/search_tab_helper_unittest.cc
@@ -401,7 +401,7 @@ class SearchTabHelperPrerenderTest : public InstantUnitTestBase {
}
bool IsInstantURLMarkedForPrerendering() {
- GURL instant_url(chrome::GetSearchResultPrefetchBaseURL(profile()));
+ GURL instant_url(search::GetSearchResultPrefetchBaseURL(profile()));
prerender::PrerenderManager* prerender_manager =
prerender::PrerenderManagerFactory::GetForProfile(profile());
return prerender_manager->HasPrerenderedUrl(instant_url, web_contents());
diff --git a/chrome/browser/ui/singleton_tabs.cc b/chrome/browser/ui/singleton_tabs.cc
index 60cf852..7c450c4 100644
--- a/chrome/browser/ui/singleton_tabs.cc
+++ b/chrome/browser/ui/singleton_tabs.cc
@@ -49,7 +49,8 @@ void ShowSingletonTabOverwritingNTP(Browser* browser,
browser->tab_strip_model()->GetActiveWebContents();
if (contents) {
const GURL& contents_url = contents->GetURL();
- if ((contents_url == GURL(kChromeUINewTabURL) || IsInstantNTP(contents) ||
+ if ((contents_url == GURL(kChromeUINewTabURL) ||
+ search::IsInstantNTP(contents) ||
contents_url == GURL(url::kAboutBlankURL)) &&
GetIndexOfSingletonTab(&local_params) < 0) {
local_params.disposition = CURRENT_TAB;
diff --git a/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.cc b/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.cc
index 65c5ce9..1ef70ed 100644
--- a/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.cc
+++ b/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.cc
@@ -493,7 +493,7 @@ void RecentTabsSubMenuModel::BuildTabsFromOtherDevices() {
continue;
const sessions::SerializedNavigationEntry& current_navigation =
tab->navigations.at(tab->normalized_navigation_index());
- if (chrome::IsNTPURL(current_navigation.virtual_url(),
+ if (search::IsNTPURL(current_navigation.virtual_url(),
browser_->profile())) {
continue;
}
diff --git a/chrome/browser/ui/toolbar/toolbar_model_impl.cc b/chrome/browser/ui/toolbar/toolbar_model_impl.cc
index 6a17942..083b11b 100644
--- a/chrome/browser/ui/toolbar/toolbar_model_impl.cc
+++ b/chrome/browser/ui/toolbar/toolbar_model_impl.cc
@@ -190,7 +190,7 @@ bool ToolbarModelImpl::ShouldDisplayURL() const {
}
}
- return !chrome::IsInstantNTP(delegate_->GetActiveWebContents());
+ return !search::IsInstantNTP(delegate_->GetActiveWebContents());
}
NavigationController* ToolbarModelImpl::GetNavigationController() const {
@@ -213,7 +213,7 @@ base::string16 ToolbarModelImpl::GetSearchTerms(bool ignore_editing) const {
return base::string16();
const WebContents* web_contents = delegate_->GetActiveWebContents();
- base::string16 search_terms(chrome::GetSearchTerms(web_contents));
+ base::string16 search_terms(search::GetSearchTerms(web_contents));
if (search_terms.empty()) {
// We mainly do this to enforce the subsequent DCHECK.
return base::string16();
diff --git a/chrome/browser/ui/toolbar/toolbar_model_impl.h b/chrome/browser/ui/toolbar/toolbar_model_impl.h
index 3c6396f..aa50896 100644
--- a/chrome/browser/ui/toolbar/toolbar_model_impl.h
+++ b/chrome/browser/ui/toolbar/toolbar_model_impl.h
@@ -58,7 +58,7 @@ class ToolbarModelImpl : public ChromeToolbarModel {
// Helper method to extract the profile from the navigation controller.
Profile* GetProfile() const;
- // Returns search terms as in chrome::GetSearchTerms() if such terms should
+ // Returns search terms as in search::GetSearchTerms() if such terms should
// appear in the omnibox (i.e. the page is sufficiently secure, search term
// replacement is enabled, editing is not in progress, etc.). If
// |ignore_editing| is true, the "editing not in progress" check is skipped.
diff --git a/chrome/browser/ui/toolbar/toolbar_model_unittest.cc b/chrome/browser/ui/toolbar/toolbar_model_unittest.cc
index c93f627..4963fb4 100644
--- a/chrome/browser/ui/toolbar/toolbar_model_unittest.cc
+++ b/chrome/browser/ui/toolbar/toolbar_model_unittest.cc
@@ -16,6 +16,7 @@
#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/browser_with_test_window_test.h"
#include "components/google/core/browser/google_switches.h"
+#include "components/search/search.h"
#include "components/toolbar/toolbar_model.h"
#include "components/variations/entropy_provider.h"
#include "content/public/browser/navigation_entry.h"
@@ -248,7 +249,7 @@ TEST_F(ToolbarModelTest, ShouldDisplayURL_QueryExtraction) {
AddTab(browser(), GURL(url::kAboutBlankURL));
// Before we enable instant extended, query extraction is disabled.
- EXPECT_FALSE(chrome::IsQueryExtractionEnabled())
+ EXPECT_FALSE(search::IsQueryExtractionEnabled())
<< "This test expects query extraction to be disabled.";
for (size_t i = 0; i < arraysize(test_items); ++i) {
const TestItem& test_item = test_items[i];
@@ -257,8 +258,8 @@ TEST_F(ToolbarModelTest, ShouldDisplayURL_QueryExtraction) {
false, test_item.should_display_url);
}
- chrome::EnableQueryExtractionForTesting();
- EXPECT_TRUE(chrome::IsQueryExtractionEnabled());
+ search::EnableQueryExtractionForTesting();
+ EXPECT_TRUE(search::IsQueryExtractionEnabled());
EXPECT_TRUE(browser()->toolbar_model()->url_replacement_enabled());
for (size_t i = 0; i < arraysize(test_items); ++i) {
const TestItem& test_item = test_items[i];
@@ -280,7 +281,7 @@ TEST_F(ToolbarModelTest, ShouldDisplayURL_QueryExtraction) {
// Verify that search terms are extracted while the page is loading.
TEST_F(ToolbarModelTest, SearchTermsWhileLoading) {
- chrome::EnableQueryExtractionForTesting();
+ search::EnableQueryExtractionForTesting();
AddTab(browser(), GURL(url::kAboutBlankURL));
// While loading, we should be willing to extract search terms.
@@ -306,7 +307,7 @@ TEST_F(ToolbarModelTest, SearchTermsWhileLoading) {
// search terms from URLs that start with that base URL even when they're not
// secure.
TEST_F(ToolbarModelTest, GoogleBaseURL) {
- chrome::EnableQueryExtractionForTesting();
+ search::EnableQueryExtractionForTesting();
AddTab(browser(), GURL(url::kAboutBlankURL));
// If the Google base URL wasn't specified on the command line, then if it's
@@ -332,7 +333,7 @@ TEST_F(PopupToolbarModelTest, ShouldDisplayURL) {
AddTab(browser(), GURL(url::kAboutBlankURL));
// Check with query extraction disabled.
- EXPECT_FALSE(chrome::IsQueryExtractionEnabled());
+ EXPECT_FALSE(search::IsQueryExtractionEnabled());
for (size_t i = 0; i < arraysize(test_items); ++i) {
const TestItem& test_item = test_items[i];
NavigateAndCheckText(test_item.url,
@@ -341,8 +342,8 @@ TEST_F(PopupToolbarModelTest, ShouldDisplayURL) {
}
// With query extraction enabled, search term replacement should be performed.
- chrome::EnableQueryExtractionForTesting();
- EXPECT_TRUE(chrome::IsQueryExtractionEnabled());
+ search::EnableQueryExtractionForTesting();
+ EXPECT_TRUE(search::IsQueryExtractionEnabled());
EXPECT_TRUE(browser()->toolbar_model()->url_replacement_enabled());
for (size_t i = 0; i < arraysize(test_items); ++i) {
const TestItem& test_item = test_items[i];
diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
index 44ba4d9..468e7e3 100644
--- a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
+++ b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
@@ -28,6 +28,7 @@
#include "components/omnibox/browser/autocomplete_input.h"
#include "components/omnibox/browser/autocomplete_match.h"
#include "components/omnibox/browser/omnibox_field_trial.h"
+#include "components/search/search.h"
#include "content/public/browser/web_contents.h"
#include "extensions/common/constants.h"
#include "net/base/escape.h"
@@ -1063,7 +1064,7 @@ void OmniboxViewViews::UpdateContextMenu(ui::SimpleMenuModel* menu_contents) {
menu_contents->AddSeparator(ui::NORMAL_SEPARATOR);
- if (chrome::IsQueryExtractionEnabled()) {
+ if (search::IsQueryExtractionEnabled()) {
int select_all_position = menu_contents->GetIndexOfCommandId(
IDS_APP_SELECT_ALL);
DCHECK_GE(select_all_position, 0);
diff --git a/chrome/browser/ui/views/tabs/browser_tab_strip_controller.cc b/chrome/browser/ui/views/tabs/browser_tab_strip_controller.cc
index ddce28b..661fffa 100644
--- a/chrome/browser/ui/views/tabs/browser_tab_strip_controller.cc
+++ b/chrome/browser/ui/views/tabs/browser_tab_strip_controller.cc
@@ -269,7 +269,7 @@ bool BrowserTabStripController::IsNewTabPage(int model_index) const {
const WebContents* contents = model_->GetWebContentsAt(model_index);
return contents && (contents->GetURL() == GURL(chrome::kChromeUINewTabURL) ||
- chrome::IsInstantNTP(contents));
+ search::IsInstantNTP(contents));
}
void BrowserTabStripController::SelectTab(int model_index) {
diff --git a/chrome/browser/ui/webui/history_ui.cc b/chrome/browser/ui/webui/history_ui.cc
index 687bca4..0fd41b3 100644
--- a/chrome/browser/ui/webui/history_ui.cc
+++ b/chrome/browser/ui/webui/history_ui.cc
@@ -209,7 +209,7 @@ content::WebUIDataSource* CreateHistoryUIHTMLSource(Profile* profile) {
prefs->GetBoolean(prefs::kAllowDeletingBrowserHistory);
source->AddBoolean("allowDeletingHistory", allow_deleting_history);
source->AddBoolean("isInstantExtendedApiEnabled",
- chrome::IsInstantExtendedAPIEnabled());
+ search::IsInstantExtendedAPIEnabled());
source->AddBoolean("isSupervisedProfile", profile->IsSupervised());
source->AddBoolean("hideDeleteVisitUI",
profile->IsSupervised() && !allow_deleting_history);
@@ -1037,7 +1037,7 @@ HistoryUI::HistoryUI(content::WebUI* web_ui) : WebUIController(web_ui) {
// On mobile we deal with foreign sessions differently.
#if !defined(OS_ANDROID) && !defined(OS_IOS)
- if (chrome::IsInstantExtendedAPIEnabled()) {
+ if (search::IsInstantExtendedAPIEnabled()) {
web_ui->AddMessageHandler(new browser_sync::ForeignSessionHandler());
web_ui->AddMessageHandler(new HistoryLoginHandler());
}
diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi
index e4fe38f..232024f 100644
--- a/chrome/chrome_tests_unit.gypi
+++ b/chrome/chrome_tests_unit.gypi
@@ -219,7 +219,6 @@
'browser/search/instant_unittest_base.cc',
'browser/search/instant_unittest_base.h',
'browser/search/most_visited_iframe_source_unittest.cc',
- 'browser/search/search_android_unittest.cc',
'browser/search_engines/search_provider_install_data_unittest.cc',
'browser/service_process/service_process_control_mac_unittest.mm',
'browser/services/gcm/fake_gcm_profile_service.cc',
diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc
index 455b2bb..e2f0115 100644
--- a/chrome/common/chrome_switches.cc
+++ b/chrome/common/chrome_switches.cc
@@ -506,9 +506,6 @@ const char kEnablePrintPreviewRegisterPromos[] =
// during chrome_browser_main.
const char kEnableProfiling[] = "enable-profiling";
-// Enables query in the omnibox.
-const char kEnableQueryExtraction[] = "enable-query-extraction";
-
// Enables support for the QUIC protocol. This is a temporary testing flag.
const char kEnableQuic[] = "enable-quic";
@@ -1215,10 +1212,6 @@ const char kEnableZeroSuggestMostVisited[] =
const char kEnableZeroSuggestMostVisitedWithoutSerp[] =
"enable-zero-suggest-most-visited-without-serp";
-// Triggers prerendering of search base page to prefetch results for the typed
-// omnibox query. Only has an effect when prerender is enabled.
-const char kPrefetchSearchResults[] = "prefetch-search-results";
-
// Specifies Android phone page loading progress bar animation.
const char kProgressBarAnimation[] = "progress-bar-animation";
#endif // defined(OS_ANDROID)
diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h
index 308e08f..d3ae812 100644
--- a/chrome/common/chrome_switches.h
+++ b/chrome/common/chrome_switches.h
@@ -146,7 +146,6 @@ extern const char kEnablePotentiallyAnnoyingSecurityFeatures[];
extern const char kEnablePowerOverlay[];
extern const char kEnablePrintPreviewRegisterPromos[];
extern const char kEnableProfiling[];
-extern const char kEnableQueryExtraction[];
extern const char kEnableQuic[];
extern const char kEnableQuicPortSelection[];
extern const char kEnableSavePasswordBubble[];
@@ -336,7 +335,6 @@ extern const char kEnableHostedMode[];
extern const char kEnableReaderModeToolbarIcon[];
extern const char kEnableZeroSuggestMostVisited[];
extern const char kEnableZeroSuggestMostVisitedWithoutSerp[];
-extern const char kPrefetchSearchResults[];
extern const char kProgressBarAnimation[];
#endif // defined(OS_ANDROID)
diff --git a/chrome/renderer/searchbox/search_bouncer.h b/chrome/renderer/searchbox/search_bouncer.h
index aa551e4..d84aacf 100644
--- a/chrome/renderer/searchbox/search_bouncer.h
+++ b/chrome/renderer/searchbox/search_bouncer.h
@@ -26,7 +26,7 @@ class SearchBouncer : public content::RenderProcessObserver {
static SearchBouncer* GetInstance();
// Returns whether a navigation to |url| should bounce back to the browser as
- // a potential Instant url. See chrome::ShouldAssignURLToInstantRenderer().
+ // a potential Instant url. See search::ShouldAssignURLToInstantRenderer().
bool ShouldFork(const GURL& url) const;
// Returns whether |url| is a valid Instant new tab page URL.
diff --git a/components/omnibox/browser/omnibox_field_trial.cc b/components/omnibox/browser/omnibox_field_trial.cc
index 9bda3e2..7552795 100644
--- a/components/omnibox/browser/omnibox_field_trial.cc
+++ b/components/omnibox/browser/omnibox_field_trial.cc
@@ -497,7 +497,7 @@ std::string OmniboxFieldTrial::GetValueForRuleInContext(
const std::string page_classification_str =
base::IntToString(static_cast<int>(page_classification));
const std::string instant_extended =
- chrome::IsInstantExtendedAPIEnabled() ? "1" : "0";
+ search::IsInstantExtendedAPIEnabled() ? "1" : "0";
// Look up rule in this exact context.
VariationParams::const_iterator it = params.find(
rule + ":" + page_classification_str + ":" + instant_extended);
diff --git a/components/omnibox/browser/omnibox_field_trial_unittest.cc b/components/omnibox/browser/omnibox_field_trial_unittest.cc
index 0ed85a7..a7fc148 100644
--- a/components/omnibox/browser/omnibox_field_trial_unittest.cc
+++ b/components/omnibox/browser/omnibox_field_trial_unittest.cc
@@ -318,7 +318,7 @@ TEST_F(OmniboxFieldTrialTest, GetValueForRuleInContext) {
base::FieldTrialList::CreateFieldTrial(
OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A");
- if (chrome::IsInstantExtendedAPIEnabled()) {
+ if (search::IsInstantExtendedAPIEnabled()) {
// Tests with Instant Extended enabled.
// Tests for rule 1.
ExpectRuleValue("rule1-4-1-value",
diff --git a/components/omnibox/browser/search_provider.cc b/components/omnibox/browser/search_provider.cc
index 6272c2f..9067f859 100644
--- a/components/omnibox/browser/search_provider.cc
+++ b/components/omnibox/browser/search_provider.cc
@@ -1003,7 +1003,7 @@ void SearchProvider::ConvertResultsToAutocompleteMatches() {
// If we've already hit the limit on non-server-scored suggestions, and
// this isn't a server-scored suggestion we can add, skip it.
if ((num_suggestions >= kMaxMatches) &&
- (!chrome::IsInstantExtendedAPIEnabled() ||
+ (!search::IsInstantExtendedAPIEnabled() ||
(i->GetAdditionalInfo(kRelevanceFromServerKey) != kTrue))) {
continue;
}
diff --git a/components/search.gypi b/components/search.gypi
index 8cb0fe7..5c79aa7 100644
--- a/components/search.gypi
+++ b/components/search.gypi
@@ -8,7 +8,10 @@
'target_name': 'search',
'type': 'static_library',
'dependencies': [
- '../base/base.gyp:base'
+ '../base/base.gyp:base',
+ '../url/url.gyp:url_lib',
+ 'google_core_browser',
+ 'search_engines',
],
'include_dirs': [
'..',
diff --git a/components/search/BUILD.gn b/components/search/BUILD.gn
index a895701..21c49c4d 100644
--- a/components/search/BUILD.gn
+++ b/components/search/BUILD.gn
@@ -12,5 +12,8 @@ static_library("search") {
deps = [
"//base",
+ "//components/google/core/browser",
+ "//components/search_engines",
+ "//url",
]
}
diff --git a/components/search/DEPS b/components/search/DEPS
index 80f6f90..d9bc813 100644
--- a/components/search/DEPS
+++ b/components/search/DEPS
@@ -1,3 +1,5 @@
include_rules = [
+ "+components/google/core",
+ "+components/search_engines",
"+components/variations",
]
diff --git a/components/search/search.cc b/components/search/search.cc
index 92b8ccb..654ec55 100644
--- a/components/search/search.cc
+++ b/components/search/search.cc
@@ -10,9 +10,12 @@
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
+#include "components/google/core/browser/google_util.h"
#include "components/search/search_switches.h"
+#include "components/search_engines/template_url.h"
+#include "url/gurl.h"
-namespace chrome {
+namespace search {
namespace {
@@ -49,8 +52,25 @@ const char kEmbeddedSearchFieldTrialName[] = "EmbeddedSearch";
// be ignored and Instant Extended will not be enabled by default.
const char kDisablingSuffix[] = "DISABLED";
+#if !defined(OS_IOS) && !defined(OS_ANDROID)
+const char kEnableQueryExtractionFlagName[] = "query_extraction";
+#endif
+
+const char kAllowPrefetchNonDefaultMatch[] = "allow_prefetch_non_default_match";
+
+#if defined(OS_ANDROID)
+const char kPrefetchSearchResultsFlagName[] = "prefetch_results";
+
+// Controls whether to reuse prerendered Instant Search base page to commit any
+// search query.
+const char kReuseInstantSearchBasePage[] = "reuse_instant_search_base_page";
+#endif
+
} // namespace
+// Negative start-margin values prevent the "es_sm" parameter from being used.
+const int kDisableStartMargin = -1;
+
bool IsInstantExtendedAPIEnabled() {
#if defined(OS_IOS)
return false;
@@ -144,4 +164,94 @@ bool GetBoolValueForFlagWithDefault(const std::string& flag,
return !!GetUInt64ValueForFlagWithDefault(flag, default_value ? 1 : 0, flags);
}
-} // namespace chrome
+std::string InstantExtendedEnabledParam(bool for_search) {
+ if (for_search && !IsQueryExtractionEnabled())
+ return std::string();
+ return std::string(google_util::kInstantExtendedAPIParam) + "=" +
+ base::Uint64ToString(EmbeddedSearchPageVersion()) + "&";
+}
+
+std::string ForceInstantResultsParam(bool for_prerender) {
+ return (for_prerender || !IsInstantExtendedAPIEnabled()) ? "ion=1&"
+ : std::string();
+}
+
+bool IsQueryExtractionEnabled() {
+#if defined(OS_IOS) || defined(OS_ANDROID)
+ return true;
+#else
+ if (!IsInstantExtendedAPIEnabled())
+ return false;
+
+ const base::CommandLine* command_line =
+ base::CommandLine::ForCurrentProcess();
+ if (command_line->HasSwitch(switches::kEnableQueryExtraction))
+ return true;
+
+ FieldTrialFlags flags;
+ return GetFieldTrialInfo(&flags) &&
+ GetBoolValueForFlagWithDefault(kEnableQueryExtractionFlagName, false,
+ flags);
+#endif // defined(OS_IOS) || defined(OS_ANDROID)
+}
+
+bool ShouldPrefetchSearchResults() {
+ if (!IsInstantExtendedAPIEnabled())
+ return false;
+
+#if defined(OS_ANDROID)
+ if (base::CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kPrefetchSearchResults)) {
+ return true;
+ }
+
+ FieldTrialFlags flags;
+ return GetFieldTrialInfo(&flags) &&
+ GetBoolValueForFlagWithDefault(kPrefetchSearchResultsFlagName, false,
+ flags);
+#else
+ return true;
+#endif
+}
+
+bool ShouldReuseInstantSearchBasePage() {
+ if (!ShouldPrefetchSearchResults())
+ return false;
+
+#if defined(OS_ANDROID)
+ FieldTrialFlags flags;
+ return GetFieldTrialInfo(&flags) &&
+ GetBoolValueForFlagWithDefault(kReuseInstantSearchBasePage, false,
+ flags);
+#else
+ return true;
+#endif
+}
+
+bool ShouldAllowPrefetchNonDefaultMatch() {
+ if (!ShouldPrefetchSearchResults())
+ return false;
+
+ FieldTrialFlags flags;
+ return GetFieldTrialInfo(&flags) &&
+ GetBoolValueForFlagWithDefault(kAllowPrefetchNonDefaultMatch, false,
+ flags);
+}
+
+// |url| should either have a secure scheme or have a non-HTTPS base URL that
+// the user specified using --google-base-url. (This allows testers to use
+// --google-base-url to point at non-HTTPS servers, which eases testing.)
+bool IsSuitableURLForInstant(const GURL& url, const TemplateURL* template_url) {
+ return template_url->HasSearchTermsReplacementKey(url) &&
+ (url.SchemeIsCryptographic() ||
+ google_util::StartsWithCommandLineGoogleBaseURL(url));
+}
+
+void EnableQueryExtractionForTesting() {
+#if !defined(OS_IOS) && !defined(OS_ANDROID)
+ base::CommandLine* cl = base::CommandLine::ForCurrentProcess();
+ cl->AppendSwitch(switches::kEnableQueryExtraction);
+#endif
+}
+
+} // namespace search
diff --git a/components/search/search.h b/components/search/search.h
index 0a7a55b..2ce6204 100644
--- a/components/search/search.h
+++ b/components/search/search.h
@@ -13,7 +13,14 @@
#include "base/strings/string16.h"
#include "base/strings/string_split.h"
-namespace chrome {
+class GURL;
+class TemplateURL;
+
+namespace search {
+
+// Use this value for "start margin" to prevent the "es_sm" parameter from
+// being used.
+extern const int kDisableStartMargin;
// Returns whether the Instant Extended API is enabled.
bool IsInstantExtendedAPIEnabled();
@@ -55,6 +62,52 @@ bool GetBoolValueForFlagWithDefault(const std::string& flag,
bool default_value,
const FieldTrialFlags& flags);
-} // namespace chrome
+// Returns a string indicating whether InstantExtended is enabled, suitable
+// for adding as a query string param to the homepage or search requests.
+// Returns an empty string otherwise.
+//
+// |for_search| should be set to true for search requests, in which case this
+// returns a non-empty string only if query extraction is enabled.
+std::string InstantExtendedEnabledParam(bool for_search);
+
+// Returns a string that will cause the search results page to update
+// incrementally. Currently, Instant Extended passes a different param to
+// search results pages that also has this effect, so by default this function
+// returns the empty string when Instant Extended is enabled. However, when
+// doing instant search result prerendering, we still need to pass this param,
+// as Instant Extended does not cause incremental updates by default for the
+// prerender page. Callers should set |for_prerender| in this case to force
+// the returned string to be non-empty.
+std::string ForceInstantResultsParam(bool for_prerender);
+
+// Returns whether query extraction is enabled.
+bool IsQueryExtractionEnabled();
+
+// Returns true if 'prefetch_results' flag is set to true in field trials to
+// prefetch high-confidence search suggestions.
+bool ShouldPrefetchSearchResults();
+
+// Returns true if 'reuse_instant_search_base_page' flag is set to true in field
+// trials to reuse the prerendered page to commit any search query.
+bool ShouldReuseInstantSearchBasePage();
+
+// Returns true if 'allow_prefetch_non_default_match' flag is enabled in field
+// trials to allow prefetching the suggestion marked to be prefetched by the
+// suggest server even if it is not the default match.
+bool ShouldAllowPrefetchNonDefaultMatch();
+
+// |url| should either have a secure scheme or have a non-HTTPS base URL that
+// the user specified using --google-base-url. (This allows testers to use
+// --google-base-url to point at non-HTTPS servers, which eases testing.)
+bool IsSuitableURLForInstant(const GURL& url, const TemplateURL* template_url);
+
+// -----------------------------------------------------
+// The following APIs are exposed for use in tests only.
+// -----------------------------------------------------
+
+// Forces query in the omnibox to be on for tests.
+void EnableQueryExtractionForTesting();
+
+} // namespace search
#endif // COMPONENTS_SEARCH_SEARCH_H_
diff --git a/components/search/search_android_unittest.cc b/components/search/search_android_unittest.cc
index 772daaf..f5c8320 100644
--- a/components/search/search_android_unittest.cc
+++ b/components/search/search_android_unittest.cc
@@ -8,11 +8,12 @@
#include "base/memory/scoped_ptr.h"
#include "base/metrics/field_trial.h"
#include "base/metrics/statistics_recorder.h"
+#include "components/search/search.h"
#include "components/search/search_switches.h"
#include "components/variations/entropy_provider.h"
#include "testing/gtest/include/gtest/gtest.h"
-namespace chrome {
+namespace search {
namespace {
@@ -25,6 +26,90 @@ TEST(SearchTest, EmbeddedSearchAPIEnabled) {
EXPECT_TRUE(IsInstantExtendedAPIEnabled());
}
+TEST(SearchTest, QueryExtractionEnabled) {
+ // Query extraction is always enabled on mobile.
+ EXPECT_TRUE(IsQueryExtractionEnabled());
+}
+
+class SearchUtilTest : public testing::Test {
+ protected:
+ void SetUp() override {
+ field_trial_list_.reset(
+ new base::FieldTrialList(new metrics::SHA1EntropyProvider("42")));
+ base::StatisticsRecorder::Initialize();
+ }
+
+ private:
+ scoped_ptr<base::FieldTrialList> field_trial_list_;
+};
+
+TEST_F(SearchUtilTest, UseDefaultEmbeddedSearchPageVersion) {
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
+ "EmbeddedSearch", "Group1 espv:-1 query_extraction:1"));
+ EXPECT_TRUE(IsQueryExtractionEnabled());
+ EXPECT_EQ("espv=1&", InstantExtendedEnabledParam(true));
+ EXPECT_EQ("espv=1&", InstantExtendedEnabledParam(false));
+}
+
+TEST_F(SearchUtilTest, ShouldPrefetchSearchResults_InstantExtendedAPIEnabled) {
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
+ "EmbeddedSearch", "Group1 espv:2 prefetch_results:1"));
+ EXPECT_TRUE(ShouldPrefetchSearchResults());
+ EXPECT_TRUE(IsInstantExtendedAPIEnabled());
+ EXPECT_EQ(2ul, EmbeddedSearchPageVersion());
+}
+
+TEST_F(SearchUtilTest, ShouldPrefetchSearchResults_InstantExtendedAPIDisabled) {
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
+ "EmbeddedSearch", "Group1 espv:1 prefetch_results:1"));
+ EXPECT_FALSE(ShouldPrefetchSearchResults());
+ EXPECT_FALSE(IsInstantExtendedAPIEnabled());
+ EXPECT_EQ(1ul, EmbeddedSearchPageVersion());
+}
+
+TEST_F(SearchUtilTest, ShouldPrefetchSearchResults_DisabledViaFieldTrials) {
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
+ "EmbeddedSearch", "Group1 espv:2 prefetch_results:0"));
+ EXPECT_FALSE(ShouldPrefetchSearchResults());
+ EXPECT_EQ(2ul, EmbeddedSearchPageVersion());
+}
+
+TEST_F(SearchUtilTest, ShouldPrefetchSearchResults_EnabledViaCommandLine) {
+ base::CommandLine::ForCurrentProcess()->AppendSwitch(
+ switches::kPrefetchSearchResults);
+ // Command-line enable should override Finch.
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
+ "EmbeddedSearch", "Group1 espv:2 prefetch_results:0"));
+ EXPECT_TRUE(ShouldPrefetchSearchResults());
+ EXPECT_EQ(2ul, EmbeddedSearchPageVersion());
+}
+
+TEST_F(SearchUtilTest,
+ ShouldReuseInstantSearchBasePage_PrefetchResultsFlagDisabled) {
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
+ "EmbeddedSearch",
+ "Group1 espv:2 prefetch_results:0 reuse_instant_search_base_page:1"));
+ EXPECT_FALSE(ShouldPrefetchSearchResults());
+ EXPECT_FALSE(ShouldReuseInstantSearchBasePage());
+ EXPECT_EQ(2ul, EmbeddedSearchPageVersion());
+}
+
+TEST_F(SearchUtilTest, ShouldReuseInstantSearchBasePage_EnabledViaFieldTrial) {
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
+ "EmbeddedSearch",
+ "Group1 espv:2 prefetch_results:1 reuse_instant_search_base_page:1"));
+ EXPECT_TRUE(ShouldReuseInstantSearchBasePage());
+ EXPECT_EQ(2ul, EmbeddedSearchPageVersion());
+}
+
+TEST_F(SearchUtilTest, ShouldReuseInstantSearchBasePage_DisabledViaFieldTrial) {
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
+ "EmbeddedSearch",
+ "Group1 espv:2 prefetch_results:1 reuse_instant_search_base_page:0"));
+ EXPECT_FALSE(ShouldReuseInstantSearchBasePage());
+ EXPECT_EQ(2ul, EmbeddedSearchPageVersion());
+}
+
} // namespace
} // namespace chrome
diff --git a/components/search/search_switches.cc b/components/search/search_switches.cc
index 9359725..d3b80da 100644
--- a/components/search/search_switches.cc
+++ b/components/search/search_switches.cc
@@ -11,6 +11,17 @@ namespace switches {
// Enables EmbeddedSearch API in the search results page.
const char kEnableEmbeddedSearchAPI[] = "enable-embeddedsearch-api";
+// Triggers prerendering of search base page to prefetch results for the typed
+// omnibox query. Only has an effect when prerender is enabled.
+const char kPrefetchSearchResults[] = "prefetch-search-results";
+
+#endif
+
+#if !defined(OS_ANDROID) && !defined(OS_IOS)
+
+// Enables query in the omnibox.
+const char kEnableQueryExtraction[] = "enable-query-extraction";
+
#endif
} // namespace switches
diff --git a/components/search/search_switches.h b/components/search/search_switches.h
index 48b50c1..46208e07 100644
--- a/components/search/search_switches.h
+++ b/components/search/search_switches.h
@@ -11,6 +11,11 @@ namespace switches {
#if defined(OS_ANDROID)
extern const char kEnableEmbeddedSearchAPI[];
+extern const char kPrefetchSearchResults[];
+#endif
+
+#if !defined(OS_ANDROID) && !defined(OS_IOS)
+extern const char kEnableQueryExtraction[];
#endif
} // namespace switches
diff --git a/components/search/search_unittest.cc b/components/search/search_unittest.cc
index 2fd5a23..4a5db38 100644
--- a/components/search/search_unittest.cc
+++ b/components/search/search_unittest.cc
@@ -9,7 +9,7 @@
#include "components/variations/entropy_provider.h"
#include "testing/gtest/include/gtest/gtest.h"
-namespace chrome {
+namespace search {
class EmbeddedSearchFieldTrialTest : public testing::Test {
protected:
@@ -130,4 +130,110 @@ TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoControlFlags) {
EXPECT_EQ(3ul, flags.size());
}
-} // namespace chrome
+#if !defined(OS_IOS) && !defined(OS_ANDROID)
+typedef EmbeddedSearchFieldTrialTest SearchTest;
+
+TEST_F(SearchTest, ShouldPrefetchSearchResults_InstantExtendedAPIEnabled) {
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch",
+ "Group1 espv:2"));
+ EXPECT_EQ(2ul, EmbeddedSearchPageVersion());
+ EXPECT_TRUE(ShouldPrefetchSearchResults());
+}
+
+TEST_F(SearchTest, ShouldPrefetchSearchResults_Default) {
+ EXPECT_TRUE(ShouldPrefetchSearchResults());
+}
+
+TEST_F(SearchTest, ShouldReuseInstantSearchBasePage_Default) {
+ EXPECT_TRUE(ShouldReuseInstantSearchBasePage());
+}
+
+TEST_F(SearchTest, ShouldAllowPrefetchNonDefaultMatch_DisabledViaFieldTrial) {
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
+ "EmbeddedSearch", "Group1 espv:89 allow_prefetch_non_default_match:0"));
+ EXPECT_FALSE(ShouldAllowPrefetchNonDefaultMatch());
+ EXPECT_EQ(89ul, EmbeddedSearchPageVersion());
+}
+
+TEST_F(SearchTest, ShouldAllowPrefetchNonDefaultMatch_EnabledViaFieldTrial) {
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
+ "EmbeddedSearch", "Group1 espv:80 allow_prefetch_non_default_match:1"));
+ EXPECT_TRUE(ShouldAllowPrefetchNonDefaultMatch());
+ EXPECT_EQ(80ul, EmbeddedSearchPageVersion());
+}
+
+TEST_F(SearchTest, ForceInstantResultsParam) {
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch",
+ "Group1 espv:2"));
+ EXPECT_TRUE(IsInstantExtendedAPIEnabled());
+ EXPECT_EQ("ion=1&", ForceInstantResultsParam(true));
+ EXPECT_EQ(std::string(), ForceInstantResultsParam(false));
+}
+
+typedef EmbeddedSearchFieldTrialTest InstantExtendedEnabledParamTest;
+
+TEST_F(InstantExtendedEnabledParamTest, QueryExtractionDisabled) {
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch",
+ "Group1 espv:12"));
+ // Make sure InstantExtendedEnabledParam() returns an empty string for search
+ // requests.
+ EXPECT_FALSE(IsQueryExtractionEnabled());
+ EXPECT_EQ("", InstantExtendedEnabledParam(true));
+ EXPECT_EQ("espv=12&", InstantExtendedEnabledParam(false));
+}
+
+TEST_F(InstantExtendedEnabledParamTest, QueryExtractionEnabled) {
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
+ "EmbeddedSearch", "Group1 espv:10 query_extraction:1"));
+ EXPECT_TRUE(IsQueryExtractionEnabled());
+ // Make sure InstantExtendedEnabledParam() returns a non-empty param string
+ // for search requests.
+ EXPECT_EQ("espv=10&", InstantExtendedEnabledParam(true));
+ EXPECT_EQ("espv=10&", InstantExtendedEnabledParam(false));
+}
+
+TEST_F(InstantExtendedEnabledParamTest, UseDefaultEmbeddedSearchPageVersion) {
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
+ "EmbeddedSearch", "Group1 espv:-1 query_extraction:1"));
+ EXPECT_TRUE(IsQueryExtractionEnabled());
+ EXPECT_EQ("espv=2&", InstantExtendedEnabledParam(true));
+ EXPECT_EQ("espv=2&", InstantExtendedEnabledParam(false));
+}
+
+typedef EmbeddedSearchFieldTrialTest IsQueryExtractionEnabledTest;
+
+TEST_F(IsQueryExtractionEnabledTest, NotSet) {
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch",
+ "Group1 espv:2"));
+ EXPECT_TRUE(IsInstantExtendedAPIEnabled());
+ EXPECT_FALSE(IsQueryExtractionEnabled());
+ EXPECT_EQ(2ul, EmbeddedSearchPageVersion());
+}
+
+TEST_F(IsQueryExtractionEnabledTest, EnabledViaFieldTrial) {
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
+ "EmbeddedSearch", "Group1 espv:2 query_extraction:1"));
+ EXPECT_TRUE(IsInstantExtendedAPIEnabled());
+ EXPECT_TRUE(IsQueryExtractionEnabled());
+ EXPECT_EQ(2ul, EmbeddedSearchPageVersion());
+}
+
+TEST_F(IsQueryExtractionEnabledTest, DisabledViaFieldTrial) {
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
+ "EmbeddedSearch", "Group1 espv:2 query_extraction:0"));
+ EXPECT_TRUE(IsInstantExtendedAPIEnabled());
+ EXPECT_FALSE(IsQueryExtractionEnabled());
+ EXPECT_EQ(2ul, EmbeddedSearchPageVersion());
+}
+
+TEST_F(IsQueryExtractionEnabledTest, EnabledViaCommandLine) {
+ EnableQueryExtractionForTesting();
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
+ "EmbeddedSearch", "Group1 espv:2 query_extraction:0"));
+ EXPECT_TRUE(IsInstantExtendedAPIEnabled());
+ EXPECT_TRUE(IsQueryExtractionEnabled());
+ EXPECT_EQ(2ul, EmbeddedSearchPageVersion());
+}
+#endif // !defined(OS_IOS) && !defined(OS_ANDROID)
+
+} // namespace search
diff --git a/extensions/browser/guest_view/web_view/web_view_guest.cc b/extensions/browser/guest_view/web_view/web_view_guest.cc
index d37d355..96da091 100644
--- a/extensions/browser/guest_view/web_view/web_view_guest.cc
+++ b/extensions/browser/guest_view/web_view/web_view_guest.cc
@@ -1253,7 +1253,7 @@ content::WebContents* WebViewGuest::OpenURLFromTab(
// decides that a fork should happen. At the time of writing this comment,
// the only way a well behaving guest could hit this code path is if it
// navigates to a URL that's associated with the default search engine.
- // This list of URLs is generated by chrome::GetSearchURLs. Validity checks
+ // This list of URLs is generated by search::GetSearchURLs. Validity checks
// are performed inside LoadURLWithParams such that if the guest attempts
// to navigate to a URL that it is not allowed to navigate to, a 'loadabort'
// event will fire in the embedder, and the guest will be navigated to
diff --git a/ios/chrome/browser/search/search_util.cc b/ios/chrome/browser/search/search_util.cc
new file mode 100644
index 0000000..079c53f
--- /dev/null
+++ b/ios/chrome/browser/search/search_util.cc
@@ -0,0 +1,69 @@
+// Copyright 2015 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 "ios/chrome/browser/search/search_util.h"
+
+#include "components/search/search.h"
+#include "components/search_engines/template_url_service.h"
+#include "ios/chrome/browser/search_engines/template_url_service_factory.h"
+#include "ios/chrome/browser/search_engines/ui_thread_search_terms_data.h"
+#include "ios/public/provider/chrome/browser/browser_state/chrome_browser_state.h"
+#include "ios/web/public/navigation_item.h"
+#include "ios/web/public/navigation_manager.h"
+#include "ios/web/public/web_state/web_state.h"
+#include "url/gurl.h"
+
+namespace {
+
+TemplateURL* GetDefaultSearchProviderTemplateURL(
+ ios::ChromeBrowserState* browser_state) {
+ if (!browser_state)
+ return nullptr;
+
+ TemplateURLService* template_url_service =
+ ios::TemplateURLServiceFactory::GetForBrowserState(browser_state);
+ return template_url_service ? template_url_service->GetDefaultSearchProvider()
+ : nullptr;
+}
+
+} // namespace
+
+base::string16 ExtractSearchTermsFromURL(ios::ChromeBrowserState* browser_state,
+ const GURL& url) {
+ base::string16 search_terms;
+ TemplateURL* template_url =
+ GetDefaultSearchProviderTemplateURL(browser_state);
+ if (template_url) {
+ template_url->ExtractSearchTermsFromURL(
+ url, ios::UIThreadSearchTermsData(browser_state), &search_terms);
+ }
+ return search_terms;
+}
+
+bool IsQueryExtractionAllowedForURL(ios::ChromeBrowserState* browser_state,
+ const GURL& url) {
+ TemplateURL* template_url =
+ GetDefaultSearchProviderTemplateURL(browser_state);
+ return template_url && search::IsSuitableURLForInstant(url, template_url);
+}
+
+base::string16 GetSearchTerms(web::WebState* web_state) {
+ if (!web_state)
+ return base::string16();
+
+ web::NavigationItem* item =
+ web_state->GetNavigationManager()->GetVisibleItem();
+ if (!item)
+ return base::string16();
+
+ if (!search::IsQueryExtractionEnabled())
+ return base::string16();
+
+ ios::ChromeBrowserState* browser_state =
+ ios::ChromeBrowserState::FromBrowserState(web_state->GetBrowserState());
+ if (!IsQueryExtractionAllowedForURL(browser_state, item->GetVirtualURL()))
+ return base::string16();
+
+ return ExtractSearchTermsFromURL(browser_state, item->GetVirtualURL());
+}
diff --git a/ios/chrome/browser/search/search_util.h b/ios/chrome/browser/search/search_util.h
new file mode 100644
index 0000000..6cb0b00
--- /dev/null
+++ b/ios/chrome/browser/search/search_util.h
@@ -0,0 +1,42 @@
+// Copyright 2015 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 IOS_CHROME_BROWSER_SEARCH_SEARCH_UTIL_H_
+#define IOS_CHROME_BROWSER_SEARCH_SEARCH_UTIL_H_
+
+#include "base/strings/string16.h"
+
+class GURL;
+
+namespace ios {
+class ChromeBrowserState;
+}
+
+namespace web {
+class WebState;
+}
+
+// Extracts and returns search terms from |url|. Does not consider
+// IsQueryExtractionEnabled() and Instant support state of the page and does
+// not check for a privileged process, so most callers should use
+// GetSearchTerms() below instead.
+base::string16 ExtractSearchTermsFromURL(ios::ChromeBrowserState* browser_state,
+ const GURL& url);
+
+// Returns true if it is okay to extract search terms from |url|. |url| must
+// have a secure scheme and must contain the search terms replacement key for
+// the default search provider.
+bool IsQueryExtractionAllowedForURL(ios::ChromeBrowserState* browser_state,
+ const GURL& url);
+
+// Returns search terms if this WebState is a search results page. It looks
+// in the visible NavigationItem first, to see if search terms have already
+// been extracted. Failing that, it tries to extract search terms from the URL.
+//
+// Returns a blank string if search terms were not found, or if search terms
+// extraction is disabled for this WebState or BrowserState, or if |web_state|
+// does not support Instant.
+base::string16 GetSearchTerms(web::WebState* web_state);
+
+#endif // IOS_CHROME_BROWSER_SEARCH_SEARCH_UTIL_H_
diff --git a/ios/chrome/browser/search_engines/ui_thread_search_terms_data.cc b/ios/chrome/browser/search_engines/ui_thread_search_terms_data.cc
index 9468dd7..e09d36f 100644
--- a/ios/chrome/browser/search_engines/ui_thread_search_terms_data.cc
+++ b/ios/chrome/browser/search_engines/ui_thread_search_terms_data.cc
@@ -15,8 +15,6 @@
#include "ios/chrome/browser/google/google_brand.h"
#include "ios/chrome/browser/google/google_url_tracker_factory.h"
#include "ios/chrome/common/channel_info.h"
-#include "ios/public/provider/chrome/browser/chrome_browser_provider.h"
-#include "ios/public/provider/chrome/browser/search_provider.h"
#include "ios/web/public/web_thread.h"
#include "url/gurl.h"
@@ -83,7 +81,7 @@ std::string UIThreadSearchTermsData::GetSearchClient() const {
std::string UIThreadSearchTermsData::GetSuggestClient() const {
DCHECK(thread_checker_.CalledOnValidThread());
- return chrome::IsInstantExtendedAPIEnabled() ? "chrome-omni" : "chrome";
+ return search::IsInstantExtendedAPIEnabled() ? "chrome-omni" : "chrome";
}
std::string UIThreadSearchTermsData::GetSuggestRequestIdentifier() const {
@@ -93,37 +91,31 @@ std::string UIThreadSearchTermsData::GetSuggestRequestIdentifier() const {
bool UIThreadSearchTermsData::IsShowingSearchTermsOnSearchResultsPages() const {
DCHECK(thread_checker_.CalledOnValidThread());
- return chrome::IsInstantExtendedAPIEnabled() &&
- ios::GetChromeBrowserProvider()
- ->GetSearchProvider()
- ->IsQueryExtractionEnabled();
+ return search::IsInstantExtendedAPIEnabled() &&
+ search::IsQueryExtractionEnabled();
}
std::string UIThreadSearchTermsData::InstantExtendedEnabledParam(
bool for_search) const {
DCHECK(thread_checker_.CalledOnValidThread());
- return ios::GetChromeBrowserProvider()
- ->GetSearchProvider()
- ->InstantExtendedEnabledParam(for_search);
+ return search::InstantExtendedEnabledParam(for_search);
}
std::string UIThreadSearchTermsData::ForceInstantResultsParam(
bool for_prerender) const {
DCHECK(thread_checker_.CalledOnValidThread());
- return ios::GetChromeBrowserProvider()
- ->GetSearchProvider()
- ->ForceInstantResultsParam(for_prerender);
+ return search::ForceInstantResultsParam(for_prerender);
}
int UIThreadSearchTermsData::OmniboxStartMargin() const {
DCHECK(thread_checker_.CalledOnValidThread());
- return ios::GetChromeBrowserProvider()
- ->GetSearchProvider()
- ->OmniboxStartMargin();
+ // iOS has not InstantService.
+ return search::kDisableStartMargin;
}
std::string UIThreadSearchTermsData::NTPIsThemedParam() const {
DCHECK(thread_checker_.CalledOnValidThread());
+ // iOS does not supports themed NTP.
return std::string();
}
diff --git a/ios/chrome/ios_chrome.gyp b/ios/chrome/ios_chrome.gyp
index 7892a20..8d87468 100644
--- a/ios/chrome/ios_chrome.gyp
+++ b/ios/chrome/ios_chrome.gyp
@@ -273,6 +273,8 @@
'browser/prefs/pref_observer_bridge.h',
'browser/prefs/pref_observer_bridge.mm',
'browser/procedural_block_types.h',
+ 'browser/search/search_util.cc',
+ 'browser/search/search_util.h',
'browser/search_engines/search_engines_util.cc',
'browser/search_engines/search_engines_util.h',
'browser/search_engines/template_url_service_client_impl.cc',
diff --git a/ios/ios_tests.gyp b/ios/ios_tests.gyp
index a12b99b..4408588 100644
--- a/ios/ios_tests.gyp
+++ b/ios/ios_tests.gyp
@@ -12,8 +12,6 @@
'sources': [
# TODO(droger): Move most of these files to
# //ios/chrome/ios_chrome_tests.gyp, see http://crbug.com/437333
- 'public/test/fake_search_provider.cc',
- 'public/test/fake_search_provider.h',
'public/test/fake_string_provider.cc',
'public/test/fake_string_provider.h',
'public/test/fake_sync_service_factory.cc',
diff --git a/ios/provider/ios_provider_chrome.gyp b/ios/provider/ios_provider_chrome.gyp
index 4b8e648..8cb07fb 100644
--- a/ios/provider/ios_provider_chrome.gyp
+++ b/ios/provider/ios_provider_chrome.gyp
@@ -22,7 +22,6 @@
'../public/provider/chrome/browser/geolocation_updater_provider.mm',
'../public/provider/chrome/browser/keyed_service_provider.cc',
'../public/provider/chrome/browser/keyed_service_provider.h',
- '../public/provider/chrome/browser/search_provider.h',
'../public/provider/chrome/browser/string_provider.h',
'../public/provider/chrome/browser/ui/infobar_view_delegate.h',
'../public/provider/chrome/browser/ui/infobar_view_protocol.h',
diff --git a/ios/public/provider/chrome/browser/chrome_browser_provider.cc b/ios/public/provider/chrome/browser/chrome_browser_provider.cc
index dac40df..c3c9c0b 100644
--- a/ios/public/provider/chrome/browser/chrome_browser_provider.cc
+++ b/ios/public/provider/chrome/browser/chrome_browser_provider.cc
@@ -100,8 +100,4 @@ rappor::RapporService* ChromeBrowserProvider::GetRapporService() {
return nullptr;
}
-SearchProvider* ChromeBrowserProvider::GetSearchProvider() {
- return nullptr;
-}
-
} // namespace ios
diff --git a/ios/public/provider/chrome/browser/chrome_browser_provider.h b/ios/public/provider/chrome/browser/chrome_browser_provider.h
index e98cb1b..794ea5e 100644
--- a/ios/public/provider/chrome/browser/chrome_browser_provider.h
+++ b/ios/public/provider/chrome/browser/chrome_browser_provider.h
@@ -47,7 +47,6 @@ namespace ios {
class ChromeBrowserProvider;
class ChromeBrowserStateManager;
class GeolocationUpdaterProvider;
-class SearchProvider;
class StringProvider;
class UpdatableResourceProvider;
@@ -102,8 +101,6 @@ class ChromeBrowserProvider {
virtual std::string GetRiskData();
// Returns the RapporService. May be null.
virtual rappor::RapporService* GetRapporService();
- // Returns the SearchProvider.
- virtual SearchProvider* GetSearchProvider();
};
} // namespace ios
diff --git a/ios/public/provider/chrome/browser/search_provider.h b/ios/public/provider/chrome/browser/search_provider.h
deleted file mode 100644
index aaf825a..0000000
--- a/ios/public/provider/chrome/browser/search_provider.h
+++ /dev/null
@@ -1,50 +0,0 @@
-// Copyright 2015 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 IOS_PUBLIC_PROVIDER_CHROME_BROWSER_SEARCH_PROVIDER_H_
-#define IOS_PUBLIC_PROVIDER_CHROME_BROWSER_SEARCH_PROVIDER_H_
-
-#include <string>
-
-#include "base/macros.h"
-
-namespace ios {
-
-// SearchProvider provides accessor for search features not yet componentized.
-class SearchProvider {
- public:
- SearchProvider() {}
- virtual ~SearchProvider() {}
-
- // Returns whether query extraction is enabled.
- virtual bool IsQueryExtractionEnabled() = 0;
-
- // Returns a string indicating whether InstantExtended is enabled, suitable
- // for adding as a query parameter to the search requests. Returns an empty
- // string otherwise.
- //
- // |for_search| should be set to true for search requests, in which case this
- // returns a non-empty string only if query extraction is enabled.
- virtual std::string InstantExtendedEnabledParam(bool for_search) = 0;
-
- // Returns a string that will cause the search results page to update
- // incrementally. Currently, Instant Extended passes a different param to
- // search results pages that also has this effect, so by default this function
- // returns the empty string when Instant Extended is enabled. However, when
- // doing instant search result prerendering, we still need to pass this param,
- // as Instant Extended does not cause incremental updates by default for the
- // prerender page. Callers should set |for_prerender| in this case to force
- // the returned string to be non-empty.
- virtual std::string ForceInstantResultsParam(bool for_prerender) = 0;
-
- // Returns the start-edge margin of the omnibox in pixels.
- virtual int OmniboxStartMargin() = 0;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(SearchProvider);
-};
-
-} // namespace
-
-#endif // IOS_PUBLIC_PROVIDER_CHROME_BROWSER_SEARCH_PROVIDER_H_
diff --git a/ios/public/test/fake_search_provider.cc b/ios/public/test/fake_search_provider.cc
deleted file mode 100644
index d122485..0000000
--- a/ios/public/test/fake_search_provider.cc
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright 2015 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 "ios/public/test/fake_search_provider.h"
-
-namespace ios {
-
-FakeSearchProvider::FakeSearchProvider() {
-}
-
-FakeSearchProvider::~FakeSearchProvider() {
-}
-
-bool FakeSearchProvider::IsQueryExtractionEnabled() {
- return false;
-}
-
-std::string FakeSearchProvider::InstantExtendedEnabledParam(bool for_search) {
- return std::string();
-}
-
-std::string FakeSearchProvider::ForceInstantResultsParam(bool for_prerender) {
- return std::string();
-}
-
-int FakeSearchProvider::OmniboxStartMargin() {
- return 0;
-}
-
-} // namespace ios
diff --git a/ios/public/test/fake_search_provider.h b/ios/public/test/fake_search_provider.h
deleted file mode 100644
index 61046b8..0000000
--- a/ios/public/test/fake_search_provider.h
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright 2015 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 IOS_PUBLIC_TEST_FAKE_SEARCH_PROVIDER_H_
-#define IOS_PUBLIC_TEST_FAKE_SEARCH_PROVIDER_H_
-
-#include "ios/public/provider/chrome/browser/search_provider.h"
-
-namespace ios {
-
-class FakeSearchProvider : public ios::SearchProvider {
- public:
- FakeSearchProvider();
- ~FakeSearchProvider() override;
-
- private:
- // ios::SearchProvider implementation.
- bool IsQueryExtractionEnabled() override;
- std::string InstantExtendedEnabledParam(bool for_search) override;
- std::string ForceInstantResultsParam(bool for_prerender) override;
- int OmniboxStartMargin() override;
-
- DISALLOW_COPY_AND_ASSIGN(FakeSearchProvider);
-};
-
-} // namespace ios
-
-#endif // IOS_PUBLIC_TEST_FAKE_SEARCH_PROVIDER_H_
diff --git a/ios/public/test/test_chrome_browser_provider.h b/ios/public/test/test_chrome_browser_provider.h
index f3bf163..698fa65 100644
--- a/ios/public/test/test_chrome_browser_provider.h
+++ b/ios/public/test/test_chrome_browser_provider.h
@@ -11,7 +11,6 @@
namespace ios {
class FakeProfileOAuth2TokenServiceIOSProvider;
-class FakeSearchProvider;
class FakeStringProvider;
class TestChromeBrowserProvider : public ChromeBrowserProvider {
@@ -25,11 +24,9 @@ class TestChromeBrowserProvider : public ChromeBrowserProvider {
// ChromeBrowserProvider:
StringProvider* GetStringProvider() override;
const char* GetChromeUIScheme() override;
- SearchProvider* GetSearchProvider() override;
private:
scoped_ptr<FakeStringProvider> string_provider_;
- scoped_ptr<FakeSearchProvider> search_provider_;
DISALLOW_COPY_AND_ASSIGN(TestChromeBrowserProvider);
};
diff --git a/ios/public/test/test_chrome_browser_provider.mm b/ios/public/test/test_chrome_browser_provider.mm
index 48d2ace..afcf24c 100644
--- a/ios/public/test/test_chrome_browser_provider.mm
+++ b/ios/public/test/test_chrome_browser_provider.mm
@@ -5,7 +5,6 @@
#include "ios/public/test/test_chrome_browser_provider.h"
#include "base/logging.h"
-#include "ios/public/test/fake_search_provider.h"
#include "ios/public/test/fake_string_provider.h"
namespace {
@@ -15,8 +14,7 @@ const char kUIScheme[] = "uischeme";
namespace ios {
TestChromeBrowserProvider::TestChromeBrowserProvider()
- : string_provider_(new FakeStringProvider),
- search_provider_(new FakeSearchProvider) {
+ : string_provider_(new FakeStringProvider) {
}
TestChromeBrowserProvider::~TestChromeBrowserProvider() {
@@ -37,8 +35,4 @@ const char* TestChromeBrowserProvider::GetChromeUIScheme() {
return kUIScheme;
}
-SearchProvider* TestChromeBrowserProvider::GetSearchProvider() {
- return search_provider_.get();
-}
-
} // namespace ios