| 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/auto_reset.h" | |
| 11 #include "base/callback.h" | 10 #include "base/callback.h" |
| 12 #include "base/i18n/break_iterator.h" | 11 #include "base/i18n/break_iterator.h" |
| 13 #include "base/i18n/case_conversion.h" | 12 #include "base/i18n/case_conversion.h" |
| 14 #include "base/i18n/icu_string_conversions.h" | 13 #include "base/i18n/icu_string_conversions.h" |
| 15 #include "base/json/json_string_value_serializer.h" | 14 #include "base/json/json_string_value_serializer.h" |
| 16 #include "base/message_loop.h" | 15 #include "base/message_loop.h" |
| 17 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
| 18 #include "base/prefs/pref_service.h" | 17 #include "base/prefs/pref_service.h" |
| 19 #include "base/strings/string16.h" | 18 #include "base/strings/string16.h" |
| 20 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 const int SearchProvider::kDefaultProviderURLFetcherID = 1; | 222 const int SearchProvider::kDefaultProviderURLFetcherID = 1; |
| 224 const int SearchProvider::kKeywordProviderURLFetcherID = 2; | 223 const int SearchProvider::kKeywordProviderURLFetcherID = 2; |
| 225 int SearchProvider::kMinimumTimeBetweenSuggestQueriesMs = 100; | 224 int SearchProvider::kMinimumTimeBetweenSuggestQueriesMs = 100; |
| 226 | 225 |
| 227 SearchProvider::SearchProvider(AutocompleteProviderListener* listener, | 226 SearchProvider::SearchProvider(AutocompleteProviderListener* listener, |
| 228 Profile* profile) | 227 Profile* profile) |
| 229 : AutocompleteProvider(listener, profile, | 228 : AutocompleteProvider(listener, profile, |
| 230 AutocompleteProvider::TYPE_SEARCH), | 229 AutocompleteProvider::TYPE_SEARCH), |
| 231 providers_(TemplateURLServiceFactory::GetForProfile(profile)), | 230 providers_(TemplateURLServiceFactory::GetForProfile(profile)), |
| 232 suggest_results_pending_(0), | 231 suggest_results_pending_(0), |
| 233 instant_finalized_(false), | |
| 234 field_trial_triggered_(false), | 232 field_trial_triggered_(false), |
| 235 field_trial_triggered_in_session_(false), | 233 field_trial_triggered_in_session_(false), |
| 236 suppress_search_suggestions_(false), | |
| 237 omnibox_start_margin_(-1) { | 234 omnibox_start_margin_(-1) { |
| 238 } | 235 } |
| 239 | 236 |
| 240 // static | 237 // static |
| 241 AutocompleteMatch SearchProvider::CreateSearchSuggestion( | 238 AutocompleteMatch SearchProvider::CreateSearchSuggestion( |
| 242 Profile* profile, | 239 Profile* profile, |
| 243 AutocompleteProvider* autocomplete_provider, | 240 AutocompleteProvider* autocomplete_provider, |
| 244 const AutocompleteInput& input, | 241 const AutocompleteInput& input, |
| 245 const string16& query_string, | 242 const string16& query_string, |
| 246 const string16& input_text, | 243 const string16& input_text, |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 new_entry.mutable_field_trial_triggered_in_session()->Add( | 343 new_entry.mutable_field_trial_triggered_in_session()->Add( |
| 347 field_trial_hashes[i]); | 344 field_trial_hashes[i]); |
| 348 } | 345 } |
| 349 } | 346 } |
| 350 } | 347 } |
| 351 | 348 |
| 352 void SearchProvider::ResetSession() { | 349 void SearchProvider::ResetSession() { |
| 353 field_trial_triggered_in_session_ = false; | 350 field_trial_triggered_in_session_ = false; |
| 354 } | 351 } |
| 355 | 352 |
| 356 void SearchProvider::FinalizeInstantQuery(const string16& input_text, | |
| 357 const InstantSuggestion& suggestion) { | |
| 358 if (done_ || instant_finalized_) | |
| 359 return; | |
| 360 | |
| 361 instant_finalized_ = true; | |
| 362 UpdateDone(); | |
| 363 | |
| 364 if (input_text.empty()) { | |
| 365 // We only need to update the listener if we're actually done. | |
| 366 if (done_) | |
| 367 listener_->OnProviderUpdate(false); | |
| 368 return; | |
| 369 } | |
| 370 | |
| 371 default_provider_suggestion_ = suggestion; | |
| 372 | |
| 373 string16 adjusted_input_text(input_text); | |
| 374 AutocompleteInput::RemoveForcedQueryStringIfNecessary(input_.type(), | |
| 375 &adjusted_input_text); | |
| 376 | |
| 377 const string16 text = adjusted_input_text + suggestion.text; | |
| 378 bool results_updated = false; | |
| 379 // Remove any matches that are identical to |text|. We don't use the | |
| 380 // destination_url for comparison as it varies depending upon the index passed | |
| 381 // to TemplateURL::ReplaceSearchTerms. | |
| 382 for (ACMatches::iterator i = matches_.begin(); i != matches_.end();) { | |
| 383 if (((i->type == AutocompleteMatchType::SEARCH_HISTORY) || | |
| 384 (i->type == AutocompleteMatchType::SEARCH_SUGGEST)) && | |
| 385 (i->fill_into_edit == text)) { | |
| 386 i = matches_.erase(i); | |
| 387 results_updated = true; | |
| 388 } else { | |
| 389 ++i; | |
| 390 } | |
| 391 } | |
| 392 | |
| 393 // Add the new Instant suggest result. | |
| 394 if (suggestion.type == INSTANT_SUGGESTION_SEARCH) { | |
| 395 // Instant has a query suggestion. Rank it higher than SEARCH_WHAT_YOU_TYPED | |
| 396 // so that it gets autocompleted. | |
| 397 const int verbatim_relevance = GetVerbatimRelevance(); | |
| 398 int did_not_accept_default_suggestion = | |
| 399 default_results_.suggest_results.empty() ? | |
| 400 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE : | |
| 401 TemplateURLRef::NO_SUGGESTION_CHOSEN; | |
| 402 MatchMap match_map; | |
| 403 AddMatchToMap(text, adjusted_input_text, verbatim_relevance + 1, | |
| 404 AutocompleteMatchType::SEARCH_SUGGEST, | |
| 405 did_not_accept_default_suggestion, false, &match_map); | |
| 406 if (!match_map.empty()) { | |
| 407 matches_.push_back(match_map.begin()->second); | |
| 408 results_updated = true; | |
| 409 } | |
| 410 } else { | |
| 411 // Instant has a URL suggestion. Rank it higher than URL_WHAT_YOU_TYPED so | |
| 412 // it gets autocompleted; use kNonURLVerbatimRelevance rather than | |
| 413 // verbatim_relevance so that the score does not change if the user keeps | |
| 414 // typing and the input changes from type UNKNOWN to URL. | |
| 415 matches_.push_back(NavigationToMatch(NavigationResult( | |
| 416 *this, GURL(UTF16ToUTF8(suggestion.text)), string16(), false, | |
| 417 kNonURLVerbatimRelevance + 1))); | |
| 418 results_updated = true; | |
| 419 } | |
| 420 | |
| 421 if (results_updated || done_) | |
| 422 listener_->OnProviderUpdate(results_updated); | |
| 423 } | |
| 424 | |
| 425 void SearchProvider::ClearInstantSuggestion() { | |
| 426 default_provider_suggestion_ = InstantSuggestion(); | |
| 427 if (done_ || instant_finalized_) | |
| 428 return; | |
| 429 instant_finalized_ = true; | |
| 430 UpdateMatches(); | |
| 431 listener_->OnProviderUpdate(true); | |
| 432 } | |
| 433 | |
| 434 void SearchProvider::SuppressSearchSuggestions() { | |
| 435 suppress_search_suggestions_ = true; | |
| 436 } | |
| 437 | |
| 438 void SearchProvider::SetOmniboxStartMargin(int omnibox_start_margin) { | 353 void SearchProvider::SetOmniboxStartMargin(int omnibox_start_margin) { |
| 439 omnibox_start_margin_ = omnibox_start_margin; | 354 omnibox_start_margin_ = omnibox_start_margin; |
| 440 } | 355 } |
| 441 | 356 |
| 442 bool SearchProvider::IsNonInstantSearchDone() const { | |
| 443 return !timer_.IsRunning() && (suggest_results_pending_ == 0); | |
| 444 } | |
| 445 | |
| 446 SearchProvider::~SearchProvider() { | 357 SearchProvider::~SearchProvider() { |
| 447 } | 358 } |
| 448 | 359 |
| 449 // static | 360 // static |
| 450 void SearchProvider::RemoveStaleResults(const string16& input, | 361 void SearchProvider::RemoveStaleResults(const string16& input, |
| 451 int verbatim_relevance, | 362 int verbatim_relevance, |
| 452 SuggestResults* suggest_results, | 363 SuggestResults* suggest_results, |
| 453 NavigationResults* navigation_results) { | 364 NavigationResults* navigation_results) { |
| 454 DCHECK_GE(verbatim_relevance, 0); | 365 DCHECK_GE(verbatim_relevance, 0); |
| 455 // Keep pointers to the head of (the highest scoring elements of) | 366 // Keep pointers to the head of (the highest scoring elements of) |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 // differently for extension and non-extension keywords. If you | 424 // differently for extension and non-extension keywords. If you |
| 514 // make such a change, however, you should update this comment to | 425 // make such a change, however, you should update this comment to |
| 515 // describe it, so it's clear why the functions diverge. | 426 // describe it, so it's clear why the functions diverge. |
| 516 if (prefer_keyword) | 427 if (prefer_keyword) |
| 517 return 1500; | 428 return 1500; |
| 518 return (type == AutocompleteInput::QUERY) ? 1450 : 1100; | 429 return (type == AutocompleteInput::QUERY) ? 1450 : 1100; |
| 519 } | 430 } |
| 520 | 431 |
| 521 void SearchProvider::Start(const AutocompleteInput& input, | 432 void SearchProvider::Start(const AutocompleteInput& input, |
| 522 bool minimal_changes) { | 433 bool minimal_changes) { |
| 523 const bool suppress_search_suggestions = suppress_search_suggestions_; | |
| 524 suppress_search_suggestions_ = false; | |
| 525 | |
| 526 // Do our best to load the model as early as possible. This will reduce | 434 // Do our best to load the model as early as possible. This will reduce |
| 527 // odds of having the model not ready when really needed (a non-empty input). | 435 // odds of having the model not ready when really needed (a non-empty input). |
| 528 TemplateURLService* model = providers_.template_url_service(); | 436 TemplateURLService* model = providers_.template_url_service(); |
| 529 DCHECK(model); | 437 DCHECK(model); |
| 530 model->Load(); | 438 model->Load(); |
| 531 | 439 |
| 532 matches_.clear(); | 440 matches_.clear(); |
| 533 field_trial_triggered_ = false; | 441 field_trial_triggered_ = false; |
| 534 | 442 |
| 535 instant_finalized_ = | |
| 536 (input.matches_requested() != AutocompleteInput::ALL_MATCHES); | |
| 537 | |
| 538 // Can't return search/suggest results for bogus input or without a profile. | 443 // Can't return search/suggest results for bogus input or without a profile. |
| 539 if (!profile_ || (input.type() == AutocompleteInput::INVALID)) { | 444 if (!profile_ || (input.type() == AutocompleteInput::INVALID)) { |
| 540 Stop(false); | 445 Stop(false); |
| 541 return; | 446 return; |
| 542 } | 447 } |
| 543 | 448 |
| 544 keyword_input_ = input; | 449 keyword_input_ = input; |
| 545 const TemplateURL* keyword_provider = | 450 const TemplateURL* keyword_provider = |
| 546 KeywordProvider::GetSubstitutingTemplateURLForInput(model, | 451 KeywordProvider::GetSubstitutingTemplateURLForInput(model, |
| 547 &keyword_input_); | 452 &keyword_input_); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 564 } | 469 } |
| 565 | 470 |
| 566 // If we're still running an old query but have since changed the query text | 471 // If we're still running an old query but have since changed the query text |
| 567 // or the providers, abort the query. | 472 // or the providers, abort the query. |
| 568 string16 default_provider_keyword(default_provider ? | 473 string16 default_provider_keyword(default_provider ? |
| 569 default_provider->keyword() : string16()); | 474 default_provider->keyword() : string16()); |
| 570 string16 keyword_provider_keyword(keyword_provider ? | 475 string16 keyword_provider_keyword(keyword_provider ? |
| 571 keyword_provider->keyword() : string16()); | 476 keyword_provider->keyword() : string16()); |
| 572 if (!minimal_changes || | 477 if (!minimal_changes || |
| 573 !providers_.equal(default_provider_keyword, keyword_provider_keyword)) { | 478 !providers_.equal(default_provider_keyword, keyword_provider_keyword)) { |
| 574 // If Instant has not come back with a suggestion, adjust the previous | |
| 575 // suggestion if possible. If |instant_finalized| is true, we are looking | |
| 576 // for synchronous matches only, so the suggestion is cleared. | |
| 577 if (instant_finalized_) | |
| 578 default_provider_suggestion_ = InstantSuggestion(); | |
| 579 else | |
| 580 AdjustDefaultProviderSuggestion(input_.text(), input.text()); | |
| 581 | |
| 582 // Cancel any in-flight suggest requests. | 479 // Cancel any in-flight suggest requests. |
| 583 if (!done_) { | 480 if (!done_) |
| 584 // The Stop(false) call below clears |default_provider_suggestion_|, but | |
| 585 // in this instance we do not want to clear cached results, so we | |
| 586 // restore it. | |
| 587 base::AutoReset<InstantSuggestion> reset(&default_provider_suggestion_, | |
| 588 InstantSuggestion()); | |
| 589 Stop(false); | 481 Stop(false); |
| 590 } | |
| 591 } | 482 } |
| 592 | 483 |
| 593 providers_.set(default_provider_keyword, keyword_provider_keyword); | 484 providers_.set(default_provider_keyword, keyword_provider_keyword); |
| 594 | 485 |
| 595 if (input.text().empty()) { | 486 if (input.text().empty()) { |
| 596 // User typed "?" alone. Give them a placeholder result indicating what | 487 // User typed "?" alone. Give them a placeholder result indicating what |
| 597 // this syntax does. | 488 // this syntax does. |
| 598 if (default_provider) { | 489 if (default_provider) { |
| 599 AutocompleteMatch match; | 490 AutocompleteMatch match; |
| 600 match.provider = this; | 491 match.provider = this; |
| 601 match.contents.assign(l10n_util::GetStringUTF16(IDS_EMPTY_KEYWORD_VALUE)); | 492 match.contents.assign(l10n_util::GetStringUTF16(IDS_EMPTY_KEYWORD_VALUE)); |
| 602 match.contents_class.push_back( | 493 match.contents_class.push_back( |
| 603 ACMatchClassification(0, ACMatchClassification::NONE)); | 494 ACMatchClassification(0, ACMatchClassification::NONE)); |
| 604 match.keyword = providers_.default_provider(); | 495 match.keyword = providers_.default_provider(); |
| 605 matches_.push_back(match); | 496 matches_.push_back(match); |
| 606 } | 497 } |
| 607 Stop(false); | 498 Stop(false); |
| 608 return; | 499 return; |
| 609 } | 500 } |
| 610 | 501 |
| 611 input_ = input; | 502 input_ = input; |
| 612 | 503 |
| 613 if (!suppress_search_suggestions) { | 504 DoHistoryQuery(minimal_changes); |
| 614 DoHistoryQuery(minimal_changes); | 505 StartOrStopSuggestQuery(minimal_changes); |
| 615 StartOrStopSuggestQuery(minimal_changes); | |
| 616 } | |
| 617 UpdateMatches(); | 506 UpdateMatches(); |
| 618 } | 507 } |
| 619 | 508 |
| 620 void SearchProvider::Stop(bool clear_cached_results) { | 509 void SearchProvider::Stop(bool clear_cached_results) { |
| 621 StopSuggest(); | 510 StopSuggest(); |
| 622 done_ = true; | 511 done_ = true; |
| 623 default_provider_suggestion_ = InstantSuggestion(); | |
| 624 | 512 |
| 625 if (clear_cached_results) | 513 if (clear_cached_results) |
| 626 ClearAllResults(); | 514 ClearAllResults(); |
| 627 } | 515 } |
| 628 | 516 |
| 629 void SearchProvider::OnURLFetchComplete(const net::URLFetcher* source) { | 517 void SearchProvider::OnURLFetchComplete(const net::URLFetcher* source) { |
| 630 DCHECK(!done_); | 518 DCHECK(!done_); |
| 631 suggest_results_pending_--; | 519 suggest_results_pending_--; |
| 632 LogOmniboxSuggestRequest(REPLY_RECEIVED); | 520 LogOmniboxSuggestRequest(REPLY_RECEIVED); |
| 633 DCHECK_GE(suggest_results_pending_, 0); // Should never go negative. | 521 DCHECK_GE(suggest_results_pending_, 0); // Should never go negative. |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 876 RemoveStaleResults(keyword_input_.text(), GetKeywordVerbatimRelevance(), | 764 RemoveStaleResults(keyword_input_.text(), GetKeywordVerbatimRelevance(), |
| 877 &keyword_results_.suggest_results, | 765 &keyword_results_.suggest_results, |
| 878 &keyword_results_.navigation_results); | 766 &keyword_results_.navigation_results); |
| 879 } else { | 767 } else { |
| 880 // User is either in keyword mode with a blank input or out of | 768 // User is either in keyword mode with a blank input or out of |
| 881 // keyword mode entirely. | 769 // keyword mode entirely. |
| 882 keyword_results_.Clear(); | 770 keyword_results_.Clear(); |
| 883 } | 771 } |
| 884 } | 772 } |
| 885 | 773 |
| 886 void SearchProvider::AdjustDefaultProviderSuggestion( | |
| 887 const string16& previous_input, | |
| 888 const string16& current_input) { | |
| 889 if (default_provider_suggestion_.type == INSTANT_SUGGESTION_URL) { | |
| 890 // Description and relevance do not matter in the check for staleness. | |
| 891 NavigationResult result(*this, GURL(default_provider_suggestion_.text), | |
| 892 string16(), false, 100); | |
| 893 // If navigation suggestion is stale, clear |default_provider_suggestion_|. | |
| 894 if (!result.IsInlineable(current_input)) | |
| 895 default_provider_suggestion_ = InstantSuggestion(); | |
| 896 } else { | |
| 897 DCHECK(default_provider_suggestion_.type == INSTANT_SUGGESTION_SEARCH); | |
| 898 // InstantSuggestion of type SEARCH contain only the suggested text, and not | |
| 899 // the full text of the query. This looks at the current and previous input | |
| 900 // to determine if the user is typing forward, and if the new input is | |
| 901 // contained in |default_provider_suggestion_|. If so, the suggestion is | |
| 902 // adjusted and can be kept. Otherwise, it is reset. | |
| 903 if (!previous_input.empty() && | |
| 904 StartsWith(current_input, previous_input, false)) { | |
| 905 // User is typing forward; verify if new input is part of the suggestion. | |
| 906 const string16 new_text = string16(current_input, previous_input.size()); | |
| 907 if (StartsWith(default_provider_suggestion_.text, new_text, false)) { | |
| 908 // New input is a prefix to the previous suggestion, adjust the | |
| 909 // suggestion to strip the prefix. | |
| 910 default_provider_suggestion_.text.erase(0, new_text.size()); | |
| 911 return; | |
| 912 } | |
| 913 } | |
| 914 // If we are here, the search suggestion is stale; reset it. | |
| 915 default_provider_suggestion_ = InstantSuggestion(); | |
| 916 } | |
| 917 } | |
| 918 | |
| 919 void SearchProvider::ApplyCalculatedRelevance() { | 774 void SearchProvider::ApplyCalculatedRelevance() { |
| 920 ApplyCalculatedSuggestRelevance(&keyword_results_.suggest_results); | 775 ApplyCalculatedSuggestRelevance(&keyword_results_.suggest_results); |
| 921 ApplyCalculatedSuggestRelevance(&default_results_.suggest_results); | 776 ApplyCalculatedSuggestRelevance(&default_results_.suggest_results); |
| 922 ApplyCalculatedNavigationRelevance(&keyword_results_.navigation_results); | 777 ApplyCalculatedNavigationRelevance(&keyword_results_.navigation_results); |
| 923 ApplyCalculatedNavigationRelevance(&default_results_.navigation_results); | 778 ApplyCalculatedNavigationRelevance(&default_results_.navigation_results); |
| 924 default_results_.has_suggested_relevance = false; | 779 default_results_.has_suggested_relevance = false; |
| 925 keyword_results_.has_suggested_relevance = false; | 780 keyword_results_.has_suggested_relevance = false; |
| 926 default_results_.verbatim_relevance = -1; | 781 default_results_.verbatim_relevance = -1; |
| 927 keyword_results_.verbatim_relevance = -1; | 782 keyword_results_.verbatim_relevance = -1; |
| 928 } | 783 } |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1102 const int keyword_verbatim_relevance = GetKeywordVerbatimRelevance(); | 957 const int keyword_verbatim_relevance = GetKeywordVerbatimRelevance(); |
| 1103 if (keyword_verbatim_relevance > 0) { | 958 if (keyword_verbatim_relevance > 0) { |
| 1104 AddMatchToMap(keyword_input_.text(), keyword_input_.text(), | 959 AddMatchToMap(keyword_input_.text(), keyword_input_.text(), |
| 1105 keyword_verbatim_relevance, | 960 keyword_verbatim_relevance, |
| 1106 AutocompleteMatchType::SEARCH_OTHER_ENGINE, | 961 AutocompleteMatchType::SEARCH_OTHER_ENGINE, |
| 1107 did_not_accept_keyword_suggestion, true, &map); | 962 did_not_accept_keyword_suggestion, true, &map); |
| 1108 } | 963 } |
| 1109 } | 964 } |
| 1110 } | 965 } |
| 1111 const size_t verbatim_matches_size = map.size(); | 966 const size_t verbatim_matches_size = map.size(); |
| 1112 if (!default_provider_suggestion_.text.empty() && | |
| 1113 default_provider_suggestion_.type == INSTANT_SUGGESTION_SEARCH && | |
| 1114 !input_.prevent_inline_autocomplete()) | |
| 1115 AddMatchToMap(input_.text() + default_provider_suggestion_.text, | |
| 1116 input_.text(), verbatim_relevance + 1, | |
| 1117 AutocompleteMatchType::SEARCH_SUGGEST, | |
| 1118 did_not_accept_default_suggestion, false, &map); | |
| 1119 | |
| 1120 AddHistoryResultsToMap(keyword_history_results_, true, | 967 AddHistoryResultsToMap(keyword_history_results_, true, |
| 1121 did_not_accept_keyword_suggestion, &map); | 968 did_not_accept_keyword_suggestion, &map); |
| 1122 AddHistoryResultsToMap(default_history_results_, false, | 969 AddHistoryResultsToMap(default_history_results_, false, |
| 1123 did_not_accept_default_suggestion, &map); | 970 did_not_accept_default_suggestion, &map); |
| 1124 | 971 |
| 1125 AddSuggestResultsToMap(keyword_results_.suggest_results, &map); | 972 AddSuggestResultsToMap(keyword_results_.suggest_results, &map); |
| 1126 AddSuggestResultsToMap(default_results_.suggest_results, &map); | 973 AddSuggestResultsToMap(default_results_.suggest_results, &map); |
| 1127 | 974 |
| 1128 // Now add the most relevant matches from the map to |matches_|. | 975 // Now add the most relevant matches from the map to |matches_|. |
| 1129 matches_.clear(); | 976 matches_.clear(); |
| 1130 for (MatchMap::const_iterator i(map.begin()); i != map.end(); ++i) | 977 for (MatchMap::const_iterator i(map.begin()); i != map.end(); ++i) |
| 1131 matches_.push_back(i->second); | 978 matches_.push_back(i->second); |
| 1132 | 979 |
| 1133 if (!default_provider_suggestion_.text.empty() && | |
| 1134 default_provider_suggestion_.type == INSTANT_SUGGESTION_URL && | |
| 1135 !input_.prevent_inline_autocomplete()) { | |
| 1136 // See comment in FinalizeInstantQuery() for why we don't use | |
| 1137 // |verbatim_relevance| here. | |
| 1138 matches_.push_back(NavigationToMatch(NavigationResult( | |
| 1139 *this, GURL(UTF16ToUTF8(default_provider_suggestion_.text)), string16(), | |
| 1140 false, kNonURLVerbatimRelevance + 1))); | |
| 1141 } | |
| 1142 AddNavigationResultsToMatches(keyword_results_.navigation_results); | 980 AddNavigationResultsToMatches(keyword_results_.navigation_results); |
| 1143 AddNavigationResultsToMatches(default_results_.navigation_results); | 981 AddNavigationResultsToMatches(default_results_.navigation_results); |
| 1144 | 982 |
| 1145 // Allow additional match(es) for verbatim results if present. | 983 // Allow additional match(es) for verbatim results if present. |
| 1146 const size_t max_total_matches = kMaxMatches + verbatim_matches_size; | 984 const size_t max_total_matches = kMaxMatches + verbatim_matches_size; |
| 1147 std::partial_sort(matches_.begin(), | 985 std::partial_sort(matches_.begin(), |
| 1148 matches_.begin() + std::min(max_total_matches, matches_.size()), | 986 matches_.begin() + std::min(max_total_matches, matches_.size()), |
| 1149 matches_.end(), &AutocompleteMatch::MoreRelevant); | 987 matches_.end(), &AutocompleteMatch::MoreRelevant); |
| 1150 | 988 |
| 1151 if (matches_.size() > max_total_matches) | 989 if (matches_.size() > max_total_matches) |
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1613 if (it->relevance() < max_query_relevance) | 1451 if (it->relevance() < max_query_relevance) |
| 1614 return; | 1452 return; |
| 1615 max_query_relevance = std::max(max_query_relevance - 1, 0); | 1453 max_query_relevance = std::max(max_query_relevance - 1, 0); |
| 1616 it->set_relevance(max_query_relevance); | 1454 it->set_relevance(max_query_relevance); |
| 1617 } | 1455 } |
| 1618 } | 1456 } |
| 1619 | 1457 |
| 1620 void SearchProvider::UpdateDone() { | 1458 void SearchProvider::UpdateDone() { |
| 1621 // We're done when the timer isn't running, there are no suggest queries | 1459 // We're done when the timer isn't running, there are no suggest queries |
| 1622 // pending, and we're not waiting on Instant. | 1460 // pending, and we're not waiting on Instant. |
| 1623 done_ = IsNonInstantSearchDone() && | 1461 done_ = !timer_.IsRunning() && (suggest_results_pending_ == 0); |
| 1624 (instant_finalized_ || !chrome::IsInstantEnabled(profile_)); | |
| 1625 } | 1462 } |
| OLD | NEW |