Skip to content

Commit

Permalink
Put server suggestions behind a feature flag so the feature is deploy…
Browse files Browse the repository at this point in the history
…ed only to a % of test users
  • Loading branch information
kiwibrowser committed Feb 6, 2021
1 parent f195a43 commit dba94b1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions components/google/core/browser/google_pref_names.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions components/google/core/browser/google_pref_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace prefs {
extern const char kLastKnownGoogleURL[];
extern const char kLastPromptedGoogleURL[];
extern const char kLastKnownSearchVersion[];
extern const char kEnableServerSuggestions[];

} // namespace prefs

Expand Down
6 changes: 6 additions & 0 deletions components/google/core/browser/search_url_tracker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -109,6 +110,7 @@ SearchURLTracker::RegisterCallback(const OnSearchURLUpdatedCallback& cb) {
void SearchURLTracker::OnURLLoaderComplete(
std::unique_ptr<std::string> response_body) {
int version_code = -1;
int enable_server_suggestions = -1;

if (response_body)
LOG(INFO) << "[Kiwi] List of search engines returned with body";
Expand All @@ -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, "{",
Expand Down
13 changes: 9 additions & 4 deletions components/omnibox/browser/search_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit dba94b1

Please sign in to comment.