| 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 done_ = true; | 188 done_ = true; |
| 187 | 189 |
| 188 if (clear_cached_results) { | 190 if (clear_cached_results) { |
| 189 // We do not call Clear() on |results_| to retain |verbatim_relevance| | 191 // We do not call Clear() on |results_| to retain |verbatim_relevance| |
| 190 // value in the |results_| object. |verbatim_relevance| is used at the | 192 // value in the |results_| object. |verbatim_relevance| is used at the |
| 191 // beginning of the next call to Start() to determine the current url | 193 // beginning of the next call to Start() to determine the current url |
| 192 // match relevance. | 194 // match relevance. |
| 193 results_.suggest_results.clear(); | 195 results_.suggest_results.clear(); |
| 194 results_.navigation_results.clear(); | 196 results_.navigation_results.clear(); |
| 195 current_query_.clear(); | 197 current_query_.clear(); |
| 198 current_title_.clear(); |
| 196 most_visited_urls_.clear(); | 199 most_visited_urls_.clear(); |
| 197 } | 200 } |
| 198 } | 201 } |
| 199 | 202 |
| 200 void ZeroSuggestProvider::DeleteMatch(const AutocompleteMatch& match) { | 203 void ZeroSuggestProvider::DeleteMatch(const AutocompleteMatch& match) { |
| 201 if (OmniboxFieldTrial::InZeroSuggestPersonalizedFieldTrial()) { | 204 if (OmniboxFieldTrial::InZeroSuggestPersonalizedFieldTrial()) { |
| 202 // Remove the deleted match from the cache, so it is not shown to the user | 205 // 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. | 206 // again. Since we cannot remove just one result, blow away the cache. |
| 204 client()->GetPrefs()->SetString(omnibox::kZeroSuggestCachedResults, | 207 client()->GetPrefs()->SetString(omnibox::kZeroSuggestCachedResults, |
| 205 std::string()); | 208 std::string()); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 const TemplateURL* ZeroSuggestProvider::GetTemplateURL(bool is_keyword) const { | 260 const TemplateURL* ZeroSuggestProvider::GetTemplateURL(bool is_keyword) const { |
| 258 // Zero suggest provider should not receive keyword results. | 261 // Zero suggest provider should not receive keyword results. |
| 259 DCHECK(!is_keyword); | 262 DCHECK(!is_keyword); |
| 260 return client()->GetTemplateURLService()->GetDefaultSearchProvider(); | 263 return client()->GetTemplateURLService()->GetDefaultSearchProvider(); |
| 261 } | 264 } |
| 262 | 265 |
| 263 const AutocompleteInput ZeroSuggestProvider::GetInput(bool is_keyword) const { | 266 const AutocompleteInput ZeroSuggestProvider::GetInput(bool is_keyword) const { |
| 264 // The callers of this method won't look at the AutocompleteInput's | 267 // 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. | 268 // |from_omnibox_focus| member, so we can set its value to false. |
| 266 return AutocompleteInput(base::string16(), base::string16::npos, | 269 return AutocompleteInput(base::string16(), base::string16::npos, |
| 267 std::string(), GURL(current_query_), | 270 std::string(), GURL(current_query_), current_title_, |
| 268 current_page_classification_, true, false, false, | 271 current_page_classification_, true, false, false, |
| 269 true, false, client()->GetSchemeClassifier()); | 272 true, false, client()->GetSchemeClassifier()); |
| 270 } | 273 } |
| 271 | 274 |
| 272 bool ZeroSuggestProvider::ShouldAppendExtraParams( | 275 bool ZeroSuggestProvider::ShouldAppendExtraParams( |
| 273 const SearchSuggestionParser::SuggestResult& result) const { | 276 const SearchSuggestionParser::SuggestResult& result) const { |
| 274 // We always use the default provider for search, so append the params. | 277 // We always use the default provider for search, so append the params. |
| 275 return true; | 278 return true; |
| 276 } | 279 } |
| 277 | 280 |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 matches_.push_back(NavigationToMatch(*it)); | 508 matches_.push_back(NavigationToMatch(*it)); |
| 506 } | 509 } |
| 507 } | 510 } |
| 508 | 511 |
| 509 AutocompleteMatch ZeroSuggestProvider::MatchForCurrentURL() { | 512 AutocompleteMatch ZeroSuggestProvider::MatchForCurrentURL() { |
| 510 // The placeholder suggestion for the current URL has high relevance so | 513 // The placeholder suggestion for the current URL has high relevance so |
| 511 // that it is in the first suggestion slot and inline autocompleted. It | 514 // that it is in the first suggestion slot and inline autocompleted. It |
| 512 // gets dropped as soon as the user types something. | 515 // gets dropped as soon as the user types something. |
| 513 AutocompleteInput tmp(GetInput(false)); | 516 AutocompleteInput tmp(GetInput(false)); |
| 514 tmp.UpdateText(permanent_text_, base::string16::npos, tmp.parts()); | 517 tmp.UpdateText(permanent_text_, base::string16::npos, tmp.parts()); |
| 515 return VerbatimMatchForURL(client(), tmp, GURL(current_query_), | 518 const base::string16 description = |
| 519 (base::FeatureList::IsEnabled(omnibox::kDisplayTitleForCurrentUrl)) |
| 520 ? current_title_ |
| 521 : base::string16(); |
| 522 return VerbatimMatchForURL(client(), tmp, GURL(current_query_), description, |
| 516 history_url_provider_, | 523 history_url_provider_, |
| 517 results_.verbatim_relevance); | 524 results_.verbatim_relevance); |
| 518 } | 525 } |
| 519 | 526 |
| 520 bool ZeroSuggestProvider::ShouldShowNonContextualZeroSuggest( | 527 bool ZeroSuggestProvider::ShouldShowNonContextualZeroSuggest( |
| 521 const GURL& suggest_url, | 528 const GURL& suggest_url, |
| 522 const GURL& current_page_url) const { | 529 const GURL& current_page_url) const { |
| 523 const TemplateURLService* template_url_service = | 530 const TemplateURLService* template_url_service = |
| 524 client()->GetTemplateURLService(); | 531 client()->GetTemplateURLService(); |
| 525 if (!ZeroSuggestEnabled(suggest_url, | 532 if (!ZeroSuggestEnabled(suggest_url, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 if (!json_data.empty()) { | 586 if (!json_data.empty()) { |
| 580 std::unique_ptr<base::Value> data( | 587 std::unique_ptr<base::Value> data( |
| 581 SearchSuggestionParser::DeserializeJsonData(json_data)); | 588 SearchSuggestionParser::DeserializeJsonData(json_data)); |
| 582 if (data && ParseSuggestResults( | 589 if (data && ParseSuggestResults( |
| 583 *data, kDefaultZeroSuggestRelevance, false, &results_)) { | 590 *data, kDefaultZeroSuggestRelevance, false, &results_)) { |
| 584 ConvertResultsToAutocompleteMatches(); | 591 ConvertResultsToAutocompleteMatches(); |
| 585 results_from_cache_ = !matches_.empty(); | 592 results_from_cache_ = !matches_.empty(); |
| 586 } | 593 } |
| 587 } | 594 } |
| 588 } | 595 } |
| OLD | NEW |