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/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/callback.h" | 10 #include "base/callback.h" |
11 #include "base/i18n/break_iterator.h" | 11 #include "base/i18n/break_iterator.h" |
12 #include "base/i18n/case_conversion.h" | 12 #include "base/i18n/case_conversion.h" |
13 #include "base/i18n/icu_string_conversions.h" | 13 #include "base/i18n/icu_string_conversions.h" |
14 #include "base/json/json_string_value_serializer.h" | 14 #include "base/json/json_string_value_serializer.h" |
15 #include "base/message_loop.h" | 15 #include "base/message_loop.h" |
16 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
17 #include "base/string16.h" | 17 #include "base/string16.h" |
18 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
19 #include "chrome/browser/autocomplete/autocomplete_classifier.h" | 19 #include "chrome/browser/autocomplete/autocomplete_classifier.h" |
20 #include "chrome/browser/autocomplete/autocomplete_field_trial.h" | 20 #include "chrome/browser/autocomplete/autocomplete_field_trial.h" |
21 #include "chrome/browser/autocomplete/autocomplete_match.h" | 21 #include "chrome/browser/autocomplete/autocomplete_match.h" |
22 #include "chrome/browser/autocomplete/keyword_provider.h" | 22 #include "chrome/browser/autocomplete/keyword_provider.h" |
23 #include "chrome/browser/history/history.h" | 23 #include "chrome/browser/history/history.h" |
| 24 #include "chrome/browser/history/in_memory_database.h" |
24 #include "chrome/browser/instant/instant_controller.h" | 25 #include "chrome/browser/instant/instant_controller.h" |
25 #include "chrome/browser/net/url_fixer_upper.h" | 26 #include "chrome/browser/net/url_fixer_upper.h" |
26 #include "chrome/browser/prefs/pref_service.h" | 27 #include "chrome/browser/prefs/pref_service.h" |
27 #include "chrome/browser/profiles/profile.h" | 28 #include "chrome/browser/profiles/profile.h" |
28 #include "chrome/browser/history/in_memory_database.h" | |
29 #include "chrome/browser/search_engines/search_engine_type.h" | 29 #include "chrome/browser/search_engines/search_engine_type.h" |
30 #include "chrome/browser/search_engines/template_url_service.h" | 30 #include "chrome/browser/search_engines/template_url_service.h" |
31 #include "chrome/browser/search_engines/template_url_service_factory.h" | 31 #include "chrome/browser/search_engines/template_url_service_factory.h" |
32 #include "chrome/common/pref_names.h" | 32 #include "chrome/common/pref_names.h" |
33 #include "chrome/common/url_constants.h" | 33 #include "chrome/common/url_constants.h" |
34 #include "content/public/common/url_fetcher.h" | 34 #include "content/public/common/url_fetcher.h" |
35 #include "googleurl/src/url_util.h" | 35 #include "googleurl/src/url_util.h" |
36 #include "grit/generated_resources.h" | 36 #include "grit/generated_resources.h" |
37 #include "net/base/escape.h" | 37 #include "net/base/escape.h" |
38 #include "net/base/load_flags.h" | 38 #include "net/base/load_flags.h" |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 } | 298 } |
299 } | 299 } |
300 | 300 |
301 void SearchProvider::Stop() { | 301 void SearchProvider::Stop() { |
302 StopSuggest(); | 302 StopSuggest(); |
303 ClearResults(); | 303 ClearResults(); |
304 done_ = true; | 304 done_ = true; |
305 default_provider_suggest_text_.clear(); | 305 default_provider_suggest_text_.clear(); |
306 } | 306 } |
307 | 307 |
308 void SearchProvider::OnURLFetchComplete(const content::URLFetcher* source) { | 308 void SearchProvider::OnURLFetchComplete(const net::URLFetcher* source) { |
309 DCHECK(!done_); | 309 DCHECK(!done_); |
310 suggest_results_pending_--; | 310 suggest_results_pending_--; |
311 DCHECK_GE(suggest_results_pending_, 0); // Should never go negative. | 311 DCHECK_GE(suggest_results_pending_, 0); // Should never go negative. |
312 const net::HttpResponseHeaders* const response_headers = | 312 const net::HttpResponseHeaders* const response_headers = |
313 source->GetResponseHeaders(); | 313 source->GetResponseHeaders(); |
314 std::string json_data; | 314 std::string json_data; |
315 source->GetResponseAsString(&json_data); | 315 source->GetResponseAsString(&json_data); |
316 // JSON is supposed to be UTF-8, but some suggest service providers send JSON | 316 // JSON is supposed to be UTF-8, but some suggest service providers send JSON |
317 // files in non-UTF-8 encodings. The actual encoding is usually specified in | 317 // files in non-UTF-8 encodings. The actual encoding is usually specified in |
318 // the Content-Type header field. | 318 // the Content-Type header field. |
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
975 | 975 |
976 return match; | 976 return match; |
977 } | 977 } |
978 | 978 |
979 void SearchProvider::UpdateDone() { | 979 void SearchProvider::UpdateDone() { |
980 // We're done when there are no more suggest queries pending (this is set to 1 | 980 // We're done when there are no more suggest queries pending (this is set to 1 |
981 // when the timer is started) and we're not waiting on instant. | 981 // when the timer is started) and we're not waiting on instant. |
982 done_ = ((suggest_results_pending_ == 0) && | 982 done_ = ((suggest_results_pending_ == 0) && |
983 (instant_finalized_ || !InstantController::IsEnabled(profile_))); | 983 (instant_finalized_ || !InstantController::IsEnabled(profile_))); |
984 } | 984 } |
OLD | NEW |