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

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: remove unused 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 kRegPathClientsGoogleUpdate[] =
36 L"Software\\Google\\Update\\Clients\\"
37 L"{430FD4D0-B729-4F61-AA34-91526481799D}";
38 const wchar_t kRegValueGoogleUpdatePv[] = L"pv";
39 const wchar_t kRegValueLastStartedAU[] = L"LastStartedAU";
40 const wchar_t kRegValueLastChecked[] = L"LastChecked";
41
42 } // namespace
43
44 UpdaterState::UpdaterState(bool is_machine) : is_machine_(is_machine) {}
45
46 std::unique_ptr<UpdaterState> UpdaterState::Create(bool is_machine) {
47 std::unique_ptr<UpdaterState> updater_state(new UpdaterState(is_machine));
48 updater_state->ReadState();
49 return updater_state;
50 }
51
52 void UpdaterState::ReadState() {
53 google_update_version_ = GetGoogleUpdateVersion(is_machine_);
54 last_autoupdate_started_ = GetGoogleUpdateLastStartedAU(is_machine_);
55 last_checked_ = GetGoogleUpdateLastChecked(is_machine_);
56 is_joined_to_domain_ = IsJoinedToDomain();
57 is_autoupdate_check_enabled_ = IsAutoupdateCheckEnabled();
58 chrome_update_policy_ = GetChromeUpdatePolicy();
59 }
60
61 update_client::InstallerAttributes UpdaterState::MakeInstallerAttributes()
62 const {
63 update_client::InstallerAttributes installer_attributes;
64
65 if (google_update_version_.IsValid())
66 installer_attributes["googleupdatever"] =
67 google_update_version_.GetString();
68
69 const base::Time now = base::Time::NowFromSystemTime();
70 if (!last_autoupdate_started_.is_null())
71 installer_attributes["laststarted"] =
72 NormalizeTimeDelta(now - last_autoupdate_started_);
73 if (!last_checked_.is_null())
74 installer_attributes["lastchecked"] =
75 NormalizeTimeDelta(now - last_checked_);
76
77 installer_attributes["domainjoined"] = is_joined_to_domain_ ? "1" : "0";
78 installer_attributes["autoupdatecheckenabled"] =
79 is_autoupdate_check_enabled_ ? "1" : "0";
80
81 DCHECK(chrome_update_policy_ >= 0 && chrome_update_policy_ <= 3 ||
82 chrome_update_policy_ == -1);
83 installer_attributes["chromeupdatepolicy"] =
84 base::IntToString(chrome_update_policy_);
85
86 return installer_attributes;
87 }
88
89 std::string UpdaterState::NormalizeTimeDelta(const base::TimeDelta& delta) {
90 const base::TimeDelta two_weeks = base::TimeDelta::FromDays(14);
91 const base::TimeDelta two_months = base::TimeDelta::FromDays(60);
92
93 std::string val; // Contains the value to return in hours.
94 if (delta <= two_weeks) {
95 val = "0";
96 } else if (two_weeks < delta && delta <= two_months) {
97 val = "408"; // 2 weeks in hours.
98 } else {
99 val = "1344"; // 2*28 days in hours.
100 }
101
102 DCHECK(!val.empty());
103 return val;
104 }
105
106 base::Version UpdaterState::GetGoogleUpdateVersion(bool is_machine) {
107 const HKEY root_key = is_machine ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
108 base::string16 version;
109 base::win::RegKey key;
110
111 if (key.Open(root_key, kRegPathClientsGoogleUpdate,
112 KEY_QUERY_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS &&
113 key.ReadValue(kRegValueGoogleUpdatePv, &version) == ERROR_SUCCESS) {
114 return base::Version(base::UTF16ToUTF8(version));
115 }
116
117 return base::Version();
118 }
119
120 base::Time UpdaterState::GetGoogleUpdateLastStartedAU(bool is_machine) {
121 return GetGoogleUpdateTimeValue(is_machine, kRegValueLastStartedAU);
122 }
123
124 base::Time UpdaterState::GetGoogleUpdateLastChecked(bool is_machine) {
125 return GetGoogleUpdateTimeValue(is_machine, kRegValueLastChecked);
126 }
127
128 base::Time UpdaterState::GetGoogleUpdateTimeValue(bool is_machine,
129 const wchar_t* value_name) {
130 const HKEY root_key = is_machine ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
131 base::win::RegKey update_key;
132
133 if (update_key.Open(root_key, kRegPathGoogleUpdate,
134 KEY_QUERY_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS) {
135 DWORD value(0);
136 if (update_key.ReadValueDW(value_name, &value) == ERROR_SUCCESS) {
137 return base::Time::FromTimeT(value);
138 }
139 }
140
141 return base::Time();
142 }
143
144 bool UpdaterState::IsAutoupdateCheckEnabled() {
145 // Check the auto-update check period override. If it is 0 or exceeds the
146 // maximum timeout, then for all intents and purposes auto updates are
147 // disabled.
148 base::win::RegKey policy_key;
149 DWORD value = 0;
150 if (policy_key.Open(HKEY_LOCAL_MACHINE, kGoogleUpdatePoliciesKey,
151 KEY_QUERY_VALUE) == ERROR_SUCCESS &&
152 policy_key.ReadValueDW(kCheckPeriodOverrideMinutes, &value) ==
153 ERROR_SUCCESS &&
154 (value == 0 || value > kCheckPeriodOverrideMinutesMax)) {
155 return false;
156 }
157
158 return true;
159 }
160
161 // Returns -1 if the policy is not found or the value was invalid. Otherwise,
162 // returns a value in the [0, 3] range, representing the value of the
163 // Chrome update group policy.
164 int UpdaterState::GetChromeUpdatePolicy() {
165 const int kMaxUpdatePolicyValue = 3;
166
167 base::win::RegKey policy_key;
168
169 if (policy_key.Open(HKEY_LOCAL_MACHINE, kGoogleUpdatePoliciesKey,
170 KEY_QUERY_VALUE) != ERROR_SUCCESS) {
171 return -1;
172 }
173
174 DWORD value = 0;
175 // First try to read the Chrome-specific override.
176 if (policy_key.ReadValueDW(kChromeUpdatePolicyOverride, &value) ==
177 ERROR_SUCCESS &&
178 value <= kMaxUpdatePolicyValue) {
179 return value;
180 }
181
182 // Try to read default override.
183 if (policy_key.ReadValueDW(kUpdatePolicyValue, &value) == ERROR_SUCCESS &&
184 value <= kMaxUpdatePolicyValue) {
185 return value;
186 }
187
188 return -1;
189 }
190
191 bool UpdaterState::IsJoinedToDomain() {
192 return base::win::IsEnrolledToDomain();
193 }
194
195 } // 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