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