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/experiment_labels.h" | 5 #include "chrome/common/variations/experiment_labels.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 | 51 |
52 // Find all currently active VariationIDs associated with Google Update. | 52 // Find all currently active VariationIDs associated with Google Update. |
53 for (base::FieldTrial::ActiveGroups::const_iterator it = | 53 for (base::FieldTrial::ActiveGroups::const_iterator it = |
54 active_groups.begin(); it != active_groups.end(); ++it) { | 54 active_groups.begin(); it != active_groups.end(); ++it) { |
55 const VariationID id = GetGoogleVariationID(GOOGLE_UPDATE_SERVICE, | 55 const VariationID id = GetGoogleVariationID(GOOGLE_UPDATE_SERVICE, |
56 it->trial_name, it->group_name); | 56 it->trial_name, it->group_name); |
57 | 57 |
58 if (id == EMPTY_ID) | 58 if (id == EMPTY_ID) |
59 continue; | 59 continue; |
60 | 60 |
61 if (!experiment_labels.empty()) { | 61 if (!experiment_labels.empty()) |
62 experiment_labels += | 62 experiment_labels += google_update::kExperimentLabelSeparator; |
63 base::ASCIIToUTF16(google_update::kExperimentLabelSep); | |
64 } | |
65 experiment_labels += CreateSingleExperimentLabel(++counter, id, | 63 experiment_labels += CreateSingleExperimentLabel(++counter, id, |
66 current_time); | 64 current_time); |
67 } | 65 } |
68 | 66 |
69 return experiment_labels; | 67 return experiment_labels; |
70 } | 68 } |
71 | 69 |
72 base::string16 ExtractNonVariationLabels(const base::string16& labels) { | 70 base::string16 ExtractNonVariationLabels(const base::string16& labels) { |
73 const base::string16 separator = | |
74 base::ASCIIToUTF16(google_update::kExperimentLabelSep); | |
75 base::string16 non_variation_labels; | |
76 | |
77 // First, split everything by the label separator. | 71 // First, split everything by the label separator. |
78 std::vector<base::string16> entries; | 72 std::vector<base::string16> entries; |
79 base::SplitStringUsingSubstr(labels, separator, &entries); | 73 base::SplitString(labels, google_update::kExperimentLabelSeparator, &entries); |
80 | 74 |
81 // For each label, keep the ones that do not look like a Variations label. | 75 // For each label, keep the ones that do not look like a Variations label. |
| 76 base::string16 non_variation_labels; |
82 for (std::vector<base::string16>::const_iterator it = entries.begin(); | 77 for (std::vector<base::string16>::const_iterator it = entries.begin(); |
83 it != entries.end(); ++it) { | 78 it != entries.end(); ++it) { |
84 if (it->empty() || | 79 if (it->empty() || |
85 StartsWith(*it, base::ASCIIToUTF16(kVariationPrefix), false)) { | 80 StartsWith(*it, base::ASCIIToUTF16(kVariationPrefix), false)) { |
86 continue; | 81 continue; |
87 } | 82 } |
88 | 83 |
89 // Dump the whole thing, including the timestamp. | 84 // Dump the whole thing, including the timestamp. |
90 if (!non_variation_labels.empty()) | 85 if (!non_variation_labels.empty()) |
91 non_variation_labels += separator; | 86 non_variation_labels += google_update::kExperimentLabelSeparator; |
92 non_variation_labels += *it; | 87 non_variation_labels += *it; |
93 } | 88 } |
94 | 89 |
95 return non_variation_labels; | 90 return non_variation_labels; |
96 } | 91 } |
97 | 92 |
98 base::string16 CombineExperimentLabels(const base::string16& variation_labels, | 93 base::string16 CombineExperimentLabels(const base::string16& variation_labels, |
99 const base::string16& other_labels) { | 94 const base::string16& other_labels) { |
100 const base::string16 separator = | 95 const base::string16 separator(1, google_update::kExperimentLabelSeparator); |
101 base::ASCIIToUTF16(google_update::kExperimentLabelSep); | |
102 DCHECK(!StartsWith(variation_labels, separator, false)); | 96 DCHECK(!StartsWith(variation_labels, separator, false)); |
103 DCHECK(!EndsWith(variation_labels, separator, false)); | 97 DCHECK(!EndsWith(variation_labels, separator, false)); |
104 DCHECK(!StartsWith(other_labels, separator, false)); | 98 DCHECK(!StartsWith(other_labels, separator, false)); |
105 DCHECK(!EndsWith(other_labels, separator, false)); | 99 DCHECK(!EndsWith(other_labels, separator, false)); |
106 // Note that if either label is empty, a separator is not necessary. | 100 // Note that if either label is empty, a separator is not necessary. |
107 base::string16 combined_labels = other_labels; | 101 base::string16 combined_labels = other_labels; |
108 if (!other_labels.empty() && !variation_labels.empty()) | 102 if (!other_labels.empty() && !variation_labels.empty()) |
109 combined_labels += separator; | 103 combined_labels += google_update::kExperimentLabelSeparator; |
110 combined_labels += variation_labels; | 104 combined_labels += variation_labels; |
111 return combined_labels; | 105 return combined_labels; |
112 } | 106 } |
113 | 107 |
114 } // namespace chrome_variations | 108 } // namespace chrome_variations |
OLD | NEW |