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

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: Harry's comments Created 7 years, 4 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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 matches_.push_back(ShortcutToACMatch(relevance, term_string, it->second)); 167 matches_.push_back(ShortcutToACMatch(relevance, term_string, it->second));
168 } 168 }
169 std::partial_sort(matches_.begin(), 169 std::partial_sort(matches_.begin(),
170 matches_.begin() + 170 matches_.begin() +
171 std::min(AutocompleteProvider::kMaxMatches, matches_.size()), 171 std::min(AutocompleteProvider::kMaxMatches, matches_.size()),
172 matches_.end(), &AutocompleteMatch::MoreRelevant); 172 matches_.end(), &AutocompleteMatch::MoreRelevant);
173 if (matches_.size() > AutocompleteProvider::kMaxMatches) { 173 if (matches_.size() > AutocompleteProvider::kMaxMatches) {
174 matches_.erase(matches_.begin() + AutocompleteProvider::kMaxMatches, 174 matches_.erase(matches_.begin() + AutocompleteProvider::kMaxMatches,
175 matches_.end()); 175 matches_.end());
176 } 176 }
177 // Reset relevance scores to guarantee no results are given an 177 // Reset relevance scores to guarantee no result is given a score that may
Peter Kasting 2013/08/06 22:56:16 Nit: result -> match
Mark P 2013/08/07 00:44:31 Done.
178 // inlineable score and all scores are decreasing (but not do assign 178 // allow it to become the highest ranked match (i.e., the default match)
179 // any scores below 1). 179 // unless the omnibox will reorder matches as necessary to correct the
180 int max_relevance = AutocompleteResult::kLowestDefaultScore - 1; 180 // problem. In the process of resetting scores, guarantee that all scores
Peter Kasting 2013/08/06 22:56:16 Nit: You may want to say why this is a problem (or
Mark P 2013/08/07 00:44:31 Added a comment. Not sure if it help or hurts.
181 for (ACMatches::iterator it = matches_.begin(); it != matches_.end(); ++it) { 181 // are decreasing (but not do assign any scores below 1).
182 max_relevance = std::min(max_relevance, it->relevance); 182 if (!OmniboxFieldTrial::ReorderForLegalDefaultMatch(
183 it->relevance = max_relevance; 183 input.current_page_classification())) {
Peter Kasting 2013/08/06 22:56:16 Nit: Indent 4, not 8
Mark P 2013/08/07 00:44:31 Done.
184 if (max_relevance > 1) 184 int max_relevance = AutocompleteResult::kLowestDefaultScore - 1;
185 --max_relevance; 185 for (ACMatches::iterator it = matches_.begin(); it != matches_.end();
186 ++it) {
187 max_relevance = std::min(max_relevance, it->relevance);
188 it->relevance = max_relevance;
189 if (max_relevance > 1)
190 --max_relevance;
191 }
186 } 192 }
187 } 193 }
188 194
189 AutocompleteMatch ShortcutsProvider::ShortcutToACMatch( 195 AutocompleteMatch ShortcutsProvider::ShortcutToACMatch(
190 int relevance, 196 int relevance,
191 const string16& term_string, 197 const string16& term_string,
192 const history::ShortcutsBackend::Shortcut& shortcut) { 198 const history::ShortcutsBackend::Shortcut& shortcut) {
193 DCHECK(!term_string.empty()); 199 DCHECK(!term_string.empty());
194 AutocompleteMatch match(this, relevance, true, 200 AutocompleteMatch match(this, relevance, true,
195 AutocompleteMatchType::HISTORY_TITLE); 201 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. 370 // (1.0 / each 5 additional hits), up to a maximum of 5x as long.
365 const double kMaxDecaySpeedDivisor = 5.0; 371 const double kMaxDecaySpeedDivisor = 5.0;
366 const double kNumUsesPerDecaySpeedDivisorIncrement = 5.0; 372 const double kNumUsesPerDecaySpeedDivisorIncrement = 5.0;
367 double decay_divisor = std::min(kMaxDecaySpeedDivisor, 373 double decay_divisor = std::min(kMaxDecaySpeedDivisor,
368 (shortcut.number_of_hits + kNumUsesPerDecaySpeedDivisorIncrement - 1) / 374 (shortcut.number_of_hits + kNumUsesPerDecaySpeedDivisorIncrement - 1) /
369 kNumUsesPerDecaySpeedDivisorIncrement); 375 kNumUsesPerDecaySpeedDivisorIncrement);
370 376
371 return static_cast<int>((base_score / exp(decay_exponent / decay_divisor)) + 377 return static_cast<int>((base_score / exp(decay_exponent / decay_divisor)) +
372 0.5); 378 0.5);
373 } 379 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698