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/shortcuts_provider.h" | 5 #include "chrome/browser/autocomplete/shortcuts_provider.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <map> | 9 #include <map> |
10 #include <vector> | 10 #include <vector> |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 const base::string16 fixed_up_input(FixupUserInput(input).second); | 145 const base::string16 fixed_up_input(FixupUserInput(input).second); |
146 for (ShortcutsBackend::ShortcutMap::const_iterator it = | 146 for (ShortcutsBackend::ShortcutMap::const_iterator it = |
147 FindFirstMatch(term_string, backend.get()); | 147 FindFirstMatch(term_string, backend.get()); |
148 it != backend->shortcuts_map().end() && | 148 it != backend->shortcuts_map().end() && |
149 StartsWith(it->first, term_string, true); ++it) { | 149 StartsWith(it->first, term_string, true); ++it) { |
150 // Don't return shortcuts with zero relevance. | 150 // Don't return shortcuts with zero relevance. |
151 int relevance = CalculateScore(term_string, it->second, max_relevance); | 151 int relevance = CalculateScore(term_string, it->second, max_relevance); |
152 if (relevance) { | 152 if (relevance) { |
153 matches_.push_back(ShortcutToACMatch(it->second, relevance, input, | 153 matches_.push_back(ShortcutToACMatch(it->second, relevance, input, |
154 fixed_up_input)); | 154 fixed_up_input)); |
155 matches_.back().ComputeStrippedDestinationURL(template_url_service); | 155 matches_.back().ComputeStrippedDestinationURL( |
| 156 input.parts().scheme.is_nonempty(), template_url_service); |
156 } | 157 } |
157 } | 158 } |
158 // Remove duplicates. Duplicates don't need to be preserved in the matches | 159 // Remove duplicates. Duplicates don't need to be preserved in the matches |
159 // because they are only used for deletions, and shortcuts deletes matches | 160 // because they are only used for deletions, and shortcuts deletes matches |
160 // based on the URL. | 161 // based on the URL. |
161 AutocompleteResult::DedupMatchesByDestination( | 162 AutocompleteResult::DedupMatchesByDestination( |
162 input.current_page_classification(), false, &matches_); | 163 input.current_page_classification(), false, &matches_); |
163 // Find best matches. | 164 // Find best matches. |
164 std::partial_sort(matches_.begin(), | 165 std::partial_sort(matches_.begin(), |
165 matches_.begin() + | 166 matches_.begin() + |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 input.text(), fixed_up_input_text, true, match.fill_into_edit); | 230 input.text(), fixed_up_input_text, true, match.fill_into_edit); |
230 if (inline_autocomplete_offset != base::string16::npos) { | 231 if (inline_autocomplete_offset != base::string16::npos) { |
231 match.inline_autocompletion = | 232 match.inline_autocompletion = |
232 match.fill_into_edit.substr(inline_autocomplete_offset); | 233 match.fill_into_edit.substr(inline_autocomplete_offset); |
233 match.allowed_to_be_default_match = | 234 match.allowed_to_be_default_match = |
234 !HistoryProvider::PreventInlineAutocomplete(input) || | 235 !HistoryProvider::PreventInlineAutocomplete(input) || |
235 match.inline_autocompletion.empty(); | 236 match.inline_autocompletion.empty(); |
236 } | 237 } |
237 } | 238 } |
238 match.EnsureUWYTIsAllowedToBeDefault( | 239 match.EnsureUWYTIsAllowedToBeDefault( |
239 input.canonicalized_url(), | 240 input.canonicalized_url(), input.parts().scheme.is_nonempty(), |
240 TemplateURLServiceFactory::GetForProfile(profile_)); | 241 TemplateURLServiceFactory::GetForProfile(profile_)); |
241 | 242 |
242 // Try to mark pieces of the contents and description as matches if they | 243 // Try to mark pieces of the contents and description as matches if they |
243 // appear in |input.text()|. | 244 // appear in |input.text()|. |
244 const base::string16 term_string = base::i18n::ToLower(input.text()); | 245 const base::string16 term_string = base::i18n::ToLower(input.text()); |
245 WordMap terms_map(CreateWordMapForString(term_string)); | 246 WordMap terms_map(CreateWordMapForString(term_string)); |
246 if (!terms_map.empty()) { | 247 if (!terms_map.empty()) { |
247 match.contents_class = ClassifyAllMatchesInString(term_string, terms_map, | 248 match.contents_class = ClassifyAllMatchesInString(term_string, terms_map, |
248 match.contents, match.contents_class); | 249 match.contents, match.contents_class); |
249 match.description_class = ClassifyAllMatchesInString(term_string, terms_map, | 250 match.description_class = ClassifyAllMatchesInString(term_string, terms_map, |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 // (1.0 / each 5 additional hits), up to a maximum of 5x as long. | 402 // (1.0 / each 5 additional hits), up to a maximum of 5x as long. |
402 const double kMaxDecaySpeedDivisor = 5.0; | 403 const double kMaxDecaySpeedDivisor = 5.0; |
403 const double kNumUsesPerDecaySpeedDivisorIncrement = 5.0; | 404 const double kNumUsesPerDecaySpeedDivisorIncrement = 5.0; |
404 double decay_divisor = std::min(kMaxDecaySpeedDivisor, | 405 double decay_divisor = std::min(kMaxDecaySpeedDivisor, |
405 (shortcut.number_of_hits + kNumUsesPerDecaySpeedDivisorIncrement - 1) / | 406 (shortcut.number_of_hits + kNumUsesPerDecaySpeedDivisorIncrement - 1) / |
406 kNumUsesPerDecaySpeedDivisorIncrement); | 407 kNumUsesPerDecaySpeedDivisorIncrement); |
407 | 408 |
408 return static_cast<int>((base_score / exp(decay_exponent / decay_divisor)) + | 409 return static_cast<int>((base_score / exp(decay_exponent / decay_divisor)) + |
409 0.5); | 410 0.5); |
410 } | 411 } |
OLD | NEW |