OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/search_provider.h" | 5 #include "chrome/browser/autocomplete/search_provider.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 | 9 |
10 #include "base/base64.h" | 10 #include "base/base64.h" |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
243 } | 243 } |
244 | 244 |
245 input_ = input; | 245 input_ = input; |
246 | 246 |
247 DoHistoryQuery(minimal_changes); | 247 DoHistoryQuery(minimal_changes); |
248 DoAnswersQuery(input); | 248 DoAnswersQuery(input); |
249 StartOrStopSuggestQuery(minimal_changes); | 249 StartOrStopSuggestQuery(minimal_changes); |
250 UpdateMatches(); | 250 UpdateMatches(); |
251 } | 251 } |
252 | 252 |
253 void SearchProvider::Stop(bool clear_cached_results) { | |
254 StopSuggest(); | |
255 done_ = true; | |
256 | |
257 if (clear_cached_results) | |
258 ClearAllResults(); | |
259 } | |
260 | |
253 const TemplateURL* SearchProvider::GetTemplateURL(bool is_keyword) const { | 261 const TemplateURL* SearchProvider::GetTemplateURL(bool is_keyword) const { |
254 return is_keyword ? providers_.GetKeywordProviderURL() | 262 return is_keyword ? providers_.GetKeywordProviderURL() |
255 : providers_.GetDefaultProviderURL(); | 263 : providers_.GetDefaultProviderURL(); |
256 } | 264 } |
257 | 265 |
258 const AutocompleteInput SearchProvider::GetInput(bool is_keyword) const { | 266 const AutocompleteInput SearchProvider::GetInput(bool is_keyword) const { |
259 return is_keyword ? keyword_input_ : input_; | 267 return is_keyword ? keyword_input_ : input_; |
260 } | 268 } |
261 | 269 |
262 bool SearchProvider::ShouldAppendExtraParams( | 270 bool SearchProvider::ShouldAppendExtraParams( |
263 const SearchSuggestionParser::SuggestResult& result) const { | 271 const SearchSuggestionParser::SuggestResult& result) const { |
264 return !result.from_keyword_provider() || | 272 return !result.from_keyword_provider() || |
265 providers_.default_provider().empty(); | 273 providers_.default_provider().empty(); |
266 } | 274 } |
267 | 275 |
268 void SearchProvider::StopSuggest() { | |
269 // Increment the appropriate field in the histogram by the number of | |
270 // pending requests that were invalidated. | |
271 for (int i = 0; i < suggest_results_pending_; ++i) | |
272 LogOmniboxSuggestRequest(REQUEST_INVALIDATED); | |
273 suggest_results_pending_ = 0; | |
274 timer_.Stop(); | |
275 // Stop any in-progress URL fetches. | |
276 keyword_fetcher_.reset(); | |
277 default_fetcher_.reset(); | |
278 } | |
279 | |
280 void SearchProvider::ClearAllResults() { | |
281 keyword_results_.Clear(); | |
282 default_results_.Clear(); | |
283 } | |
284 | |
285 void SearchProvider::RecordDeletionResult(bool success) { | 276 void SearchProvider::RecordDeletionResult(bool success) { |
286 if (success) { | 277 if (success) { |
287 base::RecordAction( | 278 base::RecordAction( |
288 base::UserMetricsAction("Omnibox.ServerSuggestDelete.Success")); | 279 base::UserMetricsAction("Omnibox.ServerSuggestDelete.Success")); |
289 } else { | 280 } else { |
290 base::RecordAction( | 281 base::RecordAction( |
291 base::UserMetricsAction("Omnibox.ServerSuggestDelete.Failure")); | 282 base::UserMetricsAction("Omnibox.ServerSuggestDelete.Failure")); |
292 } | 283 } |
293 } | 284 } |
294 | 285 |
(...skipping 22 matching lines...) Expand all Loading... | |
317 results_updated = ParseSuggestResults(*data, -1, is_keyword, results); | 308 results_updated = ParseSuggestResults(*data, -1, is_keyword, results); |
318 if (results_updated) | 309 if (results_updated) |
319 SortResults(is_keyword, results); | 310 SortResults(is_keyword, results); |
320 } | 311 } |
321 } | 312 } |
322 UpdateMatches(); | 313 UpdateMatches(); |
323 if (done_ || results_updated) | 314 if (done_ || results_updated) |
324 listener_->OnProviderUpdate(results_updated); | 315 listener_->OnProviderUpdate(results_updated); |
325 } | 316 } |
326 | 317 |
318 void SearchProvider::StopSuggest() { | |
Peter Kasting
2014/08/13 17:33:45
Nit: You still haven't inlined these two functions
hashimoto
2014/08/14 03:52:09
Sorry to not mentioning this.
StopSuggest() and Cl
| |
319 // Increment the appropriate field in the histogram by the number of | |
320 // pending requests that were invalidated. | |
321 for (int i = 0; i < suggest_results_pending_; ++i) | |
322 LogOmniboxSuggestRequest(REQUEST_INVALIDATED); | |
323 suggest_results_pending_ = 0; | |
324 timer_.Stop(); | |
325 // Stop any in-progress URL fetches. | |
326 keyword_fetcher_.reset(); | |
327 default_fetcher_.reset(); | |
328 } | |
329 | |
330 void SearchProvider::ClearAllResults() { | |
331 keyword_results_.Clear(); | |
332 default_results_.Clear(); | |
333 } | |
334 | |
327 void SearchProvider::UpdateMatchContentsClass( | 335 void SearchProvider::UpdateMatchContentsClass( |
328 const base::string16& input_text, | 336 const base::string16& input_text, |
329 SearchSuggestionParser::Results* results) { | 337 SearchSuggestionParser::Results* results) { |
330 for (SearchSuggestionParser::SuggestResults::iterator sug_it = | 338 for (SearchSuggestionParser::SuggestResults::iterator sug_it = |
331 results->suggest_results.begin(); | 339 results->suggest_results.begin(); |
332 sug_it != results->suggest_results.end(); ++sug_it) { | 340 sug_it != results->suggest_results.end(); ++sug_it) { |
333 sug_it->ClassifyMatchContents(false, input_text); | 341 sug_it->ClassifyMatchContents(false, input_text); |
334 } | 342 } |
335 const std::string languages( | 343 const std::string languages( |
336 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)); | 344 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)); |
(...skipping 925 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1262 last_answer_seen_.query_type = match->answer_type; | 1270 last_answer_seen_.query_type = match->answer_type; |
1263 } | 1271 } |
1264 | 1272 |
1265 void SearchProvider::DoAnswersQuery(const AutocompleteInput& input) { | 1273 void SearchProvider::DoAnswersQuery(const AutocompleteInput& input) { |
1266 // If the query text starts with trimmed input, this is valid prefetch data. | 1274 // If the query text starts with trimmed input, this is valid prefetch data. |
1267 prefetch_data_ = StartsWith(last_answer_seen_.full_query_text, | 1275 prefetch_data_ = StartsWith(last_answer_seen_.full_query_text, |
1268 base::CollapseWhitespace(input.text(), false), | 1276 base::CollapseWhitespace(input.text(), false), |
1269 false) ? | 1277 false) ? |
1270 last_answer_seen_ : AnswersQueryData(); | 1278 last_answer_seen_ : AnswersQueryData(); |
1271 } | 1279 } |
OLD | NEW |