OLD | NEW |
---|---|
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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 i->ComputeStrippedDestinationURL(profile); | 95 i->ComputeStrippedDestinationURL(profile); |
93 | 96 |
94 // Remove duplicates. | 97 // Remove duplicates. |
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 std::sort(matches_.begin(), matches_.end(), &AutocompleteMatch::MoreRelevant); |
103 std::partial_sort(matches_.begin(), matches_.begin() + num_matches, | 106 if (!empty() && !begin()->allowed_to_be_default_match && |
104 matches_.end(), &AutocompleteMatch::MoreRelevant); | 107 reorder_for_legal_default_match_) { |
105 matches_.resize(num_matches); | 108 // Top match is not allowed to be the default match. Find the most |
msw
2013/07/18 06:23:57
I find it odd that this simply checks the flag to
Peter Kasting
2013/07/18 17:35:28
It's basically impossible to enforce this correctl
msw
2013/07/18 17:46:53
I disagree, I suspect the problem is hard, but sho
Peter Kasting
2013/07/18 17:51:54
I don't know what this means.
msw
2013/07/18 18:12:11
We check for and trim schemes and www. prefixes el
| |
109 // relevance legal match and shift it to the front. | |
110 for (AutocompleteResult::iterator it = begin() + 1; it != end(); ++it) { | |
111 if (it->allowed_to_be_default_match) { | |
112 std::rotate(matches_.begin(), it, it + 1); | |
msw
2013/07/18 06:23:57
Why rotate instead of just moving the new default
Peter Kasting
2013/07/18 17:35:28
This rotate command _does_ just move the default m
msw
2013/07/18 17:46:53
afaict this will modify the matches preceding |it|
Peter Kasting
2013/07/18 17:51:54
Yes, which is precisely the definition of "move c
msw
2013/07/18 18:12:11
Hahaha, *face-palm*. I'll admit at first I was thi
| |
113 break; | |
114 } | |
115 } | |
116 } | |
117 matches_.resize(std::min(kMaxMatches, matches_.size())); | |
106 | 118 |
107 default_match_ = begin(); | 119 default_match_ = begin(); |
120 DCHECK((default_match_ == end()) || | |
121 default_match_->allowed_to_be_default_match); | |
msw
2013/07/18 06:23:57
Won't this fail if the user is not in the experime
Peter Kasting
2013/07/18 17:35:28
Yes.
Mark P
2013/07/21 20:31:05
Precisely: I want this to fail if the user is not
| |
108 | 122 |
109 // Set the alternate nav URL. | 123 // Set the alternate nav URL. |
110 alternate_nav_url_ = (default_match_ == end()) ? | 124 alternate_nav_url_ = (default_match_ == end()) ? |
111 GURL() : ComputeAlternateNavUrl(input, *default_match_); | 125 GURL() : ComputeAlternateNavUrl(input, *default_match_); |
112 } | 126 } |
113 | 127 |
114 bool AutocompleteResult::HasCopiedMatches() const { | 128 bool AutocompleteResult::HasCopiedMatches() const { |
115 for (ACMatches::const_iterator i(begin()); i != end(); ++i) { | 129 for (ACMatches::const_iterator i(begin()); i != end(); ++i) { |
116 if (i->from_previous) | 130 if (i->from_previous) |
117 return true; | 131 return true; |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
248 i != old_matches.rend() && delta > 0; ++i) { | 262 i != old_matches.rend() && delta > 0; ++i) { |
249 if (!HasMatchByDestination(*i, new_matches)) { | 263 if (!HasMatchByDestination(*i, new_matches)) { |
250 AutocompleteMatch match = *i; | 264 AutocompleteMatch match = *i; |
251 match.relevance = std::min(max_relevance, match.relevance); | 265 match.relevance = std::min(max_relevance, match.relevance); |
252 match.from_previous = true; | 266 match.from_previous = true; |
253 AddMatch(match); | 267 AddMatch(match); |
254 delta--; | 268 delta--; |
255 } | 269 } |
256 } | 270 } |
257 } | 271 } |
OLD | NEW |