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

Side by Side Diff: components/omnibox/shortcuts_provider.cc

Issue 1220963005: Update base::StartsWith calls to new form (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@starts_with
Patch Set: Created 5 years, 5 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 "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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 129
130 int max_relevance; 130 int max_relevance;
131 if (!OmniboxFieldTrial::ShortcutsScoringMaxRelevance( 131 if (!OmniboxFieldTrial::ShortcutsScoringMaxRelevance(
132 input.current_page_classification(), &max_relevance)) 132 input.current_page_classification(), &max_relevance))
133 max_relevance = kShortcutsProviderDefaultMaxRelevance; 133 max_relevance = kShortcutsProviderDefaultMaxRelevance;
134 TemplateURLService* template_url_service = client_->GetTemplateURLService(); 134 TemplateURLService* template_url_service = client_->GetTemplateURLService();
135 const base::string16 fixed_up_input(FixupUserInput(input).second); 135 const base::string16 fixed_up_input(FixupUserInput(input).second);
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,
140 base::CompareCase::SENSITIVE);
140 ++it) { 141 ++it) {
141 // Don't return shortcuts with zero relevance. 142 // Don't return shortcuts with zero relevance.
142 int relevance = CalculateScore(term_string, it->second, max_relevance); 143 int relevance = CalculateScore(term_string, it->second, max_relevance);
143 if (relevance) { 144 if (relevance) {
144 matches_.push_back( 145 matches_.push_back(
145 ShortcutToACMatch(it->second, relevance, input, fixed_up_input)); 146 ShortcutToACMatch(it->second, relevance, input, fixed_up_input));
146 matches_.back().ComputeStrippedDestinationURL(template_url_service); 147 matches_.back().ComputeStrippedDestinationURL(template_url_service);
147 } 148 }
148 } 149 }
149 // Remove duplicates. Duplicates don't need to be preserved in the matches 150 // Remove duplicates. Duplicates don't need to be preserved in the matches
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 // Set |inline_autocompletion| and |allowed_to_be_default_match| if possible. 202 // Set |inline_autocompletion| and |allowed_to_be_default_match| if possible.
202 // If the match is a search query this is easy: simply check whether the 203 // If the match is a search query this is easy: simply check whether the
203 // user text is a prefix of the query. If the match is a navigation, we 204 // user text is a prefix of the query. If the match is a navigation, we
204 // assume the fill_into_edit looks something like a URL, so we use 205 // assume the fill_into_edit looks something like a URL, so we use
205 // URLPrefix::GetInlineAutocompleteOffset() to try and strip off any prefixes 206 // URLPrefix::GetInlineAutocompleteOffset() to try and strip off any prefixes
206 // that the user might not think would change the meaning, but would 207 // that the user might not think would change the meaning, but would
207 // otherwise prevent inline autocompletion. This allows, for example, the 208 // otherwise prevent inline autocompletion. This allows, for example, the
208 // input of "foo.c" to autocomplete to "foo.com" for a fill_into_edit of 209 // input of "foo.c" to autocomplete to "foo.com" for a fill_into_edit of
209 // "http://foo.com". 210 // "http://foo.com".
210 if (AutocompleteMatch::IsSearchType(match.type)) { 211 if (AutocompleteMatch::IsSearchType(match.type)) {
211 if (base::StartsWith(match.fill_into_edit, input.text(), false)) { 212 if (base::StartsWith(base::i18n::ToLower(match.fill_into_edit),
213 base::i18n::ToLower(input.text()),
214 base::CompareCase::SENSITIVE)) {
212 match.inline_autocompletion = 215 match.inline_autocompletion =
213 match.fill_into_edit.substr(input.text().length()); 216 match.fill_into_edit.substr(input.text().length());
214 match.allowed_to_be_default_match = 217 match.allowed_to_be_default_match =
215 !input.prevent_inline_autocomplete() || 218 !input.prevent_inline_autocomplete() ||
216 match.inline_autocompletion.empty(); 219 match.inline_autocompletion.empty();
217 } 220 }
218 } else { 221 } else {
219 const size_t inline_autocomplete_offset = 222 const size_t inline_autocomplete_offset =
220 URLPrefix::GetInlineAutocompleteOffset( 223 URLPrefix::GetInlineAutocompleteOffset(
221 input.text(), fixed_up_input_text, true, match.fill_into_edit); 224 input.text(), fixed_up_input_text, true, match.fill_into_edit);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 // if |text| is empty assures we'll return the (correct) empty vector rather 291 // if |text| is empty assures we'll return the (correct) empty vector rather
289 // than a vector with a single (0, NONE) match. 292 // than a vector with a single (0, NONE) match.
290 if (text.empty()) 293 if (text.empty())
291 return original_class; 294 return original_class;
292 295
293 // First check whether |text| begins with |find_text| and mark that whole 296 // First check whether |text| begins with |find_text| and mark that whole
294 // section as a match if so. 297 // section as a match if so.
295 base::string16 text_lowercase(base::i18n::ToLower(text)); 298 base::string16 text_lowercase(base::i18n::ToLower(text));
296 ACMatchClassifications match_class; 299 ACMatchClassifications match_class;
297 size_t last_position = 0; 300 size_t last_position = 0;
298 if (base::StartsWith(text_lowercase, find_text, true)) { 301 if (base::StartsWith(text_lowercase, find_text,
302 base::CompareCase::SENSITIVE)) {
299 match_class.push_back( 303 match_class.push_back(
300 ACMatchClassification(0, ACMatchClassification::MATCH)); 304 ACMatchClassification(0, ACMatchClassification::MATCH));
301 last_position = find_text.length(); 305 last_position = find_text.length();
302 // If |text_lowercase| is actually equal to |find_text|, we don't need to 306 // If |text_lowercase| is actually equal to |find_text|, we don't need to
303 // (and in fact shouldn't) put a trailing NONE classification after the end 307 // (and in fact shouldn't) put a trailing NONE classification after the end
304 // of the string. 308 // of the string.
305 if (last_position < text_lowercase.length()) { 309 if (last_position < text_lowercase.length()) {
306 match_class.push_back( 310 match_class.push_back(
307 ACMatchClassification(last_position, ACMatchClassification::NONE)); 311 ACMatchClassification(last_position, ACMatchClassification::NONE));
308 } 312 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 356
353 ShortcutsBackend::ShortcutMap::const_iterator ShortcutsProvider::FindFirstMatch( 357 ShortcutsBackend::ShortcutMap::const_iterator ShortcutsProvider::FindFirstMatch(
354 const base::string16& keyword, 358 const base::string16& keyword,
355 ShortcutsBackend* backend) { 359 ShortcutsBackend* backend) {
356 DCHECK(backend); 360 DCHECK(backend);
357 ShortcutsBackend::ShortcutMap::const_iterator it = 361 ShortcutsBackend::ShortcutMap::const_iterator it =
358 backend->shortcuts_map().lower_bound(keyword); 362 backend->shortcuts_map().lower_bound(keyword);
359 // Lower bound not necessarily matches the keyword, check for item pointed by 363 // Lower bound not necessarily matches the keyword, check for item pointed by
360 // the lower bound iterator to at least start with keyword. 364 // the lower bound iterator to at least start with keyword.
361 return ((it == backend->shortcuts_map().end()) || 365 return ((it == backend->shortcuts_map().end()) ||
362 base::StartsWith(it->first, keyword, true)) 366 base::StartsWith(it->first, keyword, base::CompareCase::SENSITIVE))
363 ? it 367 ? it
364 : backend->shortcuts_map().end(); 368 : backend->shortcuts_map().end();
365 } 369 }
366 370
367 int ShortcutsProvider::CalculateScore( 371 int ShortcutsProvider::CalculateScore(
368 const base::string16& terms, 372 const base::string16& terms,
369 const ShortcutsDatabase::Shortcut& shortcut, 373 const ShortcutsDatabase::Shortcut& shortcut,
370 int max_relevance) { 374 int max_relevance) {
371 DCHECK(!terms.empty()); 375 DCHECK(!terms.empty());
372 DCHECK_LE(terms.length(), shortcut.text.length()); 376 DCHECK_LE(terms.length(), shortcut.text.length());
(...skipping 22 matching lines...) Expand all
395 const double kMaxDecaySpeedDivisor = 5.0; 399 const double kMaxDecaySpeedDivisor = 5.0;
396 const double kNumUsesPerDecaySpeedDivisorIncrement = 5.0; 400 const double kNumUsesPerDecaySpeedDivisorIncrement = 5.0;
397 double decay_divisor = std::min( 401 double decay_divisor = std::min(
398 kMaxDecaySpeedDivisor, 402 kMaxDecaySpeedDivisor,
399 (shortcut.number_of_hits + kNumUsesPerDecaySpeedDivisorIncrement - 1) / 403 (shortcut.number_of_hits + kNumUsesPerDecaySpeedDivisorIncrement - 1) /
400 kNumUsesPerDecaySpeedDivisorIncrement); 404 kNumUsesPerDecaySpeedDivisorIncrement);
401 405
402 return static_cast<int>((base_score / exp(decay_exponent / decay_divisor)) + 406 return static_cast<int>((base_score / exp(decay_exponent / decay_divisor)) +
403 0.5); 407 0.5);
404 } 408 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698