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

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: 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_inlining_(OmniboxFieldTrial::InReorderForInliningGroup()) {
25 // Reserve space for the max number of matches we'll show. 27 // Reserve space for the max number of matches we'll show.
26 matches_.reserve(kMaxMatches); 28 matches_.reserve(kMaxMatches);
27 29
28 // It's probably safe to do this in the initializer list, but there's little 30 // 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 31 // penalty to doing it here and it ensures our object is fully constructed
30 // before calling member functions. 32 // before calling member functions.
31 default_match_ = end(); 33 default_match_ = end();
32 } 34 }
33 35
34 AutocompleteResult::~AutocompleteResult() {} 36 AutocompleteResult::~AutocompleteResult() {}
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 std::sort(matches_.begin(), matches_.end(), 97 std::sort(matches_.begin(), matches_.end(),
96 &AutocompleteMatch::DestinationSortFunc); 98 &AutocompleteMatch::DestinationSortFunc);
97 matches_.erase(std::unique(matches_.begin(), matches_.end(), 99 matches_.erase(std::unique(matches_.begin(), matches_.end(),
98 &AutocompleteMatch::DestinationsEqual), 100 &AutocompleteMatch::DestinationsEqual),
99 matches_.end()); 101 matches_.end());
100 102
101 // Sort and trim to the most relevant kMaxMatches matches. 103 // Sort and trim to the most relevant kMaxMatches matches.
102 const size_t num_matches = std::min(kMaxMatches, matches_.size()); 104 const size_t num_matches = std::min(kMaxMatches, matches_.size());
103 std::partial_sort(matches_.begin(), matches_.begin() + num_matches, 105 std::partial_sort(matches_.begin(), matches_.begin() + num_matches,
104 matches_.end(), &AutocompleteMatch::MoreRelevant); 106 matches_.end(), &AutocompleteMatch::MoreRelevant);
107 if ((begin()->inline_autocomplete_offset == string16::npos) &&
108 reorder_for_inlining_) {
109 // Top match is not inlineable. Find the most relevant inlineable
110 // match and shift it to the front.
111 AutocompleteResult::iterator best_inlineable_match = end();
112 for (AutocompleteResult::iterator it = begin(); it != end(); ++it) {
113 if ((it->inline_autocomplete_offset != string16::npos) &&
114 ((best_inlineable_match == end()) ||
115 AutocompleteMatch::MoreRelevant(*it, *best_inlineable_match))) {
Peter Kasting 2013/07/13 01:31:40 Seems like we don't need the MoreRelevant() check
Mark P 2013/07/17 15:45:18 I thought about this. For long inputs, the set of
Peter Kasting 2013/07/17 18:29:48 50 calls to MoreRelevant seems immaterial. Each o
Mark P 2013/07/17 20:39:18 Okay, I trust your judgement.
116 best_inlineable_match = it;
117 }
118 }
119 DCHECK(best_inlineable_match != end());
120 std::rotate(matches_.begin(), best_inlineable_match,
121 best_inlineable_match + 1);
122 }
105 matches_.resize(num_matches); 123 matches_.resize(num_matches);
106 124
107 default_match_ = begin(); 125 default_match_ = begin();
108 126
109 // Set the alternate nav URL. 127 // Set the alternate nav URL.
110 alternate_nav_url_ = (default_match_ == end()) ? 128 alternate_nav_url_ = (default_match_ == end()) ?
111 GURL() : ComputeAlternateNavUrl(input, *default_match_); 129 GURL() : ComputeAlternateNavUrl(input, *default_match_);
112 } 130 }
113 131
114 bool AutocompleteResult::HasCopiedMatches() const { 132 bool AutocompleteResult::HasCopiedMatches() const {
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 i != old_matches.rend() && delta > 0; ++i) { 266 i != old_matches.rend() && delta > 0; ++i) {
249 if (!HasMatchByDestination(*i, new_matches)) { 267 if (!HasMatchByDestination(*i, new_matches)) {
250 AutocompleteMatch match = *i; 268 AutocompleteMatch match = *i;
251 match.relevance = std::min(max_relevance, match.relevance); 269 match.relevance = std::min(max_relevance, match.relevance);
252 match.from_previous = true; 270 match.from_previous = true;
253 AddMatch(match); 271 AddMatch(match);
254 delta--; 272 delta--;
255 } 273 }
256 } 274 }
257 } 275 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698