Chromium Code Reviews| 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/callback.h" | 10 #include "base/callback.h" |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 #include "chrome/browser/autocomplete/autocomplete_result.h" | 22 #include "chrome/browser/autocomplete/autocomplete_result.h" |
| 23 #include "chrome/browser/autocomplete/keyword_provider.h" | 23 #include "chrome/browser/autocomplete/keyword_provider.h" |
| 24 #include "chrome/browser/autocomplete/url_prefix.h" | 24 #include "chrome/browser/autocomplete/url_prefix.h" |
| 25 #include "chrome/browser/google/google_util.h" | 25 #include "chrome/browser/google/google_util.h" |
| 26 #include "chrome/browser/history/history_service.h" | 26 #include "chrome/browser/history/history_service.h" |
| 27 #include "chrome/browser/history/history_service_factory.h" | 27 #include "chrome/browser/history/history_service_factory.h" |
| 28 #include "chrome/browser/history/in_memory_database.h" | 28 #include "chrome/browser/history/in_memory_database.h" |
| 29 #include "chrome/browser/metrics/variations/variations_http_header_provider.h" | 29 #include "chrome/browser/metrics/variations/variations_http_header_provider.h" |
| 30 #include "chrome/browser/omnibox/omnibox_field_trial.h" | 30 #include "chrome/browser/omnibox/omnibox_field_trial.h" |
| 31 #include "chrome/browser/profiles/profile.h" | 31 #include "chrome/browser/profiles/profile.h" |
| 32 #include "chrome/browser/search/instant_service.h" | |
| 33 #include "chrome/browser/search/instant_service_factory.h" | |
| 34 #include "chrome/browser/search/search.h" | 32 #include "chrome/browser/search/search.h" |
| 35 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" | 33 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" |
| 36 #include "chrome/browser/search_engines/template_url_service.h" | 34 #include "chrome/browser/search_engines/template_url_service.h" |
| 37 #include "chrome/browser/search_engines/template_url_service_factory.h" | 35 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 38 #include "chrome/browser/ui/browser.h" | |
| 39 #include "chrome/browser/ui/browser_finder.h" | |
| 40 #include "chrome/browser/ui/browser_instant_controller.h" | |
| 41 #include "chrome/browser/ui/search/instant_controller.h" | 36 #include "chrome/browser/ui/search/instant_controller.h" |
| 42 #include "chrome/common/net/url_fixer_upper.h" | 37 #include "chrome/common/net/url_fixer_upper.h" |
| 43 #include "chrome/common/pref_names.h" | 38 #include "chrome/common/pref_names.h" |
| 44 #include "chrome/common/url_constants.h" | 39 #include "chrome/common/url_constants.h" |
| 45 #include "content/public/browser/user_metrics.h" | 40 #include "content/public/browser/user_metrics.h" |
| 46 #include "grit/generated_resources.h" | 41 #include "grit/generated_resources.h" |
| 47 #include "net/base/escape.h" | 42 #include "net/base/escape.h" |
| 48 #include "net/base/load_flags.h" | 43 #include "net/base/load_flags.h" |
| 49 #include "net/base/net_util.h" | 44 #include "net/base/net_util.h" |
| 50 #include "net/http/http_request_headers.h" | 45 #include "net/http/http_request_headers.h" |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 195 }; | 190 }; |
| 196 | 191 |
| 197 | 192 |
| 198 // SearchProvider ------------------------------------------------------------- | 193 // SearchProvider ------------------------------------------------------------- |
| 199 | 194 |
| 200 // static | 195 // static |
| 201 const int SearchProvider::kDefaultProviderURLFetcherID = 1; | 196 const int SearchProvider::kDefaultProviderURLFetcherID = 1; |
| 202 const int SearchProvider::kKeywordProviderURLFetcherID = 2; | 197 const int SearchProvider::kKeywordProviderURLFetcherID = 2; |
| 203 const int SearchProvider::kDeletionURLFetcherID = 3; | 198 const int SearchProvider::kDeletionURLFetcherID = 3; |
| 204 int SearchProvider::kMinimumTimeBetweenSuggestQueriesMs = 100; | 199 int SearchProvider::kMinimumTimeBetweenSuggestQueriesMs = 100; |
| 205 const char SearchProvider::kRelevanceFromServerKey[] = "relevance_from_server"; | |
| 206 const char SearchProvider::kShouldPrefetchKey[] = "should_prefetch"; | |
| 207 const char SearchProvider::kSuggestMetadataKey[] = "suggest_metadata"; | |
| 208 const char SearchProvider::kDeletionUrlKey[] = "deletion_url"; | |
| 209 const char SearchProvider::kTrue[] = "true"; | |
| 210 const char SearchProvider::kFalse[] = "false"; | |
| 211 | 200 |
| 212 SearchProvider::SearchProvider(AutocompleteProviderListener* listener, | 201 SearchProvider::SearchProvider(AutocompleteProviderListener* listener, |
| 213 Profile* profile) | 202 Profile* profile) |
| 214 : BaseSearchProvider(listener, profile, AutocompleteProvider::TYPE_SEARCH), | 203 : BaseSearchProvider(listener, profile, AutocompleteProvider::TYPE_SEARCH), |
| 215 providers_(TemplateURLServiceFactory::GetForProfile(profile)), | 204 providers_(TemplateURLServiceFactory::GetForProfile(profile)), |
| 216 suggest_results_pending_(0) { | 205 suggest_results_pending_(0) { |
| 217 } | 206 } |
| 218 | 207 |
| 219 // static | 208 // static |
| 220 bool SearchProvider::ShouldPrefetch(const AutocompleteMatch& match) { | |
| 221 return match.GetAdditionalInfo(kShouldPrefetchKey) == kTrue; | |
| 222 } | |
| 223 | |
| 224 // static | |
| 225 std::string SearchProvider::GetSuggestMetadata(const AutocompleteMatch& match) { | 209 std::string SearchProvider::GetSuggestMetadata(const AutocompleteMatch& match) { |
| 226 return match.GetAdditionalInfo(kSuggestMetadataKey); | 210 return match.GetAdditionalInfo(kSuggestMetadataKey); |
| 227 } | 211 } |
| 228 | 212 |
| 229 void SearchProvider::DeleteMatch(const AutocompleteMatch& match) { | 213 void SearchProvider::DeleteMatch(const AutocompleteMatch& match) { |
| 230 DCHECK(match.deletable); | 214 DCHECK(match.deletable); |
| 231 | 215 |
| 232 deletion_handlers_.push_back(new SuggestionDeletionHandler( | 216 deletion_handlers_.push_back(new SuggestionDeletionHandler( |
| 233 match.GetAdditionalInfo(SearchProvider::kDeletionUrlKey), | 217 match.GetAdditionalInfo(SearchProvider::kDeletionUrlKey), |
| 234 profile_, | 218 profile_, |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 485 | 469 |
| 486 scoped_ptr<base::Value> data(DeserializeJsonData(json_data)); | 470 scoped_ptr<base::Value> data(DeserializeJsonData(json_data)); |
| 487 results_updated = data.get() && ParseSuggestResults(data.get(), is_keyword); | 471 results_updated = data.get() && ParseSuggestResults(data.get(), is_keyword); |
| 488 } | 472 } |
| 489 | 473 |
| 490 UpdateMatches(); | 474 UpdateMatches(); |
| 491 if (done_ || results_updated) | 475 if (done_ || results_updated) |
| 492 listener_->OnProviderUpdate(results_updated); | 476 listener_->OnProviderUpdate(results_updated); |
| 493 } | 477 } |
| 494 | 478 |
| 479 bool SearchProvider::ShouldAppendExtraParams( | |
| 480 const SuggestResult& result) const { | |
| 481 return !result.from_keyword_provider() || | |
| 482 providers_.default_provider().empty(); | |
|
Mark P
2014/02/12 23:35:49
does this not fit on one line?
Maria
2014/02/13 21:07:36
83 chars :(
| |
| 483 } | |
| 484 | |
| 495 void SearchProvider::OnDeletionComplete(bool success, | 485 void SearchProvider::OnDeletionComplete(bool success, |
| 496 SuggestionDeletionHandler* handler) { | 486 SuggestionDeletionHandler* handler) { |
| 497 RecordDeletionResult(success); | 487 RecordDeletionResult(success); |
| 498 SuggestionDeletionHandlers::iterator it = std::find( | 488 SuggestionDeletionHandlers::iterator it = std::find( |
| 499 deletion_handlers_.begin(), deletion_handlers_.end(), handler); | 489 deletion_handlers_.begin(), deletion_handlers_.end(), handler); |
| 500 DCHECK(it != deletion_handlers_.end()); | 490 DCHECK(it != deletion_handlers_.end()); |
| 501 deletion_handlers_.erase(it); | 491 deletion_handlers_.erase(it); |
| 502 } | 492 } |
| 503 | 493 |
| 504 | 494 |
| (...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 998 int verbatim_relevance = GetVerbatimRelevance(&relevance_from_server); | 988 int verbatim_relevance = GetVerbatimRelevance(&relevance_from_server); |
| 999 int did_not_accept_default_suggestion = | 989 int did_not_accept_default_suggestion = |
| 1000 default_results_.suggest_results.empty() ? | 990 default_results_.suggest_results.empty() ? |
| 1001 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE : | 991 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE : |
| 1002 TemplateURLRef::NO_SUGGESTION_CHOSEN; | 992 TemplateURLRef::NO_SUGGESTION_CHOSEN; |
| 1003 if (verbatim_relevance > 0) { | 993 if (verbatim_relevance > 0) { |
| 1004 SuggestResult verbatim( | 994 SuggestResult verbatim( |
| 1005 input_.text(), AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, | 995 input_.text(), AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, |
| 1006 input_.text(), base::string16(), std::string(), std::string(), false, | 996 input_.text(), base::string16(), std::string(), std::string(), false, |
| 1007 verbatim_relevance, relevance_from_server, false, input_.text()); | 997 verbatim_relevance, relevance_from_server, false, input_.text()); |
| 1008 AddMatchToMap(verbatim, input_.text(), std::string(), | 998 AddMatchToMap( |
| 1009 did_not_accept_default_suggestion, &map); | 999 verbatim, input_, GetTemplateURL(verbatim), std::string(), |
| 1000 did_not_accept_default_suggestion, &map); | |
| 1010 } | 1001 } |
| 1011 if (!keyword_input_.text().empty()) { | 1002 if (!keyword_input_.text().empty()) { |
| 1012 const TemplateURL* keyword_url = providers_.GetKeywordProviderURL(); | 1003 const TemplateURL* keyword_url = providers_.GetKeywordProviderURL(); |
| 1013 // We only create the verbatim search query match for a keyword | 1004 // We only create the verbatim search query match for a keyword |
| 1014 // if it's not an extension keyword. Extension keywords are handled | 1005 // if it's not an extension keyword. Extension keywords are handled |
| 1015 // in KeywordProvider::Start(). (Extensions are complicated...) | 1006 // in KeywordProvider::Start(). (Extensions are complicated...) |
| 1016 // Note: in this provider, SEARCH_OTHER_ENGINE must correspond | 1007 // Note: in this provider, SEARCH_OTHER_ENGINE must correspond |
| 1017 // to the keyword verbatim search query. Do not create other matches | 1008 // to the keyword verbatim search query. Do not create other matches |
| 1018 // of type SEARCH_OTHER_ENGINE. | 1009 // of type SEARCH_OTHER_ENGINE. |
| 1019 if (keyword_url && | 1010 if (keyword_url && |
| 1020 (keyword_url->GetType() != TemplateURL::OMNIBOX_API_EXTENSION)) { | 1011 (keyword_url->GetType() != TemplateURL::OMNIBOX_API_EXTENSION)) { |
| 1021 bool keyword_relevance_from_server; | 1012 bool keyword_relevance_from_server; |
| 1022 const int keyword_verbatim_relevance = | 1013 const int keyword_verbatim_relevance = |
| 1023 GetKeywordVerbatimRelevance(&keyword_relevance_from_server); | 1014 GetKeywordVerbatimRelevance(&keyword_relevance_from_server); |
| 1024 if (keyword_verbatim_relevance > 0) { | 1015 if (keyword_verbatim_relevance > 0) { |
| 1025 SuggestResult verbatim( | 1016 SuggestResult verbatim( |
| 1026 keyword_input_.text(), AutocompleteMatchType::SEARCH_OTHER_ENGINE, | 1017 keyword_input_.text(), AutocompleteMatchType::SEARCH_OTHER_ENGINE, |
| 1027 keyword_input_.text(), base::string16(), std::string(), | 1018 keyword_input_.text(), base::string16(), std::string(), |
| 1028 std::string(), true, keyword_verbatim_relevance, | 1019 std::string(), true, keyword_verbatim_relevance, |
| 1029 keyword_relevance_from_server, false, keyword_input_.text()); | 1020 keyword_relevance_from_server, false, keyword_input_.text()); |
| 1030 AddMatchToMap(verbatim, keyword_input_.text(), std::string(), | 1021 AddMatchToMap( |
| 1031 did_not_accept_keyword_suggestion, &map); | 1022 verbatim, keyword_input_, GetTemplateURL(verbatim), std::string(), |
| 1023 did_not_accept_keyword_suggestion, &map); | |
| 1032 } | 1024 } |
| 1033 } | 1025 } |
| 1034 } | 1026 } |
| 1035 AddHistoryResultsToMap(keyword_history_results_, true, | 1027 AddHistoryResultsToMap(keyword_history_results_, true, |
| 1036 did_not_accept_keyword_suggestion, &map); | 1028 did_not_accept_keyword_suggestion, &map); |
| 1037 AddHistoryResultsToMap(default_history_results_, false, | 1029 AddHistoryResultsToMap(default_history_results_, false, |
| 1038 did_not_accept_default_suggestion, &map); | 1030 did_not_accept_default_suggestion, &map); |
| 1039 | 1031 |
| 1040 AddSuggestResultsToMap(keyword_results_.suggest_results, | 1032 AddSuggestResultsToMap(keyword_results_.suggest_results, |
| 1041 keyword_results_.metadata, &map); | 1033 keyword_results_.metadata, &map); |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1319 AutocompleteResult::kLowestDefaultScore) || | 1311 AutocompleteResult::kLowestDefaultScore) || |
| 1320 !HasMultipleWords(scored_results.front().suggestion())) | 1312 !HasMultipleWords(scored_results.front().suggestion())) |
| 1321 scored_results.clear(); // Didn't detect the case above, score normally. | 1313 scored_results.clear(); // Didn't detect the case above, score normally. |
| 1322 } | 1314 } |
| 1323 if (scored_results.empty()) | 1315 if (scored_results.empty()) |
| 1324 scored_results = ScoreHistoryResults(results, prevent_inline_autocomplete, | 1316 scored_results = ScoreHistoryResults(results, prevent_inline_autocomplete, |
| 1325 input_multiple_words, input_text, | 1317 input_multiple_words, input_text, |
| 1326 is_keyword); | 1318 is_keyword); |
| 1327 for (SuggestResults::const_iterator i(scored_results.begin()); | 1319 for (SuggestResults::const_iterator i(scored_results.begin()); |
| 1328 i != scored_results.end(); ++i) { | 1320 i != scored_results.end(); ++i) { |
| 1329 AddMatchToMap(*i, input_text, std::string(), | 1321 AddMatchToMap(*i, GetInput(*i), GetTemplateURL(*i), std::string(), |
| 1330 did_not_accept_suggestion, map); | 1322 did_not_accept_suggestion, map); |
| 1331 } | 1323 } |
| 1332 UMA_HISTOGRAM_TIMES("Omnibox.SearchProvider.AddHistoryResultsTime", | 1324 UMA_HISTOGRAM_TIMES("Omnibox.SearchProvider.AddHistoryResultsTime", |
| 1333 base::TimeTicks::Now() - start_time); | 1325 base::TimeTicks::Now() - start_time); |
| 1334 } | 1326 } |
| 1335 | 1327 |
| 1336 SearchProvider::SuggestResults SearchProvider::ScoreHistoryResults( | 1328 SearchProvider::SuggestResults SearchProvider::ScoreHistoryResults( |
| 1337 const HistoryResults& results, | 1329 const HistoryResults& results, |
| 1338 bool base_prevent_inline_autocomplete, | 1330 bool base_prevent_inline_autocomplete, |
| 1339 bool input_multiple_words, | 1331 bool input_multiple_words, |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1397 last_relevance = i->relevance(); | 1389 last_relevance = i->relevance(); |
| 1398 } | 1390 } |
| 1399 | 1391 |
| 1400 return scored_results; | 1392 return scored_results; |
| 1401 } | 1393 } |
| 1402 | 1394 |
| 1403 void SearchProvider::AddSuggestResultsToMap(const SuggestResults& results, | 1395 void SearchProvider::AddSuggestResultsToMap(const SuggestResults& results, |
| 1404 const std::string& metadata, | 1396 const std::string& metadata, |
| 1405 MatchMap* map) { | 1397 MatchMap* map) { |
| 1406 for (size_t i = 0; i < results.size(); ++i) { | 1398 for (size_t i = 0; i < results.size(); ++i) { |
| 1407 const bool is_keyword = results[i].from_keyword_provider(); | 1399 const SuggestResult& result = results[i]; |
| 1408 const base::string16& input = is_keyword ? keyword_input_.text() | 1400 AddMatchToMap(result, GetInput(result), GetTemplateURL(result), |
| 1409 : input_.text(); | 1401 metadata, i, map); |
| 1410 AddMatchToMap(results[i], input, metadata, i, map); | |
| 1411 } | 1402 } |
| 1412 } | 1403 } |
| 1413 | 1404 |
| 1405 const AutocompleteInput SearchProvider::GetInput( | |
|
msw
2014/02/13 02:43:50
Could BaseSearchProvider also declare this (and Ze
Maria
2014/02/13 21:07:36
Done.
| |
| 1406 const SuggestResult& result) const { | |
| 1407 return result.from_keyword_provider() ? keyword_input_ : input_; | |
| 1408 } | |
| 1409 | |
| 1410 const TemplateURL* SearchProvider::GetTemplateURL( | |
| 1411 const SuggestResult& result) const { | |
| 1412 return result.from_keyword_provider() ? providers_.GetKeywordProviderURL() | |
| 1413 : providers_.GetDefaultProviderURL(); | |
| 1414 } | |
| 1415 | |
| 1414 int SearchProvider::GetVerbatimRelevance(bool* relevance_from_server) const { | 1416 int SearchProvider::GetVerbatimRelevance(bool* relevance_from_server) const { |
| 1415 // Use the suggested verbatim relevance score if it is non-negative (valid), | 1417 // Use the suggested verbatim relevance score if it is non-negative (valid), |
| 1416 // if inline autocomplete isn't prevented (always show verbatim on backspace), | 1418 // if inline autocomplete isn't prevented (always show verbatim on backspace), |
| 1417 // and if it won't suppress verbatim, leaving no default provider matches. | 1419 // and if it won't suppress verbatim, leaving no default provider matches. |
| 1418 // Otherwise, if the default provider returned no matches and was still able | 1420 // Otherwise, if the default provider returned no matches and was still able |
| 1419 // to suppress verbatim, the user would have no search/nav matches and may be | 1421 // to suppress verbatim, the user would have no search/nav matches and may be |
| 1420 // left unable to search using their default provider from the omnibox. | 1422 // left unable to search using their default provider from the omnibox. |
| 1421 // Check for results on each verbatim calculation, as results from older | 1423 // Check for results on each verbatim calculation, as results from older |
| 1422 // queries (on previous input) may be trimmed for failing to inline new input. | 1424 // queries (on previous input) may be trimmed for failing to inline new input. |
| 1423 bool use_server_relevance = | 1425 bool use_server_relevance = |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1512 // Don't let scores go below 0. Negative relevance scores are meaningful in | 1514 // Don't let scores go below 0. Negative relevance scores are meaningful in |
| 1513 // a different way. | 1515 // a different way. |
| 1514 int base_score; | 1516 int base_score; |
| 1515 if (is_primary_provider) | 1517 if (is_primary_provider) |
| 1516 base_score = (input_.type() == AutocompleteInput::URL) ? 750 : 1050; | 1518 base_score = (input_.type() == AutocompleteInput::URL) ? 750 : 1050; |
| 1517 else | 1519 else |
| 1518 base_score = 200; | 1520 base_score = 200; |
| 1519 return std::max(0, base_score - score_discount); | 1521 return std::max(0, base_score - score_discount); |
| 1520 } | 1522 } |
| 1521 | 1523 |
| 1522 void SearchProvider::AddMatchToMap(const SuggestResult& result, | |
| 1523 const base::string16& input_text, | |
| 1524 const std::string& metadata, | |
| 1525 int accepted_suggestion, | |
| 1526 MatchMap* map) { | |
| 1527 InstantService* instant_service = | |
| 1528 InstantServiceFactory::GetForProfile(profile_); | |
| 1529 // Android and iOS have no InstantService. | |
| 1530 const int omnibox_start_margin = instant_service ? | |
| 1531 instant_service->omnibox_start_margin() : chrome::kDisableStartMargin; | |
| 1532 | |
| 1533 const TemplateURL* template_url = result.from_keyword_provider() ? | |
| 1534 providers_.GetKeywordProviderURL() : providers_.GetDefaultProviderURL(); | |
| 1535 AutocompleteMatch match = CreateSearchSuggestion( | |
| 1536 this, input_, input_text, result, template_url, accepted_suggestion, | |
| 1537 omnibox_start_margin, | |
| 1538 !result.from_keyword_provider() || providers_.default_provider().empty()); | |
| 1539 if (!match.destination_url.is_valid()) | |
| 1540 return; | |
| 1541 match.search_terms_args->bookmark_bar_pinned = | |
| 1542 profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar); | |
| 1543 match.RecordAdditionalInfo(kRelevanceFromServerKey, | |
| 1544 result.relevance_from_server() ? kTrue : kFalse); | |
| 1545 match.RecordAdditionalInfo(kShouldPrefetchKey, | |
| 1546 result.should_prefetch() ? kTrue : kFalse); | |
| 1547 | |
| 1548 if (!result.deletion_url().empty()) { | |
| 1549 GURL url(match.destination_url.GetOrigin().Resolve(result.deletion_url())); | |
| 1550 if (url.is_valid()) { | |
| 1551 match.RecordAdditionalInfo(kDeletionUrlKey, url.spec()); | |
| 1552 match.deletable = true; | |
| 1553 } | |
| 1554 } | |
| 1555 | |
| 1556 // Metadata is needed only for prefetching queries. | |
| 1557 if (result.should_prefetch()) | |
| 1558 match.RecordAdditionalInfo(kSuggestMetadataKey, metadata); | |
| 1559 | |
| 1560 // Try to add |match| to |map|. If a match for |query_string| is already in | |
| 1561 // |map|, replace it if |match| is more relevant. | |
| 1562 // NOTE: Keep this ToLower() call in sync with url_database.cc. | |
| 1563 MatchKey match_key( | |
| 1564 std::make_pair(base::i18n::ToLower(result.suggestion()), | |
| 1565 match.search_terms_args->suggest_query_params)); | |
| 1566 const std::pair<MatchMap::iterator, bool> i( | |
| 1567 map->insert(std::make_pair(match_key, match))); | |
| 1568 | |
| 1569 bool should_prefetch = result.should_prefetch(); | |
| 1570 if (!i.second) { | |
| 1571 // NOTE: We purposefully do a direct relevance comparison here instead of | |
| 1572 // using AutocompleteMatch::MoreRelevant(), so that we'll prefer "items | |
| 1573 // added first" rather than "items alphabetically first" when the scores are | |
| 1574 // equal. The only case this matters is when a user has results with the | |
| 1575 // same score that differ only by capitalization; because the history system | |
| 1576 // returns results sorted by recency, this means we'll pick the most | |
| 1577 // recent such result even if the precision of our relevance score is too | |
| 1578 // low to distinguish the two. | |
| 1579 if (match.relevance > i.first->second.relevance) { | |
| 1580 i.first->second = match; | |
| 1581 } else if (match.keyword == i.first->second.keyword) { | |
| 1582 // Old and new matches are from the same search provider. It is okay to | |
| 1583 // record one match's prefetch data onto a different match (for the same | |
| 1584 // query string) for the following reasons: | |
| 1585 // 1. Because the suggest server only sends down a query string from which | |
| 1586 // we construct a URL, rather than sending a full URL, and because we | |
| 1587 // construct URLs from query strings in the same way every time, the URLs | |
| 1588 // for the two matches will be the same. Therefore, we won't end up | |
| 1589 // prefetching something the server didn't intend. | |
| 1590 // 2. Presumably the server sets the prefetch bit on a match it things is | |
| 1591 // sufficiently relevant that the user is likely to choose it. Surely | |
| 1592 // setting the prefetch bit on a match of even higher relevance won't | |
| 1593 // violate this assumption. | |
| 1594 should_prefetch |= ShouldPrefetch(i.first->second); | |
| 1595 i.first->second.RecordAdditionalInfo(kShouldPrefetchKey, | |
| 1596 should_prefetch ? kTrue : kFalse); | |
| 1597 if (should_prefetch) | |
| 1598 i.first->second.RecordAdditionalInfo(kSuggestMetadataKey, metadata); | |
| 1599 } | |
| 1600 } | |
| 1601 } | |
| 1602 | |
| 1603 AutocompleteMatch SearchProvider::NavigationToMatch( | 1524 AutocompleteMatch SearchProvider::NavigationToMatch( |
| 1604 const NavigationResult& navigation) { | 1525 const NavigationResult& navigation) { |
| 1605 const base::string16& input = navigation.from_keyword_provider() ? | 1526 const base::string16& input = navigation.from_keyword_provider() ? |
| 1606 keyword_input_.text() : input_.text(); | 1527 keyword_input_.text() : input_.text(); |
| 1607 AutocompleteMatch match(this, navigation.relevance(), false, | 1528 AutocompleteMatch match(this, navigation.relevance(), false, |
| 1608 AutocompleteMatchType::NAVSUGGEST); | 1529 AutocompleteMatchType::NAVSUGGEST); |
| 1609 match.destination_url = navigation.url(); | 1530 match.destination_url = navigation.url(); |
| 1610 | 1531 |
| 1611 // First look for the user's input inside the formatted url as it would be | 1532 // First look for the user's input inside the formatted url as it would be |
| 1612 // without trimming the scheme, so we can find matches at the beginning of the | 1533 // without trimming the scheme, so we can find matches at the beginning of the |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1701 it->set_relevance(max_query_relevance); | 1622 it->set_relevance(max_query_relevance); |
| 1702 it->set_relevance_from_server(relevance_from_server); | 1623 it->set_relevance_from_server(relevance_from_server); |
| 1703 } | 1624 } |
| 1704 } | 1625 } |
| 1705 | 1626 |
| 1706 void SearchProvider::UpdateDone() { | 1627 void SearchProvider::UpdateDone() { |
| 1707 // We're done when the timer isn't running, there are no suggest queries | 1628 // We're done when the timer isn't running, there are no suggest queries |
| 1708 // pending, and we're not waiting on Instant. | 1629 // pending, and we're not waiting on Instant. |
| 1709 done_ = !timer_.IsRunning() && (suggest_results_pending_ == 0); | 1630 done_ = !timer_.IsRunning() && (suggest_results_pending_ == 0); |
| 1710 } | 1631 } |
| OLD | NEW |