Commit 04206cd3 authored by Moe Ahmadi's avatar Moe Ahmadi Committed by Commit Bot

[omnibox] Allows zero-prefix suggestions in NTP realbox

- Adds NTP_REALBOX page classification to BaseSearchProvider::IsNTPPage()
  and makes it a public static method to use in AutocompleteResult.
- Makes the logic to fall back to most visited site for zero suggest
  mobile only as there are currently no zero suggest experiments on
  Desktop and CrOS is handled differently.

Bug: 996516
Change-Id: I25c33ea961a0afb53abe33f3326696160c6dc3f9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1767605
Commit-Queue: Moe Ahmadi <mahmadi@chromium.org>
Reviewed-by: default avatarTommy Li <tommycli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#689996}
parent 6446ad0b
......@@ -22,6 +22,7 @@
#include "components/omnibox/browser/autocomplete_match.h"
#include "components/omnibox/browser/autocomplete_provider.h"
#include "components/omnibox/browser/autocomplete_provider_client.h"
#include "components/omnibox/browser/base_search_provider.h"
#include "components/omnibox/browser/match_compare.h"
#include "components/omnibox/browser/omnibox_pedal.h"
#include "components/omnibox/browser/omnibox_pedal_provider.h"
......@@ -167,11 +168,12 @@ void AutocompleteResult::SortAndCull(
#if !(defined(OS_ANDROID) || defined(OS_IOS))
// Do not cull the tail suggestions for zero prefix query suggetions of
// chromeOS launcher case, since there won't be any default match in this
// chromeOS launcher or NTP, since there won't be any default match in this
// scenario.
if (!(input.text().empty() &&
input.current_page_classification() ==
metrics::OmniboxEventProto::CHROMEOS_APP_LIST)) {
(input.current_page_classification() ==
metrics::OmniboxEventProto::CHROMEOS_APP_LIST ||
BaseSearchProvider::IsNTPPage(input.current_page_classification())))) {
// Wipe tail suggestions if not exclusive (minus default match).
MaybeCullTailSuggestions(&matches_);
}
......
......@@ -205,6 +205,17 @@ void BaseSearchProvider::AppendSuggestClientToAdditionalQueryParams(
}
}
// 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) ||
(classification == OEP::NTP_REALBOX);
}
void BaseSearchProvider::DeleteMatch(const AutocompleteMatch& match) {
DCHECK(match.deletable);
if (!match.GetAdditionalInfo(BaseSearchProvider::kDeletionUrlKey).empty()) {
......@@ -256,16 +267,6 @@ const char BaseSearchProvider::kFalse[] = "false";
BaseSearchProvider::~BaseSearchProvider() {}
// 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
AutocompleteMatch BaseSearchProvider::CreateSearchSuggestion(
AutocompleteProvider* autocomplete_provider,
......
......@@ -77,6 +77,10 @@ class BaseSearchProvider : public AutocompleteProvider {
metrics::OmniboxEventProto::PageClassification page_classification,
TemplateURLRef::SearchTermsArgs* search_terms_args);
// Returns whether the provided classification indicates some sort of NTP.
static bool IsNTPPage(
metrics::OmniboxEventProto::PageClassification classification);
// AutocompleteProvider:
void DeleteMatch(const AutocompleteMatch& match) override;
void AddProviderInfo(ProvidersInfo* provider_info) const override;
......@@ -113,10 +117,6 @@ 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.
......
......@@ -96,6 +96,7 @@ constexpr char kArbitraryInsecureUrlString[] = "http://www.google.com/";
constexpr char kOmniboxZeroSuggestEligibleHistogramName[] =
"Omnibox.ZeroSuggest.Eligible.OnFocusV2";
#if defined(OS_ANDROID) || defined(OS_IOS)
// If the user is not signed-in or the user does not have Google set up as their
// default search engine, the remote suggestions service is replaced with the
// most visited service.
......@@ -117,6 +118,7 @@ bool RemoteSuggestionsShouldFallBackToMostVisited(
default_provider->GetEngineType(
template_url_service->search_terms_data()) != SEARCH_ENGINE_GOOGLE;
}
#endif
} // namespace
......@@ -628,13 +630,16 @@ ZeroSuggestProvider::ResultType ZeroSuggestProvider::TypeOfResultToRun(
return REMOTE_NO_URL;
if (field_trial_variant == kRemoteNoUrlVariant) {
#if defined(OS_ANDROID) || defined(OS_IOS)
// TODO(tommycli): It's odd that this doesn't apply to kRemoteSendUrlVariant
// as well. Most likely this fallback concept should be replaced by
// a more general configuration setup.
return RemoteSuggestionsShouldFallBackToMostVisited(client(),
template_url_service)
? MOST_VISITED
: REMOTE_NO_URL;
if (RemoteSuggestionsShouldFallBackToMostVisited(client(),
template_url_service)) {
return MOST_VISITED;
}
#endif
return REMOTE_NO_URL;
}
if (field_trial_variant == kRemoteSendUrlVariant && can_send_current_url)
......
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