Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(100)

Side by Side Diff: chrome/installer/util/experiment_storage.cc

Issue 2933043002: Installer support for Windows 10 inactive user toast. (Closed)
Patch Set: now with some tests Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/util/experiment_storage.h" 5 #include "chrome/installer/util/experiment_storage.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 8
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 18 matching lines...) Expand all
29 #include "chrome/installer/util/experiment_labels.h" 29 #include "chrome/installer/util/experiment_labels.h"
30 #include "chrome/installer/util/experiment_metrics.h" 30 #include "chrome/installer/util/experiment_metrics.h"
31 #include "chrome/installer/util/google_update_settings.h" 31 #include "chrome/installer/util/google_update_settings.h"
32 #include "chrome/installer/util/shell_util.h" 32 #include "chrome/installer/util/shell_util.h"
33 33
34 namespace installer { 34 namespace installer {
35 35
36 namespace { 36 namespace {
37 37
38 constexpr base::char16 kExperimentLabelName[] = L"CrExp60"; 38 constexpr base::char16 kExperimentLabelName[] = L"CrExp60";
39 constexpr wchar_t kRegKeyRetention[] = L"Retention"; 39 constexpr wchar_t kRegKeyRetention[] = L"\\Retention";
40 constexpr wchar_t kRegValueActionDelay[] = L"ActionDelay"; 40 constexpr wchar_t kRegValueActionDelay[] = L"ActionDelay";
41 constexpr wchar_t kRegValueFirstDisplayTime[] = L"FirstDisplayTime"; 41 constexpr wchar_t kRegValueFirstDisplayTime[] = L"FirstDisplayTime";
42 constexpr wchar_t kRegValueGroup[] = L"Group"; 42 constexpr wchar_t kRegValueGroup[] = L"Group";
43 constexpr wchar_t kRegValueInactiveDays[] = L"InactiveDays"; 43 constexpr wchar_t kRegValueInactiveDays[] = L"InactiveDays";
44 constexpr wchar_t kRegValueLatestDisplayTime[] = L"LatestDisplayTime"; 44 constexpr wchar_t kRegValueLatestDisplayTime[] = L"LatestDisplayTime";
45 constexpr wchar_t kRegValueRetentionStudy[] = L"RetentionStudy"; 45 constexpr wchar_t kRegValueRetentionStudy[] = L"RetentionStudy";
46 constexpr wchar_t kRegValueState[] = L"State"; 46 constexpr wchar_t kRegValueState[] = L"State";
47 constexpr wchar_t kRegValueToastCount[] = L"ToastCount"; 47 constexpr wchar_t kRegValueToastCount[] = L"ToastCount";
48 constexpr wchar_t kRegValueToastLocation[] = L"ToastLocation"; 48 constexpr wchar_t kRegValueToastLocation[] = L"ToastLocation";
49 constexpr wchar_t kRegValueUserSessionUptime[] = L"UserSessionUptime"; 49 constexpr wchar_t kRegValueUserSessionUptime[] = L"UserSessionUptime";
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 install_static::InstallDetails::Get(); 84 install_static::InstallDetails::Get();
85 85
86 if (!system_level) { 86 if (!system_level) {
87 *path = install_details.GetClientStateKeyPath().append(kRegKeyRetention); 87 *path = install_details.GetClientStateKeyPath().append(kRegKeyRetention);
88 return true; 88 return true;
89 } 89 }
90 90
91 base::string16 user_sid; 91 base::string16 user_sid;
92 if (base::win::GetUserSidString(&user_sid)) { 92 if (base::win::GetUserSidString(&user_sid)) {
93 *path = install_details.GetClientStateMediumKeyPath() 93 *path = install_details.GetClientStateMediumKeyPath()
94 .append(L"\\")
95 .append(kRegKeyRetention) 94 .append(kRegKeyRetention)
96 .append(L"\\") 95 .append(L"\\")
97 .append(user_sid); 96 .append(user_sid);
98 return true; 97 return true;
99 } 98 }
100 99
101 NOTREACHED(); 100 NOTREACHED();
102 return false; 101 return false;
103 } 102 }
104 103
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 150
152 } // namespace 151 } // namespace
153 152
154 // ExperimentStorage::Lock ----------------------------------------------------- 153 // ExperimentStorage::Lock -----------------------------------------------------
155 154
156 ExperimentStorage::Lock::~Lock() { 155 ExperimentStorage::Lock::~Lock() {
157 BOOL result = ::ReleaseMutex(storage_->mutex_.Get()); 156 BOOL result = ::ReleaseMutex(storage_->mutex_.Get());
158 DCHECK(result); 157 DCHECK(result);
159 } 158 }
160 159
161 bool ExperimentStorage::Lock::ReadParticipation(Participation* participation) { 160 bool ExperimentStorage::Lock::ReadParticipation(Study* participation) {
162 base::win::RegKey key; 161 base::win::RegKey key;
163 // A failure to open the key likely indicates that this isn't running from a 162 // A failure to open the key likely indicates that this isn't running from a
164 // real install of Chrome. 163 // real install of Chrome.
165 if (!OpenParticipationKey(false /* !write_access */, &key)) 164 if (!OpenParticipationKey(false /* !write_access */, &key))
166 return false; 165 return false;
167 166
168 DWORD value = 0; 167 DWORD value = 0;
169 LONG result = key.ReadValueDW(kRegValueRetentionStudy, &value); 168 LONG result = key.ReadValueDW(kRegValueRetentionStudy, &value);
170 if (result != ERROR_SUCCESS) { 169 // An error most likely means that the value is not present.
171 // This likely means that the value is not present. 170 if (result != ERROR_SUCCESS || value == 0)
172 *participation = Participation::kNotEvaluated; 171 *participation = kNoStudySelected;
173 } else if (value == 0) { 172 else if (value == 1)
174 *participation = Participation::kNotParticipating; 173 *participation = kStudyOne;
175 } else { 174 else
176 *participation = Participation::kIsParticipating; 175 *participation = kStudyTwo;
177 }
178 return true; 176 return true;
179 } 177 }
180 178
181 bool ExperimentStorage::Lock::WriteParticipation(Participation participation) { 179 bool ExperimentStorage::Lock::WriteParticipation(Study participation) {
180 DCHECK(participation == kNoStudySelected || participation == kStudyOne ||
181 participation == kStudyTwo);
182 base::win::RegKey key; 182 base::win::RegKey key;
183 // A failure to open the key likely indicates that this isn't running from a 183 // A failure to open the key likely indicates that this isn't running from a
184 // real install of Chrome. 184 // real install of Chrome.
185 if (!OpenParticipationKey(true /* write_access */, &key)) 185 if (!OpenParticipationKey(true /* write_access */, &key))
186 return false; 186 return false;
187 187
188 if (participation == Participation::kNotEvaluated) 188 if (participation == kNoStudySelected)
189 return key.DeleteValue(kRegValueRetentionStudy) == ERROR_SUCCESS; 189 return key.DeleteValue(kRegValueRetentionStudy) == ERROR_SUCCESS;
190 const DWORD value = participation == Participation::kIsParticipating ? 1 : 0; 190 return key.WriteValue(kRegValueRetentionStudy, participation) ==
191 return key.WriteValue(kRegValueRetentionStudy, value) == ERROR_SUCCESS; 191 ERROR_SUCCESS;
192 } 192 }
193 193
194 bool ExperimentStorage::Lock::LoadExperiment(Experiment* experiment) { 194 bool ExperimentStorage::Lock::LoadExperiment(Experiment* experiment) {
195 // This function loads both the experiment metrics and state from the 195 // This function loads both the experiment metrics and state from the
196 // registry. 196 // registry.
197 // - If no metrics are found: |experiment| is cleared, and true is returned. 197 // - If no metrics are found: |experiment| is cleared, and true is returned.
198 // (Per-user experiment data in the registry is ignored for all users.) 198 // (Per-user experiment data in the registry is ignored for all users.)
199 // - If metrics indicate an initial state (prior to a user being elected into 199 // - If metrics indicate an initial state (prior to a user being elected into
200 // an experiment group): |experiment| is populated with the metrics and true 200 // an experiment group): |experiment| is populated with the metrics and true
201 // is returned. (Per-user experiment data in the registry is ignored for all 201 // is returned. (Per-user experiment data in the registry is ignored for all
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 WriteTime(&key, kRegValueLatestDisplayTime, 467 WriteTime(&key, kRegValueLatestDisplayTime,
468 experiment.latest_display_time_.ToInternalValue()); 468 experiment.latest_display_time_.ToInternalValue());
469 WriteTime(&key, kRegValueUserSessionUptime, 469 WriteTime(&key, kRegValueUserSessionUptime,
470 experiment.user_session_uptime_.ToInternalValue()); 470 experiment.user_session_uptime_.ToInternalValue());
471 WriteTime(&key, kRegValueActionDelay, 471 WriteTime(&key, kRegValueActionDelay,
472 experiment.action_delay_.ToInternalValue()); 472 experiment.action_delay_.ToInternalValue());
473 return true; 473 return true;
474 } 474 }
475 475
476 } // namespace installer 476 } // namespace installer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698