Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/common/variations/variations_util.h" | 5 #include "chrome/common/variations/variations_util.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/metrics/field_trial.h" | |
| 10 #include "base/strings/string_split.h" | 11 #include "base/strings/string_split.h" |
| 11 #include "chrome/common/child_process_logging.h" | 12 #include "chrome/common/child_process_logging.h" |
| 12 #include "chrome/common/crash_keys.h" | 13 #include "chrome/common/crash_keys.h" |
| 14 #include "chrome/common/variations/fieldtrial_testing_config.h" | |
| 13 #include "components/variations/active_field_trials.h" | 15 #include "components/variations/active_field_trials.h" |
| 14 #include "components/variations/variations_associated_data.h" | 16 #include "components/variations/variations_associated_data.h" |
| 15 #include "net/base/escape.h" | 17 #include "net/base/escape.h" |
| 16 | 18 |
| 17 namespace chrome_variations { | 19 namespace chrome_variations { |
| 18 | 20 |
| 19 namespace { | 21 namespace { |
| 20 | 22 |
| 21 std::string EscapeValue(const std::string& value) { | 23 std::string EscapeValue(const std::string& value) { |
| 22 return net::UnescapeURLComponent(value, net::UnescapeRule::URL_SPECIAL_CHARS); | 24 return net::UnescapeURLComponent(value, net::UnescapeRule::URL_SPECIAL_CHARS); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 std::string value = EscapeValue(key_values[i + 1]); | 58 std::string value = EscapeValue(key_values[i + 1]); |
| 57 params[key] = value; | 59 params[key] = value; |
| 58 } | 60 } |
| 59 std::string trial = EscapeValue(group_parts[0]); | 61 std::string trial = EscapeValue(group_parts[0]); |
| 60 std::string group = EscapeValue(group_parts[1]); | 62 std::string group = EscapeValue(group_parts[1]); |
| 61 variations::AssociateVariationParams(trial, group, params); | 63 variations::AssociateVariationParams(trial, group, params); |
| 62 } | 64 } |
| 63 return true; | 65 return true; |
| 64 } | 66 } |
| 65 | 67 |
| 68 bool AssociateParamsFromFieldTrialConfig() { | |
|
Alexei Svitkine (slow)
2015/07/08 17:10:17
Can you add a test?
Maybe make a helper function
danduong
2015/07/09 21:35:54
Done.
| |
| 69 for (size_t i = 0; i < kFieldTrialConfig.groups_size; ++i) { | |
| 70 const FieldTrialTestingGroup& group = kFieldTrialConfig.groups[i]; | |
| 71 if (group.params_size) { | |
|
Alexei Svitkine (slow)
2015/07/08 17:10:17
Nit: Since this is a number, explicitly != 0 for c
danduong
2015/07/09 21:35:54
Done.
| |
| 72 std::map<std::string, std::string> params; | |
| 73 for (size_t j = 0; j < group.params_size; ++j) { | |
| 74 const FieldTrialGroupParams& param = group.params[j]; | |
| 75 params[EscapeValue(param.key)] = EscapeValue(param.value); | |
| 76 } | |
| 77 std::string trial = EscapeValue(group.study); | |
| 78 std::string group_name = EscapeValue(group.group_name); | |
| 79 variations::AssociateVariationParams(trial, group_name, params); | |
| 80 } | |
| 81 base::FieldTrialList::CreateFieldTrial(group.study, group.group_name); | |
| 82 } | |
| 83 return true; | |
| 84 } | |
| 85 | |
| 66 } // namespace chrome_variations | 86 } // namespace chrome_variations |
| OLD | NEW |