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

Unified Diff: chrome/browser/autocomplete/autocomplete_result.cc

Issue 18878007: Omnibox: Make the Controller Reorder Matches for Inlining (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/autocomplete/autocomplete_result.cc
diff --git a/chrome/browser/autocomplete/autocomplete_result.cc b/chrome/browser/autocomplete/autocomplete_result.cc
index 832be7325d22f41d776ed8319d0838d65f09b58d..95bee29ba262bada9291622c58f8f60214693482 100644
--- a/chrome/browser/autocomplete/autocomplete_result.cc
+++ b/chrome/browser/autocomplete/autocomplete_result.cc
@@ -156,8 +156,20 @@ void AutocompleteResult::SortAndCull(const AutocompleteInput& input,
// Sort and trim to the most relevant kMaxMatches matches.
size_t max_num_matches = std::min(kMaxMatches, matches_.size());
CompareWithDemoteByType comparing_object(input.current_page_classification());
- std::partial_sort(matches_.begin(), matches_.begin() + max_num_matches,
- matches_.end(), comparing_object);
+ std::sort(matches_.begin(), matches_.end(), comparing_object);
+ if (!matches_.empty() && !matches_.begin()->allowed_to_be_default_match &&
+ OmniboxFieldTrial::ReorderForLegalDefaultMatch(
+ input.current_page_classification())) {
+ // Top match is not allowed to be the default match. Find the most
+ // relevant legal match and shift it to the front.
+ for (AutocompleteResult::iterator it = matches_.begin() + 1;
+ it != matches_.end(); ++it) {
+ if (it->allowed_to_be_default_match) {
+ std::rotate(matches_.begin(), it, it + 1);
+ break;
+ }
+ }
+ }
// In the process of trimming, drop all matches with a demoted relevance
// score of 0.
size_t num_matches;
@@ -166,10 +178,12 @@ void AutocompleteResult::SortAndCull(const AutocompleteInput& input,
++num_matches) {}
matches_.resize(num_matches);
- default_match_ = begin();
+ default_match_ = matches_.begin();
+ DCHECK((default_match_ == matches_.end()) ||
+ default_match_->allowed_to_be_default_match);
// Set the alternate nav URL.
- alternate_nav_url_ = (default_match_ == end()) ?
+ alternate_nav_url_ = (default_match_ == matches_.end()) ?
GURL() : ComputeAlternateNavUrl(input, *default_match_);
}

Powered by Google App Engine
This is Rietveld 408576698