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/strings/string16.h" | 7 #include "base/strings/string16.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 #include "chrome/installer/gcapi/gcapi.h" | 10 #include "chrome/installer/gcapi/gcapi.h" |
| 11 #include "chrome/installer/util/google_update_constants.h" |
11 #include "chrome/installer/util/google_update_experiment_util.h" | 12 #include "chrome/installer/util/google_update_experiment_util.h" |
12 #include "chrome/installer/util/google_update_settings.h" | 13 #include "chrome/installer/util/google_update_settings.h" |
13 | 14 |
14 using base::Time; | 15 using base::Time; |
15 using base::TimeDelta; | 16 using base::TimeDelta; |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
19 // Returns the number of weeks since 2/3/2003. | 20 // Returns the number of weeks since 2/3/2003. |
20 int GetCurrentRlzWeek() { | 21 int GetCurrentRlzWeek() { |
21 Time::Exploded february_third_2003_exploded = {2003, 2, 1, 3, 0, 0, 0, 0}; | 22 Time::Exploded february_third_2003_exploded = {2003, 2, 1, 3, 0, 0, 0, 0}; |
22 Time f = Time::FromUTCExploded(february_third_2003_exploded); | 23 Time f = Time::FromUTCExploded(february_third_2003_exploded); |
23 TimeDelta delta = Time::Now() - f; | 24 TimeDelta delta = Time::Now() - f; |
24 return delta.InDays() / 7; | 25 return delta.InDays() / 7; |
25 } | 26 } |
26 | 27 |
27 bool SetLabel(const wchar_t* brand_code, const wchar_t* label, int shell_mode) { | 28 bool SetExperimentLabel(const wchar_t* brand_code, |
| 29 const string16& label, |
| 30 int shell_mode) { |
28 if (!brand_code) { | 31 if (!brand_code) { |
29 return false; | 32 return false; |
30 } | 33 } |
31 | 34 |
| 35 const bool system_level = shell_mode == GCAPI_INVOKED_UAC_ELEVATION; |
| 36 |
| 37 string16 experiment_labels; |
| 38 if (!GoogleUpdateSettings::ReadExperimentLabels(system_level, |
| 39 &experiment_labels)) { |
| 40 return false; |
| 41 } |
| 42 |
| 43 // First erase this label from the existing experiment labels if it exists. |
| 44 size_t existing_label_begin = experiment_labels.find(label + L"="); |
| 45 if (existing_label_begin != string16::npos) { |
| 46 size_t existing_label_end = |
| 47 experiment_labels.find(google_update::kExperimentLabelSep, |
| 48 existing_label_begin); |
| 49 // Note: if |existing_label_end == string16::npos| this will work anyways |
| 50 // as npos is defined as the biggest possible unsigned integer and erase |
| 51 // will thus, by definition, erase to the end of the string. |
| 52 experiment_labels.erase(existing_label_begin, |
| 53 existing_label_end - existing_label_begin); |
| 54 } |
| 55 |
32 int week_number = GetCurrentRlzWeek(); | 56 int week_number = GetCurrentRlzWeek(); |
33 if (week_number < 0 || week_number > 999) | 57 if (week_number < 0 || week_number > 999) |
34 week_number = 999; | 58 week_number = 999; |
35 | 59 |
36 string16 experiment_labels; | 60 string16 gcapi_experiment_label; |
37 base::SStringPrintf(&experiment_labels, | 61 base::SStringPrintf(&gcapi_experiment_label, |
38 L"%ls=%ls_%d|%ls", | 62 L"%ls=%ls_%d|%ls", |
39 label, | 63 label.c_str(), |
40 brand_code, | 64 brand_code, |
41 week_number, | 65 week_number, |
42 installer::BuildExperimentDateString().c_str()); | 66 installer::BuildExperimentDateString().c_str()); |
43 | 67 |
44 return GoogleUpdateSettings::SetExperimentLabels( | 68 experiment_labels.append(google_update::kExperimentLabelSep); |
45 shell_mode == GCAPI_INVOKED_UAC_ELEVATION, | 69 experiment_labels.append(gcapi_experiment_label); |
46 experiment_labels); | 70 |
| 71 return GoogleUpdateSettings::SetExperimentLabels(system_level, |
| 72 experiment_labels); |
47 } | 73 } |
48 | 74 |
49 } // namespace | 75 } // namespace |
50 | 76 |
51 bool SetReactivationExperimentLabels(const wchar_t* brand_code, | 77 bool SetReactivationExperimentLabels(const wchar_t* brand_code, |
52 int shell_mode) { | 78 int shell_mode) { |
53 return SetLabel(brand_code, L"reacbrand", shell_mode); | 79 return SetExperimentLabel(brand_code, L"reacbrand", shell_mode); |
54 } | 80 } |
55 | 81 |
56 bool SetRelaunchExperimentLabels(const wchar_t* brand_code, int shell_mode) { | 82 bool SetRelaunchExperimentLabels(const wchar_t* brand_code, int shell_mode) { |
57 return SetLabel(brand_code, L"relaunchbrand", shell_mode); | 83 return SetExperimentLabel(brand_code, L"relaunchbrand", shell_mode); |
58 } | 84 } |
OLD | NEW |