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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 match.keyword = shortcut.match_core.keyword; | 211 match.keyword = shortcut.match_core.keyword; |
212 match.RecordAdditionalInfo("number of hits", shortcut.number_of_hits); | 212 match.RecordAdditionalInfo("number of hits", shortcut.number_of_hits); |
213 match.RecordAdditionalInfo("last access time", shortcut.last_access_time); | 213 match.RecordAdditionalInfo("last access time", shortcut.last_access_time); |
214 match.RecordAdditionalInfo("original input text", | 214 match.RecordAdditionalInfo("original input text", |
215 base::UTF16ToUTF8(shortcut.text)); | 215 base::UTF16ToUTF8(shortcut.text)); |
216 | 216 |
217 // Set |inline_autocompletion| and |allowed_to_be_default_match| if possible. | 217 // Set |inline_autocompletion| and |allowed_to_be_default_match| if possible. |
218 // If the match is a search query this is easy: simply check whether the | 218 // If the match is a search query this is easy: simply check whether the |
219 // user text is a prefix of the query. If the match is a navigation, we | 219 // user text is a prefix of the query. If the match is a navigation, we |
220 // assume the fill_into_edit looks something like a URL, so we use | 220 // assume the fill_into_edit looks something like a URL, so we use |
221 // URLPrefix::ComputeMatchStartAndInlineAutocompleteOffset() to try and strip | 221 // URLPrefix::GetInlineAutocompleteOffset() to try and strip off any prefixes |
222 // off any prefixes that the user might not think would change the meaning, | 222 // that the user might not think would change the meaning, but would |
223 // but would otherwise prevent inline autocompletion. This allows, for | 223 // otherwise prevent inline autocompletion. This allows, for example, the |
224 // example, the input of "foo.c" to autocomplete to "foo.com" for a | 224 // input of "foo.c" to autocomplete to "foo.com" for a fill_into_edit of |
225 // fill_into_edit of "http://foo.com". | 225 // "http://foo.com". |
226 if (AutocompleteMatch::IsSearchType(match.type)) { | 226 if (AutocompleteMatch::IsSearchType(match.type)) { |
227 if (StartsWith(match.fill_into_edit, input.text(), false)) { | 227 if (StartsWith(match.fill_into_edit, input.text(), false)) { |
228 match.inline_autocompletion = | 228 match.inline_autocompletion = |
229 match.fill_into_edit.substr(input.text().length()); | 229 match.fill_into_edit.substr(input.text().length()); |
230 match.allowed_to_be_default_match = | 230 match.allowed_to_be_default_match = |
231 !input.prevent_inline_autocomplete() || | 231 !input.prevent_inline_autocomplete() || |
232 match.inline_autocompletion.empty(); | 232 match.inline_autocompletion.empty(); |
233 } | 233 } |
234 } else { | 234 } else { |
235 size_t match_start, inline_autocomplete_offset; | 235 const size_t inline_autocomplete_offset = |
236 URLPrefix::ComputeMatchStartAndInlineAutocompleteOffset( | 236 URLPrefix::GetInlineAutocompleteOffset( |
237 input, fixed_up_input, true, match.fill_into_edit, | 237 input, fixed_up_input, true, match.fill_into_edit); |
238 &match_start, &inline_autocomplete_offset); | |
239 if (inline_autocomplete_offset != base::string16::npos) { | 238 if (inline_autocomplete_offset != base::string16::npos) { |
240 match.inline_autocompletion = | 239 match.inline_autocompletion = |
241 match.fill_into_edit.substr(inline_autocomplete_offset); | 240 match.fill_into_edit.substr(inline_autocomplete_offset); |
242 match.allowed_to_be_default_match = | 241 match.allowed_to_be_default_match = |
243 !HistoryProvider::PreventInlineAutocomplete(input) || | 242 !HistoryProvider::PreventInlineAutocomplete(input) || |
244 match.inline_autocompletion.empty(); | 243 match.inline_autocompletion.empty(); |
245 } else { | 244 } else { |
246 // Also allow a user's input to be marked as default if it would be fixed | 245 // Also allow a user's input to be marked as default if it would be fixed |
247 // up to the same thing as the fill_into_edit. This handles cases like | 246 // up to the same thing as the fill_into_edit. This handles cases like |
248 // the user input containing a trailing slash absent in fill_into_edit. | 247 // the user input containing a trailing slash absent in fill_into_edit. |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 // (1.0 / each 5 additional hits), up to a maximum of 5x as long. | 413 // (1.0 / each 5 additional hits), up to a maximum of 5x as long. |
415 const double kMaxDecaySpeedDivisor = 5.0; | 414 const double kMaxDecaySpeedDivisor = 5.0; |
416 const double kNumUsesPerDecaySpeedDivisorIncrement = 5.0; | 415 const double kNumUsesPerDecaySpeedDivisorIncrement = 5.0; |
417 double decay_divisor = std::min(kMaxDecaySpeedDivisor, | 416 double decay_divisor = std::min(kMaxDecaySpeedDivisor, |
418 (shortcut.number_of_hits + kNumUsesPerDecaySpeedDivisorIncrement - 1) / | 417 (shortcut.number_of_hits + kNumUsesPerDecaySpeedDivisorIncrement - 1) / |
419 kNumUsesPerDecaySpeedDivisorIncrement); | 418 kNumUsesPerDecaySpeedDivisorIncrement); |
420 | 419 |
421 return static_cast<int>((base_score / exp(decay_exponent / decay_divisor)) + | 420 return static_cast<int>((base_score / exp(decay_exponent / decay_divisor)) + |
422 0.5); | 421 0.5); |
423 } | 422 } |
OLD | NEW |