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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 // static | 84 // static |
85 void ZeroSuggestProvider::RegisterProfilePrefs( | 85 void ZeroSuggestProvider::RegisterProfilePrefs( |
86 user_prefs::PrefRegistrySyncable* registry) { | 86 user_prefs::PrefRegistrySyncable* registry) { |
87 registry->RegisterStringPref( | 87 registry->RegisterStringPref( |
88 prefs::kZeroSuggestCachedResults, | 88 prefs::kZeroSuggestCachedResults, |
89 std::string(), | 89 std::string(), |
90 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 90 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
91 } | 91 } |
92 | 92 |
93 void ZeroSuggestProvider::Start(const AutocompleteInput& input, | 93 void ZeroSuggestProvider::Start(const AutocompleteInput& input, |
94 bool minimal_changes) { | 94 bool minimal_changes, |
| 95 bool called_due_to_focus) { |
95 matches_.clear(); | 96 matches_.clear(); |
96 if (input.type() == metrics::OmniboxInputType::INVALID) | 97 if (!called_due_to_focus || |
| 98 input.type() == metrics::OmniboxInputType::INVALID) |
97 return; | 99 return; |
98 | 100 |
99 Stop(true); | 101 Stop(true); |
100 field_trial_triggered_ = false; | 102 field_trial_triggered_ = false; |
101 field_trial_triggered_in_session_ = false; | 103 field_trial_triggered_in_session_ = false; |
102 results_from_cache_ = false; | 104 results_from_cache_ = false; |
103 permanent_text_ = input.text(); | 105 permanent_text_ = input.text(); |
104 current_query_ = input.current_url().spec(); | 106 current_query_ = input.current_url().spec(); |
105 current_page_classification_ = input.current_page_classification(); | 107 current_page_classification_ = input.current_page_classification(); |
106 current_url_match_ = MatchForCurrentURL(); | 108 current_url_match_ = MatchForCurrentURL(); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 } | 172 } |
171 BaseSearchProvider::DeleteMatch(match); | 173 BaseSearchProvider::DeleteMatch(match); |
172 } | 174 } |
173 | 175 |
174 void ZeroSuggestProvider::AddProviderInfo(ProvidersInfo* provider_info) const { | 176 void ZeroSuggestProvider::AddProviderInfo(ProvidersInfo* provider_info) const { |
175 BaseSearchProvider::AddProviderInfo(provider_info); | 177 BaseSearchProvider::AddProviderInfo(provider_info); |
176 if (!results_.suggest_results.empty() || !results_.navigation_results.empty()) | 178 if (!results_.suggest_results.empty() || !results_.navigation_results.empty()) |
177 provider_info->back().set_times_returned_results_in_session(1); | 179 provider_info->back().set_times_returned_results_in_session(1); |
178 } | 180 } |
179 | 181 |
180 bool ZeroSuggestProvider::ProvidesMatchesOnOmniboxFocus() const { | |
181 return true; | |
182 } | |
183 | |
184 void ZeroSuggestProvider::ResetSession() { | 182 void ZeroSuggestProvider::ResetSession() { |
185 // The user has started editing in the omnibox, so leave | 183 // The user has started editing in the omnibox, so leave |
186 // |field_trial_triggered_in_session_| unchanged and set | 184 // |field_trial_triggered_in_session_| unchanged and set |
187 // |field_trial_triggered_| to false since zero suggest is inactive now. | 185 // |field_trial_triggered_| to false since zero suggest is inactive now. |
188 field_trial_triggered_ = false; | 186 field_trial_triggered_ = false; |
189 } | 187 } |
190 | 188 |
191 ZeroSuggestProvider::ZeroSuggestProvider( | 189 ZeroSuggestProvider::ZeroSuggestProvider( |
192 AutocompleteProviderListener* listener, | 190 AutocompleteProviderListener* listener, |
193 TemplateURLService* template_url_service, | 191 TemplateURLService* template_url_service, |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 if (!json_data.empty()) { | 480 if (!json_data.empty()) { |
483 scoped_ptr<base::Value> data( | 481 scoped_ptr<base::Value> data( |
484 SearchSuggestionParser::DeserializeJsonData(json_data)); | 482 SearchSuggestionParser::DeserializeJsonData(json_data)); |
485 if (data && ParseSuggestResults( | 483 if (data && ParseSuggestResults( |
486 *data, kDefaultZeroSuggestRelevance, false, &results_)) { | 484 *data, kDefaultZeroSuggestRelevance, false, &results_)) { |
487 ConvertResultsToAutocompleteMatches(); | 485 ConvertResultsToAutocompleteMatches(); |
488 results_from_cache_ = !matches_.empty(); | 486 results_from_cache_ = !matches_.empty(); |
489 } | 487 } |
490 } | 488 } |
491 } | 489 } |
OLD | NEW |