| 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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 matches_.reserve(kMaxMatches); | 125 matches_.reserve(kMaxMatches); |
| 126 | 126 |
| 127 // It's probably safe to do this in the initializer list, but there's little | 127 // It's probably safe to do this in the initializer list, but there's little |
| 128 // penalty to doing it here and it ensures our object is fully constructed | 128 // penalty to doing it here and it ensures our object is fully constructed |
| 129 // before calling member functions. | 129 // before calling member functions. |
| 130 default_match_ = end(); | 130 default_match_ = end(); |
| 131 } | 131 } |
| 132 | 132 |
| 133 AutocompleteResult::~AutocompleteResult() {} | 133 AutocompleteResult::~AutocompleteResult() {} |
| 134 | 134 |
| 135 void AutocompleteResult::CopyOldMatches(const AutocompleteInput& input, | 135 void AutocompleteResult::CopyOldMatches( |
| 136 const AutocompleteResult& old_matches, | 136 const AutocompleteInput& input, |
| 137 Profile* profile) { | 137 const AutocompleteResult& old_matches, |
| 138 TemplateURLService* template_url_service) { |
| 138 if (old_matches.empty()) | 139 if (old_matches.empty()) |
| 139 return; | 140 return; |
| 140 | 141 |
| 141 if (empty()) { | 142 if (empty()) { |
| 142 // If we've got no matches we can copy everything from the last result. | 143 // If we've got no matches we can copy everything from the last result. |
| 143 CopyFrom(old_matches); | 144 CopyFrom(old_matches); |
| 144 for (ACMatches::iterator i(begin()); i != end(); ++i) | 145 for (ACMatches::iterator i(begin()); i != end(); ++i) |
| 145 i->from_previous = true; | 146 i->from_previous = true; |
| 146 return; | 147 return; |
| 147 } | 148 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 163 // anything permanently. | 164 // anything permanently. |
| 164 ProviderToMatches matches_per_provider, old_matches_per_provider; | 165 ProviderToMatches matches_per_provider, old_matches_per_provider; |
| 165 BuildProviderToMatches(&matches_per_provider); | 166 BuildProviderToMatches(&matches_per_provider); |
| 166 old_matches.BuildProviderToMatches(&old_matches_per_provider); | 167 old_matches.BuildProviderToMatches(&old_matches_per_provider); |
| 167 for (ProviderToMatches::const_iterator i(old_matches_per_provider.begin()); | 168 for (ProviderToMatches::const_iterator i(old_matches_per_provider.begin()); |
| 168 i != old_matches_per_provider.end(); ++i) { | 169 i != old_matches_per_provider.end(); ++i) { |
| 169 MergeMatchesByProvider(input.current_page_classification(), | 170 MergeMatchesByProvider(input.current_page_classification(), |
| 170 i->second, matches_per_provider[i->first]); | 171 i->second, matches_per_provider[i->first]); |
| 171 } | 172 } |
| 172 | 173 |
| 173 SortAndCull(input, profile); | 174 SortAndCull(input, template_url_service); |
| 174 } | 175 } |
| 175 | 176 |
| 176 void AutocompleteResult::AppendMatches(const ACMatches& matches) { | 177 void AutocompleteResult::AppendMatches(const ACMatches& matches) { |
| 177 #ifndef NDEBUG | 178 #ifndef NDEBUG |
| 178 for (ACMatches::const_iterator i(matches.begin()); i != matches.end(); ++i) { | 179 for (ACMatches::const_iterator i(matches.begin()); i != matches.end(); ++i) { |
| 179 DCHECK_EQ(AutocompleteMatch::SanitizeString(i->contents), i->contents); | 180 DCHECK_EQ(AutocompleteMatch::SanitizeString(i->contents), i->contents); |
| 180 DCHECK_EQ(AutocompleteMatch::SanitizeString(i->description), | 181 DCHECK_EQ(AutocompleteMatch::SanitizeString(i->description), |
| 181 i->description); | 182 i->description); |
| 182 } | 183 } |
| 183 #endif | 184 #endif |
| 184 std::copy(matches.begin(), matches.end(), std::back_inserter(matches_)); | 185 std::copy(matches.begin(), matches.end(), std::back_inserter(matches_)); |
| 185 default_match_ = end(); | 186 default_match_ = end(); |
| 186 alternate_nav_url_ = GURL(); | 187 alternate_nav_url_ = GURL(); |
| 187 } | 188 } |
| 188 | 189 |
| 189 void AutocompleteResult::SortAndCull(const AutocompleteInput& input, | 190 void AutocompleteResult::SortAndCull( |
| 190 Profile* profile) { | 191 const AutocompleteInput& input, |
| 192 TemplateURLService* template_url_service) { |
| 191 for (ACMatches::iterator i(matches_.begin()); i != matches_.end(); ++i) | 193 for (ACMatches::iterator i(matches_.begin()); i != matches_.end(); ++i) |
| 192 i->ComputeStrippedDestinationURL(profile); | 194 i->ComputeStrippedDestinationURL(template_url_service); |
| 193 | 195 |
| 194 DedupMatchesByDestination(input.current_page_classification(), true, | 196 DedupMatchesByDestination(input.current_page_classification(), true, |
| 195 &matches_); | 197 &matches_); |
| 196 | 198 |
| 197 // If the result set has at least one legal default match without an inline | 199 // If the result set has at least one legal default match without an inline |
| 198 // autocompletion, then in the disable inlining experiment it will be okay | 200 // autocompletion, then in the disable inlining experiment it will be okay |
| 199 // to demote all matches with inline autocompletions. On the other hand, if | 201 // to demote all matches with inline autocompletions. On the other hand, if |
| 200 // the experiment is active but there is no legal match without an inline | 202 // the experiment is active but there is no legal match without an inline |
| 201 // autocompletion, then we'll pretend the experiment is not active and not | 203 // autocompletion, then we'll pretend the experiment is not active and not |
| 202 // demote the matches with an inline autocompletion. In other words, an | 204 // demote the matches with an inline autocompletion. In other words, an |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 i != old_matches.rend() && delta > 0; ++i) { | 447 i != old_matches.rend() && delta > 0; ++i) { |
| 446 if (!HasMatchByDestination(*i, new_matches)) { | 448 if (!HasMatchByDestination(*i, new_matches)) { |
| 447 AutocompleteMatch match = *i; | 449 AutocompleteMatch match = *i; |
| 448 match.relevance = std::min(max_relevance, match.relevance); | 450 match.relevance = std::min(max_relevance, match.relevance); |
| 449 match.from_previous = true; | 451 match.from_previous = true; |
| 450 matches_.push_back(match); | 452 matches_.push_back(match); |
| 451 delta--; | 453 delta--; |
| 452 } | 454 } |
| 453 } | 455 } |
| 454 } | 456 } |
| OLD | NEW |