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

Side by Side Diff: components/omnibox/browser/zero_suggest_provider.cc

Issue 2738003002: Add title to current page in zero suggest. (Closed)
Patch Set: Added description as a param to VerbatimMatchForURL Created 3 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/omnibox/browser/zero_suggest_provider.h" 5 #include "components/omnibox/browser/zero_suggest_provider.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/feature_list.h"
10 #include "base/i18n/case_conversion.h" 11 #include "base/i18n/case_conversion.h"
11 #include "base/json/json_string_value_serializer.h" 12 #include "base/json/json_string_value_serializer.h"
12 #include "base/metrics/histogram_macros.h" 13 #include "base/metrics/histogram_macros.h"
13 #include "base/metrics/user_metrics.h" 14 #include "base/metrics/user_metrics.h"
14 #include "base/strings/string16.h" 15 #include "base/strings/string16.h"
15 #include "base/strings/string_util.h" 16 #include "base/strings/string_util.h"
16 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
17 #include "base/time/time.h" 18 #include "base/time/time.h"
18 #include "base/trace_event/trace_event.h" 19 #include "base/trace_event/trace_event.h"
19 #include "components/data_use_measurement/core/data_use_user_data.h" 20 #include "components/data_use_measurement/core/data_use_user_data.h"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 if (!input.from_omnibox_focus() || client()->IsOffTheRecord() || 108 if (!input.from_omnibox_focus() || client()->IsOffTheRecord() ||
108 input.type() == metrics::OmniboxInputType::INVALID) 109 input.type() == metrics::OmniboxInputType::INVALID)
109 return; 110 return;
110 111
111 Stop(true, false); 112 Stop(true, false);
112 set_field_trial_triggered(false); 113 set_field_trial_triggered(false);
113 set_field_trial_triggered_in_session(false); 114 set_field_trial_triggered_in_session(false);
114 results_from_cache_ = false; 115 results_from_cache_ = false;
115 permanent_text_ = input.text(); 116 permanent_text_ = input.text();
116 current_query_ = input.current_url().spec(); 117 current_query_ = input.current_url().spec();
118 current_title_ = input.current_title();
117 current_page_classification_ = input.current_page_classification(); 119 current_page_classification_ = input.current_page_classification();
118 current_url_match_ = MatchForCurrentURL(); 120 current_url_match_ = MatchForCurrentURL();
119 121
120 std::string url_string = GetContextualSuggestionsUrl(); 122 std::string url_string = GetContextualSuggestionsUrl();
121 GURL suggest_url(url_string); 123 GURL suggest_url(url_string);
122 if (!suggest_url.is_valid()) 124 if (!suggest_url.is_valid())
123 return; 125 return;
124 126
125 // No need to send the current page URL in personalized suggest or 127 // No need to send the current page URL in personalized suggest or
126 // most visited field trials. 128 // most visited field trials.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 done_ = true; 187 done_ = true;
186 188
187 if (clear_cached_results) { 189 if (clear_cached_results) {
188 // We do not call Clear() on |results_| to retain |verbatim_relevance| 190 // We do not call Clear() on |results_| to retain |verbatim_relevance|
189 // value in the |results_| object. |verbatim_relevance| is used at the 191 // value in the |results_| object. |verbatim_relevance| is used at the
190 // beginning of the next call to Start() to determine the current url 192 // beginning of the next call to Start() to determine the current url
191 // match relevance. 193 // match relevance.
192 results_.suggest_results.clear(); 194 results_.suggest_results.clear();
193 results_.navigation_results.clear(); 195 results_.navigation_results.clear();
194 current_query_.clear(); 196 current_query_.clear();
197 current_title_.clear();
195 most_visited_urls_.clear(); 198 most_visited_urls_.clear();
196 } 199 }
197 } 200 }
198 201
199 void ZeroSuggestProvider::DeleteMatch(const AutocompleteMatch& match) { 202 void ZeroSuggestProvider::DeleteMatch(const AutocompleteMatch& match) {
200 if (OmniboxFieldTrial::InZeroSuggestPersonalizedFieldTrial()) { 203 if (OmniboxFieldTrial::InZeroSuggestPersonalizedFieldTrial()) {
201 // Remove the deleted match from the cache, so it is not shown to the user 204 // Remove the deleted match from the cache, so it is not shown to the user
202 // again. Since we cannot remove just one result, blow away the cache. 205 // again. Since we cannot remove just one result, blow away the cache.
203 client()->GetPrefs()->SetString(omnibox::kZeroSuggestCachedResults, 206 client()->GetPrefs()->SetString(omnibox::kZeroSuggestCachedResults,
204 std::string()); 207 std::string());
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 const TemplateURL* ZeroSuggestProvider::GetTemplateURL(bool is_keyword) const { 259 const TemplateURL* ZeroSuggestProvider::GetTemplateURL(bool is_keyword) const {
257 // Zero suggest provider should not receive keyword results. 260 // Zero suggest provider should not receive keyword results.
258 DCHECK(!is_keyword); 261 DCHECK(!is_keyword);
259 return client()->GetTemplateURLService()->GetDefaultSearchProvider(); 262 return client()->GetTemplateURLService()->GetDefaultSearchProvider();
260 } 263 }
261 264
262 const AutocompleteInput ZeroSuggestProvider::GetInput(bool is_keyword) const { 265 const AutocompleteInput ZeroSuggestProvider::GetInput(bool is_keyword) const {
263 // The callers of this method won't look at the AutocompleteInput's 266 // The callers of this method won't look at the AutocompleteInput's
264 // |from_omnibox_focus| member, so we can set its value to false. 267 // |from_omnibox_focus| member, so we can set its value to false.
265 return AutocompleteInput(base::string16(), base::string16::npos, 268 return AutocompleteInput(base::string16(), base::string16::npos,
266 std::string(), GURL(current_query_), 269 std::string(), GURL(current_query_), current_title_,
267 current_page_classification_, true, false, false, 270 current_page_classification_, true, false, false,
268 true, false, client()->GetSchemeClassifier()); 271 true, false, client()->GetSchemeClassifier());
269 } 272 }
270 273
271 bool ZeroSuggestProvider::ShouldAppendExtraParams( 274 bool ZeroSuggestProvider::ShouldAppendExtraParams(
272 const SearchSuggestionParser::SuggestResult& result) const { 275 const SearchSuggestionParser::SuggestResult& result) const {
273 // We always use the default provider for search, so append the params. 276 // We always use the default provider for search, so append the params.
274 return true; 277 return true;
275 } 278 }
276 279
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 matches_.push_back(NavigationToMatch(*it)); 477 matches_.push_back(NavigationToMatch(*it));
475 } 478 }
476 } 479 }
477 480
478 AutocompleteMatch ZeroSuggestProvider::MatchForCurrentURL() { 481 AutocompleteMatch ZeroSuggestProvider::MatchForCurrentURL() {
479 // The placeholder suggestion for the current URL has high relevance so 482 // The placeholder suggestion for the current URL has high relevance so
480 // that it is in the first suggestion slot and inline autocompleted. It 483 // that it is in the first suggestion slot and inline autocompleted. It
481 // gets dropped as soon as the user types something. 484 // gets dropped as soon as the user types something.
482 AutocompleteInput tmp(GetInput(false)); 485 AutocompleteInput tmp(GetInput(false));
483 tmp.UpdateText(permanent_text_, base::string16::npos, tmp.parts()); 486 tmp.UpdateText(permanent_text_, base::string16::npos, tmp.parts());
484 return VerbatimMatchForURL(client(), tmp, GURL(current_query_), 487 const base::string16 description =
488 (base::FeatureList::IsEnabled(omnibox::kDisplayTitleForCurrentUrl))
489 ? tmp.current_title()
Mark P 2017/04/13 21:12:29 Is there a difference between tmp.current_title()
gcomanici 2017/04/18 18:52:53 No difference. I followed your suggestion.
490 : base::string16();
491 return VerbatimMatchForURL(client(), tmp, GURL(current_query_), description,
485 history_url_provider_, 492 history_url_provider_,
486 results_.verbatim_relevance); 493 results_.verbatim_relevance);
487 } 494 }
488 495
489 bool ZeroSuggestProvider::ShouldShowNonContextualZeroSuggest( 496 bool ZeroSuggestProvider::ShouldShowNonContextualZeroSuggest(
490 const GURL& suggest_url, 497 const GURL& suggest_url,
491 const GURL& current_page_url) const { 498 const GURL& current_page_url) const {
492 const TemplateURLService* template_url_service = 499 const TemplateURLService* template_url_service =
493 client()->GetTemplateURLService(); 500 client()->GetTemplateURLService();
494 if (!ZeroSuggestEnabled(suggest_url, 501 if (!ZeroSuggestEnabled(suggest_url,
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 if (!json_data.empty()) { 555 if (!json_data.empty()) {
549 std::unique_ptr<base::Value> data( 556 std::unique_ptr<base::Value> data(
550 SearchSuggestionParser::DeserializeJsonData(json_data)); 557 SearchSuggestionParser::DeserializeJsonData(json_data));
551 if (data && ParseSuggestResults( 558 if (data && ParseSuggestResults(
552 *data, kDefaultZeroSuggestRelevance, false, &results_)) { 559 *data, kDefaultZeroSuggestRelevance, false, &results_)) {
553 ConvertResultsToAutocompleteMatches(); 560 ConvertResultsToAutocompleteMatches();
554 results_from_cache_ = !matches_.empty(); 561 results_from_cache_ = !matches_.empty();
555 } 562 }
556 } 563 }
557 } 564 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698