Chromium Code Reviews| 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 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 288 ACMatchClassification(word_end, ACMatchClassification::NONE)); | 288 ACMatchClassification(word_end, ACMatchClassification::NONE)); |
| 289 } | 289 } |
| 290 last_position = word_end; | 290 last_position = word_end; |
| 291 break; | 291 break; |
| 292 } | 292 } |
| 293 } | 293 } |
| 294 last_position = std::max(last_position, next_character); | 294 last_position = std::max(last_position, next_character); |
| 295 } | 295 } |
| 296 | 296 |
| 297 // Merge match-marking data with original classifications. | 297 // Merge match-marking data with original classifications. |
| 298 if ((match_class.size() == 1) && | 298 if ((match_class.size() == 1) && |
|
Peter Kasting
2012/09/10 18:56:11
This conditional can be entirely removed once the
Daniel Erat
2012/09/10 19:36:17
I had to update ShortcutsProviderTest.ClassifyAllM
| |
| 299 (match_class.back().style == ACMatchClassification::NONE)) | 299 (match_class.back().style == ACMatchClassification::NONE)) { |
| 300 return original_class; | 300 return original_class; |
| 301 ACMatchClassifications output; | 301 } else { |
| 302 for (ACMatchClassifications::const_iterator i = original_class.begin(), | 302 return AutocompleteMatch::MergeClassifications(original_class, |
| 303 j = match_class.begin(); i != original_class.end();) { | 303 match_class); |
| 304 AutocompleteMatch::AddLastClassificationIfNecessary(&output, | |
| 305 std::max(i->offset, j->offset), i->style | j->style); | |
| 306 const size_t next_i_offset = (i + 1) == original_class.end() ? | |
| 307 static_cast<size_t>(-1) : (i + 1)->offset; | |
| 308 const size_t next_j_offset = (j + 1) == match_class.end() ? | |
| 309 static_cast<size_t>(-1) : (j + 1)->offset; | |
| 310 if (next_i_offset >= next_j_offset) | |
| 311 ++j; | |
| 312 if (next_j_offset >= next_i_offset) | |
| 313 ++i; | |
| 314 } | 304 } |
| 315 return output; | |
| 316 } | 305 } |
| 317 | 306 |
| 318 history::ShortcutsBackend::ShortcutMap::const_iterator | 307 history::ShortcutsBackend::ShortcutMap::const_iterator |
| 319 ShortcutsProvider::FindFirstMatch(const string16& keyword, | 308 ShortcutsProvider::FindFirstMatch(const string16& keyword, |
| 320 history::ShortcutsBackend* backend) { | 309 history::ShortcutsBackend* backend) { |
| 321 DCHECK(backend); | 310 DCHECK(backend); |
| 322 history::ShortcutsBackend::ShortcutMap::const_iterator it = | 311 history::ShortcutsBackend::ShortcutMap::const_iterator it = |
| 323 backend->shortcuts_map().lower_bound(keyword); | 312 backend->shortcuts_map().lower_bound(keyword); |
| 324 // Lower bound not necessarily matches the keyword, check for item pointed by | 313 // Lower bound not necessarily matches the keyword, check for item pointed by |
| 325 // the lower bound iterator to at least start with keyword. | 314 // the lower bound iterator to at least start with keyword. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 357 // (1.0 / each 5 additional hits), up to a maximum of 5x as long. | 346 // (1.0 / each 5 additional hits), up to a maximum of 5x as long. |
| 358 const double kMaxDecaySpeedDivisor = 5.0; | 347 const double kMaxDecaySpeedDivisor = 5.0; |
| 359 const double kNumUsesPerDecaySpeedDivisorIncrement = 5.0; | 348 const double kNumUsesPerDecaySpeedDivisorIncrement = 5.0; |
| 360 double decay_divisor = std::min(kMaxDecaySpeedDivisor, | 349 double decay_divisor = std::min(kMaxDecaySpeedDivisor, |
| 361 (shortcut.number_of_hits + kNumUsesPerDecaySpeedDivisorIncrement - 1) / | 350 (shortcut.number_of_hits + kNumUsesPerDecaySpeedDivisorIncrement - 1) / |
| 362 kNumUsesPerDecaySpeedDivisorIncrement); | 351 kNumUsesPerDecaySpeedDivisorIncrement); |
| 363 | 352 |
| 364 return static_cast<int>((base_score / exp(decay_exponent / decay_divisor)) + | 353 return static_cast<int>((base_score / exp(decay_exponent / decay_divisor)) + |
| 365 0.5); | 354 0.5); |
| 366 } | 355 } |
| OLD | NEW |