Chromium Code Reviews| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 82 // how the values of multiple users are to be combined. | 82 // how the values of multiple users are to be combined. |
| 83 std::wstring uniquename; // presubmit: allow wstring | 83 std::wstring uniquename; // presubmit: allow wstring |
| 84 if (!base::win::GetUserSidString(&uniquename)) { | 84 if (!base::win::GetUserSidString(&uniquename)) { |
| 85 NOTREACHED(); | 85 NOTREACHED(); |
| 86 return false; | 86 return false; |
| 87 } | 87 } |
| 88 | 88 |
| 89 base::string16 reg_path(app_reg_data.GetStateMediumKey()); | 89 base::string16 reg_path(app_reg_data.GetStateMediumKey()); |
| 90 reg_path.append(L"\\"); | 90 reg_path.append(L"\\"); |
| 91 reg_path.append(name); | 91 reg_path.append(name); |
| 92 RegKey key(HKEY_LOCAL_MACHINE, reg_path.c_str(), KEY_SET_VALUE); | 92 RegKey key( |
| 93 HKEY_LOCAL_MACHINE, reg_path.c_str(), KEY_SET_VALUE | KEY_WOW64_32KEY); | |
| 93 key.WriteValue(google_update::kRegAggregateMethod, aggregate); | 94 key.WriteValue(google_update::kRegAggregateMethod, aggregate); |
| 94 return (key.WriteValue(uniquename.c_str(), value.c_str()) == ERROR_SUCCESS); | 95 return (key.WriteValue(uniquename.c_str(), value.c_str()) == ERROR_SUCCESS); |
| 95 } else { | 96 } else { |
| 96 // User installs are easy: just write the values to HKCU tree. | 97 // User installs are easy: just write the values to HKCU tree. |
| 97 RegKey key(HKEY_CURRENT_USER, app_reg_data.GetStateKey().c_str(), | 98 RegKey key(HKEY_CURRENT_USER, app_reg_data.GetStateKey().c_str(), |
|
grt (UTC plus 2)
2014/06/04 17:20:05
although you and i know that this isn't currently
Will Harris
2014/06/04 17:48:07
Done.
| |
| 98 KEY_SET_VALUE); | 99 KEY_SET_VALUE); |
| 99 return (key.WriteValue(name, value.c_str()) == ERROR_SUCCESS); | 100 return (key.WriteValue(name, value.c_str()) == ERROR_SUCCESS); |
| 100 } | 101 } |
| 101 } | 102 } |
| 102 | 103 |
| 103 bool WriteGoogleUpdateStrKey(const wchar_t* const name, | 104 bool WriteGoogleUpdateStrKey(const wchar_t* const name, |
| 104 const std::wstring& value) { | 105 const std::wstring& value) { |
| 105 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 106 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 106 return WriteGoogleUpdateStrKeyInternal( | 107 return WriteGoogleUpdateStrKeyInternal( |
| 107 dist->GetAppRegistrationData(), false, name, value, NULL); | 108 dist->GetAppRegistrationData(), false, name, value, NULL); |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 224 } | 225 } |
| 225 | 226 |
| 226 RegKey key; | 227 RegKey key; |
| 227 DWORD value = 0; | 228 DWORD value = 0; |
| 228 bool have_value = false; | 229 bool have_value = false; |
| 229 | 230 |
| 230 // For system-level installs, try ClientStateMedium first. | 231 // For system-level installs, try ClientStateMedium first. |
| 231 have_value = | 232 have_value = |
| 232 system_install && | 233 system_install && |
| 233 key.Open(HKEY_LOCAL_MACHINE, dist->GetStateMediumKey().c_str(), | 234 key.Open(HKEY_LOCAL_MACHINE, dist->GetStateMediumKey().c_str(), |
| 234 KEY_QUERY_VALUE) == ERROR_SUCCESS && | 235 KEY_QUERY_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS && |
|
grt (UTC plus 2)
2014/06/04 17:20:05
i like
const REGSAM kAccess = KEY_QUERY_VALUE |
Will Harris
2014/06/04 17:48:07
Done.
| |
| 235 key.ReadValueDW(google_update::kRegUsageStatsField, | 236 key.ReadValueDW(google_update::kRegUsageStatsField, |
| 236 &value) == ERROR_SUCCESS; | 237 &value) == ERROR_SUCCESS; |
| 237 | 238 |
| 238 // Otherwise, try ClientState. | 239 // Otherwise, try ClientState. |
| 239 if (!have_value) { | 240 if (!have_value) { |
| 240 have_value = | 241 have_value = |
| 241 key.Open(system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, | 242 key.Open(system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, |
| 242 dist->GetStateKey().c_str(), | 243 dist->GetStateKey().c_str(), |
| 243 KEY_QUERY_VALUE) == ERROR_SUCCESS && | 244 KEY_QUERY_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS && |
| 244 key.ReadValueDW(google_update::kRegUsageStatsField, | 245 key.ReadValueDW(google_update::kRegUsageStatsField, |
| 245 &value) == ERROR_SUCCESS; | 246 &value) == ERROR_SUCCESS; |
| 246 } | 247 } |
| 247 | 248 |
| 248 // Google Update specifically checks that the value is 1, so we do the same. | 249 // Google Update specifically checks that the value is 1, so we do the same. |
| 249 return have_value && value == 1; | 250 return have_value && value == 1; |
| 250 } | 251 } |
| 251 | 252 |
| 252 bool GoogleUpdateSettings::SetCollectStatsConsent(bool consented) { | 253 bool GoogleUpdateSettings::SetCollectStatsConsent(bool consented) { |
| 253 return SetCollectStatsConsentAtLevel(IsSystemInstall(), consented); | 254 return SetCollectStatsConsentAtLevel(IsSystemInstall(), consented); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 264 if (InstallUtil::IsMultiInstall(dist, system_install)) { | 265 if (InstallUtil::IsMultiInstall(dist, system_install)) { |
| 265 dist = BrowserDistribution::GetSpecificDistribution( | 266 dist = BrowserDistribution::GetSpecificDistribution( |
| 266 BrowserDistribution::CHROME_BINARIES); | 267 BrowserDistribution::CHROME_BINARIES); |
| 267 } | 268 } |
| 268 | 269 |
| 269 // Write to ClientStateMedium for system-level; ClientState otherwise. | 270 // Write to ClientStateMedium for system-level; ClientState otherwise. |
| 270 HKEY root_key = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | 271 HKEY root_key = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; |
| 271 std::wstring reg_path = | 272 std::wstring reg_path = |
| 272 system_install ? dist->GetStateMediumKey() : dist->GetStateKey(); | 273 system_install ? dist->GetStateMediumKey() : dist->GetStateKey(); |
| 273 RegKey key; | 274 RegKey key; |
| 274 LONG result = key.Create(root_key, reg_path.c_str(), KEY_SET_VALUE); | 275 LONG result = key.Create( |
| 276 root_key, reg_path.c_str(), KEY_SET_VALUE | KEY_WOW64_32KEY); | |
| 275 if (result != ERROR_SUCCESS) { | 277 if (result != ERROR_SUCCESS) { |
| 276 LOG(ERROR) << "Failed opening key " << reg_path << " to set " | 278 LOG(ERROR) << "Failed opening key " << reg_path << " to set " |
| 277 << google_update::kRegUsageStatsField << "; result: " << result; | 279 << google_update::kRegUsageStatsField << "; result: " << result; |
| 278 } else { | 280 } else { |
| 279 result = key.WriteValue(google_update::kRegUsageStatsField, value); | 281 result = key.WriteValue(google_update::kRegUsageStatsField, value); |
| 280 LOG_IF(ERROR, result != ERROR_SUCCESS) << "Failed setting " | 282 LOG_IF(ERROR, result != ERROR_SUCCESS) << "Failed setting " |
| 281 << google_update::kRegUsageStatsField << " in key " << reg_path | 283 << google_update::kRegUsageStatsField << " in key " << reg_path |
| 282 << "; result: " << result; | 284 << "; result: " << result; |
| 283 } | 285 } |
| 284 return (result == ERROR_SUCCESS); | 286 return (result == ERROR_SUCCESS); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 301 const InstallationState& machine_state, | 303 const InstallationState& machine_state, |
| 302 BrowserDistribution* dist, | 304 BrowserDistribution* dist, |
| 303 bool consented) { | 305 bool consented) { |
| 304 DCHECK(dist); | 306 DCHECK(dist); |
| 305 const DWORD eula_accepted = consented ? 1 : 0; | 307 const DWORD eula_accepted = consented ? 1 : 0; |
| 306 std::wstring reg_path = dist->GetStateMediumKey(); | 308 std::wstring reg_path = dist->GetStateMediumKey(); |
| 307 bool succeeded = true; | 309 bool succeeded = true; |
| 308 RegKey key; | 310 RegKey key; |
| 309 | 311 |
| 310 // Write the consent value into the product's ClientStateMedium key. | 312 // Write the consent value into the product's ClientStateMedium key. |
| 311 if (key.Create(HKEY_LOCAL_MACHINE, reg_path.c_str(), | 313 if (key.Create(HKEY_LOCAL_MACHINE, |
| 312 KEY_SET_VALUE) != ERROR_SUCCESS || | 314 reg_path.c_str(), |
| 315 KEY_SET_VALUE | KEY_WOW64_32KEY) != ERROR_SUCCESS || | |
|
grt (UTC plus 2)
2014/06/04 17:20:05
local const for this function, too?
Will Harris
2014/06/04 17:48:07
Done.
| |
| 313 key.WriteValue(google_update::kRegEULAAceptedField, | 316 key.WriteValue(google_update::kRegEULAAceptedField, |
| 314 eula_accepted) != ERROR_SUCCESS) { | 317 eula_accepted) != ERROR_SUCCESS) { |
| 315 succeeded = false; | 318 succeeded = false; |
| 316 } | 319 } |
| 317 | 320 |
| 318 // If this is a multi-install, also write it into the binaries' key. | 321 // If this is a multi-install, also write it into the binaries' key. |
| 319 // --mutli-install is not provided on the command-line, so deduce it from | 322 // --mutli-install is not provided on the command-line, so deduce it from |
| 320 // the product's state. | 323 // the product's state. |
| 321 const installer::ProductState* product_state = | 324 const installer::ProductState* product_state = |
| 322 machine_state.GetProductState(true, dist->GetType()); | 325 machine_state.GetProductState(true, dist->GetType()); |
| 323 if (product_state != NULL && product_state->is_multi_install()) { | 326 if (product_state != NULL && product_state->is_multi_install()) { |
| 324 dist = BrowserDistribution::GetSpecificDistribution( | 327 dist = BrowserDistribution::GetSpecificDistribution( |
| 325 BrowserDistribution::CHROME_BINARIES); | 328 BrowserDistribution::CHROME_BINARIES); |
| 326 reg_path = dist->GetStateMediumKey(); | 329 reg_path = dist->GetStateMediumKey(); |
| 327 if (key.Create(HKEY_LOCAL_MACHINE, reg_path.c_str(), | 330 if (key.Create(HKEY_LOCAL_MACHINE, reg_path.c_str(), |
| 328 KEY_SET_VALUE) != ERROR_SUCCESS || | 331 KEY_SET_VALUE | KEY_WOW64_32KEY) != ERROR_SUCCESS || |
| 329 key.WriteValue(google_update::kRegEULAAceptedField, | 332 key.WriteValue(google_update::kRegEULAAceptedField, |
| 330 eula_accepted) != ERROR_SUCCESS) { | 333 eula_accepted) != ERROR_SUCCESS) { |
| 331 succeeded = false; | 334 succeeded = false; |
| 332 } | 335 } |
| 333 } | 336 } |
| 334 | 337 |
| 335 return succeeded; | 338 return succeeded; |
| 336 } | 339 } |
| 337 | 340 |
| 338 int GoogleUpdateSettings::GetLastRunTime() { | 341 int GoogleUpdateSettings::GetLastRunTime() { |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 690 UPDATE_POLICIES_COUNT); | 693 UPDATE_POLICIES_COUNT); |
| 691 } | 694 } |
| 692 | 695 |
| 693 base::string16 GoogleUpdateSettings::GetUninstallCommandLine( | 696 base::string16 GoogleUpdateSettings::GetUninstallCommandLine( |
| 694 bool system_install) { | 697 bool system_install) { |
| 695 const HKEY root_key = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | 698 const HKEY root_key = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; |
| 696 base::string16 cmd_line; | 699 base::string16 cmd_line; |
| 697 RegKey update_key; | 700 RegKey update_key; |
| 698 | 701 |
| 699 if (update_key.Open(root_key, google_update::kRegPathGoogleUpdate, | 702 if (update_key.Open(root_key, google_update::kRegPathGoogleUpdate, |
| 700 KEY_QUERY_VALUE) == ERROR_SUCCESS) { | 703 KEY_QUERY_VALUE) == ERROR_SUCCESS) { |
|
grt (UTC plus 2)
2014/06/04 17:20:05
| KEY_WOW64_32KEY
Will Harris
2014/06/04 17:48:07
Good spot. Done.
| |
| 701 update_key.ReadValue(google_update::kRegUninstallCmdLine, &cmd_line); | 704 update_key.ReadValue(google_update::kRegUninstallCmdLine, &cmd_line); |
| 702 } | 705 } |
| 703 | 706 |
| 704 return cmd_line; | 707 return cmd_line; |
| 705 } | 708 } |
| 706 | 709 |
| 707 Version GoogleUpdateSettings::GetGoogleUpdateVersion(bool system_install) { | 710 Version GoogleUpdateSettings::GetGoogleUpdateVersion(bool system_install) { |
| 708 const HKEY root_key = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | 711 const HKEY root_key = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; |
| 709 base::string16 version; | 712 base::string16 version; |
| 710 RegKey key; | 713 RegKey key; |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 871 } | 874 } |
| 872 | 875 |
| 873 // If the key or value was not present, return the empty string. | 876 // If the key or value was not present, return the empty string. |
| 874 if (result == ERROR_FILE_NOT_FOUND || result == ERROR_PATH_NOT_FOUND) { | 877 if (result == ERROR_FILE_NOT_FOUND || result == ERROR_PATH_NOT_FOUND) { |
| 875 experiment_labels->clear(); | 878 experiment_labels->clear(); |
| 876 return true; | 879 return true; |
| 877 } | 880 } |
| 878 | 881 |
| 879 return result == ERROR_SUCCESS; | 882 return result == ERROR_SUCCESS; |
| 880 } | 883 } |
| OLD | NEW |