| 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 10 matching lines...) Expand all Loading... |
| 21 #include "chrome/browser/autocomplete/autocomplete_match.h" | 21 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 22 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h" | 22 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h" |
| 23 #include "chrome/browser/autocomplete/autocomplete_result.h" | 23 #include "chrome/browser/autocomplete/autocomplete_result.h" |
| 24 #include "chrome/browser/autocomplete/history_provider.h" | 24 #include "chrome/browser/autocomplete/history_provider.h" |
| 25 #include "chrome/browser/autocomplete/shortcuts_backend_factory.h" | 25 #include "chrome/browser/autocomplete/shortcuts_backend_factory.h" |
| 26 #include "chrome/browser/history/history_notifications.h" | 26 #include "chrome/browser/history/history_notifications.h" |
| 27 #include "chrome/browser/history/history_service.h" | 27 #include "chrome/browser/history/history_service.h" |
| 28 #include "chrome/browser/history/history_service_factory.h" | 28 #include "chrome/browser/history/history_service_factory.h" |
| 29 #include "chrome/browser/omnibox/omnibox_field_trial.h" | 29 #include "chrome/browser/omnibox/omnibox_field_trial.h" |
| 30 #include "chrome/browser/profiles/profile.h" | 30 #include "chrome/browser/profiles/profile.h" |
| 31 #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" |
| 36 #include "components/metrics/proto/omnibox_input_type.pb.h" | 35 #include "components/metrics/proto/omnibox_input_type.pb.h" |
| 37 #include "components/url_fixer/url_fixer.h" | 36 #include "components/url_fixer/url_fixer.h" |
| 38 #include "url/url_parse.h" | 37 #include "url/url_parse.h" |
| 39 | 38 |
| 40 namespace { | 39 namespace { |
| 41 | 40 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 | 151 |
| 153 for (ShortcutsBackend::ShortcutMap::const_iterator it = | 152 for (ShortcutsBackend::ShortcutMap::const_iterator it = |
| 154 FindFirstMatch(term_string, backend.get()); | 153 FindFirstMatch(term_string, backend.get()); |
| 155 it != backend->shortcuts_map().end() && | 154 it != backend->shortcuts_map().end() && |
| 156 StartsWith(it->first, term_string, true); ++it) { | 155 StartsWith(it->first, term_string, true); ++it) { |
| 157 // Don't return shortcuts with zero relevance. | 156 // Don't return shortcuts with zero relevance. |
| 158 int relevance = CalculateScore(term_string, it->second, max_relevance); | 157 int relevance = CalculateScore(term_string, it->second, max_relevance); |
| 159 if (relevance) { | 158 if (relevance) { |
| 160 matches_.push_back(ShortcutToACMatch(it->second, relevance, input, | 159 matches_.push_back(ShortcutToACMatch(it->second, relevance, input, |
| 161 fixed_up_input, input_as_gurl)); | 160 fixed_up_input, input_as_gurl)); |
| 162 matches_.back().ComputeStrippedDestinationURL( | 161 matches_.back().ComputeStrippedDestinationURL(profile_); |
| 163 TemplateURLServiceFactory::GetForProfile(profile_)); | |
| 164 } | 162 } |
| 165 } | 163 } |
| 166 // Remove duplicates. Duplicates don't need to be preserved in the matches | 164 // Remove duplicates. Duplicates don't need to be preserved in the matches |
| 167 // because they are only used for deletions, and shortcuts deletes matches | 165 // because they are only used for deletions, and shortcuts deletes matches |
| 168 // based on the URL. | 166 // based on the URL. |
| 169 AutocompleteResult::DedupMatchesByDestination( | 167 AutocompleteResult::DedupMatchesByDestination( |
| 170 input.current_page_classification(), false, &matches_); | 168 input.current_page_classification(), false, &matches_); |
| 171 // Find best matches. | 169 // Find best matches. |
| 172 std::partial_sort(matches_.begin(), | 170 std::partial_sort(matches_.begin(), |
| 173 matches_.begin() + | 171 matches_.begin() + |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 // (1.0 / each 5 additional hits), up to a maximum of 5x as long. | 414 // (1.0 / each 5 additional hits), up to a maximum of 5x as long. |
| 417 const double kMaxDecaySpeedDivisor = 5.0; | 415 const double kMaxDecaySpeedDivisor = 5.0; |
| 418 const double kNumUsesPerDecaySpeedDivisorIncrement = 5.0; | 416 const double kNumUsesPerDecaySpeedDivisorIncrement = 5.0; |
| 419 double decay_divisor = std::min(kMaxDecaySpeedDivisor, | 417 double decay_divisor = std::min(kMaxDecaySpeedDivisor, |
| 420 (shortcut.number_of_hits + kNumUsesPerDecaySpeedDivisorIncrement - 1) / | 418 (shortcut.number_of_hits + kNumUsesPerDecaySpeedDivisorIncrement - 1) / |
| 421 kNumUsesPerDecaySpeedDivisorIncrement); | 419 kNumUsesPerDecaySpeedDivisorIncrement); |
| 422 | 420 |
| 423 return static_cast<int>((base_score / exp(decay_exponent / decay_divisor)) + | 421 return static_cast<int>((base_score / exp(decay_exponent / decay_divisor)) + |
| 424 0.5); | 422 0.5); |
| 425 } | 423 } |
| OLD | NEW |