Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1382)

Side by Side Diff: chrome/browser/autocomplete/shortcuts_provider.cc

Issue 354773002: Reduces dependency from AutocompleteMatch to Profile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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"
31 #include "chrome/common/pref_names.h" 32 #include "chrome/common/pref_names.h"
32 #include "chrome/common/url_constants.h" 33 #include "chrome/common/url_constants.h"
33 #include "components/autocomplete/autocomplete_input.h" 34 #include "components/autocomplete/autocomplete_input.h"
34 #include "components/autocomplete/url_prefix.h" 35 #include "components/autocomplete/url_prefix.h"
35 #include "components/metrics/proto/omnibox_input_type.pb.h" 36 #include "components/metrics/proto/omnibox_input_type.pb.h"
36 #include "components/url_fixer/url_fixer.h" 37 #include "components/url_fixer/url_fixer.h"
37 #include "url/url_parse.h" 38 #include "url/url_parse.h"
38 39
39 namespace { 40 namespace {
40 41
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 152
152 for (ShortcutsBackend::ShortcutMap::const_iterator it = 153 for (ShortcutsBackend::ShortcutMap::const_iterator it =
153 FindFirstMatch(term_string, backend.get()); 154 FindFirstMatch(term_string, backend.get());
154 it != backend->shortcuts_map().end() && 155 it != backend->shortcuts_map().end() &&
155 StartsWith(it->first, term_string, true); ++it) { 156 StartsWith(it->first, term_string, true); ++it) {
156 // Don't return shortcuts with zero relevance. 157 // Don't return shortcuts with zero relevance.
157 int relevance = CalculateScore(term_string, it->second, max_relevance); 158 int relevance = CalculateScore(term_string, it->second, max_relevance);
158 if (relevance) { 159 if (relevance) {
159 matches_.push_back(ShortcutToACMatch(it->second, relevance, input, 160 matches_.push_back(ShortcutToACMatch(it->second, relevance, input,
160 fixed_up_input, input_as_gurl)); 161 fixed_up_input, input_as_gurl));
161 matches_.back().ComputeStrippedDestinationURL(profile_); 162 matches_.back().ComputeStrippedDestinationURL(
163 TemplateURLServiceFactory::GetForProfile(profile_));
162 } 164 }
163 } 165 }
164 // Remove duplicates. Duplicates don't need to be preserved in the matches 166 // Remove duplicates. Duplicates don't need to be preserved in the matches
165 // because they are only used for deletions, and shortcuts deletes matches 167 // because they are only used for deletions, and shortcuts deletes matches
166 // based on the URL. 168 // based on the URL.
167 AutocompleteResult::DedupMatchesByDestination( 169 AutocompleteResult::DedupMatchesByDestination(
168 input.current_page_classification(), false, &matches_); 170 input.current_page_classification(), false, &matches_);
169 // Find best matches. 171 // Find best matches.
170 std::partial_sort(matches_.begin(), 172 std::partial_sort(matches_.begin(),
171 matches_.begin() + 173 matches_.begin() +
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 // (1.0 / each 5 additional hits), up to a maximum of 5x as long. 416 // (1.0 / each 5 additional hits), up to a maximum of 5x as long.
415 const double kMaxDecaySpeedDivisor = 5.0; 417 const double kMaxDecaySpeedDivisor = 5.0;
416 const double kNumUsesPerDecaySpeedDivisorIncrement = 5.0; 418 const double kNumUsesPerDecaySpeedDivisorIncrement = 5.0;
417 double decay_divisor = std::min(kMaxDecaySpeedDivisor, 419 double decay_divisor = std::min(kMaxDecaySpeedDivisor,
418 (shortcut.number_of_hits + kNumUsesPerDecaySpeedDivisorIncrement - 1) / 420 (shortcut.number_of_hits + kNumUsesPerDecaySpeedDivisorIncrement - 1) /
419 kNumUsesPerDecaySpeedDivisorIncrement); 421 kNumUsesPerDecaySpeedDivisorIncrement);
420 422
421 return static_cast<int>((base_score / exp(decay_exponent / decay_divisor)) + 423 return static_cast<int>((base_score / exp(decay_exponent / decay_divisor)) +
422 0.5); 424 0.5);
423 } 425 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/shortcuts_backend.cc ('k') | chrome/browser/ui/app_list/search/omnibox_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698