[email protected] | cffb200 | 2014-05-22 03:58:39 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
[email protected] | 2134467 | 2013-11-07 06:04:28 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
sdefresne | a59146f | 2015-08-14 15:47:00 | [diff] [blame] | 5 | #include "components/variations/experiment_labels.h" |
[email protected] | cffb200 | 2014-05-22 03:58:39 | [diff] [blame] | 6 | |
7 | #include <vector> | ||||
[email protected] | 2134467 | 2013-11-07 06:04:28 | [diff] [blame] | 8 | |
9 | #include "base/logging.h" | ||||
10 | #include "base/strings/string_number_conversions.h" | ||||
11 | #include "base/strings/string_split.h" | ||||
12 | #include "base/strings/string_util.h" | ||||
[email protected] | d383ffc | 2013-12-06 15:27:28 | [diff] [blame] | 13 | #include "base/strings/utf_string_conversions.h" |
[email protected] | 2134467 | 2013-11-07 06:04:28 | [diff] [blame] | 14 | #include "components/variations/variations_associated_data.h" |
sdefresne | 1eeb90f | 2015-08-13 18:52:09 | [diff] [blame] | 15 | #include "components/variations/variations_experiment_util.h" |
[email protected] | 2134467 | 2013-11-07 06:04:28 | [diff] [blame] | 16 | |
blundell | 57bcfed | 2015-09-04 08:44:45 | [diff] [blame] | 17 | namespace variations { |
[email protected] | 2134467 | 2013-11-07 06:04:28 | [diff] [blame] | 18 | namespace { |
19 | |||||
[email protected] | d383ffc | 2013-12-06 15:27:28 | [diff] [blame] | 20 | const char kVariationPrefix[] = "CrVar"; |
[email protected] | 2134467 | 2013-11-07 06:04:28 | [diff] [blame] | 21 | |
[email protected] | 2134467 | 2013-11-07 06:04:28 | [diff] [blame] | 22 | } // namespace |
23 | |||||
[email protected] | 428fac1 | 2013-12-05 21:38:49 | [diff] [blame] | 24 | base::string16 ExtractNonVariationLabels(const base::string16& labels) { |
[email protected] | 2134467 | 2013-11-07 06:04:28 | [diff] [blame] | 25 | // First, split everything by the label separator. |
brettw | 94a2cc2 | 2015-07-01 19:26:54 | [diff] [blame] | 26 | std::vector<base::StringPiece16> entries = base::SplitStringPiece( |
isherman | b1917aabe | 2017-06-13 23:35:14 | [diff] [blame] | 27 | labels, base::StringPiece16(&kExperimentLabelSeparator, 1), |
brettw | 94a2cc2 | 2015-07-01 19:26:54 | [diff] [blame] | 28 | base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
[email protected] | 2134467 | 2013-11-07 06:04:28 | [diff] [blame] | 29 | |
30 | // For each label, keep the ones that do not look like a Variations label. | ||||
[email protected] | 056a1a4 | 2014-05-23 22:46:48 | [diff] [blame] | 31 | base::string16 non_variation_labels; |
brettw | 94a2cc2 | 2015-07-01 19:26:54 | [diff] [blame] | 32 | for (const base::StringPiece16& entry : entries) { |
33 | if (entry.empty() || | ||||
34 | base::StartsWith(entry, | ||||
35 | base::ASCIIToUTF16(kVariationPrefix), | ||||
36 | base::CompareCase::INSENSITIVE_ASCII)) { | ||||
[email protected] | 2134467 | 2013-11-07 06:04:28 | [diff] [blame] | 37 | continue; |
[email protected] | 036a5f3 | 2013-12-25 00:26:11 | [diff] [blame] | 38 | } |
[email protected] | 2134467 | 2013-11-07 06:04:28 | [diff] [blame] | 39 | |
40 | // Dump the whole thing, including the timestamp. | ||||
41 | if (!non_variation_labels.empty()) | ||||
isherman | b1917aabe | 2017-06-13 23:35:14 | [diff] [blame] | 42 | non_variation_labels += kExperimentLabelSeparator; |
brettw | 94a2cc2 | 2015-07-01 19:26:54 | [diff] [blame] | 43 | entry.AppendToString(&non_variation_labels); |
[email protected] | 2134467 | 2013-11-07 06:04:28 | [diff] [blame] | 44 | } |
45 | |||||
46 | return non_variation_labels; | ||||
47 | } | ||||
48 | |||||
blundell | 57bcfed | 2015-09-04 08:44:45 | [diff] [blame] | 49 | } // namespace variations |