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

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

Issue 109013006: Update some uses of UTF conversions in chrome/browser to use the base:: namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 6 years, 12 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 | Annotate | Revision Log
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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 // Like URLPrefix::BestURLPrefix() except also handles the prefix of 49 // Like URLPrefix::BestURLPrefix() except also handles the prefix of
50 // "www.". This is needed because sometimes the string we're matching 50 // "www.". This is needed because sometimes the string we're matching
51 // against here (which comes from |fill_into_edit|) can start with 51 // against here (which comes from |fill_into_edit|) can start with
52 // "www." without having a protocol at the beginning. Because "www." 52 // "www." without having a protocol at the beginning. Because "www."
53 // is not on the default prefix list, we test for it explicitly here 53 // is not on the default prefix list, we test for it explicitly here
54 // and use that match if the default list didn't have a match or the 54 // and use that match if the default list didn't have a match or the
55 // default list's match was shorter than it could've been. 55 // default list's match was shorter than it could've been.
56 const URLPrefix* BestURLPrefixWithWWWCase( 56 const URLPrefix* BestURLPrefixWithWWWCase(
57 const base::string16& text, 57 const base::string16& text,
58 const base::string16& prefix_suffix) { 58 const base::string16& prefix_suffix) {
59 CR_DEFINE_STATIC_LOCAL(URLPrefix, www_prefix, (ASCIIToUTF16("www."), 1)); 59 CR_DEFINE_STATIC_LOCAL(URLPrefix, www_prefix,
60 (base::ASCIIToUTF16("www."), 1));
60 const URLPrefix* best_prefix = URLPrefix::BestURLPrefix(text, prefix_suffix); 61 const URLPrefix* best_prefix = URLPrefix::BestURLPrefix(text, prefix_suffix);
61 if ((best_prefix == NULL) || 62 if ((best_prefix == NULL) ||
62 (best_prefix->num_components < www_prefix.num_components)) { 63 (best_prefix->num_components < www_prefix.num_components)) {
63 if (URLPrefix::PrefixMatch(www_prefix, text, prefix_suffix)) 64 if (URLPrefix::PrefixMatch(www_prefix, text, prefix_suffix))
64 best_prefix = &www_prefix; 65 best_prefix = &www_prefix;
65 } 66 }
66 return best_prefix; 67 return best_prefix;
67 } 68 }
68 69
69 } // namespace 70 } // namespace
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 const base::string16& fixed_up_term_string, 214 const base::string16& fixed_up_term_string,
214 const bool prevent_inline_autocomplete) { 215 const bool prevent_inline_autocomplete) {
215 DCHECK(!term_string.empty()); 216 DCHECK(!term_string.empty());
216 AutocompleteMatch match(shortcut.match_core.ToMatch()); 217 AutocompleteMatch match(shortcut.match_core.ToMatch());
217 match.provider = this; 218 match.provider = this;
218 match.relevance = relevance; 219 match.relevance = relevance;
219 match.deletable = true; 220 match.deletable = true;
220 DCHECK(match.destination_url.is_valid()); 221 DCHECK(match.destination_url.is_valid());
221 match.RecordAdditionalInfo("number of hits", shortcut.number_of_hits); 222 match.RecordAdditionalInfo("number of hits", shortcut.number_of_hits);
222 match.RecordAdditionalInfo("last access time", shortcut.last_access_time); 223 match.RecordAdditionalInfo("last access time", shortcut.last_access_time);
223 match.RecordAdditionalInfo("original input text", UTF16ToUTF8(shortcut.text)); 224 match.RecordAdditionalInfo("original input text",
225 base::UTF16ToUTF8(shortcut.text));
224 226
225 // Set |inline_autocompletion| and |allowed_to_be_default_match| if possible. 227 // Set |inline_autocompletion| and |allowed_to_be_default_match| if possible.
226 // If the match is a search query this is easy: simply check whether the 228 // If the match is a search query this is easy: simply check whether the
227 // user text is a prefix of the query. If the match is a navigation, we 229 // user text is a prefix of the query. If the match is a navigation, we
228 // assume the fill_into_edit looks something like a URL, so we use 230 // assume the fill_into_edit looks something like a URL, so we use
229 // BestURLPrefix() to try and strip off any prefixes that the user might 231 // BestURLPrefix() to try and strip off any prefixes that the user might
230 // not think would change the meaning, but would otherwise prevent inline 232 // not think would change the meaning, but would otherwise prevent inline
231 // autocompletion. This allows, for example, the input of "foo.c" to 233 // autocompletion. This allows, for example, the input of "foo.c" to
232 // autocomplete to "foo.com" for a fill_into_edit of "http://foo.com". 234 // autocomplete to "foo.com" for a fill_into_edit of "http://foo.com".
233 if (AutocompleteMatch::IsSearchType(match.type)) { 235 if (AutocompleteMatch::IsSearchType(match.type)) {
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 // (1.0 / each 5 additional hits), up to a maximum of 5x as long. 422 // (1.0 / each 5 additional hits), up to a maximum of 5x as long.
421 const double kMaxDecaySpeedDivisor = 5.0; 423 const double kMaxDecaySpeedDivisor = 5.0;
422 const double kNumUsesPerDecaySpeedDivisorIncrement = 5.0; 424 const double kNumUsesPerDecaySpeedDivisorIncrement = 5.0;
423 double decay_divisor = std::min(kMaxDecaySpeedDivisor, 425 double decay_divisor = std::min(kMaxDecaySpeedDivisor,
424 (shortcut.number_of_hits + kNumUsesPerDecaySpeedDivisorIncrement - 1) / 426 (shortcut.number_of_hits + kNumUsesPerDecaySpeedDivisorIncrement - 1) /
425 kNumUsesPerDecaySpeedDivisorIncrement); 427 kNumUsesPerDecaySpeedDivisorIncrement);
426 428
427 return static_cast<int>((base_score / exp(decay_exponent / decay_divisor)) + 429 return static_cast<int>((base_score / exp(decay_exponent / decay_divisor)) +
428 0.5); 430 0.5);
429 } 431 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/search_provider_unittest.cc ('k') | chrome/browser/autocomplete/shortcuts_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698