Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / components / omnibox / browser / omnibox_field_trial.h
blob2e4421d7b5a3c642a79ade2de6c777f617f8c103
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
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_OMNIBOX_BROWSER_OMNIBOX_FIELD_TRIAL_H_
6 #define COMPONENTS_OMNIBOX_BROWSER_OMNIBOX_FIELD_TRIAL_H_
8 #include <map>
9 #include <string>
10 #include <vector>
12 #include "base/basictypes.h"
13 #include "base/gtest_prod_util.h"
14 #include "components/metrics/proto/omnibox_event.pb.h"
15 #include "components/omnibox/browser/autocomplete_match_type.h"
17 namespace base {
18 class TimeDelta;
21 // The set of parameters customizing the HUP scoring.
22 struct HUPScoringParams {
23 // A set of parameters describing how to cap a given count score. First,
24 // we apply a half-life based decay of the given count and then find the
25 // maximum relevance score in the corresponding bucket list.
26 class ScoreBuckets {
27 public:
28 // (decayed_count, max_relevance) pair.
29 typedef std::pair<double, int> CountMaxRelevance;
31 ScoreBuckets();
32 ~ScoreBuckets();
34 // Computes a half-life time decay given the |elapsed_time|.
35 double HalfLifeTimeDecay(const base::TimeDelta& elapsed_time) const;
37 int relevance_cap() const { return relevance_cap_; }
38 void set_relevance_cap(int relevance_cap) {
39 relevance_cap_ = relevance_cap;
42 int half_life_days() const { return half_life_days_; }
43 void set_half_life_days(int half_life_days) {
44 half_life_days_ = half_life_days;
47 std::vector<CountMaxRelevance>& buckets() { return buckets_; }
48 const std::vector<CountMaxRelevance>& buckets() const { return buckets_; }
50 private:
51 // History matches with relevance score greater or equal to |relevance_cap_|
52 // are not affected by this experiment.
53 // Set to -1, if there is no relevance cap in place and all matches are
54 // subject to demotion.
55 int relevance_cap_;
57 // Half life time for a decayed count as measured since the last visit.
58 // Set to -1 if not used.
59 int half_life_days_;
61 // The relevance score caps for given decayed count values.
62 // Each pair (decayed_count, max_score) indicates what the maximum relevance
63 // score is of a decayed count equal or greater than decayed_count.
65 // Consider this example:
66 // [(1, 1000), (0.5, 500), (0, 100)]
67 // If decayed count is 2 (which is >= 1), the corresponding match's maximum
68 // relevance will be capped at 1000. In case of 0.5, the score is capped
69 // at 500. Anything below 0.5 is capped at 100.
71 // This list is sorted by the pair's first element in descending order.
72 std::vector<CountMaxRelevance> buckets_;
75 HUPScoringParams() : experimental_scoring_enabled(false) {}
77 bool experimental_scoring_enabled;
79 ScoreBuckets typed_count_buckets;
81 // Used only when the typed count is 0.
82 ScoreBuckets visited_count_buckets;
85 // This class manages the Omnibox field trials.
86 class OmniboxFieldTrial {
87 public:
88 // A mapping that contains multipliers indicating that matches of the
89 // specified type should have their relevance score multiplied by the
90 // given number. Omitted types are assumed to have multipliers of 1.0.
91 typedef std::map<AutocompleteMatchType::Type, float> DemotionMultipliers;
93 // Activates all dynamic field trials. The main difference between
94 // the autocomplete dynamic and static field trials is that the former
95 // don't require any code changes on the Chrome side as they are controlled
96 // on the server side. Chrome binary simply propagates all necessary
97 // information through the X-Client-Data header.
98 // This method may be called multiple times.
99 static void ActivateDynamicTrials();
101 // ---------------------------------------------------------
102 // For any experiment that's part of the bundled omnibox field trial.
104 // Returns a bitmap containing AutocompleteProvider::Type values
105 // that should be disabled in AutocompleteController.
106 static int GetDisabledProviderTypes();
108 // Returns whether the user is in any dynamic field trial where the
109 // group has a the prefix |group_prefix|.
110 static bool HasDynamicFieldTrialGroupPrefix(const char *group_prefix);
112 // ---------------------------------------------------------
113 // For the suggest field trial.
115 // Populates |field_trial_hash| with hashes of the active suggest field trial
116 // names, if any.
117 static void GetActiveSuggestFieldTrialHashes(
118 std::vector<uint32>* field_trial_hash);
120 // ---------------------------------------------------------
121 // For the AutocompleteController "stop timer" field trial.
123 // Returns the duration to be used for the AutocompleteController's stop
124 // timer. Returns the default value of 1.5 seconds if the stop timer
125 // override experiment isn't active or if parsing the experiment-provided
126 // duration fails.
127 static base::TimeDelta StopTimerFieldTrialDuration();
129 // ---------------------------------------------------------
130 // For the ZeroSuggestProvider field trial.
132 // Returns whether the user is in any field trial where the
133 // ZeroSuggestProvider should be used to get suggestions when the
134 // user clicks on the omnibox but has not typed anything yet.
135 static bool InZeroSuggestFieldTrial();
137 // Returns whether the user is in a ZeroSuggest field trial, which shows
138 // most visited URLs. This is true for both "MostVisited" and
139 // "MostVisitedWithoutSERP" trials.
140 static bool InZeroSuggestMostVisitedFieldTrial();
142 // Returns whether the user is in ZeroSuggest field trial showing most
143 // visited URLs except it doesn't show suggestions on Google search result
144 // pages.
145 static bool InZeroSuggestMostVisitedWithoutSerpFieldTrial();
147 // Returns whether the user is in a ZeroSuggest field trial and URL-based
148 // suggestions can continue to appear after the user has started typing.
149 static bool InZeroSuggestAfterTypingFieldTrial();
151 // Returns whether the user is in a ZeroSuggest field trial, but should
152 // show recently searched-for queries instead.
153 static bool InZeroSuggestPersonalizedFieldTrial();
155 // ---------------------------------------------------------
156 // For the ShortcutsScoringMaxRelevance experiment that's part of the
157 // bundled omnibox field trial.
159 // If the user is in an experiment group that, given the provided
160 // |current_page_classification| context, changes the maximum relevance
161 // ShortcutsProvider::CalculateScore() is supposed to assign, extract
162 // that maximum relevance score and put in in |max_relevance|. Returns
163 // true on a successful extraction. CalculateScore()'s return value is
164 // a product of this maximum relevance score and some attenuating factors
165 // that are all between 0 and 1. (Note that Shortcuts results may have
166 // their scores reduced later if the assigned score is higher than allowed
167 // for non-inlineable results. Shortcuts results are not allowed to be
168 // inlined.)
169 static bool ShortcutsScoringMaxRelevance(
170 metrics::OmniboxEventProto::PageClassification
171 current_page_classification,
172 int* max_relevance);
174 // ---------------------------------------------------------
175 // For the SearchHistory experiment that's part of the bundled omnibox
176 // field trial.
178 // Returns true if the user is in the experiment group that, given the
179 // provided |current_page_classification| context, scores search history
180 // query suggestions less aggressively so that they don't inline.
181 static bool SearchHistoryPreventInlining(
182 metrics::OmniboxEventProto::PageClassification
183 current_page_classification);
185 // Returns true if the user is in the experiment group that, given the
186 // provided |current_page_classification| context, disables all query
187 // suggestions from search history.
188 static bool SearchHistoryDisable(
189 metrics::OmniboxEventProto::PageClassification
190 current_page_classification);
192 // ---------------------------------------------------------
193 // For the DemoteByType experiment that's part of the bundled omnibox field
194 // trial.
196 // If the user is in an experiment group that, in the provided
197 // |current_page_classification| context, demotes the relevance scores
198 // of certain types of matches, populates the |demotions_by_type| map
199 // appropriately. Otherwise, sets |demotions_by_type| to its default
200 // value based on the context.
201 static void GetDemotionsByType(
202 metrics::OmniboxEventProto::PageClassification
203 current_page_classification,
204 DemotionMultipliers* demotions_by_type);
206 // ---------------------------------------------------------
207 // For the HistoryURL provider new scoring experiment that is part of the
208 // bundled omnibox field trial.
210 // Initializes the HUP |scoring_params| based on the active HUP scoring
211 // experiment. If there is no such experiment, this function simply sets
212 // |scoring_params|->experimental_scoring_enabled to false.
213 static void GetExperimentalHUPScoringParams(HUPScoringParams* scoring_params);
215 // For the HQPBookmarkValue experiment that's part of the
216 // bundled omnibox field trial.
218 // Returns the value an untyped visit to a bookmark should receive.
219 // Compare this value with the default of 1 for non-bookmarked untyped
220 // visits to pages and the default of 20 for typed visits. Returns
221 // 10 if the bookmark value experiment isn't active.
222 static int HQPBookmarkValue();
224 // ---------------------------------------------------------
225 // For the HQPAllowMatchInTLD experiment that's part of the
226 // bundled omnibox field trial.
228 // Returns true if HQP should allow an input term to match in the
229 // top level domain (e.g., .com) of a URL. Returns false if the
230 // allow match in TLD experiment isn't active.
231 static bool HQPAllowMatchInTLDValue();
233 // ---------------------------------------------------------
234 // For the HQPAllowMatchInScheme experiment that's part of the
235 // bundled omnibox field trial.
237 // Returns true if HQP should allow an input term to match in the
238 // scheme (e.g., http://) of a URL. Returns false if the allow
239 // match in scheme experiment isn't active.
240 static bool HQPAllowMatchInSchemeValue();
242 // ---------------------------------------------------------
243 // For SearchProvider related experiments.
245 // Returns true if the search provider should not be caching results.
246 static bool DisableResultsCaching();
248 // Returns how the search provider should poll Suggest. Currently, we support
249 // measuring polling delay from the last keystroke or last suggest request.
250 static void GetSuggestPollingStrategy(bool* from_last_keystroke,
251 int* polling_delay_ms);
253 // ---------------------------------------------------------
254 // For HQP scoring related experiments to control the topicality and scoring
255 // ranges of relevancy scores.
257 // Returns true if HQP experimental scoring is enabled. Returns false if
258 // |kHQPExperimentalScoringEnabledParam| is not specified in the field trial.
259 static bool HQPExperimentalScoringEnabled();
261 // Returns the scoring buckets for HQP experiments. Returns empty string
262 // in case |kHQPExperimentalScoringBucketsParam| or
263 // |kHQPExperimentalScoringEnabledParam| is not specified in the
264 // field trial. Scoring buckets are stored in string form giving mapping from
265 // (topicality_score, frequency_score) to final relevance score.
266 // Please see GetRelevancyScore() under
267 // chrome/browser/history::ScoredHistoryMatch for details.
268 static std::string HQPExperimentalScoringBuckets();
270 // Returns the topicality threshold for HQP experiments. Returns -1 if
271 // |kHQPExperimentalScoringTopicalityThresholdParam| or
272 // |kHQPExperimentalScoringEnabledParam| is not specified in the field trial.
273 static float HQPExperimentalTopicalityThreshold();
275 // ---------------------------------------------------------
276 // For the HQPFixFrequencyScoring experiment that's part of the
277 // bundled omnibox field trial.
279 // Returns true if HQP should apply the bug fixes to the GetFrequency()
280 // function.
281 static bool HQPFixFrequencyScoringBugs();
283 // ---------------------------------------------------------
284 // For the HQPNumTitleWords experiment that's part of the
285 // bundled omnibox field trial.
287 // Returns the number of title words that are allowed to contribute
288 // to the topicality score. Words later in the title are ignored.
289 // Returns 10 as a default if the experiment isn't active.
290 static size_t HQPNumTitleWordsToAllow();
292 // ---------------------------------------------------------
293 // For the HQPAlsoDoHUPLikeScoring experiment that's part of the
294 // bundled omnibox field trial.
296 // Returns whether HistoryQuick provider (HQP) should attempt to score
297 // suggestions also with a HistoryURL-provider-like (HUP-like) mode, and
298 // assign suggestions the max of this score and the normal score.
299 // Returns false if the experiment isn't active.
300 static bool HQPAlsoDoHUPLikeScoring();
302 // ---------------------------------------------------------
303 // For the PreventUWYTDefaultForNonURLInputs experiment that's part of the
304 // bundled omnibox field trial.
306 // Returns true if HistoryURL provider should prohibit the URL-what-you-
307 // typed match from being the legal default match for non-URL inputs.
308 // If this behavior is active, some code in AutocompleteInput::Parse() also
309 // gets disabled; this code is unnecessary given the not-allowed-to-be-
310 // default constraint. Returns false if the experiment isn't active.
311 static bool PreventUWYTDefaultForNonURLInputs();
313 // ---------------------------------------------------------
314 // Exposed publicly for the sake of unittests.
315 static const char kBundledExperimentFieldTrialName[];
316 // Rule names used by the bundled experiment.
317 static const char kDisableProvidersRule[];
318 static const char kShortcutsScoringMaxRelevanceRule[];
319 static const char kSearchHistoryRule[];
320 static const char kDemoteByTypeRule[];
321 static const char kHQPBookmarkValueRule[];
322 static const char kHQPDiscountFrecencyWhenFewVisitsRule[];
323 static const char kHQPAllowMatchInTLDRule[];
324 static const char kHQPAllowMatchInSchemeRule[];
325 static const char kZeroSuggestRule[];
326 static const char kZeroSuggestVariantRule[];
327 static const char kSuggestVariantRule[];
328 static const char kDisableResultsCachingRule[];
329 static const char kMeasureSuggestPollingDelayFromLastKeystrokeRule[];
330 static const char kSuggestPollingDelayMsRule[];
331 static const char kHQPFixFrequencyScoringBugsRule[];
332 static const char kHQPNumTitleWordsRule[];
333 static const char kHQPAlsoDoHUPLikeScoringRule[];
334 static const char kPreventUWYTDefaultForNonURLInputsRule[];
336 // Parameter names used by the HUP new scoring experiments.
337 static const char kHUPNewScoringEnabledParam[];
338 static const char kHUPNewScoringTypedCountRelevanceCapParam[];
339 static const char kHUPNewScoringTypedCountHalfLifeTimeParam[];
340 static const char kHUPNewScoringTypedCountScoreBucketsParam[];
341 static const char kHUPNewScoringVisitedCountRelevanceCapParam[];
342 static const char kHUPNewScoringVisitedCountHalfLifeTimeParam[];
343 static const char kHUPNewScoringVisitedCountScoreBucketsParam[];
345 // Parameter names used by the HQP experimental scoring experiments.
346 static const char kHQPExperimentalScoringEnabledParam[];
347 static const char kHQPExperimentalScoringBucketsParam[];
348 static const char kHQPExperimentalScoringTopicalityThresholdParam[];
350 // The amount of time to wait before sending a new suggest request after the
351 // previous one unless overridden by a field trial parameter.
352 // Non-const because some unittests modify this value.
353 static int kDefaultMinimumTimeBetweenSuggestQueriesMs;
355 private:
356 friend class OmniboxFieldTrialTest;
358 // The bundled omnibox experiment comes with a set of parameters
359 // (key-value pairs). Each key indicates a certain rule that applies in
360 // a certain context. The value indicates what the consequences of
361 // applying the rule are. For example, the value of a SearchHistory rule
362 // in the context of a search results page might indicate that we should
363 // prevent search history matches from inlining.
365 // This function returns the value associated with the |rule| that applies
366 // in the current context (which currently consists of |page_classification|
367 // and whether Instant Extended is enabled). If no such rule exists in the
368 // current context, fall back to the rule in various wildcard contexts and
369 // return its value if found. If the rule remains unfound in the global
370 // context, returns the empty string. For more details, including how we
371 // prioritize different wildcard contexts, see the implementation. How to
372 // interpret the value is left to the caller; this is rule-dependent.
373 static std::string GetValueForRuleInContext(
374 const std::string& rule,
375 metrics::OmniboxEventProto::PageClassification page_classification);
377 DISALLOW_IMPLICIT_CONSTRUCTORS(OmniboxFieldTrial);
380 #endif // COMPONENTS_OMNIBOX_BROWSER_OMNIBOX_FIELD_TRIAL_H_