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 12 matching lines...) Expand all Loading... |
23 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h" | 23 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h" |
24 #include "chrome/browser/autocomplete/autocomplete_result.h" | 24 #include "chrome/browser/autocomplete/autocomplete_result.h" |
25 #include "chrome/browser/autocomplete/history_provider.h" | 25 #include "chrome/browser/autocomplete/history_provider.h" |
26 #include "chrome/browser/autocomplete/shortcuts_backend_factory.h" | 26 #include "chrome/browser/autocomplete/shortcuts_backend_factory.h" |
27 #include "chrome/browser/autocomplete/url_prefix.h" | 27 #include "chrome/browser/autocomplete/url_prefix.h" |
28 #include "chrome/browser/history/history_notifications.h" | 28 #include "chrome/browser/history/history_notifications.h" |
29 #include "chrome/browser/history/history_service.h" | 29 #include "chrome/browser/history/history_service.h" |
30 #include "chrome/browser/history/history_service_factory.h" | 30 #include "chrome/browser/history/history_service_factory.h" |
31 #include "chrome/browser/omnibox/omnibox_field_trial.h" | 31 #include "chrome/browser/omnibox/omnibox_field_trial.h" |
32 #include "chrome/browser/profiles/profile.h" | 32 #include "chrome/browser/profiles/profile.h" |
33 #include "chrome/common/net/url_fixer_upper.h" | |
34 #include "chrome/common/pref_names.h" | 33 #include "chrome/common/pref_names.h" |
35 #include "chrome/common/url_constants.h" | 34 #include "chrome/common/url_constants.h" |
36 #include "components/metrics/proto/omnibox_input_type.pb.h" | 35 #include "components/metrics/proto/omnibox_input_type.pb.h" |
| 36 #include "components/url_fixer/url_fixer.h" |
37 #include "url/url_parse.h" | 37 #include "url/url_parse.h" |
38 | 38 |
39 namespace { | 39 namespace { |
40 | 40 |
41 class DestinationURLEqualsURL { | 41 class DestinationURLEqualsURL { |
42 public: | 42 public: |
43 explicit DestinationURLEqualsURL(const GURL& url) : url_(url) {} | 43 explicit DestinationURLEqualsURL(const GURL& url) : url_(url) {} |
44 bool operator()(const AutocompleteMatch& match) const { | 44 bool operator()(const AutocompleteMatch& match) const { |
45 return match.destination_url == url_; | 45 return match.destination_url == url_; |
46 } | 46 } |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 void ShortcutsProvider::GetMatches(const AutocompleteInput& input) { | 133 void ShortcutsProvider::GetMatches(const AutocompleteInput& input) { |
134 scoped_refptr<ShortcutsBackend> backend = | 134 scoped_refptr<ShortcutsBackend> backend = |
135 ShortcutsBackendFactory::GetForProfileIfExists(profile_); | 135 ShortcutsBackendFactory::GetForProfileIfExists(profile_); |
136 if (!backend.get()) | 136 if (!backend.get()) |
137 return; | 137 return; |
138 // Get the URLs from the shortcuts database with keys that partially or | 138 // Get the URLs from the shortcuts database with keys that partially or |
139 // completely match the search term. | 139 // completely match the search term. |
140 base::string16 term_string(base::i18n::ToLower(input.text())); | 140 base::string16 term_string(base::i18n::ToLower(input.text())); |
141 DCHECK(!term_string.empty()); | 141 DCHECK(!term_string.empty()); |
142 | 142 |
143 const GURL& input_as_gurl = URLFixerUpper::FixupURL( | 143 const GURL& input_as_gurl = |
144 base::UTF16ToUTF8(input.text()), std::string()); | 144 url_fixer::FixupURL(base::UTF16ToUTF8(input.text()), std::string()); |
145 const base::string16 fixed_up_input(FixupUserInput(input).second); | 145 const base::string16 fixed_up_input(FixupUserInput(input).second); |
146 | 146 |
147 int max_relevance; | 147 int max_relevance; |
148 if (!OmniboxFieldTrial::ShortcutsScoringMaxRelevance( | 148 if (!OmniboxFieldTrial::ShortcutsScoringMaxRelevance( |
149 input.current_page_classification(), &max_relevance)) | 149 input.current_page_classification(), &max_relevance)) |
150 max_relevance = kShortcutsProviderDefaultMaxRelevance; | 150 max_relevance = kShortcutsProviderDefaultMaxRelevance; |
151 | 151 |
152 for (ShortcutsBackend::ShortcutMap::const_iterator it = | 152 for (ShortcutsBackend::ShortcutMap::const_iterator it = |
153 FindFirstMatch(term_string, backend.get()); | 153 FindFirstMatch(term_string, backend.get()); |
154 it != backend->shortcuts_map().end() && | 154 it != backend->shortcuts_map().end() && |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 if (inline_autocomplete_offset != base::string16::npos) { | 238 if (inline_autocomplete_offset != base::string16::npos) { |
239 match.inline_autocompletion = | 239 match.inline_autocompletion = |
240 match.fill_into_edit.substr(inline_autocomplete_offset); | 240 match.fill_into_edit.substr(inline_autocomplete_offset); |
241 match.allowed_to_be_default_match = | 241 match.allowed_to_be_default_match = |
242 !HistoryProvider::PreventInlineAutocomplete(input) || | 242 !HistoryProvider::PreventInlineAutocomplete(input) || |
243 match.inline_autocompletion.empty(); | 243 match.inline_autocompletion.empty(); |
244 } else { | 244 } else { |
245 // Also allow a user's input to be marked as default if it would be fixed | 245 // Also allow a user's input to be marked as default if it would be fixed |
246 // up to the same thing as the fill_into_edit. This handles cases like | 246 // up to the same thing as the fill_into_edit. This handles cases like |
247 // the user input containing a trailing slash absent in fill_into_edit. | 247 // the user input containing a trailing slash absent in fill_into_edit. |
248 match.allowed_to_be_default_match = (input_as_gurl == | 248 match.allowed_to_be_default_match = |
249 URLFixerUpper::FixupURL(base::UTF16ToUTF8(match.fill_into_edit), | 249 (input_as_gurl == |
250 std::string())); | 250 url_fixer::FixupURL(base::UTF16ToUTF8(match.fill_into_edit), |
| 251 std::string())); |
251 } | 252 } |
252 } | 253 } |
253 | 254 |
254 // Try to mark pieces of the contents and description as matches if they | 255 // Try to mark pieces of the contents and description as matches if they |
255 // appear in |input.text()|. | 256 // appear in |input.text()|. |
256 const base::string16 term_string = base::i18n::ToLower(input.text()); | 257 const base::string16 term_string = base::i18n::ToLower(input.text()); |
257 WordMap terms_map(CreateWordMapForString(term_string)); | 258 WordMap terms_map(CreateWordMapForString(term_string)); |
258 if (!terms_map.empty()) { | 259 if (!terms_map.empty()) { |
259 match.contents_class = ClassifyAllMatchesInString(term_string, terms_map, | 260 match.contents_class = ClassifyAllMatchesInString(term_string, terms_map, |
260 match.contents, match.contents_class); | 261 match.contents, match.contents_class); |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 // (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. |
414 const double kMaxDecaySpeedDivisor = 5.0; | 415 const double kMaxDecaySpeedDivisor = 5.0; |
415 const double kNumUsesPerDecaySpeedDivisorIncrement = 5.0; | 416 const double kNumUsesPerDecaySpeedDivisorIncrement = 5.0; |
416 double decay_divisor = std::min(kMaxDecaySpeedDivisor, | 417 double decay_divisor = std::min(kMaxDecaySpeedDivisor, |
417 (shortcut.number_of_hits + kNumUsesPerDecaySpeedDivisorIncrement - 1) / | 418 (shortcut.number_of_hits + kNumUsesPerDecaySpeedDivisorIncrement - 1) / |
418 kNumUsesPerDecaySpeedDivisorIncrement); | 419 kNumUsesPerDecaySpeedDivisorIncrement); |
419 | 420 |
420 return static_cast<int>((base_score / exp(decay_exponent / decay_divisor)) + | 421 return static_cast<int>((base_score / exp(decay_exponent / decay_divisor)) + |
421 0.5); | 422 0.5); |
422 } | 423 } |
OLD | NEW |