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 kSearchHistoryFieldTrialName[] = "OmniboxSearchHistory"; | 25 const char kBundledExperimentFieldTrialName[] = "OmniboxBundledExperimentV1"; |
| 26 |
| 27 // Rule names used by the bundled experiment. |
| 28 const char kSearchHistoryRule[] = "SearchHistory"; |
26 | 29 |
27 // The autocomplete dynamic field trial name prefix. Each field trial is | 30 // The autocomplete dynamic field trial name prefix. Each field trial is |
28 // configured dynamically and is retrieved automatically by Chrome during | 31 // configured dynamically and is retrieved automatically by Chrome during |
29 // the startup. | 32 // the startup. |
30 const char kAutocompleteDynamicFieldTrialPrefix[] = "AutocompleteDynamicTrial_"; | 33 const char kAutocompleteDynamicFieldTrialPrefix[] = "AutocompleteDynamicTrial_"; |
31 // The maximum number of the autocomplete dynamic field trials (aka layers). | 34 // The maximum number of the autocomplete dynamic field trials (aka layers). |
32 const int kMaxAutocompleteDynamicFieldTrials = 5; | 35 const int kMaxAutocompleteDynamicFieldTrials = 5; |
33 | 36 |
34 // Field trial experiment probabilities. | 37 // Field trial experiment probabilities. |
35 | 38 |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 return false; | 214 return false; |
212 if (!base::StringToInt(base::StringPiece( | 215 if (!base::StringToInt(base::StringPiece( |
213 group_name.substr(strlen(kMaxRelevanceGroupPrefix))), | 216 group_name.substr(strlen(kMaxRelevanceGroupPrefix))), |
214 max_relevance)) { | 217 max_relevance)) { |
215 LOG(WARNING) << "Malformed MaxRelevance string: " << group_name; | 218 LOG(WARNING) << "Malformed MaxRelevance string: " << group_name; |
216 return false; | 219 return false; |
217 } | 220 } |
218 return true; | 221 return true; |
219 } | 222 } |
220 | 223 |
221 bool OmniboxFieldTrial::SearchHistoryPreventInlining() { | 224 bool OmniboxFieldTrial::SearchHistoryPreventInlining( |
222 return (base::FieldTrialList::FindFullName(kSearchHistoryFieldTrialName) == | 225 AutocompleteInput::PageClassification current_page_classification) { |
223 "PreventInlining"); | 226 return OmniboxFieldTrial::GetValueForRuleInContext( |
| 227 kSearchHistoryRule, current_page_classification) == "PreventInlining"; |
224 } | 228 } |
225 | 229 |
226 bool OmniboxFieldTrial::SearchHistoryDisable() { | 230 bool OmniboxFieldTrial::SearchHistoryDisable( |
227 return (base::FieldTrialList::FindFullName(kSearchHistoryFieldTrialName) == | 231 AutocompleteInput::PageClassification current_page_classification) { |
228 "Disable"); | 232 return OmniboxFieldTrial::GetValueForRuleInContext( |
| 233 kSearchHistoryRule, current_page_classification) == "Disable"; |
229 } | 234 } |
| 235 |
| 236 // Background and implementation details: |
| 237 // |
| 238 // Each experiment group in any field trial can come with an optional set of |
| 239 // parameters (key-value pairs). In the bundled omnibox experiment |
| 240 // (kBundledExperimentFieldTrialName), each experiment group comes with a |
| 241 // list of parameters in the form: |
| 242 // key=<Rule>:<AutocompleteInput::PageClassification (as an int)> |
| 243 // value=<arbitrary string> |
| 244 // The AutocompleteInput::PageClassification can also be "*", which means |
| 245 // this rule applies in all page classification contexts. |
| 246 // One example parameter is |
| 247 // key=SearchHistory:6 |
| 248 // value=PreventInlining |
| 249 // This means in page classification context 6 (a search result page doing |
| 250 // search term replacement), the SearchHistory experiment should |
| 251 // PreventInlining. |
| 252 // |
| 253 // In short, this function tries to find the value associated with key |
| 254 // |rule|:|page_classification|, failing that it looks up |rule|:*, |
| 255 // and failing that it returns the empty string. |
| 256 std::string OmniboxFieldTrial::GetValueForRuleInContext( |
| 257 const std::string& rule, |
| 258 AutocompleteInput::PageClassification page_classification) { |
| 259 std::map<std::string, std::string> params; |
| 260 if (!chrome_variations::GetVariationParams(kBundledExperimentFieldTrialName, |
| 261 ¶ms)) { |
| 262 return std::string(); |
| 263 } |
| 264 // Look up rule in this exact context. |
| 265 std::map<std::string, std::string>::iterator it = |
| 266 params.find(rule + ":" + base::IntToString( |
| 267 static_cast<int>(page_classification))); |
| 268 if (it != params.end()) |
| 269 return it->second; |
| 270 // Look up rule in the global context. |
| 271 it = params.find(rule + ":*"); |
| 272 return (it != params.end()) ? it->second : std::string(); |
| 273 } |
OLD | NEW |