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_split.h" | 11 #include "base/strings/string_split.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
14 #include "chrome/browser/search/search.h" | 14 #include "chrome/browser/search/search.h" |
15 #include "chrome/common/metrics/metrics_util.h" | 15 #include "chrome/common/metrics/metrics_util.h" |
16 #include "chrome/common/metrics/variations/variation_ids.h" | 16 #include "chrome/common/metrics/variations/variation_ids.h" |
17 #include "chrome/common/metrics/variations/variations_util.h" | 17 #include "chrome/common/metrics/variations/variations_util.h" |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 // Field trial names. | 21 // Field trial names. |
22 const char kHUPCullRedirectsFieldTrialName[] = "OmniboxHUPCullRedirects"; | 22 const char kHUPCullRedirectsFieldTrialName[] = "OmniboxHUPCullRedirects"; |
23 const char kHUPCreateShorterMatchFieldTrialName[] = | 23 const char kHUPCreateShorterMatchFieldTrialName[] = |
24 "OmniboxHUPCreateShorterMatch"; | 24 "OmniboxHUPCreateShorterMatch"; |
25 const char kStopTimerFieldTrialName[] = "OmniboxStopTimer"; | 25 const char kStopTimerFieldTrialName[] = "OmniboxStopTimer"; |
26 const char kShortcutsScoringFieldTrialName[] = "OmniboxShortcutsScoring"; | 26 const char kShortcutsScoringFieldTrialName[] = "OmniboxShortcutsScoring"; |
27 const char kBundledExperimentFieldTrialName[] = "OmniboxBundledExperimentV1"; | |
28 | |
29 // Rule names used by the bundled experiment. | |
30 const char kSearchHistoryRule[] = "SearchHistory"; | |
31 const char kDemoteByTypeRule[] = "DemoteByType"; | |
32 | 27 |
33 // The autocomplete dynamic field trial name prefix. Each field trial is | 28 // The autocomplete dynamic field trial name prefix. Each field trial is |
34 // configured dynamically and is retrieved automatically by Chrome during | 29 // configured dynamically and is retrieved automatically by Chrome during |
35 // the startup. | 30 // the startup. |
36 const char kAutocompleteDynamicFieldTrialPrefix[] = "AutocompleteDynamicTrial_"; | 31 const char kAutocompleteDynamicFieldTrialPrefix[] = "AutocompleteDynamicTrial_"; |
37 // The maximum number of the autocomplete dynamic field trials (aka layers). | 32 // The maximum number of the autocomplete dynamic field trials (aka layers). |
38 const int kMaxAutocompleteDynamicFieldTrials = 5; | 33 const int kMaxAutocompleteDynamicFieldTrials = 5; |
39 | 34 |
40 // Field trial experiment probabilities. | 35 // Field trial experiment probabilities. |
41 | 36 |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 // errors smartly. | 253 // errors smartly. |
259 int k, v; | 254 int k, v; |
260 base::StringToInt(it->first, &k); | 255 base::StringToInt(it->first, &k); |
261 base::StringToInt(it->second, &v); | 256 base::StringToInt(it->second, &v); |
262 (*demotions_by_type)[static_cast<AutocompleteMatchType::Type>(k)] = | 257 (*demotions_by_type)[static_cast<AutocompleteMatchType::Type>(k)] = |
263 static_cast<float>(v) / 100.0f; | 258 static_cast<float>(v) / 100.0f; |
264 } | 259 } |
265 } | 260 } |
266 } | 261 } |
267 | 262 |
| 263 bool OmniboxFieldTrial::ReorderForLegalDefaultMatch( |
| 264 AutocompleteInput::PageClassification current_page_classification) { |
| 265 return OmniboxFieldTrial::GetValueForRuleInContext( |
| 266 kReorderForLegalDefaultMatchRule, current_page_classification) == |
| 267 kReorderForLegalDefaultMatchRuleEnabled; |
| 268 } |
| 269 |
| 270 const char OmniboxFieldTrial::kBundledExperimentFieldTrialName[] = |
| 271 "OmniboxBundledExperimentV1"; |
| 272 const char OmniboxFieldTrial::kSearchHistoryRule[] = "SearchHistory"; |
| 273 const char OmniboxFieldTrial::kDemoteByTypeRule[] = "DemoteByType"; |
| 274 const char OmniboxFieldTrial::kReorderForLegalDefaultMatchRule[] = |
| 275 "ReorderForLegalDefaultMatch"; |
| 276 const char OmniboxFieldTrial::kReorderForLegalDefaultMatchRuleEnabled[] = |
| 277 "ReorderForLegalDefaultMatch"; |
| 278 |
268 // Background and implementation details: | 279 // Background and implementation details: |
269 // | 280 // |
270 // Each experiment group in any field trial can come with an optional set of | 281 // Each experiment group in any field trial can come with an optional set of |
271 // parameters (key-value pairs). In the bundled omnibox experiment | 282 // parameters (key-value pairs). In the bundled omnibox experiment |
272 // (kBundledExperimentFieldTrialName), each experiment group comes with a | 283 // (kBundledExperimentFieldTrialName), each experiment group comes with a |
273 // list of parameters in the form: | 284 // list of parameters in the form: |
274 // key=<Rule>: | 285 // key=<Rule>: |
275 // <AutocompleteInput::PageClassification (as an int)>: | 286 // <AutocompleteInput::PageClassification (as an int)>: |
276 // <whether Instant Extended is enabled (as a 1 or 0)> | 287 // <whether Instant Extended is enabled (as a 1 or 0)> |
277 // (note that there are no linebreaks in keys; this format is for | 288 // (note that there are no linebreaks in keys; this format is for |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 if (it != params.end()) | 331 if (it != params.end()) |
321 return it->second; | 332 return it->second; |
322 // Fall back to the global instant extended context. | 333 // Fall back to the global instant extended context. |
323 it = params.find(rule + ":" + page_classification_str + ":*"); | 334 it = params.find(rule + ":" + page_classification_str + ":*"); |
324 if (it != params.end()) | 335 if (it != params.end()) |
325 return it->second; | 336 return it->second; |
326 // Look up rule in the global context. | 337 // Look up rule in the global context. |
327 it = params.find(rule + ":*:*"); | 338 it = params.find(rule + ":*:*"); |
328 return (it != params.end()) ? it->second : std::string(); | 339 return (it != params.end()) ? it->second : std::string(); |
329 } | 340 } |
OLD | NEW |