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 return base::GetFieldTrialParamByFeatureAsInt( | |
27 omnibox::kUIExperimentMaxAutocompleteMatches, | |
28 OmniboxFieldTrial::kUIMaxAutocompleteMatchesParam, 6); | |
Peter Kasting
2017/05/10 22:08:05
Nit: For clarity, pull this 6 out as a named const
tommycli
2017/05/10 22:44:29
Done.
| |
29 } | |
25 | 30 |
26 void AutocompleteResult::Selection::Clear() { | 31 void AutocompleteResult::Selection::Clear() { |
27 destination_url = GURL(); | 32 destination_url = GURL(); |
28 provider_affinity = NULL; | 33 provider_affinity = NULL; |
29 is_history_what_you_typed_match = false; | 34 is_history_what_you_typed_match = false; |
30 } | 35 } |
31 | 36 |
32 AutocompleteResult::AutocompleteResult() { | 37 AutocompleteResult::AutocompleteResult() { |
33 // Reserve space for the max number of matches we'll show. | 38 // Reserve space for the max number of matches we'll show. |
34 matches_.reserve(kMaxMatches); | 39 matches_.reserve(GetMaxMatches()); |
35 | 40 |
36 // It's probably safe to do this in the initializer list, but there's little | 41 // 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 | 42 // penalty to doing it here and it ensures our object is fully constructed |
38 // before calling member functions. | 43 // before calling member functions. |
39 default_match_ = end(); | 44 default_match_ = end(); |
40 } | 45 } |
41 | 46 |
42 AutocompleteResult::~AutocompleteResult() {} | 47 AutocompleteResult::~AutocompleteResult() {} |
43 | 48 |
44 void AutocompleteResult::CopyOldMatches( | 49 void AutocompleteResult::CopyOldMatches( |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 } | 127 } |
123 | 128 |
124 void AutocompleteResult::SortAndCull( | 129 void AutocompleteResult::SortAndCull( |
125 const AutocompleteInput& input, | 130 const AutocompleteInput& input, |
126 TemplateURLService* template_url_service) { | 131 TemplateURLService* template_url_service) { |
127 for (ACMatches::iterator i(matches_.begin()); i != matches_.end(); ++i) | 132 for (ACMatches::iterator i(matches_.begin()); i != matches_.end(); ++i) |
128 i->ComputeStrippedDestinationURL(input, template_url_service); | 133 i->ComputeStrippedDestinationURL(input, template_url_service); |
129 | 134 |
130 SortAndDedupMatches(input.current_page_classification(), &matches_); | 135 SortAndDedupMatches(input.current_page_classification(), &matches_); |
131 | 136 |
132 // Sort and trim to the most relevant kMaxMatches matches. | 137 // Sort and trim to the most relevant GetMaxMatches() matches. |
133 size_t max_num_matches = std::min(kMaxMatches, matches_.size()); | 138 size_t max_num_matches = std::min(GetMaxMatches(), matches_.size()); |
134 CompareWithDemoteByType<AutocompleteMatch> comparing_object( | 139 CompareWithDemoteByType<AutocompleteMatch> comparing_object( |
135 input.current_page_classification()); | 140 input.current_page_classification()); |
136 std::sort(matches_.begin(), matches_.end(), comparing_object); | 141 std::sort(matches_.begin(), matches_.end(), comparing_object); |
137 // Top match is not allowed to be the default match. Find the most | 142 // Top match is not allowed to be the default match. Find the most |
138 // relevant legal match and shift it to the front. | 143 // relevant legal match and shift it to the front. |
139 ACMatches::iterator it = FindTopMatch(&matches_); | 144 ACMatches::iterator it = FindTopMatch(&matches_); |
140 if (it != matches_.end()) | 145 if (it != matches_.end()) |
141 std::rotate(matches_.begin(), it, it + 1); | 146 std::rotate(matches_.begin(), it, it + 1); |
142 // In the process of trimming, drop all matches with a demoted relevance | 147 // In the process of trimming, drop all matches with a demoted relevance |
143 // score of 0. | 148 // score of 0. |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
398 i != old_matches.rend() && delta > 0; ++i) { | 403 i != old_matches.rend() && delta > 0; ++i) { |
399 if (!HasMatchByDestination(*i, new_matches)) { | 404 if (!HasMatchByDestination(*i, new_matches)) { |
400 AutocompleteMatch match = *i; | 405 AutocompleteMatch match = *i; |
401 match.relevance = std::min(max_relevance, match.relevance); | 406 match.relevance = std::min(max_relevance, match.relevance); |
402 match.from_previous = true; | 407 match.from_previous = true; |
403 matches_.push_back(match); | 408 matches_.push_back(match); |
404 delta--; | 409 delta--; |
405 } | 410 } |
406 } | 411 } |
407 } | 412 } |
OLD | NEW |