Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(461)

Side by Side Diff: chrome/browser/autocomplete/shortcuts_provider.cc

Issue 1098843004: Omnibox - Do Not Allow HTTP/HTTPS Equivalence if User Explicitly Entered A Scheme (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: forgot string implementation Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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. If we then simply
162 // clamp to kMaxMatches and let the AutocompleteResult take care of
163 // collapsing the duplicates, we'll effectively only be returning one match,
164 // instead of several possibilities.
165 //
166 // Note that while removing duplicates, we don't populate a match's
167 // |duplicate_matches| field--duplicates don't need to be preserved in the
168 // matches because they are only used for deletions, and this provider
169 // deletes matches based on the URL.
161 AutocompleteResult::DedupMatchesByDestination( 170 AutocompleteResult::DedupMatchesByDestination(
162 input.current_page_classification(), false, &matches_); 171 input.current_page_classification(), false, &matches_);
163 // Find best matches. 172 // Find best matches.
164 std::partial_sort(matches_.begin(), 173 std::partial_sort(matches_.begin(),
165 matches_.begin() + 174 matches_.begin() +
166 std::min(AutocompleteProvider::kMaxMatches, matches_.size()), 175 std::min(AutocompleteProvider::kMaxMatches, matches_.size()),
167 matches_.end(), &AutocompleteMatch::MoreRelevant); 176 matches_.end(), &AutocompleteMatch::MoreRelevant);
168 if (matches_.size() > AutocompleteProvider::kMaxMatches) { 177 if (matches_.size() > AutocompleteProvider::kMaxMatches) {
169 matches_.erase(matches_.begin() + AutocompleteProvider::kMaxMatches, 178 matches_.erase(matches_.begin() + AutocompleteProvider::kMaxMatches,
170 matches_.end()); 179 matches_.end());
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 input.text(), fixed_up_input_text, true, match.fill_into_edit); 238 input.text(), fixed_up_input_text, true, match.fill_into_edit);
230 if (inline_autocomplete_offset != base::string16::npos) { 239 if (inline_autocomplete_offset != base::string16::npos) {
231 match.inline_autocompletion = 240 match.inline_autocompletion =
232 match.fill_into_edit.substr(inline_autocomplete_offset); 241 match.fill_into_edit.substr(inline_autocomplete_offset);
233 match.allowed_to_be_default_match = 242 match.allowed_to_be_default_match =
234 !HistoryProvider::PreventInlineAutocomplete(input) || 243 !HistoryProvider::PreventInlineAutocomplete(input) ||
235 match.inline_autocompletion.empty(); 244 match.inline_autocompletion.empty();
236 } 245 }
237 } 246 }
238 match.EnsureUWYTIsAllowedToBeDefault( 247 match.EnsureUWYTIsAllowedToBeDefault(
239 input.canonicalized_url(), 248 input,
240 TemplateURLServiceFactory::GetForProfile(profile_)); 249 TemplateURLServiceFactory::GetForProfile(profile_));
241 250
242 // Try to mark pieces of the contents and description as matches if they 251 // Try to mark pieces of the contents and description as matches if they
243 // appear in |input.text()|. 252 // appear in |input.text()|.
244 const base::string16 term_string = base::i18n::ToLower(input.text()); 253 const base::string16 term_string = base::i18n::ToLower(input.text());
245 WordMap terms_map(CreateWordMapForString(term_string)); 254 WordMap terms_map(CreateWordMapForString(term_string));
246 if (!terms_map.empty()) { 255 if (!terms_map.empty()) {
247 match.contents_class = ClassifyAllMatchesInString(term_string, terms_map, 256 match.contents_class = ClassifyAllMatchesInString(term_string, terms_map,
248 match.contents, match.contents_class); 257 match.contents, match.contents_class);
249 match.description_class = ClassifyAllMatchesInString(term_string, terms_map, 258 match.description_class = ClassifyAllMatchesInString(term_string, terms_map,
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 // (1.0 / each 5 additional hits), up to a maximum of 5x as long. 410 // (1.0 / each 5 additional hits), up to a maximum of 5x as long.
402 const double kMaxDecaySpeedDivisor = 5.0; 411 const double kMaxDecaySpeedDivisor = 5.0;
403 const double kNumUsesPerDecaySpeedDivisorIncrement = 5.0; 412 const double kNumUsesPerDecaySpeedDivisorIncrement = 5.0;
404 double decay_divisor = std::min(kMaxDecaySpeedDivisor, 413 double decay_divisor = std::min(kMaxDecaySpeedDivisor,
405 (shortcut.number_of_hits + kNumUsesPerDecaySpeedDivisorIncrement - 1) / 414 (shortcut.number_of_hits + kNumUsesPerDecaySpeedDivisorIncrement - 1) /
406 kNumUsesPerDecaySpeedDivisorIncrement); 415 kNumUsesPerDecaySpeedDivisorIncrement);
407 416
408 return static_cast<int>((base_score / exp(decay_exponent / decay_divisor)) + 417 return static_cast<int>((base_score / exp(decay_exponent / decay_divisor)) +
409 0.5); 418 0.5);
410 } 419 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/search_provider_unittest.cc ('k') | components/omnibox/autocomplete_input.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698