| 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" |
| 14 #include "chrome/installer/gcapi/gcapi.h" |
| 14 | 15 |
| 15 using base::Time; | 16 using base::Time; |
| 16 using base::TimeDelta; | 17 using base::TimeDelta; |
| 17 using base::win::RegKey; | 18 using base::win::RegKey; |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 const wchar_t kExperimentLabels[] = L"experiment_labels"; | 22 const wchar_t kExperimentLabels[] = L"experiment_labels"; |
| 22 | 23 |
| 23 const wchar_t* kExperimentAppGuids[] = { | 24 const wchar_t* kExperimentAppGuids[] = { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 // Returns the number of weeks since 2/3/2003. | 67 // Returns the number of weeks since 2/3/2003. |
| 67 int GetCurrentRlzWeek() { | 68 int GetCurrentRlzWeek() { |
| 68 Time::Exploded february_third_2003_exploded = {2003, 2, 1, 3, 0, 0, 0, 0}; | 69 Time::Exploded february_third_2003_exploded = {2003, 2, 1, 3, 0, 0, 0, 0}; |
| 69 Time f = Time::FromUTCExploded(february_third_2003_exploded); | 70 Time f = Time::FromUTCExploded(february_third_2003_exploded); |
| 70 TimeDelta delta = Time::Now() - f; | 71 TimeDelta delta = Time::Now() - f; |
| 71 return delta.InDays() / 7; | 72 return delta.InDays() / 7; |
| 72 } | 73 } |
| 73 | 74 |
| 74 } // namespace | 75 } // namespace |
| 75 | 76 |
| 76 bool SetOmahaExperimentLabel(const wchar_t* brand_code) { | 77 bool SetOmahaExperimentLabel(const wchar_t* brand_code, int shell_mode) { |
| 77 if (!brand_code) { | 78 if (!brand_code) { |
| 78 return false; | 79 return false; |
| 79 } | 80 } |
| 80 | 81 |
| 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 |
| 81 int week_number = GetCurrentRlzWeek(); | 89 int week_number = GetCurrentRlzWeek(); |
| 82 if (week_number < 0 || week_number > 999) | 90 if (week_number < 0 || week_number > 999) |
| 83 week_number = 999; | 91 week_number = 999; |
| 84 | 92 |
| 85 string16 experiment_label; | 93 string16 experiment_label; |
| 86 base::SStringPrintf(&experiment_label, | 94 base::SStringPrintf(&experiment_label, |
| 87 L"%ls_%d|%ls", | 95 L"reacbrand=%ls_%d|%ls", |
| 88 brand_code, | 96 brand_code, |
| 89 week_number, | 97 week_number, |
| 90 BuildOmahaExperimentDateString().c_str()); | 98 BuildOmahaExperimentDateString().c_str()); |
| 91 | 99 |
| 92 int successful_writes = 0; | 100 int successful_writes = 0; |
| 93 for (int i = 0; i < arraysize(kExperimentAppGuids); ++i) { | 101 for (int i = 0; i < arraysize(kExperimentAppGuids); ++i) { |
| 94 string16 experiment_path(google_update::kRegPathClientState); | 102 string16 experiment_path(google_update::kRegPathClientState); |
| 95 experiment_path += L"\\"; | 103 experiment_path += L"\\"; |
| 96 experiment_path += kExperimentAppGuids[i]; | 104 experiment_path += kExperimentAppGuids[i]; |
| 97 | 105 |
| 98 RegKey client_state(HKEY_LOCAL_MACHINE, experiment_path.c_str(), | 106 RegKey client_state(registry_hive, experiment_path.c_str(), |
| 99 KEY_SET_VALUE); | 107 KEY_SET_VALUE); |
| 100 if (client_state.Valid()) { | 108 if (client_state.Valid()) { |
| 101 if (client_state.WriteValue(kExperimentLabels, | 109 if (client_state.WriteValue(kExperimentLabels, |
| 102 experiment_label.c_str()) == ERROR_SUCCESS) { | 110 experiment_label.c_str()) == ERROR_SUCCESS) { |
| 103 successful_writes++; | 111 successful_writes++; |
| 104 } | 112 } |
| 105 } | 113 } |
| 106 } | 114 } |
| 107 | 115 |
| 108 return (successful_writes == arraysize(kExperimentAppGuids)); | 116 return (successful_writes == arraysize(kExperimentAppGuids)); |
| 109 } | 117 } |
| OLD | NEW |