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
3 // found in the LICENSE file.
5 #include "chrome/common/variations/variations_util.h"
10 #include "base/strings/string_split.h"
11 #include "chrome/common/child_process_logging.h"
12 #include "chrome/common/crash_keys.h"
13 #include "components/variations/active_field_trials.h"
14 #include "components/variations/variations_associated_data.h"
15 #include "net/base/escape.h"
17 namespace chrome_variations
{
21 std::string
EscapeValue(const std::string
& value
) {
22 return net::UnescapeURLComponent(value
, net::UnescapeRule::URL_SPECIAL_CHARS
);
27 void SetChildProcessLoggingVariationList() {
28 std::vector
<std::string
> experiment_strings
;
29 variations::GetFieldTrialActiveGroupIdsAsStrings(&experiment_strings
);
30 crash_keys::SetVariationsList(experiment_strings
);
33 bool AssociateParamsFromString(const std::string
& varations_string
) {
34 // Format: Trial1.Group1:k1/v1/k2/v2,Trial2.Group2:k1/v1/k2/v2
35 std::vector
<std::string
> experiment_groups
;
36 base::SplitString(varations_string
, ',', &experiment_groups
);
37 for (const auto& experiment_group
: experiment_groups
) {
38 std::vector
<std::string
> experiment
;
39 base::SplitString(experiment_group
, ':', &experiment
);
40 if (experiment
.size() != 2)
43 std::vector
<std::string
> group_parts
;
44 base::SplitString(experiment
[0], '.', &group_parts
);
45 if (group_parts
.size() != 2)
48 std::vector
<std::string
> key_values
;
49 base::SplitString(experiment
[1], '/', &key_values
);
50 if (key_values
.size() % 2 != 0)
53 std::map
<std::string
, std::string
> params
;
54 for (size_t i
= 0; i
< key_values
.size(); i
+= 2) {
55 std::string key
= EscapeValue(key_values
[i
]);
56 std::string value
= EscapeValue(key_values
[i
+ 1]);
59 std::string trial
= EscapeValue(group_parts
[0]);
60 std::string group
= EscapeValue(group_parts
[1]);
61 variations::AssociateVariationParams(trial
, group
, params
);
66 } // namespace chrome_variations