Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(358)

Side by Side Diff: chrome/common/metrics/variations/variations_util.cc

Issue 23579003: GCAPI should append to the existing experiment_labels instead of clobbering them. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: check return value of ReadExperimentLabels Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/installer/gcapi/gcapi_omaha_experiment.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/common/metrics/variations/variations_util.h" 5 #include "chrome/common/metrics/variations/variations_util.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/strings/string16.h" 9 #include "base/strings/string16.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 "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "chrome/common/child_process_logging.h" 15 #include "chrome/common/child_process_logging.h"
16 #include "chrome/installer/util/google_update_constants.h"
16 #include "chrome/installer/util/google_update_experiment_util.h" 17 #include "chrome/installer/util/google_update_experiment_util.h"
17 18
18 namespace chrome_variations { 19 namespace chrome_variations {
19 20
20 namespace { 21 namespace {
21 22
22 const char kVariationPrefix[] = "CrVar"; 23 const char kVariationPrefix[] = "CrVar";
23 const char kExperimentLabelSep[] = ";";
robertshield 2013/08/30 01:13:53 This has gone from a char to a wchar_t and doesn't
Alexei Svitkine (slow) 2013/08/30 02:16:47 It should be a char16, since on some platforms wch
gab 2013/08/30 02:43:18 Good catch; thanks for the hint; done.
24 24
25 // Populates |name_group_ids| based on |active_groups|. 25 // Populates |name_group_ids| based on |active_groups|.
26 void GetFieldTrialActiveGroupIdsForActiveGroups( 26 void GetFieldTrialActiveGroupIdsForActiveGroups(
27 const base::FieldTrial::ActiveGroups& active_groups, 27 const base::FieldTrial::ActiveGroups& active_groups,
28 std::vector<ActiveGroupId>* name_group_ids) { 28 std::vector<ActiveGroupId>* name_group_ids) {
29 DCHECK(name_group_ids->empty()); 29 DCHECK(name_group_ids->empty());
30 for (base::FieldTrial::ActiveGroups::const_iterator it = 30 for (base::FieldTrial::ActiveGroups::const_iterator it =
31 active_groups.begin(); it != active_groups.end(); ++it) { 31 active_groups.begin(); it != active_groups.end(); ++it) {
32 name_group_ids->push_back(MakeActiveGroupId(it->trial_name, 32 name_group_ids->push_back(MakeActiveGroupId(it->trial_name,
33 it->group_name)); 33 it->group_name));
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 // Find all currently active VariationIDs associated with Google Update. 111 // Find all currently active VariationIDs associated with Google Update.
112 for (base::FieldTrial::ActiveGroups::const_iterator it = 112 for (base::FieldTrial::ActiveGroups::const_iterator it =
113 active_groups.begin(); it != active_groups.end(); ++it) { 113 active_groups.begin(); it != active_groups.end(); ++it) {
114 const VariationID id = GetGoogleVariationID(GOOGLE_UPDATE_SERVICE, 114 const VariationID id = GetGoogleVariationID(GOOGLE_UPDATE_SERVICE,
115 it->trial_name, it->group_name); 115 it->trial_name, it->group_name);
116 116
117 if (id == EMPTY_ID) 117 if (id == EMPTY_ID)
118 continue; 118 continue;
119 119
120 if (!experiment_labels.empty()) 120 if (!experiment_labels.empty())
121 experiment_labels += ASCIIToUTF16(kExperimentLabelSep); 121 experiment_labels += google_update::kExperimentLabelSep;
122 experiment_labels += CreateSingleExperimentLabel(++counter, id); 122 experiment_labels += CreateSingleExperimentLabel(++counter, id);
123 } 123 }
124 124
125 return experiment_labels; 125 return experiment_labels;
126 } 126 }
127 127
128 string16 ExtractNonVariationLabels(const string16& labels) { 128 string16 ExtractNonVariationLabels(const string16& labels) {
129 const string16 separator = ASCIIToUTF16(kExperimentLabelSep);
130 string16 non_variation_labels; 129 string16 non_variation_labels;
131 130
132 // First, split everything by the label separator. 131 // First, split everything by the label separator.
133 std::vector<string16> entries; 132 std::vector<string16> entries;
134 base::SplitStringUsingSubstr(labels, separator, &entries); 133 base::SplitStringUsingSubstr(
134 labels, google_update::kExperimentLabelSep, &entries);
135 135
136 // For each label, keep the ones that do not look like a Variations label. 136 // For each label, keep the ones that do not look like a Variations label.
137 for (std::vector<string16>::const_iterator it = entries.begin(); 137 for (std::vector<string16>::const_iterator it = entries.begin();
138 it != entries.end(); ++it) { 138 it != entries.end(); ++it) {
139 if (it->empty() || StartsWith(*it, ASCIIToUTF16(kVariationPrefix), false)) 139 if (it->empty() || StartsWith(*it, ASCIIToUTF16(kVariationPrefix), false))
140 continue; 140 continue;
141 141
142 // Dump the whole thing, including the timestamp. 142 // Dump the whole thing, including the timestamp.
143 if (!non_variation_labels.empty()) 143 if (!non_variation_labels.empty())
144 non_variation_labels += separator; 144 non_variation_labels += google_update::kExperimentLabelSep;
145 non_variation_labels += *it; 145 non_variation_labels += *it;
146 } 146 }
147 147
148 return non_variation_labels; 148 return non_variation_labels;
149 } 149 }
150 150
151 string16 CombineExperimentLabels(const string16& variation_labels, 151 string16 CombineExperimentLabels(const string16& variation_labels,
152 const string16& other_labels) { 152 const string16& other_labels) {
153 const string16 separator = ASCIIToUTF16(kExperimentLabelSep); 153 DCHECK(!StartsWith(variation_labels, google_update::kExperimentLabelSep,
154 DCHECK(!StartsWith(variation_labels, separator, false)); 154 false));
155 DCHECK(!EndsWith(variation_labels, separator, false)); 155 DCHECK(!EndsWith(variation_labels, google_update::kExperimentLabelSep,
156 DCHECK(!StartsWith(other_labels, separator, false)); 156 false));
157 DCHECK(!EndsWith(other_labels, separator, false)); 157 DCHECK(!StartsWith(other_labels, google_update::kExperimentLabelSep, false));
158 DCHECK(!EndsWith(other_labels, google_update::kExperimentLabelSep, false));
158 // Note that if either label is empty, a separator is not necessary. 159 // Note that if either label is empty, a separator is not necessary.
159 string16 combined_labels = other_labels; 160 string16 combined_labels = other_labels;
160 if (!other_labels.empty() && !variation_labels.empty()) 161 if (!other_labels.empty() && !variation_labels.empty())
161 combined_labels += separator; 162 combined_labels += google_update::kExperimentLabelSep;
162 combined_labels += variation_labels; 163 combined_labels += variation_labels;
163 return combined_labels; 164 return combined_labels;
164 } 165 }
165 166
166 // Functions below are exposed for testing explicitly behind this namespace. 167 // Functions below are exposed for testing explicitly behind this namespace.
167 // They simply wrap existing functions in this file. 168 // They simply wrap existing functions in this file.
168 namespace testing { 169 namespace testing {
169 170
170 void TestGetFieldTrialActiveGroupIds( 171 void TestGetFieldTrialActiveGroupIds(
171 const base::FieldTrial::ActiveGroups& active_groups, 172 const base::FieldTrial::ActiveGroups& active_groups,
172 std::vector<ActiveGroupId>* name_group_ids) { 173 std::vector<ActiveGroupId>* name_group_ids) {
173 GetFieldTrialActiveGroupIdsForActiveGroups(active_groups, 174 GetFieldTrialActiveGroupIdsForActiveGroups(active_groups,
174 name_group_ids); 175 name_group_ids);
175 } 176 }
176 177
177 } // namespace testing 178 } // namespace testing
178 179
179 } // namespace chrome_variations 180 } // namespace chrome_variations
OLDNEW
« no previous file with comments | « no previous file | chrome/installer/gcapi/gcapi_omaha_experiment.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698