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..111de79b4b7ae86e11da3d639910b2dc57d59e90 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; |
@@ -21,7 +22,9 @@ void AutocompleteResult::Selection::Clear() { |
is_history_what_you_typed_match = false; |
} |
-AutocompleteResult::AutocompleteResult() { |
+AutocompleteResult::AutocompleteResult() |
+ : reorder_for_legal_default_match_( |
+ OmniboxFieldTrial::InReorderForLegalDefaultMatchGroup()) { |
// Reserve space for the max number of matches we'll show. |
matches_.reserve(kMaxMatches); |
@@ -99,12 +102,23 @@ 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); |
+ if (!empty() && !begin()->allowed_to_be_default_match && |
+ reorder_for_legal_default_match_) { |
+ // Top match is not allowed to be the default match. Find the most |
msw
2013/07/18 06:23:57
I find it odd that this simply checks the flag to
Peter Kasting
2013/07/18 17:35:28
It's basically impossible to enforce this correctl
msw
2013/07/18 17:46:53
I disagree, I suspect the problem is hard, but sho
Peter Kasting
2013/07/18 17:51:54
I don't know what this means.
msw
2013/07/18 18:12:11
We check for and trim schemes and www. prefixes el
|
+ // 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); |
msw
2013/07/18 06:23:57
Why rotate instead of just moving the new default
Peter Kasting
2013/07/18 17:35:28
This rotate command _does_ just move the default m
msw
2013/07/18 17:46:53
afaict this will modify the matches preceding |it|
Peter Kasting
2013/07/18 17:51:54
Yes, which is precisely the definition of "move c
msw
2013/07/18 18:12:11
Hahaha, *face-palm*. I'll admit at first I was thi
|
+ break; |
+ } |
+ } |
+ } |
+ matches_.resize(std::min(kMaxMatches, matches_.size())); |
default_match_ = begin(); |
+ DCHECK((default_match_ == end()) || |
+ default_match_->allowed_to_be_default_match); |
msw
2013/07/18 06:23:57
Won't this fail if the user is not in the experime
Peter Kasting
2013/07/18 17:35:28
Yes.
Mark P
2013/07/21 20:31:05
Precisely: I want this to fail if the user is not
|
// Set the alternate nav URL. |
alternate_nav_url_ = (default_match_ == end()) ? |