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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 matches_.push_back(ShortcutToACMatch(relevance, term_string, it->second)); | 168 matches_.push_back(ShortcutToACMatch(relevance, term_string, it->second)); |
169 } | 169 } |
170 std::partial_sort(matches_.begin(), | 170 std::partial_sort(matches_.begin(), |
171 matches_.begin() + | 171 matches_.begin() + |
172 std::min(AutocompleteProvider::kMaxMatches, matches_.size()), | 172 std::min(AutocompleteProvider::kMaxMatches, matches_.size()), |
173 matches_.end(), &AutocompleteMatch::MoreRelevant); | 173 matches_.end(), &AutocompleteMatch::MoreRelevant); |
174 if (matches_.size() > AutocompleteProvider::kMaxMatches) { | 174 if (matches_.size() > AutocompleteProvider::kMaxMatches) { |
175 matches_.erase(matches_.begin() + AutocompleteProvider::kMaxMatches, | 175 matches_.erase(matches_.begin() + AutocompleteProvider::kMaxMatches, |
176 matches_.end()); | 176 matches_.end()); |
177 } | 177 } |
178 // Reset relevance scores to guarantee no results are given an | 178 // Reset relevance scores to guarantee no match is given a score that may |
179 // inlineable score and all scores are decreasing (but not do assign | 179 // allow it to become the highest ranked match (i.e., the default match) |
180 // any scores below 1). | 180 // unless the omnibox will reorder matches as necessary to correct the |
181 max_relevance = AutocompleteResult::kLowestDefaultScore - 1; | 181 // problem. (Shortcuts matches are sometimes not inline-autocompletable |
182 for (ACMatches::iterator it = matches_.begin(); it != matches_.end(); ++it) { | 182 // and, even when they are, the ShortcutsProvider does not bother to set |
183 max_relevance = std::min(max_relevance, it->relevance); | 183 // |inline_autocompletion|. Hence these matches can never be displayed |
184 it->relevance = max_relevance; | 184 // corectly in the omnibox as the default match.) In the process of |
185 if (max_relevance > 1) | 185 // resetting scores, guarantee that all scores are decreasing (but do |
186 --max_relevance; | 186 // not assign any scores below 1). |
| 187 if (!OmniboxFieldTrial::ReorderForLegalDefaultMatch( |
| 188 input.current_page_classification())) { |
| 189 int max_relevance = AutocompleteResult::kLowestDefaultScore - 1; |
| 190 for (ACMatches::iterator it = matches_.begin(); it != matches_.end(); |
| 191 ++it) { |
| 192 max_relevance = std::min(max_relevance, it->relevance); |
| 193 it->relevance = max_relevance; |
| 194 if (max_relevance > 1) |
| 195 --max_relevance; |
| 196 } |
187 } | 197 } |
188 } | 198 } |
189 | 199 |
190 AutocompleteMatch ShortcutsProvider::ShortcutToACMatch( | 200 AutocompleteMatch ShortcutsProvider::ShortcutToACMatch( |
191 int relevance, | 201 int relevance, |
192 const string16& term_string, | 202 const string16& term_string, |
193 const history::ShortcutsBackend::Shortcut& shortcut) { | 203 const history::ShortcutsBackend::Shortcut& shortcut) { |
194 DCHECK(!term_string.empty()); | 204 DCHECK(!term_string.empty()); |
195 AutocompleteMatch match(this, relevance, true, | 205 AutocompleteMatch match(this, relevance, true, |
196 AutocompleteMatchType::HISTORY_TITLE); | 206 AutocompleteMatchType::HISTORY_TITLE); |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 // (1.0 / each 5 additional hits), up to a maximum of 5x as long. | 376 // (1.0 / each 5 additional hits), up to a maximum of 5x as long. |
367 const double kMaxDecaySpeedDivisor = 5.0; | 377 const double kMaxDecaySpeedDivisor = 5.0; |
368 const double kNumUsesPerDecaySpeedDivisorIncrement = 5.0; | 378 const double kNumUsesPerDecaySpeedDivisorIncrement = 5.0; |
369 double decay_divisor = std::min(kMaxDecaySpeedDivisor, | 379 double decay_divisor = std::min(kMaxDecaySpeedDivisor, |
370 (shortcut.number_of_hits + kNumUsesPerDecaySpeedDivisorIncrement - 1) / | 380 (shortcut.number_of_hits + kNumUsesPerDecaySpeedDivisorIncrement - 1) / |
371 kNumUsesPerDecaySpeedDivisorIncrement); | 381 kNumUsesPerDecaySpeedDivisorIncrement); |
372 | 382 |
373 return static_cast<int>((base_score / exp(decay_exponent / decay_divisor)) + | 383 return static_cast<int>((base_score / exp(decay_exponent / decay_divisor)) + |
374 0.5); | 384 0.5); |
375 } | 385 } |
OLD | NEW |