| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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::string16> entries; |
| 75 base::SplitString(labels, google_update::kExperimentLabelSeparator, &entries); | 75 base::SplitString(labels, google_update::kExperimentLabelSeparator, &entries); |
| 76 | 76 |
| 77 // For each label, keep the ones that do not look like a Variations label. | 77 // For each label, keep the ones that do not look like a Variations label. |
| 78 base::string16 non_variation_labels; | 78 base::string16 non_variation_labels; |
| 79 for (std::vector<base::string16>::const_iterator it = entries.begin(); | 79 for (std::vector<base::string16>::const_iterator it = entries.begin(); |
| 80 it != entries.end(); ++it) { | 80 it != entries.end(); ++it) { |
| 81 if (it->empty() || | 81 if (it->empty() || |
| 82 StartsWith(*it, base::ASCIIToUTF16(kVariationPrefix), false)) { | 82 base::StartsWith(*it, base::ASCIIToUTF16(kVariationPrefix), false)) { |
| 83 continue; | 83 continue; |
| 84 } | 84 } |
| 85 | 85 |
| 86 // Dump the whole thing, including the timestamp. | 86 // Dump the whole thing, including the timestamp. |
| 87 if (!non_variation_labels.empty()) | 87 if (!non_variation_labels.empty()) |
| 88 non_variation_labels += google_update::kExperimentLabelSeparator; | 88 non_variation_labels += google_update::kExperimentLabelSeparator; |
| 89 non_variation_labels += *it; | 89 non_variation_labels += *it; |
| 90 } | 90 } |
| 91 | 91 |
| 92 return non_variation_labels; | 92 return non_variation_labels; |
| 93 } | 93 } |
| 94 | 94 |
| 95 base::string16 CombineExperimentLabels(const base::string16& variation_labels, | 95 base::string16 CombineExperimentLabels(const base::string16& variation_labels, |
| 96 const base::string16& other_labels) { | 96 const base::string16& other_labels) { |
| 97 const base::string16 separator(1, google_update::kExperimentLabelSeparator); | 97 const base::string16 separator(1, google_update::kExperimentLabelSeparator); |
| 98 DCHECK(!StartsWith(variation_labels, separator, false)); | 98 DCHECK(!base::StartsWith(variation_labels, separator, false)); |
| 99 DCHECK(!EndsWith(variation_labels, separator, false)); | 99 DCHECK(!EndsWith(variation_labels, separator, false)); |
| 100 DCHECK(!StartsWith(other_labels, separator, false)); | 100 DCHECK(!base::StartsWith(other_labels, separator, false)); |
| 101 DCHECK(!EndsWith(other_labels, separator, false)); | 101 DCHECK(!EndsWith(other_labels, separator, false)); |
| 102 // Note that if either label is empty, a separator is not necessary. | 102 // Note that if either label is empty, a separator is not necessary. |
| 103 base::string16 combined_labels = other_labels; | 103 base::string16 combined_labels = other_labels; |
| 104 if (!other_labels.empty() && !variation_labels.empty()) | 104 if (!other_labels.empty() && !variation_labels.empty()) |
| 105 combined_labels += google_update::kExperimentLabelSeparator; | 105 combined_labels += google_update::kExperimentLabelSeparator; |
| 106 combined_labels += variation_labels; | 106 combined_labels += variation_labels; |
| 107 return combined_labels; | 107 return combined_labels; |
| 108 } | 108 } |
| 109 | 109 |
| 110 } // namespace chrome_variations | 110 } // namespace chrome_variations |
| OLD | NEW |