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/autocomplete/autocomplete_field_trial.h" | 5 #include "chrome/browser/autocomplete/autocomplete_field_trial.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 // For the field trial that allows HistoryQuick provider to use the | 98 // For the field trial that allows HistoryQuick provider to use the |
99 // cursor position, put 25% ( = 25/100 ) of the users in the experiment group. | 99 // cursor position, put 25% ( = 25/100 ) of the users in the experiment group. |
100 const base::FieldTrial::Probability | 100 const base::FieldTrial::Probability |
101 kHQPUseCursorPositionFieldTrialDivisor = 100; | 101 kHQPUseCursorPositionFieldTrialDivisor = 100; |
102 const base::FieldTrial::Probability | 102 const base::FieldTrial::Probability |
103 kHQPUseCursorPositionFieldTrialExperimentFraction = 25; | 103 kHQPUseCursorPositionFieldTrialExperimentFraction = 25; |
104 | 104 |
105 | 105 |
106 // Field trial IDs. | 106 // Field trial IDs. |
107 // Though they are not literally "const", they are set only once, in | 107 // Though they are not literally "const", they are set only once, in |
108 // Activate() below. | 108 // ActivateStaticTrials() below. |
109 | 109 |
110 // Whether the static field trials have been initialized by | 110 // Whether the static field trials have been initialized by |
111 // ActivateStaticTrials method. | 111 // ActivateStaticTrials() method. |
112 bool static_field_trials_initialized = false; | 112 bool static_field_trials_initialized = false; |
113 | 113 |
114 // Field trial ID for the disallow-inline History Quick Provider | 114 // Field trial ID for the disallow-inline History Quick Provider |
115 // experiment group. | 115 // experiment group. |
116 int disallow_inline_hqp_experiment_group = 0; | 116 int disallow_inline_hqp_experiment_group = 0; |
117 | 117 |
118 // Field trial ID for the History Quick Provider new scoring experiment group. | 118 // Field trial ID for the History Quick Provider new scoring experiment group. |
119 int hqp_new_scoring_experiment_group = 0; | 119 int hqp_new_scoring_experiment_group = 0; |
120 | 120 |
121 // Field trial ID for the HistoryURL provider cull redirects experiment group. | 121 // Field trial ID for the HistoryURL provider cull redirects experiment group. |
122 int hup_dont_cull_redirects_experiment_group = 0; | 122 int hup_dont_cull_redirects_experiment_group = 0; |
123 | 123 |
124 // Field trial ID for the HistoryURL provider create shorter match | 124 // Field trial ID for the HistoryURL provider create shorter match |
125 // experiment group. | 125 // experiment group. |
126 int hup_dont_create_shorter_match_experiment_group = 0; | 126 int hup_dont_create_shorter_match_experiment_group = 0; |
127 | 127 |
128 // Field trial ID for the HistoryQuick provider replaces HistoryURL provider | 128 // Field trial ID for the HistoryQuick provider replaces HistoryURL provider |
129 // experiment group. | 129 // experiment group. |
130 int hqp_replace_hup_scoring_experiment_group = 0; | 130 int hqp_replace_hup_scoring_experiment_group = 0; |
131 | 131 |
132 // Field trial ID for the HistoryQuick provider only count matches at | 132 // Field trial ID for the HistoryQuick provider only count matches at |
133 // word boundaries experiment group. | 133 // word boundaries experiment group. |
134 int hqp_only_count_matches_at_word_boundaries_experiment_group = 0; | 134 int hqp_only_count_matches_at_word_boundaries_experiment_group = 0; |
135 | 135 |
136 // Field trial ID for the HistoryQuick provider use cursor position | 136 // Field trial ID for the HistoryQuick provider use cursor position |
137 // experiment group. | 137 // experiment group. |
138 int hqp_use_cursor_position_experiment_group = 0; | 138 int hqp_use_cursor_position_experiment_group = 0; |
139 | 139 |
| 140 // Concatenates the autocomplete dynamic field trial prefix with a field trial |
| 141 // ID to form a complete autocomplete field trial name. |
| 142 std::string DynamicFieldTrialName(int id) { |
| 143 return base::StringPrintf("%s%d", kAutocompleteDynamicFieldTrialPrefix, id); |
140 } | 144 } |
141 | 145 |
| 146 } // namespace |
| 147 |
142 | 148 |
143 void AutocompleteFieldTrial::ActivateStaticTrials() { | 149 void AutocompleteFieldTrial::ActivateStaticTrials() { |
144 DCHECK(!static_field_trials_initialized); | 150 DCHECK(!static_field_trials_initialized); |
145 | 151 |
146 // Create inline History Quick Provider field trial. | 152 // Create inline History Quick Provider field trial. |
147 // Make it expire on November 8, 2012. | 153 // Make it expire on November 8, 2012. |
148 scoped_refptr<base::FieldTrial> trial( | 154 scoped_refptr<base::FieldTrial> trial( |
149 base::FieldTrialList::FactoryGetFieldTrial( | 155 base::FieldTrialList::FactoryGetFieldTrial( |
150 kDisallowInlineHQPFieldTrialName, kDisallowInlineHQPFieldTrialDivisor, | 156 kDisallowInlineHQPFieldTrialName, kDisallowInlineHQPFieldTrialDivisor, |
151 "Standard", 2012, 11, 8, NULL)); | 157 "Standard", 2012, 11, 8, NULL)); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 "Standard", 2013, 8, 23, NULL); | 260 "Standard", 2013, 8, 23, NULL); |
255 trial->UseOneTimeRandomization(); | 261 trial->UseOneTimeRandomization(); |
256 hqp_use_cursor_position_experiment_group = | 262 hqp_use_cursor_position_experiment_group = |
257 trial->AppendGroup("HQPUseCursorPosition", | 263 trial->AppendGroup("HQPUseCursorPosition", |
258 kHQPUseCursorPositionFieldTrialExperimentFraction); | 264 kHQPUseCursorPositionFieldTrialExperimentFraction); |
259 | 265 |
260 static_field_trials_initialized = true; | 266 static_field_trials_initialized = true; |
261 } | 267 } |
262 | 268 |
263 void AutocompleteFieldTrial::ActivateDynamicTrials() { | 269 void AutocompleteFieldTrial::ActivateDynamicTrials() { |
264 // Initialize all autocomplete dynamic field trials. | 270 // Initialize all autocomplete dynamic field trials. This method may be |
| 271 // called multiple times. |
| 272 for (int i = 0; i < kMaxAutocompleteDynamicFieldTrials; ++i) |
| 273 base::FieldTrialList::FindValue(DynamicFieldTrialName(i)); |
| 274 } |
| 275 |
| 276 int AutocompleteFieldTrial::GetDisabledProviderTypes() { |
| 277 // Make sure that Autocomplete dynamic field trials are activated. It's OK to |
| 278 // call this method multiple times. |
| 279 ActivateDynamicTrials(); |
| 280 |
| 281 // We assume that each group may contain a substring |
| 282 // "DisabledProviders_<mask>" where "mask" is a bitmap of disabled provider |
| 283 // types (AutocompleteProvider::Type). |
| 284 int provider_types = 0; |
265 for (int i = 0; i < kMaxAutocompleteDynamicFieldTrials; ++i) { | 285 for (int i = 0; i < kMaxAutocompleteDynamicFieldTrials; ++i) { |
266 base::FieldTrialList::FindValue( | 286 std::string group_name = base::FieldTrialList::FindFullName( |
267 base::StringPrintf("%s%d", kAutocompleteDynamicFieldTrialPrefix, i)); | 287 DynamicFieldTrialName(i)); |
| 288 if (!group_name.empty()) { |
| 289 const char kDisabledProviders[] = "DisabledProviders_"; |
| 290 const size_t pos = group_name.find(kDisabledProviders); |
| 291 if (pos == std::string::npos) |
| 292 continue; |
| 293 int types = 0; |
| 294 // It's OK to ignore the result, because we don't care about perfect |
| 295 // conversions. |
| 296 base::StringToInt(base::StringPiece( |
| 297 group_name.substr(pos + strlen(kDisabledProviders))), &types); |
| 298 if (types == 0) |
| 299 LOG(WARNING) << "Expecting a non-zero bitmap; group = " << group_name; |
| 300 provider_types |= types; |
| 301 } |
268 } | 302 } |
| 303 return provider_types; |
269 } | 304 } |
270 | 305 |
271 bool AutocompleteFieldTrial::InDisallowInlineHQPFieldTrial() { | 306 bool AutocompleteFieldTrial::InDisallowInlineHQPFieldTrial() { |
272 return base::FieldTrialList::TrialExists(kDisallowInlineHQPFieldTrialName); | 307 return base::FieldTrialList::TrialExists(kDisallowInlineHQPFieldTrialName); |
273 } | 308 } |
274 | 309 |
275 bool AutocompleteFieldTrial::InDisallowInlineHQPFieldTrialExperimentGroup() { | 310 bool AutocompleteFieldTrial::InDisallowInlineHQPFieldTrialExperimentGroup() { |
276 if (!base::FieldTrialList::TrialExists(kDisallowInlineHQPFieldTrialName)) | 311 if (!base::FieldTrialList::TrialExists(kDisallowInlineHQPFieldTrialName)) |
277 return false; | 312 return false; |
278 | 313 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 bool AutocompleteFieldTrial:: | 407 bool AutocompleteFieldTrial:: |
373 InHQPUseCursorPositionFieldTrialExperimentGroup() { | 408 InHQPUseCursorPositionFieldTrialExperimentGroup() { |
374 if (!InHQPUseCursorPositionFieldTrial()) | 409 if (!InHQPUseCursorPositionFieldTrial()) |
375 return false; | 410 return false; |
376 | 411 |
377 // Return true if we're in the experiment group. | 412 // Return true if we're in the experiment group. |
378 const int group = base::FieldTrialList::FindValue( | 413 const int group = base::FieldTrialList::FindValue( |
379 kHQPUseCursorPositionFieldTrialName); | 414 kHQPUseCursorPositionFieldTrialName); |
380 return group == hqp_use_cursor_position_experiment_group; | 415 return group == hqp_use_cursor_position_experiment_group; |
381 } | 416 } |
OLD | NEW |