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/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(input, |
| 156 template_url_service); | |
| 156 } | 157 } |
| 157 } | 158 } |
| 158 // Remove duplicates. Duplicates don't need to be preserved in the matches | 159 // Remove duplicates. This is important because it's common to have multiple |
| 159 // because they are only used for deletions, and shortcuts deletes matches | 160 // shortcuts pointing to the same URL, e.g., ma, mai, and mail all pointing |
| 160 // based on the URL. | 161 // to mail.google.com, so typing "m" will return them all. Note that while |
|
Peter Kasting
2015/06/09 20:36:38
Nit: I might add after "return them all" this sent
Mark P
2015/06/10 23:38:34
Done.
| |
| 162 // removing duplicates, we don't populate a match's |duplicate_matches| | |
| 163 // field--duplicates don't need to be preserved in the matches because they | |
| 164 // are only used for deletions, and shortcuts deletes matches based on the | |
|
Peter Kasting
2015/06/09 20:36:38
Nit: shortcuts -> this provider?
Mark P
2015/06/10 23:38:34
Sure.
| |
| 165 // URL. | |
| 161 AutocompleteResult::DedupMatchesByDestination( | 166 AutocompleteResult::DedupMatchesByDestination( |
| 162 input.current_page_classification(), false, &matches_); | 167 input.current_page_classification(), false, &matches_); |
| 163 // Find best matches. | 168 // Find best matches. |
| 164 std::partial_sort(matches_.begin(), | 169 std::partial_sort(matches_.begin(), |
| 165 matches_.begin() + | 170 matches_.begin() + |
| 166 std::min(AutocompleteProvider::kMaxMatches, matches_.size()), | 171 std::min(AutocompleteProvider::kMaxMatches, matches_.size()), |
| 167 matches_.end(), &AutocompleteMatch::MoreRelevant); | 172 matches_.end(), &AutocompleteMatch::MoreRelevant); |
| 168 if (matches_.size() > AutocompleteProvider::kMaxMatches) { | 173 if (matches_.size() > AutocompleteProvider::kMaxMatches) { |
| 169 matches_.erase(matches_.begin() + AutocompleteProvider::kMaxMatches, | 174 matches_.erase(matches_.begin() + AutocompleteProvider::kMaxMatches, |
| 170 matches_.end()); | 175 matches_.end()); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 229 input.text(), fixed_up_input_text, true, match.fill_into_edit); | 234 input.text(), fixed_up_input_text, true, match.fill_into_edit); |
| 230 if (inline_autocomplete_offset != base::string16::npos) { | 235 if (inline_autocomplete_offset != base::string16::npos) { |
| 231 match.inline_autocompletion = | 236 match.inline_autocompletion = |
| 232 match.fill_into_edit.substr(inline_autocomplete_offset); | 237 match.fill_into_edit.substr(inline_autocomplete_offset); |
| 233 match.allowed_to_be_default_match = | 238 match.allowed_to_be_default_match = |
| 234 !HistoryProvider::PreventInlineAutocomplete(input) || | 239 !HistoryProvider::PreventInlineAutocomplete(input) || |
| 235 match.inline_autocompletion.empty(); | 240 match.inline_autocompletion.empty(); |
| 236 } | 241 } |
| 237 } | 242 } |
| 238 match.EnsureUWYTIsAllowedToBeDefault( | 243 match.EnsureUWYTIsAllowedToBeDefault( |
| 239 input.canonicalized_url(), | 244 input, |
| 240 TemplateURLServiceFactory::GetForProfile(profile_)); | 245 TemplateURLServiceFactory::GetForProfile(profile_)); |
| 241 | 246 |
| 242 // Try to mark pieces of the contents and description as matches if they | 247 // Try to mark pieces of the contents and description as matches if they |
| 243 // appear in |input.text()|. | 248 // appear in |input.text()|. |
| 244 const base::string16 term_string = base::i18n::ToLower(input.text()); | 249 const base::string16 term_string = base::i18n::ToLower(input.text()); |
| 245 WordMap terms_map(CreateWordMapForString(term_string)); | 250 WordMap terms_map(CreateWordMapForString(term_string)); |
| 246 if (!terms_map.empty()) { | 251 if (!terms_map.empty()) { |
| 247 match.contents_class = ClassifyAllMatchesInString(term_string, terms_map, | 252 match.contents_class = ClassifyAllMatchesInString(term_string, terms_map, |
| 248 match.contents, match.contents_class); | 253 match.contents, match.contents_class); |
| 249 match.description_class = ClassifyAllMatchesInString(term_string, terms_map, | 254 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. | 406 // (1.0 / each 5 additional hits), up to a maximum of 5x as long. |
| 402 const double kMaxDecaySpeedDivisor = 5.0; | 407 const double kMaxDecaySpeedDivisor = 5.0; |
| 403 const double kNumUsesPerDecaySpeedDivisorIncrement = 5.0; | 408 const double kNumUsesPerDecaySpeedDivisorIncrement = 5.0; |
| 404 double decay_divisor = std::min(kMaxDecaySpeedDivisor, | 409 double decay_divisor = std::min(kMaxDecaySpeedDivisor, |
| 405 (shortcut.number_of_hits + kNumUsesPerDecaySpeedDivisorIncrement - 1) / | 410 (shortcut.number_of_hits + kNumUsesPerDecaySpeedDivisorIncrement - 1) / |
| 406 kNumUsesPerDecaySpeedDivisorIncrement); | 411 kNumUsesPerDecaySpeedDivisorIncrement); |
| 407 | 412 |
| 408 return static_cast<int>((base_score / exp(decay_exponent / decay_divisor)) + | 413 return static_cast<int>((base_score / exp(decay_exponent / decay_divisor)) + |
| 409 0.5); | 414 0.5); |
| 410 } | 415 } |
| OLD | NEW |