| 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 | 94 |
| 95 void ShortcutsProvider::DeleteMatch(const AutocompleteMatch& match) { | 95 void ShortcutsProvider::DeleteMatch(const AutocompleteMatch& match) { |
| 96 // Copy the URL since deleting from |matches_| will invalidate |match|. | 96 // Copy the URL since deleting from |matches_| will invalidate |match|. |
| 97 GURL url(match.destination_url); | 97 GURL url(match.destination_url); |
| 98 DCHECK(url.is_valid()); | 98 DCHECK(url.is_valid()); |
| 99 | 99 |
| 100 // When a user deletes a match, he probably means for the URL to disappear out | 100 // When a user deletes a match, he probably means for the URL to disappear out |
| 101 // of history entirely. So nuke all shortcuts that map to this URL. | 101 // of history entirely. So nuke all shortcuts that map to this URL. |
| 102 scoped_refptr<ShortcutsBackend> backend = | 102 scoped_refptr<ShortcutsBackend> backend = |
| 103 ShortcutsBackendFactory::GetForProfileIfExists(profile_); | 103 ShortcutsBackendFactory::GetForProfileIfExists(profile_); |
| 104 if (backend) // Can be NULL in Incognito. | 104 if (backend.get()) // Can be NULL in Incognito. |
| 105 backend->DeleteShortcutsWithURL(url); | 105 backend->DeleteShortcutsWithURL(url); |
| 106 | 106 |
| 107 matches_.erase(std::remove_if(matches_.begin(), matches_.end(), | 107 matches_.erase(std::remove_if(matches_.begin(), matches_.end(), |
| 108 DestinationURLEqualsURL(url)), | 108 DestinationURLEqualsURL(url)), |
| 109 matches_.end()); | 109 matches_.end()); |
| 110 // NOTE: |match| is now dead! | 110 // NOTE: |match| is now dead! |
| 111 | 111 |
| 112 // Delete the match from the history DB. This will eventually result in a | 112 // Delete the match from the history DB. This will eventually result in a |
| 113 // second call to DeleteShortcutsWithURL(), which is harmless. | 113 // second call to DeleteShortcutsWithURL(), which is harmless. |
| 114 HistoryService* const history_service = | 114 HistoryService* const history_service = |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 // (1.0 / each 5 additional hits), up to a maximum of 5x as long. | 404 // (1.0 / each 5 additional hits), up to a maximum of 5x as long. |
| 405 const double kMaxDecaySpeedDivisor = 5.0; | 405 const double kMaxDecaySpeedDivisor = 5.0; |
| 406 const double kNumUsesPerDecaySpeedDivisorIncrement = 5.0; | 406 const double kNumUsesPerDecaySpeedDivisorIncrement = 5.0; |
| 407 double decay_divisor = std::min(kMaxDecaySpeedDivisor, | 407 double decay_divisor = std::min(kMaxDecaySpeedDivisor, |
| 408 (shortcut.number_of_hits + kNumUsesPerDecaySpeedDivisorIncrement - 1) / | 408 (shortcut.number_of_hits + kNumUsesPerDecaySpeedDivisorIncrement - 1) / |
| 409 kNumUsesPerDecaySpeedDivisorIncrement); | 409 kNumUsesPerDecaySpeedDivisorIncrement); |
| 410 | 410 |
| 411 return static_cast<int>((base_score / exp(decay_exponent / decay_divisor)) + | 411 return static_cast<int>((base_score / exp(decay_exponent / decay_divisor)) + |
| 412 0.5); | 412 0.5); |
| 413 } | 413 } |
| OLD | NEW |