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 // See the corresponding header file for description of the functions in this | 5 // See the corresponding header file for description of the functions in this |
| 6 // file. | 6 // file. |
| 7 | 7 |
| 8 #include "chrome/installer/util/install_util.h" | 8 #include "chrome/installer/util/install_util.h" |
| 9 | 9 |
| 10 #include <shellapi.h> | 10 #include <shellapi.h> |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 279 void InstallUtil::AddInstallerResultItems( | 279 void InstallUtil::AddInstallerResultItems( |
| 280 bool system_install, | 280 bool system_install, |
| 281 const base::string16& state_key, | 281 const base::string16& state_key, |
| 282 installer::InstallStatus status, | 282 installer::InstallStatus status, |
| 283 int string_resource_id, | 283 int string_resource_id, |
| 284 const base::string16* const launch_cmd, | 284 const base::string16* const launch_cmd, |
| 285 WorkItemList* install_list) { | 285 WorkItemList* install_list) { |
| 286 DCHECK(install_list); | 286 DCHECK(install_list); |
| 287 const HKEY root = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | 287 const HKEY root = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; |
| 288 DWORD installer_result = (GetInstallReturnCode(status) == 0) ? 0 : 1; | 288 DWORD installer_result = (GetInstallReturnCode(status) == 0) ? 0 : 1; |
| 289 install_list->AddCreateRegKeyWorkItem(root, state_key); | 289 install_list->AddCreateRegKeyWorkItem( |
| 290 install_list->AddSetRegValueWorkItem(root, state_key, | 290 root, state_key, WorkItem::kWow64Default); |
| 291 install_list->AddSetRegValueWorkItem(root, | |
| 292 state_key, | |
| 291 installer::kInstallerResult, | 293 installer::kInstallerResult, |
| 292 installer_result, true); | 294 installer_result, |
| 293 install_list->AddSetRegValueWorkItem(root, state_key, | 295 true, |
| 296 WorkItem::kWow64Default); | |
| 297 install_list->AddSetRegValueWorkItem(root, | |
| 298 state_key, | |
| 294 installer::kInstallerError, | 299 installer::kInstallerError, |
| 295 static_cast<DWORD>(status), true); | 300 static_cast<DWORD>(status), |
| 301 true, | |
| 302 WorkItem::kWow64Default); | |
| 296 if (string_resource_id != 0) { | 303 if (string_resource_id != 0) { |
| 297 base::string16 msg = installer::GetLocalizedString(string_resource_id); | 304 base::string16 msg = installer::GetLocalizedString(string_resource_id); |
| 298 install_list->AddSetRegValueWorkItem(root, state_key, | 305 install_list->AddSetRegValueWorkItem(root, |
| 299 installer::kInstallerResultUIString, msg, true); | 306 state_key, |
| 307 installer::kInstallerResultUIString, | |
| 308 msg, | |
| 309 true, | |
| 310 WorkItem::kWow64Default); | |
| 300 } | 311 } |
| 301 if (launch_cmd != NULL && !launch_cmd->empty()) { | 312 if (launch_cmd != NULL && !launch_cmd->empty()) { |
| 302 install_list->AddSetRegValueWorkItem(root, state_key, | 313 install_list->AddSetRegValueWorkItem( |
| 303 installer::kInstallerSuccessLaunchCmdLine, *launch_cmd, true); | 314 root, |
| 315 state_key, | |
| 316 installer::kInstallerSuccessLaunchCmdLine, | |
| 317 *launch_cmd, | |
| 318 true, | |
| 319 WorkItem::kWow64Default); | |
| 304 } | 320 } |
| 305 } | 321 } |
| 306 | 322 |
| 307 void InstallUtil::UpdateInstallerStage(bool system_install, | 323 void InstallUtil::UpdateInstallerStage(bool system_install, |
| 308 const base::string16& state_key_path, | 324 const base::string16& state_key_path, |
| 309 installer::InstallerStage stage) { | 325 installer::InstallerStage stage) { |
| 310 DCHECK_LE(static_cast<installer::InstallerStage>(0), stage); | 326 DCHECK_LE(static_cast<installer::InstallerStage>(0), stage); |
| 311 DCHECK_GT(installer::NUM_STAGES, stage); | 327 DCHECK_GT(installer::NUM_STAGES, stage); |
| 312 const HKEY root = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | 328 const HKEY root = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; |
| 313 RegKey state_key; | 329 RegKey state_key; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 410 | 426 |
| 411 // static | 427 // static |
| 412 bool InstallUtil::GetEULASentinelFilePath(base::FilePath* path) { | 428 bool InstallUtil::GetEULASentinelFilePath(base::FilePath* path) { |
| 413 base::FilePath user_data_dir; | 429 base::FilePath user_data_dir; |
| 414 if (!PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)) | 430 if (!PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)) |
| 415 return false; | 431 return false; |
| 416 *path = user_data_dir.Append(installer::kEULASentinelFile); | 432 *path = user_data_dir.Append(installer::kEULASentinelFile); |
| 417 return true; | 433 return true; |
| 418 } | 434 } |
| 419 | 435 |
| 420 // This method tries to delete a registry key and logs an error message | 436 // Deletes the registry key at path key_path under the key given by root_key. |
| 421 // in case of failure. It returns true if deletion is successful (or the key did | 437 LONG InstallUtil::DeleteRegistryKey(HKEY root_key, |
|
grt (UTC plus 2)
2014/05/21 16:41:05
previously, this would return true for both succes
Will Harris
2014/05/21 23:23:16
I changed this since it was used by the new code i
grt (UTC plus 2)
2014/05/22 01:37:44
Does it? I could be reading it wrong, but modulo t
Will Harris
2014/05/22 21:29:24
Done.
| |
| 422 // not exist), otherwise false. | 438 const base::string16& key_path, |
| 423 bool InstallUtil::DeleteRegistryKey(HKEY root_key, | 439 REGSAM wow64_access) { |
| 424 const base::string16& key_path) { | 440 RegKey root_regkey; |
| 425 VLOG(1) << "Deleting registry key " << key_path; | 441 LONG result = root_regkey.Open(root_key, L"", |
| 426 LONG result = ::SHDeleteKey(root_key, key_path.c_str()); | 442 KEY_READ | KEY_WRITE | wow64_access); |
| 427 if (result != ERROR_SUCCESS && result != ERROR_FILE_NOT_FOUND) { | 443 if (result != ERROR_SUCCESS) |
| 428 LOG(ERROR) << "Failed to delete registry key: " << key_path | 444 return result; |
| 429 << " error: " << result; | 445 return root_regkey.DeleteKey(key_path.c_str()); |
| 430 return false; | |
| 431 } | |
| 432 return true; | |
| 433 } | 446 } |
| 434 | 447 |
| 435 // This method tries to delete a registry value and logs an error message | 448 // This method tries to delete a registry value and logs an error message |
| 436 // in case of failure. It returns true if deletion is successful (or the key did | 449 // in case of failure. It returns true if deletion is successful (or the key did |
| 437 // not exist), otherwise false. | 450 // not exist), otherwise false. |
| 438 bool InstallUtil::DeleteRegistryValue(HKEY reg_root, | 451 bool InstallUtil::DeleteRegistryValue(HKEY reg_root, |
| 439 const base::string16& key_path, | 452 const base::string16& key_path, |
| 440 const base::string16& value_name) { | 453 const base::string16& value_name) { |
| 441 RegKey key; | 454 RegKey key; |
| 442 LONG result = key.Open(reg_root, key_path.c_str(), KEY_SET_VALUE); | 455 LONG result = key.Open(reg_root, key_path.c_str(), KEY_SET_VALUE); |
| 443 if (result == ERROR_SUCCESS) | 456 if (result == ERROR_SUCCESS) |
| 444 result = key.DeleteValue(value_name.c_str()); | 457 result = key.DeleteValue(value_name.c_str()); |
| 445 if (result != ERROR_SUCCESS && result != ERROR_FILE_NOT_FOUND) { | 458 if (result != ERROR_SUCCESS && result != ERROR_FILE_NOT_FOUND) { |
| 446 LOG(ERROR) << "Failed to delete registry value: " << value_name | 459 LOG(ERROR) << "Failed to delete registry value: " << value_name |
| 447 << " error: " << result; | 460 << " error: " << result; |
| 448 return false; | 461 return false; |
| 449 } | 462 } |
| 450 return true; | 463 return true; |
| 451 } | 464 } |
| 452 | 465 |
| 453 // static | 466 // static |
| 454 InstallUtil::ConditionalDeleteResult InstallUtil::DeleteRegistryKeyIf( | 467 InstallUtil::ConditionalDeleteResult InstallUtil::DeleteRegistryKeyIf( |
| 455 HKEY root_key, | 468 HKEY root_key, |
| 456 const base::string16& key_to_delete_path, | 469 const base::string16& key_to_delete_path, |
| 457 const base::string16& key_to_test_path, | 470 const base::string16& key_to_test_path, |
| 458 const wchar_t* value_name, | 471 const wchar_t* value_name, |
| 459 const RegistryValuePredicate& predicate) { | 472 const RegistryValuePredicate& predicate, |
| 473 const REGSAM wow64_access) { | |
| 460 DCHECK(root_key); | 474 DCHECK(root_key); |
| 461 ConditionalDeleteResult delete_result = NOT_FOUND; | 475 ConditionalDeleteResult delete_result = NOT_FOUND; |
| 462 RegKey key; | 476 RegKey key; |
| 463 base::string16 actual_value; | 477 base::string16 actual_value; |
| 464 if (key.Open(root_key, key_to_test_path.c_str(), | 478 if (key.Open(root_key, key_to_test_path.c_str(), |
| 465 KEY_QUERY_VALUE) == ERROR_SUCCESS && | 479 KEY_QUERY_VALUE) == ERROR_SUCCESS && |
| 466 key.ReadValue(value_name, &actual_value) == ERROR_SUCCESS && | 480 key.ReadValue(value_name, &actual_value) == ERROR_SUCCESS && |
| 467 predicate.Evaluate(actual_value)) { | 481 predicate.Evaluate(actual_value)) { |
| 468 key.Close(); | 482 key.Close(); |
| 469 delete_result = DeleteRegistryKey(root_key, key_to_delete_path) | 483 LONG result = DeleteRegistryKey(root_key, key_to_delete_path, wow64_access); |
| 484 delete_result = (result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND) | |
| 470 ? DELETED : DELETE_FAILED; | 485 ? DELETED : DELETE_FAILED; |
| 471 } | 486 } |
| 472 return delete_result; | 487 return delete_result; |
| 473 } | 488 } |
| 474 | 489 |
| 475 // static | 490 // static |
| 476 InstallUtil::ConditionalDeleteResult InstallUtil::DeleteRegistryValueIf( | 491 InstallUtil::ConditionalDeleteResult InstallUtil::DeleteRegistryValueIf( |
| 477 HKEY root_key, | 492 HKEY root_key, |
| 478 const wchar_t* key_path, | 493 const wchar_t* key_path, |
| 479 const wchar_t* value_name, | 494 const wchar_t* value_name, |
| 480 const RegistryValuePredicate& predicate) { | 495 const RegistryValuePredicate& predicate, |
| 496 REGSAM wow64_access) { | |
| 481 DCHECK(root_key); | 497 DCHECK(root_key); |
| 482 DCHECK(key_path); | 498 DCHECK(key_path); |
| 483 ConditionalDeleteResult delete_result = NOT_FOUND; | 499 ConditionalDeleteResult delete_result = NOT_FOUND; |
| 484 RegKey key; | 500 RegKey key; |
| 485 base::string16 actual_value; | 501 base::string16 actual_value; |
| 486 if (key.Open(root_key, key_path, | 502 if (key.Open(root_key, key_path, |
| 487 KEY_QUERY_VALUE | KEY_SET_VALUE) == ERROR_SUCCESS && | 503 KEY_QUERY_VALUE | KEY_SET_VALUE | wow64_access) |
| 504 == ERROR_SUCCESS && | |
| 488 key.ReadValue(value_name, &actual_value) == ERROR_SUCCESS && | 505 key.ReadValue(value_name, &actual_value) == ERROR_SUCCESS && |
| 489 predicate.Evaluate(actual_value)) { | 506 predicate.Evaluate(actual_value)) { |
| 490 LONG result = key.DeleteValue(value_name); | 507 LONG result = key.DeleteValue(value_name); |
| 491 if (result != ERROR_SUCCESS) { | 508 if (result != ERROR_SUCCESS) { |
| 492 LOG(ERROR) << "Failed to delete registry value: " | 509 LOG(ERROR) << "Failed to delete registry value: " |
| 493 << (value_name ? value_name : L"(Default)") | 510 << (value_name ? value_name : L"(Default)") |
| 494 << " error: " << result; | 511 << " error: " << result; |
| 495 delete_result = DELETE_FAILED; | 512 delete_result = DELETE_FAILED; |
| 496 } | 513 } |
| 497 delete_result = DELETED; | 514 delete_result = DELETED; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 604 // Open the program and see if it references the expected file. | 621 // Open the program and see if it references the expected file. |
| 605 base::File file; | 622 base::File file; |
| 606 BY_HANDLE_FILE_INFORMATION info = {}; | 623 BY_HANDLE_FILE_INFORMATION info = {}; |
| 607 | 624 |
| 608 return (OpenForInfo(path, &file) && | 625 return (OpenForInfo(path, &file) && |
| 609 GetInfo(file, &info) && | 626 GetInfo(file, &info) && |
| 610 info.dwVolumeSerialNumber == file_info_.dwVolumeSerialNumber && | 627 info.dwVolumeSerialNumber == file_info_.dwVolumeSerialNumber && |
| 611 info.nFileIndexHigh == file_info_.nFileIndexHigh && | 628 info.nFileIndexHigh == file_info_.nFileIndexHigh && |
| 612 info.nFileIndexLow == file_info_.nFileIndexLow); | 629 info.nFileIndexLow == file_info_.nFileIndexLow); |
| 613 } | 630 } |
| OLD | NEW |