| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 FOUND_SAME_SETTING | 33 FOUND_SAME_SETTING |
| 34 }; | 34 }; |
| 35 | 35 |
| 36 bool ReadGoogleUpdateStrKey(const wchar_t* const name, std::wstring* value) { | 36 bool ReadGoogleUpdateStrKey(const wchar_t* const name, std::wstring* value) { |
| 37 // The registry functions below will end up going to disk. Do this on another | 37 // The registry functions below will end up going to disk. Do this on another |
| 38 // thread to avoid slowing the IO thread. http://crbug.com/62121 | 38 // thread to avoid slowing the IO thread. http://crbug.com/62121 |
| 39 base::ThreadRestrictions::ScopedAllowIO allow_io; | 39 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 40 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 40 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 41 std::wstring reg_path = dist->GetStateKey(); | 41 std::wstring reg_path = dist->GetStateKey(); |
| 42 RegKey key(HKEY_CURRENT_USER, reg_path.c_str(), KEY_READ); | 42 RegKey key(HKEY_CURRENT_USER, reg_path.c_str(), KEY_READ); |
| 43 if (!key.ReadValue(name, value)) { | 43 if (key.ReadValue(name, value) != ERROR_SUCCESS) { |
| 44 RegKey hklm_key(HKEY_LOCAL_MACHINE, reg_path.c_str(), KEY_READ); | 44 RegKey hklm_key(HKEY_LOCAL_MACHINE, reg_path.c_str(), KEY_READ); |
| 45 return hklm_key.ReadValue(name, value); | 45 return (hklm_key.ReadValue(name, value) == ERROR_SUCCESS); |
| 46 } | 46 } |
| 47 return true; | 47 return true; |
| 48 } | 48 } |
| 49 | 49 |
| 50 bool WriteGoogleUpdateStrKey(const wchar_t* const name, | 50 bool WriteGoogleUpdateStrKey(const wchar_t* const name, |
| 51 const std::wstring& value) { | 51 const std::wstring& value) { |
| 52 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 52 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 53 std::wstring reg_path = dist->GetStateKey(); | 53 std::wstring reg_path = dist->GetStateKey(); |
| 54 RegKey key(HKEY_CURRENT_USER, reg_path.c_str(), KEY_READ | KEY_WRITE); | 54 RegKey key(HKEY_CURRENT_USER, reg_path.c_str(), KEY_READ | KEY_WRITE); |
| 55 return key.WriteValue(name, value.c_str()); | 55 return key.WriteValue(name, value.c_str()) == ERROR_SUCCESS; |
| 56 } | 56 } |
| 57 | 57 |
| 58 bool ClearGoogleUpdateStrKey(const wchar_t* const name) { | 58 bool ClearGoogleUpdateStrKey(const wchar_t* const name) { |
| 59 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 59 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 60 std::wstring reg_path = dist->GetStateKey(); | 60 std::wstring reg_path = dist->GetStateKey(); |
| 61 RegKey key(HKEY_CURRENT_USER, reg_path.c_str(), KEY_READ | KEY_WRITE); | 61 RegKey key(HKEY_CURRENT_USER, reg_path.c_str(), KEY_READ | KEY_WRITE); |
| 62 std::wstring value; | 62 std::wstring value; |
| 63 if (!key.ReadValue(name, &value)) | 63 if (key.ReadValue(name, &value) != ERROR_SUCCESS) |
| 64 return false; | 64 return false; |
| 65 return key.WriteValue(name, L""); | 65 return key.WriteValue(name, L"") == ERROR_SUCCESS; |
| 66 } | 66 } |
| 67 | 67 |
| 68 bool RemoveGoogleUpdateStrKey(const wchar_t* const name) { | 68 bool RemoveGoogleUpdateStrKey(const wchar_t* const name) { |
| 69 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 69 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 70 std::wstring reg_path = dist->GetStateKey(); | 70 std::wstring reg_path = dist->GetStateKey(); |
| 71 RegKey key(HKEY_CURRENT_USER, reg_path.c_str(), KEY_READ | KEY_WRITE); | 71 RegKey key(HKEY_CURRENT_USER, reg_path.c_str(), KEY_READ | KEY_WRITE); |
| 72 if (!key.ValueExists(name)) | 72 if (!key.ValueExists(name)) |
| 73 return true; | 73 return true; |
| 74 return key.DeleteValue(name); | 74 return key.DeleteValue(name) == ERROR_SUCCESS; |
| 75 } | 75 } |
| 76 | 76 |
| 77 EulaSearchResult HasEULASetting(HKEY root, const std::wstring& state_key, | 77 EulaSearchResult HasEULASetting(HKEY root, const std::wstring& state_key, |
| 78 bool setting) { | 78 bool setting) { |
| 79 RegKey key; | 79 RegKey key; |
| 80 DWORD previous_value; | 80 DWORD previous_value = setting ? 1 : 0; |
| 81 | 81 |
| 82 if (!key.Open(root, state_key.c_str(), KEY_QUERY_VALUE)) | 82 if (key.Open(root, state_key.c_str(), KEY_QUERY_VALUE) != ERROR_SUCCESS) |
| 83 return NO_SETTING; | 83 return NO_SETTING; |
| 84 | 84 |
| 85 if (!key.ReadValueDW(google_update::kRegEULAAceptedField, &previous_value)) | 85 LONG result = key.ReadValueDW(google_update::kRegEULAAceptedField, |
| 86 &previous_value); |
| 87 if (result != ERROR_SUCCESS) |
| 86 return FOUND_CLIENT_STATE; | 88 return FOUND_CLIENT_STATE; |
| 87 | 89 |
| 88 return ((previous_value != 0) == setting) ? | 90 return ((previous_value != 0) == setting) ? |
| 89 FOUND_SAME_SETTING : FOUND_OPPOSITE_SETTING; | 91 FOUND_SAME_SETTING : FOUND_OPPOSITE_SETTING; |
| 90 } | 92 } |
| 91 | 93 |
| 92 } // namespace. | 94 } // namespace. |
| 93 | 95 |
| 94 bool GoogleUpdateSettings::GetCollectStatsConsent() { | 96 bool GoogleUpdateSettings::GetCollectStatsConsent() { |
| 95 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 97 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 96 std::wstring reg_path = dist->GetStateKey(); | 98 std::wstring reg_path = dist->GetStateKey(); |
| 97 RegKey key(HKEY_CURRENT_USER, reg_path.c_str(), KEY_READ); | 99 RegKey key(HKEY_CURRENT_USER, reg_path.c_str(), KEY_READ); |
| 98 DWORD value; | 100 DWORD value = 0; |
| 99 if (!key.ReadValueDW(google_update::kRegUsageStatsField, &value)) { | 101 LONG result = key.ReadValueDW(google_update::kRegUsageStatsField, &value); |
| 100 RegKey hklm_key(HKEY_LOCAL_MACHINE, reg_path.c_str(), KEY_READ); | 102 if (result != ERROR_SUCCESS) { |
| 101 if (!hklm_key.ReadValueDW(google_update::kRegUsageStatsField, &value)) | 103 key.Open(HKEY_LOCAL_MACHINE, reg_path.c_str(), KEY_READ); |
| 102 return false; | 104 key.ReadValueDW(google_update::kRegUsageStatsField, &value); |
| 103 } | 105 } |
| 104 return (1 == value); | 106 return (1 == value); |
| 105 } | 107 } |
| 106 | 108 |
| 107 bool GoogleUpdateSettings::SetCollectStatsConsent(bool consented) { | 109 bool GoogleUpdateSettings::SetCollectStatsConsent(bool consented) { |
| 108 DWORD value = consented? 1 : 0; | 110 DWORD value = consented? 1 : 0; |
| 109 // Writing to HKLM is only a best effort deal. | 111 // Writing to HKLM is only a best effort deal. |
| 110 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 112 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 111 std::wstring reg_path = dist->GetStateMediumKey(); | 113 std::wstring reg_path = dist->GetStateMediumKey(); |
| 112 RegKey key_hklm(HKEY_LOCAL_MACHINE, reg_path.c_str(), KEY_READ | KEY_WRITE); | 114 RegKey key(HKEY_LOCAL_MACHINE, reg_path.c_str(), KEY_READ | KEY_WRITE); |
| 113 key_hklm.WriteValue(google_update::kRegUsageStatsField, value); | 115 key.WriteValue(google_update::kRegUsageStatsField, value); |
| 114 // Writing to HKCU is used both by chrome and by the crash reporter. | 116 // Writing to HKCU is used both by chrome and by the crash reporter. |
| 115 reg_path = dist->GetStateKey(); | 117 reg_path = dist->GetStateKey(); |
| 116 RegKey key_hkcu(HKEY_CURRENT_USER, reg_path.c_str(), KEY_READ | KEY_WRITE); | 118 key.Open(HKEY_CURRENT_USER, reg_path.c_str(), KEY_READ | KEY_WRITE); |
| 117 return key_hkcu.WriteValue(google_update::kRegUsageStatsField, value); | 119 LONG result = key.WriteValue(google_update::kRegUsageStatsField, value); |
| 120 return result == ERROR_SUCCESS; |
| 118 } | 121 } |
| 119 | 122 |
| 120 bool GoogleUpdateSettings::GetMetricsId(std::wstring* metrics_id) { | 123 bool GoogleUpdateSettings::GetMetricsId(std::wstring* metrics_id) { |
| 121 return ReadGoogleUpdateStrKey(google_update::kRegMetricsId, metrics_id); | 124 return ReadGoogleUpdateStrKey(google_update::kRegMetricsId, metrics_id); |
| 122 } | 125 } |
| 123 | 126 |
| 124 bool GoogleUpdateSettings::SetMetricsId(const std::wstring& metrics_id) { | 127 bool GoogleUpdateSettings::SetMetricsId(const std::wstring& metrics_id) { |
| 125 return WriteGoogleUpdateStrKey(google_update::kRegMetricsId, metrics_id); | 128 return WriteGoogleUpdateStrKey(google_update::kRegMetricsId, metrics_id); |
| 126 } | 129 } |
| 127 | 130 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 149 reg_path = product.distribution()->GetStateMediumKey(); | 152 reg_path = product.distribution()->GetStateMediumKey(); |
| 150 } | 153 } |
| 151 } | 154 } |
| 152 if (status == NO_SETTING) { | 155 if (status == NO_SETTING) { |
| 153 LOG(WARNING) | 156 LOG(WARNING) |
| 154 << "eulaaccepted value not found; setting consent on package"; | 157 << "eulaaccepted value not found; setting consent on package"; |
| 155 reg_path = package.properties()->GetStateMediumKey(); | 158 reg_path = package.properties()->GetStateMediumKey(); |
| 156 } | 159 } |
| 157 } | 160 } |
| 158 RegKey key(HKEY_LOCAL_MACHINE, reg_path.c_str(), KEY_SET_VALUE); | 161 RegKey key(HKEY_LOCAL_MACHINE, reg_path.c_str(), KEY_SET_VALUE); |
| 159 return key.WriteValue(google_update::kRegEULAAceptedField, consented ? 1 : 0); | 162 LONG result = key.WriteValue(google_update::kRegEULAAceptedField, |
| 163 consented ? 1 : 0); |
| 164 return result == ERROR_SUCCESS; |
| 160 } | 165 } |
| 161 | 166 |
| 162 int GoogleUpdateSettings::GetLastRunTime() { | 167 int GoogleUpdateSettings::GetLastRunTime() { |
| 163 std::wstring time_s; | 168 std::wstring time_s; |
| 164 if (!ReadGoogleUpdateStrKey(google_update::kRegLastRunTimeField, &time_s)) | 169 if (!ReadGoogleUpdateStrKey(google_update::kRegLastRunTimeField, &time_s)) |
| 165 return -1; | 170 return -1; |
| 166 int64 time_i; | 171 int64 time_i; |
| 167 if (!base::StringToInt64(time_s, &time_i)) | 172 if (!base::StringToInt64(time_s, &time_i)) |
| 168 return -1; | 173 return -1; |
| 169 base::TimeDelta td = | 174 base::TimeDelta td = |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 void GoogleUpdateSettings::UpdateInstallStatus(bool system_install, | 245 void GoogleUpdateSettings::UpdateInstallStatus(bool system_install, |
| 241 bool incremental_install, bool multi_install, int install_return_code, | 246 bool incremental_install, bool multi_install, int install_return_code, |
| 242 const std::wstring& product_guid) { | 247 const std::wstring& product_guid) { |
| 243 HKEY reg_root = (system_install) ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | 248 HKEY reg_root = (system_install) ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; |
| 244 | 249 |
| 245 RegKey key; | 250 RegKey key; |
| 246 installer::ChannelInfo channel_info; | 251 installer::ChannelInfo channel_info; |
| 247 std::wstring reg_key(google_update::kRegPathClientState); | 252 std::wstring reg_key(google_update::kRegPathClientState); |
| 248 reg_key.append(L"\\"); | 253 reg_key.append(L"\\"); |
| 249 reg_key.append(product_guid); | 254 reg_key.append(product_guid); |
| 250 if (!key.Open(reg_root, reg_key.c_str(), KEY_QUERY_VALUE | KEY_SET_VALUE) || | 255 LONG result = key.Open(reg_root, reg_key.c_str(), |
| 251 !channel_info.Initialize(key)) { | 256 KEY_QUERY_VALUE | KEY_SET_VALUE); |
| 257 if (result != ERROR_SUCCESS || !channel_info.Initialize(key)) { |
| 252 VLOG(1) << "Application key not found."; | 258 VLOG(1) << "Application key not found."; |
| 253 if (!incremental_install && !multi_install || !install_return_code) { | 259 if (!incremental_install && !multi_install || !install_return_code) { |
| 254 VLOG(1) << "Returning without changing application key."; | 260 VLOG(1) << "Returning without changing application key."; |
| 255 return; | 261 return; |
| 256 } else if (!key.Valid()) { | 262 } else if (!key.Valid()) { |
| 257 reg_key.assign(google_update::kRegPathClientState); | 263 reg_key.assign(google_update::kRegPathClientState); |
| 258 if (!key.Open(reg_root, reg_key.c_str(), KEY_CREATE_SUB_KEY) || | 264 result = key.Open(reg_root, reg_key.c_str(), KEY_CREATE_SUB_KEY); |
| 259 !key.CreateKey(product_guid.c_str(), KEY_SET_VALUE)) { | 265 if (result != ERROR_SUCCESS) |
| 266 result = key.CreateKey(product_guid.c_str(), KEY_SET_VALUE); |
| 267 |
| 268 if (result != ERROR_SUCCESS) { |
| 260 LOG(ERROR) << "Failed to create application key."; | 269 LOG(ERROR) << "Failed to create application key."; |
| 261 return; | 270 return; |
| 262 } | 271 } |
| 263 } | 272 } |
| 264 } | 273 } |
| 265 | 274 |
| 266 if (UpdateGoogleUpdateApKey(incremental_install, multi_install, | 275 if (UpdateGoogleUpdateApKey(incremental_install, multi_install, |
| 267 install_return_code, &channel_info) && | 276 install_return_code, &channel_info) && |
| 268 !channel_info.Write(&key)) { | 277 !channel_info.Write(&key)) { |
| 269 LOG(ERROR) << "Failed to write value " << channel_info.value() | 278 LOG(ERROR) << "Failed to write value " << channel_info.value() |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 }; | 363 }; |
| 355 const wchar_t** end = &kBrands[arraysize(kBrands)]; | 364 const wchar_t** end = &kBrands[arraysize(kBrands)]; |
| 356 const wchar_t** found = std::find(&kBrands[0], end, brand); | 365 const wchar_t** found = std::find(&kBrands[0], end, brand); |
| 357 if (found != end) | 366 if (found != end) |
| 358 return true; | 367 return true; |
| 359 if (StartsWith(brand, L"EUB", true) || StartsWith(brand, L"EUC", true) || | 368 if (StartsWith(brand, L"EUB", true) || StartsWith(brand, L"EUC", true) || |
| 360 StartsWith(brand, L"GGR", true)) | 369 StartsWith(brand, L"GGR", true)) |
| 361 return true; | 370 return true; |
| 362 return false; | 371 return false; |
| 363 } | 372 } |
| OLD | NEW |