| 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 "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/i18n/case_conversion.h" | 8 #include "base/i18n/case_conversion.h" |
| 9 #include "base/json/json_string_value_serializer.h" | 9 #include "base/json/json_string_value_serializer.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 11 #include "base/metrics/user_metrics.h" | 11 #include "base/metrics/user_metrics.h" |
| 12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
| 13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
| 14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 17 #include "components/history/core/browser/history_types.h" | 17 #include "components/history/core/browser/history_types.h" |
| 18 #include "components/history/core/browser/top_sites.h" | 18 #include "components/history/core/browser/top_sites.h" |
| 19 #include "components/metrics/proto/omnibox_input_type.pb.h" | 19 #include "components/metrics/proto/omnibox_input_type.pb.h" |
| 20 #include "components/omnibox/browser/autocomplete_classifier.h" | 20 #include "components/omnibox/browser/autocomplete_classifier.h" |
| 21 #include "components/omnibox/browser/autocomplete_input.h" | 21 #include "components/omnibox/browser/autocomplete_input.h" |
| 22 #include "components/omnibox/browser/autocomplete_match.h" | 22 #include "components/omnibox/browser/autocomplete_match.h" |
| 23 #include "components/omnibox/browser/autocomplete_provider_listener.h" | 23 #include "components/omnibox/browser/autocomplete_provider_listener.h" |
| 24 #include "components/omnibox/browser/history_url_provider.h" | 24 #include "components/omnibox/browser/history_url_provider.h" |
| 25 #include "components/omnibox/browser/omnibox_field_trial.h" | 25 #include "components/omnibox/browser/omnibox_field_trial.h" |
| 26 #include "components/omnibox/browser/omnibox_pref_names.h" | 26 #include "components/omnibox/browser/omnibox_pref_names.h" |
| 27 #include "components/omnibox/browser/search_provider.h" | 27 #include "components/omnibox/browser/search_provider.h" |
| 28 #include "components/pref_registry/pref_registry_syncable.h" | 28 #include "components/pref_registry/pref_registry_syncable.h" |
| 29 #include "components/search_engines/template_url_service.h" | 29 #include "components/search_engines/template_url_service.h" |
| 30 #include "components/url_formatter/url_formatter.h" | |
| 31 #include "components/variations/net/variations_http_header_provider.h" | 30 #include "components/variations/net/variations_http_header_provider.h" |
| 32 #include "net/base/escape.h" | 31 #include "net/base/escape.h" |
| 33 #include "net/base/load_flags.h" | 32 #include "net/base/load_flags.h" |
| 33 #include "net/base/net_util.h" |
| 34 #include "net/http/http_request_headers.h" | 34 #include "net/http/http_request_headers.h" |
| 35 #include "net/url_request/url_fetcher.h" | 35 #include "net/url_request/url_fetcher.h" |
| 36 #include "net/url_request/url_request_status.h" | 36 #include "net/url_request/url_request_status.h" |
| 37 #include "url/gurl.h" | 37 #include "url/gurl.h" |
| 38 | 38 |
| 39 namespace { | 39 namespace { |
| 40 | 40 |
| 41 // TODO(hfung): The histogram code was copied and modified from | 41 // TODO(hfung): The histogram code was copied and modified from |
| 42 // search_provider.cc. Refactor and consolidate the code. | 42 // search_provider.cc. Refactor and consolidate the code. |
| 43 // We keep track in a histogram how many suggest requests we send, how | 43 // We keep track in a histogram how many suggest requests we send, how |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 } | 281 } |
| 282 | 282 |
| 283 AutocompleteMatch ZeroSuggestProvider::NavigationToMatch( | 283 AutocompleteMatch ZeroSuggestProvider::NavigationToMatch( |
| 284 const SearchSuggestionParser::NavigationResult& navigation) { | 284 const SearchSuggestionParser::NavigationResult& navigation) { |
| 285 AutocompleteMatch match(this, navigation.relevance(), false, | 285 AutocompleteMatch match(this, navigation.relevance(), false, |
| 286 navigation.type()); | 286 navigation.type()); |
| 287 match.destination_url = navigation.url(); | 287 match.destination_url = navigation.url(); |
| 288 | 288 |
| 289 // Zero suggest results should always omit protocols and never appear bold. | 289 // Zero suggest results should always omit protocols and never appear bold. |
| 290 const std::string languages(client()->GetAcceptLanguages()); | 290 const std::string languages(client()->GetAcceptLanguages()); |
| 291 match.contents = url_formatter::FormatUrl( | 291 match.contents = net::FormatUrl(navigation.url(), languages, |
| 292 navigation.url(), languages, url_formatter::kFormatUrlOmitAll, | 292 net::kFormatUrlOmitAll, net::UnescapeRule::SPACES, NULL, NULL, NULL); |
| 293 net::UnescapeRule::SPACES, nullptr, nullptr, nullptr); | |
| 294 match.fill_into_edit += | 293 match.fill_into_edit += |
| 295 AutocompleteInput::FormattedStringWithEquivalentMeaning( | 294 AutocompleteInput::FormattedStringWithEquivalentMeaning( |
| 296 navigation.url(), match.contents, client()->GetSchemeClassifier()); | 295 navigation.url(), match.contents, client()->GetSchemeClassifier()); |
| 297 | 296 |
| 298 AutocompleteMatch::ClassifyLocationInString(base::string16::npos, 0, | 297 AutocompleteMatch::ClassifyLocationInString(base::string16::npos, 0, |
| 299 match.contents.length(), ACMatchClassification::URL, | 298 match.contents.length(), ACMatchClassification::URL, |
| 300 &match.contents_class); | 299 &match.contents_class); |
| 301 | 300 |
| 302 match.description = | 301 match.description = |
| 303 AutocompleteMatch::SanitizeString(navigation.description()); | 302 AutocompleteMatch::SanitizeString(navigation.description()); |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 if (!json_data.empty()) { | 471 if (!json_data.empty()) { |
| 473 scoped_ptr<base::Value> data( | 472 scoped_ptr<base::Value> data( |
| 474 SearchSuggestionParser::DeserializeJsonData(json_data)); | 473 SearchSuggestionParser::DeserializeJsonData(json_data)); |
| 475 if (data && ParseSuggestResults( | 474 if (data && ParseSuggestResults( |
| 476 *data, kDefaultZeroSuggestRelevance, false, &results_)) { | 475 *data, kDefaultZeroSuggestRelevance, false, &results_)) { |
| 477 ConvertResultsToAutocompleteMatches(); | 476 ConvertResultsToAutocompleteMatches(); |
| 478 results_from_cache_ = !matches_.empty(); | 477 results_from_cache_ = !matches_.empty(); |
| 479 } | 478 } |
| 480 } | 479 } |
| 481 } | 480 } |
| OLD | NEW |