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