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 #include <limits> | 10 #include <limits> |
| 11 #include <vector> |
11 | 12 |
12 #include "base/command_line.h" | 13 #include "base/command_line.h" |
13 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
14 #include "base/logging.h" | 15 #include "base/logging.h" |
15 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
16 #include "base/path_service.h" | 17 #include "base/path_service.h" |
17 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
18 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
19 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
20 #include "base/threading/thread_restrictions.h" | 21 #include "base/threading/thread_restrictions.h" |
21 #include "base/time/time.h" | 22 #include "base/time/time.h" |
22 #include "base/win/registry.h" | 23 #include "base/win/registry.h" |
23 #include "base/win/win_util.h" | 24 #include "base/win/win_util.h" |
24 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.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/google_update_constants.h" | 29 #include "chrome/installer/util/google_update_constants.h" |
29 #include "chrome/installer/util/install_util.h" | 30 #include "chrome/installer/util/install_util.h" |
30 #include "chrome/installer/util/installation_state.h" | 31 #include "chrome/installer/util/installation_state.h" |
31 #include "chrome/installer/util/product.h" | 32 #include "chrome/installer/util/product.h" |
32 | 33 |
33 using base::win::RegKey; | 34 using base::win::RegKey; |
34 using installer::InstallationState; | 35 using installer::InstallationState; |
35 | 36 |
36 const wchar_t GoogleUpdateSettings::kPoliciesKey[] = | 37 const wchar_t GoogleUpdateSettings::kPoliciesKey[] = |
37 L"SOFTWARE\\Policies\\Google\\Update"; | 38 L"SOFTWARE\\Policies\\Google\\Update"; |
38 const wchar_t GoogleUpdateSettings::kUpdatePolicyValue[] = L"UpdateDefault"; | 39 const wchar_t GoogleUpdateSettings::kUpdatePolicyValue[] = L"UpdateDefault"; |
| 40 const wchar_t GoogleUpdateSettings::kDownloadPreferencePolicyValue[] = |
| 41 L"DownloadPreference"; |
39 const wchar_t GoogleUpdateSettings::kUpdateOverrideValuePrefix[] = L"Update"; | 42 const wchar_t GoogleUpdateSettings::kUpdateOverrideValuePrefix[] = L"Update"; |
40 const wchar_t GoogleUpdateSettings::kCheckPeriodOverrideMinutes[] = | 43 const wchar_t GoogleUpdateSettings::kCheckPeriodOverrideMinutes[] = |
41 L"AutoUpdateCheckPeriodMinutes"; | 44 L"AutoUpdateCheckPeriodMinutes"; |
42 | 45 |
43 // Don't allow update periods longer than six weeks. | 46 // Don't allow update periods longer than six weeks. |
44 const int GoogleUpdateSettings::kCheckPeriodOverrideMinutesMax = | 47 const int GoogleUpdateSettings::kCheckPeriodOverrideMinutesMax = |
45 60 * 24 * 7 * 6; | 48 60 * 24 * 7 * 6; |
46 | 49 |
47 const GoogleUpdateSettings::UpdatePolicy | 50 const GoogleUpdateSettings::UpdatePolicy |
48 GoogleUpdateSettings::kDefaultUpdatePolicy = | 51 GoogleUpdateSettings::kDefaultUpdatePolicy = |
(...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
763 // permissions to make changes (the most likely reason is that there is no | 766 // permissions to make changes (the most likely reason is that there is no |
764 // policy set). Simply return whether or not we think updates are enabled. | 767 // policy set). Simply return whether or not we think updates are enabled. |
765 return AreAutoupdatesEnabled(); | 768 return AreAutoupdatesEnabled(); |
766 } | 769 } |
767 | 770 |
768 #endif | 771 #endif |
769 // Non Google Chrome isn't going to autoupdate. | 772 // Non Google Chrome isn't going to autoupdate. |
770 return true; | 773 return true; |
771 } | 774 } |
772 | 775 |
| 776 // Reads and sanitizes the value of |
| 777 // "HKLM\SOFTWARE\Policies\Google\Update\DownloadPreference". A valid |
| 778 // group policy option must be a single alpha numeric word of up to 32 |
| 779 // characters. |
| 780 base::string16 GoogleUpdateSettings::GetDownloadPreference() { |
| 781 RegKey policy_key; |
| 782 base::string16 value; |
| 783 if (policy_key.Open(HKEY_LOCAL_MACHINE, kPoliciesKey, KEY_QUERY_VALUE) == |
| 784 ERROR_SUCCESS && |
| 785 policy_key.ReadValue(kDownloadPreferencePolicyValue, &value) == |
| 786 ERROR_SUCCESS) { |
| 787 // Validates that |value| matches `[a-zA-z]{0-32}`. |
| 788 const size_t kMaxValueLength = 32; |
| 789 if (value.size() > kMaxValueLength) |
| 790 return base::string16(); |
| 791 for (auto ch : value) { |
| 792 if (!base::IsAsciiAlpha(ch)) |
| 793 return base::string16(); |
| 794 } |
| 795 return value; |
| 796 } |
| 797 return base::string16(); |
| 798 } |
| 799 |
773 void GoogleUpdateSettings::RecordChromeUpdatePolicyHistograms() { | 800 void GoogleUpdateSettings::RecordChromeUpdatePolicyHistograms() { |
774 const bool is_multi_install = InstallUtil::IsMultiInstall( | 801 const bool is_multi_install = InstallUtil::IsMultiInstall( |
775 BrowserDistribution::GetDistribution(), IsSystemInstall()); | 802 BrowserDistribution::GetDistribution(), IsSystemInstall()); |
776 const base::string16 app_guid = | 803 const base::string16 app_guid = |
777 BrowserDistribution::GetSpecificDistribution( | 804 BrowserDistribution::GetSpecificDistribution( |
778 is_multi_install ? BrowserDistribution::CHROME_BINARIES : | 805 is_multi_install ? BrowserDistribution::CHROME_BINARIES : |
779 BrowserDistribution::CHROME_BROWSER)->GetAppGuid(); | 806 BrowserDistribution::CHROME_BROWSER)->GetAppGuid(); |
780 | 807 |
781 bool is_overridden = false; | 808 bool is_overridden = false; |
782 const UpdatePolicy update_policy = GetAppUpdatePolicy(app_guid, | 809 const UpdatePolicy update_policy = GetAppUpdatePolicy(app_guid, |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
971 } | 998 } |
972 | 999 |
973 // If the key or value was not present, return the empty string. | 1000 // If the key or value was not present, return the empty string. |
974 if (result == ERROR_FILE_NOT_FOUND || result == ERROR_PATH_NOT_FOUND) { | 1001 if (result == ERROR_FILE_NOT_FOUND || result == ERROR_PATH_NOT_FOUND) { |
975 experiment_labels->clear(); | 1002 experiment_labels->clear(); |
976 return true; | 1003 return true; |
977 } | 1004 } |
978 | 1005 |
979 return result == ERROR_SUCCESS; | 1006 return result == ERROR_SUCCESS; |
980 } | 1007 } |
OLD | NEW |