Chromium Code Reviews| 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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 if (!input.from_omnibox_focus() || | 108 if (!input.from_omnibox_focus() || |
| 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 | |
| 120 std::string url_string = GetContextualSuggestionsUrl(); | 121 std::string url_string = GetContextualSuggestionsUrl(); |
| 121 GURL suggest_url(url_string); | 122 GURL suggest_url(url_string); |
| 122 if (!suggest_url.is_valid()) | 123 if (!suggest_url.is_valid()) |
| 123 return; | 124 return; |
| 124 | 125 |
| 125 // No need to send the current page URL in personalized suggest or | 126 // No need to send the current page URL in personalized suggest or |
| 126 // most visited field trials. | 127 // most visited field trials. |
| 127 const TemplateURLService* template_url_service = | 128 const TemplateURLService* template_url_service = |
| 128 client()->GetTemplateURLService(); | 129 client()->GetTemplateURLService(); |
| 129 const TemplateURL* default_provider = | 130 const TemplateURL* default_provider = |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 255 | 256 |
| 256 const TemplateURL* ZeroSuggestProvider::GetTemplateURL(bool is_keyword) const { | 257 const TemplateURL* ZeroSuggestProvider::GetTemplateURL(bool is_keyword) const { |
| 257 // Zero suggest provider should not receive keyword results. | 258 // Zero suggest provider should not receive keyword results. |
| 258 DCHECK(!is_keyword); | 259 DCHECK(!is_keyword); |
| 259 return client()->GetTemplateURLService()->GetDefaultSearchProvider(); | 260 return client()->GetTemplateURLService()->GetDefaultSearchProvider(); |
| 260 } | 261 } |
| 261 | 262 |
| 262 const AutocompleteInput ZeroSuggestProvider::GetInput(bool is_keyword) const { | 263 const AutocompleteInput ZeroSuggestProvider::GetInput(bool is_keyword) const { |
| 263 // The callers of this method won't look at the AutocompleteInput's | 264 // 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. | 265 // |from_omnibox_focus| member, so we can set its value to false. |
| 265 return AutocompleteInput(base::string16(), base::string16::npos, | 266 return AutocompleteInput( |
| 266 std::string(), GURL(current_query_), | 267 base::string16(), base::string16::npos, std::string(), |
| 267 current_page_classification_, true, false, false, | 268 GURL(current_query_), base::string16(), current_page_classification_, |
| 268 true, false, client()->GetSchemeClassifier()); | 269 true, false, false, true, false, client()->GetSchemeClassifier()); |
| 269 } | 270 } |
| 270 | 271 |
| 271 bool ZeroSuggestProvider::ShouldAppendExtraParams( | 272 bool ZeroSuggestProvider::ShouldAppendExtraParams( |
| 272 const SearchSuggestionParser::SuggestResult& result) const { | 273 const SearchSuggestionParser::SuggestResult& result) const { |
| 273 // We always use the default provider for search, so append the params. | 274 // We always use the default provider for search, so append the params. |
| 274 return true; | 275 return true; |
| 275 } | 276 } |
| 276 | 277 |
| 277 void ZeroSuggestProvider::RecordDeletionResult(bool success) { | 278 void ZeroSuggestProvider::RecordDeletionResult(bool success) { |
| 278 if (success) { | 279 if (success) { |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 474 matches_.push_back(NavigationToMatch(*it)); | 475 matches_.push_back(NavigationToMatch(*it)); |
| 475 } | 476 } |
| 476 } | 477 } |
| 477 | 478 |
| 478 AutocompleteMatch ZeroSuggestProvider::MatchForCurrentURL() { | 479 AutocompleteMatch ZeroSuggestProvider::MatchForCurrentURL() { |
| 479 // The placeholder suggestion for the current URL has high relevance so | 480 // The placeholder suggestion for the current URL has high relevance so |
| 480 // that it is in the first suggestion slot and inline autocompleted. It | 481 // that it is in the first suggestion slot and inline autocompleted. It |
| 481 // gets dropped as soon as the user types something. | 482 // gets dropped as soon as the user types something. |
| 482 AutocompleteInput tmp(GetInput(false)); | 483 AutocompleteInput tmp(GetInput(false)); |
| 483 tmp.UpdateText(permanent_text_, base::string16::npos, tmp.parts()); | 484 tmp.UpdateText(permanent_text_, base::string16::npos, tmp.parts()); |
| 484 return VerbatimMatchForURL(client(), tmp, GURL(current_query_), | 485 auto match = |
| 485 history_url_provider_, | 486 VerbatimMatchForURL(client(), tmp, GURL(current_query_), |
|
Mark P
2017/04/10 22:38:02
Instead of this, please pass the title all the way
gcomanici
2017/04/11 20:51:41
Done.
| |
| 486 results_.verbatim_relevance); | 487 history_url_provider_, results_.verbatim_relevance); |
| 488 if (base::FeatureList::IsEnabled( | |
| 489 omnibox::kIncludeTitleToACMatchForCurrentUrl)) { | |
| 490 match.description = current_title_; | |
| 491 AutocompleteMatch::ClassifyLocationInString( | |
| 492 base::string16::npos, 0, match.description.length(), | |
| 493 ACMatchClassification::NONE, &match.description_class); | |
| 494 } | |
| 495 return match; | |
| 487 } | 496 } |
| 488 | 497 |
| 489 bool ZeroSuggestProvider::ShouldShowNonContextualZeroSuggest( | 498 bool ZeroSuggestProvider::ShouldShowNonContextualZeroSuggest( |
| 490 const GURL& suggest_url, | 499 const GURL& suggest_url, |
| 491 const GURL& current_page_url) const { | 500 const GURL& current_page_url) const { |
| 492 const TemplateURLService* template_url_service = | 501 const TemplateURLService* template_url_service = |
| 493 client()->GetTemplateURLService(); | 502 client()->GetTemplateURLService(); |
| 494 if (!ZeroSuggestEnabled(suggest_url, | 503 if (!ZeroSuggestEnabled(suggest_url, |
| 495 template_url_service->GetDefaultSearchProvider(), | 504 template_url_service->GetDefaultSearchProvider(), |
| 496 current_page_classification_, | 505 current_page_classification_, |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 548 if (!json_data.empty()) { | 557 if (!json_data.empty()) { |
| 549 std::unique_ptr<base::Value> data( | 558 std::unique_ptr<base::Value> data( |
| 550 SearchSuggestionParser::DeserializeJsonData(json_data)); | 559 SearchSuggestionParser::DeserializeJsonData(json_data)); |
| 551 if (data && ParseSuggestResults( | 560 if (data && ParseSuggestResults( |
| 552 *data, kDefaultZeroSuggestRelevance, false, &results_)) { | 561 *data, kDefaultZeroSuggestRelevance, false, &results_)) { |
| 553 ConvertResultsToAutocompleteMatches(); | 562 ConvertResultsToAutocompleteMatches(); |
| 554 results_from_cache_ = !matches_.empty(); | 563 results_from_cache_ = !matches_.empty(); |
| 555 } | 564 } |
| 556 } | 565 } |
| 557 } | 566 } |
| OLD | NEW |