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

Unified 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, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/autocomplete/autocomplete_result_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/autocomplete/autocomplete_result.cc
diff --git a/chrome/browser/autocomplete/autocomplete_result.cc b/chrome/browser/autocomplete/autocomplete_result.cc
index b4637f67a0b9ec77c44a5a48db3156e87c99ecde..a65ca2b8a880ab22a7f49678dd149d11278bdfbd 100644
--- a/chrome/browser/autocomplete/autocomplete_result.cc
+++ b/chrome/browser/autocomplete/autocomplete_result.cc
@@ -8,6 +8,7 @@
#include <iterator>
#include "base/logging.h"
+#include "base/metrics/histogram.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/autocomplete/autocomplete_input.h"
#include "chrome/browser/autocomplete/autocomplete_match.h"
@@ -92,6 +93,18 @@ bool DestinationSort::operator()(const AutocompleteMatch& elem1,
return elem1.stripped_destination_url < elem2.stripped_destination_url;
}
+// Returns true if |match| is allowed to the default match taking into account
+// whether we're supposed to (and able to) demote all matches with inline
+// autocompletions.
+bool AllowedToBeDefaultMatchAccountingForDisableInliningExperiment(
+ const AutocompleteMatch& match,
+ const bool has_legal_default_match_without_completion) {
+ return match.allowed_to_be_default_match &&
+ (!OmniboxFieldTrial::DisableInlining() ||
+ !has_legal_default_match_without_completion ||
+ match.inline_autocompletion.empty());
+}
+
}; // namespace
// static
@@ -177,16 +190,37 @@ void AutocompleteResult::SortAndCull(const AutocompleteInput& input,
DedupMatchesByDestination(input.current_page_classification(), true,
&matches_);
+ // If the result set has at least one legal default match without an inline
+ // autocompletion, then in the disable inlining experiment it will be okay
+ // to demote all matches with inline autocompletions. On the other hand, if
+ // the experiment is active but there is no legal match without an inline
+ // autocompletion, then we'll pretend the experiment is not active and not
+ // demote the matches with an inline autocompletion. In other words, an
+ // alternate name for this variable is
+ // allowed_to_demote_matches_with_inline_autocompletion.
+ bool has_legal_default_match_without_completion = false;
+ for (AutocompleteResult::iterator it = matches_.begin();
+ (it != matches_.end()) && !has_legal_default_match_without_completion;
+ ++it) {
+ if (it->allowed_to_be_default_match && it->inline_autocompletion.empty())
+ has_legal_default_match_without_completion = true;
+ }
+ UMA_HISTOGRAM_BOOLEAN("Omnibox.HasLegalDefaultMatchWithoutCompletion",
+ has_legal_default_match_without_completion);
+
// Sort and trim to the most relevant kMaxMatches matches.
size_t max_num_matches = std::min(kMaxMatches, matches_.size());
CompareWithDemoteByType comparing_object(input.current_page_classification());
std::sort(matches_.begin(), matches_.end(), comparing_object);
- if (!matches_.empty() && !matches_.begin()->allowed_to_be_default_match) {
+ if (!matches_.empty() &&
+ !AllowedToBeDefaultMatchAccountingForDisableInliningExperiment(
+ *matches_.begin(), has_legal_default_match_without_completion)) {
// Top match is not allowed to be the default match. Find the most
// relevant legal match and shift it to the front.
for (AutocompleteResult::iterator it = matches_.begin() + 1;
it != matches_.end(); ++it) {
- if (it->allowed_to_be_default_match) {
+ if (AllowedToBeDefaultMatchAccountingForDisableInliningExperiment(
+ *it, has_legal_default_match_without_completion)) {
std::rotate(matches_.begin(), it, it + 1);
break;
}
« 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