| OLD | NEW |
| 1 | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 4 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 5 | 4 |
| 6 #include "components/component_updater/updater_state_win.h" | 5 #include "components/update_client/updater_state.h" |
| 7 | 6 |
| 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 | 14 |
| 15 #include "base/win/registry.h" | 15 #include "base/win/registry.h" |
| 16 #include "base/win/win_util.h" | 16 #include "base/win/win_util.h" |
| 17 | 17 |
| 18 namespace component_updater { | 18 // TODO(sorin): implement this in terms of |
| 19 // chrome/installer/util/google_update_settings (crbug.com/615187). |
| 20 |
| 21 namespace update_client { |
| 19 | 22 |
| 20 namespace { | 23 namespace { |
| 21 | 24 |
| 22 // Google Update group policy settings. | 25 // Google Update group policy settings. |
| 23 const wchar_t kGoogleUpdatePoliciesKey[] = | 26 const wchar_t kGoogleUpdatePoliciesKey[] = |
| 24 L"SOFTWARE\\Policies\\Google\\Update"; | 27 L"SOFTWARE\\Policies\\Google\\Update"; |
| 25 const wchar_t kCheckPeriodOverrideMinutes[] = L"AutoUpdateCheckPeriodMinutes"; | 28 const wchar_t kCheckPeriodOverrideMinutes[] = L"AutoUpdateCheckPeriodMinutes"; |
| 26 const wchar_t kUpdatePolicyValue[] = L"UpdateDefault"; | 29 const wchar_t kUpdatePolicyValue[] = L"UpdateDefault"; |
| 27 const wchar_t kChromeUpdatePolicyOverride[] = | 30 const wchar_t kChromeUpdatePolicyOverride[] = |
| 28 L"Update{8A69D345-D564-463C-AFF1-A69D9E530F96}"; | 31 L"Update{8A69D345-D564-463C-AFF1-A69D9E530F96}"; |
| 29 | 32 |
| 30 // Don't allow update periods longer than six weeks (Chrome release cadence). | 33 // Don't allow update periods longer than six weeks (Chrome release cadence). |
| 31 const int kCheckPeriodOverrideMinutesMax = 60 * 24 * 7 * 6; | 34 const int kCheckPeriodOverrideMinutesMax = 60 * 24 * 7 * 6; |
| 32 | 35 |
| 33 // Google Update registry settings. | 36 // Google Update registry settings. |
| 34 const wchar_t kRegPathGoogleUpdate[] = L"Software\\Google\\Update"; | 37 const wchar_t kRegPathGoogleUpdate[] = L"Software\\Google\\Update"; |
| 35 const wchar_t kRegPathClientsGoogleUpdate[] = | 38 const wchar_t kRegPathClientsGoogleUpdate[] = |
| 36 L"Software\\Google\\Update\\Clients\\" | 39 L"Software\\Google\\Update\\Clients\\" |
| 37 L"{430FD4D0-B729-4F61-AA34-91526481799D}"; | 40 L"{430FD4D0-B729-4F61-AA34-91526481799D}"; |
| 38 const wchar_t kRegValueGoogleUpdatePv[] = L"pv"; | 41 const wchar_t kRegValueGoogleUpdatePv[] = L"pv"; |
| 39 const wchar_t kRegValueLastStartedAU[] = L"LastStartedAU"; | 42 const wchar_t kRegValueLastStartedAU[] = L"LastStartedAU"; |
| 40 const wchar_t kRegValueLastChecked[] = L"LastChecked"; | 43 const wchar_t kRegValueLastChecked[] = L"LastChecked"; |
| 41 | 44 |
| 42 } // namespace | 45 } // namespace |
| 43 | 46 |
| 44 UpdaterState::UpdaterState(bool is_machine) : is_machine_(is_machine) {} | 47 std::string UpdaterState::GetUpdaterName() { |
| 45 | 48 return std::string("Omaha"); |
| 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 } | 49 } |
| 51 | 50 |
| 52 void UpdaterState::ReadState() { | 51 base::Version UpdaterState::GetUpdaterVersion(bool is_machine) { |
| 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; | 52 const HKEY root_key = is_machine ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; |
| 108 base::string16 version; | 53 base::string16 version; |
| 109 base::win::RegKey key; | 54 base::win::RegKey key; |
| 110 | 55 |
| 111 if (key.Open(root_key, kRegPathClientsGoogleUpdate, | 56 if (key.Open(root_key, kRegPathClientsGoogleUpdate, |
| 112 KEY_QUERY_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS && | 57 KEY_QUERY_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS && |
| 113 key.ReadValue(kRegValueGoogleUpdatePv, &version) == ERROR_SUCCESS) { | 58 key.ReadValue(kRegValueGoogleUpdatePv, &version) == ERROR_SUCCESS) { |
| 114 return base::Version(base::UTF16ToUTF8(version)); | 59 return base::Version(base::UTF16ToUTF8(version)); |
| 115 } | 60 } |
| 116 | 61 |
| 117 return base::Version(); | 62 return base::Version(); |
| 118 } | 63 } |
| 119 | 64 |
| 120 base::Time UpdaterState::GetGoogleUpdateLastStartedAU(bool is_machine) { | 65 base::Time UpdaterState::GetUpdaterLastStartedAU(bool is_machine) { |
| 121 return GetGoogleUpdateTimeValue(is_machine, kRegValueLastStartedAU); | 66 return GetUpdaterTimeValue(is_machine, kRegValueLastStartedAU); |
| 122 } | 67 } |
| 123 | 68 |
| 124 base::Time UpdaterState::GetGoogleUpdateLastChecked(bool is_machine) { | 69 base::Time UpdaterState::GetUpdaterLastChecked(bool is_machine) { |
| 125 return GetGoogleUpdateTimeValue(is_machine, kRegValueLastChecked); | 70 return GetUpdaterTimeValue(is_machine, kRegValueLastChecked); |
| 126 } | 71 } |
| 127 | 72 |
| 128 base::Time UpdaterState::GetGoogleUpdateTimeValue(bool is_machine, | 73 base::Time UpdaterState::GetUpdaterTimeValue(bool is_machine, |
| 129 const wchar_t* value_name) { | 74 const wchar_t* value_name) { |
| 130 const HKEY root_key = is_machine ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | 75 const HKEY root_key = is_machine ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; |
| 131 base::win::RegKey update_key; | 76 base::win::RegKey update_key; |
| 132 | 77 |
| 133 if (update_key.Open(root_key, kRegPathGoogleUpdate, | 78 if (update_key.Open(root_key, kRegPathGoogleUpdate, |
| 134 KEY_QUERY_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS) { | 79 KEY_QUERY_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS) { |
| 135 DWORD value(0); | 80 DWORD value(0); |
| 136 if (update_key.ReadValueDW(value_name, &value) == ERROR_SUCCESS) { | 81 if (update_key.ReadValueDW(value_name, &value) == ERROR_SUCCESS) { |
| 137 return base::Time::FromTimeT(value); | 82 return base::Time::FromTimeT(value); |
| 138 } | 83 } |
| 139 } | 84 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 154 (value == 0 || value > kCheckPeriodOverrideMinutesMax)) { | 99 (value == 0 || value > kCheckPeriodOverrideMinutesMax)) { |
| 155 return false; | 100 return false; |
| 156 } | 101 } |
| 157 | 102 |
| 158 return true; | 103 return true; |
| 159 } | 104 } |
| 160 | 105 |
| 161 // Returns -1 if the policy is not found or the value was invalid. Otherwise, | 106 // 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 | 107 // returns a value in the [0, 3] range, representing the value of the |
| 163 // Chrome update group policy. | 108 // Chrome update group policy. |
| 164 int UpdaterState::GetChromeUpdatePolicy() { | 109 int UpdaterState::GetUpdatePolicy() { |
| 165 const int kMaxUpdatePolicyValue = 3; | 110 const int kMaxUpdatePolicyValue = 3; |
| 166 | 111 |
| 167 base::win::RegKey policy_key; | 112 base::win::RegKey policy_key; |
| 168 | 113 |
| 169 if (policy_key.Open(HKEY_LOCAL_MACHINE, kGoogleUpdatePoliciesKey, | 114 if (policy_key.Open(HKEY_LOCAL_MACHINE, kGoogleUpdatePoliciesKey, |
| 170 KEY_QUERY_VALUE) != ERROR_SUCCESS) { | 115 KEY_QUERY_VALUE) != ERROR_SUCCESS) { |
| 171 return -1; | 116 return -1; |
| 172 } | 117 } |
| 173 | 118 |
| 174 DWORD value = 0; | 119 DWORD value = 0; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 185 return value; | 130 return value; |
| 186 } | 131 } |
| 187 | 132 |
| 188 return -1; | 133 return -1; |
| 189 } | 134 } |
| 190 | 135 |
| 191 bool UpdaterState::IsJoinedToDomain() { | 136 bool UpdaterState::IsJoinedToDomain() { |
| 192 return base::win::IsEnrolledToDomain(); | 137 return base::win::IsEnrolledToDomain(); |
| 193 } | 138 } |
| 194 | 139 |
| 195 } // namespace component_updater | 140 } // namespace update_client |
| OLD | NEW |