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