Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(252)

Side by Side Diff: chrome/browser/autocomplete/search_provider.cc

Issue 455563002: Prefetch cache pt1 - MRU (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@pfq-base
Patch Set: Get rid of C++11 features... :( Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(template_url_service, profile, 135 : BaseSearchProvider(template_url_service, profile,
136 AutocompleteProvider::TYPE_SEARCH), 136 AutocompleteProvider::TYPE_SEARCH),
137 listener_(listener), 137 listener_(listener),
138 suggest_results_pending_(0), 138 suggest_results_pending_(0),
139 providers_(template_url_service) { 139 providers_(template_url_service),
140 answers_cache_(1) {
140 } 141 }
141 142
142 // static 143 // static
143 std::string SearchProvider::GetSuggestMetadata(const AutocompleteMatch& match) { 144 std::string SearchProvider::GetSuggestMetadata(const AutocompleteMatch& match) {
144 return match.GetAdditionalInfo(kSuggestMetadataKey); 145 return match.GetAdditionalInfo(kSuggestMetadataKey);
145 } 146 }
146 147
147 void SearchProvider::ResetSession() { 148 void SearchProvider::ResetSession() {
148 field_trial_triggered_in_session_ = false; 149 field_trial_triggered_in_session_ = false;
149 } 150 }
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 663
663 // Bail if the suggestion URL is invalid with the given replacements. 664 // Bail if the suggestion URL is invalid with the given replacements.
664 TemplateURLRef::SearchTermsArgs search_term_args(input.text()); 665 TemplateURLRef::SearchTermsArgs search_term_args(input.text());
665 search_term_args.input_type = input.type(); 666 search_term_args.input_type = input.type();
666 search_term_args.cursor_position = input.cursor_position(); 667 search_term_args.cursor_position = input.cursor_position();
667 search_term_args.page_classification = input.current_page_classification(); 668 search_term_args.page_classification = input.current_page_classification();
668 if (OmniboxFieldTrial::EnableAnswersInSuggest()) { 669 if (OmniboxFieldTrial::EnableAnswersInSuggest()) {
669 search_term_args.session_token = GetSessionToken(); 670 search_term_args.session_token = GetSessionToken();
670 if (!prefetch_data_.full_query_text.empty()) { 671 if (!prefetch_data_.full_query_text.empty()) {
671 search_term_args.prefetch_query = 672 search_term_args.prefetch_query =
672 base::UTF16ToUTF8(last_answer_seen_.full_query_text); 673 base::UTF16ToUTF8(prefetch_data_.full_query_text);
673 search_term_args.prefetch_query_type = 674 search_term_args.prefetch_query_type =
674 base::UTF16ToUTF8(last_answer_seen_.query_type); 675 base::UTF16ToUTF8(prefetch_data_.query_type);
675 } 676 }
676 } 677 }
677 GURL suggest_url(template_url->suggestions_url_ref().ReplaceSearchTerms( 678 GURL suggest_url(template_url->suggestions_url_ref().ReplaceSearchTerms(
678 search_term_args, 679 search_term_args,
679 providers_.template_url_service()->search_terms_data())); 680 providers_.template_url_service()->search_terms_data()));
680 if (!suggest_url.is_valid()) 681 if (!suggest_url.is_valid())
681 return NULL; 682 return NULL;
682 // Send the current page URL if user setting and URL requirements are met and 683 // Send the current page URL if user setting and URL requirements are met and
683 // the user is in the field trial. 684 // the user is in the field trial.
684 if (CanSendURL(current_page_url_, suggest_url, template_url, 685 if (CanSendURL(current_page_url_, suggest_url, template_url,
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after
1249 // only be in the second slot if AutocompleteController ranked a local search 1250 // only be in the second slot if AutocompleteController ranked a local search
1250 // history or a verbatim item higher than the answer. 1251 // history or a verbatim item higher than the answer.
1251 AutocompleteResult::const_iterator match = result.begin(); 1252 AutocompleteResult::const_iterator match = result.begin();
1252 if (match->answer_contents.empty() && result.size() > 1) 1253 if (match->answer_contents.empty() && result.size() > 1)
1253 ++match; 1254 ++match;
1254 if (match->answer_contents.empty() || match->answer_type.empty() || 1255 if (match->answer_contents.empty() || match->answer_type.empty() ||
1255 match->fill_into_edit.empty()) 1256 match->fill_into_edit.empty())
1256 return; 1257 return;
1257 1258
1258 // Valid answer encountered, cache it for further queries. 1259 // Valid answer encountered, cache it for further queries.
1259 last_answer_seen_.full_query_text = match->fill_into_edit; 1260 answers_cache_.UpdateRecentAnswers(match->fill_into_edit, match->answer_type);
1260 last_answer_seen_.query_type = match->answer_type;
1261 } 1261 }
1262 1262
1263 void SearchProvider::DoAnswersQuery(const AutocompleteInput& input) { 1263 void SearchProvider::DoAnswersQuery(const AutocompleteInput& input) {
1264 // If the query text starts with trimmed input, this is valid prefetch data. 1264 prefetch_data_ = answers_cache_.GetTopAnswerEntry(input.text());
1265 prefetch_data_ = StartsWith(last_answer_seen_.full_query_text,
1266 base::CollapseWhitespace(input.text(), false),
1267 false) ?
1268 last_answer_seen_ : AnswersQueryData();
1269 } 1265 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/search_provider.h ('k') | chrome/browser/autocomplete/search_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698