OLD | NEW |
---|---|
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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
108 if (!input.from_omnibox_focus() || client()->IsOffTheRecord() || | 109 if (!input.from_omnibox_focus() || client()->IsOffTheRecord() || |
109 input.type() == metrics::OmniboxInputType::INVALID) | 110 input.type() == metrics::OmniboxInputType::INVALID) |
110 return; | 111 return; |
111 | 112 |
112 Stop(true, false); | 113 Stop(true, false); |
113 set_field_trial_triggered(false); | 114 set_field_trial_triggered(false); |
114 set_field_trial_triggered_in_session(false); | 115 set_field_trial_triggered_in_session(false); |
115 results_from_cache_ = false; | 116 results_from_cache_ = false; |
116 permanent_text_ = input.text(); | 117 permanent_text_ = input.text(); |
117 current_query_ = input.current_url().spec(); | 118 current_query_ = input.current_url().spec(); |
119 current_title_ = input.current_title(); | |
118 current_page_classification_ = input.current_page_classification(); | 120 current_page_classification_ = input.current_page_classification(); |
119 current_url_match_ = MatchForCurrentURL(); | 121 current_url_match_ = MatchForCurrentURL(); |
120 | 122 |
121 std::string url_string = GetContextualSuggestionsUrl(); | 123 std::string url_string = GetContextualSuggestionsUrl(); |
122 GURL suggest_url(url_string); | 124 GURL suggest_url(url_string); |
123 if (!suggest_url.is_valid()) | 125 if (!suggest_url.is_valid()) |
124 return; | 126 return; |
125 | 127 |
126 // No need to send the current page URL in personalized suggest or | 128 // No need to send the current page URL in personalized suggest or |
127 // most visited field trials. | 129 // most visited field trials. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
167 } else if (!ShouldShowNonContextualZeroSuggest(suggest_url, | 169 } else if (!ShouldShowNonContextualZeroSuggest(suggest_url, |
168 input.current_url())) { | 170 input.current_url())) { |
169 return; | 171 return; |
170 } | 172 } |
171 | 173 |
172 done_ = false; | 174 done_ = false; |
173 // TODO(jered): Consider adding locally-sourced zero-suggestions here too. | 175 // TODO(jered): Consider adding locally-sourced zero-suggestions here too. |
174 // These may be useful on the NTP or more relevant to the user than server | 176 // These may be useful on the NTP or more relevant to the user than server |
175 // suggestions, if based on local browsing history. | 177 // suggestions, if based on local browsing history. |
176 MaybeUseCachedSuggestions(); | 178 MaybeUseCachedSuggestions(); |
179 LOG(ERROR) << suggest_url.possibly_invalid_spec(); | |
Mark P
2017/04/27 05:44:08
Did you intend to keep this here? Please reconsid
gcomanici
2017/04/27 17:29:30
Removed.
| |
177 Run(suggest_url); | 180 Run(suggest_url); |
178 } | 181 } |
179 | 182 |
180 void ZeroSuggestProvider::Stop(bool clear_cached_results, | 183 void ZeroSuggestProvider::Stop(bool clear_cached_results, |
181 bool due_to_user_inactivity) { | 184 bool due_to_user_inactivity) { |
182 if (fetcher_) | 185 if (fetcher_) |
183 LogOmniboxZeroSuggestRequest(ZERO_SUGGEST_REQUEST_INVALIDATED); | 186 LogOmniboxZeroSuggestRequest(ZERO_SUGGEST_REQUEST_INVALIDATED); |
184 fetcher_.reset(); | 187 fetcher_.reset(); |
185 waiting_for_most_visited_urls_request_ = false; | 188 waiting_for_most_visited_urls_request_ = false; |
186 done_ = true; | 189 done_ = true; |
187 | 190 |
188 if (clear_cached_results) { | 191 if (clear_cached_results) { |
189 // We do not call Clear() on |results_| to retain |verbatim_relevance| | 192 // We do not call Clear() on |results_| to retain |verbatim_relevance| |
190 // value in the |results_| object. |verbatim_relevance| is used at the | 193 // value in the |results_| object. |verbatim_relevance| is used at the |
191 // beginning of the next call to Start() to determine the current url | 194 // beginning of the next call to Start() to determine the current url |
192 // match relevance. | 195 // match relevance. |
193 results_.suggest_results.clear(); | 196 results_.suggest_results.clear(); |
194 results_.navigation_results.clear(); | 197 results_.navigation_results.clear(); |
195 current_query_.clear(); | 198 current_query_.clear(); |
199 current_title_.clear(); | |
196 most_visited_urls_.clear(); | 200 most_visited_urls_.clear(); |
197 } | 201 } |
198 } | 202 } |
199 | 203 |
200 void ZeroSuggestProvider::DeleteMatch(const AutocompleteMatch& match) { | 204 void ZeroSuggestProvider::DeleteMatch(const AutocompleteMatch& match) { |
201 if (OmniboxFieldTrial::InZeroSuggestPersonalizedFieldTrial()) { | 205 if (OmniboxFieldTrial::InZeroSuggestPersonalizedFieldTrial()) { |
202 // Remove the deleted match from the cache, so it is not shown to the user | 206 // Remove the deleted match from the cache, so it is not shown to the user |
203 // again. Since we cannot remove just one result, blow away the cache. | 207 // again. Since we cannot remove just one result, blow away the cache. |
204 client()->GetPrefs()->SetString(omnibox::kZeroSuggestCachedResults, | 208 client()->GetPrefs()->SetString(omnibox::kZeroSuggestCachedResults, |
205 std::string()); | 209 std::string()); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
257 const TemplateURL* ZeroSuggestProvider::GetTemplateURL(bool is_keyword) const { | 261 const TemplateURL* ZeroSuggestProvider::GetTemplateURL(bool is_keyword) const { |
258 // Zero suggest provider should not receive keyword results. | 262 // Zero suggest provider should not receive keyword results. |
259 DCHECK(!is_keyword); | 263 DCHECK(!is_keyword); |
260 return client()->GetTemplateURLService()->GetDefaultSearchProvider(); | 264 return client()->GetTemplateURLService()->GetDefaultSearchProvider(); |
261 } | 265 } |
262 | 266 |
263 const AutocompleteInput ZeroSuggestProvider::GetInput(bool is_keyword) const { | 267 const AutocompleteInput ZeroSuggestProvider::GetInput(bool is_keyword) const { |
264 // The callers of this method won't look at the AutocompleteInput's | 268 // The callers of this method won't look at the AutocompleteInput's |
265 // |from_omnibox_focus| member, so we can set its value to false. | 269 // |from_omnibox_focus| member, so we can set its value to false. |
266 return AutocompleteInput(base::string16(), base::string16::npos, | 270 return AutocompleteInput(base::string16(), base::string16::npos, |
267 std::string(), GURL(current_query_), | 271 std::string(), GURL(current_query_), current_title_, |
268 current_page_classification_, true, false, false, | 272 current_page_classification_, true, false, false, |
269 true, false, client()->GetSchemeClassifier()); | 273 true, false, client()->GetSchemeClassifier()); |
270 } | 274 } |
271 | 275 |
272 bool ZeroSuggestProvider::ShouldAppendExtraParams( | 276 bool ZeroSuggestProvider::ShouldAppendExtraParams( |
273 const SearchSuggestionParser::SuggestResult& result) const { | 277 const SearchSuggestionParser::SuggestResult& result) const { |
274 // We always use the default provider for search, so append the params. | 278 // We always use the default provider for search, so append the params. |
275 return true; | 279 return true; |
276 } | 280 } |
277 | 281 |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
505 matches_.push_back(NavigationToMatch(*it)); | 509 matches_.push_back(NavigationToMatch(*it)); |
506 } | 510 } |
507 } | 511 } |
508 | 512 |
509 AutocompleteMatch ZeroSuggestProvider::MatchForCurrentURL() { | 513 AutocompleteMatch ZeroSuggestProvider::MatchForCurrentURL() { |
510 // The placeholder suggestion for the current URL has high relevance so | 514 // The placeholder suggestion for the current URL has high relevance so |
511 // that it is in the first suggestion slot and inline autocompleted. It | 515 // that it is in the first suggestion slot and inline autocompleted. It |
512 // gets dropped as soon as the user types something. | 516 // gets dropped as soon as the user types something. |
513 AutocompleteInput tmp(GetInput(false)); | 517 AutocompleteInput tmp(GetInput(false)); |
514 tmp.UpdateText(permanent_text_, base::string16::npos, tmp.parts()); | 518 tmp.UpdateText(permanent_text_, base::string16::npos, tmp.parts()); |
515 return VerbatimMatchForURL(client(), tmp, GURL(current_query_), | 519 const base::string16 description = |
520 (base::FeatureList::IsEnabled(omnibox::kDisplayTitleForCurrentUrl)) | |
521 ? current_title_ | |
522 : base::string16(); | |
523 return VerbatimMatchForURL(client(), tmp, GURL(current_query_), description, | |
516 history_url_provider_, | 524 history_url_provider_, |
517 results_.verbatim_relevance); | 525 results_.verbatim_relevance); |
518 } | 526 } |
519 | 527 |
520 bool ZeroSuggestProvider::ShouldShowNonContextualZeroSuggest( | 528 bool ZeroSuggestProvider::ShouldShowNonContextualZeroSuggest( |
521 const GURL& suggest_url, | 529 const GURL& suggest_url, |
522 const GURL& current_page_url) const { | 530 const GURL& current_page_url) const { |
523 const TemplateURLService* template_url_service = | 531 const TemplateURLService* template_url_service = |
524 client()->GetTemplateURLService(); | 532 client()->GetTemplateURLService(); |
525 if (!ZeroSuggestEnabled(suggest_url, | 533 if (!ZeroSuggestEnabled(suggest_url, |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
579 if (!json_data.empty()) { | 587 if (!json_data.empty()) { |
580 std::unique_ptr<base::Value> data( | 588 std::unique_ptr<base::Value> data( |
581 SearchSuggestionParser::DeserializeJsonData(json_data)); | 589 SearchSuggestionParser::DeserializeJsonData(json_data)); |
582 if (data && ParseSuggestResults( | 590 if (data && ParseSuggestResults( |
583 *data, kDefaultZeroSuggestRelevance, false, &results_)) { | 591 *data, kDefaultZeroSuggestRelevance, false, &results_)) { |
584 ConvertResultsToAutocompleteMatches(); | 592 ConvertResultsToAutocompleteMatches(); |
585 results_from_cache_ = !matches_.empty(); | 593 results_from_cache_ = !matches_.empty(); |
586 } | 594 } |
587 } | 595 } |
588 } | 596 } |
OLD | NEW |