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

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: upload again 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"
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 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 i->ComputeStrippedDestinationURL(profile); 93 i->ComputeStrippedDestinationURL(profile);
93 94
94 // Remove duplicates. 95 // Remove duplicates.
95 std::sort(matches_.begin(), matches_.end(), 96 std::sort(matches_.begin(), matches_.end(),
96 &AutocompleteMatch::DestinationSortFunc); 97 &AutocompleteMatch::DestinationSortFunc);
97 matches_.erase(std::unique(matches_.begin(), matches_.end(), 98 matches_.erase(std::unique(matches_.begin(), matches_.end(),
98 &AutocompleteMatch::DestinationsEqual), 99 &AutocompleteMatch::DestinationsEqual),
99 matches_.end()); 100 matches_.end());
100 101
101 // Sort and trim to the most relevant kMaxMatches matches. 102 // Sort and trim to the most relevant kMaxMatches matches.
102 const size_t num_matches = std::min(kMaxMatches, matches_.size()); 103 std::sort(matches_.begin(), matches_.end(), &AutocompleteMatch::MoreRelevant);
H Fung 2013/08/06 22:03:17 Nit: Since you use begin() and end() below, maybe
Mark P 2013/08/06 22:18:06 Switched below to matches_ to be consistent with t
H Fung 2013/08/06 22:53:00 I meant that AutocompleteMatch::DestinationSortFun
Mark P 2013/08/07 00:44:31 I think you don't understand what partial_sort doe
103 std::partial_sort(matches_.begin(), matches_.begin() + num_matches, 104 if (!empty() && !begin()->allowed_to_be_default_match &&
104 matches_.end(), &AutocompleteMatch::MoreRelevant); 105 OmniboxFieldTrial::ReorderForLegalDefaultMatch(
105 matches_.resize(num_matches); 106 input.current_page_classification())) {
107 // Top match is not allowed to be the default match. Find the most
108 // relevance legal match and shift it to the front.
109 for (AutocompleteResult::iterator it = begin() + 1; it != end(); ++it) {
110 if (it->allowed_to_be_default_match) {
111 std::rotate(matches_.begin(), it, it + 1);
112 break;
113 }
114 }
115 }
116 matches_.resize(std::min(kMaxMatches, matches_.size()));
106 117
107 default_match_ = begin(); 118 default_match_ = begin();
119 DCHECK((default_match_ == end()) ||
H Fung 2013/08/06 22:03:17 I'm not sure, so feel free to ignore, but maybe em
Mark P 2013/08/06 22:18:06 I can't do default_match_.empty() because default_
120 default_match_->allowed_to_be_default_match);
108 121
109 // Set the alternate nav URL. 122 // Set the alternate nav URL.
110 alternate_nav_url_ = (default_match_ == end()) ? 123 alternate_nav_url_ = (default_match_ == end()) ?
111 GURL() : ComputeAlternateNavUrl(input, *default_match_); 124 GURL() : ComputeAlternateNavUrl(input, *default_match_);
112 } 125 }
113 126
114 bool AutocompleteResult::HasCopiedMatches() const { 127 bool AutocompleteResult::HasCopiedMatches() const {
115 for (ACMatches::const_iterator i(begin()); i != end(); ++i) { 128 for (ACMatches::const_iterator i(begin()); i != end(); ++i) {
116 if (i->from_previous) 129 if (i->from_previous)
117 return true; 130 return true;
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 i != old_matches.rend() && delta > 0; ++i) { 261 i != old_matches.rend() && delta > 0; ++i) {
249 if (!HasMatchByDestination(*i, new_matches)) { 262 if (!HasMatchByDestination(*i, new_matches)) {
250 AutocompleteMatch match = *i; 263 AutocompleteMatch match = *i;
251 match.relevance = std::min(max_relevance, match.relevance); 264 match.relevance = std::min(max_relevance, match.relevance);
252 match.from_previous = true; 265 match.from_previous = true;
253 AddMatch(match); 266 AddMatch(match);
254 delta--; 267 delta--;
255 } 268 }
256 } 269 }
257 } 270 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698