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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 experiment_labels += google_update::kExperimentLabelSeparator; | 64 experiment_labels += google_update::kExperimentLabelSeparator; |
65 experiment_labels += CreateSingleExperimentLabel(++counter, id, | 65 experiment_labels += CreateSingleExperimentLabel(++counter, id, |
66 current_time); | 66 current_time); |
67 } | 67 } |
68 | 68 |
69 return experiment_labels; | 69 return experiment_labels; |
70 } | 70 } |
71 | 71 |
72 base::string16 ExtractNonVariationLabels(const base::string16& labels) { | 72 base::string16 ExtractNonVariationLabels(const base::string16& labels) { |
73 // First, split everything by the label separator. | 73 // First, split everything by the label separator. |
74 std::vector<base::string16> entries; | 74 std::vector<base::StringPiece16> entries = base::SplitStringPiece( |
75 base::SplitString(labels, google_update::kExperimentLabelSeparator, &entries); | 75 labels, base::StringPiece16(&google_update::kExperimentLabelSeparator, 1), |
| 76 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
76 | 77 |
77 // For each label, keep the ones that do not look like a Variations label. | 78 // For each label, keep the ones that do not look like a Variations label. |
78 base::string16 non_variation_labels; | 79 base::string16 non_variation_labels; |
79 for (std::vector<base::string16>::const_iterator it = entries.begin(); | 80 for (const base::StringPiece16& entry : entries) { |
80 it != entries.end(); ++it) { | 81 if (entry.empty() || |
81 if (it->empty() || | 82 base::StartsWith(entry, |
82 base::StartsWith(*it, base::ASCIIToUTF16(kVariationPrefix), false)) { | 83 base::ASCIIToUTF16(kVariationPrefix), |
| 84 base::CompareCase::INSENSITIVE_ASCII)) { |
83 continue; | 85 continue; |
84 } | 86 } |
85 | 87 |
86 // Dump the whole thing, including the timestamp. | 88 // Dump the whole thing, including the timestamp. |
87 if (!non_variation_labels.empty()) | 89 if (!non_variation_labels.empty()) |
88 non_variation_labels += google_update::kExperimentLabelSeparator; | 90 non_variation_labels += google_update::kExperimentLabelSeparator; |
89 non_variation_labels += *it; | 91 entry.AppendToString(&non_variation_labels); |
90 } | 92 } |
91 | 93 |
92 return non_variation_labels; | 94 return non_variation_labels; |
93 } | 95 } |
94 | 96 |
95 base::string16 CombineExperimentLabels(const base::string16& variation_labels, | 97 base::string16 CombineExperimentLabels(const base::string16& variation_labels, |
96 const base::string16& other_labels) { | 98 const base::string16& other_labels) { |
97 const base::string16 separator(1, google_update::kExperimentLabelSeparator); | 99 base::StringPiece16 separator(&google_update::kExperimentLabelSeparator, 1); |
98 DCHECK(!base::StartsWith(variation_labels, separator, false)); | 100 DCHECK(!base::StartsWith(variation_labels, separator, |
99 DCHECK(!base::EndsWith(variation_labels, separator, false)); | 101 base::CompareCase::SENSITIVE)); |
100 DCHECK(!base::StartsWith(other_labels, separator, false)); | 102 DCHECK(!base::EndsWith(variation_labels, separator, |
101 DCHECK(!base::EndsWith(other_labels, separator, false)); | 103 base::CompareCase::SENSITIVE)); |
| 104 DCHECK(!base::StartsWith(other_labels, separator, |
| 105 base::CompareCase::SENSITIVE)); |
| 106 DCHECK(!base::EndsWith(other_labels, separator, |
| 107 base::CompareCase::SENSITIVE)); |
102 // Note that if either label is empty, a separator is not necessary. | 108 // Note that if either label is empty, a separator is not necessary. |
103 base::string16 combined_labels = other_labels; | 109 base::string16 combined_labels = other_labels; |
104 if (!other_labels.empty() && !variation_labels.empty()) | 110 if (!other_labels.empty() && !variation_labels.empty()) |
105 combined_labels += google_update::kExperimentLabelSeparator; | 111 combined_labels += google_update::kExperimentLabelSeparator; |
106 combined_labels += variation_labels; | 112 combined_labels += variation_labels; |
107 return combined_labels; | 113 return combined_labels; |
108 } | 114 } |
109 | 115 |
110 } // namespace chrome_variations | 116 } // namespace chrome_variations |
OLD | NEW |