Chromium Code Reviews| 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_ = default_match_ == end() ? GURL() : | 137 alternate_nav_url_ = default_match_ == end() ? |
|
Peter Kasting
2013/06/18 23:31:19
Nit: Parens around comparison
beaudoin
2013/06/19 18:21:10
Done.
| |
| 138 ComputeAlternateNavUrl(input, *default_match_); | 138 GURL() : ComputeAlternateNavUrl(input, *default_match_); |
| 139 } | 139 } |
| 140 | 140 |
| 141 bool AutocompleteResult::HasCopiedMatches() const { | 141 bool AutocompleteResult::HasCopiedMatches() const { |
| 142 for (ACMatches::const_iterator i(begin()); i != end(); ++i) { | 142 for (ACMatches::const_iterator i(begin()); i != end(); ++i) { |
| 143 if (i->from_previous) | 143 if (i->from_previous) |
| 144 return true; | 144 return true; |
| 145 } | 145 } |
| 146 return false; | 146 return false; |
| 147 } | 147 } |
| 148 | 148 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 200 void AutocompleteResult::Validate() const { | 200 void AutocompleteResult::Validate() const { |
| 201 for (const_iterator i(begin()); i != end(); ++i) | 201 for (const_iterator i(begin()); i != end(); ++i) |
| 202 i->Validate(); | 202 i->Validate(); |
| 203 } | 203 } |
| 204 #endif | 204 #endif |
| 205 | 205 |
| 206 // static | 206 // static |
| 207 GURL AutocompleteResult::ComputeAlternateNavUrl( | 207 GURL AutocompleteResult::ComputeAlternateNavUrl( |
| 208 const AutocompleteInput& input, | 208 const AutocompleteInput& input, |
| 209 const AutocompleteMatch& match) { | 209 const AutocompleteMatch& match) { |
| 210 return (input.type() == AutocompleteInput::UNKNOWN && | 210 return ((input.type() == AutocompleteInput::UNKNOWN) && |
| 211 AutocompleteMatch::IsSearchType(match.type) && | 211 (AutocompleteMatch::IsSearchType(match.type)) && |
| 212 match.transition != content::PAGE_TRANSITION_KEYWORD && | 212 (match.transition != content::PAGE_TRANSITION_KEYWORD) && |
| 213 input.canonicalized_url() != match.destination_url) ? | 213 (input.canonicalized_url() != match.destination_url)) ? |
| 214 input.canonicalized_url() : GURL(); | 214 input.canonicalized_url() : GURL(); |
| 215 } | 215 } |
| 216 | 216 |
| 217 void AutocompleteResult::BuildProviderToMatches( | 217 void AutocompleteResult::BuildProviderToMatches( |
| 218 ProviderToMatches* provider_to_matches) const { | 218 ProviderToMatches* provider_to_matches) const { |
| 219 for (ACMatches::const_iterator i(begin()); i != end(); ++i) | 219 for (ACMatches::const_iterator i(begin()); i != end(); ++i) |
| 220 (*provider_to_matches)[i->provider].push_back(*i); | 220 (*provider_to_matches)[i->provider].push_back(*i); |
| 221 } | 221 } |
| 222 | 222 |
| 223 // static | 223 // static |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 248 i != old_matches.rend() && delta > 0; ++i) { | 248 i != old_matches.rend() && delta > 0; ++i) { |
| 249 if (!HasMatchByDestination(*i, new_matches)) { | 249 if (!HasMatchByDestination(*i, new_matches)) { |
| 250 AutocompleteMatch match = *i; | 250 AutocompleteMatch match = *i; |
| 251 match.relevance = std::min(max_relevance, match.relevance); | 251 match.relevance = std::min(max_relevance, match.relevance); |
| 252 match.from_previous = true; | 252 match.from_previous = true; |
| 253 AddMatch(match); | 253 AddMatch(match); |
| 254 delta--; | 254 delta--; |
| 255 } | 255 } |
| 256 } | 256 } |
| 257 } | 257 } |
| OLD | NEW |