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

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

Issue 18878007: Omnibox: Make the Controller Reorder Matches for Inlining (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 }; 48 };
49 49
50 } // namespace 50 } // namespace
51 51
52 ShortcutsProvider::ShortcutsProvider(AutocompleteProviderListener* listener, 52 ShortcutsProvider::ShortcutsProvider(AutocompleteProviderListener* listener,
53 Profile* profile) 53 Profile* profile)
54 : AutocompleteProvider(listener, profile, 54 : AutocompleteProvider(listener, profile,
55 AutocompleteProvider::TYPE_SHORTCUTS), 55 AutocompleteProvider::TYPE_SHORTCUTS),
56 languages_(profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)), 56 languages_(profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)),
57 initialized_(false), 57 initialized_(false),
58 max_relevance_(AutocompleteResult::kLowestDefaultScore - 1) { 58 max_relevance_(AutocompleteResult::kLowestDefaultScore - 1),
59 omnibox_will_reorder_for_inlining_(
60 OmniboxFieldTrial::InReorderForInliningGroup()) {
59 scoped_refptr<history::ShortcutsBackend> backend = 61 scoped_refptr<history::ShortcutsBackend> backend =
60 ShortcutsBackendFactory::GetForProfile(profile_); 62 ShortcutsBackendFactory::GetForProfile(profile_);
61 if (backend.get()) { 63 if (backend.get()) {
62 backend->AddObserver(this); 64 backend->AddObserver(this);
63 if (backend->initialized()) 65 if (backend->initialized())
64 initialized_ = true; 66 initialized_ = true;
65 } 67 }
66 int max_relevance; 68 int max_relevance;
67 if (OmniboxFieldTrial::ShortcutsScoringMaxRelevance(&max_relevance)) 69 if (OmniboxFieldTrial::ShortcutsScoringMaxRelevance(&max_relevance))
68 max_relevance_ = max_relevance; 70 max_relevance_ = max_relevance;
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 matches_.begin() + 172 matches_.begin() +
171 std::min(AutocompleteProvider::kMaxMatches, matches_.size()), 173 std::min(AutocompleteProvider::kMaxMatches, matches_.size()),
172 matches_.end(), &AutocompleteMatch::MoreRelevant); 174 matches_.end(), &AutocompleteMatch::MoreRelevant);
173 if (matches_.size() > AutocompleteProvider::kMaxMatches) { 175 if (matches_.size() > AutocompleteProvider::kMaxMatches) {
174 matches_.erase(matches_.begin() + AutocompleteProvider::kMaxMatches, 176 matches_.erase(matches_.begin() + AutocompleteProvider::kMaxMatches,
175 matches_.end()); 177 matches_.end());
176 } 178 }
177 // Reset relevance scores to guarantee no results are given an 179 // Reset relevance scores to guarantee no results are given an
178 // inlineable score and all scores are decreasing (but not do assign 180 // inlineable score and all scores are decreasing (but not do assign
179 // any scores below 1). 181 // any scores below 1).
180 int max_relevance = AutocompleteResult::kLowestDefaultScore - 1; 182 if (!omnibox_will_reorder_for_inlining_) {
181 for (ACMatches::iterator it = matches_.begin(); it != matches_.end(); ++it) { 183 int max_relevance = AutocompleteResult::kLowestDefaultScore - 1;
182 max_relevance = std::min(max_relevance, it->relevance); 184 for (ACMatches::iterator it = matches_.begin(); it != matches_.end();
183 it->relevance = max_relevance; 185 ++it) {
184 if (max_relevance > 1) 186 max_relevance = std::min(max_relevance, it->relevance);
185 --max_relevance; 187 it->relevance = max_relevance;
188 if (max_relevance > 1)
189 --max_relevance;
190 }
186 } 191 }
187 } 192 }
188 193
189 AutocompleteMatch ShortcutsProvider::ShortcutToACMatch( 194 AutocompleteMatch ShortcutsProvider::ShortcutToACMatch(
190 int relevance, 195 int relevance,
191 const string16& term_string, 196 const string16& term_string,
192 const history::ShortcutsBackend::Shortcut& shortcut) { 197 const history::ShortcutsBackend::Shortcut& shortcut) {
193 DCHECK(!term_string.empty()); 198 DCHECK(!term_string.empty());
194 AutocompleteMatch match(this, relevance, true, 199 AutocompleteMatch match(this, relevance, true,
195 AutocompleteMatchType::HISTORY_TITLE); 200 AutocompleteMatchType::HISTORY_TITLE);
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 // (1.0 / each 5 additional hits), up to a maximum of 5x as long. 369 // (1.0 / each 5 additional hits), up to a maximum of 5x as long.
365 const double kMaxDecaySpeedDivisor = 5.0; 370 const double kMaxDecaySpeedDivisor = 5.0;
366 const double kNumUsesPerDecaySpeedDivisorIncrement = 5.0; 371 const double kNumUsesPerDecaySpeedDivisorIncrement = 5.0;
367 double decay_divisor = std::min(kMaxDecaySpeedDivisor, 372 double decay_divisor = std::min(kMaxDecaySpeedDivisor,
368 (shortcut.number_of_hits + kNumUsesPerDecaySpeedDivisorIncrement - 1) / 373 (shortcut.number_of_hits + kNumUsesPerDecaySpeedDivisorIncrement - 1) /
369 kNumUsesPerDecaySpeedDivisorIncrement); 374 kNumUsesPerDecaySpeedDivisorIncrement);
370 375
371 return static_cast<int>((base_score / exp(decay_exponent / decay_divisor)) + 376 return static_cast<int>((base_score / exp(decay_exponent / decay_divisor)) +
372 0.5); 377 0.5);
373 } 378 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698