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" |
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
584 (*list)[i].set_relevance(CalculateRelevanceForNavigation(is_keyword) + | 584 (*list)[i].set_relevance(CalculateRelevanceForNavigation(is_keyword) + |
585 (list->size() - i - 1)); | 585 (list->size() - i - 1)); |
586 } | 586 } |
587 } | 587 } |
588 | 588 |
589 net::URLFetcher* SearchProvider::CreateSuggestFetcher( | 589 net::URLFetcher* SearchProvider::CreateSuggestFetcher( |
590 int id, | 590 int id, |
591 const TemplateURLRef& suggestions_url, | 591 const TemplateURLRef& suggestions_url, |
592 const string16& text) { | 592 const string16& text) { |
593 DCHECK(suggestions_url.SupportsReplacement()); | 593 DCHECK(suggestions_url.SupportsReplacement()); |
594 net::URLFetcher* fetcher = content::URLFetcher::Create(id, | 594 net::URLFetcher* fetcher = content::URLFetcher::Create( |
595 GURL(suggestions_url.ReplaceSearchTerms(text, | 595 id, GURL(suggestions_url.ReplaceSearchTerms(SearchTermsArgs(text))), |
596 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())), | |
597 net::URLFetcher::GET, this); | 596 net::URLFetcher::GET, this); |
598 fetcher->SetRequestContext(profile_->GetRequestContext()); | 597 fetcher->SetRequestContext(profile_->GetRequestContext()); |
599 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES); | 598 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES); |
600 fetcher->Start(); | 599 fetcher->Start(); |
601 return fetcher; | 600 return fetcher; |
602 } | 601 } |
603 | 602 |
604 bool SearchProvider::ParseSuggestResults(Value* root_val, bool is_keyword) { | 603 bool SearchProvider::ParseSuggestResults(Value* root_val, bool is_keyword) { |
605 // TODO(pkasting): Fix |have_suggest_results_|; see http://crbug.com/130631 | 604 // TODO(pkasting): Fix |have_suggest_results_|; see http://crbug.com/130631 |
606 have_suggest_results_ = false; | 605 have_suggest_results_ = false; |
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1052 } | 1051 } |
1053 match.fill_into_edit.append(query_string); | 1052 match.fill_into_edit.append(query_string); |
1054 // Not all suggestions start with the original input. | 1053 // Not all suggestions start with the original input. |
1055 if (!input_.prevent_inline_autocomplete() && | 1054 if (!input_.prevent_inline_autocomplete() && |
1056 !match.fill_into_edit.compare(search_start, input_text.length(), | 1055 !match.fill_into_edit.compare(search_start, input_text.length(), |
1057 input_text)) | 1056 input_text)) |
1058 match.inline_autocomplete_offset = search_start + input_text.length(); | 1057 match.inline_autocomplete_offset = search_start + input_text.length(); |
1059 | 1058 |
1060 const TemplateURLRef& search_url = provider_url->url_ref(); | 1059 const TemplateURLRef& search_url = provider_url->url_ref(); |
1061 DCHECK(search_url.SupportsReplacement()); | 1060 DCHECK(search_url.SupportsReplacement()); |
1062 match.destination_url = GURL(search_url.ReplaceSearchTerms(query_string, | 1061 match.search_terms_args.reset(new SearchTermsArgs(query_string)); |
1063 accepted_suggestion, input_text)); | 1062 match.search_terms_args->original_query = input_text; |
1063 match.search_terms_args->accepted_suggestion = accepted_suggestion; | |
1064 // This is the initial replacement, which is necessary for URL dedupping | |
Peter Kasting
2012/06/16 03:14:17
Nit: How about:
"This is the destination URL sans
Bart N
2012/06/16 23:38:10
Done.
| |
1065 // by AutocompleteController. | |
1066 match.destination_url = GURL(search_url.ReplaceSearchTerms( | |
Peter Kasting
2012/06/16 03:14:17
Nit: Can this be wrapped after '=' instead?
Bart N
2012/06/16 23:38:10
Done.
| |
1067 *match.search_terms_args.get())); | |
1064 | 1068 |
1065 // Search results don't look like URLs. | 1069 // Search results don't look like URLs. |
1066 match.transition = is_keyword ? | 1070 match.transition = is_keyword ? |
1067 content::PAGE_TRANSITION_KEYWORD : content::PAGE_TRANSITION_GENERATED; | 1071 content::PAGE_TRANSITION_KEYWORD : content::PAGE_TRANSITION_GENERATED; |
1068 | 1072 |
1069 // Try to add |match| to |map|. If a match for |query_string| is already in | 1073 // Try to add |match| to |map|. If a match for |query_string| is already in |
1070 // |map|, replace it if |match| is more relevant. | 1074 // |map|, replace it if |match| is more relevant. |
1071 // NOTE: Keep this ToLower() call in sync with url_database.cc. | 1075 // NOTE: Keep this ToLower() call in sync with url_database.cc. |
1072 const std::pair<MatchMap::iterator, bool> i = map->insert( | 1076 const std::pair<MatchMap::iterator, bool> i = map->insert( |
1073 std::pair<string16, AutocompleteMatch>( | 1077 std::pair<string16, AutocompleteMatch>( |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1145 ACMatchClassification::NONE, &match.description_class); | 1149 ACMatchClassification::NONE, &match.description_class); |
1146 return match; | 1150 return match; |
1147 } | 1151 } |
1148 | 1152 |
1149 void SearchProvider::UpdateDone() { | 1153 void SearchProvider::UpdateDone() { |
1150 // We're done when there are no more suggest queries pending (this is set to 1 | 1154 // We're done when there are no more suggest queries pending (this is set to 1 |
1151 // when the timer is started) and we're not waiting on instant. | 1155 // when the timer is started) and we're not waiting on instant. |
1152 done_ = ((suggest_results_pending_ == 0) && | 1156 done_ = ((suggest_results_pending_ == 0) && |
1153 (instant_finalized_ || !InstantController::IsEnabled(profile_))); | 1157 (instant_finalized_ || !InstantController::IsEnabled(profile_))); |
1154 } | 1158 } |
OLD | NEW |