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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_OMNIBOX_OMNIBOX_FIELD_TRIAL_H_
6 #define CHROME_BROWSER_OMNIBOX_OMNIBOX_FIELD_TRIAL_H_
12 #include "base/basictypes.h"
13 #include "base/gtest_prod_util.h"
14 #include "chrome/browser/autocomplete/autocomplete_input.h"
15 #include "chrome/common/autocomplete_match_type.h"
17 // This class manages the Omnibox field trials.
18 class OmniboxFieldTrial {
20 // A mapping that contains multipliers indicating that matches of the
21 // specified type should have their relevance score multiplied by the
22 // given number. Omitted types are assumed to have multipliers of 1.0.
23 typedef std::map<AutocompleteMatchType::Type, float> DemotionMultipliers;
25 // Creates the static field trial groups.
26 // *** MUST NOT BE CALLED MORE THAN ONCE. ***
27 static void ActivateStaticTrials();
29 // Activates all dynamic field trials. The main difference between
30 // the autocomplete dynamic and static field trials is that the former
31 // don't require any code changes on the Chrome side as they are controlled
32 // on the server side. Chrome binary simply propagates all necessary
33 // information through the X-Chrome-Variations header.
34 // This method, unlike ActivateStaticTrials(), may be called multiple times.
35 static void ActivateDynamicTrials();
37 // Returns a bitmap containing AutocompleteProvider::Type values
38 // that should be disabled in AutocompleteController.
39 // This method simply goes over all autocomplete dynamic field trial groups
40 // and looks for group names like "ProvidersDisabled_NNN" where NNN is
41 // an integer corresponding to a bitmap mask. All extracted bitmaps
42 // are OR-ed together and returned as the final result.
43 static int GetDisabledProviderTypes();
45 // Returns whether the user is in any dynamic field trial where the
46 // group has a the prefix |group_prefix|.
47 static bool HasDynamicFieldTrialGroupPrefix(const char *group_prefix);
49 // ---------------------------------------------------------
50 // For the suggest field trial.
52 // Populates |field_trial_hash| with hashes of the active suggest field trial
54 static void GetActiveSuggestFieldTrialHashes(
55 std::vector<uint32>* field_trial_hash);
57 // ---------------------------------------------------------
58 // For the HistoryURL provider disable culling redirects field trial.
60 // Returns whether the user is in any group for this field trial.
61 // (Should always be true unless initialization went wrong.)
62 static bool InHUPCullRedirectsFieldTrial();
64 // Returns whether we should disable culling of redirects in
65 // HistoryURL provider.
66 static bool InHUPCullRedirectsFieldTrialExperimentGroup();
68 // ---------------------------------------------------------
69 // For the HistoryURL provider disable creating a shorter match
72 // Returns whether the user is in any group for this field trial.
73 // (Should always be true unless initialization went wrong.)
74 static bool InHUPCreateShorterMatchFieldTrial();
76 // Returns whether we should disable creating a shorter match in
77 // HistoryURL provider.
78 static bool InHUPCreateShorterMatchFieldTrialExperimentGroup();
80 // ---------------------------------------------------------
81 // For the AutocompleteController "stop timer" field trial.
83 // Returns whether the user should get the experimental setup or the
84 // default setup for this field trial. The experiment group uses
85 // a timer in AutocompleteController to tell the providers to stop
86 // looking for matches after too much time has passed. In other words,
87 // it tries to tell the providers to stop updating the list of suggested
88 // matches if updating the matches would probably be disruptive because
89 // they're arriving so late.
90 static bool InStopTimerFieldTrialExperimentGroup();
92 // ---------------------------------------------------------
93 // For the ZeroSuggestProvider field trial.
95 // Returns whether the user is in any field trial where the
96 // ZeroSuggestProvider should be used to get suggestions when the
97 // user clicks on the omnibox but has not typed anything yet.
98 static bool InZeroSuggestFieldTrial();
100 // Returns whether the user is in a ZeroSuggest field trial, but should
101 // show most visited URL instead. This is used to compare metrics of
102 // ZeroSuggest and most visited suggestions.
103 static bool InZeroSuggestMostVisitedFieldTrial();
105 // ---------------------------------------------------------
106 // For the ShortcutsScoringMaxRelevance experiment that's part of the
107 // bundled omnibox field trial.
109 // If the user is in an experiment group that, given the provided
110 // |current_page_classification| context, changes the maximum relevance
111 // ShortcutsProvider::CalculateScore() is supposed to assign, extract
112 // that maximum relevance score and put in in |max_relevance|. Returns
113 // true on a successful extraction. CalculateScore()'s return value is
114 // a product of this maximum relevance score and some attenuating factors
115 // that are all between 0 and 1. (Note that Shortcuts results may have
116 // their scores reduced later if the assigned score is higher than allowed
117 // for non-inlineable results. Shortcuts results are not allowed to be
119 static bool ShortcutsScoringMaxRelevance(
120 AutocompleteInput::PageClassification current_page_classification,
123 // ---------------------------------------------------------
124 // For the SearchHistory experiment that's part of the bundled omnibox
127 // Returns true if the user is in the experiment group that, given the
128 // provided |current_page_classification| context, scores search history
129 // query suggestions less aggressively so that they don't inline.
130 static bool SearchHistoryPreventInlining(
131 AutocompleteInput::PageClassification current_page_classification);
133 // Returns true if the user is in the experiment group that, given the
134 // provided |current_page_classification| context, disables all query
135 // suggestions from search history.
136 static bool SearchHistoryDisable(
137 AutocompleteInput::PageClassification current_page_classification);
139 // ---------------------------------------------------------
140 // For the DemoteByType experiment that's part of the bundled omnibox field
143 // If the user is in an experiment group that, in the provided
144 // |current_page_classification| context, demotes the relevance scores
145 // of certain types of matches, populates the |demotions_by_type| map
146 // appropriately. Otherwise, clears |demotions_by_type|.
147 static void GetDemotionsByType(
148 AutocompleteInput::PageClassification current_page_classification,
149 DemotionMultipliers* demotions_by_type);
151 // ---------------------------------------------------------
152 // For the ReorderForLegalDefaultMatch experiment that's part of the
153 // bundled omnibox field trial.
155 // Returns true if the omnibox will reorder matches, in the provided
156 // |current_page_classification| context so that a match that's allowed to
157 // be the default match will appear first. This means AutocompleteProviders
158 // can score matches however they desire without regard to making sure the
159 // top match when all the matches from all providers are merged is a legal
161 static bool ReorderForLegalDefaultMatch(
162 AutocompleteInput::PageClassification current_page_classification);
164 // ---------------------------------------------------------
165 // Exposed publicly for the sake of unittests.
166 static const char kBundledExperimentFieldTrialName[];
167 // Rule names used by the bundled experiment.
168 static const char kShortcutsScoringMaxRelevanceRule[];
169 static const char kSearchHistoryRule[];
170 static const char kDemoteByTypeRule[];
171 static const char kReorderForLegalDefaultMatchRule[];
173 static const char kReorderForLegalDefaultMatchRuleEnabled[];
176 friend class OmniboxFieldTrialTest;
178 // The bundled omnibox experiment comes with a set of parameters
179 // (key-value pairs). Each key indicates a certain rule that applies in
180 // a certain context. The value indicates what the consequences of
181 // applying the rule are. For example, the value of a SearchHistory rule
182 // in the context of a search results page might indicate that we should
183 // prevent search history matches from inlining.
185 // This function returns the value associated with the |rule| that applies
186 // in the current context (which currently consists of |page_classification|
187 // and whether Instant Extended is enabled). If no such rule exists in the
188 // current context, fall back to the rule in various wildcard contexts and
189 // return its value if found. If the rule remains unfound in the global
190 // context, returns the empty string. For more details, including how we
191 // prioritize different wildcard contexts, see the implementation. How to
192 // interpret the value is left to the caller; this is rule-dependent.
193 static std::string GetValueForRuleInContext(
194 const std::string& rule,
195 AutocompleteInput::PageClassification page_classification);
197 DISALLOW_IMPLICIT_CONSTRUCTORS(OmniboxFieldTrial);
200 #endif // CHROME_BROWSER_OMNIBOX_OMNIBOX_FIELD_TRIAL_H_