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

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

Issue 1606943007: Implement Windows GPO support for "dlpref" in component updater. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix typo. Created 4 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 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::kDownloadPreference[] =
41 L"DownloadPreference";
42 const wchar_t GoogleUpdateSettings::kDownloadPreferenceCacheable[] =
43 L"cacheable";
39 const wchar_t GoogleUpdateSettings::kUpdateOverrideValuePrefix[] = L"Update"; 44 const wchar_t GoogleUpdateSettings::kUpdateOverrideValuePrefix[] = L"Update";
40 const wchar_t GoogleUpdateSettings::kCheckPeriodOverrideMinutes[] = 45 const wchar_t GoogleUpdateSettings::kCheckPeriodOverrideMinutes[] =
41 L"AutoUpdateCheckPeriodMinutes"; 46 L"AutoUpdateCheckPeriodMinutes";
42 47
43 // Don't allow update periods longer than six weeks. 48 // Don't allow update periods longer than six weeks.
44 const int GoogleUpdateSettings::kCheckPeriodOverrideMinutesMax = 49 const int GoogleUpdateSettings::kCheckPeriodOverrideMinutesMax =
45 60 * 24 * 7 * 6; 50 60 * 24 * 7 * 6;
46 51
47 const GoogleUpdateSettings::UpdatePolicy 52 const GoogleUpdateSettings::UpdatePolicy
48 GoogleUpdateSettings::kDefaultUpdatePolicy = 53 GoogleUpdateSettings::kDefaultUpdatePolicy =
(...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after
763 // permissions to make changes (the most likely reason is that there is no 768 // 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. 769 // policy set). Simply return whether or not we think updates are enabled.
765 return AreAutoupdatesEnabled(); 770 return AreAutoupdatesEnabled();
766 } 771 }
767 772
768 #endif 773 #endif
769 // Non Google Chrome isn't going to autoupdate. 774 // Non Google Chrome isn't going to autoupdate.
770 return true; 775 return true;
771 } 776 }
772 777
778 // Reads and sanitizes the value of
779 // "HKLM\SOFTWARE\Policies\Google\Update\DownloadPreference". A valid
780 // group policy option must be a single alpha numeric word of up to 32
781 // characters.
782 base::string16 GoogleUpdateSettings::GetDownloadPreference() {
783 // Validates that the argument value matches `[a-zA-z]{0-32}`.
784 struct Validator {
785 public:
786 static bool Validate(const base::string16& value) {
787 const size_t kMaxValueLength = 32;
788 if (value.size() > kMaxValueLength)
789 return false;
790 for (auto ch : value) {
791 if (!base::IsAsciiAlpha(ch))
792 return false;
793 }
794 return true;
795 }
796 };
797
798 RegKey policy_key;
799 base::string16 value;
800 if (policy_key.Open(HKEY_LOCAL_MACHINE, kPoliciesKey, KEY_QUERY_VALUE) ==
801 ERROR_SUCCESS &&
gab 2016/01/21 21:08:49 Is this git cl format's output? Would feel more na
Sorin Jianu 2016/01/25 20:04:58 Correct.
802 policy_key.ReadValue(kDownloadPreference, &value) == ERROR_SUCCESS &&
803 Validator::Validate(value)) {
gab 2016/01/22 16:06:50 Actually, why use a static method inside a local c
Sorin Jianu 2016/01/25 20:04:58 I tried to follow the existing structure of the co
gab 2016/01/25 20:33:50 Hmmm I don't see code defining a local static meth
Sorin Jianu 2016/01/25 21:27:56 I meant I followed the structure of: if (open(key)
gab 2016/01/26 03:44:55 Thanks, I prefer the latest version inline. To me
Sorin Jianu 2016/01/26 18:09:48 Acknowledged.
804 return value;
805 }
806
807 return base::string16();
808 }
809
773 void GoogleUpdateSettings::RecordChromeUpdatePolicyHistograms() { 810 void GoogleUpdateSettings::RecordChromeUpdatePolicyHistograms() {
774 const bool is_multi_install = InstallUtil::IsMultiInstall( 811 const bool is_multi_install = InstallUtil::IsMultiInstall(
775 BrowserDistribution::GetDistribution(), IsSystemInstall()); 812 BrowserDistribution::GetDistribution(), IsSystemInstall());
776 const base::string16 app_guid = 813 const base::string16 app_guid =
777 BrowserDistribution::GetSpecificDistribution( 814 BrowserDistribution::GetSpecificDistribution(
778 is_multi_install ? BrowserDistribution::CHROME_BINARIES : 815 is_multi_install ? BrowserDistribution::CHROME_BINARIES :
779 BrowserDistribution::CHROME_BROWSER)->GetAppGuid(); 816 BrowserDistribution::CHROME_BROWSER)->GetAppGuid();
780 817
781 bool is_overridden = false; 818 bool is_overridden = false;
782 const UpdatePolicy update_policy = GetAppUpdatePolicy(app_guid, 819 const UpdatePolicy update_policy = GetAppUpdatePolicy(app_guid,
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
971 } 1008 }
972 1009
973 // If the key or value was not present, return the empty string. 1010 // If the key or value was not present, return the empty string.
974 if (result == ERROR_FILE_NOT_FOUND || result == ERROR_PATH_NOT_FOUND) { 1011 if (result == ERROR_FILE_NOT_FOUND || result == ERROR_PATH_NOT_FOUND) {
975 experiment_labels->clear(); 1012 experiment_labels->clear();
976 return true; 1013 return true;
977 } 1014 }
978 1015
979 return result == ERROR_SUCCESS; 1016 return result == ERROR_SUCCESS;
980 } 1017 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698