| 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" | |
| 10 #include "base/time.h" | 9 #include "base/time.h" |
| 11 #include "base/win/registry.h" | 10 #include "base/win/registry.h" |
| 12 #include "chrome/installer/util/browser_distribution.h" | |
| 13 #include "chrome/installer/util/google_update_constants.h" | |
| 14 #include "chrome/installer/gcapi/gcapi.h" | 11 #include "chrome/installer/gcapi/gcapi.h" |
| 12 #include "chrome/installer/util/install_util.h" |
| 15 | 13 |
| 16 using base::Time; | 14 using base::Time; |
| 17 using base::TimeDelta; | 15 using base::TimeDelta; |
| 18 using base::win::RegKey; | 16 using base::win::RegKey; |
| 19 | 17 |
| 20 namespace { | 18 namespace { |
| 21 | 19 |
| 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[] = | 20 const wchar_t* kDays[] = |
| 30 { L"Sun", L"Mon", L"Tue", L"Wed", L"Thu", L"Fri", L"Sat" }; | 21 { L"Sun", L"Mon", L"Tue", L"Wed", L"Thu", L"Fri", L"Sat" }; |
| 31 | 22 |
| 32 const wchar_t* kMonths[] = {L"Jan", L"Feb", L"Mar", L"Apr", L"May", L"Jun", | 23 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"}; | 24 L"Jul", L"Aug", L"Sep", L"Oct", L"Nov", L"Dec"}; |
| 34 | 25 |
| 35 // Constructs a date string of the following format for the current time plus | 26 // Constructs a date string of the following format for the current time plus |
| 36 // one year: | 27 // one year: |
| 37 // "DAY, DD0 MON YYYY HH0:MI0:SE0 TZ" | 28 // "DAY, DD0 MON YYYY HH0:MI0:SE0 TZ" |
| 38 // DAY = 3 character day of week, | 29 // DAY = 3 character day of week, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 67 // Returns the number of weeks since 2/3/2003. | 58 // Returns the number of weeks since 2/3/2003. |
| 68 int GetCurrentRlzWeek() { | 59 int GetCurrentRlzWeek() { |
| 69 Time::Exploded february_third_2003_exploded = {2003, 2, 1, 3, 0, 0, 0, 0}; | 60 Time::Exploded february_third_2003_exploded = {2003, 2, 1, 3, 0, 0, 0, 0}; |
| 70 Time f = Time::FromUTCExploded(february_third_2003_exploded); | 61 Time f = Time::FromUTCExploded(february_third_2003_exploded); |
| 71 TimeDelta delta = Time::Now() - f; | 62 TimeDelta delta = Time::Now() - f; |
| 72 return delta.InDays() / 7; | 63 return delta.InDays() / 7; |
| 73 } | 64 } |
| 74 | 65 |
| 75 } // namespace | 66 } // namespace |
| 76 | 67 |
| 77 bool SetOmahaExperimentLabel(const wchar_t* brand_code, int shell_mode) { | 68 bool SetGCAPIOmahaExperimentLabel(const wchar_t* brand_code, int shell_mode) { |
| 78 if (!brand_code) { | 69 if (!brand_code) { |
| 79 return false; | 70 return false; |
| 80 } | 71 } |
| 81 | 72 |
| 82 // 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- | |
| 84 // elevated shell, we write the experiment label to HKLM. | |
| 85 HKEY registry_hive = | |
| 86 shell_mode == GCAPI_INVOKED_UAC_ELEVATION ? HKEY_LOCAL_MACHINE : | |
| 87 HKEY_CURRENT_USER; | |
| 88 | |
| 89 int week_number = GetCurrentRlzWeek(); | 73 int week_number = GetCurrentRlzWeek(); |
| 90 if (week_number < 0 || week_number > 999) | 74 if (week_number < 0 || week_number > 999) |
| 91 week_number = 999; | 75 week_number = 999; |
| 92 | 76 |
| 93 string16 experiment_label; | 77 string16 experiment_label; |
| 94 base::SStringPrintf(&experiment_label, | 78 base::SStringPrintf(&experiment_label, |
| 95 L"reacbrand=%ls_%d|%ls", | 79 L"reacbrand=%ls_%d|%ls", |
| 96 brand_code, | 80 brand_code, |
| 97 week_number, | 81 week_number, |
| 98 BuildOmahaExperimentDateString().c_str()); | 82 BuildOmahaExperimentDateString().c_str()); |
| 99 | 83 |
| 100 int successful_writes = 0; | 84 return InstallUtil::SetOmahaExperimentLabel(experiment_label, |
| 101 for (int i = 0; i < arraysize(kExperimentAppGuids); ++i) { | 85 shell_mode == GCAPI_INVOKED_UAC_ELEVATION); |
| 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 } | 86 } |
| OLD | NEW |