OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/omnibox/omnibox_field_trial.h" | 5 #include "chrome/browser/omnibox/omnibox_field_trial.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "components/variations/variations_associated_data.h" | 23 #include "components/variations/variations_associated_data.h" |
24 | 24 |
25 using metrics::OmniboxEventProto; | 25 using metrics::OmniboxEventProto; |
26 | 26 |
27 namespace { | 27 namespace { |
28 | 28 |
29 typedef std::map<std::string, std::string> VariationParams; | 29 typedef std::map<std::string, std::string> VariationParams; |
30 typedef HUPScoringParams::ScoreBuckets ScoreBuckets; | 30 typedef HUPScoringParams::ScoreBuckets ScoreBuckets; |
31 | 31 |
32 // Field trial names. | 32 // Field trial names. |
33 const char kHUPCullRedirectsFieldTrialName[] = "OmniboxHUPCullRedirects"; | |
34 const char kHUPCreateShorterMatchFieldTrialName[] = | |
35 "OmniboxHUPCreateShorterMatch"; | |
36 const char kStopTimerFieldTrialName[] = "OmniboxStopTimer"; | 33 const char kStopTimerFieldTrialName[] = "OmniboxStopTimer"; |
37 | 34 |
38 // The autocomplete dynamic field trial name prefix. Each field trial is | 35 // The autocomplete dynamic field trial name prefix. Each field trial is |
39 // configured dynamically and is retrieved automatically by Chrome during | 36 // configured dynamically and is retrieved automatically by Chrome during |
40 // the startup. | 37 // the startup. |
41 const char kAutocompleteDynamicFieldTrialPrefix[] = "AutocompleteDynamicTrial_"; | 38 const char kAutocompleteDynamicFieldTrialPrefix[] = "AutocompleteDynamicTrial_"; |
42 // The maximum number of the autocomplete dynamic field trials (aka layers). | 39 // The maximum number of the autocomplete dynamic field trials (aka layers). |
43 const int kMaxAutocompleteDynamicFieldTrials = 5; | 40 const int kMaxAutocompleteDynamicFieldTrials = 5; |
44 | 41 |
45 // Field trial experiment probabilities. | |
46 | |
47 // For HistoryURL provider cull redirects field trial, put 0% ( = 0/100 ) | |
48 // of the users in the don't-cull-redirects experiment group. | |
49 // TODO(mpearson): Remove this field trial and the code it uses once I'm | |
50 // sure it's no longer needed. | |
51 const base::FieldTrial::Probability kHUPCullRedirectsFieldTrialDivisor = 100; | |
52 const base::FieldTrial::Probability | |
53 kHUPCullRedirectsFieldTrialExperimentFraction = 0; | |
54 | |
55 // For HistoryURL provider create shorter match field trial, put 0% | |
56 // ( = 25/100 ) of the users in the don't-create-a-shorter-match | |
57 // experiment group. | |
58 // TODO(mpearson): Remove this field trial and the code it uses once I'm | |
59 // sure it's no longer needed. | |
60 const base::FieldTrial::Probability | |
61 kHUPCreateShorterMatchFieldTrialDivisor = 100; | |
62 const base::FieldTrial::Probability | |
63 kHUPCreateShorterMatchFieldTrialExperimentFraction = 0; | |
64 | |
65 // Field trial IDs. | |
66 // Though they are not literally "const", they are set only once, in | |
67 // ActivateStaticTrials() below. | |
68 | |
69 // Whether the static field trials have been initialized by | |
70 // ActivateStaticTrials() method. | |
71 bool static_field_trials_initialized = false; | |
72 | |
73 // Field trial ID for the HistoryURL provider cull redirects experiment group. | |
74 int hup_dont_cull_redirects_experiment_group = 0; | |
75 | |
76 // Field trial ID for the HistoryURL provider create shorter match | |
77 // experiment group. | |
78 int hup_dont_create_shorter_match_experiment_group = 0; | |
79 | |
80 | 42 |
81 // Concatenates the autocomplete dynamic field trial prefix with a field trial | 43 // Concatenates the autocomplete dynamic field trial prefix with a field trial |
82 // ID to form a complete autocomplete field trial name. | 44 // ID to form a complete autocomplete field trial name. |
83 std::string DynamicFieldTrialName(int id) { | 45 std::string DynamicFieldTrialName(int id) { |
84 return base::StringPrintf("%s%d", kAutocompleteDynamicFieldTrialPrefix, id); | 46 return base::StringPrintf("%s%d", kAutocompleteDynamicFieldTrialPrefix, id); |
85 } | 47 } |
86 | 48 |
87 void InitializeScoreBuckets(const VariationParams& params, | 49 void InitializeScoreBuckets(const VariationParams& params, |
88 const char* relevance_cap_param, | 50 const char* relevance_cap_param, |
89 const char* half_life_param, | 51 const char* half_life_param, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 double time_ms; | 100 double time_ms; |
139 if ((half_life_days_ <= 0) || | 101 if ((half_life_days_ <= 0) || |
140 ((time_ms = elapsed_time.InMillisecondsF()) <= 0)) | 102 ((time_ms = elapsed_time.InMillisecondsF()) <= 0)) |
141 return 1.0; | 103 return 1.0; |
142 | 104 |
143 const double half_life_intervals = | 105 const double half_life_intervals = |
144 time_ms / base::TimeDelta::FromDays(half_life_days_).InMillisecondsF(); | 106 time_ms / base::TimeDelta::FromDays(half_life_days_).InMillisecondsF(); |
145 return pow(2.0, -half_life_intervals); | 107 return pow(2.0, -half_life_intervals); |
146 } | 108 } |
147 | 109 |
148 void OmniboxFieldTrial::ActivateStaticTrials() { | |
149 DCHECK(!static_field_trials_initialized); | |
150 | |
151 // Create the HistoryURL provider cull redirects field trial. | |
152 // Make it expire on March 1, 2013. | |
153 scoped_refptr<base::FieldTrial> trial( | |
154 base::FieldTrialList::FactoryGetFieldTrial( | |
155 kHUPCullRedirectsFieldTrialName, kHUPCullRedirectsFieldTrialDivisor, | |
156 "Standard", 2013, 3, 1, base::FieldTrial::ONE_TIME_RANDOMIZED, NULL)); | |
157 hup_dont_cull_redirects_experiment_group = | |
158 trial->AppendGroup("DontCullRedirects", | |
159 kHUPCullRedirectsFieldTrialExperimentFraction); | |
160 | |
161 // Create the HistoryURL provider create shorter match field trial. | |
162 // Make it expire on March 1, 2013. | |
163 trial = base::FieldTrialList::FactoryGetFieldTrial( | |
164 kHUPCreateShorterMatchFieldTrialName, | |
165 kHUPCreateShorterMatchFieldTrialDivisor, "Standard", 2013, 3, 1, | |
166 base::FieldTrial::ONE_TIME_RANDOMIZED, NULL); | |
167 hup_dont_create_shorter_match_experiment_group = | |
168 trial->AppendGroup("DontCreateShorterMatch", | |
169 kHUPCreateShorterMatchFieldTrialExperimentFraction); | |
170 | |
171 static_field_trials_initialized = true; | |
172 } | |
173 | |
174 void OmniboxFieldTrial::ActivateDynamicTrials() { | 110 void OmniboxFieldTrial::ActivateDynamicTrials() { |
175 // Initialize all autocomplete dynamic field trials. This method may be | 111 // Initialize all autocomplete dynamic field trials. This method may be |
176 // called multiple times. | 112 // called multiple times. |
177 for (int i = 0; i < kMaxAutocompleteDynamicFieldTrials; ++i) | 113 for (int i = 0; i < kMaxAutocompleteDynamicFieldTrials; ++i) |
178 base::FieldTrialList::FindValue(DynamicFieldTrialName(i)); | 114 base::FieldTrialList::FindValue(DynamicFieldTrialName(i)); |
179 } | 115 } |
180 | 116 |
181 int OmniboxFieldTrial::GetDisabledProviderTypes() { | 117 int OmniboxFieldTrial::GetDisabledProviderTypes() { |
182 // Make sure that Autocomplete dynamic field trials are activated. It's OK to | 118 // Make sure that Autocomplete dynamic field trials are activated. It's OK to |
183 // call this method multiple times. | 119 // call this method multiple times. |
(...skipping 24 matching lines...) Expand all Loading... |
208 const std::string& trial_name = DynamicFieldTrialName(i); | 144 const std::string& trial_name = DynamicFieldTrialName(i); |
209 if (base::FieldTrialList::TrialExists(trial_name)) | 145 if (base::FieldTrialList::TrialExists(trial_name)) |
210 field_trial_hashes->push_back(metrics::HashName(trial_name)); | 146 field_trial_hashes->push_back(metrics::HashName(trial_name)); |
211 } | 147 } |
212 if (base::FieldTrialList::TrialExists(kBundledExperimentFieldTrialName)) { | 148 if (base::FieldTrialList::TrialExists(kBundledExperimentFieldTrialName)) { |
213 field_trial_hashes->push_back( | 149 field_trial_hashes->push_back( |
214 metrics::HashName(kBundledExperimentFieldTrialName)); | 150 metrics::HashName(kBundledExperimentFieldTrialName)); |
215 } | 151 } |
216 } | 152 } |
217 | 153 |
218 bool OmniboxFieldTrial::InHUPCullRedirectsFieldTrial() { | |
219 return base::FieldTrialList::TrialExists(kHUPCullRedirectsFieldTrialName); | |
220 } | |
221 | |
222 bool OmniboxFieldTrial::InHUPCullRedirectsFieldTrialExperimentGroup() { | |
223 if (!base::FieldTrialList::TrialExists(kHUPCullRedirectsFieldTrialName)) | |
224 return false; | |
225 | |
226 // Return true if we're in the experiment group. | |
227 const int group = base::FieldTrialList::FindValue( | |
228 kHUPCullRedirectsFieldTrialName); | |
229 return group == hup_dont_cull_redirects_experiment_group; | |
230 } | |
231 | |
232 bool OmniboxFieldTrial::InHUPCreateShorterMatchFieldTrial() { | |
233 return | |
234 base::FieldTrialList::TrialExists(kHUPCreateShorterMatchFieldTrialName); | |
235 } | |
236 | |
237 bool OmniboxFieldTrial::InHUPCreateShorterMatchFieldTrialExperimentGroup() { | |
238 if (!base::FieldTrialList::TrialExists(kHUPCreateShorterMatchFieldTrialName)) | |
239 return false; | |
240 | |
241 // Return true if we're in the experiment group. | |
242 const int group = base::FieldTrialList::FindValue( | |
243 kHUPCreateShorterMatchFieldTrialName); | |
244 return group == hup_dont_create_shorter_match_experiment_group; | |
245 } | |
246 | |
247 base::TimeDelta OmniboxFieldTrial::StopTimerFieldTrialDuration() { | 154 base::TimeDelta OmniboxFieldTrial::StopTimerFieldTrialDuration() { |
248 int stop_timer_ms; | 155 int stop_timer_ms; |
249 if (base::StringToInt( | 156 if (base::StringToInt( |
250 base::FieldTrialList::FindFullName(kStopTimerFieldTrialName), | 157 base::FieldTrialList::FindFullName(kStopTimerFieldTrialName), |
251 &stop_timer_ms)) | 158 &stop_timer_ms)) |
252 return base::TimeDelta::FromMilliseconds(stop_timer_ms); | 159 return base::TimeDelta::FromMilliseconds(stop_timer_ms); |
253 return base::TimeDelta::FromMilliseconds(1500); | 160 return base::TimeDelta::FromMilliseconds(1500); |
254 } | 161 } |
255 | 162 |
256 bool OmniboxFieldTrial::InZeroSuggestFieldTrial() { | 163 bool OmniboxFieldTrial::InZeroSuggestFieldTrial() { |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 if (it != params.end()) | 434 if (it != params.end()) |
528 return it->second; | 435 return it->second; |
529 // Fall back to the global instant extended context. | 436 // Fall back to the global instant extended context. |
530 it = params.find(rule + ":" + page_classification_str + ":*"); | 437 it = params.find(rule + ":" + page_classification_str + ":*"); |
531 if (it != params.end()) | 438 if (it != params.end()) |
532 return it->second; | 439 return it->second; |
533 // Look up rule in the global context. | 440 // Look up rule in the global context. |
534 it = params.find(rule + ":*:*"); | 441 it = params.find(rule + ":*:*"); |
535 return (it != params.end()) ? it->second : std::string(); | 442 return (it != params.end()) ? it->second : std::string(); |
536 } | 443 } |
OLD | NEW |