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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 void ZeroSuggestProvider::Stop(bool clear_cached_results) { | 146 void ZeroSuggestProvider::Stop(bool clear_cached_results) { |
147 if (fetcher_) | 147 if (fetcher_) |
148 LogOmniboxZeroSuggestRequest(ZERO_SUGGEST_REQUEST_INVALIDATED); | 148 LogOmniboxZeroSuggestRequest(ZERO_SUGGEST_REQUEST_INVALIDATED); |
149 fetcher_.reset(); | 149 fetcher_.reset(); |
150 waiting_for_most_visited_urls_request_ = false; | 150 waiting_for_most_visited_urls_request_ = false; |
151 done_ = true; | 151 done_ = true; |
152 | 152 |
153 if (clear_cached_results) { | 153 if (clear_cached_results) { |
154 // We do not call Clear() on |results_| to retain |verbatim_relevance| | 154 // We do not call Clear() on |results_| to retain |verbatim_relevance| |
155 // value in the |results_| object. |verbatim_relevance| is used at the | 155 // value in the |results_| object. |verbatim_relevance| is used at the |
156 // beginning of the next StartZeroSuggest() call to determine the current | 156 // beginning of the next OnOmniboxFocused() call to determine the current |
157 // url match relevance. | 157 // url match relevance. |
158 results_.suggest_results.clear(); | 158 results_.suggest_results.clear(); |
159 results_.navigation_results.clear(); | 159 results_.navigation_results.clear(); |
160 current_query_.clear(); | 160 current_query_.clear(); |
161 } | 161 } |
162 } | 162 } |
163 | 163 |
164 void ZeroSuggestProvider::DeleteMatch(const AutocompleteMatch& match) { | 164 void ZeroSuggestProvider::DeleteMatch(const AutocompleteMatch& match) { |
165 if (OmniboxFieldTrial::InZeroSuggestPersonalizedFieldTrial()) { | 165 if (OmniboxFieldTrial::InZeroSuggestPersonalizedFieldTrial()) { |
166 // Remove the deleted match from the cache, so it is not shown to the user | 166 // Remove the deleted match from the cache, so it is not shown to the user |
167 // again. Since we cannot remove just one result, blow away the cache. | 167 // again. Since we cannot remove just one result, blow away the cache. |
168 profile_->GetPrefs()->SetString(prefs::kZeroSuggestCachedResults, | 168 profile_->GetPrefs()->SetString(prefs::kZeroSuggestCachedResults, |
169 std::string()); | 169 std::string()); |
170 } | 170 } |
171 BaseSearchProvider::DeleteMatch(match); | 171 BaseSearchProvider::DeleteMatch(match); |
172 } | 172 } |
173 | 173 |
174 void ZeroSuggestProvider::AddProviderInfo(ProvidersInfo* provider_info) const { | 174 void ZeroSuggestProvider::AddProviderInfo(ProvidersInfo* provider_info) const { |
175 BaseSearchProvider::AddProviderInfo(provider_info); | 175 BaseSearchProvider::AddProviderInfo(provider_info); |
176 if (!results_.suggest_results.empty() || !results_.navigation_results.empty()) | 176 if (!results_.suggest_results.empty() || !results_.navigation_results.empty()) |
177 provider_info->back().set_times_returned_results_in_session(1); | 177 provider_info->back().set_times_returned_results_in_session(1); |
178 } | 178 } |
179 | 179 |
| 180 bool ZeroSuggestProvider::ProvidesMatchesOnOmniboxFocus() const { |
| 181 return true; |
| 182 } |
| 183 |
180 void ZeroSuggestProvider::ResetSession() { | 184 void ZeroSuggestProvider::ResetSession() { |
181 // The user has started editing in the omnibox, so leave | 185 // The user has started editing in the omnibox, so leave |
182 // |field_trial_triggered_in_session_| unchanged and set | 186 // |field_trial_triggered_in_session_| unchanged and set |
183 // |field_trial_triggered_| to false since zero suggest is inactive now. | 187 // |field_trial_triggered_| to false since zero suggest is inactive now. |
184 field_trial_triggered_ = false; | 188 field_trial_triggered_ = false; |
185 } | 189 } |
186 | 190 |
187 ZeroSuggestProvider::ZeroSuggestProvider( | 191 ZeroSuggestProvider::ZeroSuggestProvider( |
188 AutocompleteProviderListener* listener, | 192 AutocompleteProviderListener* listener, |
189 TemplateURLService* template_url_service, | 193 TemplateURLService* template_url_service, |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 if (!json_data.empty()) { | 482 if (!json_data.empty()) { |
479 scoped_ptr<base::Value> data( | 483 scoped_ptr<base::Value> data( |
480 SearchSuggestionParser::DeserializeJsonData(json_data)); | 484 SearchSuggestionParser::DeserializeJsonData(json_data)); |
481 if (data && ParseSuggestResults( | 485 if (data && ParseSuggestResults( |
482 *data, kDefaultZeroSuggestRelevance, false, &results_)) { | 486 *data, kDefaultZeroSuggestRelevance, false, &results_)) { |
483 ConvertResultsToAutocompleteMatches(); | 487 ConvertResultsToAutocompleteMatches(); |
484 results_from_cache_ = !matches_.empty(); | 488 results_from_cache_ = !matches_.empty(); |
485 } | 489 } |
486 } | 490 } |
487 } | 491 } |
OLD | NEW |