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_OMNIBOX_FIELD_TRIAL_H_
6 #define COMPONENTS_OMNIBOX_OMNIBOX_FIELD_TRIAL_H_
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/autocomplete_match_type.h"
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.
28 // (decayed_count, max_relevance) pair.
29 typedef std::pair
<double, int> CountMaxRelevance
;
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_
; }
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.
57 // Half life time for a decayed count as measured since the last visit.
58 // Set to -1 if not used.
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
{
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
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
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
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
169 static bool ShortcutsScoringMaxRelevance(
170 metrics::OmniboxEventProto::PageClassification
171 current_page_classification
,
174 // ---------------------------------------------------------
175 // For the SearchHistory experiment that's part of the bundled omnibox
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
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 the AnswersInSuggest experiment that's part of the bundled omnibox
246 // Returns true if the AnswersInSuggest feature should be enabled causing
247 // query responses such as current weather conditions or stock quotes
248 // to be provided in the Omnibox suggestion list. Considers both the
249 // field trial state as well as the overriding command-line flags.
250 static bool EnableAnswersInSuggest();
252 // ---------------------------------------------------------
253 // For the DisplayHintTextWhenPossible experiment that's part of the
254 // bundled omnibox field trial.
256 // Returns true if the omnibox should display hint text (Search
257 // <search engine> or type URL) when possible (i.e., the omnibox
258 // is otherwise non-empty).
259 static bool DisplayHintTextWhenPossible();
261 // ---------------------------------------------------------
262 // For SearchProvider related experiments.
264 // Returns true if the search provider should not be caching results.
265 static bool DisableResultsCaching();
267 // Returns how the search provider should poll Suggest. Currently, we support
268 // measuring polling delay from the last keystroke or last suggest request.
269 static void GetSuggestPollingStrategy(bool* from_last_keystroke
,
270 int* polling_delay_ms
);
272 // ---------------------------------------------------------
273 // For HQP scoring related experiments to control the topicality and scoring
274 // ranges of relevancy scores.
276 // Returns true if HQP experimental scoring is enabled. Returns false if
277 // |kHQPExperimentalScoringEnabledParam| is not specified in the field trial.
278 static bool HQPExperimentalScoringEnabled();
280 // Returns the scoring buckets for HQP experiments. Returns empty string
281 // in case |kHQPExperimentalScoringBucketsParam| or
282 // |kHQPExperimentalScoringEnabledParam| is not specified in the
283 // field trial. Scoring buckets are stored in string form giving mapping from
284 // (topicality_score, frequency_score) to final relevance score.
285 // Please see GetRelevancyScore() under
286 // chrome/browser/history::ScoredHistoryMatch for details.
287 static std::string
HQPExperimentalScoringBuckets();
289 // Returns the topicality threshold for HQP experiments. Returns -1 if
290 // |kHQPExperimentalScoringTopicalityThresholdParam| or
291 // |kHQPExperimentalScoringEnabledParam| is not specified in the field trial.
292 static float HQPExperimentalTopicalityThreshold();
294 // ---------------------------------------------------------
295 // For the HQPFixFrequencyScoring experiment that's part of the
296 // bundled omnibox field trial.
298 // Returns true if HQP should apply the bug fixes to the GetFrequency()
300 static bool HQPFixFrequencyScoringBugs();
302 // ---------------------------------------------------------
303 // For the HQPNumTitleWords experiment that's part of the
304 // bundled omnibox field trial.
306 // Returns the number of title words that are allowed to contribute
307 // to the topicality score. Words later in the title are ignored.
308 // Returns 10 as a default if the experiment isn't active.
309 static size_t HQPNumTitleWordsToAllow();
311 // ---------------------------------------------------------
312 // Exposed publicly for the sake of unittests.
313 static const char kBundledExperimentFieldTrialName
[];
314 // Rule names used by the bundled experiment.
315 static const char kDisableProvidersRule
[];
316 static const char kShortcutsScoringMaxRelevanceRule
[];
317 static const char kSearchHistoryRule
[];
318 static const char kDemoteByTypeRule
[];
319 static const char kHQPBookmarkValueRule
[];
320 static const char kHQPDiscountFrecencyWhenFewVisitsRule
[];
321 static const char kHQPAllowMatchInTLDRule
[];
322 static const char kHQPAllowMatchInSchemeRule
[];
323 static const char kZeroSuggestRule
[];
324 static const char kZeroSuggestVariantRule
[];
325 static const char kAnswersInSuggestRule
[];
326 static const char kDisplayHintTextWhenPossibleRule
[];
327 static const char kDisableResultsCachingRule
[];
328 static const char kMeasureSuggestPollingDelayFromLastKeystrokeRule
[];
329 static const char kSuggestPollingDelayMsRule
[];
330 static const char kHQPFixFrequencyScoringBugsRule
[];
331 static const char kHQPNumTitleWordsRule
[];
333 // Parameter names used by the HUP new scoring experiments.
334 static const char kHUPNewScoringEnabledParam
[];
335 static const char kHUPNewScoringTypedCountRelevanceCapParam
[];
336 static const char kHUPNewScoringTypedCountHalfLifeTimeParam
[];
337 static const char kHUPNewScoringTypedCountScoreBucketsParam
[];
338 static const char kHUPNewScoringVisitedCountRelevanceCapParam
[];
339 static const char kHUPNewScoringVisitedCountHalfLifeTimeParam
[];
340 static const char kHUPNewScoringVisitedCountScoreBucketsParam
[];
342 // Parameter names used by the HQP experimental scoring experiments.
343 static const char kHQPExperimentalScoringEnabledParam
[];
344 static const char kHQPExperimentalScoringBucketsParam
[];
345 static const char kHQPExperimentalScoringTopicalityThresholdParam
[];
347 // The amount of time to wait before sending a new suggest request after the
348 // previous one unless overridden by a field trial parameter.
349 // Non-const because some unittests modify this value.
350 static int kDefaultMinimumTimeBetweenSuggestQueriesMs
;
353 friend class OmniboxFieldTrialTest
;
355 // The bundled omnibox experiment comes with a set of parameters
356 // (key-value pairs). Each key indicates a certain rule that applies in
357 // a certain context. The value indicates what the consequences of
358 // applying the rule are. For example, the value of a SearchHistory rule
359 // in the context of a search results page might indicate that we should
360 // prevent search history matches from inlining.
362 // This function returns the value associated with the |rule| that applies
363 // in the current context (which currently consists of |page_classification|
364 // and whether Instant Extended is enabled). If no such rule exists in the
365 // current context, fall back to the rule in various wildcard contexts and
366 // return its value if found. If the rule remains unfound in the global
367 // context, returns the empty string. For more details, including how we
368 // prioritize different wildcard contexts, see the implementation. How to
369 // interpret the value is left to the caller; this is rule-dependent.
370 static std::string
GetValueForRuleInContext(
371 const std::string
& rule
,
372 metrics::OmniboxEventProto::PageClassification page_classification
);
374 DISALLOW_IMPLICIT_CONSTRUCTORS(OmniboxFieldTrial
);
377 #endif // COMPONENTS_OMNIBOX_OMNIBOX_FIELD_TRIAL_H_