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

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: adds test 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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 } 171 }
171 172
172 void AutocompleteResult::SortAndCull(const AutocompleteInput& input, 173 void AutocompleteResult::SortAndCull(const AutocompleteInput& input,
173 Profile* profile) { 174 Profile* profile) {
174 for (ACMatches::iterator i(matches_.begin()); i != matches_.end(); ++i) 175 for (ACMatches::iterator i(matches_.begin()); i != matches_.end(); ++i)
175 i->ComputeStrippedDestinationURL(profile); 176 i->ComputeStrippedDestinationURL(profile);
176 177
177 DedupMatchesByDestination(input.current_page_classification(), true, 178 DedupMatchesByDestination(input.current_page_classification(), true,
178 &matches_); 179 &matches_);
179 180
181 // If the result set has at least one legal default match without an
182 // inline autocompletion, then in the disable inlining experiment it's
Peter Kasting 2014/05/29 21:30:49 Nit: it's -> it
Mark P 2014/05/30 00:03:58 Done. Also adjusted wrapping.
183 // will be okay to demote all matches with inline autocompletions. On
184 // the other hand, if the experiment is active but there is no legal
185 // match without an inline autocompletion, then we'll pretend the
186 // experiment is not active and not demote the matches with an inline
187 // autocompletion. In other words, an alternate name for this variable is
188 // allowed_to_demote_matches_with_inline_autocompletion.
189 bool has_legal_default_match_without_completion = false;
190 for (AutocompleteResult::iterator it = matches_.begin();
191 (it != matches_.end()) && !has_legal_default_match_without_completion;
192 ++it) {
193 if (it->allowed_to_be_default_match && it->inline_autocompletion.empty())
194 has_legal_default_match_without_completion = true;
195 }
196 UMA_HISTOGRAM_BOOLEAN("Omnibox.HasLegalDefaultMatchWithoutCompletion",
197 has_legal_default_match_without_completion);
198
180 // Sort and trim to the most relevant kMaxMatches matches. 199 // Sort and trim to the most relevant kMaxMatches matches.
181 size_t max_num_matches = std::min(kMaxMatches, matches_.size()); 200 size_t max_num_matches = std::min(kMaxMatches, matches_.size());
182 CompareWithDemoteByType comparing_object(input.current_page_classification()); 201 CompareWithDemoteByType comparing_object(input.current_page_classification());
183 std::sort(matches_.begin(), matches_.end(), comparing_object); 202 std::sort(matches_.begin(), matches_.end(), comparing_object);
184 if (!matches_.empty() && !matches_.begin()->allowed_to_be_default_match) { 203 if (!matches_.empty() &&
204 (!matches_.begin()->allowed_to_be_default_match ||
Peter Kasting 2014/05/29 21:30:49 I might create a small helper functions which does
Mark P 2014/05/30 00:03:58 Done. The function name is awkward though. If yo
205 (OmniboxFieldTrial::DisableInlining() &&
206 has_legal_default_match_without_completion &&
207 !matches_.begin()->inline_autocompletion.empty()))) {
185 // Top match is not allowed to be the default match. Find the most 208 // Top match is not allowed to be the default match. Find the most
186 // relevant legal match and shift it to the front. 209 // relevant legal match and shift it to the front.
187 for (AutocompleteResult::iterator it = matches_.begin() + 1; 210 for (AutocompleteResult::iterator it = matches_.begin() + 1;
188 it != matches_.end(); ++it) { 211 it != matches_.end(); ++it) {
189 if (it->allowed_to_be_default_match) { 212 if (it->allowed_to_be_default_match &&
213 (!OmniboxFieldTrial::DisableInlining() ||
214 !has_legal_default_match_without_completion ||
215 it->inline_autocompletion.empty())) {
190 std::rotate(matches_.begin(), it, it + 1); 216 std::rotate(matches_.begin(), it, it + 1);
191 break; 217 break;
192 } 218 }
193 } 219 }
194 } 220 }
195 // In the process of trimming, drop all matches with a demoted relevance 221 // In the process of trimming, drop all matches with a demoted relevance
196 // score of 0. 222 // score of 0.
197 size_t num_matches; 223 size_t num_matches;
198 for (num_matches = 0u; (num_matches < max_num_matches) && 224 for (num_matches = 0u; (num_matches < max_num_matches) &&
199 (comparing_object.GetDemotedRelevance(*match_at(num_matches)) > 0); 225 (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) { 449 i != old_matches.rend() && delta > 0; ++i) {
424 if (!HasMatchByDestination(*i, new_matches)) { 450 if (!HasMatchByDestination(*i, new_matches)) {
425 AutocompleteMatch match = *i; 451 AutocompleteMatch match = *i;
426 match.relevance = std::min(max_relevance, match.relevance); 452 match.relevance = std::min(max_relevance, match.relevance);
427 match.from_previous = true; 453 match.from_previous = true;
428 AddMatch(page_classification, match); 454 AddMatch(page_classification, match);
429 delta--; 455 delta--;
430 } 456 }
431 } 457 }
432 } 458 }
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