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

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

Issue 2933043002: Installer support for Windows 10 inactive user toast. (Closed)
Patch Set: review feedback 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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 150
151 } // namespace 151 } // namespace
152 152
153 // ExperimentStorage::Lock ----------------------------------------------------- 153 // ExperimentStorage::Lock -----------------------------------------------------
154 154
155 ExperimentStorage::Lock::~Lock() { 155 ExperimentStorage::Lock::~Lock() {
156 BOOL result = ::ReleaseMutex(storage_->mutex_.Get()); 156 BOOL result = ::ReleaseMutex(storage_->mutex_.Get());
157 DCHECK(result); 157 DCHECK(result);
158 } 158 }
159 159
160 bool ExperimentStorage::Lock::ReadParticipation(Participation* participation) { 160 bool ExperimentStorage::Lock::ReadParticipation(Study* participation) {
161 base::win::RegKey key; 161 base::win::RegKey key;
162 // 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
163 // real install of Chrome. 163 // real install of Chrome.
164 if (!OpenParticipationKey(false /* !write_access */, &key)) 164 if (!OpenParticipationKey(false /* !write_access */, &key))
165 return false; 165 return false;
166 166
167 DWORD value = 0; 167 DWORD value = 0;
168 LONG result = key.ReadValueDW(kRegValueRetentionStudy, &value); 168 LONG result = key.ReadValueDW(kRegValueRetentionStudy, &value);
169 if (result != ERROR_SUCCESS) { 169 // An error most likely means that the value is not present.
170 // This likely means that the value is not present. 170 if (result != ERROR_SUCCESS || value == 0)
171 *participation = Participation::kNotEvaluated; 171 *participation = kNoStudySelected;
172 } else if (value == 0) { 172 else if (value == 1)
173 *participation = Participation::kNotParticipating; 173 *participation = kStudyOne;
174 } else { 174 else
175 *participation = Participation::kIsParticipating; 175 *participation = kStudyTwo;
176 }
177 return true; 176 return true;
178 } 177 }
179 178
180 bool ExperimentStorage::Lock::WriteParticipation(Participation participation) { 179 bool ExperimentStorage::Lock::WriteParticipation(Study participation) {
180 DCHECK(participation == kNoStudySelected || participation == kStudyOne ||
181 participation == kStudyTwo);
181 base::win::RegKey key; 182 base::win::RegKey key;
182 // 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
183 // real install of Chrome. 184 // real install of Chrome.
184 if (!OpenParticipationKey(true /* write_access */, &key)) 185 if (!OpenParticipationKey(true /* write_access */, &key))
185 return false; 186 return false;
186 187
187 if (participation == Participation::kNotEvaluated) 188 if (participation == kNoStudySelected)
188 return key.DeleteValue(kRegValueRetentionStudy) == ERROR_SUCCESS; 189 return key.DeleteValue(kRegValueRetentionStudy) == ERROR_SUCCESS;
189 const DWORD value = participation == Participation::kIsParticipating ? 1 : 0; 190 return key.WriteValue(kRegValueRetentionStudy, participation) ==
190 return key.WriteValue(kRegValueRetentionStudy, value) == ERROR_SUCCESS; 191 ERROR_SUCCESS;
191 } 192 }
192 193
193 bool ExperimentStorage::Lock::LoadExperiment(Experiment* experiment) { 194 bool ExperimentStorage::Lock::LoadExperiment(Experiment* experiment) {
194 // This function loads both the experiment metrics and state from the 195 // This function loads both the experiment metrics and state from the
195 // registry. 196 // registry.
196 // - 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.
197 // (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.)
198 // - 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
199 // an experiment group): |experiment| is populated with the metrics and true 200 // an experiment group): |experiment| is populated with the metrics and true
200 // 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 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 WriteTime(&key, kRegValueLatestDisplayTime, 471 WriteTime(&key, kRegValueLatestDisplayTime,
471 experiment.latest_display_time().ToInternalValue()); 472 experiment.latest_display_time().ToInternalValue());
472 WriteTime(&key, kRegValueUserSessionUptime, 473 WriteTime(&key, kRegValueUserSessionUptime,
473 experiment.user_session_uptime().ToInternalValue()); 474 experiment.user_session_uptime().ToInternalValue());
474 WriteTime(&key, kRegValueActionDelay, 475 WriteTime(&key, kRegValueActionDelay,
475 experiment.action_delay().ToInternalValue()); 476 experiment.action_delay().ToInternalValue());
476 return true; 477 return true;
477 } 478 }
478 479
479 } // namespace installer 480 } // namespace installer
OLDNEW
« no previous file with comments | « chrome/installer/util/experiment_storage.h ('k') | chrome/installer/util/experiment_storage_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698