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

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

Issue 2933043002: Installer support for Windows 10 inactive user toast. (Closed)
Patch Set: two studies 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 #ifndef CHROME_INSTALLER_UTIL_EXPERIMENT_STORAGE_H_ 5 #ifndef CHROME_INSTALLER_UTIL_EXPERIMENT_STORAGE_H_
6 #define CHROME_INSTALLER_UTIL_EXPERIMENT_STORAGE_H_ 6 #define CHROME_INSTALLER_UTIL_EXPERIMENT_STORAGE_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/strings/string16.h" 11 #include "base/strings/string16.h"
12 #include "base/win/scoped_handle.h" 12 #include "base/win/scoped_handle.h"
13 13
14 namespace installer { 14 namespace installer {
15 15
16 class Experiment; 16 class Experiment;
17 struct ExperimentMetrics; 17 struct ExperimentMetrics;
18 18
19 // Manages the storage of experiment state on the machine. 19 // Manages the storage of experiment state on the machine.
20 // 20 //
21 // Participation is a per-install property evaluated one time to determine 21 // Participation is a per-install property evaluated one time to determine which
22 // whether or not the install as a whole participates in the study. It is 22 // study the client participates in. It is stored in the install's ClientState
23 // stored in the install's ClientState key. 23 // key.
24 // 24 //
25 // ExperimentMetrics are stored in a per-install experiment_label, while the 25 // ExperimentMetrics are stored in a per-install experiment_label, while the
26 // fine-grained Experiment data are stored in a per-user key in Chrome's 26 // fine-grained Experiment data are stored in a per-user key in Chrome's
27 // ClientState or ClientStateMedium key. For system-level installs, metrics are 27 // ClientState or ClientStateMedium key. For system-level installs, metrics are
28 // reported for only a single user on the machine, so only that one user will 28 // reported for only a single user on the machine, so only that one user will
29 // participate in the experiment. 29 // participate in the experiment.
30 // 30 //
31 // Owing to this "metrics are per-install" property in the face of potentially 31 // Owing to this "metrics are per-install" property in the face of potentially
32 // multiple users running the same install, ExperimentMetrics are considered the 32 // multiple users running the same install, ExperimentMetrics are considered the
33 // source of truth for an install's participation in the experiment. For any 33 // source of truth for an install's participation in the experiment. For any
34 // given state expressed in the experiment_label holding these metrics, there 34 // given state expressed in the experiment_label holding these metrics, there
35 // should be matching Experiment data for precisely one user. 35 // should be matching Experiment data for precisely one user.
36 // 36 //
37 // As state is written across multiple locations in the registry, a global 37 // As state is written across multiple locations in the registry, a global
38 // mutex is used for all reads and writes to ensure consistent state. 38 // mutex is used for all reads and writes to ensure consistent state.
39 class ExperimentStorage { 39 class ExperimentStorage {
40 public: 40 public:
41 enum class Participation { 41 // An identifier of which study the install participates in.
42 // No participation state was found for the install. 42 using Study = uint32_t;
43 kNotEvaluated,
44 43
45 // The client is not participating in the study. 44 // The possible Study values.
46 kNotParticipating, 45 static constexpr Study kNoStudySelected = 0;
47 46 static constexpr Study kStudyOne = 1;
48 // The client is participating in the study. 47 static constexpr Study kStudyTwo = 2;
49 kIsParticipating,
50 };
51 48
52 // Grants the holder exclusive access to the data in the registry. Consumers 49 // Grants the holder exclusive access to the data in the registry. Consumers
53 // are expected to not hold an instance across any blocking operations. 50 // are expected to not hold an instance across any blocking operations.
54 class Lock { 51 class Lock {
55 public: 52 public:
56 ~Lock(); 53 ~Lock();
57 54
58 // Reads the participation state for the install. Returns false in case of 55 // Reads the participation state for the install. Returns false in case of
59 // error. 56 // error. |participation| is set to kNotEvaluated if no value is present;
60 bool ReadParticipation(Participation* participation); 57 // otherwise, it is set to the value found.
58 bool ReadParticipation(Study* participation);
61 59
62 // Writes the participation state for the install. Returns false if the 60 // Writes the participation state for the install. Returns false if the
63 // write failed. 61 // write failed.
64 bool WriteParticipation(Participation participation); 62 bool WriteParticipation(Study participation);
65 63
66 // Loads the experiment metrics and data from the registry. Returns false if 64 // Loads the experiment metrics and data from the registry. Returns false if
67 // the state in the registry corresponds to a different user or could not be 65 // the state in the registry corresponds to a different user or could not be
68 // read. 66 // read.
69 bool LoadExperiment(Experiment* experiment); 67 bool LoadExperiment(Experiment* experiment);
70 68
71 // Stores the experiment metrics and data in |experiment| into the registry. 69 // Stores the experiment metrics and data in |experiment| into the registry.
72 bool StoreExperiment(const Experiment& experiment); 70 bool StoreExperiment(const Experiment& experiment);
73 71
74 // Loads per-install experiment metrics into |metrics|. Returns true if a 72 // Loads per-install experiment metrics into |metrics|. Returns true if a
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 135
138 // A global mutex with a distinct name for the current installation. 136 // A global mutex with a distinct name for the current installation.
139 base::win::ScopedHandle mutex_; 137 base::win::ScopedHandle mutex_;
140 138
141 DISALLOW_COPY_AND_ASSIGN(ExperimentStorage); 139 DISALLOW_COPY_AND_ASSIGN(ExperimentStorage);
142 }; 140 };
143 141
144 } // namespace installer 142 } // namespace installer
145 143
146 #endif // CHROME_INSTALLER_UTIL_EXPERIMENT_STORAGE_H_ 144 #endif // CHROME_INSTALLER_UTIL_EXPERIMENT_STORAGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698