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

Side by Side Diff: components/component_updater/updater_state_win.cc

Issue 2286483002: Serialize Google Update state as part of the recovery component update checks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 3 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
« no previous file with comments | « components/component_updater/updater_state_win.h ('k') | components/components_tests.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1
2 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5
6 #include "components/component_updater/updater_state_win.h"
7
8 #include <utility>
9
10 #include "base/memory/ptr_util.h"
11 #include "base/strings/string16.h"
12 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/utf_string_conversions.h"
14
15 #include "base/win/registry.h"
16 #include "base/win/win_util.h"
17
18 namespace component_updater {
19
20 namespace {
21
22 // Google Update group policy settings.
23 const wchar_t kGoogleUpdatePoliciesKey[] =
24 L"SOFTWARE\\Policies\\Google\\Update";
25 const wchar_t kCheckPeriodOverrideMinutes[] = L"AutoUpdateCheckPeriodMinutes";
26 const wchar_t kUpdatePolicyValue[] = L"UpdateDefault";
27 const wchar_t kChromeUpdatePolicyOverride[] =
28 L"Update{8A69D345-D564-463C-AFF1-A69D9E530F96}";
29
30 // Don't allow update periods longer than six weeks (Chrome release cadence).
31 const int kCheckPeriodOverrideMinutesMax = 60 * 24 * 7 * 6;
32
33 // Google Update registry settings.
34 const wchar_t kRegPathGoogleUpdate[] = L"Software\\Google\\Update";
35 const wchar_t kRegPathClients[] = L"Software\\Google\\Update\\Clients";
36 const wchar_t kRegPathClientsGoogleUpdate[] =
37 L"Software\\Google\\Update\\Clients\\"
38 L"{430FD4D0-B729-4F61-AA34-91526481799D}";
39 const wchar_t kRegValueGoogleUpdatePv[] = L"pv";
40 const wchar_t kRegValueLastStartedAU[] = L"LastStartedAU";
41 const wchar_t kRegValueLastChecked[] = L"LastChecked";
42
43 } // namespace
44
45 UpdaterState::UpdaterState(bool is_machine) : is_machine_(is_machine) {}
46
47 std::unique_ptr<UpdaterState> UpdaterState::Create(bool is_machine) {
48 std::unique_ptr<UpdaterState> updater_state(new UpdaterState(is_machine));
49 updater_state->ReadState();
50 return std::move(updater_state);
51 }
52
53 void UpdaterState::ReadState() {
54 google_update_version_ = GetGoogleUpdateVersion(is_machine_);
55 last_autoupdate_started_ = GetGoogleUpdateLastStartedAU(is_machine_);
56 last_checked_ = GetGoogleUpdateLastChecked(is_machine_);
57 is_joined_to_domain_ = IsJoinedToDomain();
58 is_autoupdate_check_enabled_ = IsAutoupdateCheckEnabled();
59 chrome_update_policy_ = GetChromeUpdatePolicy();
60 }
61
62 update_client::InstallerAttributes UpdaterState::MakeInstallerAttributes()
63 const {
64 update_client::InstallerAttributes installer_attributes;
65
66 if (google_update_version_.IsValid())
67 installer_attributes["googleupdatever"] =
68 google_update_version_.GetString();
69
70 const base::Time now = base::Time::NowFromSystemTime();
71 if (!last_autoupdate_started_.is_null())
72 installer_attributes["laststarted"] =
73 NormalizeTimeDelta(now - last_autoupdate_started_);
74 if (!last_checked_.is_null())
75 installer_attributes["lastchecked"] =
76 NormalizeTimeDelta(now - last_checked_);
77
78 installer_attributes["domainjoined"] = is_joined_to_domain_ ? "1" : "0";
79 installer_attributes["autoupdatecheckenabled"] =
80 is_autoupdate_check_enabled_ ? "1" : "0";
81
82 DCHECK(chrome_update_policy_ >= 0 && chrome_update_policy_ <= 3 ||
83 chrome_update_policy_ == -1);
84 installer_attributes["chromeupdatepolicy"] =
85 base::IntToString(chrome_update_policy_);
86
87 return installer_attributes;
88 }
89
90 std::string UpdaterState::NormalizeTimeDelta(const base::TimeDelta& delta) {
91 const base::TimeDelta two_weeks = base::TimeDelta::FromDays(14);
92 const base::TimeDelta two_months = base::TimeDelta::FromDays(60);
93
94 std::string val; // Contains the value to return in hours.
95 if (delta <= two_weeks) {
96 val = "0";
97 } else if (two_weeks < delta && delta <= two_months) {
98 val = "408"; // 2 weeks in hours.
99 } else {
100 val = "1440"; // 2 months in hours.
waffles 2016/08/25 23:17:55 Maybe stick with 28-day long "months"? (1344)
Sorin Jianu 2016/08/25 23:20:47 Done.
101 }
102
103 DCHECK(!val.empty());
104 return val;
105 }
106
107 base::Version UpdaterState::GetGoogleUpdateVersion(bool is_machine) {
108 const HKEY root_key = is_machine ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
109 base::string16 version;
110 base::win::RegKey key;
111
112 if (key.Open(root_key, kRegPathClientsGoogleUpdate,
113 KEY_QUERY_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS &&
114 key.ReadValue(kRegValueGoogleUpdatePv, &version) == ERROR_SUCCESS) {
115 return base::Version(base::UTF16ToUTF8(version));
116 }
117
118 return base::Version();
119 }
120
121 base::Time UpdaterState::GetGoogleUpdateLastStartedAU(bool is_machine) {
122 return GetGoogleUpdateTimeValue(is_machine, kRegValueLastStartedAU);
123 }
124
125 base::Time UpdaterState::GetGoogleUpdateLastChecked(bool is_machine) {
126 return GetGoogleUpdateTimeValue(is_machine, kRegValueLastChecked);
127 }
128
129 base::Time UpdaterState::GetGoogleUpdateTimeValue(bool is_machine,
130 const wchar_t* value_name) {
131 const HKEY root_key = is_machine ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
132 base::win::RegKey update_key;
133
134 if (update_key.Open(root_key, kRegPathGoogleUpdate,
135 KEY_QUERY_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS) {
136 DWORD value(0);
137 if (update_key.ReadValueDW(value_name, &value) == ERROR_SUCCESS) {
138 return base::Time::FromTimeT(value);
139 }
140 }
141
142 return base::Time();
143 }
144
145 bool UpdaterState::IsAutoupdateCheckEnabled() {
146 // Check the auto-update check period override. If it is 0 or exceeds the
147 // maximum timeout, then for all intents and purposes auto updates are
148 // disabled.
149 base::win::RegKey policy_key;
150 DWORD value = 0;
151 if (policy_key.Open(HKEY_LOCAL_MACHINE, kGoogleUpdatePoliciesKey,
152 KEY_QUERY_VALUE) == ERROR_SUCCESS &&
153 policy_key.ReadValueDW(kCheckPeriodOverrideMinutes, &value) ==
154 ERROR_SUCCESS &&
155 (value == 0 || value > kCheckPeriodOverrideMinutesMax)) {
waffles 2016/08/25 23:17:55 Is it possible for value < 0? If so, what happens
Sorin Jianu 2016/08/25 23:20:47 it is an unsigned type.
156 return false;
157 }
158
159 return true;
160 }
161
162 // Returns -1 if the policy is not found or the value was invalid. Otherwise,
163 // returns a value in the [0, 3] range, representing the value of the
164 // Chrome update group policy.
165 int UpdaterState::GetChromeUpdatePolicy() {
166 const int kMaxUpdatePolicyValue = 3;
167
168 base::win::RegKey policy_key;
169
170 if (policy_key.Open(HKEY_LOCAL_MACHINE, kGoogleUpdatePoliciesKey,
171 KEY_QUERY_VALUE) != ERROR_SUCCESS) {
172 return -1;
173 }
174
175 DWORD value = 0;
176 // First try to read the Chrome-specific override.
177 if (policy_key.ReadValueDW(kChromeUpdatePolicyOverride, &value) ==
178 ERROR_SUCCESS &&
179 value <= kMaxUpdatePolicyValue) {
180 return value;
181 }
182
183 // Try to read default override.
184 if (policy_key.ReadValueDW(kUpdatePolicyValue, &value) == ERROR_SUCCESS &&
185 value <= kMaxUpdatePolicyValue) {
186 return value;
187 }
188
189 return -1;
190 }
191
192 bool UpdaterState::IsJoinedToDomain() {
193 return base::win::IsEnrolledToDomain();
194 }
195
196 } // namespace component_updater
OLDNEW
« no previous file with comments | « components/component_updater/updater_state_win.h ('k') | components/components_tests.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698