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/command_line.h" |
10 #include "base/logging.h" | 11 #include "base/logging.h" |
11 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
12 #include "components/metrics/proto/omnibox_event.pb.h" | 13 #include "components/metrics/proto/omnibox_event.pb.h" |
13 #include "components/metrics/proto/omnibox_input_type.pb.h" | 14 #include "components/metrics/proto/omnibox_input_type.pb.h" |
14 #include "components/omnibox/autocomplete_input.h" | 15 #include "components/omnibox/autocomplete_input.h" |
15 #include "components/omnibox/autocomplete_match.h" | 16 #include "components/omnibox/autocomplete_match.h" |
16 #include "components/omnibox/autocomplete_provider.h" | 17 #include "components/omnibox/autocomplete_provider.h" |
17 #include "components/omnibox/omnibox_field_trial.h" | 18 #include "components/omnibox/omnibox_field_trial.h" |
| 19 #include "components/omnibox/omnibox_switches.h" |
18 #include "components/search/search.h" | 20 #include "components/search/search.h" |
19 #include "components/url_fixer/url_fixer.h" | 21 #include "components/url_fixer/url_fixer.h" |
20 | 22 |
21 using metrics::OmniboxEventProto; | 23 using metrics::OmniboxEventProto; |
22 | 24 |
23 namespace { | 25 namespace { |
24 | 26 |
25 // This class implements a special version of AutocompleteMatch::MoreRelevant | 27 // This class implements a special version of AutocompleteMatch::MoreRelevant |
26 // that allows matches of particular types to be demoted in AutocompleteResult. | 28 // that allows matches of particular types to be demoted in AutocompleteResult. |
27 class CompareWithDemoteByType { | 29 class CompareWithDemoteByType { |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 | 165 |
164 void AutocompleteResult::AppendMatches(const AutocompleteInput& input, | 166 void AutocompleteResult::AppendMatches(const AutocompleteInput& input, |
165 const ACMatches& matches) { | 167 const ACMatches& matches) { |
166 for (const auto& i : matches) { | 168 for (const auto& i : matches) { |
167 #ifndef NDEBUG | 169 #ifndef NDEBUG |
168 DCHECK_EQ(AutocompleteMatch::SanitizeString(i.contents), i.contents); | 170 DCHECK_EQ(AutocompleteMatch::SanitizeString(i.contents), i.contents); |
169 DCHECK_EQ(AutocompleteMatch::SanitizeString(i.description), | 171 DCHECK_EQ(AutocompleteMatch::SanitizeString(i.description), |
170 i.description); | 172 i.description); |
171 #endif | 173 #endif |
172 matches_.push_back(i); | 174 matches_.push_back(i); |
173 matches_.back().PossiblySwapContentsAndDescriptionForURLSuggestion(input); | 175 if (!AutocompleteMatch::IsSearchType(i.type) && !i.description.empty() && |
| 176 base::CommandLine::ForCurrentProcess()-> |
| 177 HasSwitch(switches::kEmphasizeTitlesInOmniboxDropdown) && |
| 178 ((input.type() == metrics::OmniboxInputType::QUERY) || |
| 179 (input.type() == metrics::OmniboxInputType::FORCED_QUERY)) && |
| 180 AutocompleteMatch::HasMatchStyle(i.description_class)) { |
| 181 matches_.back().swap_contents_and_description = true; |
| 182 } |
174 } | 183 } |
175 default_match_ = end(); | 184 default_match_ = end(); |
176 alternate_nav_url_ = GURL(); | 185 alternate_nav_url_ = GURL(); |
177 } | 186 } |
178 | 187 |
179 void AutocompleteResult::SortAndCull( | 188 void AutocompleteResult::SortAndCull( |
180 const AutocompleteInput& input, | 189 const AutocompleteInput& input, |
181 TemplateURLService* template_url_service) { | 190 TemplateURLService* template_url_service) { |
182 for (ACMatches::iterator i(matches_.begin()); i != matches_.end(); ++i) | 191 for (ACMatches::iterator i(matches_.begin()); i != matches_.end(); ++i) |
183 i->ComputeStrippedDestinationURL(template_url_service); | 192 i->ComputeStrippedDestinationURL(template_url_service); |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 i != old_matches.rend() && delta > 0; ++i) { | 446 i != old_matches.rend() && delta > 0; ++i) { |
438 if (!HasMatchByDestination(*i, new_matches)) { | 447 if (!HasMatchByDestination(*i, new_matches)) { |
439 AutocompleteMatch match = *i; | 448 AutocompleteMatch match = *i; |
440 match.relevance = std::min(max_relevance, match.relevance); | 449 match.relevance = std::min(max_relevance, match.relevance); |
441 match.from_previous = true; | 450 match.from_previous = true; |
442 matches_.push_back(match); | 451 matches_.push_back(match); |
443 delta--; | 452 delta--; |
444 } | 453 } |
445 } | 454 } |
446 } | 455 } |
OLD | NEW |