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