blob: 1b0d85a5c96aac932c2362162574be2299c41561 [file] [log] [blame]
[email protected]cffb2002014-05-22 03:58:391// Copyright 2014 The Chromium Authors. All rights reserved.
[email protected]21344672013-11-07 06:04:282// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
sdefresnea59146f2015-08-14 15:47:005#include "components/variations/experiment_labels.h"
[email protected]cffb2002014-05-22 03:58:396
7#include <vector>
[email protected]21344672013-11-07 06:04:288
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]d383ffc2013-12-06 15:27:2813#include "base/strings/utf_string_conversions.h"
[email protected]21344672013-11-07 06:04:2814#include "components/variations/variations_associated_data.h"
sdefresne1eeb90f2015-08-13 18:52:0915#include "components/variations/variations_experiment_util.h"
[email protected]21344672013-11-07 06:04:2816
blundell57bcfed2015-09-04 08:44:4517namespace variations {
[email protected]21344672013-11-07 06:04:2818namespace {
19
[email protected]d383ffc2013-12-06 15:27:2820const char kVariationPrefix[] = "CrVar";
[email protected]21344672013-11-07 06:04:2821
[email protected]21344672013-11-07 06:04:2822} // namespace
23
[email protected]428fac12013-12-05 21:38:4924base::string16 ExtractNonVariationLabels(const base::string16& labels) {
[email protected]21344672013-11-07 06:04:2825 // First, split everything by the label separator.
brettw94a2cc22015-07-01 19:26:5426 std::vector<base::StringPiece16> entries = base::SplitStringPiece(
ishermanb1917aabe2017-06-13 23:35:1427 labels, base::StringPiece16(&kExperimentLabelSeparator, 1),
brettw94a2cc22015-07-01 19:26:5428 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
[email protected]21344672013-11-07 06:04:2829
30 // For each label, keep the ones that do not look like a Variations label.
[email protected]056a1a42014-05-23 22:46:4831 base::string16 non_variation_labels;
brettw94a2cc22015-07-01 19:26:5432 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]21344672013-11-07 06:04:2837 continue;
[email protected]036a5f32013-12-25 00:26:1138 }
[email protected]21344672013-11-07 06:04:2839
40 // Dump the whole thing, including the timestamp.
41 if (!non_variation_labels.empty())
ishermanb1917aabe2017-06-13 23:35:1442 non_variation_labels += kExperimentLabelSeparator;
brettw94a2cc22015-07-01 19:26:5443 entry.AppendToString(&non_variation_labels);
[email protected]21344672013-11-07 06:04:2844 }
45
46 return non_variation_labels;
47}
48
blundell57bcfed2015-09-04 08:44:4549} // namespace variations