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::GetConsequencesOfRuleInPageClassificationContext( |
227 current_page_classification, kSearchHistoryRule) == "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::GetConsequencesOfRuleInPageClassificationContext( |
233 current_page_classification, kSearchHistoryRule) == "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=<AutocompleteInput::PageClassification (as an int)>:<Rule> | |
243 // value=<Consequences> | |
244 // The AutocompleteInput::PageClassification can also be "*", which means | |
245 // this rule applies in all contexts. | |
246 // One example parameter is | |
247 // key=6:SearchHistory | |
248 // value=PreventInlining | |
249 // This means in context 6 (a search result page doing search term replacement), | |
250 // the SearchHistory experience should PreventInlining. | |
251 // | |
252 // In short, this function tries to find the value associated with key | |
253 // |current_page_classification|:|rule|, failing that it looks up | |
254 // *:|rule|, and failing that it returns the empty string. | |
255 std::string OmniboxFieldTrial::GetConsequencesOfRuleInPageClassificationContext( | |
Mark P
2013/07/30 21:00:29
asvitkine: This function would be a little shorter
| |
256 AutocompleteInput::PageClassification current_page_classification, | |
257 const std::string& rule) { | |
258 std::map<std::string, std::string> params; | |
259 if (!chrome_variations::GetVariationParams(kBundledExperimentFieldTrialName, | |
260 ¶ms)) { | |
261 return ""; | |
262 } | |
263 // Lookup rule in this exact context. | |
264 std::map<std::string, std::string>::iterator it = | |
265 params.find(base::IntToString( | |
266 static_cast<int>(current_page_classification)) + ":" + rule); | |
267 if (it != params.end()) | |
268 return it->second; | |
269 // Lookup rule in the global context. | |
270 it = params.find("*:" + rule); | |
271 if (it != params.end()) | |
272 return it->second; | |
273 return ""; | |
274 } | |
OLD | NEW |