blob: 81741cc9b18625853ed30b66ffe3e2d89b7182a2 [file] [log] [blame]
[email protected]e41982a72012-11-20 07:16:511// Copyright 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
5#include "chrome/browser/autocomplete/search_provider.h"
6
[email protected]1cb2dac2010-03-08 21:49:157#include <algorithm>
[email protected]c3a4bd992010-08-18 20:25:018#include <cmath>
[email protected]1cb2dac2010-03-08 21:49:159
[email protected]2041cf342010-02-19 03:15:5910#include "base/callback.h"
[email protected]51124552011-07-16 01:37:1011#include "base/i18n/break_iterator.h"
[email protected]503d03872011-05-06 08:36:2612#include "base/i18n/case_conversion.h"
[email protected]ffbec692012-02-26 20:26:4213#include "base/json/json_string_value_serializer.h"
[email protected]fa1e0e12013-07-18 00:10:1414#include "base/message_loop/message_loop.h"
[email protected]f5b95ba92012-03-27 14:05:1915#include "base/metrics/histogram.h"
[email protected]3853a4c2013-02-11 17:15:5716#include "base/prefs/pref_service.h"
[email protected]5889bfb2014-03-19 00:26:4817#include "base/strings/string_util.h"
[email protected]135cb802013-06-09 16:44:2018#include "base/strings/utf_string_conversions.h"
[email protected]ea3b9a502011-04-04 14:19:3719#include "chrome/browser/autocomplete/autocomplete_classifier.h"
[email protected]810ffba2012-06-12 01:07:4820#include "chrome/browser/autocomplete/autocomplete_classifier_factory.h"
[email protected]5af9bc82012-06-29 00:53:4821#include "chrome/browser/autocomplete/autocomplete_provider_listener.h"
[email protected]73c2b1632012-07-02 22:51:3822#include "chrome/browser/autocomplete/autocomplete_result.h"
[email protected]2c812ba02011-07-14 00:23:1523#include "chrome/browser/autocomplete/keyword_provider.h"
[email protected]371dab12012-06-01 03:23:5524#include "chrome/browser/autocomplete/url_prefix.h"
[email protected]9b9fa672013-11-07 06:04:5225#include "chrome/browser/google/google_util.h"
[email protected]6a2c09f2013-01-25 04:50:0726#include "chrome/browser/history/history_service.h"
[email protected]9d2db762012-06-19 00:01:1027#include "chrome/browser/history/history_service_factory.h"
[email protected]10c2d692012-05-11 05:32:2328#include "chrome/browser/history/in_memory_database.h"
[email protected]ab7780792013-01-10 01:26:0929#include "chrome/browser/metrics/variations/variations_http_header_provider.h"
[email protected]684fcc12013-03-08 22:50:0230#include "chrome/browser/omnibox/omnibox_field_trial.h"
[email protected]8ecad5e2010-12-02 21:18:3331#include "chrome/browser/profiles/profile.h"
[email protected]a7b8e43d2013-03-18 18:52:4332#include "chrome/browser/search/search.h"
[email protected]9899a612012-08-21 23:50:0433#include "chrome/browser/search_engines/template_url_prepopulate_data.h"
[email protected]8e5c89a2011-06-07 18:13:3334#include "chrome/browser/search_engines/template_url_service.h"
35#include "chrome/browser/search_engines/template_url_service_factory.h"
[email protected]c4a9d4c2013-08-10 07:06:2736#include "chrome/browser/ui/search/instant_controller.h"
initial.commit09911bf2008-07-26 23:55:2937#include "chrome/common/pref_names.h"
[email protected]dcf7d352009-02-26 01:56:0238#include "chrome/common/url_constants.h"
[email protected]7267ff82013-12-03 17:20:3039#include "content/public/browser/user_metrics.h"
[email protected]34ac8f32009-02-22 23:03:2740#include "grit/generated_resources.h"
initial.commit09911bf2008-07-26 23:55:2941#include "net/base/escape.h"
[email protected]d3cf8682f02012-02-29 23:29:3442#include "net/base/load_flags.h"
[email protected]371dab12012-06-01 03:23:5543#include "net/base/net_util.h"
[email protected]bd3b4712012-12-18 17:01:3044#include "net/http/http_request_headers.h"
[email protected]3dc1bc42012-06-19 08:20:5345#include "net/url_request/url_fetcher.h"
[email protected]319d9e6f2009-02-18 19:47:2146#include "net/url_request/url_request_status.h"
[email protected]c051a1b2011-01-21 23:30:1747#include "ui/base/l10n/l10n_util.h"
[email protected]761fa4702013-07-02 15:25:1548#include "url/url_util.h"
initial.commit09911bf2008-07-26 23:55:2949
[email protected]bc8bb0cd2013-06-24 21:50:2350
51// Helpers --------------------------------------------------------------------
[email protected]e1acf6f2008-10-27 20:43:3352
[email protected]51124552011-07-16 01:37:1053namespace {
54
[email protected]7706a522012-08-16 17:42:2555// We keep track in a histogram how many suggest requests we send, how
56// many suggest requests we invalidate (e.g., due to a user typing
57// another character), and how many replies we receive.
58// *** ADD NEW ENUMS AFTER ALL PREVIOUSLY DEFINED ONES! ***
59// (excluding the end-of-list enum value)
60// We do not want values of existing enums to change or else it screws
61// up the statistics.
62enum SuggestRequestsHistogramValue {
63 REQUEST_SENT = 1,
64 REQUEST_INVALIDATED,
65 REPLY_RECEIVED,
66 MAX_SUGGEST_REQUEST_HISTOGRAM_VALUE
67};
68
[email protected]90fe2bb2013-01-15 03:42:1369// The verbatim score for an input which is not an URL.
70const int kNonURLVerbatimRelevance = 1300;
71
[email protected]7706a522012-08-16 17:42:2572// Increments the appropriate value in the histogram by one.
73void LogOmniboxSuggestRequest(
74 SuggestRequestsHistogramValue request_value) {
75 UMA_HISTOGRAM_ENUMERATION("Omnibox.SuggestRequests", request_value,
76 MAX_SUGGEST_REQUEST_HISTOGRAM_VALUE);
77}
78
[email protected]0085863a2013-12-06 21:19:0379bool HasMultipleWords(const base::string16& text) {
[email protected]51124552011-07-16 01:37:1080 base::i18n::BreakIterator i(text, base::i18n::BreakIterator::BREAK_WORD);
81 bool found_word = false;
82 if (i.Init()) {
83 while (i.Advance()) {
84 if (i.IsWord()) {
85 if (found_word)
86 return true;
87 found_word = true;
88 }
89 }
90 }
91 return false;
92}
93
[email protected]d1f0a7f2012-06-05 10:26:4294} // namespace
[email protected]51124552011-07-16 01:37:1095
[email protected]3954c3a2012-04-10 20:17:5596// SearchProvider::Providers --------------------------------------------------
[email protected]b547666d2009-04-23 16:37:5897
[email protected]85b8d6f2012-05-08 20:53:4798SearchProvider::Providers::Providers(TemplateURLService* template_url_service)
[email protected]02346202014-02-05 05:18:3099 : template_url_service_(template_url_service) {}
[email protected]85b8d6f2012-05-08 20:53:47100
101const TemplateURL* SearchProvider::Providers::GetDefaultProviderURL() const {
102 return default_provider_.empty() ? NULL :
103 template_url_service_->GetTemplateURLForKeyword(default_provider_);
104}
105
106const TemplateURL* SearchProvider::Providers::GetKeywordProviderURL() const {
107 return keyword_provider_.empty() ? NULL :
108 template_url_service_->GetTemplateURLForKeyword(keyword_provider_);
[email protected]257ab712009-04-14 17:16:24109}
110
[email protected]3954c3a2012-04-10 20:17:55111
[email protected]bc8bb0cd2013-06-24 21:50:23112// SearchProvider::CompareScoredResults ---------------------------------------
113
114class SearchProvider::CompareScoredResults {
115 public:
116 bool operator()(const Result& a, const Result& b) {
117 // Sort in descending relevance order.
118 return a.relevance() > b.relevance();
119 }
120};
121
122
[email protected]3954c3a2012-04-10 20:17:55123// SearchProvider -------------------------------------------------------------
124
125// static
[email protected]24dbf2302013-04-05 16:59:25126int SearchProvider::kMinimumTimeBetweenSuggestQueriesMs = 100;
[email protected]3954c3a2012-04-10 20:17:55127
[email protected]bc8bb0cd2013-06-24 21:50:23128SearchProvider::SearchProvider(AutocompleteProviderListener* listener,
129 Profile* profile)
[email protected]02346202014-02-05 05:18:30130 : BaseSearchProvider(listener, profile, AutocompleteProvider::TYPE_SEARCH),
[email protected]cfa164bf2014-03-19 11:51:15131 providers_(TemplateURLServiceFactory::GetForProfile(profile)) {
[email protected]bc8bb0cd2013-06-24 21:50:23132}
133
[email protected]cb86ee6f2013-04-28 16:58:15134// static
[email protected]987fad782013-08-28 06:23:18135std::string SearchProvider::GetSuggestMetadata(const AutocompleteMatch& match) {
136 return match.GetAdditionalInfo(kSuggestMetadataKey);
137}
138
[email protected]bc8bb0cd2013-06-24 21:50:23139void SearchProvider::ResetSession() {
140 field_trial_triggered_in_session_ = false;
[email protected]4ab4c7c2010-11-24 04:49:34141}
142
[email protected]bc8bb0cd2013-06-24 21:50:23143SearchProvider::~SearchProvider() {
144}
145
[email protected]ee6110b2014-01-09 22:26:31146void SearchProvider::UpdateMatchContentsClass(const base::string16& input_text,
[email protected]23db6492014-01-16 02:35:30147 Results* results) {
148 for (SuggestResults::iterator sug_it = results->suggest_results.begin();
149 sug_it != results->suggest_results.end(); ++sug_it) {
[email protected]ee6110b2014-01-09 22:26:31150 sug_it->ClassifyMatchContents(false, input_text);
151 }
[email protected]23db6492014-01-16 02:35:30152 const std::string languages(
153 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages));
154 for (NavigationResults::iterator nav_it = results->navigation_results.begin();
155 nav_it != results->navigation_results.end(); ++nav_it) {
156 nav_it->CalculateAndClassifyMatchContents(false, input_text, languages);
157 }
[email protected]ee6110b2014-01-09 22:26:31158}
159
160// static
[email protected]bc8bb0cd2013-06-24 21:50:23161int SearchProvider::CalculateRelevanceForKeywordVerbatim(
162 AutocompleteInput::Type type,
163 bool prefer_keyword) {
164 // This function is responsible for scoring verbatim query matches
165 // for non-extension keywords. KeywordProvider::CalculateRelevance()
166 // scores verbatim query matches for extension keywords, as well as
167 // for keyword matches (i.e., suggestions of a keyword itself, not a
168 // suggestion of a query on a keyword search engine). These two
169 // functions are currently in sync, but there's no reason we
170 // couldn't decide in the future to score verbatim matches
171 // differently for extension and non-extension keywords. If you
172 // make such a change, however, you should update this comment to
173 // describe it, so it's clear why the functions diverge.
174 if (prefer_keyword)
175 return 1500;
176 return (type == AutocompleteInput::QUERY) ? 1450 : 1100;
177}
178
initial.commit09911bf2008-07-26 23:55:29179void SearchProvider::Start(const AutocompleteInput& input,
[email protected]8deeb952008-10-09 18:21:27180 bool minimal_changes) {
[email protected]04504c242013-01-22 21:08:55181 // Do our best to load the model as early as possible. This will reduce
182 // odds of having the model not ready when really needed (a non-empty input).
183 TemplateURLService* model = providers_.template_url_service();
184 DCHECK(model);
185 model->Load();
186
initial.commit09911bf2008-07-26 23:55:29187 matches_.clear();
[email protected]618d6e62012-12-16 05:55:57188 field_trial_triggered_ = false;
initial.commit09911bf2008-07-26 23:55:29189
[email protected]6c85aa02009-02-27 12:08:09190 // Can't return search/suggest results for bogus input or without a profile.
initial.commit09911bf2008-07-26 23:55:29191 if (!profile_ || (input.type() == AutocompleteInput::INVALID)) {
[email protected]9950e5d52014-02-25 23:34:19192 Stop(true);
initial.commit09911bf2008-07-26 23:55:29193 return;
194 }
195
[email protected]14710852013-02-05 23:45:41196 keyword_input_ = input;
[email protected]257ab712009-04-14 17:16:24197 const TemplateURL* keyword_provider =
[email protected]14710852013-02-05 23:45:41198 KeywordProvider::GetSubstitutingTemplateURLForInput(model,
199 &keyword_input_);
200 if (keyword_provider == NULL)
201 keyword_input_.Clear();
202 else if (keyword_input_.text().empty())
[email protected]257ab712009-04-14 17:16:24203 keyword_provider = NULL;
[email protected]257ab712009-04-14 17:16:24204
[email protected]85b8d6f2012-05-08 20:53:47205 const TemplateURL* default_provider = model->GetDefaultSearchProvider();
[email protected]9b74ab52012-03-30 16:08:07206 if (default_provider && !default_provider->SupportsReplacement())
[email protected]257ab712009-04-14 17:16:24207 default_provider = NULL;
208
209 if (keyword_provider == default_provider)
[email protected]e17511f2011-07-13 14:09:18210 default_provider = NULL; // No use in querying the same provider twice.
[email protected]257ab712009-04-14 17:16:24211
212 if (!default_provider && !keyword_provider) {
213 // No valid providers.
[email protected]9950e5d52014-02-25 23:34:19214 Stop(true);
initial.commit09911bf2008-07-26 23:55:29215 return;
216 }
217
218 // If we're still running an old query but have since changed the query text
[email protected]257ab712009-04-14 17:16:24219 // or the providers, abort the query.
[email protected]0085863a2013-12-06 21:19:03220 base::string16 default_provider_keyword(default_provider ?
221 default_provider->keyword() : base::string16());
222 base::string16 keyword_provider_keyword(keyword_provider ?
223 keyword_provider->keyword() : base::string16());
[email protected]9e789742011-01-10 23:27:32224 if (!minimal_changes ||
[email protected]85b8d6f2012-05-08 20:53:47225 !providers_.equal(default_provider_keyword, keyword_provider_keyword)) {
[email protected]bb900e02013-03-14 14:15:29226 // Cancel any in-flight suggest requests.
[email protected]e1290ee62013-06-26 18:31:15227 if (!done_)
[email protected]e29249dc52012-07-19 17:33:50228 Stop(false);
[email protected]257ab712009-04-14 17:16:24229 }
initial.commit09911bf2008-07-26 23:55:29230
[email protected]85b8d6f2012-05-08 20:53:47231 providers_.set(default_provider_keyword, keyword_provider_keyword);
initial.commit09911bf2008-07-26 23:55:29232
233 if (input.text().empty()) {
234 // User typed "?" alone. Give them a placeholder result indicating what
235 // this syntax does.
[email protected]257ab712009-04-14 17:16:24236 if (default_provider) {
[email protected]69c579e2010-04-23 20:01:00237 AutocompleteMatch match;
238 match.provider = this;
[email protected]a2fedb1e2011-01-25 15:23:36239 match.contents.assign(l10n_util::GetStringUTF16(IDS_EMPTY_KEYWORD_VALUE));
[email protected]257ab712009-04-14 17:16:24240 match.contents_class.push_back(
[email protected]2c33dd22010-02-11 21:46:35241 ACMatchClassification(0, ACMatchClassification::NONE));
[email protected]85b8d6f2012-05-08 20:53:47242 match.keyword = providers_.default_provider();
[email protected]45f89a92013-08-12 13:41:36243 match.allowed_to_be_default_match = true;
[email protected]257ab712009-04-14 17:16:24244 matches_.push_back(match);
245 }
[email protected]9950e5d52014-02-25 23:34:19246 Stop(true);
initial.commit09911bf2008-07-26 23:55:29247 return;
248 }
249
250 input_ = input;
251
[email protected]e1290ee62013-06-26 18:31:15252 DoHistoryQuery(minimal_changes);
253 StartOrStopSuggestQuery(minimal_changes);
[email protected]344946a12012-12-20 12:03:42254 UpdateMatches();
initial.commit09911bf2008-07-26 23:55:29255}
256
[email protected]d4a94b92014-03-04 01:35:22257void SearchProvider::SortResults(bool is_keyword,
258 const base::ListValue* relevances,
259 Results* results) {
260 // Ignore suggested scores for non-keyword matches in keyword mode; if the
261 // server is allowed to score these, it could interfere with the user's
262 // ability to get good keyword results.
263 const bool abandon_suggested_scores =
264 !is_keyword && !providers_.keyword_provider().empty();
265 // Apply calculated relevance scores to suggestions if a valid list was
266 // not provided or we're abandoning suggested scores entirely.
267 if ((relevances == NULL) || abandon_suggested_scores) {
268 ApplyCalculatedSuggestRelevance(&results->suggest_results);
269 ApplyCalculatedNavigationRelevance(&results->navigation_results);
270 // If abandoning scores entirely, also abandon the verbatim score.
271 if (abandon_suggested_scores)
272 results->verbatim_relevance = -1;
273 }
274
275 // Keep the result lists sorted.
276 const CompareScoredResults comparator = CompareScoredResults();
277 std::stable_sort(results->suggest_results.begin(),
278 results->suggest_results.end(),
279 comparator);
280 std::stable_sort(results->navigation_results.begin(),
281 results->navigation_results.end(),
282 comparator);
283}
284
[email protected]cfa164bf2014-03-19 11:51:15285const TemplateURL* SearchProvider::GetTemplateURL(bool is_keyword) const {
286 return is_keyword ? providers_.GetKeywordProviderURL()
287 : providers_.GetDefaultProviderURL();
[email protected]9487b392014-02-14 02:48:18288}
289
[email protected]d4a94b92014-03-04 01:35:22290const AutocompleteInput SearchProvider::GetInput(bool is_keyword) const {
291 return is_keyword ? keyword_input_ : input_;
[email protected]9487b392014-02-14 02:48:18292}
293
[email protected]cfa164bf2014-03-19 11:51:15294BaseSearchProvider::Results* SearchProvider::GetResultsToFill(bool is_keyword) {
295 return is_keyword ? &keyword_results_ : &default_results_;
296}
297
[email protected]9487b392014-02-14 02:48:18298bool SearchProvider::ShouldAppendExtraParams(
299 const SuggestResult& result) const {
300 return !result.from_keyword_provider() ||
301 providers_.default_provider().empty();
302}
303
[email protected]ef6866f2014-02-18 08:26:34304void SearchProvider::StopSuggest() {
305 // Increment the appropriate field in the histogram by the number of
306 // pending requests that were invalidated.
307 for (int i = 0; i < suggest_results_pending_; ++i)
308 LogOmniboxSuggestRequest(REQUEST_INVALIDATED);
309 suggest_results_pending_ = 0;
310 timer_.Stop();
311 // Stop any in-progress URL fetches.
312 keyword_fetcher_.reset();
313 default_fetcher_.reset();
314}
315
316void SearchProvider::ClearAllResults() {
317 keyword_results_.Clear();
318 default_results_.Clear();
319}
320
[email protected]d4a94b92014-03-04 01:35:22321int SearchProvider::GetDefaultResultRelevance() const {
322 return -1;
323}
324
[email protected]7267ff82013-12-03 17:20:30325void SearchProvider::RecordDeletionResult(bool success) {
326 if (success) {
327 content::RecordAction(
[email protected]e6e30ac2014-01-13 21:24:39328 base::UserMetricsAction("Omnibox.ServerSuggestDelete.Success"));
[email protected]7267ff82013-12-03 17:20:30329 } else {
330 content::RecordAction(
[email protected]e6e30ac2014-01-13 21:24:39331 base::UserMetricsAction("Omnibox.ServerSuggestDelete.Failure"));
[email protected]7267ff82013-12-03 17:20:30332 }
333}
334
[email protected]cfa164bf2014-03-19 11:51:15335void SearchProvider::LogFetchComplete(bool success, bool is_keyword) {
336 LogOmniboxSuggestRequest(REPLY_RECEIVED);
337 // Record response time for suggest requests sent to Google. We care
338 // only about the common case: the Google default provider used in
339 // non-keyword mode.
340 const TemplateURL* default_url = providers_.GetDefaultProviderURL();
341 if (!is_keyword && default_url &&
342 (TemplateURLPrepopulateData::GetEngineType(*default_url) ==
343 SEARCH_ENGINE_GOOGLE)) {
344 const base::TimeDelta elapsed_time =
345 base::TimeTicks::Now() - time_suggest_request_sent_;
346 if (success) {
347 UMA_HISTOGRAM_TIMES("Omnibox.SuggestRequest.Success.GoogleResponseTime",
348 elapsed_time);
349 } else {
350 UMA_HISTOGRAM_TIMES("Omnibox.SuggestRequest.Failure.GoogleResponseTime",
351 elapsed_time);
352 }
353 }
354}
355
356bool SearchProvider::IsKeywordFetcher(const net::URLFetcher* fetcher) const {
357 return fetcher == keyword_fetcher_.get();
358}
359
360void SearchProvider::UpdateMatches() {
[email protected]cfa164bf2014-03-19 11:51:15361 ConvertResultsToAutocompleteMatches();
362
363 // Check constraints that may be violated by suggested relevances.
364 if (!matches_.empty() &&
365 (default_results_.HasServerProvidedScores() ||
366 keyword_results_.HasServerProvidedScores())) {
367 // These blocks attempt to repair undesirable behavior by suggested
368 // relevances with minimal impact, preserving other suggested relevances.
369
[email protected]cfa164bf2014-03-19 11:51:15370 if (!HasKeywordDefaultMatchInKeywordMode()) {
371 // In keyword mode, disregard the keyword verbatim suggested relevance
372 // if necessary so there at least one keyword match that's allowed to
373 // be the default match.
374 keyword_results_.verbatim_relevance = -1;
375 ConvertResultsToAutocompleteMatches();
376 }
[email protected]89bd27d12014-04-12 17:36:23377 if (IsTopMatchSearchWithURLInput()) {
[email protected]cfa164bf2014-03-19 11:51:15378 // Disregard the suggested search and verbatim relevances if the input
379 // type is URL and the top match is a highly-ranked search suggestion.
380 // For example, prevent a search for "foo.com" from outranking another
381 // provider's navigation for "foo.com" or "foo.com/url_from_history".
382 ApplyCalculatedSuggestRelevance(&keyword_results_.suggest_results);
383 ApplyCalculatedSuggestRelevance(&default_results_.suggest_results);
384 default_results_.verbatim_relevance = -1;
385 keyword_results_.verbatim_relevance = -1;
386 ConvertResultsToAutocompleteMatches();
387 }
[email protected]89bd27d12014-04-12 17:36:23388 if (FindTopMatch() == matches_.end()) {
389 // Guarantee that SearchProvider returns a legal default match. (The
390 // omnibox always needs at least one legal default match, and it relies
391 // on SearchProvider to always return one.)
[email protected]cfa164bf2014-03-19 11:51:15392 ApplyCalculatedRelevance();
393 ConvertResultsToAutocompleteMatches();
394 }
[email protected]cfa164bf2014-03-19 11:51:15395 DCHECK(HasKeywordDefaultMatchInKeywordMode());
[email protected]89bd27d12014-04-12 17:36:23396 DCHECK(!IsTopMatchSearchWithURLInput());
397 DCHECK(FindTopMatch() != matches_.end());
[email protected]cfa164bf2014-03-19 11:51:15398 }
399 UMA_HISTOGRAM_CUSTOM_COUNTS(
400 "Omnibox.SearchProviderMatches", matches_.size(), 1, 6, 7);
401
402 const TemplateURL* keyword_url = providers_.GetKeywordProviderURL();
403 if ((keyword_url != NULL) && HasKeywordDefaultMatchInKeywordMode()) {
404 // If there is a keyword match that is allowed to be the default match,
405 // then prohibit default provider matches from being the default match lest
406 // such matches cause the user to break out of keyword mode.
407 for (ACMatches::iterator it = matches_.begin(); it != matches_.end();
408 ++it) {
409 if (it->keyword != keyword_url->keyword())
410 it->allowed_to_be_default_match = false;
411 }
412 }
413
414 base::TimeTicks update_starred_start_time(base::TimeTicks::Now());
415 UpdateStarredStateOfMatches();
416 UMA_HISTOGRAM_TIMES("Omnibox.SearchProvider.UpdateStarredTime",
417 base::TimeTicks::Now() - update_starred_start_time);
418 UpdateDone();
[email protected]cfa164bf2014-03-19 11:51:15419}
420
[email protected]bc8bb0cd2013-06-24 21:50:23421void SearchProvider::Run() {
422 // Start a new request with the current input.
423 suggest_results_pending_ = 0;
424 time_suggest_request_sent_ = base::TimeTicks::Now();
[email protected]abe441e2013-05-06 12:35:05425
[email protected]bc8bb0cd2013-06-24 21:50:23426 default_fetcher_.reset(CreateSuggestFetcher(kDefaultProviderURLFetcherID,
427 providers_.GetDefaultProviderURL(), input_));
428 keyword_fetcher_.reset(CreateSuggestFetcher(kKeywordProviderURLFetcherID,
429 providers_.GetKeywordProviderURL(), keyword_input_));
430
431 // Both the above can fail if the providers have been modified or deleted
432 // since the query began.
433 if (suggest_results_pending_ == 0) {
434 UpdateDone();
435 // We only need to update the listener if we're actually done.
436 if (done_)
437 listener_->OnProviderUpdate(false);
438 }
[email protected]601858c02010-09-01 17:08:20439}
440
[email protected]8d457132010-11-04 18:13:40441void SearchProvider::DoHistoryQuery(bool minimal_changes) {
442 // The history query results are synchronous, so if minimal_changes is true,
443 // we still have the last results and don't need to do anything.
444 if (minimal_changes)
initial.commit09911bf2008-07-26 23:55:29445 return;
446
[email protected]8d457132010-11-04 18:13:40447 keyword_history_results_.clear();
448 default_history_results_.clear();
initial.commit09911bf2008-07-26 23:55:29449
[email protected]78e5e432013-08-03 02:10:10450 if (OmniboxFieldTrial::SearchHistoryDisable(
451 input_.current_page_classification()))
[email protected]d8cd76b2013-07-10 09:46:16452 return;
453
[email protected]8d457132010-11-04 18:13:40454 HistoryService* const history_service =
[email protected]9d2db762012-06-19 00:01:10455 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
[email protected]8d457132010-11-04 18:13:40456 history::URLDatabase* url_db = history_service ?
457 history_service->InMemoryDatabase() : NULL;
[email protected]8d457132010-11-04 18:13:40458 if (!url_db)
initial.commit09911bf2008-07-26 23:55:29459 return;
460
[email protected]51124552011-07-16 01:37:10461 // Request history for both the keyword and default provider. We grab many
462 // more matches than we'll ultimately clamp to so that if there are several
463 // recent multi-word matches who scores are lowered (see
464 // AddHistoryResultsToMap()), they won't crowd out older, higher-scoring
465 // matches. Note that this doesn't fix the problem entirely, but merely
466 // limits it to cases with a very large number of such multi-word matches; for
467 // now, this seems OK compared with the complexity of a real fix, which would
468 // require multiple searches and tracking of "single- vs. multi-word" in the
469 // database.
470 int num_matches = kMaxMatches * 5;
[email protected]85b8d6f2012-05-08 20:53:47471 const TemplateURL* default_url = providers_.GetDefaultProviderURL();
472 if (default_url) {
[email protected]b4bec972014-04-05 18:07:15473 const base::TimeTicks start_time = base::TimeTicks::Now();
[email protected]85b8d6f2012-05-08 20:53:47474 url_db->GetMostRecentKeywordSearchTerms(default_url->id(), input_.text(),
475 num_matches, &default_history_results_);
[email protected]31afdf72013-09-26 04:29:36476 UMA_HISTOGRAM_TIMES(
477 "Omnibox.SearchProvider.GetMostRecentKeywordTermsDefaultProviderTime",
478 base::TimeTicks::Now() - start_time);
[email protected]257ab712009-04-14 17:16:24479 }
[email protected]85b8d6f2012-05-08 20:53:47480 const TemplateURL* keyword_url = providers_.GetKeywordProviderURL();
481 if (keyword_url) {
482 url_db->GetMostRecentKeywordSearchTerms(keyword_url->id(),
[email protected]14710852013-02-05 23:45:41483 keyword_input_.text(), num_matches, &keyword_history_results_);
[email protected]3954c3a2012-04-10 20:17:55484 }
initial.commit09911bf2008-07-26 23:55:29485}
486
[email protected]6dc950f2012-07-16 19:49:08487void SearchProvider::StartOrStopSuggestQuery(bool minimal_changes) {
[email protected]83c726482008-09-10 06:36:34488 if (!IsQuerySuitableForSuggest()) {
initial.commit09911bf2008-07-26 23:55:29489 StopSuggest();
[email protected]71b46152013-05-03 16:39:20490 ClearAllResults();
initial.commit09911bf2008-07-26 23:55:29491 return;
492 }
493
494 // For the minimal_changes case, if we finished the previous query and still
495 // have its results, or are allowed to keep running it, just do that, rather
496 // than starting a new query.
497 if (minimal_changes &&
[email protected]cc1526e2013-05-17 04:04:24498 (!default_results_.suggest_results.empty() ||
499 !default_results_.navigation_results.empty() ||
500 !keyword_results_.suggest_results.empty() ||
501 !keyword_results_.navigation_results.empty() ||
[email protected]ea3b9a502011-04-04 14:19:37502 (!done_ &&
503 input_.matches_requested() == AutocompleteInput::ALL_MATCHES)))
initial.commit09911bf2008-07-26 23:55:29504 return;
505
506 // We can't keep running any previous query, so halt it.
507 StopSuggest();
[email protected]d1f0a7f2012-06-05 10:26:42508
509 // Remove existing results that cannot inline autocomplete the new input.
[email protected]71b46152013-05-03 16:39:20510 RemoveAllStaleResults();
initial.commit09911bf2008-07-26 23:55:29511
[email protected]ee6110b2014-01-09 22:26:31512 // Update the content classifications of remaining results so they look good
513 // against the current input.
[email protected]23db6492014-01-16 02:35:30514 UpdateMatchContentsClass(input_.text(), &default_results_);
515 if (!keyword_input_.text().empty())
516 UpdateMatchContentsClass(keyword_input_.text(), &keyword_results_);
[email protected]ee6110b2014-01-09 22:26:31517
initial.commit09911bf2008-07-26 23:55:29518 // We can't start a new query if we're only allowed synchronous results.
[email protected]ea3b9a502011-04-04 14:19:37519 if (input_.matches_requested() != AutocompleteInput::ALL_MATCHES)
initial.commit09911bf2008-07-26 23:55:29520 return;
521
[email protected]24dbf2302013-04-05 16:59:25522 // To avoid flooding the suggest server, don't send a query until at
523 // least 100 ms since the last query.
[email protected]515ffa942012-11-27 20:18:24524 base::TimeTicks next_suggest_time(time_suggest_request_sent_ +
[email protected]bc8bb0cd2013-06-24 21:50:23525 base::TimeDelta::FromMilliseconds(kMinimumTimeBetweenSuggestQueriesMs));
[email protected]515ffa942012-11-27 20:18:24526 base::TimeTicks now(base::TimeTicks::Now());
527 if (now >= next_suggest_time) {
528 Run();
529 return;
530 }
531 timer_.Start(FROM_HERE, next_suggest_time - now, this, &SearchProvider::Run);
initial.commit09911bf2008-07-26 23:55:29532}
533
[email protected]83c726482008-09-10 06:36:34534bool SearchProvider::IsQuerySuitableForSuggest() const {
[email protected]3954c3a2012-04-10 20:17:55535 // Don't run Suggest in incognito mode, if the engine doesn't support it, or
536 // if the user has disabled it.
[email protected]85b8d6f2012-05-08 20:53:47537 const TemplateURL* default_url = providers_.GetDefaultProviderURL();
538 const TemplateURL* keyword_url = providers_.GetKeywordProviderURL();
[email protected]83c726482008-09-10 06:36:34539 if (profile_->IsOffTheRecord() ||
[email protected]85b8d6f2012-05-08 20:53:47540 ((!default_url || default_url->suggestions_url().empty()) &&
541 (!keyword_url || keyword_url->suggestions_url().empty())) ||
[email protected]83c726482008-09-10 06:36:34542 !profile_->GetPrefs()->GetBoolean(prefs::kSearchSuggestEnabled))
543 return false;
544
[email protected]cac59d32010-08-09 23:23:14545 // If the input type might be a URL, we take extra care so that private data
[email protected]83c726482008-09-10 06:36:34546 // isn't sent to the server.
[email protected]83c726482008-09-10 06:36:34547
[email protected]cac59d32010-08-09 23:23:14548 // FORCED_QUERY means the user is explicitly asking us to search for this, so
549 // we assume it isn't a URL and/or there isn't private data.
550 if (input_.type() == AutocompleteInput::FORCED_QUERY)
551 return true;
[email protected]83c726482008-09-10 06:36:34552
[email protected]f608ea102013-03-18 15:08:09553 // Next we check the scheme. If this is UNKNOWN/URL with a scheme that isn't
554 // http/https/ftp, we shouldn't send it. Sending things like file: and data:
555 // is both a waste of time and a disclosure of potentially private, local
556 // data. Other "schemes" may actually be usernames, and we don't want to send
557 // passwords. If the scheme is OK, we still need to check other cases below.
558 // If this is QUERY, then the presence of these schemes means the user
559 // explicitly typed one, and thus this is probably a URL that's being entered
560 // and happens to currently be invalid -- in which case we again want to run
561 // our checks below. Other QUERY cases are less likely to be URLs and thus we
562 // assume we're OK.
[email protected]e9a82042013-09-15 03:38:29563 if (!LowerCaseEqualsASCII(input_.scheme(), content::kHttpScheme) &&
[email protected]4654bfe2013-08-26 03:36:58564 !LowerCaseEqualsASCII(input_.scheme(), content::kHttpsScheme) &&
[email protected]72aa4c22013-12-01 15:09:35565 !LowerCaseEqualsASCII(input_.scheme(), content::kFtpScheme))
[email protected]cac59d32010-08-09 23:23:14566 return (input_.type() == AutocompleteInput::QUERY);
567
568 // Don't send URLs with usernames, queries or refs. Some of these are
569 // private, and the Suggest server is unlikely to have any useful results
570 // for any of them. Also don't send URLs with ports, as we may initially
571 // think that a username + password is a host + port (and we don't want to
572 // send usernames/passwords), and even if the port really is a port, the
573 // server is once again unlikely to have and useful results.
[email protected]825e16f2013-09-30 23:52:58574 // Note that we only block based on refs if the input is URL-typed, as search
575 // queries can legitimately have #s in them which the URL parser
576 // overaggressively categorizes as a url with a ref.
[email protected]cac59d32010-08-09 23:23:14577 const url_parse::Parsed& parts = input_.parts();
578 if (parts.username.is_nonempty() || parts.port.is_nonempty() ||
[email protected]825e16f2013-09-30 23:52:58579 parts.query.is_nonempty() ||
580 (parts.ref.is_nonempty() && (input_.type() == AutocompleteInput::URL)))
[email protected]cac59d32010-08-09 23:23:14581 return false;
582
583 // Don't send anything for https except the hostname. Hostnames are OK
584 // because they are visible when the TCP connection is established, but the
585 // specific path may reveal private information.
[email protected]4654bfe2013-08-26 03:36:58586 if (LowerCaseEqualsASCII(input_.scheme(), content::kHttpsScheme) &&
[email protected]a2fedb1e2011-01-25 15:23:36587 parts.path.is_nonempty())
[email protected]cac59d32010-08-09 23:23:14588 return false;
[email protected]83c726482008-09-10 06:36:34589
590 return true;
591}
592
[email protected]71b46152013-05-03 16:39:20593void SearchProvider::RemoveAllStaleResults() {
[email protected]dc735c02013-11-12 23:23:41594 if (keyword_input_.text().empty()) {
[email protected]1e1550e2013-05-02 17:37:51595 // User is either in keyword mode with a blank input or out of
596 // keyword mode entirely.
[email protected]cc1526e2013-05-17 04:04:24597 keyword_results_.Clear();
[email protected]1e1550e2013-05-02 17:37:51598 }
[email protected]d1f0a7f2012-06-05 10:26:42599}
600
[email protected]d1f0a7f2012-06-05 10:26:42601void SearchProvider::ApplyCalculatedRelevance() {
[email protected]cc1526e2013-05-17 04:04:24602 ApplyCalculatedSuggestRelevance(&keyword_results_.suggest_results);
603 ApplyCalculatedSuggestRelevance(&default_results_.suggest_results);
604 ApplyCalculatedNavigationRelevance(&keyword_results_.navigation_results);
605 ApplyCalculatedNavigationRelevance(&default_results_.navigation_results);
[email protected]cc1526e2013-05-17 04:04:24606 default_results_.verbatim_relevance = -1;
607 keyword_results_.verbatim_relevance = -1;
[email protected]d1f0a7f2012-06-05 10:26:42608}
609
[email protected]188b50c2013-03-28 07:19:42610void SearchProvider::ApplyCalculatedSuggestRelevance(SuggestResults* list) {
[email protected]d1f0a7f2012-06-05 10:26:42611 for (size_t i = 0; i < list->size(); ++i) {
[email protected]188b50c2013-03-28 07:19:42612 SuggestResult& result = (*list)[i];
613 result.set_relevance(
614 result.CalculateRelevance(input_, providers_.has_keyword_provider()) +
615 (list->size() - i - 1));
[email protected]d30268a2013-06-25 22:31:07616 result.set_relevance_from_server(false);
[email protected]d1f0a7f2012-06-05 10:26:42617 }
618}
619
[email protected]188b50c2013-03-28 07:19:42620void SearchProvider::ApplyCalculatedNavigationRelevance(
621 NavigationResults* list) {
[email protected]d1f0a7f2012-06-05 10:26:42622 for (size_t i = 0; i < list->size(); ++i) {
[email protected]188b50c2013-03-28 07:19:42623 NavigationResult& result = (*list)[i];
624 result.set_relevance(
625 result.CalculateRelevance(input_, providers_.has_keyword_provider()) +
626 (list->size() - i - 1));
[email protected]d30268a2013-06-25 22:31:07627 result.set_relevance_from_server(false);
[email protected]d1f0a7f2012-06-05 10:26:42628 }
629}
630
[email protected]15fb2aa2012-05-22 22:52:59631net::URLFetcher* SearchProvider::CreateSuggestFetcher(
[email protected]7cc6e5632011-10-25 17:56:12632 int id,
[email protected]9ff91722012-09-07 05:29:12633 const TemplateURL* template_url,
[email protected]14710852013-02-05 23:45:41634 const AutocompleteInput& input) {
[email protected]9ff91722012-09-07 05:29:12635 if (!template_url || template_url->suggestions_url().empty())
636 return NULL;
637
638 // Bail if the suggestion URL is invalid with the given replacements.
[email protected]14710852013-02-05 23:45:41639 TemplateURLRef::SearchTermsArgs search_term_args(input.text());
640 search_term_args.cursor_position = input.cursor_position();
[email protected]d5015ca2013-08-08 22:04:18641 search_term_args.page_classification = input.current_page_classification();
[email protected]9ff91722012-09-07 05:29:12642 GURL suggest_url(template_url->suggestions_url_ref().ReplaceSearchTerms(
[email protected]00790562012-12-14 09:57:16643 search_term_args));
[email protected]9ff91722012-09-07 05:29:12644 if (!suggest_url.is_valid())
645 return NULL;
[email protected]9b9fa672013-11-07 06:04:52646 // Send the current page URL if user setting and URL requirements are met and
647 // the user is in the field trial.
648 if (CanSendURL(current_page_url_, suggest_url, template_url,
649 input.current_page_classification(), profile_) &&
650 OmniboxFieldTrial::InZeroSuggestAfterTypingFieldTrial()) {
651 search_term_args.current_page_url = current_page_url_.spec();
652 // Create the suggest URL again with the current page URL.
653 suggest_url = GURL(template_url->suggestions_url_ref().ReplaceSearchTerms(
654 search_term_args));
655 }
[email protected]9ff91722012-09-07 05:29:12656
657 suggest_results_pending_++;
658 LogOmniboxSuggestRequest(REQUEST_SENT);
659
660 net::URLFetcher* fetcher =
661 net::URLFetcher::Create(id, suggest_url, net::URLFetcher::GET, this);
[email protected]7cc6e5632011-10-25 17:56:12662 fetcher->SetRequestContext(profile_->GetRequestContext());
[email protected]d3cf8682f02012-02-29 23:29:34663 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES);
[email protected]bd3b4712012-12-18 17:01:30664 // Add Chrome experiment state to the request headers.
665 net::HttpRequestHeaders headers;
[email protected]ab7780792013-01-10 01:26:09666 chrome_variations::VariationsHttpHeaderProvider::GetInstance()->AppendHeaders(
[email protected]bd3b4712012-12-18 17:01:30667 fetcher->GetOriginalURL(), profile_->IsOffTheRecord(), false, &headers);
668 fetcher->SetExtraRequestHeaders(headers.ToString());
[email protected]257ab712009-04-14 17:16:24669 fetcher->Start();
670 return fetcher;
671}
672
[email protected]344946a12012-12-20 12:03:42673void SearchProvider::ConvertResultsToAutocompleteMatches() {
initial.commit09911bf2008-07-26 23:55:29674 // Convert all the results to matches and add them to a map, so we can keep
675 // the most relevant match for each result.
[email protected]31afdf72013-09-26 04:29:36676 base::TimeTicks start_time(base::TimeTicks::Now());
initial.commit09911bf2008-07-26 23:55:29677 MatchMap map;
[email protected]bc8bb0cd2013-06-24 21:50:23678 const base::Time no_time;
[email protected]cc1526e2013-05-17 04:04:24679 int did_not_accept_keyword_suggestion =
680 keyword_results_.suggest_results.empty() ?
initial.commit09911bf2008-07-26 23:55:29681 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE :
682 TemplateURLRef::NO_SUGGESTION_CHOSEN;
initial.commit09911bf2008-07-26 23:55:29683
[email protected]d30268a2013-06-25 22:31:07684 bool relevance_from_server;
685 int verbatim_relevance = GetVerbatimRelevance(&relevance_from_server);
[email protected]cc1526e2013-05-17 04:04:24686 int did_not_accept_default_suggestion =
687 default_results_.suggest_results.empty() ?
[email protected]55ce8f12012-05-09 04:44:08688 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE :
689 TemplateURLRef::NO_SUGGESTION_CHOSEN;
[email protected]d1f0a7f2012-06-05 10:26:42690 if (verbatim_relevance > 0) {
[email protected]c2ca3fd2014-03-22 03:07:44691 const base::string16& trimmed_verbatim =
692 base::CollapseWhitespace(input_.text(), false);
[email protected]2c03c06b2013-12-11 20:45:02693 SuggestResult verbatim(
[email protected]c2ca3fd2014-03-22 03:07:44694 trimmed_verbatim, AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED,
695 trimmed_verbatim, base::string16(), base::string16(), std::string(),
[email protected]61f99082014-02-24 02:17:49696 std::string(), false, verbatim_relevance, relevance_from_server, false,
[email protected]c2ca3fd2014-03-22 03:07:44697 trimmed_verbatim);
[email protected]57482a72014-03-14 22:27:37698 AddMatchToMap(verbatim, std::string(), did_not_accept_default_suggestion,
699 false, &map);
[email protected]d1f0a7f2012-06-05 10:26:42700 }
[email protected]5423e562013-02-07 03:58:45701 if (!keyword_input_.text().empty()) {
702 const TemplateURL* keyword_url = providers_.GetKeywordProviderURL();
703 // We only create the verbatim search query match for a keyword
704 // if it's not an extension keyword. Extension keywords are handled
705 // in KeywordProvider::Start(). (Extensions are complicated...)
706 // Note: in this provider, SEARCH_OTHER_ENGINE must correspond
707 // to the keyword verbatim search query. Do not create other matches
708 // of type SEARCH_OTHER_ENGINE.
[email protected]bdcbcd82013-10-28 13:40:25709 if (keyword_url &&
710 (keyword_url->GetType() != TemplateURL::OMNIBOX_API_EXTENSION)) {
[email protected]d30268a2013-06-25 22:31:07711 bool keyword_relevance_from_server;
712 const int keyword_verbatim_relevance =
713 GetKeywordVerbatimRelevance(&keyword_relevance_from_server);
[email protected]dab8d52d2013-03-05 07:35:28714 if (keyword_verbatim_relevance > 0) {
[email protected]c2ca3fd2014-03-22 03:07:44715 const base::string16& trimmed_verbatim =
716 base::CollapseWhitespace(keyword_input_.text(), false);
[email protected]2c03c06b2013-12-11 20:45:02717 SuggestResult verbatim(
[email protected]c2ca3fd2014-03-22 03:07:44718 trimmed_verbatim, AutocompleteMatchType::SEARCH_OTHER_ENGINE,
719 trimmed_verbatim, base::string16(), base::string16(),
[email protected]61f99082014-02-24 02:17:49720 std::string(), std::string(), true, keyword_verbatim_relevance,
[email protected]c2ca3fd2014-03-22 03:07:44721 keyword_relevance_from_server, false, trimmed_verbatim);
[email protected]57482a72014-03-14 22:27:37722 AddMatchToMap(verbatim, std::string(),
723 did_not_accept_keyword_suggestion, false, &map);
[email protected]dab8d52d2013-03-05 07:35:28724 }
[email protected]5423e562013-02-07 03:58:45725 }
726 }
[email protected]257ab712009-04-14 17:16:24727 AddHistoryResultsToMap(keyword_history_results_, true,
728 did_not_accept_keyword_suggestion, &map);
729 AddHistoryResultsToMap(default_history_results_, false,
730 did_not_accept_default_suggestion, &map);
731
[email protected]d1cb6a822013-09-18 19:43:00732 AddSuggestResultsToMap(keyword_results_.suggest_results,
733 keyword_results_.metadata, &map);
[email protected]987fad782013-08-28 06:23:18734 AddSuggestResultsToMap(default_results_.suggest_results,
735 default_results_.metadata, &map);
initial.commit09911bf2008-07-26 23:55:29736
[email protected]d30268a2013-06-25 22:31:07737 ACMatches matches;
initial.commit09911bf2008-07-26 23:55:29738 for (MatchMap::const_iterator i(map.begin()); i != map.end(); ++i)
[email protected]d30268a2013-06-25 22:31:07739 matches.push_back(i->second);
initial.commit09911bf2008-07-26 23:55:29740
[email protected]d30268a2013-06-25 22:31:07741 AddNavigationResultsToMatches(keyword_results_.navigation_results, &matches);
742 AddNavigationResultsToMatches(default_results_.navigation_results, &matches);
initial.commit09911bf2008-07-26 23:55:29743
[email protected]d30268a2013-06-25 22:31:07744 // Now add the most relevant matches to |matches_|. We take up to kMaxMatches
745 // suggest/navsuggest matches, regardless of origin. If Instant Extended is
746 // enabled and we have server-provided (and thus hopefully more accurate)
747 // scores for some suggestions, we allow more of those, until we reach
748 // AutocompleteResult::kMaxMatches total matches (that is, enough to fill the
749 // whole popup).
750 //
751 // We will always return any verbatim matches, no matter how we obtained their
752 // scores, unless we have already accepted AutocompleteResult::kMaxMatches
753 // higher-scoring matches under the conditions above.
[email protected]d30268a2013-06-25 22:31:07754 std::sort(matches.begin(), matches.end(), &AutocompleteMatch::MoreRelevant);
755 matches_.clear();
[email protected]3723e6e2012-06-11 21:06:56756
[email protected]d30268a2013-06-25 22:31:07757 size_t num_suggestions = 0;
758 for (ACMatches::const_iterator i(matches.begin());
759 (i != matches.end()) &&
760 (matches_.size() < AutocompleteResult::kMaxMatches);
761 ++i) {
762 // SEARCH_OTHER_ENGINE is only used in the SearchProvider for the keyword
763 // verbatim result, so this condition basically means "if this match is a
764 // suggestion of some sort".
765 if ((i->type != AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED) &&
766 (i->type != AutocompleteMatchType::SEARCH_OTHER_ENGINE)) {
767 // If we've already hit the limit on non-server-scored suggestions, and
768 // this isn't a server-scored suggestion we can add, skip it.
769 if ((num_suggestions >= kMaxMatches) &&
770 (!chrome::IsInstantExtendedAPIEnabled() ||
771 (i->GetAdditionalInfo(kRelevanceFromServerKey) != kTrue))) {
772 continue;
773 }
774
775 ++num_suggestions;
776 }
777
778 matches_.push_back(*i);
779 }
[email protected]31afdf72013-09-26 04:29:36780 UMA_HISTOGRAM_TIMES("Omnibox.SearchProvider.ConvertResultsTime",
781 base::TimeTicks::Now() - start_time);
[email protected]344946a12012-12-20 12:03:42782}
783
[email protected]89bd27d12014-04-12 17:36:23784ACMatches::const_iterator SearchProvider::FindTopMatch() const {
[email protected]0a8718b12013-11-13 18:41:31785 ACMatches::const_iterator it = matches_.begin();
786 while ((it != matches_.end()) && !it->allowed_to_be_default_match)
787 ++it;
788 return it;
[email protected]9dfb4d362013-04-05 02:15:12789}
790
[email protected]1c1e7842013-11-22 16:28:16791bool SearchProvider::HasKeywordDefaultMatchInKeywordMode() const {
792 const TemplateURL* keyword_url = providers_.GetKeywordProviderURL();
793 // If the user is not in keyword mode, return true to say that this
794 // constraint is not violated.
795 if (keyword_url == NULL)
796 return true;
797 for (ACMatches::const_iterator it = matches_.begin(); it != matches_.end();
798 ++it) {
799 if ((it->keyword == keyword_url->keyword()) &&
800 it->allowed_to_be_default_match)
801 return true;
802 }
803 return false;
804}
805
[email protected]89bd27d12014-04-12 17:36:23806bool SearchProvider::IsTopMatchSearchWithURLInput() const {
807 ACMatches::const_iterator first_match = FindTopMatch();
[email protected]0a8718b12013-11-13 18:41:31808 return (input_.type() == AutocompleteInput::URL) &&
809 (first_match != matches_.end()) &&
810 (first_match->relevance > CalculateRelevanceForVerbatim()) &&
811 (first_match->type != AutocompleteMatchType::NAVSUGGEST);
[email protected]344946a12012-12-20 12:03:42812}
813
[email protected]257ab712009-04-14 17:16:24814void SearchProvider::AddNavigationResultsToMatches(
[email protected]d30268a2013-06-25 22:31:07815 const NavigationResults& navigation_results,
816 ACMatches* matches) {
[email protected]bc8bb0cd2013-06-24 21:50:23817 for (NavigationResults::const_iterator it = navigation_results.begin();
818 it != navigation_results.end(); ++it) {
[email protected]d30268a2013-06-25 22:31:07819 matches->push_back(NavigationToMatch(*it));
[email protected]bc8bb0cd2013-06-24 21:50:23820 // In the absence of suggested relevance scores, use only the single
821 // highest-scoring result. (The results are already sorted by relevance.)
[email protected]d30268a2013-06-25 22:31:07822 if (!it->relevance_from_server())
[email protected]bc8bb0cd2013-06-24 21:50:23823 return;
[email protected]257ab712009-04-14 17:16:24824 }
825}
826
827void SearchProvider::AddHistoryResultsToMap(const HistoryResults& results,
828 bool is_keyword,
829 int did_not_accept_suggestion,
830 MatchMap* map) {
[email protected]51124552011-07-16 01:37:10831 if (results.empty())
832 return;
833
[email protected]31afdf72013-09-26 04:29:36834 base::TimeTicks start_time(base::TimeTicks::Now());
[email protected]d7ad4772012-06-01 03:12:54835 bool prevent_inline_autocomplete = input_.prevent_inline_autocomplete() ||
836 (input_.type() == AutocompleteInput::URL);
[email protected]0085863a2013-12-06 21:19:03837 const base::string16& input_text =
[email protected]14710852013-02-05 23:45:41838 is_keyword ? keyword_input_.text() : input_.text();
[email protected]51124552011-07-16 01:37:10839 bool input_multiple_words = HasMultipleWords(input_text);
840
[email protected]55ce8f12012-05-09 04:44:08841 SuggestResults scored_results;
842 if (!prevent_inline_autocomplete && input_multiple_words) {
843 // ScoreHistoryResults() allows autocompletion of multi-word, 1-visit
844 // queries if the input also has multiple words. But if we were already
[email protected]f13a2132014-04-22 08:13:52845 // scoring a multi-word, multi-visit query aggressively, and the current
846 // input is still a prefix of it, then changing the suggestion suddenly
847 // feels wrong. To detect this case, first score as if only one word has
848 // been typed, then check if the best result came from aggressive search
849 // history scoring. If it did, then just keep that score set. This
850 // 1200 the lowest possible score in CalculateRelevanceForHistory()'s
851 // aggressive-scoring curve.
[email protected]55ce8f12012-05-09 04:44:08852 scored_results = ScoreHistoryResults(results, prevent_inline_autocomplete,
853 false, input_text, is_keyword);
[email protected]f13a2132014-04-22 08:13:52854 if ((scored_results.front().relevance() < 1200) ||
[email protected]9dfb4d362013-04-05 02:15:12855 !HasMultipleWords(scored_results.front().suggestion()))
[email protected]55ce8f12012-05-09 04:44:08856 scored_results.clear(); // Didn't detect the case above, score normally.
[email protected]51124552011-07-16 01:37:10857 }
[email protected]55ce8f12012-05-09 04:44:08858 if (scored_results.empty())
859 scored_results = ScoreHistoryResults(results, prevent_inline_autocomplete,
860 input_multiple_words, input_text,
861 is_keyword);
862 for (SuggestResults::const_iterator i(scored_results.begin());
863 i != scored_results.end(); ++i) {
[email protected]57482a72014-03-14 22:27:37864 AddMatchToMap(*i, std::string(), did_not_accept_suggestion, true, map);
[email protected]51124552011-07-16 01:37:10865 }
[email protected]31afdf72013-09-26 04:29:36866 UMA_HISTOGRAM_TIMES("Omnibox.SearchProvider.AddHistoryResultsTime",
867 base::TimeTicks::Now() - start_time);
[email protected]51124552011-07-16 01:37:10868}
869
[email protected]55ce8f12012-05-09 04:44:08870SearchProvider::SuggestResults SearchProvider::ScoreHistoryResults(
[email protected]51124552011-07-16 01:37:10871 const HistoryResults& results,
872 bool base_prevent_inline_autocomplete,
873 bool input_multiple_words,
[email protected]0085863a2013-12-06 21:19:03874 const base::string16& input_text,
[email protected]51124552011-07-16 01:37:10875 bool is_keyword) {
[email protected]810ffba2012-06-12 01:07:48876 AutocompleteClassifier* classifier =
877 AutocompleteClassifierFactory::GetForProfile(profile_);
[email protected]55ce8f12012-05-09 04:44:08878 SuggestResults scored_results;
[email protected]78e5e432013-08-03 02:10:10879 const bool prevent_search_history_inlining =
880 OmniboxFieldTrial::SearchHistoryPreventInlining(
881 input_.current_page_classification());
[email protected]c2ca3fd2014-03-22 03:07:44882 const base::string16& trimmed_input =
883 base::CollapseWhitespace(input_text, false);
[email protected]257ab712009-04-14 17:16:24884 for (HistoryResults::const_iterator i(results.begin()); i != results.end();
885 ++i) {
[email protected]c2ca3fd2014-03-22 03:07:44886 const base::string16& trimmed_suggestion =
887 base::CollapseWhitespace(i->term, false);
888
[email protected]51124552011-07-16 01:37:10889 // Don't autocomplete multi-word queries that have only been seen once
890 // unless the user has typed more than one word.
891 bool prevent_inline_autocomplete = base_prevent_inline_autocomplete ||
[email protected]c2ca3fd2014-03-22 03:07:44892 (!input_multiple_words && (i->visits < 2) &&
893 HasMultipleWords(trimmed_suggestion));
[email protected]51124552011-07-16 01:37:10894
[email protected]ea3b9a502011-04-04 14:19:37895 // Don't autocomplete search terms that would normally be treated as URLs
[email protected]51124552011-07-16 01:37:10896 // when typed. For example, if the user searched for "google.com" and types
897 // "goog", don't autocomplete to the search term "google.com". Otherwise,
898 // the input will look like a URL but act like a search, which is confusing.
[email protected]cc447362011-04-06 03:57:48899 // NOTE: We don't check this in the following cases:
900 // * When inline autocomplete is disabled, we won't be inline
901 // autocompleting this term, so we don't need to worry about confusion as
902 // much. This also prevents calling Classify() again from inside the
903 // classifier (which will corrupt state and likely crash), since the
[email protected]51124552011-07-16 01:37:10904 // classifier always disables inline autocomplete.
[email protected]cc447362011-04-06 03:57:48905 // * When the user has typed the whole term, the "what you typed" history
906 // match will outrank us for URL-like inputs anyway, so we need not do
907 // anything special.
[email protected]c2ca3fd2014-03-22 03:07:44908 if (!prevent_inline_autocomplete && classifier &&
909 (trimmed_suggestion != trimmed_input)) {
[email protected]ea3b9a502011-04-04 14:19:37910 AutocompleteMatch match;
[email protected]c2ca3fd2014-03-22 03:07:44911 classifier->Classify(trimmed_suggestion, false, false,
[email protected]51abb7b2014-02-09 23:00:08912 input_.current_page_classification(), &match, NULL);
[email protected]2905f742011-10-13 03:51:58913 prevent_inline_autocomplete =
[email protected]749e7ae02012-09-05 18:47:46914 !AutocompleteMatch::IsSearchType(match.type);
[email protected]ea3b9a502011-04-04 14:19:37915 }
[email protected]51124552011-07-16 01:37:10916
[email protected]78e5e432013-08-03 02:10:10917 int relevance = CalculateRelevanceForHistory(
918 i->time, is_keyword, !prevent_inline_autocomplete,
919 prevent_search_history_inlining);
[email protected]2c03c06b2013-12-11 20:45:02920 scored_results.push_back(SuggestResult(
[email protected]c2ca3fd2014-03-22 03:07:44921 trimmed_suggestion, AutocompleteMatchType::SEARCH_HISTORY,
922 trimmed_suggestion, base::string16(), base::string16(), std::string(),
923 std::string(), is_keyword, relevance, false, false, trimmed_input));
[email protected]257ab712009-04-14 17:16:24924 }
[email protected]51124552011-07-16 01:37:10925
926 // History returns results sorted for us. However, we may have docked some
927 // results' scores, so things are no longer in order. Do a stable sort to get
928 // things back in order without otherwise disturbing results with equal
929 // scores, then force the scores to be unique, so that the order in which
930 // they're shown is deterministic.
[email protected]55ce8f12012-05-09 04:44:08931 std::stable_sort(scored_results.begin(), scored_results.end(),
932 CompareScoredResults());
[email protected]51124552011-07-16 01:37:10933 int last_relevance = 0;
[email protected]55ce8f12012-05-09 04:44:08934 for (SuggestResults::iterator i(scored_results.begin());
935 i != scored_results.end(); ++i) {
936 if ((i != scored_results.begin()) && (i->relevance() >= last_relevance))
937 i->set_relevance(last_relevance - 1);
938 last_relevance = i->relevance();
[email protected]51124552011-07-16 01:37:10939 }
940
[email protected]55ce8f12012-05-09 04:44:08941 return scored_results;
[email protected]257ab712009-04-14 17:16:24942}
943
[email protected]55ce8f12012-05-09 04:44:08944void SearchProvider::AddSuggestResultsToMap(const SuggestResults& results,
[email protected]987fad782013-08-28 06:23:18945 const std::string& metadata,
[email protected]55ce8f12012-05-09 04:44:08946 MatchMap* map) {
[email protected]9487b392014-02-14 02:48:18947 for (size_t i = 0; i < results.size(); ++i)
[email protected]57482a72014-03-14 22:27:37948 AddMatchToMap(results[i], metadata, i, false, map);
initial.commit09911bf2008-07-26 23:55:29949}
950
[email protected]d30268a2013-06-25 22:31:07951int SearchProvider::GetVerbatimRelevance(bool* relevance_from_server) const {
[email protected]dc6943b2012-06-19 06:39:56952 // Use the suggested verbatim relevance score if it is non-negative (valid),
953 // if inline autocomplete isn't prevented (always show verbatim on backspace),
[email protected]1beee342012-06-19 22:22:28954 // and if it won't suppress verbatim, leaving no default provider matches.
955 // Otherwise, if the default provider returned no matches and was still able
[email protected]dc6943b2012-06-19 06:39:56956 // to suppress verbatim, the user would have no search/nav matches and may be
[email protected]1beee342012-06-19 22:22:28957 // left unable to search using their default provider from the omnibox.
[email protected]dc6943b2012-06-19 06:39:56958 // Check for results on each verbatim calculation, as results from older
959 // queries (on previous input) may be trimmed for failing to inline new input.
[email protected]bc8bb0cd2013-06-24 21:50:23960 bool use_server_relevance =
961 (default_results_.verbatim_relevance >= 0) &&
[email protected]dab8d52d2013-03-05 07:35:28962 !input_.prevent_inline_autocomplete() &&
[email protected]bc8bb0cd2013-06-24 21:50:23963 ((default_results_.verbatim_relevance > 0) ||
[email protected]cc1526e2013-05-17 04:04:24964 !default_results_.suggest_results.empty() ||
[email protected]bc8bb0cd2013-06-24 21:50:23965 !default_results_.navigation_results.empty());
[email protected]d30268a2013-06-25 22:31:07966 if (relevance_from_server)
967 *relevance_from_server = use_server_relevance;
[email protected]bc8bb0cd2013-06-24 21:50:23968 return use_server_relevance ?
969 default_results_.verbatim_relevance : CalculateRelevanceForVerbatim();
[email protected]382a0642012-06-06 06:13:52970}
[email protected]d1f0a7f2012-06-05 10:26:42971
[email protected]382a0642012-06-06 06:13:52972int SearchProvider::CalculateRelevanceForVerbatim() const {
[email protected]85b8d6f2012-05-08 20:53:47973 if (!providers_.keyword_provider().empty())
[email protected]52d08b12009-10-19 18:42:36974 return 250;
[email protected]dab8d52d2013-03-05 07:35:28975 return CalculateRelevanceForVerbatimIgnoringKeywordModeState();
976}
[email protected]52d08b12009-10-19 18:42:36977
[email protected]dab8d52d2013-03-05 07:35:28978int SearchProvider::
979 CalculateRelevanceForVerbatimIgnoringKeywordModeState() const {
initial.commit09911bf2008-07-26 23:55:29980 switch (input_.type()) {
981 case AutocompleteInput::UNKNOWN:
[email protected]52d08b12009-10-19 18:42:36982 case AutocompleteInput::QUERY:
983 case AutocompleteInput::FORCED_QUERY:
[email protected]90fe2bb2013-01-15 03:42:13984 return kNonURLVerbatimRelevance;
initial.commit09911bf2008-07-26 23:55:29985
initial.commit09911bf2008-07-26 23:55:29986 case AutocompleteInput::URL:
[email protected]52d08b12009-10-19 18:42:36987 return 850;
initial.commit09911bf2008-07-26 23:55:29988
989 default:
990 NOTREACHED();
991 return 0;
992 }
993}
994
[email protected]d30268a2013-06-25 22:31:07995int SearchProvider::GetKeywordVerbatimRelevance(
996 bool* relevance_from_server) const {
[email protected]dab8d52d2013-03-05 07:35:28997 // Use the suggested verbatim relevance score if it is non-negative (valid),
998 // if inline autocomplete isn't prevented (always show verbatim on backspace),
999 // and if it won't suppress verbatim, leaving no keyword provider matches.
1000 // Otherwise, if the keyword provider returned no matches and was still able
1001 // to suppress verbatim, the user would have no search/nav matches and may be
1002 // left unable to search using their keyword provider from the omnibox.
1003 // Check for results on each verbatim calculation, as results from older
1004 // queries (on previous input) may be trimmed for failing to inline new input.
[email protected]bc8bb0cd2013-06-24 21:50:231005 bool use_server_relevance =
1006 (keyword_results_.verbatim_relevance >= 0) &&
[email protected]dab8d52d2013-03-05 07:35:281007 !input_.prevent_inline_autocomplete() &&
[email protected]bc8bb0cd2013-06-24 21:50:231008 ((keyword_results_.verbatim_relevance > 0) ||
[email protected]cc1526e2013-05-17 04:04:241009 !keyword_results_.suggest_results.empty() ||
[email protected]bc8bb0cd2013-06-24 21:50:231010 !keyword_results_.navigation_results.empty());
[email protected]d30268a2013-06-25 22:31:071011 if (relevance_from_server)
1012 *relevance_from_server = use_server_relevance;
[email protected]bc8bb0cd2013-06-24 21:50:231013 return use_server_relevance ?
1014 keyword_results_.verbatim_relevance :
1015 CalculateRelevanceForKeywordVerbatim(keyword_input_.type(),
1016 keyword_input_.prefer_keyword());
[email protected]5423e562013-02-07 03:58:451017}
1018
[email protected]51124552011-07-16 01:37:101019int SearchProvider::CalculateRelevanceForHistory(
[email protected]bc8bb0cd2013-06-24 21:50:231020 const base::Time& time,
[email protected]51124552011-07-16 01:37:101021 bool is_keyword,
[email protected]78e5e432013-08-03 02:10:101022 bool use_aggressive_method,
1023 bool prevent_search_history_inlining) const {
[email protected]aa613d62010-11-09 20:40:181024 // The relevance of past searches falls off over time. There are two distinct
1025 // equations used. If the first equation is used (searches to the primary
[email protected]78e5e432013-08-03 02:10:101026 // provider that we want to score aggressively), the score is in the range
1027 // 1300-1599 (unless |prevent_search_history_inlining|, in which case
[email protected]d8cd76b2013-07-10 09:46:161028 // it's in the range 1200-1299). If the second equation is used the
1029 // relevance of a search 15 minutes ago is discounted 50 points, while the
1030 // relevance of a search two weeks ago is discounted 450 points.
[email protected]bc8bb0cd2013-06-24 21:50:231031 double elapsed_time = std::max((base::Time::Now() - time).InSecondsF(), 0.0);
[email protected]188b50c2013-03-28 07:19:421032 bool is_primary_provider = is_keyword || !providers_.has_keyword_provider();
[email protected]78e5e432013-08-03 02:10:101033 if (is_primary_provider && use_aggressive_method) {
[email protected]aa613d62010-11-09 20:40:181034 // Searches with the past two days get a different curve.
[email protected]51124552011-07-16 01:37:101035 const double autocomplete_time = 2 * 24 * 60 * 60;
[email protected]aa613d62010-11-09 20:40:181036 if (elapsed_time < autocomplete_time) {
[email protected]d8cd76b2013-07-10 09:46:161037 int max_score = is_keyword ? 1599 : 1399;
[email protected]78e5e432013-08-03 02:10:101038 if (prevent_search_history_inlining)
[email protected]d8cd76b2013-07-10 09:46:161039 max_score = 1299;
1040 return max_score - static_cast<int>(99 *
[email protected]aa613d62010-11-09 20:40:181041 std::pow(elapsed_time / autocomplete_time, 2.5));
1042 }
1043 elapsed_time -= autocomplete_time;
1044 }
1045
[email protected]c3a4bd992010-08-18 20:25:011046 const int score_discount =
1047 static_cast<int>(6.5 * std::pow(elapsed_time, 0.3));
initial.commit09911bf2008-07-26 23:55:291048
[email protected]6c85aa02009-02-27 12:08:091049 // Don't let scores go below 0. Negative relevance scores are meaningful in
1050 // a different way.
initial.commit09911bf2008-07-26 23:55:291051 int base_score;
[email protected]51124552011-07-16 01:37:101052 if (is_primary_provider)
[email protected]52d08b12009-10-19 18:42:361053 base_score = (input_.type() == AutocompleteInput::URL) ? 750 : 1050;
[email protected]51124552011-07-16 01:37:101054 else
1055 base_score = 200;
initial.commit09911bf2008-07-26 23:55:291056 return std::max(0, base_score - score_discount);
1057}
1058
initial.commit09911bf2008-07-26 23:55:291059AutocompleteMatch SearchProvider::NavigationToMatch(
[email protected]188b50c2013-03-28 07:19:421060 const NavigationResult& navigation) {
[email protected]5889bfb2014-03-19 00:26:481061 base::string16 input;
1062 const bool trimmed_whitespace = base::TrimWhitespace(
1063 navigation.from_keyword_provider() ?
1064 keyword_input_.text() : input_.text(),
1065 base::TRIM_TRAILING, &input) != base::TRIM_NONE;
[email protected]55ce8f12012-05-09 04:44:081066 AutocompleteMatch match(this, navigation.relevance(), false,
[email protected]b7f64d742013-05-21 04:04:041067 AutocompleteMatchType::NAVSUGGEST);
[email protected]55ce8f12012-05-09 04:44:081068 match.destination_url = navigation.url();
[email protected]371dab12012-06-01 03:23:551069
[email protected]23db6492014-01-16 02:35:301070 // First look for the user's input inside the formatted url as it would be
[email protected]371dab12012-06-01 03:23:551071 // without trimming the scheme, so we can find matches at the beginning of the
1072 // scheme.
[email protected]371dab12012-06-01 03:23:551073 const URLPrefix* prefix =
[email protected]23db6492014-01-16 02:35:301074 URLPrefix::BestURLPrefix(navigation.formatted_url(), input);
[email protected]371dab12012-06-01 03:23:551075 size_t match_start = (prefix == NULL) ?
[email protected]23db6492014-01-16 02:35:301076 navigation.formatted_url().find(input) : prefix->prefix.length();
[email protected]d2445c82013-11-04 22:28:351077 bool trim_http = !AutocompleteInput::HasHTTPScheme(input) &&
1078 (!prefix || (match_start != 0));
[email protected]23db6492014-01-16 02:35:301079 const net::FormatUrlTypes format_types =
1080 net::kFormatUrlOmitAll & ~(trim_http ? 0 : net::kFormatUrlOmitHTTP);
[email protected]371dab12012-06-01 03:23:551081
[email protected]371dab12012-06-01 03:23:551082 const std::string languages(
1083 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages));
[email protected]23db6492014-01-16 02:35:301084 size_t inline_autocomplete_offset = (prefix == NULL) ?
1085 base::string16::npos : (match_start + input.length());
[email protected]371dab12012-06-01 03:23:551086 match.fill_into_edit +=
1087 AutocompleteInput::FormattedStringWithEquivalentMeaning(navigation.url(),
1088 net::FormatUrl(navigation.url(), languages, format_types,
1089 net::UnescapeRule::SPACES, NULL, NULL,
1090 &inline_autocomplete_offset));
[email protected]14119032013-11-07 08:14:261091 // Preserve the forced query '?' prefix in |match.fill_into_edit|.
1092 // Otherwise, user edits to a suggestion would show non-Search results.
1093 if (input_.type() == AutocompleteInput::FORCED_QUERY) {
[email protected]670d3232013-12-24 17:58:581094 match.fill_into_edit.insert(0, base::ASCIIToUTF16("?"));
[email protected]0085863a2013-12-06 21:19:031095 if (inline_autocomplete_offset != base::string16::npos)
[email protected]14119032013-11-07 08:14:261096 ++inline_autocomplete_offset;
1097 }
[email protected]6c94a1022014-02-21 03:48:041098 if (inline_autocomplete_offset != base::string16::npos) {
[email protected]518024c2013-07-19 23:40:251099 DCHECK(inline_autocomplete_offset <= match.fill_into_edit.length());
1100 match.inline_autocompletion =
1101 match.fill_into_edit.substr(inline_autocomplete_offset);
1102 }
[email protected]6c94a1022014-02-21 03:48:041103 // An inlineable navsuggestion can only be the default match when there
1104 // is no keyword provider active, lest it appear first and break the user
[email protected]5889bfb2014-03-19 00:26:481105 // out of keyword mode. It can also only be default if either the inline
1106 // autocompletion is empty or we're not preventing inline autocompletion.
1107 // Finally, if we have an inlineable navsuggestion with an inline completion
1108 // that we're not preventing, make sure we didn't trim any whitespace.
1109 // We don't want to claim http://foo.com/bar is inlineable against the
1110 // input "foo.com/b ".
[email protected]6c94a1022014-02-21 03:48:041111 match.allowed_to_be_default_match = navigation.IsInlineable(input) &&
1112 (providers_.GetKeywordProviderURL() == NULL) &&
[email protected]5889bfb2014-03-19 00:26:481113 (match.inline_autocompletion.empty() ||
1114 (!input_.prevent_inline_autocomplete() && !trimmed_whitespace));
[email protected]371dab12012-06-01 03:23:551115
[email protected]23db6492014-01-16 02:35:301116 match.contents = navigation.match_contents();
1117 match.contents_class = navigation.match_contents_class();
[email protected]55ce8f12012-05-09 04:44:081118 match.description = navigation.description();
[email protected]371dab12012-06-01 03:23:551119 AutocompleteMatch::ClassifyMatchInString(input, match.description,
1120 ACMatchClassification::NONE, &match.description_class);
[email protected]d30268a2013-06-25 22:31:071121
1122 match.RecordAdditionalInfo(
1123 kRelevanceFromServerKey,
1124 navigation.relevance_from_server() ? kTrue : kFalse);
[email protected]987fad782013-08-28 06:23:181125 match.RecordAdditionalInfo(kShouldPrefetchKey, kFalse);
[email protected]d30268a2013-06-25 22:31:071126
initial.commit09911bf2008-07-26 23:55:291127 return match;
1128}
[email protected]4ab4c7c2010-11-24 04:49:341129
[email protected]4ab4c7c2010-11-24 04:49:341130void SearchProvider::UpdateDone() {
[email protected]2cdf1172012-08-26 12:21:331131 // We're done when the timer isn't running, there are no suggest queries
[email protected]5fac3782013-03-06 09:32:311132 // pending, and we're not waiting on Instant.
[email protected]e1290ee62013-06-26 18:31:151133 done_ = !timer_.IsRunning() && (suggest_results_pending_ == 0);
[email protected]4ab4c7c2010-11-24 04:49:341134}