OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/installer/gcapi/gcapi_omaha_experiment.h" | 5 #include "chrome/installer/gcapi/gcapi_omaha_experiment.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/strings/string_split.h" | 8 #include "base/strings/string_split.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
13 #include "chrome/installer/gcapi/gcapi.h" | 13 #include "chrome/installer/gcapi/gcapi.h" |
14 #include "chrome/installer/util/google_update_constants.h" | 14 #include "chrome/installer/util/google_update_constants.h" |
15 #include "chrome/installer/util/google_update_experiment_util.h" | |
16 #include "chrome/installer/util/google_update_settings.h" | 15 #include "chrome/installer/util/google_update_settings.h" |
| 16 #include "components/variations/variations_experiment_util.h" |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 // Returns the number of weeks since 2/3/2003. | 20 // Returns the number of weeks since 2/3/2003. |
21 int GetCurrentRlzWeek(const base::Time& current_time) { | 21 int GetCurrentRlzWeek(const base::Time& current_time) { |
22 base::Time::Exploded february_third_2003_exploded = | 22 base::Time::Exploded february_third_2003_exploded = |
23 {2003, 2, 1, 3, 0, 0, 0, 0}; | 23 {2003, 2, 1, 3, 0, 0, 0, 0}; |
24 base::Time f = base::Time::FromUTCExploded(february_third_2003_exploded); | 24 base::Time f = base::Time::FromUTCExploded(february_third_2003_exploded); |
25 base::TimeDelta delta = current_time - f; | 25 base::TimeDelta delta = current_time - f; |
26 return delta.InDays() / 7; | 26 return delta.InDays() / 7; |
(...skipping 10 matching lines...) Expand all Loading... |
37 | 37 |
38 base::string16 original_labels; | 38 base::string16 original_labels; |
39 if (!GoogleUpdateSettings::ReadExperimentLabels(system_level, | 39 if (!GoogleUpdateSettings::ReadExperimentLabels(system_level, |
40 &original_labels)) { | 40 &original_labels)) { |
41 return false; | 41 return false; |
42 } | 42 } |
43 | 43 |
44 // Split the original labels by the label separator. | 44 // Split the original labels by the label separator. |
45 std::vector<base::string16> entries = base::SplitString( | 45 std::vector<base::string16> entries = base::SplitString( |
46 original_labels, | 46 original_labels, |
47 base::string16(1, google_update::kExperimentLabelSeparator), | 47 base::string16(1, variations::kExperimentLabelSeparator), |
48 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 48 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
49 | 49 |
50 // Keep all labels, but the one we want to add/replace. | 50 // Keep all labels, but the one we want to add/replace. |
51 base::string16 label_and_separator(label); | 51 base::string16 label_and_separator(label); |
52 label_and_separator.push_back('='); | 52 label_and_separator.push_back('='); |
53 base::string16 new_labels; | 53 base::string16 new_labels; |
54 for (const base::string16& entry : entries) { | 54 for (const base::string16& entry : entries) { |
55 if (!entry.empty() && | 55 if (!entry.empty() && |
56 !base::StartsWith(entry, label_and_separator, | 56 !base::StartsWith(entry, label_and_separator, |
57 base::CompareCase::SENSITIVE)) { | 57 base::CompareCase::SENSITIVE)) { |
58 new_labels += entry; | 58 new_labels += entry; |
59 new_labels += google_update::kExperimentLabelSeparator; | 59 new_labels += variations::kExperimentLabelSeparator; |
60 } | 60 } |
61 } | 61 } |
62 | 62 |
63 new_labels.append( | 63 new_labels.append( |
64 gcapi_internals::GetGCAPIExperimentLabel(brand_code, label)); | 64 gcapi_internals::GetGCAPIExperimentLabel(brand_code, label)); |
65 | 65 |
66 return GoogleUpdateSettings::SetExperimentLabels(system_level, | 66 return GoogleUpdateSettings::SetExperimentLabels(system_level, |
67 new_labels); | 67 new_labels); |
68 } | 68 } |
69 | 69 |
(...skipping 14 matching lines...) Expand all Loading... |
84 instance_time_value = base::Time::Now().ToTimeT(); | 84 instance_time_value = base::Time::Now().ToTimeT(); |
85 | 85 |
86 base::Time instance_time = base::Time::FromTimeT(instance_time_value); | 86 base::Time instance_time = base::Time::FromTimeT(instance_time_value); |
87 | 87 |
88 base::string16 gcapi_experiment_label; | 88 base::string16 gcapi_experiment_label; |
89 base::SStringPrintf(&gcapi_experiment_label, | 89 base::SStringPrintf(&gcapi_experiment_label, |
90 L"%ls=%ls_%d|%ls", | 90 L"%ls=%ls_%d|%ls", |
91 label.c_str(), | 91 label.c_str(), |
92 brand_code, | 92 brand_code, |
93 GetCurrentRlzWeek(instance_time), | 93 GetCurrentRlzWeek(instance_time), |
94 installer::BuildExperimentDateString( | 94 variations::BuildExperimentDateString( |
95 instance_time).c_str()); | 95 instance_time).c_str()); |
96 return gcapi_experiment_label; | 96 return gcapi_experiment_label; |
97 } | 97 } |
98 | 98 |
99 } // namespace gcapi_internals | 99 } // namespace gcapi_internals |
100 | 100 |
101 bool SetReactivationExperimentLabels(const wchar_t* brand_code, | 101 bool SetReactivationExperimentLabels(const wchar_t* brand_code, |
102 int shell_mode) { | 102 int shell_mode) { |
103 return SetExperimentLabel(brand_code, gcapi_internals::kReactivationLabel, | 103 return SetExperimentLabel(brand_code, gcapi_internals::kReactivationLabel, |
104 shell_mode); | 104 shell_mode); |
105 } | 105 } |
106 | 106 |
107 bool SetRelaunchExperimentLabels(const wchar_t* brand_code, int shell_mode) { | 107 bool SetRelaunchExperimentLabels(const wchar_t* brand_code, int shell_mode) { |
108 return SetExperimentLabel(brand_code, gcapi_internals::kRelaunchLabel, | 108 return SetExperimentLabel(brand_code, gcapi_internals::kRelaunchLabel, |
109 shell_mode); | 109 shell_mode); |
110 } | 110 } |
OLD | NEW |