| 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> |
| 11 | 11 |
| 12 #include "base/i18n/break_iterator.h" | 12 #include "base/i18n/break_iterator.h" |
| 13 #include "base/i18n/case_conversion.h" | 13 #include "base/i18n/case_conversion.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
| 16 #include "base/prefs/pref_service.h" | 16 #include "base/prefs/pref_service.h" |
| 17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
| 18 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
| 19 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 20 #include "base/time/time.h" | 20 #include "base/time/time.h" |
| 21 #include "chrome/browser/autocomplete/autocomplete_match.h" | 21 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 22 #include "chrome/browser/autocomplete/autocomplete_result.h" | 22 #include "chrome/browser/autocomplete/autocomplete_result.h" |
| 23 #include "chrome/browser/autocomplete/history_provider.h" | 23 #include "chrome/browser/autocomplete/history_provider.h" |
| 24 #include "chrome/browser/autocomplete/shortcuts_backend_factory.h" | 24 #include "chrome/browser/autocomplete/shortcuts_backend_factory.h" |
| 25 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | |
| 26 #include "chrome/browser/history/history_notifications.h" | 25 #include "chrome/browser/history/history_notifications.h" |
| 27 #include "chrome/browser/history/history_service.h" | 26 #include "chrome/browser/history/history_service.h" |
| 28 #include "chrome/browser/history/history_service_factory.h" | 27 #include "chrome/browser/history/history_service_factory.h" |
| 29 #include "chrome/browser/omnibox/omnibox_field_trial.h" | 28 #include "chrome/browser/omnibox/omnibox_field_trial.h" |
| 30 #include "chrome/browser/profiles/profile.h" | 29 #include "chrome/browser/profiles/profile.h" |
| 31 #include "chrome/browser/search_engines/template_url_service_factory.h" | 30 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 32 #include "chrome/common/pref_names.h" | 31 #include "chrome/common/pref_names.h" |
| 33 #include "chrome/common/url_constants.h" | 32 #include "chrome/common/url_constants.h" |
| 34 #include "components/autocomplete/autocomplete_input.h" | 33 #include "components/autocomplete/autocomplete_input.h" |
| 35 #include "components/autocomplete/url_prefix.h" | 34 #include "components/autocomplete/url_prefix.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 base::TimeTicks start_time = base::TimeTicks::Now(); | 83 base::TimeTicks start_time = base::TimeTicks::Now(); |
| 85 GetMatches(input); | 84 GetMatches(input); |
| 86 if (input.text().length() < 6) { | 85 if (input.text().length() < 6) { |
| 87 base::TimeTicks end_time = base::TimeTicks::Now(); | 86 base::TimeTicks end_time = base::TimeTicks::Now(); |
| 88 std::string name = "ShortcutsProvider.QueryIndexTime." + | 87 std::string name = "ShortcutsProvider.QueryIndexTime." + |
| 89 base::IntToString(input.text().size()); | 88 base::IntToString(input.text().size()); |
| 90 base::HistogramBase* counter = base::Histogram::FactoryGet( | 89 base::HistogramBase* counter = base::Histogram::FactoryGet( |
| 91 name, 1, 1000, 50, base::Histogram::kUmaTargetedHistogramFlag); | 90 name, 1, 1000, 50, base::Histogram::kUmaTargetedHistogramFlag); |
| 92 counter->Add(static_cast<int>((end_time - start_time).InMilliseconds())); | 91 counter->Add(static_cast<int>((end_time - start_time).InMilliseconds())); |
| 93 } | 92 } |
| 94 UpdateStarredStateOfMatches(BookmarkModelFactory::GetForProfile(profile_)); | |
| 95 } | 93 } |
| 96 | 94 |
| 97 void ShortcutsProvider::DeleteMatch(const AutocompleteMatch& match) { | 95 void ShortcutsProvider::DeleteMatch(const AutocompleteMatch& match) { |
| 98 // Copy the URL since deleting from |matches_| will invalidate |match|. | 96 // Copy the URL since deleting from |matches_| will invalidate |match|. |
| 99 GURL url(match.destination_url); | 97 GURL url(match.destination_url); |
| 100 DCHECK(url.is_valid()); | 98 DCHECK(url.is_valid()); |
| 101 | 99 |
| 102 // 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 |
| 103 // 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. |
| 104 scoped_refptr<ShortcutsBackend> backend = | 102 scoped_refptr<ShortcutsBackend> backend = |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 // (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. |
| 407 const double kMaxDecaySpeedDivisor = 5.0; | 405 const double kMaxDecaySpeedDivisor = 5.0; |
| 408 const double kNumUsesPerDecaySpeedDivisorIncrement = 5.0; | 406 const double kNumUsesPerDecaySpeedDivisorIncrement = 5.0; |
| 409 double decay_divisor = std::min(kMaxDecaySpeedDivisor, | 407 double decay_divisor = std::min(kMaxDecaySpeedDivisor, |
| 410 (shortcut.number_of_hits + kNumUsesPerDecaySpeedDivisorIncrement - 1) / | 408 (shortcut.number_of_hits + kNumUsesPerDecaySpeedDivisorIncrement - 1) / |
| 411 kNumUsesPerDecaySpeedDivisorIncrement); | 409 kNumUsesPerDecaySpeedDivisorIncrement); |
| 412 | 410 |
| 413 return static_cast<int>((base_score / exp(decay_exponent / decay_divisor)) + | 411 return static_cast<int>((base_score / exp(decay_exponent / decay_divisor)) + |
| 414 0.5); | 412 0.5); |
| 415 } | 413 } |
| OLD | NEW |