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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
127 // SearchProvider ------------------------------------------------------------- | 127 // SearchProvider ------------------------------------------------------------- |
128 | 128 |
129 // static | 129 // static |
130 int SearchProvider::kMinimumTimeBetweenSuggestQueriesMs = 100; | 130 int SearchProvider::kMinimumTimeBetweenSuggestQueriesMs = 100; |
131 | 131 |
132 SearchProvider::SearchProvider(AutocompleteProviderListener* listener, | 132 SearchProvider::SearchProvider(AutocompleteProviderListener* listener, |
133 TemplateURLService* template_url_service, | 133 TemplateURLService* template_url_service, |
134 Profile* profile) | 134 Profile* profile) |
135 : BaseSearchProvider(listener, template_url_service, profile, | 135 : BaseSearchProvider(listener, template_url_service, profile, |
136 AutocompleteProvider::TYPE_SEARCH), | 136 AutocompleteProvider::TYPE_SEARCH), |
137 providers_(template_url_service) { | 137 providers_(template_url_service), |
138 answers_cache_(1) { | |
138 } | 139 } |
139 | 140 |
140 // static | 141 // static |
141 std::string SearchProvider::GetSuggestMetadata(const AutocompleteMatch& match) { | 142 std::string SearchProvider::GetSuggestMetadata(const AutocompleteMatch& match) { |
142 return match.GetAdditionalInfo(kSuggestMetadataKey); | 143 return match.GetAdditionalInfo(kSuggestMetadataKey); |
143 } | 144 } |
144 | 145 |
145 void SearchProvider::ResetSession() { | 146 void SearchProvider::ResetSession() { |
146 field_trial_triggered_in_session_ = false; | 147 field_trial_triggered_in_session_ = false; |
147 } | 148 } |
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
646 | 647 |
647 // Bail if the suggestion URL is invalid with the given replacements. | 648 // Bail if the suggestion URL is invalid with the given replacements. |
648 TemplateURLRef::SearchTermsArgs search_term_args(input.text()); | 649 TemplateURLRef::SearchTermsArgs search_term_args(input.text()); |
649 search_term_args.input_type = input.type(); | 650 search_term_args.input_type = input.type(); |
650 search_term_args.cursor_position = input.cursor_position(); | 651 search_term_args.cursor_position = input.cursor_position(); |
651 search_term_args.page_classification = input.current_page_classification(); | 652 search_term_args.page_classification = input.current_page_classification(); |
652 if (OmniboxFieldTrial::EnableAnswersInSuggest()) { | 653 if (OmniboxFieldTrial::EnableAnswersInSuggest()) { |
653 search_term_args.session_token = GetSessionToken(); | 654 search_term_args.session_token = GetSessionToken(); |
654 if (!prefetch_data_.full_query_text.empty()) { | 655 if (!prefetch_data_.full_query_text.empty()) { |
655 search_term_args.prefetch_query = | 656 search_term_args.prefetch_query = |
656 base::UTF16ToUTF8(last_answer_seen_.full_query_text); | 657 base::UTF16ToUTF8(prefetch_data_.full_query_text); |
657 search_term_args.prefetch_query_type = | 658 search_term_args.prefetch_query_type = |
658 base::UTF16ToUTF8(last_answer_seen_.query_type); | 659 base::UTF16ToUTF8(prefetch_data_.query_type); |
659 } | 660 } |
660 } | 661 } |
661 GURL suggest_url(template_url->suggestions_url_ref().ReplaceSearchTerms( | 662 GURL suggest_url(template_url->suggestions_url_ref().ReplaceSearchTerms( |
662 search_term_args, | 663 search_term_args, |
663 providers_.template_url_service()->search_terms_data())); | 664 providers_.template_url_service()->search_terms_data())); |
664 if (!suggest_url.is_valid()) | 665 if (!suggest_url.is_valid()) |
665 return NULL; | 666 return NULL; |
666 // Send the current page URL if user setting and URL requirements are met and | 667 // Send the current page URL if user setting and URL requirements are met and |
667 // the user is in the field trial. | 668 // the user is in the field trial. |
668 if (CanSendURL(current_page_url_, suggest_url, template_url, | 669 if (CanSendURL(current_page_url_, suggest_url, template_url, |
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1230 // only be in the second slot if AutocompleteController ranked a local search | 1231 // only be in the second slot if AutocompleteController ranked a local search |
1231 // history or a verbatim item higher than the answer. | 1232 // history or a verbatim item higher than the answer. |
1232 AutocompleteResult::const_iterator match = result.begin(); | 1233 AutocompleteResult::const_iterator match = result.begin(); |
1233 if (match->answer_contents.empty() && result.size() > 1) | 1234 if (match->answer_contents.empty() && result.size() > 1) |
1234 ++match; | 1235 ++match; |
1235 if (match->answer_contents.empty() || match->answer_type.empty() || | 1236 if (match->answer_contents.empty() || match->answer_type.empty() || |
1236 match->fill_into_edit.empty()) | 1237 match->fill_into_edit.empty()) |
1237 return; | 1238 return; |
1238 | 1239 |
1239 // Valid answer encountered, cache it for further queries. | 1240 // Valid answer encountered, cache it for further queries. |
1240 last_answer_seen_.full_query_text = match->fill_into_edit; | 1241 answers_cache_.UpdateRecentAnswers(match->fill_into_edit, match->answer_type); |
1241 last_answer_seen_.query_type = match->answer_type; | |
1242 } | 1242 } |
1243 | 1243 |
1244 void SearchProvider::DoAnswersQuery(const AutocompleteInput& input) { | 1244 void SearchProvider::DoAnswersQuery(const AutocompleteInput& input) { |
1245 // If the query text starts with trimmed input, this is valid prefetch data. | 1245 prefetch_data_ = answers_cache_.GetTopAnswerEntry(input.text()); |
Peter Kasting
2014/08/11 22:15:33
Should this just be inlined into the caller? Or a
groby-ooo-7-16
2014/08/12 01:16:27
This is mostly so I can test that DoAnswersQuery a
| |
1246 prefetch_data_ = StartsWith(last_answer_seen_.full_query_text, | |
1247 base::CollapseWhitespace(input.text(), false), | |
1248 false) ? | |
1249 last_answer_seen_ : AnswersQueryData(); | |
1250 } | 1246 } |
OLD | NEW |