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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 // Remove duplicates. 149 // Remove duplicates.
150 std::sort(matches_.begin(), matches_.end(), 150 std::sort(matches_.begin(), matches_.end(),
151 &AutocompleteMatch::DestinationSortFunc); 151 &AutocompleteMatch::DestinationSortFunc);
152 matches_.erase(std::unique(matches_.begin(), matches_.end(), 152 matches_.erase(std::unique(matches_.begin(), matches_.end(),
153 &AutocompleteMatch::DestinationsEqual), 153 &AutocompleteMatch::DestinationsEqual),
154 matches_.end()); 154 matches_.end());
155 155
156 // Sort and trim to the most relevant kMaxMatches matches. 156 // Sort and trim to the most relevant kMaxMatches matches.
157 size_t max_num_matches = std::min(kMaxMatches, matches_.size()); 157 size_t max_num_matches = std::min(kMaxMatches, matches_.size());
158 CompareWithDemoteByType comparing_object(input.current_page_classification()); 158 CompareWithDemoteByType comparing_object(input.current_page_classification());
159 std::partial_sort(matches_.begin(), matches_.begin() + max_num_matches, 159 std::sort(matches_.begin(), matches_.end(), comparing_object);
160 matches_.end(), comparing_object); 160 if (!matches_.empty() && !matches_.begin()->allowed_to_be_default_match &&
161 OmniboxFieldTrial::ReorderForLegalDefaultMatch(
162 input.current_page_classification())) {
163 // Top match is not allowed to be the default match. Find the most
164 // relevant legal match and shift it to the front.
165 for (AutocompleteResult::iterator it = matches_.begin() + 1;
166 it != matches_.end(); ++it) {
167 if (it->allowed_to_be_default_match) {
168 std::rotate(matches_.begin(), it, it + 1);
169 break;
170 }
171 }
172 }
161 // In the process of trimming, drop all matches with a demoted relevance 173 // In the process of trimming, drop all matches with a demoted relevance
162 // score of 0. 174 // score of 0.
163 size_t num_matches; 175 size_t num_matches;
164 for (num_matches = 0u; (num_matches < max_num_matches) && 176 for (num_matches = 0u; (num_matches < max_num_matches) &&
165 (comparing_object.GetDemotedRelevance(*match_at(num_matches)) > 0); 177 (comparing_object.GetDemotedRelevance(*match_at(num_matches)) > 0);
166 ++num_matches) {} 178 ++num_matches) {}
167 matches_.resize(num_matches); 179 matches_.resize(num_matches);
168 180
169 default_match_ = begin(); 181 default_match_ = matches_.begin();
182 DCHECK((default_match_ == matches_.end()) ||
msw 2013/08/10 17:32:18 nit: Use matches_.empty(), not default_match_ == m
Mark P 2013/08/11 03:22:48 I'd prefer to leave this as it is because it's mea
183 default_match_->allowed_to_be_default_match);
170 184
171 // Set the alternate nav URL. 185 // Set the alternate nav URL.
172 alternate_nav_url_ = (default_match_ == end()) ? 186 alternate_nav_url_ = (default_match_ == matches_.end()) ?
173 GURL() : ComputeAlternateNavUrl(input, *default_match_); 187 GURL() : ComputeAlternateNavUrl(input, *default_match_);
174 } 188 }
175 189
176 bool AutocompleteResult::HasCopiedMatches() const { 190 bool AutocompleteResult::HasCopiedMatches() const {
177 for (ACMatches::const_iterator i(begin()); i != end(); ++i) { 191 for (ACMatches::const_iterator i(begin()); i != end(); ++i) {
178 if (i->from_previous) 192 if (i->from_previous)
179 return true; 193 return true;
180 } 194 }
181 return false; 195 return false;
182 } 196 }
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 i != old_matches.rend() && delta > 0; ++i) { 347 i != old_matches.rend() && delta > 0; ++i) {
334 if (!HasMatchByDestination(*i, new_matches)) { 348 if (!HasMatchByDestination(*i, new_matches)) {
335 AutocompleteMatch match = *i; 349 AutocompleteMatch match = *i;
336 match.relevance = std::min(max_relevance, match.relevance); 350 match.relevance = std::min(max_relevance, match.relevance);
337 match.from_previous = true; 351 match.from_previous = true;
338 AddMatch(page_classification, match); 352 AddMatch(page_classification, match);
339 delta--; 353 delta--;
340 } 354 }
341 } 355 }
342 } 356 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698