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 14 matching lines...) Expand all Loading... |
25 #include "chrome/browser/history/top_sites.h" | 25 #include "chrome/browser/history/top_sites.h" |
26 #include "chrome/browser/metrics/variations/variations_http_header_provider.h" | 26 #include "chrome/browser/metrics/variations/variations_http_header_provider.h" |
27 #include "chrome/browser/omnibox/omnibox_field_trial.h" | 27 #include "chrome/browser/omnibox/omnibox_field_trial.h" |
28 #include "chrome/browser/profiles/profile.h" | 28 #include "chrome/browser/profiles/profile.h" |
29 #include "chrome/browser/search/search.h" | 29 #include "chrome/browser/search/search.h" |
30 #include "chrome/browser/search_engines/template_url_service.h" | 30 #include "chrome/browser/search_engines/template_url_service.h" |
31 #include "chrome/browser/search_engines/template_url_service_factory.h" | 31 #include "chrome/browser/search_engines/template_url_service_factory.h" |
32 #include "chrome/common/net/url_fixer_upper.h" | 32 #include "chrome/common/net/url_fixer_upper.h" |
33 #include "chrome/common/pref_names.h" | 33 #include "chrome/common/pref_names.h" |
34 #include "chrome/common/url_constants.h" | 34 #include "chrome/common/url_constants.h" |
35 #include "components/metrics/proto/omnibox_input_type.pb.h" | |
36 #include "components/pref_registry/pref_registry_syncable.h" | 35 #include "components/pref_registry/pref_registry_syncable.h" |
37 #include "content/public/browser/user_metrics.h" | 36 #include "content/public/browser/user_metrics.h" |
38 #include "net/base/escape.h" | 37 #include "net/base/escape.h" |
39 #include "net/base/load_flags.h" | 38 #include "net/base/load_flags.h" |
40 #include "net/base/net_util.h" | 39 #include "net/base/net_util.h" |
41 #include "net/http/http_request_headers.h" | 40 #include "net/http/http_request_headers.h" |
42 #include "net/url_request/url_fetcher.h" | 41 #include "net/url_request/url_fetcher.h" |
43 #include "net/url_request/url_request_status.h" | 42 #include "net/url_request/url_request_status.h" |
44 #include "url/gurl.h" | 43 #include "url/gurl.h" |
45 | 44 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 user_prefs::PrefRegistrySyncable* registry) { | 86 user_prefs::PrefRegistrySyncable* registry) { |
88 registry->RegisterStringPref( | 87 registry->RegisterStringPref( |
89 prefs::kZeroSuggestCachedResults, | 88 prefs::kZeroSuggestCachedResults, |
90 std::string(), | 89 std::string(), |
91 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 90 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
92 } | 91 } |
93 | 92 |
94 void ZeroSuggestProvider::Start(const AutocompleteInput& input, | 93 void ZeroSuggestProvider::Start(const AutocompleteInput& input, |
95 bool minimal_changes) { | 94 bool minimal_changes) { |
96 matches_.clear(); | 95 matches_.clear(); |
97 if (input.type() == metrics::OmniboxInputType::INVALID) | 96 if (input.type() == AutocompleteInput::INVALID) |
98 return; | 97 return; |
99 | 98 |
100 Stop(true); | 99 Stop(true); |
101 field_trial_triggered_ = false; | 100 field_trial_triggered_ = false; |
102 field_trial_triggered_in_session_ = false; | 101 field_trial_triggered_in_session_ = false; |
103 results_from_cache_ = false; | 102 results_from_cache_ = false; |
104 permanent_text_ = input.text(); | 103 permanent_text_ = input.text(); |
105 current_query_ = input.current_url().spec(); | 104 current_query_ = input.current_url().spec(); |
106 current_page_classification_ = input.current_page_classification(); | 105 current_page_classification_ = input.current_page_classification(); |
107 current_url_match_ = MatchForCurrentURL(); | 106 current_url_match_ = MatchForCurrentURL(); |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 std::string json_data = profile_->GetPrefs()->GetString( | 452 std::string json_data = profile_->GetPrefs()->GetString( |
454 prefs::kZeroSuggestCachedResults); | 453 prefs::kZeroSuggestCachedResults); |
455 if (!json_data.empty()) { | 454 if (!json_data.empty()) { |
456 scoped_ptr<base::Value> data(DeserializeJsonData(json_data)); | 455 scoped_ptr<base::Value> data(DeserializeJsonData(json_data)); |
457 if (data && ParseSuggestResults(*data.get(), false, &results_)) { | 456 if (data && ParseSuggestResults(*data.get(), false, &results_)) { |
458 ConvertResultsToAutocompleteMatches(); | 457 ConvertResultsToAutocompleteMatches(); |
459 results_from_cache_ = !matches_.empty(); | 458 results_from_cache_ = !matches_.empty(); |
460 } | 459 } |
461 } | 460 } |
462 } | 461 } |
OLD | NEW |