Index: chrome/browser/autocomplete/autocomplete_result.cc |
diff --git a/chrome/browser/autocomplete/autocomplete_result.cc b/chrome/browser/autocomplete/autocomplete_result.cc |
index 0c01b3923344778c50e930e693230cfa507aa19c..8226b704aa004857ed33b5bea9d8f7a4b4f3f0a1 100644 |
--- a/chrome/browser/autocomplete/autocomplete_result.cc |
+++ b/chrome/browser/autocomplete/autocomplete_result.cc |
@@ -154,10 +154,19 @@ void AutocompleteResult::SortAndCull(const AutocompleteInput& input, |
&AutocompleteMatch::DestinationsEqual), |
matches_.end()); |
+ // Don't demote the top match if applicable. |
+ OmniboxFieldTrial::UndemotableTopMatchTypes undemotable_top_types; |
+ OmniboxFieldTrial::GetUndemotableTopTypes(input.current_page_classification(), |
+ &undemotable_top_types); |
+ const bool preserve_top_match = !matches_.empty() && |
+ (undemotable_top_types.find(matches_.begin()->type) != |
Peter Kasting
2013/11/05 04:09:55
Nit: Instead of using find(), use count() and chec
H Fung
2013/11/05 06:11:27
Done. Actually, should ContainsKey() be used inst
Peter Kasting
2013/11/05 20:00:34
From stl_util.h? I don't really know why we have
|
+ undemotable_top_types.end()); |
+ |
// 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::sort(matches_.begin(), matches_.end(), comparing_object); |
+ std::sort(preserve_top_match ? matches_.begin() + 1 : matches_.begin(), |
Peter Kasting
2013/11/05 04:09:55
Nit: Slightly briefer: matches.begin() + (preserve
H Fung
2013/11/05 06:11:27
Done.
|
+ matches_.end(), comparing_object); |
if (!matches_.empty() && !matches_.begin()->allowed_to_be_default_match && |
OmniboxFieldTrial::ReorderForLegalDefaultMatch( |
input.current_page_classification())) { |
@@ -316,6 +325,8 @@ void AutocompleteResult::AddMatch( |
DCHECK_EQ(AutocompleteMatch::SanitizeString(match.contents), match.contents); |
DCHECK_EQ(AutocompleteMatch::SanitizeString(match.description), |
match.description); |
+ // GetUndemotableTopTypes() is not used here because it's done in |
+ // SortAndCull(), and we depend on SortAndCull() to be called afterwards. |
CompareWithDemoteByType comparing_object(page_classification); |
ACMatches::iterator insertion_point = |
std::upper_bound(begin(), end(), match, comparing_object); |