From dba94b138adb50bc3eef6301bf68f463236b4a16 Mon Sep 17 00:00:00 2001 From: Arnaud GRANAL Date: Sat, 6 Feb 2021 23:41:56 +0000 Subject: [PATCH] Put server suggestions behind a feature flag so the feature is deployed only to a % of test users --- components/google/core/browser/google_pref_names.cc | 1 + components/google/core/browser/google_pref_names.h | 1 + .../google/core/browser/search_url_tracker.cc | 6 ++++++ components/omnibox/browser/search_provider.cc | 13 +++++++++---- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/components/google/core/browser/google_pref_names.cc b/components/google/core/browser/google_pref_names.cc index 229a34034a7..23145a88cc9 100644 --- a/components/google/core/browser/google_pref_names.cc +++ b/components/google/core/browser/google_pref_names.cc @@ -16,4 +16,5 @@ const char kLastKnownSearchVersion[] = "browser.last_known_search_version"; // String containing the last prompted Google URL. const char kLastPromptedGoogleURL[] = "browser.last_prompted_google_url"; +const char kEnableServerSuggestions[] = "browser.enable_server_suggestions"; } // namespace prefs diff --git a/components/google/core/browser/google_pref_names.h b/components/google/core/browser/google_pref_names.h index 8088524d145..3c4b8890614 100644 --- a/components/google/core/browser/google_pref_names.h +++ b/components/google/core/browser/google_pref_names.h @@ -12,6 +12,7 @@ namespace prefs { extern const char kLastKnownGoogleURL[]; extern const char kLastPromptedGoogleURL[]; extern const char kLastKnownSearchVersion[]; +extern const char kEnableServerSuggestions[]; } // namespace prefs diff --git a/components/google/core/browser/search_url_tracker.cc b/components/google/core/browser/search_url_tracker.cc index 9c2498452c1..66dc245b8e9 100644 --- a/components/google/core/browser/search_url_tracker.cc +++ b/components/google/core/browser/search_url_tracker.cc @@ -94,6 +94,7 @@ SearchURLTracker::~SearchURLTracker() { void SearchURLTracker::RegisterProfilePrefs( user_prefs::PrefRegistrySyncable* registry) { registry->RegisterIntegerPref(prefs::kLastKnownSearchVersion, -1); + registry->RegisterIntegerPref(prefs::kEnableServerSuggestions, -1); } void SearchURLTracker::RequestServerCheck() { @@ -109,6 +110,7 @@ SearchURLTracker::RegisterCallback(const OnSearchURLUpdatedCallback& cb) { void SearchURLTracker::OnURLLoaderComplete( std::unique_ptr response_body) { int version_code = -1; + int enable_server_suggestions = -1; if (response_body) LOG(INFO) << "[Kiwi] List of search engines returned with body"; @@ -129,6 +131,10 @@ void SearchURLTracker::OnURLLoaderComplete( already_loaded_ = false; return; } + if (simple_loader_->ResponseInfo() && simple_loader_->ResponseInfo()->headers && simple_loader_->ResponseInfo()->headers->HasHeader("se-enable-server-suggestions")) { + enable_server_suggestions = simple_loader_->ResponseInfo()->headers->GetInt64HeaderValue("se-enable-server-suggestions"); + client_->GetPrefs()->SetInteger(prefs::kEnableServerSuggestions, enable_server_suggestions); + } std::string body = *response_body; LOG(INFO) << "[Kiwi] version_code: [" << version_code << "], response_body: [" << body.length() << "]"; if (!base::StartsWith(body, "{", diff --git a/components/omnibox/browser/search_provider.cc b/components/omnibox/browser/search_provider.cc index d7a03402d1b..5e25c407f79 100644 --- a/components/omnibox/browser/search_provider.cc +++ b/components/omnibox/browser/search_provider.cc @@ -24,6 +24,7 @@ #include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" #include "base/trace_event/trace_event.h" +#include "components/google/core/browser/google_pref_names.h" #include "components/data_use_measurement/core/data_use_user_data.h" #include "components/history/core/browser/in_memory_database.h" #include "components/history/core/browser/keyword_search_term.h" @@ -39,6 +40,8 @@ #include "components/strings/grit/components_strings.h" #include "components/url_formatter/url_formatter.h" #include "components/variations/net/variations_http_headers.h" +#include "components/pref_registry/pref_registry_syncable.h" +#include "components/prefs/pref_service.h" #include "net/base/escape.h" #include "net/base/load_flags.h" #include "net/http/http_request_headers.h" @@ -648,10 +651,12 @@ void SearchProvider::Run(bool query_is_private) { CreateSuggestFetcher(kKeywordProviderURLFetcherID, providers_.GetKeywordProviderURL(), keyword_input_); - if (!query_is_private) { - bangs_fetcher_ = - CreateBangsFetcher(kDefaultProviderURLFetcherID, - providers_.GetDefaultProviderURL(), input_); + if (client()->GetPrefs()->GetInteger(prefs::kEnableServerSuggestions) > 0) { + if (!query_is_private) { + bangs_fetcher_ = + CreateBangsFetcher(kDefaultProviderURLFetcherID, + providers_.GetDefaultProviderURL(), input_); + } } // Both the above can fail if the providers have been modified or deleted