| 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" |
| 11 #include "base/strings/string_split.h" | 11 #include "base/strings/string_split.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "chrome/installer/util/google_update_experiment_util.h" | 14 #include "chrome/installer/util/google_update_experiment_util.h" |
| 15 #include "components/variations/variations_associated_data.h" | 15 #include "components/variations/variations_associated_data.h" |
| 16 | 16 |
| 17 namespace chrome_variations { | 17 namespace chrome_variations { |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 const char kVariationPrefix[] = "CrVar"; | 21 const char kVariationPrefix[] = "CrVar"; |
| 22 | 22 |
| 23 // This method builds a single experiment label for a Chrome Variation, | 23 // This method builds a single experiment label for a Chrome Variation, |
| 24 // including a timestamp that is a year in the future from |current_time|. Since | 24 // including a timestamp that is a year in the future from |current_time|. Since |
| 25 // multiple headers can be transmitted, |count| is a number that is appended | 25 // multiple headers can be transmitted, |count| is a number that is appended |
| 26 // after the label key to differentiate the labels. | 26 // after the label key to differentiate the labels. |
| 27 base::string16 CreateSingleExperimentLabel(int count, | 27 base::string16 CreateSingleExperimentLabel(int count, VariationID id, |
| 28 variations::VariationID id, | |
| 29 const base::Time& current_time) { | 28 const base::Time& current_time) { |
| 30 // Build the parts separately so they can be validated. | 29 // Build the parts separately so they can be validated. |
| 31 const base::string16 key = | 30 const base::string16 key = |
| 32 base::ASCIIToUTF16(kVariationPrefix) + base::IntToString16(count); | 31 base::ASCIIToUTF16(kVariationPrefix) + base::IntToString16(count); |
| 33 DCHECK_LE(key.size(), 8U); | 32 DCHECK_LE(key.size(), 8U); |
| 34 const base::string16 value = base::IntToString16(id); | 33 const base::string16 value = base::IntToString16(id); |
| 35 DCHECK_LE(value.size(), 8U); | 34 DCHECK_LE(value.size(), 8U); |
| 36 base::string16 label(key); | 35 base::string16 label(key); |
| 37 label += base::ASCIIToUTF16("="); | 36 label += base::ASCIIToUTF16("="); |
| 38 label += value; | 37 label += value; |
| 39 label += base::ASCIIToUTF16("|"); | 38 label += base::ASCIIToUTF16("|"); |
| 40 label += installer::BuildExperimentDateString(current_time); | 39 label += installer::BuildExperimentDateString(current_time); |
| 41 return label; | 40 return label; |
| 42 } | 41 } |
| 43 | 42 |
| 44 } // namespace | 43 } // namespace |
| 45 | 44 |
| 46 base::string16 BuildGoogleUpdateExperimentLabel( | 45 base::string16 BuildGoogleUpdateExperimentLabel( |
| 47 const base::FieldTrial::ActiveGroups& active_groups) { | 46 const base::FieldTrial::ActiveGroups& active_groups) { |
| 48 base::string16 experiment_labels; | 47 base::string16 experiment_labels; |
| 49 int counter = 0; | 48 int counter = 0; |
| 50 | 49 |
| 51 const base::Time current_time(base::Time::Now()); | 50 const base::Time current_time(base::Time::Now()); |
| 52 | 51 |
| 53 // Find all currently active VariationIDs associated with Google Update. | 52 // Find all currently active VariationIDs associated with Google Update. |
| 54 for (base::FieldTrial::ActiveGroups::const_iterator it = | 53 for (base::FieldTrial::ActiveGroups::const_iterator it = |
| 55 active_groups.begin(); it != active_groups.end(); ++it) { | 54 active_groups.begin(); it != active_groups.end(); ++it) { |
| 56 const variations::VariationID id = | 55 const VariationID id = GetGoogleVariationID(GOOGLE_UPDATE_SERVICE, |
| 57 variations::GetGoogleVariationID(variations::GOOGLE_UPDATE_SERVICE, | 56 it->trial_name, it->group_name); |
| 58 it->trial_name, it->group_name); | |
| 59 | 57 |
| 60 if (id == variations::EMPTY_ID) | 58 if (id == EMPTY_ID) |
| 61 continue; | 59 continue; |
| 62 | 60 |
| 63 if (!experiment_labels.empty()) | 61 if (!experiment_labels.empty()) |
| 64 experiment_labels += google_update::kExperimentLabelSeparator; | 62 experiment_labels += google_update::kExperimentLabelSeparator; |
| 65 experiment_labels += CreateSingleExperimentLabel(++counter, id, | 63 experiment_labels += CreateSingleExperimentLabel(++counter, id, |
| 66 current_time); | 64 current_time); |
| 67 } | 65 } |
| 68 | 66 |
| 69 return experiment_labels; | 67 return experiment_labels; |
| 70 } | 68 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 101 DCHECK(!EndsWith(other_labels, separator, false)); | 99 DCHECK(!EndsWith(other_labels, separator, false)); |
| 102 // Note that if either label is empty, a separator is not necessary. | 100 // Note that if either label is empty, a separator is not necessary. |
| 103 base::string16 combined_labels = other_labels; | 101 base::string16 combined_labels = other_labels; |
| 104 if (!other_labels.empty() && !variation_labels.empty()) | 102 if (!other_labels.empty() && !variation_labels.empty()) |
| 105 combined_labels += google_update::kExperimentLabelSeparator; | 103 combined_labels += google_update::kExperimentLabelSeparator; |
| 106 combined_labels += variation_labels; | 104 combined_labels += variation_labels; |
| 107 return combined_labels; | 105 return combined_labels; |
| 108 } | 106 } |
| 109 | 107 |
| 110 } // namespace chrome_variations | 108 } // namespace chrome_variations |
| OLD | NEW |