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 <string> | 7 #include <string> |
8 | 8 |
9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
13 #include "chrome/common/metrics/metrics_util.h" | 13 #include "chrome/common/metrics/metrics_util.h" |
14 #include "chrome/common/metrics/variations/variation_ids.h" | 14 #include "chrome/common/metrics/variations/variation_ids.h" |
15 #include "chrome/common/metrics/variations/variations_util.h" | 15 #include "chrome/common/metrics/variations/variations_util.h" |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 // Field trial names. | 19 // Field trial names. |
20 const char kHUPCullRedirectsFieldTrialName[] = "OmniboxHUPCullRedirects"; | 20 const char kHUPCullRedirectsFieldTrialName[] = "OmniboxHUPCullRedirects"; |
21 const char kHUPCreateShorterMatchFieldTrialName[] = | 21 const char kHUPCreateShorterMatchFieldTrialName[] = |
22 "OmniboxHUPCreateShorterMatch"; | 22 "OmniboxHUPCreateShorterMatch"; |
23 const char kStopTimerFieldTrialName[] = "OmniboxStopTimer"; | 23 const char kStopTimerFieldTrialName[] = "OmniboxStopTimer"; |
24 const char kShortcutsScoringFieldTrialName[] = "OmniboxShortcutsScoring"; | 24 const char kShortcutsScoringFieldTrialName[] = "OmniboxShortcutsScoring"; |
25 const char kBundledExperimentFieldTrialName[] = "OmniboxBundledExperimentV1"; | 25 const char kBundledExperimentFieldTrialName[] = "OmniboxBundledExperimentV1"; |
26 | 26 |
27 // Rule names used by the bundled experiment. | 27 // Rule names used by the bundled experiment. |
28 const char kSearchHistoryRule[] = "SearchHistory"; | 28 const char kSearchHistoryRule[] = "SearchHistory"; |
| 29 const char kReorderForLegalDefaultMatchRule[] = "ReorderForLegalDefaultMatch"; |
29 | 30 |
30 // The autocomplete dynamic field trial name prefix. Each field trial is | 31 // The autocomplete dynamic field trial name prefix. Each field trial is |
31 // configured dynamically and is retrieved automatically by Chrome during | 32 // configured dynamically and is retrieved automatically by Chrome during |
32 // the startup. | 33 // the startup. |
33 const char kAutocompleteDynamicFieldTrialPrefix[] = "AutocompleteDynamicTrial_"; | 34 const char kAutocompleteDynamicFieldTrialPrefix[] = "AutocompleteDynamicTrial_"; |
34 // The maximum number of the autocomplete dynamic field trials (aka layers). | 35 // The maximum number of the autocomplete dynamic field trials (aka layers). |
35 const int kMaxAutocompleteDynamicFieldTrials = 5; | 36 const int kMaxAutocompleteDynamicFieldTrials = 5; |
36 | 37 |
37 // Field trial experiment probabilities. | 38 // Field trial experiment probabilities. |
38 | 39 |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 return OmniboxFieldTrial::GetValueForRuleInContext( | 227 return OmniboxFieldTrial::GetValueForRuleInContext( |
227 kSearchHistoryRule, current_page_classification) == "PreventInlining"; | 228 kSearchHistoryRule, current_page_classification) == "PreventInlining"; |
228 } | 229 } |
229 | 230 |
230 bool OmniboxFieldTrial::SearchHistoryDisable( | 231 bool OmniboxFieldTrial::SearchHistoryDisable( |
231 AutocompleteInput::PageClassification current_page_classification) { | 232 AutocompleteInput::PageClassification current_page_classification) { |
232 return OmniboxFieldTrial::GetValueForRuleInContext( | 233 return OmniboxFieldTrial::GetValueForRuleInContext( |
233 kSearchHistoryRule, current_page_classification) == "Disable"; | 234 kSearchHistoryRule, current_page_classification) == "Disable"; |
234 } | 235 } |
235 | 236 |
| 237 bool OmniboxFieldTrial::ReorderForLegalDefaultMatch( |
| 238 AutocompleteInput::PageClassification current_page_classification) { |
| 239 return OmniboxFieldTrial::GetValueForRuleInContext( |
| 240 kReorderForLegalDefaultMatchRule, current_page_classification) == |
| 241 "ReorderForLegalDefaultMatch"; |
| 242 } |
| 243 |
236 // Background and implementation details: | 244 // Background and implementation details: |
237 // | 245 // |
238 // Each experiment group in any field trial can come with an optional set of | 246 // Each experiment group in any field trial can come with an optional set of |
239 // parameters (key-value pairs). In the bundled omnibox experiment | 247 // parameters (key-value pairs). In the bundled omnibox experiment |
240 // (kBundledExperimentFieldTrialName), each experiment group comes with a | 248 // (kBundledExperimentFieldTrialName), each experiment group comes with a |
241 // list of parameters in the form: | 249 // list of parameters in the form: |
242 // key=<Rule>:<AutocompleteInput::PageClassification (as an int)> | 250 // key=<Rule>:<AutocompleteInput::PageClassification (as an int)> |
243 // value=<arbitrary string> | 251 // value=<arbitrary string> |
244 // The AutocompleteInput::PageClassification can also be "*", which means | 252 // The AutocompleteInput::PageClassification can also be "*", which means |
245 // this rule applies in all page classification contexts. | 253 // this rule applies in all page classification contexts. |
(...skipping 18 matching lines...) Expand all Loading... |
264 // Look up rule in this exact context. | 272 // Look up rule in this exact context. |
265 std::map<std::string, std::string>::iterator it = | 273 std::map<std::string, std::string>::iterator it = |
266 params.find(rule + ":" + base::IntToString( | 274 params.find(rule + ":" + base::IntToString( |
267 static_cast<int>(page_classification))); | 275 static_cast<int>(page_classification))); |
268 if (it != params.end()) | 276 if (it != params.end()) |
269 return it->second; | 277 return it->second; |
270 // Look up rule in the global context. | 278 // Look up rule in the global context. |
271 it = params.find(rule + ":*"); | 279 it = params.find(rule + ":*"); |
272 return (it != params.end()) ? it->second : std::string(); | 280 return (it != params.end()) ? it->second : std::string(); |
273 } | 281 } |
OLD | NEW |