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 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 AddMatchToMap(results[i], std::string(), i, false, false, map); | 283 AddMatchToMap(results[i], std::string(), i, false, false, map); |
284 } | 284 } |
285 | 285 |
286 AutocompleteMatch ZeroSuggestProvider::NavigationToMatch( | 286 AutocompleteMatch ZeroSuggestProvider::NavigationToMatch( |
287 const SearchSuggestionParser::NavigationResult& navigation) { | 287 const SearchSuggestionParser::NavigationResult& navigation) { |
288 AutocompleteMatch match(this, navigation.relevance(), false, | 288 AutocompleteMatch match(this, navigation.relevance(), false, |
289 navigation.type()); | 289 navigation.type()); |
290 match.destination_url = navigation.url(); | 290 match.destination_url = navigation.url(); |
291 | 291 |
292 // Zero suggest results should always omit protocols and never appear bold. | 292 // Zero suggest results should always omit protocols and never appear bold. |
293 const std::string languages(client()->GetAcceptLanguages()); | |
294 match.contents = url_formatter::FormatUrl( | 293 match.contents = url_formatter::FormatUrl( |
295 navigation.url(), languages, url_formatter::kFormatUrlOmitAll, | 294 navigation.url(), url_formatter::kFormatUrlOmitAll, |
296 net::UnescapeRule::SPACES, nullptr, nullptr, nullptr); | 295 net::UnescapeRule::SPACES, nullptr, nullptr, nullptr); |
297 match.fill_into_edit += | 296 match.fill_into_edit += |
298 AutocompleteInput::FormattedStringWithEquivalentMeaning( | 297 AutocompleteInput::FormattedStringWithEquivalentMeaning( |
299 navigation.url(), match.contents, client()->GetSchemeClassifier()); | 298 navigation.url(), match.contents, client()->GetSchemeClassifier()); |
300 | 299 |
301 AutocompleteMatch::ClassifyLocationInString(base::string16::npos, 0, | 300 AutocompleteMatch::ClassifyLocationInString(base::string16::npos, 0, |
302 match.contents.length(), ACMatchClassification::URL, | 301 match.contents.length(), ACMatchClassification::URL, |
303 &match.contents_class); | 302 &match.contents_class); |
304 | 303 |
305 match.description = | 304 match.description = |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 return; | 376 return; |
378 matches_.push_back(current_url_match_); | 377 matches_.push_back(current_url_match_); |
379 int relevance = 600; | 378 int relevance = 600; |
380 if (num_results > 0) { | 379 if (num_results > 0) { |
381 UMA_HISTOGRAM_COUNTS( | 380 UMA_HISTOGRAM_COUNTS( |
382 "Omnibox.ZeroSuggest.MostVisitedResultsCounterfactual", | 381 "Omnibox.ZeroSuggest.MostVisitedResultsCounterfactual", |
383 most_visited_urls_.size()); | 382 most_visited_urls_.size()); |
384 } | 383 } |
385 const base::string16 current_query_string16( | 384 const base::string16 current_query_string16( |
386 base::ASCIIToUTF16(current_query_)); | 385 base::ASCIIToUTF16(current_query_)); |
387 const std::string languages(client()->GetAcceptLanguages()); | |
388 for (size_t i = 0; i < most_visited_urls_.size(); i++) { | 386 for (size_t i = 0; i < most_visited_urls_.size(); i++) { |
389 const history::MostVisitedURL& url = most_visited_urls_[i]; | 387 const history::MostVisitedURL& url = most_visited_urls_[i]; |
390 SearchSuggestionParser::NavigationResult nav( | 388 SearchSuggestionParser::NavigationResult nav( |
391 client()->GetSchemeClassifier(), url.url, | 389 client()->GetSchemeClassifier(), url.url, |
392 AutocompleteMatchType::NAVSUGGEST, url.title, std::string(), false, | 390 AutocompleteMatchType::NAVSUGGEST, url.title, std::string(), false, |
393 relevance, true, current_query_string16, languages); | 391 relevance, true, current_query_string16); |
394 matches_.push_back(NavigationToMatch(nav)); | 392 matches_.push_back(NavigationToMatch(nav)); |
395 --relevance; | 393 --relevance; |
396 } | 394 } |
397 return; | 395 return; |
398 } | 396 } |
399 | 397 |
400 if (num_results == 0) | 398 if (num_results == 0) |
401 return; | 399 return; |
402 | 400 |
403 // TODO(jered): Rip this out once the first match is decoupled from the | 401 // TODO(jered): Rip this out once the first match is decoupled from the |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 if (!json_data.empty()) { | 465 if (!json_data.empty()) { |
468 scoped_ptr<base::Value> data( | 466 scoped_ptr<base::Value> data( |
469 SearchSuggestionParser::DeserializeJsonData(json_data)); | 467 SearchSuggestionParser::DeserializeJsonData(json_data)); |
470 if (data && ParseSuggestResults( | 468 if (data && ParseSuggestResults( |
471 *data, kDefaultZeroSuggestRelevance, false, &results_)) { | 469 *data, kDefaultZeroSuggestRelevance, false, &results_)) { |
472 ConvertResultsToAutocompleteMatches(); | 470 ConvertResultsToAutocompleteMatches(); |
473 results_from_cache_ = !matches_.empty(); | 471 results_from_cache_ = !matches_.empty(); |
474 } | 472 } |
475 } | 473 } |
476 } | 474 } |
OLD | NEW |