| 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/metrics/histogram.h" | |
| 12 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 13 #include "components/metrics/proto/omnibox_event.pb.h" | 12 #include "components/metrics/proto/omnibox_event.pb.h" |
| 14 #include "components/metrics/proto/omnibox_input_type.pb.h" | 13 #include "components/metrics/proto/omnibox_input_type.pb.h" |
| 15 #include "components/omnibox/autocomplete_input.h" | 14 #include "components/omnibox/autocomplete_input.h" |
| 16 #include "components/omnibox/autocomplete_match.h" | 15 #include "components/omnibox/autocomplete_match.h" |
| 17 #include "components/omnibox/autocomplete_provider.h" | 16 #include "components/omnibox/autocomplete_provider.h" |
| 18 #include "components/omnibox/omnibox_field_trial.h" | 17 #include "components/omnibox/omnibox_field_trial.h" |
| 19 #include "components/search/search.h" | 18 #include "components/search/search.h" |
| 20 #include "components/url_fixer/url_fixer.h" | 19 #include "components/url_fixer/url_fixer.h" |
| 21 | 20 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 // first, so that when we call std::unique(), these are the ones that get | 89 // first, so that when we call std::unique(), these are the ones that get |
| 91 // preserved. | 90 // preserved. |
| 92 if (AutocompleteMatch::DestinationsEqual(elem1, elem2) || | 91 if (AutocompleteMatch::DestinationsEqual(elem1, elem2) || |
| 93 (elem1.stripped_destination_url.is_empty() && | 92 (elem1.stripped_destination_url.is_empty() && |
| 94 elem2.stripped_destination_url.is_empty())) { | 93 elem2.stripped_destination_url.is_empty())) { |
| 95 return demote_by_type_(elem1, elem2); | 94 return demote_by_type_(elem1, elem2); |
| 96 } | 95 } |
| 97 return elem1.stripped_destination_url < elem2.stripped_destination_url; | 96 return elem1.stripped_destination_url < elem2.stripped_destination_url; |
| 98 } | 97 } |
| 99 | 98 |
| 100 // Returns true if |match| is allowed to the default match taking into account | |
| 101 // whether we're supposed to (and able to) demote all matches with inline | |
| 102 // autocompletions. | |
| 103 bool AllowedToBeDefaultMatchAccountingForDisableInliningExperiment( | |
| 104 const AutocompleteMatch& match, | |
| 105 const bool has_legal_default_match_without_completion) { | |
| 106 return match.allowed_to_be_default_match && | |
| 107 (!OmniboxFieldTrial::DisableInlining() || | |
| 108 !has_legal_default_match_without_completion || | |
| 109 match.inline_autocompletion.empty()); | |
| 110 } | |
| 111 | |
| 112 }; // namespace | 99 }; // namespace |
| 113 | 100 |
| 114 // static | 101 // static |
| 115 const size_t AutocompleteResult::kMaxMatches = 6; | 102 const size_t AutocompleteResult::kMaxMatches = 6; |
| 116 | 103 |
| 117 void AutocompleteResult::Selection::Clear() { | 104 void AutocompleteResult::Selection::Clear() { |
| 118 destination_url = GURL(); | 105 destination_url = GURL(); |
| 119 provider_affinity = NULL; | 106 provider_affinity = NULL; |
| 120 is_history_what_you_typed_match = false; | 107 is_history_what_you_typed_match = false; |
| 121 } | 108 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 | 176 |
| 190 void AutocompleteResult::SortAndCull( | 177 void AutocompleteResult::SortAndCull( |
| 191 const AutocompleteInput& input, | 178 const AutocompleteInput& input, |
| 192 TemplateURLService* template_url_service) { | 179 TemplateURLService* template_url_service) { |
| 193 for (ACMatches::iterator i(matches_.begin()); i != matches_.end(); ++i) | 180 for (ACMatches::iterator i(matches_.begin()); i != matches_.end(); ++i) |
| 194 i->ComputeStrippedDestinationURL(template_url_service); | 181 i->ComputeStrippedDestinationURL(template_url_service); |
| 195 | 182 |
| 196 DedupMatchesByDestination(input.current_page_classification(), true, | 183 DedupMatchesByDestination(input.current_page_classification(), true, |
| 197 &matches_); | 184 &matches_); |
| 198 | 185 |
| 199 // If the result set has at least one legal default match without an inline | |
| 200 // autocompletion, then in the disable inlining experiment it will be okay | |
| 201 // to demote all matches with inline autocompletions. On the other hand, if | |
| 202 // the experiment is active but there is no legal match without an inline | |
| 203 // autocompletion, then we'll pretend the experiment is not active and not | |
| 204 // demote the matches with an inline autocompletion. In other words, an | |
| 205 // alternate name for this variable is | |
| 206 // allowed_to_demote_matches_with_inline_autocompletion. | |
| 207 bool has_legal_default_match_without_completion = false; | |
| 208 for (AutocompleteResult::iterator it = matches_.begin(); | |
| 209 (it != matches_.end()) && !has_legal_default_match_without_completion; | |
| 210 ++it) { | |
| 211 if (it->allowed_to_be_default_match && it->inline_autocompletion.empty()) | |
| 212 has_legal_default_match_without_completion = true; | |
| 213 } | |
| 214 UMA_HISTOGRAM_BOOLEAN("Omnibox.HasLegalDefaultMatchWithoutCompletion", | |
| 215 has_legal_default_match_without_completion); | |
| 216 | |
| 217 // Sort and trim to the most relevant kMaxMatches matches. | 186 // Sort and trim to the most relevant kMaxMatches matches. |
| 218 size_t max_num_matches = std::min(kMaxMatches, matches_.size()); | 187 size_t max_num_matches = std::min(kMaxMatches, matches_.size()); |
| 219 CompareWithDemoteByType comparing_object(input.current_page_classification()); | 188 CompareWithDemoteByType comparing_object(input.current_page_classification()); |
| 220 std::sort(matches_.begin(), matches_.end(), comparing_object); | 189 std::sort(matches_.begin(), matches_.end(), comparing_object); |
| 221 if (!matches_.empty() && | 190 if (!matches_.empty() && !matches_.begin()->allowed_to_be_default_match) { |
| 222 !AllowedToBeDefaultMatchAccountingForDisableInliningExperiment( | |
| 223 *matches_.begin(), has_legal_default_match_without_completion)) { | |
| 224 // Top match is not allowed to be the default match. Find the most | 191 // Top match is not allowed to be the default match. Find the most |
| 225 // relevant legal match and shift it to the front. | 192 // relevant legal match and shift it to the front. |
| 226 for (AutocompleteResult::iterator it = matches_.begin() + 1; | 193 for (AutocompleteResult::iterator it = matches_.begin() + 1; |
| 227 it != matches_.end(); ++it) { | 194 it != matches_.end(); ++it) { |
| 228 if (AllowedToBeDefaultMatchAccountingForDisableInliningExperiment( | 195 if (it->allowed_to_be_default_match) { |
| 229 *it, has_legal_default_match_without_completion)) { | |
| 230 std::rotate(matches_.begin(), it, it + 1); | 196 std::rotate(matches_.begin(), it, it + 1); |
| 231 break; | 197 break; |
| 232 } | 198 } |
| 233 } | 199 } |
| 234 } | 200 } |
| 235 // In the process of trimming, drop all matches with a demoted relevance | 201 // In the process of trimming, drop all matches with a demoted relevance |
| 236 // score of 0. | 202 // score of 0. |
| 237 size_t num_matches; | 203 size_t num_matches; |
| 238 for (num_matches = 0u; (num_matches < max_num_matches) && | 204 for (num_matches = 0u; (num_matches < max_num_matches) && |
| 239 (comparing_object.GetDemotedRelevance(*match_at(num_matches)) > 0); | 205 (comparing_object.GetDemotedRelevance(*match_at(num_matches)) > 0); |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 i != old_matches.rend() && delta > 0; ++i) { | 423 i != old_matches.rend() && delta > 0; ++i) { |
| 458 if (!HasMatchByDestination(*i, new_matches)) { | 424 if (!HasMatchByDestination(*i, new_matches)) { |
| 459 AutocompleteMatch match = *i; | 425 AutocompleteMatch match = *i; |
| 460 match.relevance = std::min(max_relevance, match.relevance); | 426 match.relevance = std::min(max_relevance, match.relevance); |
| 461 match.from_previous = true; | 427 match.from_previous = true; |
| 462 matches_.push_back(match); | 428 matches_.push_back(match); |
| 463 delta--; | 429 delta--; |
| 464 } | 430 } |
| 465 } | 431 } |
| 466 } | 432 } |
| OLD | NEW |