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

Side by Side Diff: chrome/browser/autocomplete/autocomplete_result.cc

Issue 55413002: Don't demote top match for certain match types. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add tests, fix bugs. Created 7 years, 1 month 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/autocomplete_result.h" 5 #include "chrome/browser/autocomplete/autocomplete_result.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 Profile* profile) { 146 Profile* profile) {
147 for (ACMatches::iterator i(matches_.begin()); i != matches_.end(); ++i) 147 for (ACMatches::iterator i(matches_.begin()); i != matches_.end(); ++i)
148 i->ComputeStrippedDestinationURL(profile); 148 i->ComputeStrippedDestinationURL(profile);
149 149
150 // Remove duplicates. 150 // Remove duplicates.
151 std::sort(matches_.begin(), matches_.end(), 151 std::sort(matches_.begin(), matches_.end(),
152 &AutocompleteMatch::DestinationSortFunc); 152 &AutocompleteMatch::DestinationSortFunc);
153 matches_.erase(std::unique(matches_.begin(), matches_.end(), 153 matches_.erase(std::unique(matches_.begin(), matches_.end(),
154 &AutocompleteMatch::DestinationsEqual), 154 &AutocompleteMatch::DestinationsEqual),
155 matches_.end()); 155 matches_.end());
156 size_t max_num_matches = std::min(kMaxMatches, matches_.size());
Mark P 2013/11/04 18:47:56 Can you put this "don't demote top match under cer
H Fung 2013/11/04 19:44:08 I think that would require CompareWithDemoteByType
157
158 // Don't demote the top match if applicable.
159 OmniboxFieldTrial::UndemotableTopMatchTypes undemotable_top_types;
160 OmniboxFieldTrial::GetUndemotableTopTypes(input.current_page_classification(),
161 &undemotable_top_types);
162 const bool have_top_undemotable_match = !matches_.empty() &&
163 undemotable_top_types.find(matches_.begin()->type) !=
164 undemotable_top_types.end();
165 AutocompleteMatch top_undemotable_match;
166 if (have_top_undemotable_match) {
167 top_undemotable_match = *matches_.begin();
168 matches_.erase(matches_.begin());
169 }
156 170
157 // Sort and trim to the most relevant kMaxMatches matches. 171 // Sort and trim to the most relevant kMaxMatches matches.
158 size_t max_num_matches = std::min(kMaxMatches, matches_.size());
159 CompareWithDemoteByType comparing_object(input.current_page_classification()); 172 CompareWithDemoteByType comparing_object(input.current_page_classification());
160 std::sort(matches_.begin(), matches_.end(), comparing_object); 173 std::sort(matches_.begin(), matches_.end(), comparing_object);
174 if (have_top_undemotable_match)
175 matches_.insert(matches_.begin(), top_undemotable_match);
161 if (!matches_.empty() && !matches_.begin()->allowed_to_be_default_match && 176 if (!matches_.empty() && !matches_.begin()->allowed_to_be_default_match &&
162 OmniboxFieldTrial::ReorderForLegalDefaultMatch( 177 OmniboxFieldTrial::ReorderForLegalDefaultMatch(
163 input.current_page_classification())) { 178 input.current_page_classification())) {
164 // Top match is not allowed to be the default match. Find the most 179 // Top match is not allowed to be the default match. Find the most
165 // relevant legal match and shift it to the front. 180 // relevant legal match and shift it to the front.
166 for (AutocompleteResult::iterator it = matches_.begin() + 1; 181 for (AutocompleteResult::iterator it = matches_.begin() + 1;
167 it != matches_.end(); ++it) { 182 it != matches_.end(); ++it) {
168 if (it->allowed_to_be_default_match) { 183 if (it->allowed_to_be_default_match) {
169 std::rotate(matches_.begin(), it, it + 1); 184 std::rotate(matches_.begin(), it, it + 1);
170 break; 185 break;
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 i != old_matches.rend() && delta > 0; ++i) { 377 i != old_matches.rend() && delta > 0; ++i) {
363 if (!HasMatchByDestination(*i, new_matches)) { 378 if (!HasMatchByDestination(*i, new_matches)) {
364 AutocompleteMatch match = *i; 379 AutocompleteMatch match = *i;
365 match.relevance = std::min(max_relevance, match.relevance); 380 match.relevance = std::min(max_relevance, match.relevance);
366 match.from_previous = true; 381 match.from_previous = true;
367 AddMatch(page_classification, match); 382 AddMatch(page_classification, match);
368 delta--; 383 delta--;
369 } 384 }
370 } 385 }
371 } 386 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698