| 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 "components/omnibox/shortcuts_provider.h" | 5 #include "components/omnibox/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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 for (ShortcutsBackend::ShortcutMap::const_iterator it = | 136 for (ShortcutsBackend::ShortcutMap::const_iterator it = |
| 137 FindFirstMatch(term_string, backend.get()); | 137 FindFirstMatch(term_string, backend.get()); |
| 138 it != backend->shortcuts_map().end() && | 138 it != backend->shortcuts_map().end() && |
| 139 base::StartsWith(it->first, term_string, true); | 139 base::StartsWith(it->first, term_string, true); |
| 140 ++it) { | 140 ++it) { |
| 141 // Don't return shortcuts with zero relevance. | 141 // Don't return shortcuts with zero relevance. |
| 142 int relevance = CalculateScore(term_string, it->second, max_relevance); | 142 int relevance = CalculateScore(term_string, it->second, max_relevance); |
| 143 if (relevance) { | 143 if (relevance) { |
| 144 matches_.push_back( | 144 matches_.push_back( |
| 145 ShortcutToACMatch(it->second, relevance, input, fixed_up_input)); | 145 ShortcutToACMatch(it->second, relevance, input, fixed_up_input)); |
| 146 matches_.back().ComputeStrippedDestinationURL(template_url_service); | 146 matches_.back().ComputeStrippedDestinationURL( |
| 147 input, client_->GetAcceptLanguages(), template_url_service); |
| 147 } | 148 } |
| 148 } | 149 } |
| 149 // Remove duplicates. Duplicates don't need to be preserved in the matches | 150 // Remove duplicates. This is important because it's common to have multiple |
| 150 // because they are only used for deletions, and shortcuts deletes matches | 151 // shortcuts pointing to the same URL, e.g., ma, mai, and mail all pointing |
| 151 // based on the URL. | 152 // to mail.google.com, so typing "m" will return them all. If we then simply |
| 153 // clamp to kMaxMatches and let the AutocompleteResult take care of |
| 154 // collapsing the duplicates, we'll effectively only be returning one match, |
| 155 // instead of several possibilities. |
| 156 // |
| 157 // Note that while removing duplicates, we don't populate a match's |
| 158 // |duplicate_matches| field--duplicates don't need to be preserved in the |
| 159 // matches because they are only used for deletions, and this provider |
| 160 // deletes matches based on the URL. |
| 152 AutocompleteResult::DedupMatchesByDestination( | 161 AutocompleteResult::DedupMatchesByDestination( |
| 153 input.current_page_classification(), false, &matches_); | 162 input.current_page_classification(), false, &matches_); |
| 154 // Find best matches. | 163 // Find best matches. |
| 155 std::partial_sort( | 164 std::partial_sort( |
| 156 matches_.begin(), | 165 matches_.begin(), |
| 157 matches_.begin() + | 166 matches_.begin() + |
| 158 std::min(AutocompleteProvider::kMaxMatches, matches_.size()), | 167 std::min(AutocompleteProvider::kMaxMatches, matches_.size()), |
| 159 matches_.end(), &AutocompleteMatch::MoreRelevant); | 168 matches_.end(), &AutocompleteMatch::MoreRelevant); |
| 160 if (matches_.size() > AutocompleteProvider::kMaxMatches) { | 169 if (matches_.size() > AutocompleteProvider::kMaxMatches) { |
| 161 matches_.erase(matches_.begin() + AutocompleteProvider::kMaxMatches, | 170 matches_.erase(matches_.begin() + AutocompleteProvider::kMaxMatches, |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 URLPrefix::GetInlineAutocompleteOffset( | 229 URLPrefix::GetInlineAutocompleteOffset( |
| 221 input.text(), fixed_up_input_text, true, match.fill_into_edit); | 230 input.text(), fixed_up_input_text, true, match.fill_into_edit); |
| 222 if (inline_autocomplete_offset != base::string16::npos) { | 231 if (inline_autocomplete_offset != base::string16::npos) { |
| 223 match.inline_autocompletion = | 232 match.inline_autocompletion = |
| 224 match.fill_into_edit.substr(inline_autocomplete_offset); | 233 match.fill_into_edit.substr(inline_autocomplete_offset); |
| 225 match.allowed_to_be_default_match = | 234 match.allowed_to_be_default_match = |
| 226 !HistoryProvider::PreventInlineAutocomplete(input) || | 235 !HistoryProvider::PreventInlineAutocomplete(input) || |
| 227 match.inline_autocompletion.empty(); | 236 match.inline_autocompletion.empty(); |
| 228 } | 237 } |
| 229 } | 238 } |
| 230 match.EnsureUWYTIsAllowedToBeDefault(input.canonicalized_url(), | 239 match.EnsureUWYTIsAllowedToBeDefault(input, |
| 240 client_->GetAcceptLanguages(), |
| 231 client_->GetTemplateURLService()); | 241 client_->GetTemplateURLService()); |
| 232 | 242 |
| 233 // 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 |
| 234 // appear in |input.text()|. | 244 // appear in |input.text()|. |
| 235 const base::string16 term_string = base::i18n::ToLower(input.text()); | 245 const base::string16 term_string = base::i18n::ToLower(input.text()); |
| 236 WordMap terms_map(CreateWordMapForString(term_string)); | 246 WordMap terms_map(CreateWordMapForString(term_string)); |
| 237 if (!terms_map.empty()) { | 247 if (!terms_map.empty()) { |
| 238 match.contents_class = ClassifyAllMatchesInString( | 248 match.contents_class = ClassifyAllMatchesInString( |
| 239 term_string, terms_map, match.contents, match.contents_class); | 249 term_string, terms_map, match.contents, match.contents_class); |
| 240 match.description_class = ClassifyAllMatchesInString( | 250 match.description_class = ClassifyAllMatchesInString( |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 const double kMaxDecaySpeedDivisor = 5.0; | 405 const double kMaxDecaySpeedDivisor = 5.0; |
| 396 const double kNumUsesPerDecaySpeedDivisorIncrement = 5.0; | 406 const double kNumUsesPerDecaySpeedDivisorIncrement = 5.0; |
| 397 double decay_divisor = std::min( | 407 double decay_divisor = std::min( |
| 398 kMaxDecaySpeedDivisor, | 408 kMaxDecaySpeedDivisor, |
| 399 (shortcut.number_of_hits + kNumUsesPerDecaySpeedDivisorIncrement - 1) / | 409 (shortcut.number_of_hits + kNumUsesPerDecaySpeedDivisorIncrement - 1) / |
| 400 kNumUsesPerDecaySpeedDivisorIncrement); | 410 kNumUsesPerDecaySpeedDivisorIncrement); |
| 401 | 411 |
| 402 return static_cast<int>((base_score / exp(decay_exponent / decay_divisor)) + | 412 return static_cast<int>((base_score / exp(decay_exponent / decay_divisor)) + |
| 403 0.5); | 413 0.5); |
| 404 } | 414 } |
| OLD | NEW |