Commit 5bc2e3de authored by Jenny Zhang's avatar Jenny Zhang Committed by Commit Bot

Integrate app_list zero state suggestion with omnibox.

1. Add query params pgcl=14 and sclient=cros-launcher for launcher queries to completion server.
2. Enable ZeroSuggestProvider to process empty queries from cros launcher.
3. The above changes are only enabled when zero state is enabled by flag, which by default is off.

Bug: 854242
Change-Id: I9ca99a668b74ab642ff1d020eb14565fb4af12ff
Reviewed-on: https://chromium-review.googlesource.com/1178971Reviewed-by: default avatarMark Pearson <mpearson@chromium.org>
Commit-Queue: Jenny Zhang <jennyz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#590003}
parent 4a17983f
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "chrome/browser/ui/app_list/search/omnibox_provider.h" #include "chrome/browser/ui/app_list/search/omnibox_provider.h"
#include "ash/public/cpp/app_list/app_list_features.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "chrome/browser/autocomplete/chrome_autocomplete_provider_client.h" #include "chrome/browser/autocomplete/chrome_autocomplete_provider_client.h"
#include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h"
...@@ -22,20 +23,35 @@ namespace app_list { ...@@ -22,20 +23,35 @@ namespace app_list {
OmniboxProvider::OmniboxProvider(Profile* profile, OmniboxProvider::OmniboxProvider(Profile* profile,
AppListControllerDelegate* list_controller) AppListControllerDelegate* list_controller)
: profile_(profile), : profile_(profile),
is_zero_state_enabled_(features::IsZeroStateSuggestionsEnabled()),
list_controller_(list_controller), list_controller_(list_controller),
controller_(std::make_unique<AutocompleteController>( controller_(std::make_unique<AutocompleteController>(
std::make_unique<ChromeAutocompleteProviderClient>(profile), std::make_unique<ChromeAutocompleteProviderClient>(profile),
this, this,
AutocompleteClassifier::DefaultOmniboxProviders() & is_zero_state_enabled_
~AutocompleteProvider::TYPE_ZERO_SUGGEST)) {} ? AutocompleteClassifier::DefaultOmniboxProviders()
: AutocompleteClassifier::DefaultOmniboxProviders() &
~AutocompleteProvider::TYPE_ZERO_SUGGEST)) {}
OmniboxProvider::~OmniboxProvider() {} OmniboxProvider::~OmniboxProvider() {}
void OmniboxProvider::Start(const base::string16& query) { void OmniboxProvider::Start(const base::string16& query) {
controller_->Stop(false); controller_->Stop(false);
AutocompleteInput input = // The new page classification value(CHROMEOS_APP_LIST) is introduced
AutocompleteInput(query, metrics::OmniboxEventProto::INVALID_SPEC, // to differentiate the suggest requests initiated by ChromeOS app_list from
ChromeAutocompleteSchemeClassifier(profile_)); // the ones by Chrome omnibox. Until we fully test the integration with
// suggest server with Zero State feature, we will keep the related change
// out of picture if zero state feature is not enabled.
AutocompleteInput input = AutocompleteInput(
query,
is_zero_state_enabled_ ? metrics::OmniboxEventProto::CHROMEOS_APP_LIST
: metrics::OmniboxEventProto::INVALID_SPEC,
ChromeAutocompleteSchemeClassifier(profile_));
// Sets the |from_omnibox_focus| flag to enable ZeroSuggestProvider to process
// the requests from app_list.
if (is_zero_state_enabled_ && input.text().empty())
input.set_from_omnibox_focus(true);
controller_->Start(input); controller_->Start(input);
} }
......
...@@ -37,6 +37,7 @@ class OmniboxProvider : public SearchProvider, ...@@ -37,6 +37,7 @@ class OmniboxProvider : public SearchProvider,
void OnResultChanged(bool default_match_changed) override; void OnResultChanged(bool default_match_changed) override;
Profile* profile_; Profile* profile_;
bool is_zero_state_enabled_;
AppListControllerDelegate* list_controller_; AppListControllerDelegate* list_controller_;
// The omnibox AutocompleteController that collects/sorts/dup- // The omnibox AutocompleteController that collects/sorts/dup-
......
...@@ -168,6 +168,23 @@ AutocompleteMatch BaseSearchProvider::CreateSearchSuggestion( ...@@ -168,6 +168,23 @@ AutocompleteMatch BaseSearchProvider::CreateSearchSuggestion(
template_url, search_terms_data, 0, false); template_url, search_terms_data, 0, false);
} }
// static
void BaseSearchProvider::AppendSuggestClientToAdditionalQueryParams(
const TemplateURL* template_url,
const SearchTermsData& search_terms_data,
metrics::OmniboxEventProto::PageClassification page_classification,
TemplateURLRef::SearchTermsArgs* search_terms_args) {
// Only append the suggest client query param for Google template URL.
if (template_url->GetEngineType(search_terms_data) != SEARCH_ENGINE_GOOGLE)
return;
if (page_classification == metrics::OmniboxEventProto::CHROMEOS_APP_LIST) {
if (!search_terms_args->additional_query_params.empty())
search_terms_args->additional_query_params.append("&");
search_terms_args->additional_query_params.append("sclient=cros-launcher");
}
}
void BaseSearchProvider::DeleteMatch(const AutocompleteMatch& match) { void BaseSearchProvider::DeleteMatch(const AutocompleteMatch& match) {
DCHECK(match.deletable); DCHECK(match.deletable);
if (!match.GetAdditionalInfo(BaseSearchProvider::kDeletionUrlKey).empty()) { if (!match.GetAdditionalInfo(BaseSearchProvider::kDeletionUrlKey).empty()) {
......
...@@ -57,6 +57,15 @@ class BaseSearchProvider : public AutocompleteProvider { ...@@ -57,6 +57,15 @@ class BaseSearchProvider : public AutocompleteProvider {
const TemplateURL* template_url, const TemplateURL* template_url,
const SearchTermsData& search_terms_data); const SearchTermsData& search_terms_data);
// Appends specific suggest client based on page |page_classification| to
// the additional query params of |search_terms_args| only for Google template
// URLs.
static void AppendSuggestClientToAdditionalQueryParams(
const TemplateURL* template_url,
const SearchTermsData& search_terms_data,
metrics::OmniboxEventProto::PageClassification page_classification,
TemplateURLRef::SearchTermsArgs* search_terms_args);
// AutocompleteProvider: // AutocompleteProvider:
void DeleteMatch(const AutocompleteMatch& match) override; void DeleteMatch(const AutocompleteMatch& match) override;
void AddProviderInfo(ProvidersInfo* provider_info) const override; void AddProviderInfo(ProvidersInfo* provider_info) const override;
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/values.h" #include "base/values.h"
#include "components/data_use_measurement/core/data_use_user_data.h" #include "components/data_use_measurement/core/data_use_user_data.h"
#include "components/omnibox/browser/base_search_provider.h"
#include "components/omnibox/browser/omnibox_field_trial.h" #include "components/omnibox/browser/omnibox_field_trial.h"
#include "components/search_engines/template_url_service.h" #include "components/search_engines/template_url_service.h"
#include "components/sync/base/time.h" #include "components/sync/base/time.h"
...@@ -100,6 +101,7 @@ ContextualSuggestionsService::~ContextualSuggestionsService() {} ...@@ -100,6 +101,7 @@ ContextualSuggestionsService::~ContextualSuggestionsService() {}
void ContextualSuggestionsService::CreateContextualSuggestionsRequest( void ContextualSuggestionsService::CreateContextualSuggestionsRequest(
const std::string& current_url, const std::string& current_url,
const base::Time& visit_time, const base::Time& visit_time,
const AutocompleteInput& input,
const TemplateURLService* template_url_service, const TemplateURLService* template_url_service,
StartCallback start_callback, StartCallback start_callback,
CompletionCallback completion_callback) { CompletionCallback completion_callback) {
...@@ -110,7 +112,7 @@ void ContextualSuggestionsService::CreateContextualSuggestionsRequest( ...@@ -110,7 +112,7 @@ void ContextualSuggestionsService::CreateContextualSuggestionsRequest(
std::move(start_callback), std::move(start_callback),
std::move(completion_callback)); std::move(completion_callback));
else else
CreateDefaultRequest(current_url, template_url_service, CreateDefaultRequest(current_url, input, template_url_service,
std::move(start_callback), std::move(start_callback),
std::move(completion_callback)); std::move(completion_callback));
} }
...@@ -123,6 +125,7 @@ void ContextualSuggestionsService::StopCreatingContextualSuggestionsRequest() { ...@@ -123,6 +125,7 @@ void ContextualSuggestionsService::StopCreatingContextualSuggestionsRequest() {
// static // static
GURL ContextualSuggestionsService::ContextualSuggestionsUrl( GURL ContextualSuggestionsService::ContextualSuggestionsUrl(
const std::string& current_url, const std::string& current_url,
const AutocompleteInput& input,
const TemplateURLService* template_url_service) { const TemplateURLService* template_url_service) {
if (template_url_service == nullptr) { if (template_url_service == nullptr) {
return GURL(); return GURL();
...@@ -143,6 +146,13 @@ GURL ContextualSuggestionsService::ContextualSuggestionsUrl( ...@@ -143,6 +146,13 @@ GURL ContextualSuggestionsService::ContextualSuggestionsUrl(
if (!current_url.empty()) { if (!current_url.empty()) {
search_term_args.current_page_url = current_url; search_term_args.current_page_url = current_url;
} }
search_term_args.page_classification = input.current_page_classification();
// Append a specific suggest client in ChromeOS app_list launcher contexts.
BaseSearchProvider::AppendSuggestClientToAdditionalQueryParams(
search_engine, search_terms_data, input.current_page_classification(),
&search_term_args);
return GURL(suggestion_url_ref.ReplaceSearchTerms(search_term_args, return GURL(suggestion_url_ref.ReplaceSearchTerms(search_term_args,
search_terms_data)); search_terms_data));
} }
...@@ -188,11 +198,12 @@ GURL ContextualSuggestionsService::ExperimentalContextualSuggestionsUrl( ...@@ -188,11 +198,12 @@ GURL ContextualSuggestionsService::ExperimentalContextualSuggestionsUrl(
void ContextualSuggestionsService::CreateDefaultRequest( void ContextualSuggestionsService::CreateDefaultRequest(
const std::string& current_url, const std::string& current_url,
const AutocompleteInput& input,
const TemplateURLService* template_url_service, const TemplateURLService* template_url_service,
StartCallback start_callback, StartCallback start_callback,
CompletionCallback completion_callback) { CompletionCallback completion_callback) {
const GURL suggest_url = const GURL suggest_url =
ContextualSuggestionsUrl(current_url, template_url_service); ContextualSuggestionsUrl(current_url, input, template_url_service);
DCHECK(suggest_url.is_valid()); DCHECK(suggest_url.is_valid());
net::NetworkTrafficAnnotationTag traffic_annotation = net::NetworkTrafficAnnotationTag traffic_annotation =
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/memory/scoped_refptr.h" #include "base/memory/scoped_refptr.h"
#include "components/keyed_service/core/keyed_service.h" #include "components/keyed_service/core/keyed_service.h"
#include "components/omnibox/browser/autocomplete_input.h"
#include "net/traffic_annotation/network_traffic_annotation.h" #include "net/traffic_annotation/network_traffic_annotation.h"
#include "services/identity/public/cpp/access_token_info.h" #include "services/identity/public/cpp/access_token_info.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -60,6 +61,9 @@ class ContextualSuggestionsService : public KeyedService { ...@@ -60,6 +61,9 @@ class ContextualSuggestionsService : public KeyedService {
// |visit_time| is the time of the visit for the URL for which suggestions // |visit_time| is the time of the visit for the URL for which suggestions
// should be fetched. // should be fetched.
// //
// |input| is the current user input of the autocomplete query, whose
// |current_page_classification| will be used to build the suggestion url.
//
// |template_url_service| may be null, but some services may be disabled. // |template_url_service| may be null, but some services may be disabled.
// //
// |start_callback| is called to transfer ownership of the created loader to // |start_callback| is called to transfer ownership of the created loader to
...@@ -75,6 +79,7 @@ class ContextualSuggestionsService : public KeyedService { ...@@ -75,6 +79,7 @@ class ContextualSuggestionsService : public KeyedService {
void CreateContextualSuggestionsRequest( void CreateContextualSuggestionsRequest(
const std::string& current_url, const std::string& current_url,
const base::Time& visit_time, const base::Time& visit_time,
const AutocompleteInput& input,
const TemplateURLService* template_url_service, const TemplateURLService* template_url_service,
StartCallback start_callback, StartCallback start_callback,
CompletionCallback completion_callback); CompletionCallback completion_callback);
...@@ -90,10 +95,14 @@ class ContextualSuggestionsService : public KeyedService { ...@@ -90,10 +95,14 @@ class ContextualSuggestionsService : public KeyedService {
// //
// |current_url| is the page the user is currently browsing and may be empty. // |current_url| is the page the user is currently browsing and may be empty.
// //
// |input| is the current user input of the autocomplete query, whose
// |current_page_classification| will be used to build the suggestion url.
//
// Note that this method is public and is also used by ZeroSuggestProvider for // Note that this method is public and is also used by ZeroSuggestProvider for
// suggestions that do not take |current_url| into consideration. // suggestions that do not take |current_url| into consideration.
static GURL ContextualSuggestionsUrl( static GURL ContextualSuggestionsUrl(
const std::string& current_url, const std::string& current_url,
const AutocompleteInput& input,
const TemplateURLService* template_url_service); const TemplateURLService* template_url_service);
private: private:
...@@ -121,6 +130,7 @@ class ContextualSuggestionsService : public KeyedService { ...@@ -121,6 +130,7 @@ class ContextualSuggestionsService : public KeyedService {
// This function is called by CreateContextualSuggestionsRequest. See its // This function is called by CreateContextualSuggestionsRequest. See its
// function definition for details on the parameters. // function definition for details on the parameters.
void CreateDefaultRequest(const std::string& current_url, void CreateDefaultRequest(const std::string& current_url,
const AutocompleteInput& input,
const TemplateURLService* template_url_service, const TemplateURLService* template_url_service,
StartCallback start_callback, StartCallback start_callback,
CompletionCallback completion_callback); CompletionCallback completion_callback);
......
...@@ -892,14 +892,24 @@ std::unique_ptr<network::SimpleURLLoader> SearchProvider::CreateSuggestLoader( ...@@ -892,14 +892,24 @@ std::unique_ptr<network::SimpleURLLoader> SearchProvider::CreateSuggestLoader(
base::UTF16ToUTF8(prefetch_data_.query_type); base::UTF16ToUTF8(prefetch_data_.query_type);
} }
// Append a specific suggest client if it is in ChromeOS app_list launcher
// contexts.
const SearchTermsData& search_terms_data =
client()->GetTemplateURLService()->search_terms_data();
BaseSearchProvider::AppendSuggestClientToAdditionalQueryParams(
template_url, search_terms_data, input.current_page_classification(),
&search_term_args);
// If the request is from omnibox focus, send empty search term args. The // If the request is from omnibox focus, send empty search term args. The
// purpose of such a request is to signal the server to warm up; no info // purpose of such a request is to signal the server to warm up; no info
// is required. // is required.
TemplateURLRef::SearchTermsArgs empty_search_term_args((base::string16()));
BaseSearchProvider::AppendSuggestClientToAdditionalQueryParams(
template_url, search_terms_data, input.current_page_classification(),
&empty_search_term_args);
GURL suggest_url(template_url->suggestions_url_ref().ReplaceSearchTerms( GURL suggest_url(template_url->suggestions_url_ref().ReplaceSearchTerms(
input.from_omnibox_focus() input.from_omnibox_focus() ? empty_search_term_args : search_term_args,
? TemplateURLRef::SearchTermsArgs(base::string16()) search_terms_data));
: search_term_args,
client()->GetTemplateURLService()->search_terms_data()));
if (!suggest_url.is_valid()) if (!suggest_url.is_valid())
return nullptr; return nullptr;
......
...@@ -130,8 +130,14 @@ void ZeroSuggestProvider::Start(const AutocompleteInput& input, ...@@ -130,8 +130,14 @@ void ZeroSuggestProvider::Start(const AutocompleteInput& input,
TRACE_EVENT0("omnibox", "ZeroSuggestProvider::Start"); TRACE_EVENT0("omnibox", "ZeroSuggestProvider::Start");
matches_.clear(); matches_.clear();
Stop(true, false); Stop(true, false);
if (!input.from_omnibox_focus() || client()->IsOffTheRecord() || if (!input.from_omnibox_focus() || client()->IsOffTheRecord())
input.type() == metrics::OmniboxInputType::INVALID) return;
// Zero suggest is allowed to run in the Chrome OS app_list context
// with invalid (empty) input.
if (input.type() == metrics::OmniboxInputType::INVALID &&
input.current_page_classification() !=
metrics::OmniboxEventProto::CHROMEOS_APP_LIST)
return; return;
result_type_running_ = NONE; result_type_running_ = NONE;
...@@ -144,7 +150,7 @@ void ZeroSuggestProvider::Start(const AutocompleteInput& input, ...@@ -144,7 +150,7 @@ void ZeroSuggestProvider::Start(const AutocompleteInput& input,
current_url_match_ = MatchForCurrentURL(); current_url_match_ = MatchForCurrentURL();
GURL suggest_url = ContextualSuggestionsService::ContextualSuggestionsUrl( GURL suggest_url = ContextualSuggestionsService::ContextualSuggestionsUrl(
/*current_url=*/"", client()->GetTemplateURLService()); /*current_url=*/"", input, client()->GetTemplateURLService());
if (!suggest_url.is_valid()) if (!suggest_url.is_valid())
return; return;
...@@ -180,7 +186,7 @@ void ZeroSuggestProvider::Start(const AutocompleteInput& input, ...@@ -180,7 +186,7 @@ void ZeroSuggestProvider::Start(const AutocompleteInput& input,
client() client()
->GetContextualSuggestionsService(/*create_if_necessary=*/true) ->GetContextualSuggestionsService(/*create_if_necessary=*/true)
->CreateContextualSuggestionsRequest( ->CreateContextualSuggestionsRequest(
current_url, client()->GetCurrentVisitTimestamp(), current_url, client()->GetCurrentVisitTimestamp(), input,
client()->GetTemplateURLService(), client()->GetTemplateURLService(),
base::BindOnce( base::BindOnce(
&ZeroSuggestProvider::OnContextualSuggestionsLoaderAvailable, &ZeroSuggestProvider::OnContextualSuggestionsLoaderAvailable,
...@@ -259,8 +265,9 @@ ZeroSuggestProvider::ZeroSuggestProvider( ...@@ -259,8 +265,9 @@ ZeroSuggestProvider::ZeroSuggestProvider(
client->GetTemplateURLService(); client->GetTemplateURLService();
// Template URL service can be null in tests. // Template URL service can be null in tests.
if (template_url_service != nullptr) { if (template_url_service != nullptr) {
AutocompleteInput empty_input;
GURL suggest_url = ContextualSuggestionsService::ContextualSuggestionsUrl( GURL suggest_url = ContextualSuggestionsService::ContextualSuggestionsUrl(
/*current_url=*/"", template_url_service); /*current_url=*/"", /*empty input*/ empty_input, template_url_service);
// To check whether this is allowed, use an arbitrary insecure (http) URL // To check whether this is allowed, use an arbitrary insecure (http) URL
// as the URL we'd want suggestions for. The value of OTHER as the current // as the URL we'd want suggestions for. The value of OTHER as the current
// page classification is to correspond with that URL. // page classification is to correspond with that URL.
...@@ -473,7 +480,13 @@ void ZeroSuggestProvider::ConvertResultsToAutocompleteMatches() { ...@@ -473,7 +480,13 @@ void ZeroSuggestProvider::ConvertResultsToAutocompleteMatches() {
if (num_results == 0) if (num_results == 0)
return; return;
matches_.push_back(current_url_match_); // Normally |current_url_match_.destination_url| should be valid unless it is
// under particular page context.
DCHECK(current_page_classification_ ==
metrics::OmniboxEventProto::CHROMEOS_APP_LIST ||
current_url_match_.destination_url.is_valid());
if (current_url_match_.destination_url.is_valid())
matches_.push_back(current_url_match_);
for (MatchMap::const_iterator it(map.begin()); it != map.end(); ++it) for (MatchMap::const_iterator it(map.begin()); it != map.end(); ++it)
matches_.push_back(it->second); matches_.push_back(it->second);
...@@ -513,19 +526,22 @@ bool ZeroSuggestProvider::AllowZeroSuggestSuggestions( ...@@ -513,19 +526,22 @@ bool ZeroSuggestProvider::AllowZeroSuggestSuggestions(
if (client()->IsOffTheRecord()) if (client()->IsOffTheRecord())
return false; return false;
// Only show zero suggest for pages with URLs the user will recognize. // Only show zero suggest for pages with URLs the user will recognize
// if it is not running in ChromeOS app_list context.
// This list intentionally does not include items such as ftp: and file: // This list intentionally does not include items such as ftp: and file:
// because (a) these do not work on Android and iOS, where non-contextual // because (a) these do not work on Android and iOS, where non-contextual
// zero suggest is launched and (b) on desktop, where contextual zero suggest // zero suggest is launched and (b) on desktop, where contextual zero suggest
// is running, these types of schemes aren't eligible to be sent to the // is running, these types of schemes aren't eligible to be sent to the
// server to ask for suggestions (and thus in practice we won't display zero // server to ask for suggestions (and thus in practice we won't display zero
// suggest for them). // suggest for them).
if (!current_page_url.is_valid() || if (current_page_classification_ !=
((current_page_url.scheme() != url::kHttpScheme) && metrics::OmniboxEventProto::CHROMEOS_APP_LIST &&
(current_page_url.scheme() != url::kHttpsScheme) && (!current_page_url.is_valid() ||
(current_page_url.scheme() != url::kAboutScheme) && ((current_page_url.scheme() != url::kHttpScheme) &&
(current_page_url.scheme() != (current_page_url.scheme() != url::kHttpsScheme) &&
client()->GetEmbedderRepresentationOfAboutScheme()))) (current_page_url.scheme() != url::kAboutScheme) &&
(current_page_url.scheme() !=
client()->GetEmbedderRepresentationOfAboutScheme()))))
return false; return false;
return true; return true;
...@@ -579,6 +595,11 @@ ZeroSuggestProvider::ResultType ZeroSuggestProvider::TypeOfResultToRun( ...@@ -579,6 +595,11 @@ ZeroSuggestProvider::ResultType ZeroSuggestProvider::TypeOfResultToRun(
if (!AllowZeroSuggestSuggestions(current_url)) if (!AllowZeroSuggestSuggestions(current_url))
return NONE; return NONE;
if (current_page_classification_ ==
metrics::OmniboxEventProto::CHROMEOS_APP_LIST) {
return DEFAULT_SERP;
}
if (OmniboxFieldTrial::InZeroSuggestPersonalizedFieldTrial()) if (OmniboxFieldTrial::InZeroSuggestPersonalizedFieldTrial())
return PersonalizedServiceShouldFallBackToMostVisited( return PersonalizedServiceShouldFallBackToMostVisited(
client()->GetPrefs(), client()->IsAuthenticated(), client()->GetPrefs(), client()->IsAuthenticated(),
......
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