Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: chrome/browser/autocomplete/zero_suggest_provider.cc

Issue 456843003: Remove protected virtual methods from BaseSearchProvider (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/autocomplete/zero_suggest_provider.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 } 132 }
133 133
134 done_ = false; 134 done_ = false;
135 // TODO(jered): Consider adding locally-sourced zero-suggestions here too. 135 // TODO(jered): Consider adding locally-sourced zero-suggestions here too.
136 // These may be useful on the NTP or more relevant to the user than server 136 // These may be useful on the NTP or more relevant to the user than server
137 // suggestions, if based on local browsing history. 137 // suggestions, if based on local browsing history.
138 MaybeUseCachedSuggestions(); 138 MaybeUseCachedSuggestions();
139 Run(suggest_url); 139 Run(suggest_url);
140 } 140 }
141 141
142 void ZeroSuggestProvider::Stop(bool clear_cached_results) {
143 if (fetcher_)
144 LogOmniboxZeroSuggestRequest(ZERO_SUGGEST_REQUEST_INVALIDATED);
145 fetcher_.reset();
146 done_ = true;
147
148 if (clear_cached_results) {
149 // We do not call Clear() on |results_| to retain |verbatim_relevance|
150 // value in the |results_| object. |verbatim_relevance| is used at the
151 // beginning of the next StartZeroSuggest() call to determine the current
152 // url match relevance.
153 results_.suggest_results.clear();
154 results_.navigation_results.clear();
155 current_query_.clear();
156 }
157 }
158
142 void ZeroSuggestProvider::DeleteMatch(const AutocompleteMatch& match) { 159 void ZeroSuggestProvider::DeleteMatch(const AutocompleteMatch& match) {
143 if (OmniboxFieldTrial::InZeroSuggestPersonalizedFieldTrial()) { 160 if (OmniboxFieldTrial::InZeroSuggestPersonalizedFieldTrial()) {
144 // Remove the deleted match from the cache, so it is not shown to the user 161 // Remove the deleted match from the cache, so it is not shown to the user
145 // again. Since we cannot remove just one result, blow away the cache. 162 // again. Since we cannot remove just one result, blow away the cache.
146 profile_->GetPrefs()->SetString(prefs::kZeroSuggestCachedResults, 163 profile_->GetPrefs()->SetString(prefs::kZeroSuggestCachedResults,
147 std::string()); 164 std::string());
148 } 165 }
149 BaseSearchProvider::DeleteMatch(match); 166 BaseSearchProvider::DeleteMatch(match);
150 } 167 }
151 168
169 void ZeroSuggestProvider::AddProviderInfo(ProvidersInfo* provider_info) const {
170 BaseSearchProvider::AddProviderInfo(provider_info);
171 if (!results_.suggest_results.empty() || !results_.navigation_results.empty())
172 provider_info->back().set_times_returned_results_in_session(1);
173 }
174
152 void ZeroSuggestProvider::ResetSession() { 175 void ZeroSuggestProvider::ResetSession() {
153 // The user has started editing in the omnibox, so leave 176 // The user has started editing in the omnibox, so leave
154 // |field_trial_triggered_in_session_| unchanged and set 177 // |field_trial_triggered_in_session_| unchanged and set
155 // |field_trial_triggered_| to false since zero suggest is inactive now. 178 // |field_trial_triggered_| to false since zero suggest is inactive now.
156 field_trial_triggered_ = false; 179 field_trial_triggered_ = false;
157 } 180 }
158 181
159 void ZeroSuggestProvider::ModifyProviderInfo(
160 metrics::OmniboxEventProto_ProviderInfo* provider_info) const {
161 if (!results_.suggest_results.empty() || !results_.navigation_results.empty())
162 provider_info->set_times_returned_results_in_session(1);
163 }
164
165 ZeroSuggestProvider::ZeroSuggestProvider( 182 ZeroSuggestProvider::ZeroSuggestProvider(
166 AutocompleteProviderListener* listener, 183 AutocompleteProviderListener* listener,
167 TemplateURLService* template_url_service, 184 TemplateURLService* template_url_service,
168 Profile* profile) 185 Profile* profile)
169 : BaseSearchProvider(template_url_service, profile, 186 : BaseSearchProvider(template_url_service, profile,
170 AutocompleteProvider::TYPE_ZERO_SUGGEST), 187 AutocompleteProvider::TYPE_ZERO_SUGGEST),
171 listener_(listener), 188 listener_(listener),
172 results_from_cache_(false), 189 results_from_cache_(false),
173 weak_ptr_factory_(this) { 190 weak_ptr_factory_(this) {
174 } 191 }
(...skipping 13 matching lines...) Expand all
188 GURL(current_query_), current_page_classification_, true, false, false, 205 GURL(current_query_), current_page_classification_, true, false, false,
189 true, ChromeAutocompleteSchemeClassifier(profile_)); 206 true, ChromeAutocompleteSchemeClassifier(profile_));
190 } 207 }
191 208
192 bool ZeroSuggestProvider::ShouldAppendExtraParams( 209 bool ZeroSuggestProvider::ShouldAppendExtraParams(
193 const SearchSuggestionParser::SuggestResult& result) const { 210 const SearchSuggestionParser::SuggestResult& result) const {
194 // We always use the default provider for search, so append the params. 211 // We always use the default provider for search, so append the params.
195 return true; 212 return true;
196 } 213 }
197 214
198 void ZeroSuggestProvider::StopSuggest() {
199 if (fetcher_)
200 LogOmniboxZeroSuggestRequest(ZERO_SUGGEST_REQUEST_INVALIDATED);
201 fetcher_.reset();
202 }
203
204 void ZeroSuggestProvider::ClearAllResults() {
205 // We do not call Clear() on |results_| to retain |verbatim_relevance|
206 // value in the |results_| object. |verbatim_relevance| is used at the
207 // beginning of the next StartZeroSuggest() call to determine the current url
208 // match relevance.
209 results_.suggest_results.clear();
210 results_.navigation_results.clear();
211 current_query_.clear();
212 }
213
214 void ZeroSuggestProvider::RecordDeletionResult(bool success) { 215 void ZeroSuggestProvider::RecordDeletionResult(bool success) {
215 if (success) { 216 if (success) {
216 base::RecordAction( 217 base::RecordAction(
217 base::UserMetricsAction("Omnibox.ZeroSuggestDelete.Success")); 218 base::UserMetricsAction("Omnibox.ZeroSuggestDelete.Success"));
218 } else { 219 } else {
219 base::RecordAction( 220 base::RecordAction(
220 base::UserMetricsAction("Omnibox.ZeroSuggestDelete.Failure")); 221 base::UserMetricsAction("Omnibox.ZeroSuggestDelete.Failure"));
221 } 222 }
222 } 223 }
223 224
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 if (!json_data.empty()) { 456 if (!json_data.empty()) {
456 scoped_ptr<base::Value> data( 457 scoped_ptr<base::Value> data(
457 SearchSuggestionParser::DeserializeJsonData(json_data)); 458 SearchSuggestionParser::DeserializeJsonData(json_data));
458 if (data && ParseSuggestResults( 459 if (data && ParseSuggestResults(
459 *data, kDefaultZeroSuggestRelevance, false, &results_)) { 460 *data, kDefaultZeroSuggestRelevance, false, &results_)) {
460 ConvertResultsToAutocompleteMatches(); 461 ConvertResultsToAutocompleteMatches();
461 results_from_cache_ = !matches_.empty(); 462 results_from_cache_ = !matches_.empty();
462 } 463 }
463 } 464 }
464 } 465 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/zero_suggest_provider.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698