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/i18n/case_conversion.h" | 10 #include "base/i18n/case_conversion.h" |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 333 return results_from_cache_; | 333 return results_from_cache_; |
| 334 } | 334 } |
| 335 | 335 |
| 336 void ZeroSuggestProvider::AddSuggestResultsToMap( | 336 void ZeroSuggestProvider::AddSuggestResultsToMap( |
| 337 const SearchSuggestionParser::SuggestResults& results, | 337 const SearchSuggestionParser::SuggestResults& results, |
| 338 MatchMap* map) { | 338 MatchMap* map) { |
| 339 for (size_t i = 0; i < results.size(); ++i) | 339 for (size_t i = 0; i < results.size(); ++i) |
| 340 AddMatchToMap(results[i], std::string(), i, false, false, map); | 340 AddMatchToMap(results[i], std::string(), i, false, false, map); |
| 341 } | 341 } |
| 342 | 342 |
| 343 AutocompleteMatch ZeroSuggestProvider::NavigationToMatch( | 343 AutocompleteMatch ZeroSuggestProvider::NavigationToMatch( |
|
Mark P
2017/03/21 19:54:25
Per my request to make this more general, you'll a
gcomanici
2017/03/22 02:39:03
Done.
| |
| 344 const SearchSuggestionParser::NavigationResult& navigation) { | 344 const SearchSuggestionParser::NavigationResult& navigation) { |
| 345 AutocompleteMatch match(this, navigation.relevance(), false, | 345 AutocompleteMatch match(this, navigation.relevance(), false, |
| 346 navigation.type()); | 346 navigation.type()); |
| 347 match.destination_url = navigation.url(); | 347 match.destination_url = navigation.url(); |
| 348 | 348 |
| 349 // Zero suggest results should always omit protocols and never appear bold. | 349 // Zero suggest results should always omit protocols and never appear bold. |
| 350 match.contents = url_formatter::FormatUrl( | 350 match.contents = url_formatter::FormatUrl( |
| 351 navigation.url(), url_formatter::kFormatUrlOmitAll, | 351 navigation.url(), url_formatter::kFormatUrlOmitAll, |
| 352 net::UnescapeRule::SPACES, nullptr, nullptr, nullptr); | 352 net::UnescapeRule::SPACES, nullptr, nullptr, nullptr); |
| 353 match.fill_into_edit += | 353 match.fill_into_edit += |
| 354 AutocompleteInput::FormattedStringWithEquivalentMeaning( | 354 AutocompleteInput::FormattedStringWithEquivalentMeaning( |
| 355 navigation.url(), match.contents, client()->GetSchemeClassifier()); | 355 navigation.url(), match.contents, client()->GetSchemeClassifier()); |
| 356 | 356 |
| 357 AutocompleteMatch::ClassifyLocationInString(base::string16::npos, 0, | 357 AutocompleteMatch::ClassifyLocationInString(base::string16::npos, 0, |
| 358 match.contents.length(), ACMatchClassification::URL, | 358 match.contents.length(), ACMatchClassification::URL, |
| 359 &match.contents_class); | 359 &match.contents_class); |
| 360 | 360 |
| 361 match.description = | 361 match.description = |
| 362 AutocompleteMatch::SanitizeString(navigation.description()); | 362 AutocompleteMatch::SanitizeString(navigation.description()); |
| 363 AutocompleteMatch::ClassifyLocationInString(base::string16::npos, 0, | 363 AutocompleteMatch::ClassifyLocationInString(base::string16::npos, 0, |
| 364 match.description.length(), ACMatchClassification::NONE, | 364 match.description.length(), ACMatchClassification::NONE, |
| 365 &match.description_class); | 365 &match.description_class); |
| 366 match.specific_type_identifier = navigation.specific_type_identifier(); | |
| 366 return match; | 367 return match; |
| 367 } | 368 } |
| 368 | 369 |
| 369 void ZeroSuggestProvider::Run(const GURL& suggest_url) { | 370 void ZeroSuggestProvider::Run(const GURL& suggest_url) { |
| 370 if (OmniboxFieldTrial::InZeroSuggestMostVisitedFieldTrial()) { | 371 if (OmniboxFieldTrial::InZeroSuggestMostVisitedFieldTrial()) { |
| 371 most_visited_urls_.clear(); | 372 most_visited_urls_.clear(); |
| 372 scoped_refptr<history::TopSites> ts = client()->GetTopSites(); | 373 scoped_refptr<history::TopSites> ts = client()->GetTopSites(); |
| 373 if (ts) { | 374 if (ts) { |
| 374 waiting_for_most_visited_urls_request_ = true; | 375 waiting_for_most_visited_urls_request_ = true; |
| 375 ts->GetMostVisitedURLs( | 376 ts->GetMostVisitedURLs( |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 441 "Omnibox.ZeroSuggest.MostVisitedResultsCounterfactual", | 442 "Omnibox.ZeroSuggest.MostVisitedResultsCounterfactual", |
| 442 most_visited_urls_.size()); | 443 most_visited_urls_.size()); |
| 443 } | 444 } |
| 444 const base::string16 current_query_string16( | 445 const base::string16 current_query_string16( |
| 445 base::ASCIIToUTF16(current_query_)); | 446 base::ASCIIToUTF16(current_query_)); |
| 446 for (size_t i = 0; i < most_visited_urls_.size(); i++) { | 447 for (size_t i = 0; i < most_visited_urls_.size(); i++) { |
| 447 const history::MostVisitedURL& url = most_visited_urls_[i]; | 448 const history::MostVisitedURL& url = most_visited_urls_[i]; |
| 448 SearchSuggestionParser::NavigationResult nav( | 449 SearchSuggestionParser::NavigationResult nav( |
| 449 client()->GetSchemeClassifier(), url.url, | 450 client()->GetSchemeClassifier(), url.url, |
| 450 AutocompleteMatchType::NAVSUGGEST, url.title, std::string(), false, | 451 AutocompleteMatchType::NAVSUGGEST, url.title, std::string(), false, |
| 451 relevance, true, current_query_string16); | 452 relevance, true, current_query_string16, 0); |
| 452 matches_.push_back(NavigationToMatch(nav)); | 453 matches_.push_back(NavigationToMatch(nav)); |
| 453 --relevance; | 454 --relevance; |
| 454 } | 455 } |
| 455 return; | 456 return; |
| 456 } | 457 } |
| 457 | 458 |
| 458 if (num_results == 0) | 459 if (num_results == 0) |
| 459 return; | 460 return; |
| 460 | 461 |
| 461 // TODO(jered): Rip this out once the first match is decoupled from the | 462 // TODO(jered): Rip this out once the first match is decoupled from the |
| 462 // current typing in the omnibox. | 463 // current typing in the omnibox. |
| 463 matches_.push_back(current_url_match_); | 464 matches_.push_back(current_url_match_); |
| 464 | 465 |
| 465 for (MatchMap::const_iterator it(map.begin()); it != map.end(); ++it) | 466 for (MatchMap::const_iterator it(map.begin()); it != map.end(); ++it) |
| 466 matches_.push_back(it->second); | 467 matches_.push_back(it->second); |
| 467 | 468 |
| 468 const SearchSuggestionParser::NavigationResults& nav_results( | 469 const SearchSuggestionParser::NavigationResults& nav_results( |
| 469 results_.navigation_results); | 470 results_.navigation_results); |
| 470 for (SearchSuggestionParser::NavigationResults::const_iterator it( | 471 for (SearchSuggestionParser::NavigationResults::const_iterator it( |
| 471 nav_results.begin()); it != nav_results.end(); ++it) | 472 nav_results.begin()); |
| 473 it != nav_results.end(); ++it) { | |
| 472 matches_.push_back(NavigationToMatch(*it)); | 474 matches_.push_back(NavigationToMatch(*it)); |
| 475 } | |
| 473 } | 476 } |
| 474 | 477 |
| 475 AutocompleteMatch ZeroSuggestProvider::MatchForCurrentURL() { | 478 AutocompleteMatch ZeroSuggestProvider::MatchForCurrentURL() { |
| 476 // The placeholder suggestion for the current URL has high relevance so | 479 // The placeholder suggestion for the current URL has high relevance so |
| 477 // that it is in the first suggestion slot and inline autocompleted. It | 480 // that it is in the first suggestion slot and inline autocompleted. It |
| 478 // gets dropped as soon as the user types something. | 481 // gets dropped as soon as the user types something. |
| 479 AutocompleteInput tmp(GetInput(false)); | 482 AutocompleteInput tmp(GetInput(false)); |
| 480 tmp.UpdateText(permanent_text_, base::string16::npos, tmp.parts()); | 483 tmp.UpdateText(permanent_text_, base::string16::npos, tmp.parts()); |
| 481 return VerbatimMatchForURL(client(), tmp, GURL(current_query_), | 484 return VerbatimMatchForURL(client(), tmp, GURL(current_query_), |
| 482 history_url_provider_, | 485 history_url_provider_, |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 545 if (!json_data.empty()) { | 548 if (!json_data.empty()) { |
| 546 std::unique_ptr<base::Value> data( | 549 std::unique_ptr<base::Value> data( |
| 547 SearchSuggestionParser::DeserializeJsonData(json_data)); | 550 SearchSuggestionParser::DeserializeJsonData(json_data)); |
| 548 if (data && ParseSuggestResults( | 551 if (data && ParseSuggestResults( |
| 549 *data, kDefaultZeroSuggestRelevance, false, &results_)) { | 552 *data, kDefaultZeroSuggestRelevance, false, &results_)) { |
| 550 ConvertResultsToAutocompleteMatches(); | 553 ConvertResultsToAutocompleteMatches(); |
| 551 results_from_cache_ = !matches_.empty(); | 554 results_from_cache_ = !matches_.empty(); |
| 552 } | 555 } |
| 553 } | 556 } |
| 554 } | 557 } |
| OLD | NEW |