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 "chrome/browser/autocomplete/zero_suggest_provider.h" | 5 #include "chrome/browser/autocomplete/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" |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include "components/history/core/browser/history_types.h" | 26 #include "components/history/core/browser/history_types.h" |
27 #include "components/history/core/browser/top_sites.h" | 27 #include "components/history/core/browser/top_sites.h" |
28 #include "components/metrics/proto/omnibox_input_type.pb.h" | 28 #include "components/metrics/proto/omnibox_input_type.pb.h" |
29 #include "components/omnibox/autocomplete_input.h" | 29 #include "components/omnibox/autocomplete_input.h" |
30 #include "components/omnibox/autocomplete_match.h" | 30 #include "components/omnibox/autocomplete_match.h" |
31 #include "components/omnibox/autocomplete_provider_listener.h" | 31 #include "components/omnibox/autocomplete_provider_listener.h" |
32 #include "components/omnibox/omnibox_field_trial.h" | 32 #include "components/omnibox/omnibox_field_trial.h" |
33 #include "components/omnibox/search_provider.h" | 33 #include "components/omnibox/search_provider.h" |
34 #include "components/pref_registry/pref_registry_syncable.h" | 34 #include "components/pref_registry/pref_registry_syncable.h" |
35 #include "components/search_engines/template_url_service.h" | 35 #include "components/search_engines/template_url_service.h" |
| 36 #include "components/url_formatter/url_formatter.h" |
36 #include "components/variations/net/variations_http_header_provider.h" | 37 #include "components/variations/net/variations_http_header_provider.h" |
37 #include "net/base/escape.h" | 38 #include "net/base/escape.h" |
38 #include "net/base/load_flags.h" | 39 #include "net/base/load_flags.h" |
39 #include "net/base/net_util.h" | |
40 #include "net/http/http_request_headers.h" | 40 #include "net/http/http_request_headers.h" |
41 #include "net/url_request/url_fetcher.h" | 41 #include "net/url_request/url_fetcher.h" |
42 #include "net/url_request/url_request_status.h" | 42 #include "net/url_request/url_request_status.h" |
43 #include "url/gurl.h" | 43 #include "url/gurl.h" |
44 | 44 |
45 namespace { | 45 namespace { |
46 | 46 |
47 // TODO(hfung): The histogram code was copied and modified from | 47 // TODO(hfung): The histogram code was copied and modified from |
48 // search_provider.cc. Refactor and consolidate the code. | 48 // search_provider.cc. Refactor and consolidate the code. |
49 // We keep track in a histogram how many suggest requests we send, how | 49 // We keep track in a histogram how many suggest requests we send, how |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 | 292 |
293 AutocompleteMatch ZeroSuggestProvider::NavigationToMatch( | 293 AutocompleteMatch ZeroSuggestProvider::NavigationToMatch( |
294 const SearchSuggestionParser::NavigationResult& navigation) { | 294 const SearchSuggestionParser::NavigationResult& navigation) { |
295 AutocompleteMatch match(this, navigation.relevance(), false, | 295 AutocompleteMatch match(this, navigation.relevance(), false, |
296 navigation.type()); | 296 navigation.type()); |
297 match.destination_url = navigation.url(); | 297 match.destination_url = navigation.url(); |
298 | 298 |
299 // Zero suggest results should always omit protocols and never appear bold. | 299 // Zero suggest results should always omit protocols and never appear bold. |
300 const std::string languages( | 300 const std::string languages( |
301 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)); | 301 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)); |
302 match.contents = net::FormatUrl(navigation.url(), languages, | 302 match.contents = url_formatter::FormatUrl( |
303 net::kFormatUrlOmitAll, net::UnescapeRule::SPACES, NULL, NULL, NULL); | 303 navigation.url(), languages, url_formatter::kFormatUrlOmitAll, |
| 304 net::UnescapeRule::SPACES, nullptr, nullptr, nullptr); |
304 match.fill_into_edit += | 305 match.fill_into_edit += |
305 AutocompleteInput::FormattedStringWithEquivalentMeaning(navigation.url(), | 306 AutocompleteInput::FormattedStringWithEquivalentMeaning(navigation.url(), |
306 match.contents, ChromeAutocompleteSchemeClassifier(profile_)); | 307 match.contents, ChromeAutocompleteSchemeClassifier(profile_)); |
307 | 308 |
308 AutocompleteMatch::ClassifyLocationInString(base::string16::npos, 0, | 309 AutocompleteMatch::ClassifyLocationInString(base::string16::npos, 0, |
309 match.contents.length(), ACMatchClassification::URL, | 310 match.contents.length(), ACMatchClassification::URL, |
310 &match.contents_class); | 311 &match.contents_class); |
311 | 312 |
312 match.description = | 313 match.description = |
313 AutocompleteMatch::SanitizeString(navigation.description()); | 314 AutocompleteMatch::SanitizeString(navigation.description()); |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 if (!json_data.empty()) { | 481 if (!json_data.empty()) { |
481 scoped_ptr<base::Value> data( | 482 scoped_ptr<base::Value> data( |
482 SearchSuggestionParser::DeserializeJsonData(json_data)); | 483 SearchSuggestionParser::DeserializeJsonData(json_data)); |
483 if (data && ParseSuggestResults( | 484 if (data && ParseSuggestResults( |
484 *data, kDefaultZeroSuggestRelevance, false, &results_)) { | 485 *data, kDefaultZeroSuggestRelevance, false, &results_)) { |
485 ConvertResultsToAutocompleteMatches(); | 486 ConvertResultsToAutocompleteMatches(); |
486 results_from_cache_ = !matches_.empty(); | 487 results_from_cache_ = !matches_.empty(); |
487 } | 488 } |
488 } | 489 } |
489 } | 490 } |
OLD | NEW |