OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 have_suggest_results_ = false; | 434 have_suggest_results_ = false; |
435 } | 435 } |
436 | 436 |
437 URLFetcher* SearchProvider::CreateSuggestFetcher(int id, | 437 URLFetcher* SearchProvider::CreateSuggestFetcher(int id, |
438 const TemplateURL& provider, | 438 const TemplateURL& provider, |
439 const string16& text) { | 439 const string16& text) { |
440 const TemplateURLRef* const suggestions_url = provider.suggestions_url(); | 440 const TemplateURLRef* const suggestions_url = provider.suggestions_url(); |
441 DCHECK(suggestions_url->SupportsReplacement()); | 441 DCHECK(suggestions_url->SupportsReplacement()); |
442 URLFetcher* fetcher = URLFetcher::Create(id, | 442 URLFetcher* fetcher = URLFetcher::Create(id, |
443 GURL(suggestions_url->ReplaceSearchTerms( | 443 GURL(suggestions_url->ReplaceSearchTerms( |
444 provider, text, | 444 profile_, provider, text, |
445 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())), | 445 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())), |
446 URLFetcher::GET, this); | 446 URLFetcher::GET, this); |
447 fetcher->set_request_context(profile_->GetRequestContext()); | 447 fetcher->set_request_context(profile_->GetRequestContext()); |
448 fetcher->Start(); | 448 fetcher->Start(); |
449 return fetcher; | 449 return fetcher; |
450 } | 450 } |
451 | 451 |
452 bool SearchProvider::ParseSuggestResults(Value* root_val, | 452 bool SearchProvider::ParseSuggestResults(Value* root_val, |
453 bool is_keyword, | 453 bool is_keyword, |
454 const string16& input_text, | 454 const string16& input_text, |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
877 match.fill_into_edit.append(query_string); | 877 match.fill_into_edit.append(query_string); |
878 // Not all suggestions start with the original input. | 878 // Not all suggestions start with the original input. |
879 if (!prevent_inline_autocomplete && | 879 if (!prevent_inline_autocomplete && |
880 !match.fill_into_edit.compare(search_start, input_text.length(), | 880 !match.fill_into_edit.compare(search_start, input_text.length(), |
881 input_text)) | 881 input_text)) |
882 match.inline_autocomplete_offset = search_start + input_text.length(); | 882 match.inline_autocomplete_offset = search_start + input_text.length(); |
883 | 883 |
884 const TemplateURLRef* const search_url = provider.url(); | 884 const TemplateURLRef* const search_url = provider.url(); |
885 DCHECK(search_url->SupportsReplacement()); | 885 DCHECK(search_url->SupportsReplacement()); |
886 match.destination_url = | 886 match.destination_url = |
887 GURL(search_url->ReplaceSearchTerms(provider, | 887 GURL(search_url->ReplaceSearchTerms(profile_, |
| 888 provider, |
888 query_string, | 889 query_string, |
889 accepted_suggestion, | 890 accepted_suggestion, |
890 input_text)); | 891 input_text)); |
891 | 892 |
892 // Search results don't look like URLs. | 893 // Search results don't look like URLs. |
893 match.transition = | 894 match.transition = |
894 is_keyword ? PageTransition::KEYWORD : PageTransition::GENERATED; | 895 is_keyword ? PageTransition::KEYWORD : PageTransition::GENERATED; |
895 | 896 |
896 // Try to add |match| to |map|. If a match for |query_string| is already in | 897 // Try to add |match| to |map|. If a match for |query_string| is already in |
897 // |map|, replace it if |match| is more relevant. | 898 // |map|, replace it if |match| is more relevant. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
944 | 945 |
945 return match; | 946 return match; |
946 } | 947 } |
947 | 948 |
948 void SearchProvider::UpdateDone() { | 949 void SearchProvider::UpdateDone() { |
949 // We're done when there are no more suggest queries pending (this is set to 1 | 950 // We're done when there are no more suggest queries pending (this is set to 1 |
950 // when the timer is started) and we're not waiting on instant. | 951 // when the timer is started) and we're not waiting on instant. |
951 done_ = ((suggest_results_pending_ == 0) && | 952 done_ = ((suggest_results_pending_ == 0) && |
952 (instant_finalized_ || !InstantController::IsEnabled(profile_))); | 953 (instant_finalized_ || !InstantController::IsEnabled(profile_))); |
953 } | 954 } |
OLD | NEW |