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" |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
127 | 127 |
128 // Sort and trim to the most relevant kMaxMatches matches. | 128 // Sort and trim to the most relevant kMaxMatches matches. |
129 const size_t num_matches = std::min(kMaxMatches, matches_.size()); | 129 const size_t num_matches = std::min(kMaxMatches, matches_.size()); |
130 std::partial_sort(matches_.begin(), matches_.begin() + num_matches, | 130 std::partial_sort(matches_.begin(), matches_.begin() + num_matches, |
131 matches_.end(), &AutocompleteMatch::MoreRelevant); | 131 matches_.end(), &AutocompleteMatch::MoreRelevant); |
132 matches_.resize(num_matches); | 132 matches_.resize(num_matches); |
133 | 133 |
134 default_match_ = begin(); | 134 default_match_ = begin(); |
135 | 135 |
136 // Set the alternate nav URL. | 136 // Set the alternate nav URL. |
137 alternate_nav_url_ = GURL(); | 137 alternate_nav_url_ = default_match_ == end() ? GURL() : |
Peter Kasting
2013/06/18 17:44:00
Nit: Wrap after '?' instead of ':'. Put parens ar
beaudoin
2013/06/18 22:37:34
Done.
| |
138 if (input.type() == AutocompleteInput::UNKNOWN && | 138 ComputeAlternateNavUrl(input, *default_match_); |
139 default_match_ != end() && | |
140 AutocompleteMatch::IsSearchType(default_match_->type) && | |
141 default_match_->transition != content::PAGE_TRANSITION_KEYWORD && | |
142 input.canonicalized_url() != default_match_->destination_url) | |
143 alternate_nav_url_ = input.canonicalized_url(); | |
144 } | 139 } |
145 | 140 |
146 bool AutocompleteResult::HasCopiedMatches() const { | 141 bool AutocompleteResult::HasCopiedMatches() const { |
147 for (ACMatches::const_iterator i(begin()); i != end(); ++i) { | 142 for (ACMatches::const_iterator i(begin()); i != end(); ++i) { |
148 if (i->from_previous) | 143 if (i->from_previous) |
149 return true; | 144 return true; |
150 } | 145 } |
151 return false; | 146 return false; |
152 } | 147 } |
153 | 148 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
201 alternate_nav_url_.Swap(&(other->alternate_nav_url_)); | 196 alternate_nav_url_.Swap(&(other->alternate_nav_url_)); |
202 } | 197 } |
203 | 198 |
204 #ifndef NDEBUG | 199 #ifndef NDEBUG |
205 void AutocompleteResult::Validate() const { | 200 void AutocompleteResult::Validate() const { |
206 for (const_iterator i(begin()); i != end(); ++i) | 201 for (const_iterator i(begin()); i != end(); ++i) |
207 i->Validate(); | 202 i->Validate(); |
208 } | 203 } |
209 #endif | 204 #endif |
210 | 205 |
206 // static | |
207 GURL AutocompleteResult::ComputeAlternateNavUrl( | |
208 const AutocompleteInput& input, | |
209 const AutocompleteMatch& match) { | |
210 return (input.type() == AutocompleteInput::UNKNOWN && | |
Peter Kasting
2013/06/18 17:44:00
Nit: Parens around binary subexpressions
beaudoin
2013/06/18 22:37:34
Done.
| |
211 AutocompleteMatch::IsSearchType(match.type) && | |
212 match.transition != content::PAGE_TRANSITION_KEYWORD && | |
213 input.canonicalized_url() != match.destination_url) ? | |
214 input.canonicalized_url() : GURL(); | |
215 } | |
216 | |
211 void AutocompleteResult::BuildProviderToMatches( | 217 void AutocompleteResult::BuildProviderToMatches( |
212 ProviderToMatches* provider_to_matches) const { | 218 ProviderToMatches* provider_to_matches) const { |
213 for (ACMatches::const_iterator i(begin()); i != end(); ++i) | 219 for (ACMatches::const_iterator i(begin()); i != end(); ++i) |
214 (*provider_to_matches)[i->provider].push_back(*i); | 220 (*provider_to_matches)[i->provider].push_back(*i); |
215 } | 221 } |
216 | 222 |
217 // static | 223 // static |
218 bool AutocompleteResult::HasMatchByDestination(const AutocompleteMatch& match, | 224 bool AutocompleteResult::HasMatchByDestination(const AutocompleteMatch& match, |
219 const ACMatches& matches) { | 225 const ACMatches& matches) { |
220 for (ACMatches::const_iterator i(matches.begin()); i != matches.end(); ++i) { | 226 for (ACMatches::const_iterator i(matches.begin()); i != matches.end(); ++i) { |
(...skipping 21 matching lines...) Expand all Loading... | |
242 i != old_matches.rend() && delta > 0; ++i) { | 248 i != old_matches.rend() && delta > 0; ++i) { |
243 if (!HasMatchByDestination(*i, new_matches)) { | 249 if (!HasMatchByDestination(*i, new_matches)) { |
244 AutocompleteMatch match = *i; | 250 AutocompleteMatch match = *i; |
245 match.relevance = std::min(max_relevance, match.relevance); | 251 match.relevance = std::min(max_relevance, match.relevance); |
246 match.from_previous = true; | 252 match.from_previous = true; |
247 AddMatch(match); | 253 AddMatch(match); |
248 delta--; | 254 delta--; |
249 } | 255 } |
250 } | 256 } |
251 } | 257 } |
OLD | NEW |