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

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: upload again 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 58a19c98b6bcbb4720141f66a1f0a0242b9b2706..981ad453ccc3e97947c39daf4b042501930ed16d 100644
--- a/chrome/browser/autocomplete/autocomplete_result.cc
+++ b/chrome/browser/autocomplete/autocomplete_result.cc
@@ -10,6 +10,7 @@
#include "base/logging.h"
#include "chrome/browser/autocomplete/autocomplete_input.h"
#include "chrome/browser/autocomplete/autocomplete_match.h"
+#include "chrome/browser/omnibox/omnibox_field_trial.h"
// static
const size_t AutocompleteResult::kMaxMatches = 6;
@@ -99,12 +100,24 @@ void AutocompleteResult::SortAndCull(const AutocompleteInput& input,
matches_.end());
// Sort and trim to the most relevant kMaxMatches matches.
- const size_t num_matches = std::min(kMaxMatches, matches_.size());
- std::partial_sort(matches_.begin(), matches_.begin() + num_matches,
- matches_.end(), &AutocompleteMatch::MoreRelevant);
- matches_.resize(num_matches);
+ std::sort(matches_.begin(), matches_.end(), &AutocompleteMatch::MoreRelevant);
H Fung 2013/08/06 22:03:17 Nit: Since you use begin() and end() below, maybe
Mark P 2013/08/06 22:18:06 Switched below to matches_ to be consistent with t
H Fung 2013/08/06 22:53:00 I meant that AutocompleteMatch::DestinationSortFun
Mark P 2013/08/07 00:44:31 I think you don't understand what partial_sort doe
+ if (!empty() && !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
+ // relevance legal match and shift it to the front.
+ for (AutocompleteResult::iterator it = begin() + 1; it != end(); ++it) {
+ if (it->allowed_to_be_default_match) {
+ std::rotate(matches_.begin(), it, it + 1);
+ break;
+ }
+ }
+ }
+ matches_.resize(std::min(kMaxMatches, matches_.size()));
default_match_ = begin();
+ DCHECK((default_match_ == end()) ||
H Fung 2013/08/06 22:03:17 I'm not sure, so feel free to ignore, but maybe em
Mark P 2013/08/06 22:18:06 I can't do default_match_.empty() because default_
+ default_match_->allowed_to_be_default_match);
// Set the alternate nav URL.
alternate_nav_url_ = (default_match_ == end()) ?

Powered by Google App Engine
This is Rietveld 408576698