OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/omnibox/browser/autocomplete_result.h" | 5 #include "components/omnibox/browser/autocomplete_result.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <iterator> | 8 #include <iterator> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 // It's probably safe to do this in the initializer list, but there's little | 116 // It's probably safe to do this in the initializer list, but there's little |
117 // penalty to doing it here and it ensures our object is fully constructed | 117 // penalty to doing it here and it ensures our object is fully constructed |
118 // before calling member functions. | 118 // before calling member functions. |
119 default_match_ = end(); | 119 default_match_ = end(); |
120 } | 120 } |
121 | 121 |
122 AutocompleteResult::~AutocompleteResult() {} | 122 AutocompleteResult::~AutocompleteResult() {} |
123 | 123 |
124 void AutocompleteResult::CopyOldMatches( | 124 void AutocompleteResult::CopyOldMatches( |
125 const AutocompleteInput& input, | 125 const AutocompleteInput& input, |
126 const std::string& languages, | |
127 const AutocompleteResult& old_matches, | 126 const AutocompleteResult& old_matches, |
128 TemplateURLService* template_url_service) { | 127 TemplateURLService* template_url_service) { |
129 if (old_matches.empty()) | 128 if (old_matches.empty()) |
130 return; | 129 return; |
131 | 130 |
132 if (empty()) { | 131 if (empty()) { |
133 // If we've got no matches we can copy everything from the last result. | 132 // If we've got no matches we can copy everything from the last result. |
134 CopyFrom(old_matches); | 133 CopyFrom(old_matches); |
135 for (ACMatches::iterator i(begin()); i != end(); ++i) | 134 for (ACMatches::iterator i(begin()); i != end(); ++i) |
136 i->from_previous = true; | 135 i->from_previous = true; |
(...skipping 17 matching lines...) Expand all Loading... |
154 // anything permanently. | 153 // anything permanently. |
155 ProviderToMatches matches_per_provider, old_matches_per_provider; | 154 ProviderToMatches matches_per_provider, old_matches_per_provider; |
156 BuildProviderToMatches(&matches_per_provider); | 155 BuildProviderToMatches(&matches_per_provider); |
157 old_matches.BuildProviderToMatches(&old_matches_per_provider); | 156 old_matches.BuildProviderToMatches(&old_matches_per_provider); |
158 for (ProviderToMatches::const_iterator i(old_matches_per_provider.begin()); | 157 for (ProviderToMatches::const_iterator i(old_matches_per_provider.begin()); |
159 i != old_matches_per_provider.end(); ++i) { | 158 i != old_matches_per_provider.end(); ++i) { |
160 MergeMatchesByProvider(input.current_page_classification(), | 159 MergeMatchesByProvider(input.current_page_classification(), |
161 i->second, matches_per_provider[i->first]); | 160 i->second, matches_per_provider[i->first]); |
162 } | 161 } |
163 | 162 |
164 SortAndCull(input, languages, template_url_service); | 163 SortAndCull(input, template_url_service); |
165 } | 164 } |
166 | 165 |
167 void AutocompleteResult::AppendMatches(const AutocompleteInput& input, | 166 void AutocompleteResult::AppendMatches(const AutocompleteInput& input, |
168 const ACMatches& matches) { | 167 const ACMatches& matches) { |
169 for (const auto& i : matches) { | 168 for (const auto& i : matches) { |
170 #ifndef NDEBUG | 169 #ifndef NDEBUG |
171 DCHECK_EQ(AutocompleteMatch::SanitizeString(i.contents), i.contents); | 170 DCHECK_EQ(AutocompleteMatch::SanitizeString(i.contents), i.contents); |
172 DCHECK_EQ(AutocompleteMatch::SanitizeString(i.description), | 171 DCHECK_EQ(AutocompleteMatch::SanitizeString(i.description), |
173 i.description); | 172 i.description); |
174 #endif | 173 #endif |
(...skipping 22 matching lines...) Expand all Loading... |
197 } | 196 } |
198 matches_.back().swap_contents_and_description = emphasize; | 197 matches_.back().swap_contents_and_description = emphasize; |
199 } | 198 } |
200 } | 199 } |
201 default_match_ = end(); | 200 default_match_ = end(); |
202 alternate_nav_url_ = GURL(); | 201 alternate_nav_url_ = GURL(); |
203 } | 202 } |
204 | 203 |
205 void AutocompleteResult::SortAndCull( | 204 void AutocompleteResult::SortAndCull( |
206 const AutocompleteInput& input, | 205 const AutocompleteInput& input, |
207 const std::string& languages, | |
208 TemplateURLService* template_url_service) { | 206 TemplateURLService* template_url_service) { |
209 for (ACMatches::iterator i(matches_.begin()); i != matches_.end(); ++i) | 207 for (ACMatches::iterator i(matches_.begin()); i != matches_.end(); ++i) |
210 i->ComputeStrippedDestinationURL(input, languages, template_url_service); | 208 i->ComputeStrippedDestinationURL(input, template_url_service); |
211 | 209 |
212 DedupMatchesByDestination(input.current_page_classification(), true, | 210 DedupMatchesByDestination(input.current_page_classification(), true, |
213 &matches_); | 211 &matches_); |
214 | 212 |
215 // Sort and trim to the most relevant kMaxMatches matches. | 213 // Sort and trim to the most relevant kMaxMatches matches. |
216 size_t max_num_matches = std::min(kMaxMatches, matches_.size()); | 214 size_t max_num_matches = std::min(kMaxMatches, matches_.size()); |
217 CompareWithDemoteByType comparing_object(input.current_page_classification()); | 215 CompareWithDemoteByType comparing_object(input.current_page_classification()); |
218 std::sort(matches_.begin(), matches_.end(), comparing_object); | 216 std::sort(matches_.begin(), matches_.end(), comparing_object); |
219 if (!matches_.empty() && !matches_.begin()->allowed_to_be_default_match) { | 217 if (!matches_.empty() && !matches_.begin()->allowed_to_be_default_match) { |
220 // Top match is not allowed to be the default match. Find the most | 218 // Top match is not allowed to be the default match. Find the most |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 i != old_matches.rend() && delta > 0; ++i) { | 462 i != old_matches.rend() && delta > 0; ++i) { |
465 if (!HasMatchByDestination(*i, new_matches)) { | 463 if (!HasMatchByDestination(*i, new_matches)) { |
466 AutocompleteMatch match = *i; | 464 AutocompleteMatch match = *i; |
467 match.relevance = std::min(max_relevance, match.relevance); | 465 match.relevance = std::min(max_relevance, match.relevance); |
468 match.from_previous = true; | 466 match.from_previous = true; |
469 matches_.push_back(match); | 467 matches_.push_back(match); |
470 delta--; | 468 delta--; |
471 } | 469 } |
472 } | 470 } |
473 } | 471 } |
OLD | NEW |