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

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

Issue 105473003: Add explicit base namespace to string16 users. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/experiment_labels_win.h" 5 #include "chrome/common/metrics/variations/experiment_labels_win.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/string_split.h" 9 #include "base/strings/string_split.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
11 #include "chrome/installer/util/google_update_constants.h" 11 #include "chrome/installer/util/google_update_constants.h"
12 #include "chrome/installer/util/google_update_experiment_util.h" 12 #include "chrome/installer/util/google_update_experiment_util.h"
13 #include "components/variations/variations_associated_data.h" 13 #include "components/variations/variations_associated_data.h"
14 14
15 namespace chrome_variations { 15 namespace chrome_variations {
16 16
17 namespace { 17 namespace {
18 18
19 const wchar_t kVariationPrefix[] = L"CrVar"; 19 const wchar_t kVariationPrefix[] = L"CrVar";
20 20
21 // This method builds a single experiment label for a Chrome Variation, 21 // This method builds a single experiment label for a Chrome Variation,
22 // including a timestamp that is a year in the future from |current_time|. Since 22 // including a timestamp that is a year in the future from |current_time|. Since
23 // multiple headers can be transmitted, |count| is a number that is appended 23 // multiple headers can be transmitted, |count| is a number that is appended
24 // after the label key to differentiate the labels. 24 // after the label key to differentiate the labels.
25 string16 CreateSingleExperimentLabel(int count, VariationID id, 25 base::string16 CreateSingleExperimentLabel(int count, VariationID id,
26 const base::Time& current_time) { 26 const base::Time& current_time) {
27 // Build the parts separately so they can be validated. 27 // Build the parts separately so they can be validated.
28 const string16 key = kVariationPrefix + base::IntToString16(count); 28 const base::string16 key = kVariationPrefix + base::IntToString16(count);
29 DCHECK_LE(key.size(), 8U); 29 DCHECK_LE(key.size(), 8U);
30 const string16 value = base::IntToString16(id); 30 const base::string16 value = base::IntToString16(id);
31 DCHECK_LE(value.size(), 8U); 31 DCHECK_LE(value.size(), 8U);
32 string16 label(key); 32 base::string16 label(key);
33 label += L'='; 33 label += L'=';
34 label += value; 34 label += value;
35 label += L'|'; 35 label += L'|';
36 label += installer::BuildExperimentDateString(current_time); 36 label += installer::BuildExperimentDateString(current_time);
37 return label; 37 return label;
38 } 38 }
39 39
40 } // namespace 40 } // namespace
41 41
42 string16 BuildGoogleUpdateExperimentLabel( 42 base::string16 BuildGoogleUpdateExperimentLabel(
43 const base::FieldTrial::ActiveGroups& active_groups) { 43 const base::FieldTrial::ActiveGroups& active_groups) {
44 string16 experiment_labels; 44 base::string16 experiment_labels;
45 int counter = 0; 45 int counter = 0;
46 46
47 const base::Time current_time(base::Time::Now()); 47 const base::Time current_time(base::Time::Now());
48 48
49 // Find all currently active VariationIDs associated with Google Update. 49 // Find all currently active VariationIDs associated with Google Update.
50 for (base::FieldTrial::ActiveGroups::const_iterator it = 50 for (base::FieldTrial::ActiveGroups::const_iterator it =
51 active_groups.begin(); it != active_groups.end(); ++it) { 51 active_groups.begin(); it != active_groups.end(); ++it) {
52 const VariationID id = GetGoogleVariationID(GOOGLE_UPDATE_SERVICE, 52 const VariationID id = GetGoogleVariationID(GOOGLE_UPDATE_SERVICE,
53 it->trial_name, it->group_name); 53 it->trial_name, it->group_name);
54 54
55 if (id == EMPTY_ID) 55 if (id == EMPTY_ID)
56 continue; 56 continue;
57 57
58 if (!experiment_labels.empty()) 58 if (!experiment_labels.empty())
59 experiment_labels += google_update::kExperimentLabelSep; 59 experiment_labels += google_update::kExperimentLabelSep;
60 experiment_labels += CreateSingleExperimentLabel(++counter, id, 60 experiment_labels += CreateSingleExperimentLabel(++counter, id,
61 current_time); 61 current_time);
62 } 62 }
63 63
64 return experiment_labels; 64 return experiment_labels;
65 } 65 }
66 66
67 string16 ExtractNonVariationLabels(const string16& labels) { 67 base::string16 ExtractNonVariationLabels(const base::string16& labels) {
68 string16 non_variation_labels; 68 base::string16 non_variation_labels;
69 69
70 // First, split everything by the label separator. 70 // First, split everything by the label separator.
71 std::vector<string16> entries; 71 std::vector<base::string16> entries;
72 base::SplitStringUsingSubstr(labels, google_update::kExperimentLabelSep, 72 base::SplitStringUsingSubstr(labels, google_update::kExperimentLabelSep,
73 &entries); 73 &entries);
74 74
75 // 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 for (std::vector<string16>::const_iterator it = entries.begin(); 76 for (std::vector<base::string16>::const_iterator it = entries.begin();
77 it != entries.end(); ++it) { 77 it != entries.end(); ++it) {
78 if (it->empty() || StartsWith(*it, kVariationPrefix, false)) 78 if (it->empty() || StartsWith(*it, kVariationPrefix, false))
79 continue; 79 continue;
80 80
81 // Dump the whole thing, including the timestamp. 81 // Dump the whole thing, including the timestamp.
82 if (!non_variation_labels.empty()) 82 if (!non_variation_labels.empty())
83 non_variation_labels += google_update::kExperimentLabelSep; 83 non_variation_labels += google_update::kExperimentLabelSep;
84 non_variation_labels += *it; 84 non_variation_labels += *it;
85 } 85 }
86 86
87 return non_variation_labels; 87 return non_variation_labels;
88 } 88 }
89 89
90 string16 CombineExperimentLabels(const string16& variation_labels, 90 base::string16 CombineExperimentLabels(const base::string16& variation_labels,
91 const string16& other_labels) { 91 const base::string16& other_labels) {
92 DCHECK(!StartsWith(variation_labels, google_update::kExperimentLabelSep, 92 DCHECK(!StartsWith(variation_labels, google_update::kExperimentLabelSep,
93 false)); 93 false));
94 DCHECK(!EndsWith(variation_labels, google_update::kExperimentLabelSep, 94 DCHECK(!EndsWith(variation_labels, google_update::kExperimentLabelSep,
95 false)); 95 false));
96 DCHECK(!StartsWith(other_labels, google_update::kExperimentLabelSep, false)); 96 DCHECK(!StartsWith(other_labels, google_update::kExperimentLabelSep, false));
97 DCHECK(!EndsWith(other_labels, google_update::kExperimentLabelSep, false)); 97 DCHECK(!EndsWith(other_labels, google_update::kExperimentLabelSep, false));
98 // Note that if either label is empty, a separator is not necessary. 98 // Note that if either label is empty, a separator is not necessary.
99 string16 combined_labels = other_labels; 99 base::string16 combined_labels = other_labels;
100 if (!other_labels.empty() && !variation_labels.empty()) 100 if (!other_labels.empty() && !variation_labels.empty())
101 combined_labels += google_update::kExperimentLabelSep; 101 combined_labels += google_update::kExperimentLabelSep;
102 combined_labels += variation_labels; 102 combined_labels += variation_labels;
103 return combined_labels; 103 return combined_labels;
104 } 104 }
105 105
106 } // namespace chrome_variations 106 } // namespace chrome_variations
OLDNEW
« no previous file with comments | « chrome/common/metrics/variations/experiment_labels_win.h ('k') | chrome/common/multi_process_lock_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698