- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / omnibox / omnibox_field_trial.h
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.
4
5 #ifndef CHROME_BROWSER_OMNIBOX_OMNIBOX_FIELD_TRIAL_H_
6 #define CHROME_BROWSER_OMNIBOX_OMNIBOX_FIELD_TRIAL_H_
7
8 #include <map>
9 #include <string>
10 #include <vector>
11
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"
16
17 // This class manages the Omnibox field trials.
18 class OmniboxFieldTrial {
19  public:
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;
24
25   // Creates the static field trial groups.
26   // *** MUST NOT BE CALLED MORE THAN ONCE. ***
27   static void ActivateStaticTrials();
28
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();
36
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();
44
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);
48
49   // ---------------------------------------------------------
50   // For the suggest field trial.
51
52   // Populates |field_trial_hash| with hashes of the active suggest field trial
53   // names, if any.
54   static void GetActiveSuggestFieldTrialHashes(
55       std::vector<uint32>* field_trial_hash);
56
57   // ---------------------------------------------------------
58   // For the HistoryURL provider disable culling redirects field trial.
59
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();
63
64   // Returns whether we should disable culling of redirects in
65   // HistoryURL provider.
66   static bool InHUPCullRedirectsFieldTrialExperimentGroup();
67
68   // ---------------------------------------------------------
69   // For the HistoryURL provider disable creating a shorter match
70   // field trial.
71
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();
75
76   // Returns whether we should disable creating a shorter match in
77   // HistoryURL provider.
78   static bool InHUPCreateShorterMatchFieldTrialExperimentGroup();
79
80   // ---------------------------------------------------------
81   // For the AutocompleteController "stop timer" field trial.
82
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();
91
92   // ---------------------------------------------------------
93   // For the ZeroSuggestProvider field trial.
94
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();
99
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();
104
105   // ---------------------------------------------------------
106   // For the ShortcutsScoringMaxRelevance experiment that's part of the
107   // bundled omnibox field trial.
108
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
118   // inlined.)
119   static bool ShortcutsScoringMaxRelevance(
120       AutocompleteInput::PageClassification current_page_classification,
121       int* max_relevance);
122
123   // ---------------------------------------------------------
124   // For the SearchHistory experiment that's part of the bundled omnibox
125   // field trial.
126
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);
132
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);
138
139   // ---------------------------------------------------------
140   // For the DemoteByType experiment that's part of the bundled omnibox field
141   // trial.
142
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);
150
151   // ---------------------------------------------------------
152   // For the ReorderForLegalDefaultMatch experiment that's part of the
153   // bundled omnibox field trial.
154
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
160   // default match.
161   static bool ReorderForLegalDefaultMatch(
162       AutocompleteInput::PageClassification current_page_classification);
163
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[];
172   // Rule values.
173   static const char kReorderForLegalDefaultMatchRuleEnabled[];
174
175  private:
176   friend class OmniboxFieldTrialTest;
177
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.
184   //
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);
196
197   DISALLOW_IMPLICIT_CONSTRUCTORS(OmniboxFieldTrial);
198 };
199
200 #endif  // CHROME_BROWSER_OMNIBOX_OMNIBOX_FIELD_TRIAL_H_