Commit fb1a8eac authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Move functionality only used by ZeroSuggestProvider out of BaseSearchProvider.

This requires exposing a previously-local-to-the-file function as protected, but
this seems like an OK tradeoff.

In the process, also rejiggered a few things (e.g. eliminated a file-scope using
directive).

BUG=none
TEST=none

Change-Id: I5fafda5ce264370cbe6d67e39f24c58fef7543ee
Reviewed-on: https://chromium-review.googlesource.com/792123
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarMark Pearson <mpearson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#519530}
parent 4ade6b1b
......@@ -26,23 +26,9 @@
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "net/url_request/url_fetcher.h"
#include "net/url_request/url_fetcher_delegate.h"
#include "third_party/metrics_proto/omnibox_event.pb.h"
#include "third_party/metrics_proto/omnibox_input_type.pb.h"
#include "url/gurl.h"
using metrics::OmniboxEventProto;
namespace {
bool IsNTPPage(OmniboxEventProto::PageClassification page_classification) {
return (page_classification == OmniboxEventProto::NTP) ||
(page_classification == OmniboxEventProto::OBSOLETE_INSTANT_NTP) ||
(page_classification ==
OmniboxEventProto::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS) ||
(page_classification ==
OmniboxEventProto::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS);
}
} // namespace
// SuggestionDeletionHandler -------------------------------------------------
// This class handles making requests to the server in order to delete
......@@ -224,23 +210,14 @@ const char BaseSearchProvider::kFalse[] = "false";
BaseSearchProvider::~BaseSearchProvider() {}
void BaseSearchProvider::SetDeletionURL(const std::string& deletion_url,
AutocompleteMatch* match) {
if (deletion_url.empty())
return;
TemplateURLService* template_url_service = client_->GetTemplateURLService();
if (!template_url_service)
return;
GURL url =
template_url_service->GetDefaultSearchProvider()->GenerateSearchURL(
template_url_service->search_terms_data());
url = url.GetOrigin().Resolve(deletion_url);
if (url.is_valid()) {
match->RecordAdditionalInfo(BaseSearchProvider::kDeletionUrlKey,
url.spec());
match->deletable = true;
}
// static
bool BaseSearchProvider::IsNTPPage(
metrics::OmniboxEventProto::PageClassification classification) {
using OEP = metrics::OmniboxEventProto;
return (classification == OEP::NTP) ||
(classification == OEP::OBSOLETE_INSTANT_NTP) ||
(classification == OEP::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS) ||
(classification == OEP::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS);
}
// static
......@@ -330,29 +307,12 @@ AutocompleteMatch BaseSearchProvider::CreateSearchSuggestion(
return match;
}
// static
bool BaseSearchProvider::ZeroSuggestEnabled(
OmniboxEventProto::PageClassification page_classification,
const AutocompleteProviderClient* client) {
// Don't show zero suggest on the NTP.
// TODO(hfung): Experiment with showing MostVisited zero suggest on NTP
// under the conditions described in crbug.com/305366.
if (IsNTPPage(page_classification))
return false;
// Don't run if in incognito mode.
if (client->IsOffTheRecord())
return false;
return true;
}
// static
bool BaseSearchProvider::CanSendURL(
const GURL& current_page_url,
const GURL& suggest_url,
const TemplateURL* template_url,
OmniboxEventProto::PageClassification page_classification,
metrics::OmniboxEventProto::PageClassification page_classification,
const SearchTermsData& search_terms_data,
AutocompleteProviderClient* client) {
// Make sure we are sending the suggest request through a cryptographically
......@@ -405,6 +365,25 @@ bool BaseSearchProvider::CanSendURL(
return true;
}
void BaseSearchProvider::SetDeletionURL(const std::string& deletion_url,
AutocompleteMatch* match) {
if (deletion_url.empty())
return;
TemplateURLService* template_url_service = client_->GetTemplateURLService();
if (!template_url_service)
return;
GURL url =
template_url_service->GetDefaultSearchProvider()->GenerateSearchURL(
template_url_service->search_terms_data());
url = url.GetOrigin().Resolve(deletion_url);
if (url.is_valid()) {
match->RecordAdditionalInfo(BaseSearchProvider::kDeletionUrlKey,
url.spec());
match->deletable = true;
}
}
void BaseSearchProvider::AddMatchToMap(
const SearchSuggestionParser::SuggestResult& result,
const std::string& metadata,
......
......@@ -102,6 +102,10 @@ class BaseSearchProvider : public AutocompleteProvider {
typedef std::vector<std::unique_ptr<SuggestionDeletionHandler>>
SuggestionDeletionHandlers;
// Returns whether the provided classification indicates some sort of NTP.
static bool IsNTPPage(
metrics::OmniboxEventProto::PageClassification classification);
// Returns an AutocompleteMatch with the given |autocomplete_provider|
// for the search |suggestion|, which represents a search via |template_url|.
// If |template_url| is NULL, returns a match with an invalid destination URL.
......@@ -128,15 +132,6 @@ class BaseSearchProvider : public AutocompleteProvider {
int accepted_suggestion,
bool append_extra_query_params);
// Returns whether the requirements for requesting zero suggest results
// are met. The requirements are
// * The user is enrolled in a zero suggest experiment.
// * The user is not on the NTP.
// * The user is not in incognito mode. (Incognito disables suggest entirely.)
static bool ZeroSuggestEnabled(
metrics::OmniboxEventProto::PageClassification page_classification,
const AutocompleteProviderClient* client);
// Returns whether we can send the URL of the current page in any suggest
// requests. Doing this requires that all the following hold:
// * The suggest request is sent over HTTPS. This avoids leaking the current
......
......@@ -503,7 +503,14 @@ AutocompleteMatch ZeroSuggestProvider::MatchForCurrentURL() {
bool ZeroSuggestProvider::ShouldShowNonContextualZeroSuggest(
const GURL& current_page_url) const {
if (!ZeroSuggestEnabled(current_page_classification_, client()))
// Don't show zero suggest on the NTP.
// TODO(hfung): Experiment with showing MostVisited zero suggest on NTP
// under the conditions described in crbug.com/305366.
if (IsNTPPage(current_page_classification_))
return false;
// Don't run if in incognito mode.
if (client()->IsOffTheRecord())
return false;
// If we cannot send URLs, then only the MostVisited and Personalized
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment