Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Unified Diff: components/omnibox/browser/zero_suggest_provider.cc

Issue 2965173002: Add ContextualSuggestionsService to Omnibox (Closed)
Patch Set: Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/omnibox/browser/zero_suggest_provider.cc
diff --git a/components/omnibox/browser/zero_suggest_provider.cc b/components/omnibox/browser/zero_suggest_provider.cc
index 45e7d86b1172c646767a6874edd5866065ef9424..934b751d1f7c3ee2ddf96fff2b5439b3b8868c56 100644
--- a/components/omnibox/browser/zero_suggest_provider.cc
+++ b/components/omnibox/browser/zero_suggest_provider.cc
@@ -85,32 +85,6 @@ const int kDefaultZeroSuggestRelevance = 100;
// Used for testing whether zero suggest is ever available.
constexpr char kArbitraryInsecureUrlString[] = "http://www.google.com/";
-// Returns true if the folowing conditions are valid:
-// * The |default_provider| is Google.
-// * The user is in the ZeroSuggestRedirectToChrome field trial.
-// * The field trial provides a valid server address where the suggest request
-// is redirected.
-// * The suggest request is over HTTPS. This avoids leaking the current page URL
-// or personal data in unencrypted network traffic.
-// Note: these checks are in addition to CanSendUrl() on the default contextual
-// suggestion URL.
-bool UseExperimentalSuggestService(const TemplateURLService& default_provider) {
- const TemplateURL& default_provider_url =
- *default_provider.GetDefaultSearchProvider();
- const SearchTermsData& search_terms_data =
- default_provider.search_terms_data();
- if ((default_provider_url.GetEngineType(search_terms_data) !=
- SEARCH_ENGINE_GOOGLE) ||
- !OmniboxFieldTrial::InZeroSuggestRedirectToChromeFieldTrial())
- return false;
- // Check that the suggest URL for redirect to chrome field trial is valid.
- const GURL suggest_url(
- OmniboxFieldTrial::ZeroSuggestRedirectToChromeServerAddress());
- if (!suggest_url.is_valid())
- return false;
- return suggest_url.SchemeIsCryptographic();
-}
-
} // namespace
// static
@@ -177,20 +151,31 @@ void ZeroSuggestProvider::Start(const AutocompleteInput& input,
if (can_send_current_url &&
!OmniboxFieldTrial::InZeroSuggestPersonalizedFieldTrial() &&
!OmniboxFieldTrial::InZeroSuggestMostVisitedFieldTrial()) {
- // Update suggest_url to include the current_page_url.
- if (UseExperimentalSuggestService(*template_url_service)) {
- suggest_url = GURL(
- OmniboxFieldTrial::ZeroSuggestRedirectToChromeServerAddress() +
- "/url=" + net::EscapePath(current_query_) +
- OmniboxFieldTrial::ZeroSuggestRedirectToChromeAdditionalFields());
- } else {
- base::string16 prefix;
- TemplateURLRef::SearchTermsArgs search_term_args(prefix);
- search_term_args.current_page_url = current_query_;
- suggest_url =
- GURL(default_provider->suggestions_url_ref().ReplaceSearchTerms(
- search_term_args, template_url_service->search_terms_data()));
+ // Maybe redirect the request to the service maintained by Chrome, which
+ // provides experimental contextual suggestions.
+ contextual_suggestions::ContextualSuggestionsService*
+ contextual_suggestions_service =
+ client()->GetContextualSuggestionsService();
+ if (contextual_suggestions_service != nullptr &&
+ contextual_suggestions_service
+ ->UseExperimentalZeroSuggestSuggestions()) {
+ // Create a request for experimental suggestions with |this| as the
Mark P 2017/07/07 20:13:54 bug: probably want to set done_ = false here.
gcomanici 2017/07/07 21:24:46 I am setting it in the callback function (see Zero
+ // fetcher delegate.
+ contextual_suggestions_service->CreateContextualSuggestionsRequest(
+ current_query_, /*fetcher_delegate=*/this,
+ base::BindOnce(
+ &ZeroSuggestProvider::OnContextualSuggestionsFetcherAvailable,
+ weak_ptr_factory_.GetWeakPtr()));
+ return;
}
+
+ // Update suggest_url to include the current_page_url.
+ base::string16 prefix;
+ TemplateURLRef::SearchTermsArgs search_term_args(prefix);
+ search_term_args.current_page_url = current_query_;
+ suggest_url =
+ GURL(default_provider->suggestions_url_ref().ReplaceSearchTerms(
+ search_term_args, template_url_service->search_terms_data()));
} else if (!ShouldShowNonContextualZeroSuggest(input.current_url())) {
return;
}
@@ -203,6 +188,17 @@ void ZeroSuggestProvider::Start(const AutocompleteInput& input,
Run(suggest_url);
}
+void ZeroSuggestProvider::OnContextualSuggestionsFetcherAvailable(
+ std::unique_ptr<net::URLFetcher> fetcher) {
+ if (fetcher == nullptr) {
+ return;
+ }
+ fetcher_ = std::move(fetcher);
+ done_ = false;
+ fetcher_->Start();
+ LogOmniboxZeroSuggestRequest(ZERO_SUGGEST_REQUEST_SENT);
+}
+
void ZeroSuggestProvider::Stop(bool clear_cached_results,
bool due_to_user_inactivity) {
if (fetcher_)

Powered by Google App Engine
This is Rietveld 408576698