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/string16.h" | 7 #include "base/string16.h" |
8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
9 #include "base/string_number_conversions.h" | 9 //#include "base/string_number_conversions.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
11 #include "base/win/registry.h" | 11 #include "base/win/registry.h" |
12 #include "chrome/installer/util/browser_distribution.h" | 12 //#include "chrome/installer/util/browser_distribution.h" |
13 #include "chrome/installer/util/google_update_constants.h" | 13 //#include "chrome/installer/util/google_update_constants.h" |
robertshield
2012/11/20 15:29:49
should delete the commented includes
SteveT
2012/11/20 15:45:01
Oops, sorry. Was playing around with which were st
| |
14 #include "chrome/installer/gcapi/gcapi.h" | 14 #include "chrome/installer/gcapi/gcapi.h" |
15 #include "chrome/installer/util/install_util.h" | |
15 | 16 |
16 using base::Time; | 17 using base::Time; |
17 using base::TimeDelta; | 18 using base::TimeDelta; |
18 using base::win::RegKey; | 19 using base::win::RegKey; |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
22 const wchar_t kExperimentLabels[] = L"experiment_labels"; | |
23 | |
24 const wchar_t* kExperimentAppGuids[] = { | |
25 L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}", | |
26 L"{8A69D345-D564-463C-AFF1-A69D9E530F96}", | |
27 }; | |
28 | |
29 const wchar_t* kDays[] = | 23 const wchar_t* kDays[] = |
30 { L"Sun", L"Mon", L"Tue", L"Wed", L"Thu", L"Fri", L"Sat" }; | 24 { L"Sun", L"Mon", L"Tue", L"Wed", L"Thu", L"Fri", L"Sat" }; |
31 | 25 |
32 const wchar_t* kMonths[] = {L"Jan", L"Feb", L"Mar", L"Apr", L"May", L"Jun", | 26 const wchar_t* kMonths[] = {L"Jan", L"Feb", L"Mar", L"Apr", L"May", L"Jun", |
33 L"Jul", L"Aug", L"Sep", L"Oct", L"Nov", L"Dec"}; | 27 L"Jul", L"Aug", L"Sep", L"Oct", L"Nov", L"Dec"}; |
34 | 28 |
35 // Constructs a date string of the following format for the current time plus | 29 // Constructs a date string of the following format for the current time plus |
36 // one year: | 30 // one year: |
37 // "DAY, DD0 MON YYYY HH0:MI0:SE0 TZ" | 31 // "DAY, DD0 MON YYYY HH0:MI0:SE0 TZ" |
38 // DAY = 3 character day of week, | 32 // DAY = 3 character day of week, |
(...skipping 28 matching lines...) Expand all Loading... | |
67 // Returns the number of weeks since 2/3/2003. | 61 // Returns the number of weeks since 2/3/2003. |
68 int GetCurrentRlzWeek() { | 62 int GetCurrentRlzWeek() { |
69 Time::Exploded february_third_2003_exploded = {2003, 2, 1, 3, 0, 0, 0, 0}; | 63 Time::Exploded february_third_2003_exploded = {2003, 2, 1, 3, 0, 0, 0, 0}; |
70 Time f = Time::FromUTCExploded(february_third_2003_exploded); | 64 Time f = Time::FromUTCExploded(february_third_2003_exploded); |
71 TimeDelta delta = Time::Now() - f; | 65 TimeDelta delta = Time::Now() - f; |
72 return delta.InDays() / 7; | 66 return delta.InDays() / 7; |
73 } | 67 } |
74 | 68 |
75 } // namespace | 69 } // namespace |
76 | 70 |
77 bool SetOmahaExperimentLabel(const wchar_t* brand_code, int shell_mode) { | 71 bool SetGCAPIOmahaExperimentLabel(const wchar_t* brand_code, int shell_mode) { |
78 if (!brand_code) { | 72 if (!brand_code) { |
79 return false; | 73 return false; |
80 } | 74 } |
81 | 75 |
82 // When this function is invoked in standard, non-elevated shell, we default | 76 // When this function is invoked in standard, non-elevated shell, we default |
83 // to writing the experiment label to HKCU. When it is invoked in a UAC- | 77 // to writing the experiment label to HKCU. When it is invoked in a UAC- |
84 // elevated shell, we write the experiment label to HKLM. | 78 // elevated shell, we write the experiment label to HKLM. |
85 HKEY registry_hive = | 79 HKEY registry_hive = |
86 shell_mode == GCAPI_INVOKED_UAC_ELEVATION ? HKEY_LOCAL_MACHINE : | 80 shell_mode == GCAPI_INVOKED_UAC_ELEVATION ? HKEY_LOCAL_MACHINE : |
87 HKEY_CURRENT_USER; | 81 HKEY_CURRENT_USER; |
88 | 82 |
89 int week_number = GetCurrentRlzWeek(); | 83 int week_number = GetCurrentRlzWeek(); |
90 if (week_number < 0 || week_number > 999) | 84 if (week_number < 0 || week_number > 999) |
91 week_number = 999; | 85 week_number = 999; |
92 | 86 |
93 string16 experiment_label; | 87 string16 experiment_label; |
94 base::SStringPrintf(&experiment_label, | 88 base::SStringPrintf(&experiment_label, |
95 L"reacbrand=%ls_%d|%ls", | 89 L"reacbrand=%ls_%d|%ls", |
96 brand_code, | 90 brand_code, |
97 week_number, | 91 week_number, |
98 BuildOmahaExperimentDateString().c_str()); | 92 BuildOmahaExperimentDateString().c_str()); |
99 | 93 |
100 int successful_writes = 0; | 94 return InstallUtil::SetOmahaExperimentLabel(experiment_label, registry_hive); |
101 for (int i = 0; i < arraysize(kExperimentAppGuids); ++i) { | |
102 string16 experiment_path(google_update::kRegPathClientState); | |
103 experiment_path += L"\\"; | |
104 experiment_path += kExperimentAppGuids[i]; | |
105 | |
106 RegKey client_state(registry_hive, experiment_path.c_str(), | |
107 KEY_SET_VALUE); | |
108 if (client_state.Valid()) { | |
109 if (client_state.WriteValue(kExperimentLabels, | |
110 experiment_label.c_str()) == ERROR_SUCCESS) { | |
111 successful_writes++; | |
112 } | |
113 } | |
114 } | |
115 | |
116 return (successful_writes == arraysize(kExperimentAppGuids)); | |
117 } | 95 } |
OLD | NEW |