OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/omnibox/browser/autocomplete_result.h" | 5 #include "components/omnibox/browser/autocomplete_result.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <iterator> | 8 #include <iterator> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/metrics/field_trial_params.h" |
12 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
13 #include "components/metrics/proto/omnibox_event.pb.h" | 14 #include "components/metrics/proto/omnibox_event.pb.h" |
14 #include "components/metrics/proto/omnibox_input_type.pb.h" | 15 #include "components/metrics/proto/omnibox_input_type.pb.h" |
15 #include "components/omnibox/browser/autocomplete_input.h" | 16 #include "components/omnibox/browser/autocomplete_input.h" |
16 #include "components/omnibox/browser/autocomplete_match.h" | 17 #include "components/omnibox/browser/autocomplete_match.h" |
17 #include "components/omnibox/browser/autocomplete_provider.h" | 18 #include "components/omnibox/browser/autocomplete_provider.h" |
18 #include "components/omnibox/browser/match_compare.h" | 19 #include "components/omnibox/browser/match_compare.h" |
19 #include "components/omnibox/browser/omnibox_field_trial.h" | 20 #include "components/omnibox/browser/omnibox_field_trial.h" |
20 #include "components/omnibox/browser/omnibox_switches.h" | 21 #include "components/omnibox/browser/omnibox_switches.h" |
21 #include "components/url_formatter/url_fixer.h" | 22 #include "components/url_formatter/url_fixer.h" |
22 | 23 |
23 // static | 24 // static |
24 const size_t AutocompleteResult::kMaxMatches = 6; | 25 size_t AutocompleteResult::GetMaxMatches() { |
| 26 constexpr size_t kDefaultMaxAutocompleteMatches = 6; |
| 27 |
| 28 return base::GetFieldTrialParamByFeatureAsInt( |
| 29 omnibox::kUIExperimentMaxAutocompleteMatches, |
| 30 OmniboxFieldTrial::kUIMaxAutocompleteMatchesParam, |
| 31 kDefaultMaxAutocompleteMatches); |
| 32 } |
25 | 33 |
26 void AutocompleteResult::Selection::Clear() { | 34 void AutocompleteResult::Selection::Clear() { |
27 destination_url = GURL(); | 35 destination_url = GURL(); |
28 provider_affinity = NULL; | 36 provider_affinity = NULL; |
29 is_history_what_you_typed_match = false; | 37 is_history_what_you_typed_match = false; |
30 } | 38 } |
31 | 39 |
32 AutocompleteResult::AutocompleteResult() { | 40 AutocompleteResult::AutocompleteResult() { |
33 // Reserve space for the max number of matches we'll show. | 41 // Reserve space for the max number of matches we'll show. |
34 matches_.reserve(kMaxMatches); | 42 matches_.reserve(GetMaxMatches()); |
35 | 43 |
36 // It's probably safe to do this in the initializer list, but there's little | 44 // It's probably safe to do this in the initializer list, but there's little |
37 // penalty to doing it here and it ensures our object is fully constructed | 45 // penalty to doing it here and it ensures our object is fully constructed |
38 // before calling member functions. | 46 // before calling member functions. |
39 default_match_ = end(); | 47 default_match_ = end(); |
40 } | 48 } |
41 | 49 |
42 AutocompleteResult::~AutocompleteResult() {} | 50 AutocompleteResult::~AutocompleteResult() {} |
43 | 51 |
44 void AutocompleteResult::CopyOldMatches( | 52 void AutocompleteResult::CopyOldMatches( |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 } | 130 } |
123 | 131 |
124 void AutocompleteResult::SortAndCull( | 132 void AutocompleteResult::SortAndCull( |
125 const AutocompleteInput& input, | 133 const AutocompleteInput& input, |
126 TemplateURLService* template_url_service) { | 134 TemplateURLService* template_url_service) { |
127 for (ACMatches::iterator i(matches_.begin()); i != matches_.end(); ++i) | 135 for (ACMatches::iterator i(matches_.begin()); i != matches_.end(); ++i) |
128 i->ComputeStrippedDestinationURL(input, template_url_service); | 136 i->ComputeStrippedDestinationURL(input, template_url_service); |
129 | 137 |
130 SortAndDedupMatches(input.current_page_classification(), &matches_); | 138 SortAndDedupMatches(input.current_page_classification(), &matches_); |
131 | 139 |
132 // Sort and trim to the most relevant kMaxMatches matches. | 140 // Sort and trim to the most relevant GetMaxMatches() matches. |
133 size_t max_num_matches = std::min(kMaxMatches, matches_.size()); | 141 size_t max_num_matches = std::min(GetMaxMatches(), matches_.size()); |
134 CompareWithDemoteByType<AutocompleteMatch> comparing_object( | 142 CompareWithDemoteByType<AutocompleteMatch> comparing_object( |
135 input.current_page_classification()); | 143 input.current_page_classification()); |
136 std::sort(matches_.begin(), matches_.end(), comparing_object); | 144 std::sort(matches_.begin(), matches_.end(), comparing_object); |
137 // Top match is not allowed to be the default match. Find the most | 145 // Top match is not allowed to be the default match. Find the most |
138 // relevant legal match and shift it to the front. | 146 // relevant legal match and shift it to the front. |
139 ACMatches::iterator it = FindTopMatch(&matches_); | 147 ACMatches::iterator it = FindTopMatch(&matches_); |
140 if (it != matches_.end()) | 148 if (it != matches_.end()) |
141 std::rotate(matches_.begin(), it, it + 1); | 149 std::rotate(matches_.begin(), it, it + 1); |
142 // In the process of trimming, drop all matches with a demoted relevance | 150 // In the process of trimming, drop all matches with a demoted relevance |
143 // score of 0. | 151 // score of 0. |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 i != old_matches.rend() && delta > 0; ++i) { | 406 i != old_matches.rend() && delta > 0; ++i) { |
399 if (!HasMatchByDestination(*i, new_matches)) { | 407 if (!HasMatchByDestination(*i, new_matches)) { |
400 AutocompleteMatch match = *i; | 408 AutocompleteMatch match = *i; |
401 match.relevance = std::min(max_relevance, match.relevance); | 409 match.relevance = std::min(max_relevance, match.relevance); |
402 match.from_previous = true; | 410 match.from_previous = true; |
403 matches_.push_back(match); | 411 matches_.push_back(match); |
404 delta--; | 412 delta--; |
405 } | 413 } |
406 } | 414 } |
407 } | 415 } |
OLD | NEW |