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

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

Issue 2619323003: Remove uses of BrowserDistribution::CHROME_BINARIES in installer_util. (Closed)
Patch Set: Created 3 years, 11 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/google_update_settings.h" 5 #include "chrome/installer/util/google_update_settings.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <limits> 10 #include <limits>
11 #include <vector> 11 #include <vector>
huangs 2017/01/09 21:27:08 <vector> now unused?
grt (UTC plus 2) 2017/01/10 08:43:56 You bet. <limits>, too.
12 12
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/metrics/histogram.h" 16 #include "base/metrics/histogram.h"
17 #include "base/numerics/safe_conversions.h" 17 #include "base/numerics/safe_conversions.h"
18 #include "base/path_service.h" 18 #include "base/path_service.h"
19 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
20 #include "base/strings/string_util.h" 20 #include "base/strings/string_util.h"
21 #include "base/strings/utf_string_conversions.h" 21 #include "base/strings/utf_string_conversions.h"
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 149 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
150 base::string16 reg_path = dist->GetStateKey(); 150 base::string16 reg_path = dist->GetStateKey();
151 RegKey key(HKEY_CURRENT_USER, 151 RegKey key(HKEY_CURRENT_USER,
152 reg_path.c_str(), 152 reg_path.c_str(),
153 KEY_READ | KEY_WRITE | KEY_WOW64_32KEY); 153 KEY_READ | KEY_WRITE | KEY_WOW64_32KEY);
154 if (!key.HasValue(name)) 154 if (!key.HasValue(name))
155 return true; 155 return true;
156 return (key.DeleteValue(name) == ERROR_SUCCESS); 156 return (key.DeleteValue(name) == ERROR_SUCCESS);
157 } 157 }
158 158
159 // Initializes |channel_info| based on |system_install| and |dist|. Also 159 // Initializes |channel_info| based on |system_install|. Returns false on
160 // returns whether the install is a multi-install via output parameter 160 // failure.
161 // |is_multi_install|. Returns false on failure.
162 bool InitChannelInfo(bool system_install, 161 bool InitChannelInfo(bool system_install,
163 installer::ChannelInfo* channel_info, 162 installer::ChannelInfo* channel_info) {
164 bool* is_multi_install) { 163 HKEY root_key = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
165 // Determine whether or not chrome is multi-install. If so, updates are 164 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
166 // delivered under the binaries' app guid, so that's where the relevant 165 RegKey key(root_key, dist->GetStateKey().c_str(),
167 // channel is found. 166 KEY_QUERY_VALUE | KEY_WOW64_32KEY);
168 installer::ProductState state; 167 return channel_info->Initialize(key);
169 ignore_result(state.Initialize(system_install));
170 if (!state.is_multi_install()) {
171 // Use the channel info that was just read for this single-install chrome.
172 *channel_info = state.channel();
173 } else {
174 // Read the channel info from the binaries' state key.
175 HKEY root_key = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
176 BrowserDistribution* dist = BrowserDistribution::GetSpecificDistribution(
177 BrowserDistribution::CHROME_BINARIES);
178 RegKey key(root_key, dist->GetStateKey().c_str(),
179 KEY_READ | KEY_WOW64_32KEY);
180
181 if (!channel_info->Initialize(key))
182 return false;
183 }
184 *is_multi_install = state.is_multi_install();
185 return true;
186 } 168 }
187 169
188 bool GetChromeChannelInternal(bool system_install, 170 bool GetChromeChannelInternal(bool system_install,
189 bool add_multi_modifier,
190 base::string16* channel) { 171 base::string16* channel) {
191 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
192
193 // Shortcut in case this distribution knows what channel it is (canary). 172 // Shortcut in case this distribution knows what channel it is (canary).
194 if (dist->GetChromeChannel(channel)) 173 if (BrowserDistribution::GetDistribution()->GetChromeChannel(channel))
195 return true; 174 return true;
196 175
197 installer::ChannelInfo channel_info; 176 installer::ChannelInfo channel_info;
198 bool is_multi_install = false; 177 if (!InitChannelInfo(system_install, &channel_info)) {
199 if (!InitChannelInfo(system_install, &channel_info, &is_multi_install)) {
200 channel->assign(installer::kChromeChannelUnknown); 178 channel->assign(installer::kChromeChannelUnknown);
201 return false; 179 return false;
202 } 180 }
203 181
204 if (!channel_info.GetChannelName(channel)) 182 if (!channel_info.GetChannelName(channel))
205 channel->assign(installer::kChromeChannelUnknown); 183 channel->assign(installer::kChromeChannelUnknown);
206 184
207 // Tag the channel name if this is a multi-install.
208 if (add_multi_modifier && is_multi_install) {
209 if (!channel->empty())
210 channel->push_back(L'-');
211 channel->push_back(L'm');
212 }
213
214 return true; 185 return true;
215 } 186 }
216 187
217 #if defined(GOOGLE_CHROME_BUILD) 188 #if defined(GOOGLE_CHROME_BUILD)
218 // Populates |update_policy| with the UpdatePolicy enum value corresponding to a 189 // Populates |update_policy| with the UpdatePolicy enum value corresponding to a
219 // DWORD read from the registry and returns true if |value| is within range. 190 // DWORD read from the registry and returns true if |value| is within range.
220 // If |value| is out of range, returns false without modifying |update_policy|. 191 // If |value| is out of range, returns false without modifying |update_policy|.
221 bool GetUpdatePolicyFromDword( 192 bool GetUpdatePolicyFromDword(
222 const DWORD value, 193 const DWORD value,
223 GoogleUpdateSettings::UpdatePolicy* update_policy) { 194 GoogleUpdateSettings::UpdatePolicy* update_policy) {
224 switch (value) { 195 switch (value) {
225 case GoogleUpdateSettings::UPDATES_DISABLED: 196 case GoogleUpdateSettings::UPDATES_DISABLED:
226 case GoogleUpdateSettings::AUTOMATIC_UPDATES: 197 case GoogleUpdateSettings::AUTOMATIC_UPDATES:
227 case GoogleUpdateSettings::MANUAL_UPDATES_ONLY: 198 case GoogleUpdateSettings::MANUAL_UPDATES_ONLY:
228 case GoogleUpdateSettings::AUTO_UPDATES_ONLY: 199 case GoogleUpdateSettings::AUTO_UPDATES_ONLY:
229 *update_policy = static_cast<GoogleUpdateSettings::UpdatePolicy>(value); 200 *update_policy = static_cast<GoogleUpdateSettings::UpdatePolicy>(value);
230 return true; 201 return true;
231 default: 202 default:
232 LOG(WARNING) << "Unexpected update policy override value: " << value; 203 LOG(WARNING) << "Unexpected update policy override value: " << value;
233 } 204 }
234 return false; 205 return false;
235 } 206 }
236 #endif // defined(GOOGLE_CHROME_BUILD) 207 #endif // defined(GOOGLE_CHROME_BUILD)
237 208
238 bool UpdateDidRunStateForApp(const AppRegistrationData& app_reg_data,
239 bool did_run) {
240 return WriteGoogleUpdateStrKeyInternal(
241 app_reg_data, google_update::kRegDidRunField, did_run ? L"1" : L"0");
242 }
243
244 // Convenience routine: GoogleUpdateSettings::UpdateDidRunStateForApp()
245 // specialized for Chrome Binaries.
246 bool UpdateDidRunStateForBinaries(bool did_run) {
247 BrowserDistribution* dist = BrowserDistribution::GetSpecificDistribution(
248 BrowserDistribution::CHROME_BINARIES);
249 return UpdateDidRunStateForApp(dist->GetAppRegistrationData(), did_run);
250 }
251
252 } // namespace 209 } // namespace
253 210
254 bool GoogleUpdateSettings::IsSystemInstall() { 211 bool GoogleUpdateSettings::IsSystemInstall() {
255 bool system_install = false; 212 bool system_install = false;
256 base::FilePath module_dir; 213 base::FilePath module_dir;
257 if (!PathService::Get(base::DIR_MODULE, &module_dir)) { 214 if (!PathService::Get(base::DIR_MODULE, &module_dir)) {
258 LOG(WARNING) 215 LOG(WARNING)
259 << "Failed to get directory of module; assuming per-user install."; 216 << "Failed to get directory of module; assuming per-user install.";
260 } else { 217 } else {
261 system_install = !InstallUtil::IsPerUserInstall(module_dir); 218 system_install = !InstallUtil::IsPerUserInstall(module_dir);
262 } 219 }
263 return system_install; 220 return system_install;
264 } 221 }
265 222
266 bool GoogleUpdateSettings::GetCollectStatsConsent() { 223 bool GoogleUpdateSettings::GetCollectStatsConsent() {
267 return GetCollectStatsConsentAtLevel(IsSystemInstall()); 224 return GetCollectStatsConsentAtLevel(IsSystemInstall());
268 } 225 }
269 226
270 bool GoogleUpdateSettings::SetCollectStatsConsent(bool consented) { 227 bool GoogleUpdateSettings::SetCollectStatsConsent(bool consented) {
271 return SetCollectStatsConsentAtLevel(IsSystemInstall(), consented); 228 return SetCollectStatsConsentAtLevel(IsSystemInstall(), consented);
272 } 229 }
273 230
274 bool GoogleUpdateSettings::GetCollectStatsConsentAtLevel(bool system_install) { 231 bool GoogleUpdateSettings::GetCollectStatsConsentAtLevel(bool system_install) {
275 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
276
277 // Consent applies to all products in a multi-install package.
278 if (InstallUtil::IsMultiInstall(system_install)) {
279 dist = BrowserDistribution::GetSpecificDistribution(
280 BrowserDistribution::CHROME_BINARIES);
281 }
282
283 return GetCollectStatsConsentForApp(system_install, 232 return GetCollectStatsConsentForApp(system_install,
284 dist->GetAppRegistrationData()) == 233 BrowserDistribution::GetDistribution()
234 ->GetAppRegistrationData()) ==
285 google_update::TRISTATE_TRUE; 235 google_update::TRISTATE_TRUE;
286 } 236 }
287 237
288 google_update::Tristate GoogleUpdateSettings::GetCollectStatsConsentForApp( 238 google_update::Tristate GoogleUpdateSettings::GetCollectStatsConsentForApp(
289 bool system_install, 239 bool system_install,
290 const AppRegistrationData& reg_data) { 240 const AppRegistrationData& reg_data) {
291 RegKey key; 241 RegKey key;
292 DWORD value = google_update::TRISTATE_NONE; 242 DWORD value = google_update::TRISTATE_NONE;
293 bool have_value = false; 243 bool have_value = false;
294 const REGSAM kAccess = KEY_QUERY_VALUE | KEY_WOW64_32KEY; 244 const REGSAM kAccess = KEY_QUERY_VALUE | KEY_WOW64_32KEY;
(...skipping 20 matching lines...) Expand all
315 265
316 return value == google_update::TRISTATE_TRUE ? google_update::TRISTATE_TRUE 266 return value == google_update::TRISTATE_TRUE ? google_update::TRISTATE_TRUE
317 : google_update::TRISTATE_FALSE; 267 : google_update::TRISTATE_FALSE;
318 } 268 }
319 269
320 // static 270 // static
321 bool GoogleUpdateSettings::SetCollectStatsConsentAtLevel(bool system_install, 271 bool GoogleUpdateSettings::SetCollectStatsConsentAtLevel(bool system_install,
322 bool consented) { 272 bool consented) {
323 DWORD value = 273 DWORD value =
324 consented ? google_update::TRISTATE_TRUE : google_update::TRISTATE_FALSE; 274 consented ? google_update::TRISTATE_TRUE : google_update::TRISTATE_FALSE;
325
326 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 275 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
327 276
328 // Consent applies to all products in a multi-install package.
329 if (InstallUtil::IsMultiInstall(system_install)) {
330 dist = BrowserDistribution::GetSpecificDistribution(
331 BrowserDistribution::CHROME_BINARIES);
332 }
333
334 // Write to ClientStateMedium for system-level; ClientState otherwise. 277 // Write to ClientStateMedium for system-level; ClientState otherwise.
335 HKEY root_key = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; 278 HKEY root_key = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
336 base::string16 reg_path = 279 base::string16 reg_path =
337 system_install ? dist->GetStateMediumKey() : dist->GetStateKey(); 280 system_install ? dist->GetStateMediumKey() : dist->GetStateKey();
338 RegKey key; 281 RegKey key;
339 LONG result = key.Create( 282 LONG result = key.Create(
340 root_key, reg_path.c_str(), KEY_SET_VALUE | KEY_WOW64_32KEY); 283 root_key, reg_path.c_str(), KEY_SET_VALUE | KEY_WOW64_32KEY);
341 if (result != ERROR_SUCCESS) { 284 if (result != ERROR_SUCCESS) {
342 LOG(ERROR) << "Failed opening key " << reg_path << " to set " 285 LOG(ERROR) << "Failed opening key " << reg_path << " to set "
343 << google_update::kRegUsageStatsField << "; result: " << result; 286 << google_update::kRegUsageStatsField << "; result: " << result;
344 } else { 287 } else {
345 result = key.WriteValue(google_update::kRegUsageStatsField, value); 288 result = key.WriteValue(google_update::kRegUsageStatsField, value);
346 LOG_IF(ERROR, result != ERROR_SUCCESS) << "Failed setting " 289 LOG_IF(ERROR, result != ERROR_SUCCESS) << "Failed setting "
347 << google_update::kRegUsageStatsField << " in key " << reg_path 290 << google_update::kRegUsageStatsField << " in key " << reg_path
348 << "; result: " << result; 291 << "; result: " << result;
349 } 292 }
350 293
351 // When opting out, clear registry backup of client id and related values. 294 // When opting out, clear registry backup of client id and related values.
352 if (result == ERROR_SUCCESS && !consented) 295 if (result == ERROR_SUCCESS && !consented)
353 StoreMetricsClientInfo(metrics::ClientInfo()); 296 StoreMetricsClientInfo(metrics::ClientInfo());
354 297
355 return (result == ERROR_SUCCESS); 298 return (result == ERROR_SUCCESS);
356 } 299 }
357 300
358 // static 301 // static
359 bool GoogleUpdateSettings::GetCollectStatsConsentDefault( 302 bool GoogleUpdateSettings::GetCollectStatsConsentDefault(
360 bool* stats_consent_default) { 303 bool* stats_consent_default) {
361 installer::ChannelInfo channel_info; 304 installer::ChannelInfo channel_info;
362 bool is_multi_install = false; 305 if (InitChannelInfo(IsSystemInstall(), &channel_info)) {
363 if (InitChannelInfo(IsSystemInstall(), &channel_info, &is_multi_install)) {
364 base::string16 stats_default = channel_info.GetStatsDefault(); 306 base::string16 stats_default = channel_info.GetStatsDefault();
365 if (stats_default == L"0" || stats_default == L"1") { 307 if (stats_default == L"0" || stats_default == L"1") {
366 *stats_consent_default = (stats_default == L"1"); 308 *stats_consent_default = (stats_default == L"1");
367 return true; 309 return true;
368 } 310 }
369 } 311 }
370 return false; 312 return false;
371 } 313 }
372 314
373 std::unique_ptr<metrics::ClientInfo> 315 std::unique_ptr<metrics::ClientInfo>
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 } 417 }
476 418
477 bool GoogleUpdateSettings::GetReferral(base::string16* referral) { 419 bool GoogleUpdateSettings::GetReferral(base::string16* referral) {
478 return ReadGoogleUpdateStrKey(google_update::kRegReferralField, referral); 420 return ReadGoogleUpdateStrKey(google_update::kRegReferralField, referral);
479 } 421 }
480 422
481 bool GoogleUpdateSettings::ClearReferral() { 423 bool GoogleUpdateSettings::ClearReferral() {
482 return ClearGoogleUpdateStrKey(google_update::kRegReferralField); 424 return ClearGoogleUpdateStrKey(google_update::kRegReferralField);
483 } 425 }
484 426
485 bool GoogleUpdateSettings::UpdateDidRunState(bool did_run, bool system_level) { 427 bool GoogleUpdateSettings::UpdateDidRunState(bool did_run, bool system_level) {
Sébastien Marchand 2017/01/09 21:19:39 Oops, you forgot to remove the |bool system_level|
grt (UTC plus 2) 2017/01/10 08:43:56 Doh!
486 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 428 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
487 bool result = UpdateDidRunStateForApp(dist->GetAppRegistrationData(), 429 return WriteGoogleUpdateStrKeyInternal(dist->GetAppRegistrationData(),
488 did_run); 430 google_update::kRegDidRunField,
489 // Update state for binaries, even if the previous call was unsuccessful. 431 did_run ? L"1" : L"0");
490 if (InstallUtil::IsMultiInstall(system_level))
491 result = UpdateDidRunStateForBinaries(did_run) && result;
492 return result;
493 } 432 }
494 433
495 base::string16 GoogleUpdateSettings::GetChromeChannel(bool system_install) { 434 base::string16 GoogleUpdateSettings::GetChromeChannel(bool system_install) {
496 base::string16 channel; 435 base::string16 channel;
497 GetChromeChannelInternal(system_install, false, &channel); 436 GetChromeChannelInternal(system_install, &channel);
498 return channel; 437 return channel;
499 } 438 }
500 439
501 bool GoogleUpdateSettings::GetChromeChannelAndModifiers(
502 bool system_install,
503 base::string16* channel) {
504 return GetChromeChannelInternal(system_install, true, channel);
505 }
506
507 void GoogleUpdateSettings::UpdateInstallStatus(bool system_install, 440 void GoogleUpdateSettings::UpdateInstallStatus(bool system_install,
508 installer::ArchiveType archive_type, int install_return_code, 441 installer::ArchiveType archive_type, int install_return_code,
509 const base::string16& product_guid) { 442 const base::string16& product_guid) {
510 DCHECK(archive_type != installer::UNKNOWN_ARCHIVE_TYPE || 443 DCHECK(archive_type != installer::UNKNOWN_ARCHIVE_TYPE ||
511 install_return_code != 0); 444 install_return_code != 0);
512 HKEY reg_root = (system_install) ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; 445 HKEY reg_root = (system_install) ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
513 446
514 RegKey key; 447 RegKey key;
515 installer::ChannelInfo channel_info; 448 installer::ChannelInfo channel_info;
516 base::string16 reg_key(google_update::kRegPathClientState); 449 base::string16 reg_key(google_update::kRegPathClientState);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 } else { 516 } else {
584 VLOG(1) << "Incremental installer failure; already on channel: " 517 VLOG(1) << "Incremental installer failure; already on channel: "
585 << value->value(); 518 << value->value();
586 } 519 }
587 } else { 520 } else {
588 // It's okay if we don't know the archive type. In this case, leave the 521 // It's okay if we don't know the archive type. In this case, leave the
589 // "-full" suffix as we found it. 522 // "-full" suffix as we found it.
590 DCHECK_EQ(installer::UNKNOWN_ARCHIVE_TYPE, archive_type); 523 DCHECK_EQ(installer::UNKNOWN_ARCHIVE_TYPE, archive_type);
591 } 524 }
592 525
593 if (value->SetMultiFailSuffix(false)) { 526 if (value->SetMultiFailSuffix(false)) {
huangs 2017/01/09 21:27:08 Should this be addressed? If we should leave this,
grt (UTC plus 2) 2017/01/10 08:43:56 Done.
594 VLOG(1) << "Removed multi-install failure key; switching to channel: " 527 VLOG(1) << "Removed multi-install failure key; switching to channel: "
595 << value->value(); 528 << value->value();
596 modified = true; 529 modified = true;
597 } 530 }
598 531
599 if (value->ClearStage()) { 532 if (value->ClearStage()) {
600 VLOG(1) << "Removed (legacy) stage information; switching to channel: " 533 VLOG(1) << "Removed (legacy) stage information; switching to channel: "
601 << value->value(); 534 << value->value();
602 modified = true; 535 modified = true;
603 } 536 }
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 RegKey policy_key; 625 RegKey policy_key;
693 DWORD value = 0; 626 DWORD value = 0;
694 if (policy_key.Open(HKEY_LOCAL_MACHINE, kPoliciesKey, 627 if (policy_key.Open(HKEY_LOCAL_MACHINE, kPoliciesKey,
695 KEY_QUERY_VALUE) == ERROR_SUCCESS && 628 KEY_QUERY_VALUE) == ERROR_SUCCESS &&
696 policy_key.ReadValueDW(kCheckPeriodOverrideMinutes, 629 policy_key.ReadValueDW(kCheckPeriodOverrideMinutes,
697 &value) == ERROR_SUCCESS && 630 &value) == ERROR_SUCCESS &&
698 (value == 0 || value > kCheckPeriodOverrideMinutesMax)) { 631 (value == 0 || value > kCheckPeriodOverrideMinutesMax)) {
699 return false; 632 return false;
700 } 633 }
701 634
702 // Auto updates are subtly broken when Chrome and the binaries have different
703 // overrides in place. If this Chrome cannot possibly be multi-install by
704 // virtue of being a side-by-side installation, simply check Chrome's policy.
705 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 635 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
706 UpdatePolicy app_policy = GetAppUpdatePolicy(dist->GetAppGuid(), nullptr); 636 UpdatePolicy app_policy = GetAppUpdatePolicy(dist->GetAppGuid(), nullptr);
707 if (InstallUtil::IsChromeSxSProcess()) 637 return app_policy == AUTOMATIC_UPDATES || app_policy == AUTO_UPDATES_ONLY;
708 return app_policy == AUTOMATIC_UPDATES || app_policy == AUTO_UPDATES_ONLY;
709
710 // Otherwise, check for consistency between Chrome and the binaries regardless
711 // of whether or not this Chrome is multi-install since the next update likely
712 // will attempt to migrate it to such.
713 BrowserDistribution* binaries = BrowserDistribution::GetSpecificDistribution(
714 BrowserDistribution::CHROME_BINARIES);
715 return (GetAppUpdatePolicy(binaries->GetAppGuid(), nullptr) == app_policy &&
716 (app_policy == AUTOMATIC_UPDATES || app_policy == AUTO_UPDATES_ONLY));
717 #else // defined(GOOGLE_CHROME_BUILD) 638 #else // defined(GOOGLE_CHROME_BUILD)
718 // Chromium does not auto update. 639 // Chromium does not auto update.
719 return false; 640 return false;
720 #endif // !defined(GOOGLE_CHROME_BUILD) 641 #endif // !defined(GOOGLE_CHROME_BUILD)
721 } 642 }
722 643
723 // static 644 // static
724 bool GoogleUpdateSettings::ReenableAutoupdates() { 645 bool GoogleUpdateSettings::ReenableAutoupdates() {
725 #if defined(GOOGLE_CHROME_BUILD) 646 #if defined(GOOGLE_CHROME_BUILD)
726 int needs_reset_count = 0; 647 int needs_reset_count = 0;
727 int did_reset_count = 0; 648 int did_reset_count = 0;
728 649
729 // Reset overrides for Chrome and for the binaries if this Chrome supports
730 // multi-install.
731 std::vector<base::string16> app_guids;
732 app_guids.push_back(BrowserDistribution::GetDistribution()->GetAppGuid());
733 if (!InstallUtil::IsChromeSxSProcess()) {
734 app_guids.push_back(BrowserDistribution::GetSpecificDistribution(
735 BrowserDistribution::CHROME_BINARIES)->GetAppGuid());
736 }
737
738 UpdatePolicy update_policy = kDefaultUpdatePolicy; 650 UpdatePolicy update_policy = kDefaultUpdatePolicy;
739 RegKey policy_key; 651 RegKey policy_key;
740 if (policy_key.Open(HKEY_LOCAL_MACHINE, kPoliciesKey, 652 if (policy_key.Open(HKEY_LOCAL_MACHINE, kPoliciesKey,
741 KEY_SET_VALUE | KEY_QUERY_VALUE) == ERROR_SUCCESS) { 653 KEY_SET_VALUE | KEY_QUERY_VALUE) == ERROR_SUCCESS) {
742 // Set to true while app-specific overrides are present that allow automatic 654 // Set to true while app-specific overrides are present that allow automatic
743 // updates. When this is the case, the defaults are irrelevant and don't 655 // updates. When this is the case, the defaults are irrelevant and don't
744 // need to be checked or reset. 656 // need to be checked or reset.
745 bool automatic_updates_allowed_by_overrides = true; 657 bool automatic_updates_allowed_by_overrides = true;
746 DWORD value = 0; 658 DWORD value = 0;
747 for (const base::string16& app_guid : app_guids) { 659
748 // First check the app-specific override value and reset that if needed. 660 // First check the app-specific override value and reset that if needed.
749 // Note that this intentionally sets the override to AUTOMATIC_UPDATES 661 // Note that this intentionally sets the override to AUTOMATIC_UPDATES even
750 // even if it was previously AUTO_UPDATES_ONLY. The thinking is that 662 // if it was previously AUTO_UPDATES_ONLY. The thinking is that
751 // AUTOMATIC_UPDATES is marginally more likely to let a user update and 663 // AUTOMATIC_UPDATES is marginally more likely to let a user update and this
752 // this code is only called when a stuck user asks for updates. 664 // code is only called when a stuck user asks for updates.
753 base::string16 app_update_override(kUpdateOverrideValuePrefix); 665 base::string16 app_update_override(kUpdateOverrideValuePrefix);
754 app_update_override.append(app_guid); 666 app_update_override.append(
755 if (policy_key.ReadValueDW(app_update_override.c_str(), 667 BrowserDistribution::GetDistribution()->GetAppGuid());
756 &value) != ERROR_SUCCESS) { 668 if (policy_key.ReadValueDW(app_update_override.c_str(), &value) !=
757 automatic_updates_allowed_by_overrides = false; 669 ERROR_SUCCESS) {
758 } else if (!GetUpdatePolicyFromDword(value, &update_policy) || 670 automatic_updates_allowed_by_overrides = false;
759 update_policy != GoogleUpdateSettings::AUTOMATIC_UPDATES) { 671 } else if (!GetUpdatePolicyFromDword(value, &update_policy) ||
760 automatic_updates_allowed_by_overrides = false; 672 update_policy != GoogleUpdateSettings::AUTOMATIC_UPDATES) {
761 ++needs_reset_count; 673 automatic_updates_allowed_by_overrides = false;
762 if (policy_key.WriteValue( 674 ++needs_reset_count;
763 app_update_override.c_str(), 675 if (policy_key.WriteValue(
764 static_cast<DWORD>(GoogleUpdateSettings::AUTOMATIC_UPDATES)) == 676 app_update_override.c_str(),
765 ERROR_SUCCESS) { 677 static_cast<DWORD>(GoogleUpdateSettings::AUTOMATIC_UPDATES)) ==
766 ++did_reset_count; 678 ERROR_SUCCESS) {
767 } 679 ++did_reset_count;
768 } 680 }
769 } 681 }
770 682
771 // If there were no app-specific override policies, see if there's a global 683 // If there were no app-specific override policies, see if there's a global
772 // policy preventing updates and delete it if so. 684 // policy preventing updates and delete it if so.
773 if (!automatic_updates_allowed_by_overrides && 685 if (!automatic_updates_allowed_by_overrides &&
774 policy_key.ReadValueDW(kUpdatePolicyValue, &value) == ERROR_SUCCESS && 686 policy_key.ReadValueDW(kUpdatePolicyValue, &value) == ERROR_SUCCESS &&
775 (!GetUpdatePolicyFromDword(value, &update_policy) || 687 (!GetUpdatePolicyFromDword(value, &update_policy) ||
776 update_policy != GoogleUpdateSettings::AUTOMATIC_UPDATES)) { 688 update_policy != GoogleUpdateSettings::AUTOMATIC_UPDATES)) {
777 ++needs_reset_count; 689 ++needs_reset_count;
(...skipping 13 matching lines...) Expand all
791 703
792 // Return whether the number of successful resets is the same as the 704 // Return whether the number of successful resets is the same as the
793 // number of things that appeared to need resetting. 705 // number of things that appeared to need resetting.
794 return (needs_reset_count == did_reset_count); 706 return (needs_reset_count == did_reset_count);
795 } else { 707 } else {
796 // For some reason we couldn't open the policy key with the desired 708 // For some reason we couldn't open the policy key with the desired
797 // permissions to make changes (the most likely reason is that there is no 709 // permissions to make changes (the most likely reason is that there is no
798 // policy set). Simply return whether or not we think updates are enabled. 710 // policy set). Simply return whether or not we think updates are enabled.
799 return AreAutoupdatesEnabled(); 711 return AreAutoupdatesEnabled();
800 } 712 }
801
802 #endif 713 #endif
803 // Non Google Chrome isn't going to autoupdate. 714 // Non Google Chrome isn't going to autoupdate.
804 return true; 715 return true;
805 } 716 }
806 717
807 // Reads and sanitizes the value of 718 // Reads and sanitizes the value of
808 // "HKLM\SOFTWARE\Policies\Google\Update\DownloadPreference". A valid 719 // "HKLM\SOFTWARE\Policies\Google\Update\DownloadPreference". A valid
809 // group policy option must be a single alpha numeric word of up to 32 720 // group policy option must be a single alpha numeric word of up to 32
810 // characters. 721 // characters.
811 base::string16 GoogleUpdateSettings::GetDownloadPreference() { 722 base::string16 GoogleUpdateSettings::GetDownloadPreference() {
(...skipping 10 matching lines...) Expand all
822 for (auto ch : value) { 733 for (auto ch : value) {
823 if (!base::IsAsciiAlpha(ch)) 734 if (!base::IsAsciiAlpha(ch))
824 return base::string16(); 735 return base::string16();
825 } 736 }
826 return value; 737 return value;
827 } 738 }
828 return base::string16(); 739 return base::string16();
829 } 740 }
830 741
831 void GoogleUpdateSettings::RecordChromeUpdatePolicyHistograms() { 742 void GoogleUpdateSettings::RecordChromeUpdatePolicyHistograms() {
832 const bool is_multi_install = InstallUtil::IsMultiInstall(IsSystemInstall());
833 const base::string16 app_guid = 743 const base::string16 app_guid =
834 BrowserDistribution::GetSpecificDistribution( 744 BrowserDistribution::GetDistribution()->GetAppGuid();
835 is_multi_install ? BrowserDistribution::CHROME_BINARIES :
836 BrowserDistribution::CHROME_BROWSER)->GetAppGuid();
837 745
838 bool is_overridden = false; 746 bool is_overridden = false;
839 const UpdatePolicy update_policy = GetAppUpdatePolicy(app_guid, 747 const UpdatePolicy update_policy = GetAppUpdatePolicy(app_guid,
840 &is_overridden); 748 &is_overridden);
841 UMA_HISTOGRAM_BOOLEAN("GoogleUpdate.UpdatePolicyIsOverridden", is_overridden); 749 UMA_HISTOGRAM_BOOLEAN("GoogleUpdate.UpdatePolicyIsOverridden", is_overridden);
842 UMA_HISTOGRAM_ENUMERATION("GoogleUpdate.EffectivePolicy", update_policy, 750 UMA_HISTOGRAM_ENUMERATION("GoogleUpdate.EffectivePolicy", update_policy,
843 UPDATE_POLICIES_COUNT); 751 UPDATE_POLICIES_COUNT);
844 } 752 }
845 753
846 base::string16 GoogleUpdateSettings::GetUninstallCommandLine( 754 base::string16 GoogleUpdateSettings::GetUninstallCommandLine(
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
1029 } 937 }
1030 938
1031 // If the key or value was not present, return the empty string. 939 // If the key or value was not present, return the empty string.
1032 if (result == ERROR_FILE_NOT_FOUND || result == ERROR_PATH_NOT_FOUND) { 940 if (result == ERROR_FILE_NOT_FOUND || result == ERROR_PATH_NOT_FOUND) {
1033 experiment_labels->clear(); 941 experiment_labels->clear();
1034 return true; 942 return true;
1035 } 943 }
1036 944
1037 return result == ERROR_SUCCESS; 945 return result == ERROR_SUCCESS;
1038 } 946 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698