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/autocomplete_result.h" | 5 #include "components/omnibox/autocomplete_result.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <iterator> | 8 #include <iterator> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "components/metrics/proto/omnibox_event.pb.h" | 12 #include "components/metrics/proto/omnibox_event.pb.h" |
13 #include "components/metrics/proto/omnibox_input_type.pb.h" | 13 #include "components/metrics/proto/omnibox_input_type.pb.h" |
14 #include "components/omnibox/autocomplete_input.h" | 14 #include "components/omnibox/autocomplete_input.h" |
15 #include "components/omnibox/autocomplete_match.h" | 15 #include "components/omnibox/autocomplete_match.h" |
16 #include "components/omnibox/autocomplete_provider.h" | 16 #include "components/omnibox/autocomplete_provider.h" |
| 17 #include "components/omnibox/autocomplete_provider_client.h" |
17 #include "components/omnibox/omnibox_field_trial.h" | 18 #include "components/omnibox/omnibox_field_trial.h" |
18 #include "components/search/search.h" | 19 #include "components/search/search.h" |
19 #include "components/url_fixer/url_fixer.h" | 20 #include "components/url_fixer/url_fixer.h" |
20 | 21 |
21 using metrics::OmniboxEventProto; | 22 using metrics::OmniboxEventProto; |
22 | 23 |
23 namespace { | 24 namespace { |
24 | 25 |
25 // This class implements a special version of AutocompleteMatch::MoreRelevant | 26 // This class implements a special version of AutocompleteMatch::MoreRelevant |
26 // that allows matches of particular types to be demoted in AutocompleteResult. | 27 // that allows matches of particular types to be demoted in AutocompleteResult. |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 | 101 |
101 // static | 102 // static |
102 const size_t AutocompleteResult::kMaxMatches = 6; | 103 const size_t AutocompleteResult::kMaxMatches = 6; |
103 | 104 |
104 void AutocompleteResult::Selection::Clear() { | 105 void AutocompleteResult::Selection::Clear() { |
105 destination_url = GURL(); | 106 destination_url = GURL(); |
106 provider_affinity = NULL; | 107 provider_affinity = NULL; |
107 is_history_what_you_typed_match = false; | 108 is_history_what_you_typed_match = false; |
108 } | 109 } |
109 | 110 |
110 AutocompleteResult::AutocompleteResult() { | 111 AutocompleteResult::AutocompleteResult(AutocompleteProviderClient* client): |
| 112 client_(client) { |
111 // Reserve space for the max number of matches we'll show. | 113 // Reserve space for the max number of matches we'll show. |
112 matches_.reserve(kMaxMatches); | 114 matches_.reserve(kMaxMatches); |
113 | 115 |
114 // It's probably safe to do this in the initializer list, but there's little | 116 // It's probably safe to do this in the initializer list, but there's little |
115 // penalty to doing it here and it ensures our object is fully constructed | 117 // penalty to doing it here and it ensures our object is fully constructed |
116 // before calling member functions. | 118 // before calling member functions. |
117 default_match_ = end(); | 119 default_match_ = end(); |
118 } | 120 } |
119 | 121 |
120 AutocompleteResult::~AutocompleteResult() {} | 122 AutocompleteResult::~AutocompleteResult() {} |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 matches_.push_back(i); | 174 matches_.push_back(i); |
173 matches_.back().PossiblySwapContentsAndDescriptionForURLSuggestion(input); | 175 matches_.back().PossiblySwapContentsAndDescriptionForURLSuggestion(input); |
174 } | 176 } |
175 default_match_ = end(); | 177 default_match_ = end(); |
176 alternate_nav_url_ = GURL(); | 178 alternate_nav_url_ = GURL(); |
177 } | 179 } |
178 | 180 |
179 void AutocompleteResult::SortAndCull( | 181 void AutocompleteResult::SortAndCull( |
180 const AutocompleteInput& input, | 182 const AutocompleteInput& input, |
181 TemplateURLService* template_url_service) { | 183 TemplateURLService* template_url_service) { |
182 for (ACMatches::iterator i(matches_.begin()); i != matches_.end(); ++i) | 184 for (ACMatches::iterator i(matches_.begin()); i != matches_.end(); ++i) { |
183 i->ComputeStrippedDestinationURL(template_url_service); | 185 i->ComputeStrippedDestinationURL( |
| 186 input, client_->GetAcceptLanguages(), template_url_service); |
| 187 } |
184 | 188 |
185 DedupMatchesByDestination(input.current_page_classification(), true, | 189 DedupMatchesByDestination(input.current_page_classification(), true, |
186 &matches_); | 190 &matches_); |
187 | 191 |
188 // Sort and trim to the most relevant kMaxMatches matches. | 192 // Sort and trim to the most relevant kMaxMatches matches. |
189 size_t max_num_matches = std::min(kMaxMatches, matches_.size()); | 193 size_t max_num_matches = std::min(kMaxMatches, matches_.size()); |
190 CompareWithDemoteByType comparing_object(input.current_page_classification()); | 194 CompareWithDemoteByType comparing_object(input.current_page_classification()); |
191 std::sort(matches_.begin(), matches_.end(), comparing_object); | 195 std::sort(matches_.begin(), matches_.end(), comparing_object); |
192 if (!matches_.empty() && !matches_.begin()->allowed_to_be_default_match) { | 196 if (!matches_.empty() && !matches_.begin()->allowed_to_be_default_match) { |
193 // Top match is not allowed to be the default match. Find the most | 197 // Top match is not allowed to be the default match. Find the most |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 i != old_matches.rend() && delta > 0; ++i) { | 441 i != old_matches.rend() && delta > 0; ++i) { |
438 if (!HasMatchByDestination(*i, new_matches)) { | 442 if (!HasMatchByDestination(*i, new_matches)) { |
439 AutocompleteMatch match = *i; | 443 AutocompleteMatch match = *i; |
440 match.relevance = std::min(max_relevance, match.relevance); | 444 match.relevance = std::min(max_relevance, match.relevance); |
441 match.from_previous = true; | 445 match.from_previous = true; |
442 matches_.push_back(match); | 446 matches_.push_back(match); |
443 delta--; | 447 delta--; |
444 } | 448 } |
445 } | 449 } |
446 } | 450 } |
OLD | NEW |