Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(279)

Side by Side Diff: chrome/browser/autocomplete/autocomplete_result.cc

Issue 303013002: Omnibox: Create Disable-Inlining Experiment (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Peter's comments Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/autocomplete/autocomplete_result_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/autocomplete/autocomplete_result.h" 5 #include "chrome/browser/autocomplete/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"
11 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
12 #include "chrome/browser/autocomplete/autocomplete_input.h" 13 #include "chrome/browser/autocomplete/autocomplete_input.h"
13 #include "chrome/browser/autocomplete/autocomplete_match.h" 14 #include "chrome/browser/autocomplete/autocomplete_match.h"
14 #include "chrome/browser/autocomplete/autocomplete_provider.h" 15 #include "chrome/browser/autocomplete/autocomplete_provider.h"
15 #include "chrome/browser/omnibox/omnibox_field_trial.h" 16 #include "chrome/browser/omnibox/omnibox_field_trial.h"
16 #include "chrome/browser/search/search.h" 17 #include "chrome/browser/search/search.h"
17 #include "chrome/common/autocomplete_match_type.h" 18 #include "chrome/common/autocomplete_match_type.h"
18 19
19 namespace { 20 namespace {
20 21
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 // first, so that when we call std::unique(), these are the ones that get 86 // first, so that when we call std::unique(), these are the ones that get
86 // preserved. 87 // preserved.
87 if (AutocompleteMatch::DestinationsEqual(elem1, elem2) || 88 if (AutocompleteMatch::DestinationsEqual(elem1, elem2) ||
88 (elem1.stripped_destination_url.is_empty() && 89 (elem1.stripped_destination_url.is_empty() &&
89 elem2.stripped_destination_url.is_empty())) { 90 elem2.stripped_destination_url.is_empty())) {
90 return demote_by_type_(elem1, elem2); 91 return demote_by_type_(elem1, elem2);
91 } 92 }
92 return elem1.stripped_destination_url < elem2.stripped_destination_url; 93 return elem1.stripped_destination_url < elem2.stripped_destination_url;
93 } 94 }
94 95
96 // Returns true if |match| is allowed to the default match taking into account
97 // whether we're supposed to (and able to) demote all matches with inline
98 // autocompletions.
99 bool AllowedToBeDefaultMatchAccountingForDisableInliningExperiment(
100 const AutocompleteMatch& match,
101 const bool has_legal_default_match_without_completion) {
102 return match.allowed_to_be_default_match &&
103 (!OmniboxFieldTrial::DisableInlining() ||
104 !has_legal_default_match_without_completion ||
105 match.inline_autocompletion.empty());
106 }
107
95 }; // namespace 108 }; // namespace
96 109
97 // static 110 // static
98 const size_t AutocompleteResult::kMaxMatches = 6; 111 const size_t AutocompleteResult::kMaxMatches = 6;
99 112
100 void AutocompleteResult::Selection::Clear() { 113 void AutocompleteResult::Selection::Clear() {
101 destination_url = GURL(); 114 destination_url = GURL();
102 provider_affinity = NULL; 115 provider_affinity = NULL;
103 is_history_what_you_typed_match = false; 116 is_history_what_you_typed_match = false;
104 } 117 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 } 183 }
171 184
172 void AutocompleteResult::SortAndCull(const AutocompleteInput& input, 185 void AutocompleteResult::SortAndCull(const AutocompleteInput& input,
173 Profile* profile) { 186 Profile* profile) {
174 for (ACMatches::iterator i(matches_.begin()); i != matches_.end(); ++i) 187 for (ACMatches::iterator i(matches_.begin()); i != matches_.end(); ++i)
175 i->ComputeStrippedDestinationURL(profile); 188 i->ComputeStrippedDestinationURL(profile);
176 189
177 DedupMatchesByDestination(input.current_page_classification(), true, 190 DedupMatchesByDestination(input.current_page_classification(), true,
178 &matches_); 191 &matches_);
179 192
193 // If the result set has at least one legal default match without an inline
194 // autocompletion, then in the disable inlining experiment it will be okay
195 // to demote all matches with inline autocompletions. On the other hand, if
196 // the experiment is active but there is no legal match without an inline
197 // autocompletion, then we'll pretend the experiment is not active and not
198 // demote the matches with an inline autocompletion. In other words, an
199 // alternate name for this variable is
200 // allowed_to_demote_matches_with_inline_autocompletion.
201 bool has_legal_default_match_without_completion = false;
202 for (AutocompleteResult::iterator it = matches_.begin();
203 (it != matches_.end()) && !has_legal_default_match_without_completion;
204 ++it) {
205 if (it->allowed_to_be_default_match && it->inline_autocompletion.empty())
206 has_legal_default_match_without_completion = true;
207 }
208 UMA_HISTOGRAM_BOOLEAN("Omnibox.HasLegalDefaultMatchWithoutCompletion",
209 has_legal_default_match_without_completion);
210
180 // Sort and trim to the most relevant kMaxMatches matches. 211 // Sort and trim to the most relevant kMaxMatches matches.
181 size_t max_num_matches = std::min(kMaxMatches, matches_.size()); 212 size_t max_num_matches = std::min(kMaxMatches, matches_.size());
182 CompareWithDemoteByType comparing_object(input.current_page_classification()); 213 CompareWithDemoteByType comparing_object(input.current_page_classification());
183 std::sort(matches_.begin(), matches_.end(), comparing_object); 214 std::sort(matches_.begin(), matches_.end(), comparing_object);
184 if (!matches_.empty() && !matches_.begin()->allowed_to_be_default_match) { 215 if (!matches_.empty() &&
216 !AllowedToBeDefaultMatchAccountingForDisableInliningExperiment(
217 *matches_.begin(), has_legal_default_match_without_completion)) {
185 // Top match is not allowed to be the default match. Find the most 218 // Top match is not allowed to be the default match. Find the most
186 // relevant legal match and shift it to the front. 219 // relevant legal match and shift it to the front.
187 for (AutocompleteResult::iterator it = matches_.begin() + 1; 220 for (AutocompleteResult::iterator it = matches_.begin() + 1;
188 it != matches_.end(); ++it) { 221 it != matches_.end(); ++it) {
189 if (it->allowed_to_be_default_match) { 222 if (AllowedToBeDefaultMatchAccountingForDisableInliningExperiment(
223 *it, has_legal_default_match_without_completion)) {
190 std::rotate(matches_.begin(), it, it + 1); 224 std::rotate(matches_.begin(), it, it + 1);
191 break; 225 break;
192 } 226 }
193 } 227 }
194 } 228 }
195 // In the process of trimming, drop all matches with a demoted relevance 229 // In the process of trimming, drop all matches with a demoted relevance
196 // score of 0. 230 // score of 0.
197 size_t num_matches; 231 size_t num_matches;
198 for (num_matches = 0u; (num_matches < max_num_matches) && 232 for (num_matches = 0u; (num_matches < max_num_matches) &&
199 (comparing_object.GetDemotedRelevance(*match_at(num_matches)) > 0); 233 (comparing_object.GetDemotedRelevance(*match_at(num_matches)) > 0);
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 i != old_matches.rend() && delta > 0; ++i) { 457 i != old_matches.rend() && delta > 0; ++i) {
424 if (!HasMatchByDestination(*i, new_matches)) { 458 if (!HasMatchByDestination(*i, new_matches)) {
425 AutocompleteMatch match = *i; 459 AutocompleteMatch match = *i;
426 match.relevance = std::min(max_relevance, match.relevance); 460 match.relevance = std::min(max_relevance, match.relevance);
427 match.from_previous = true; 461 match.from_previous = true;
428 AddMatch(page_classification, match); 462 AddMatch(page_classification, match);
429 delta--; 463 delta--;
430 } 464 }
431 } 465 }
432 } 466 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/autocomplete/autocomplete_result_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698