| OLD | NEW |
| 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 | 10 |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/metrics/histogram_macros.h" | 14 #include "base/metrics/histogram_macros.h" |
| 15 #include "base/numerics/safe_conversions.h" | 15 #include "base/numerics/safe_conversions.h" |
| 16 #include "base/path_service.h" | 16 #include "base/path_service.h" |
| 17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
| 18 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
| 19 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 20 #include "base/threading/thread_restrictions.h" | 20 #include "base/threading/thread_restrictions.h" |
| 21 #include "base/time/time.h" | 21 #include "base/time/time.h" |
| 22 #include "base/win/registry.h" | 22 #include "base/win/registry.h" |
| 23 #include "base/win/win_util.h" | 23 #include "base/win/win_util.h" |
| 24 #include "chrome/common/chrome_switches.h" | 24 #include "chrome/common/chrome_switches.h" |
| 25 #include "chrome/install_static/install_util.h" |
| 25 #include "chrome/installer/util/app_registration_data.h" | 26 #include "chrome/installer/util/app_registration_data.h" |
| 26 #include "chrome/installer/util/browser_distribution.h" | 27 #include "chrome/installer/util/browser_distribution.h" |
| 27 #include "chrome/installer/util/channel_info.h" | 28 #include "chrome/installer/util/channel_info.h" |
| 28 #include "chrome/installer/util/install_util.h" | 29 #include "chrome/installer/util/install_util.h" |
| 29 #include "chrome/installer/util/installation_state.h" | 30 #include "chrome/installer/util/installation_state.h" |
| 30 #include "chrome/installer/util/product.h" | 31 #include "chrome/installer/util/product.h" |
| 31 | 32 |
| 32 using base::win::RegKey; | 33 using base::win::RegKey; |
| 33 using installer::InstallationState; | 34 using installer::InstallationState; |
| 34 | 35 |
| (...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 int handle, const base::string16& key, const base::string16& value) { | 546 int handle, const base::string16& key, const base::string16& value) { |
| 546 HKEY reg_key = reinterpret_cast<HKEY>( | 547 HKEY reg_key = reinterpret_cast<HKEY>( |
| 547 reinterpret_cast<void*>(static_cast<uintptr_t>(handle))); | 548 reinterpret_cast<void*>(static_cast<uintptr_t>(handle))); |
| 548 DWORD size = static_cast<DWORD>(value.size()) * sizeof(wchar_t); | 549 DWORD size = static_cast<DWORD>(value.size()) * sizeof(wchar_t); |
| 549 LSTATUS status = RegSetValueEx(reg_key, key.c_str(), 0, REG_SZ, | 550 LSTATUS status = RegSetValueEx(reg_key, key.c_str(), 0, REG_SZ, |
| 550 reinterpret_cast<const BYTE*>(value.c_str()), size); | 551 reinterpret_cast<const BYTE*>(value.c_str()), size); |
| 551 return status == ERROR_SUCCESS; | 552 return status == ERROR_SUCCESS; |
| 552 } | 553 } |
| 553 | 554 |
| 554 GoogleUpdateSettings::UpdatePolicy GoogleUpdateSettings::GetAppUpdatePolicy( | 555 GoogleUpdateSettings::UpdatePolicy GoogleUpdateSettings::GetAppUpdatePolicy( |
| 555 const base::string16& app_guid, | 556 base::StringPiece16 app_guid, |
| 556 bool* is_overridden) { | 557 bool* is_overridden) { |
| 557 bool found_override = false; | 558 bool found_override = false; |
| 558 UpdatePolicy update_policy = kDefaultUpdatePolicy; | 559 UpdatePolicy update_policy = kDefaultUpdatePolicy; |
| 559 | 560 |
| 560 #if defined(GOOGLE_CHROME_BUILD) | 561 #if defined(GOOGLE_CHROME_BUILD) |
| 561 DCHECK(!app_guid.empty()); | 562 DCHECK(!app_guid.empty()); |
| 562 RegKey policy_key; | 563 RegKey policy_key; |
| 563 | 564 |
| 564 // Google Update Group Policy settings are always in HKLM. | 565 // Google Update Group Policy settings are always in HKLM. |
| 565 // TODO(wfh): Check if policies should go into Wow6432Node or not. | 566 // TODO(wfh): Check if policies should go into Wow6432Node or not. |
| 566 if (policy_key.Open(HKEY_LOCAL_MACHINE, kPoliciesKey, KEY_QUERY_VALUE) == | 567 if (policy_key.Open(HKEY_LOCAL_MACHINE, kPoliciesKey, KEY_QUERY_VALUE) == |
| 567 ERROR_SUCCESS) { | 568 ERROR_SUCCESS) { |
| 568 DWORD value = 0; | 569 DWORD value = 0; |
| 569 base::string16 app_update_override(kUpdateOverrideValuePrefix); | 570 base::string16 app_update_override(kUpdateOverrideValuePrefix); |
| 570 app_update_override.append(app_guid); | 571 app_guid.AppendToString(&app_update_override); |
| 571 // First try to read and comprehend the app-specific override. | 572 // First try to read and comprehend the app-specific override. |
| 572 found_override = (policy_key.ReadValueDW(app_update_override.c_str(), | 573 found_override = (policy_key.ReadValueDW(app_update_override.c_str(), |
| 573 &value) == ERROR_SUCCESS && | 574 &value) == ERROR_SUCCESS && |
| 574 GetUpdatePolicyFromDword(value, &update_policy)); | 575 GetUpdatePolicyFromDword(value, &update_policy)); |
| 575 | 576 |
| 576 // Failing that, try to read and comprehend the default override. | 577 // Failing that, try to read and comprehend the default override. |
| 577 if (!found_override && | 578 if (!found_override && |
| 578 policy_key.ReadValueDW(kUpdatePolicyValue, &value) == ERROR_SUCCESS) { | 579 policy_key.ReadValueDW(kUpdatePolicyValue, &value) == ERROR_SUCCESS) { |
| 579 GetUpdatePolicyFromDword(value, &update_policy); | 580 GetUpdatePolicyFromDword(value, &update_policy); |
| 580 } | 581 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 596 RegKey policy_key; | 597 RegKey policy_key; |
| 597 DWORD value = 0; | 598 DWORD value = 0; |
| 598 if (policy_key.Open(HKEY_LOCAL_MACHINE, kPoliciesKey, | 599 if (policy_key.Open(HKEY_LOCAL_MACHINE, kPoliciesKey, |
| 599 KEY_QUERY_VALUE) == ERROR_SUCCESS && | 600 KEY_QUERY_VALUE) == ERROR_SUCCESS && |
| 600 policy_key.ReadValueDW(kCheckPeriodOverrideMinutes, | 601 policy_key.ReadValueDW(kCheckPeriodOverrideMinutes, |
| 601 &value) == ERROR_SUCCESS && | 602 &value) == ERROR_SUCCESS && |
| 602 (value == 0 || value > kCheckPeriodOverrideMinutesMax)) { | 603 (value == 0 || value > kCheckPeriodOverrideMinutesMax)) { |
| 603 return false; | 604 return false; |
| 604 } | 605 } |
| 605 | 606 |
| 606 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 607 UpdatePolicy app_policy = |
| 607 UpdatePolicy app_policy = GetAppUpdatePolicy(dist->GetAppGuid(), nullptr); | 608 GetAppUpdatePolicy(install_static::GetAppGuid(), nullptr); |
| 608 return app_policy == AUTOMATIC_UPDATES || app_policy == AUTO_UPDATES_ONLY; | 609 return app_policy == AUTOMATIC_UPDATES || app_policy == AUTO_UPDATES_ONLY; |
| 609 #else // defined(GOOGLE_CHROME_BUILD) | 610 #else // defined(GOOGLE_CHROME_BUILD) |
| 610 // Chromium does not auto update. | 611 // Chromium does not auto update. |
| 611 return false; | 612 return false; |
| 612 #endif // !defined(GOOGLE_CHROME_BUILD) | 613 #endif // !defined(GOOGLE_CHROME_BUILD) |
| 613 } | 614 } |
| 614 | 615 |
| 615 // static | 616 // static |
| 616 bool GoogleUpdateSettings::ReenableAutoupdates() { | 617 bool GoogleUpdateSettings::ReenableAutoupdates() { |
| 617 #if defined(GOOGLE_CHROME_BUILD) | 618 #if defined(GOOGLE_CHROME_BUILD) |
| 618 int needs_reset_count = 0; | 619 int needs_reset_count = 0; |
| 619 int did_reset_count = 0; | 620 int did_reset_count = 0; |
| 620 | 621 |
| 621 UpdatePolicy update_policy = kDefaultUpdatePolicy; | 622 UpdatePolicy update_policy = kDefaultUpdatePolicy; |
| 622 RegKey policy_key; | 623 RegKey policy_key; |
| 623 if (policy_key.Open(HKEY_LOCAL_MACHINE, kPoliciesKey, | 624 if (policy_key.Open(HKEY_LOCAL_MACHINE, kPoliciesKey, |
| 624 KEY_SET_VALUE | KEY_QUERY_VALUE) == ERROR_SUCCESS) { | 625 KEY_SET_VALUE | KEY_QUERY_VALUE) == ERROR_SUCCESS) { |
| 625 // Set to true while app-specific overrides are present that allow automatic | 626 // Set to true while app-specific overrides are present that allow automatic |
| 626 // updates. When this is the case, the defaults are irrelevant and don't | 627 // updates. When this is the case, the defaults are irrelevant and don't |
| 627 // need to be checked or reset. | 628 // need to be checked or reset. |
| 628 bool automatic_updates_allowed_by_overrides = true; | 629 bool automatic_updates_allowed_by_overrides = true; |
| 629 DWORD value = 0; | 630 DWORD value = 0; |
| 630 | 631 |
| 631 // First check the app-specific override value and reset that if needed. | 632 // First check the app-specific override value and reset that if needed. |
| 632 // Note that this intentionally sets the override to AUTOMATIC_UPDATES even | 633 // Note that this intentionally sets the override to AUTOMATIC_UPDATES even |
| 633 // if it was previously AUTO_UPDATES_ONLY. The thinking is that | 634 // if it was previously AUTO_UPDATES_ONLY. The thinking is that |
| 634 // AUTOMATIC_UPDATES is marginally more likely to let a user update and this | 635 // AUTOMATIC_UPDATES is marginally more likely to let a user update and this |
| 635 // code is only called when a stuck user asks for updates. | 636 // code is only called when a stuck user asks for updates. |
| 636 base::string16 app_update_override(kUpdateOverrideValuePrefix); | 637 base::string16 app_update_override(kUpdateOverrideValuePrefix); |
| 637 app_update_override.append( | 638 app_update_override.append(install_static::GetAppGuid()); |
| 638 BrowserDistribution::GetDistribution()->GetAppGuid()); | |
| 639 if (policy_key.ReadValueDW(app_update_override.c_str(), &value) != | 639 if (policy_key.ReadValueDW(app_update_override.c_str(), &value) != |
| 640 ERROR_SUCCESS) { | 640 ERROR_SUCCESS) { |
| 641 automatic_updates_allowed_by_overrides = false; | 641 automatic_updates_allowed_by_overrides = false; |
| 642 } else if (!GetUpdatePolicyFromDword(value, &update_policy) || | 642 } else if (!GetUpdatePolicyFromDword(value, &update_policy) || |
| 643 update_policy != GoogleUpdateSettings::AUTOMATIC_UPDATES) { | 643 update_policy != GoogleUpdateSettings::AUTOMATIC_UPDATES) { |
| 644 automatic_updates_allowed_by_overrides = false; | 644 automatic_updates_allowed_by_overrides = false; |
| 645 ++needs_reset_count; | 645 ++needs_reset_count; |
| 646 if (policy_key.WriteValue( | 646 if (policy_key.WriteValue( |
| 647 app_update_override.c_str(), | 647 app_update_override.c_str(), |
| 648 static_cast<DWORD>(GoogleUpdateSettings::AUTOMATIC_UPDATES)) == | 648 static_cast<DWORD>(GoogleUpdateSettings::AUTOMATIC_UPDATES)) == |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 704 for (auto ch : value) { | 704 for (auto ch : value) { |
| 705 if (!base::IsAsciiAlpha(ch)) | 705 if (!base::IsAsciiAlpha(ch)) |
| 706 return base::string16(); | 706 return base::string16(); |
| 707 } | 707 } |
| 708 return value; | 708 return value; |
| 709 } | 709 } |
| 710 return base::string16(); | 710 return base::string16(); |
| 711 } | 711 } |
| 712 | 712 |
| 713 void GoogleUpdateSettings::RecordChromeUpdatePolicyHistograms() { | 713 void GoogleUpdateSettings::RecordChromeUpdatePolicyHistograms() { |
| 714 const base::string16 app_guid = | |
| 715 BrowserDistribution::GetDistribution()->GetAppGuid(); | |
| 716 | |
| 717 bool is_overridden = false; | 714 bool is_overridden = false; |
| 718 const UpdatePolicy update_policy = GetAppUpdatePolicy(app_guid, | 715 const UpdatePolicy update_policy = |
| 719 &is_overridden); | 716 GetAppUpdatePolicy(install_static::GetAppGuid(), &is_overridden); |
| 720 UMA_HISTOGRAM_BOOLEAN("GoogleUpdate.UpdatePolicyIsOverridden", is_overridden); | 717 UMA_HISTOGRAM_BOOLEAN("GoogleUpdate.UpdatePolicyIsOverridden", is_overridden); |
| 721 UMA_HISTOGRAM_ENUMERATION("GoogleUpdate.EffectivePolicy", update_policy, | 718 UMA_HISTOGRAM_ENUMERATION("GoogleUpdate.EffectivePolicy", update_policy, |
| 722 UPDATE_POLICIES_COUNT); | 719 UPDATE_POLICIES_COUNT); |
| 723 } | 720 } |
| 724 | 721 |
| 725 base::string16 GoogleUpdateSettings::GetUninstallCommandLine( | 722 base::string16 GoogleUpdateSettings::GetUninstallCommandLine( |
| 726 bool system_install) { | 723 bool system_install) { |
| 727 const HKEY root_key = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | 724 const HKEY root_key = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; |
| 728 base::string16 cmd_line; | 725 base::string16 cmd_line; |
| 729 RegKey update_key; | 726 RegKey update_key; |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 842 | 839 |
| 843 bool GoogleUpdateSettings::GetUpdateDetailForGoogleUpdate(bool system_install, | 840 bool GoogleUpdateSettings::GetUpdateDetailForGoogleUpdate(bool system_install, |
| 844 ProductData* data) { | 841 ProductData* data) { |
| 845 return GetUpdateDetailForApp(system_install, | 842 return GetUpdateDetailForApp(system_install, |
| 846 google_update::kGoogleUpdateUpgradeCode, | 843 google_update::kGoogleUpdateUpgradeCode, |
| 847 data); | 844 data); |
| 848 } | 845 } |
| 849 | 846 |
| 850 bool GoogleUpdateSettings::GetUpdateDetail(bool system_install, | 847 bool GoogleUpdateSettings::GetUpdateDetail(bool system_install, |
| 851 ProductData* data) { | 848 ProductData* data) { |
| 852 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 849 return GetUpdateDetailForApp(system_install, install_static::GetAppGuid(), |
| 853 return GetUpdateDetailForApp(system_install, | |
| 854 dist->GetAppGuid().c_str(), | |
| 855 data); | 850 data); |
| 856 } | 851 } |
| 857 | 852 |
| 858 bool GoogleUpdateSettings::SetExperimentLabels( | 853 bool GoogleUpdateSettings::SetExperimentLabels( |
| 859 bool system_install, | 854 bool system_install, |
| 860 const base::string16& experiment_labels) { | 855 const base::string16& experiment_labels) { |
| 861 HKEY reg_root = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | 856 HKEY reg_root = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; |
| 862 | 857 |
| 863 // Use the browser distribution and install level to write to the correct | 858 // Use the browser distribution and install level to write to the correct |
| 864 // client state/app guid key. | 859 // client state/app guid key. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 908 } | 903 } |
| 909 | 904 |
| 910 // If the key or value was not present, return the empty string. | 905 // If the key or value was not present, return the empty string. |
| 911 if (result == ERROR_FILE_NOT_FOUND || result == ERROR_PATH_NOT_FOUND) { | 906 if (result == ERROR_FILE_NOT_FOUND || result == ERROR_PATH_NOT_FOUND) { |
| 912 experiment_labels->clear(); | 907 experiment_labels->clear(); |
| 913 return true; | 908 return true; |
| 914 } | 909 } |
| 915 | 910 |
| 916 return result == ERROR_SUCCESS; | 911 return result == ERROR_SUCCESS; |
| 917 } | 912 } |
| OLD | NEW |