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

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: one final pass through the code Created 7 years, 5 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"
11 #include "chrome/browser/autocomplete/autocomplete_input.h" 11 #include "chrome/browser/autocomplete/autocomplete_input.h"
12 #include "chrome/browser/autocomplete/autocomplete_match.h" 12 #include "chrome/browser/autocomplete/autocomplete_match.h"
13 #include "chrome/browser/omnibox/omnibox_field_trial.h"
13 14
14 // static 15 // static
15 const size_t AutocompleteResult::kMaxMatches = 6; 16 const size_t AutocompleteResult::kMaxMatches = 6;
16 const int AutocompleteResult::kLowestDefaultScore = 1200; 17 const int AutocompleteResult::kLowestDefaultScore = 1200;
17 18
18 void AutocompleteResult::Selection::Clear() { 19 void AutocompleteResult::Selection::Clear() {
19 destination_url = GURL(); 20 destination_url = GURL();
20 provider_affinity = NULL; 21 provider_affinity = NULL;
21 is_history_what_you_typed_match = false; 22 is_history_what_you_typed_match = false;
22 } 23 }
23 24
24 AutocompleteResult::AutocompleteResult() { 25 AutocompleteResult::AutocompleteResult()
26 : reorder_for_legal_default_match_(
27 OmniboxFieldTrial::InReorderForLegalDefaultMatchGroup()) {
25 // Reserve space for the max number of matches we'll show. 28 // Reserve space for the max number of matches we'll show.
26 matches_.reserve(kMaxMatches); 29 matches_.reserve(kMaxMatches);
27 30
28 // It's probably safe to do this in the initializer list, but there's little 31 // It's probably safe to do this in the initializer list, but there's little
29 // penalty to doing it here and it ensures our object is fully constructed 32 // penalty to doing it here and it ensures our object is fully constructed
30 // before calling member functions. 33 // before calling member functions.
31 default_match_ = end(); 34 default_match_ = end();
32 } 35 }
33 36
34 AutocompleteResult::~AutocompleteResult() {} 37 AutocompleteResult::~AutocompleteResult() {}
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 std::sort(matches_.begin(), matches_.end(), 98 std::sort(matches_.begin(), matches_.end(),
96 &AutocompleteMatch::DestinationSortFunc); 99 &AutocompleteMatch::DestinationSortFunc);
97 matches_.erase(std::unique(matches_.begin(), matches_.end(), 100 matches_.erase(std::unique(matches_.begin(), matches_.end(),
98 &AutocompleteMatch::DestinationsEqual), 101 &AutocompleteMatch::DestinationsEqual),
99 matches_.end()); 102 matches_.end());
100 103
101 // Sort and trim to the most relevant kMaxMatches matches. 104 // Sort and trim to the most relevant kMaxMatches matches.
102 const size_t num_matches = std::min(kMaxMatches, matches_.size()); 105 const size_t num_matches = std::min(kMaxMatches, matches_.size());
103 std::partial_sort(matches_.begin(), matches_.begin() + num_matches, 106 std::partial_sort(matches_.begin(), matches_.begin() + num_matches,
104 matches_.end(), &AutocompleteMatch::MoreRelevant); 107 matches_.end(), &AutocompleteMatch::MoreRelevant);
108 if ((begin() != end()) && !begin()->allowed_to_be_default_match &&
Peter Kasting 2013/07/17 18:29:48 Nit: First condition should be "!empty()"
Mark P 2013/07/17 20:39:18 Done. Note that given the code below, I can remov
Peter Kasting 2013/07/17 22:12:30 I would leave these here. I think it's slightly c
Mark P 2013/07/17 23:50:45 Done.
109 reorder_for_legal_default_match_) {
110 // Top match is not allowed to be the default match. Find the most
111 // relevant legal match and shift it to the front.
112 AutocompleteResult::iterator best_legal_default_match = end();
113 for (AutocompleteResult::iterator it = begin(); it != end(); ++it) {
114 if (it->allowed_to_be_default_match &&
115 ((best_legal_default_match == end()) ||
116 AutocompleteMatch::MoreRelevant(*it, *best_legal_default_match))) {
117 best_legal_default_match = it;
118 }
119 }
120 DCHECK(best_legal_default_match != end());
Peter Kasting 2013/07/17 18:29:48 Our existing code probably violates this, so be ca
Mark P 2013/07/17 20:39:18 Yes, I know. I added the DCHECK in hope that it w
121 std::rotate(matches_.begin(), best_legal_default_match,
122 best_legal_default_match + 1);
123 }
105 matches_.resize(num_matches); 124 matches_.resize(num_matches);
106 125
107 default_match_ = begin(); 126 default_match_ = begin();
127 DCHECK((default_match_ == end()) ||
128 default_match_->allowed_to_be_default_match);
Peter Kasting 2013/07/17 18:29:48 Nit: Indent 4, not even
Mark P 2013/07/17 20:39:18 Done.
108 129
109 // Set the alternate nav URL. 130 // Set the alternate nav URL.
110 alternate_nav_url_ = (default_match_ == end()) ? 131 alternate_nav_url_ = (default_match_ == end()) ?
111 GURL() : ComputeAlternateNavUrl(input, *default_match_); 132 GURL() : ComputeAlternateNavUrl(input, *default_match_);
112 } 133 }
113 134
114 bool AutocompleteResult::HasCopiedMatches() const { 135 bool AutocompleteResult::HasCopiedMatches() const {
115 for (ACMatches::const_iterator i(begin()); i != end(); ++i) { 136 for (ACMatches::const_iterator i(begin()); i != end(); ++i) {
116 if (i->from_previous) 137 if (i->from_previous)
117 return true; 138 return true;
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 i != old_matches.rend() && delta > 0; ++i) { 269 i != old_matches.rend() && delta > 0; ++i) {
249 if (!HasMatchByDestination(*i, new_matches)) { 270 if (!HasMatchByDestination(*i, new_matches)) {
250 AutocompleteMatch match = *i; 271 AutocompleteMatch match = *i;
251 match.relevance = std::min(max_relevance, match.relevance); 272 match.relevance = std::min(max_relevance, match.relevance);
252 match.from_previous = true; 273 match.from_previous = true;
253 AddMatch(match); 274 AddMatch(match);
254 delta--; 275 delta--;
255 } 276 }
256 } 277 }
257 } 278 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698