| 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, |
| 293 WorkItem::kWow64Default, |
| 291 installer::kInstallerResult, | 294 installer::kInstallerResult, |
| 292 installer_result, true); | 295 installer_result, |
| 293 install_list->AddSetRegValueWorkItem(root, state_key, | 296 true); |
| 297 install_list->AddSetRegValueWorkItem(root, |
| 298 state_key, |
| 299 WorkItem::kWow64Default, |
| 294 installer::kInstallerError, | 300 installer::kInstallerError, |
| 295 static_cast<DWORD>(status), true); | 301 static_cast<DWORD>(status), |
| 302 true); |
| 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 WorkItem::kWow64Default, |
| 308 installer::kInstallerResultUIString, |
| 309 msg, |
| 310 true); |
| 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 WorkItem::kWow64Default, |
| 317 installer::kInstallerSuccessLaunchCmdLine, |
| 318 *launch_cmd, |
| 319 true); |
| 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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 // This method tries to delete a registry key and logs an error message |
| 421 // in case of failure. It returns true if deletion is successful (or the key did | 437 // in case of failure. It returns true if deletion is successful (or the key did |
| 422 // not exist), otherwise false. | 438 // not exist), otherwise false. |
| 423 bool InstallUtil::DeleteRegistryKey(HKEY root_key, | 439 bool InstallUtil::DeleteRegistryKey(HKEY root_key, |
| 424 const base::string16& key_path) { | 440 const base::string16& key_path, |
| 441 REGSAM wow64_access) { |
| 425 VLOG(1) << "Deleting registry key " << key_path; | 442 VLOG(1) << "Deleting registry key " << key_path; |
| 426 LONG result = ::SHDeleteKey(root_key, key_path.c_str()); | 443 RegKey target_key; |
| 427 if (result != ERROR_SUCCESS && result != ERROR_FILE_NOT_FOUND) { | 444 LONG result = target_key.Open(root_key, key_path.c_str(), |
| 445 KEY_READ | KEY_WRITE | wow64_access); |
| 446 |
| 447 if (result == ERROR_FILE_NOT_FOUND) |
| 448 return true; |
| 449 |
| 450 if (result == ERROR_SUCCESS) |
| 451 result = target_key.DeleteKey(L""); |
| 452 |
| 453 if (result != ERROR_SUCCESS) { |
| 428 LOG(ERROR) << "Failed to delete registry key: " << key_path | 454 LOG(ERROR) << "Failed to delete registry key: " << key_path |
| 429 << " error: " << result; | 455 << " error: " << result; |
| 430 return false; | 456 return false; |
| 431 } | 457 } |
| 432 return true; | 458 return true; |
| 433 } | 459 } |
| 434 | 460 |
| 435 // This method tries to delete a registry value and logs an error message | 461 // 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 | 462 // in case of failure. It returns true if deletion is successful (or the key did |
| 437 // not exist), otherwise false. | 463 // not exist), otherwise false. |
| 438 bool InstallUtil::DeleteRegistryValue(HKEY reg_root, | 464 bool InstallUtil::DeleteRegistryValue(HKEY reg_root, |
| 439 const base::string16& key_path, | 465 const base::string16& key_path, |
| 466 REGSAM wow64_access, |
| 440 const base::string16& value_name) { | 467 const base::string16& value_name) { |
| 441 RegKey key; | 468 RegKey key; |
| 442 LONG result = key.Open(reg_root, key_path.c_str(), KEY_SET_VALUE); | 469 LONG result = key.Open(reg_root, key_path.c_str(), |
| 470 KEY_SET_VALUE | wow64_access); |
| 443 if (result == ERROR_SUCCESS) | 471 if (result == ERROR_SUCCESS) |
| 444 result = key.DeleteValue(value_name.c_str()); | 472 result = key.DeleteValue(value_name.c_str()); |
| 445 if (result != ERROR_SUCCESS && result != ERROR_FILE_NOT_FOUND) { | 473 if (result != ERROR_SUCCESS && result != ERROR_FILE_NOT_FOUND) { |
| 446 LOG(ERROR) << "Failed to delete registry value: " << value_name | 474 LOG(ERROR) << "Failed to delete registry value: " << value_name |
| 447 << " error: " << result; | 475 << " error: " << result; |
| 448 return false; | 476 return false; |
| 449 } | 477 } |
| 450 return true; | 478 return true; |
| 451 } | 479 } |
| 452 | 480 |
| 453 // static | 481 // static |
| 454 InstallUtil::ConditionalDeleteResult InstallUtil::DeleteRegistryKeyIf( | 482 InstallUtil::ConditionalDeleteResult InstallUtil::DeleteRegistryKeyIf( |
| 455 HKEY root_key, | 483 HKEY root_key, |
| 456 const base::string16& key_to_delete_path, | 484 const base::string16& key_to_delete_path, |
| 457 const base::string16& key_to_test_path, | 485 const base::string16& key_to_test_path, |
| 486 const REGSAM wow64_access, |
| 458 const wchar_t* value_name, | 487 const wchar_t* value_name, |
| 459 const RegistryValuePredicate& predicate) { | 488 const RegistryValuePredicate& predicate) { |
| 460 DCHECK(root_key); | 489 DCHECK(root_key); |
| 461 ConditionalDeleteResult delete_result = NOT_FOUND; | 490 ConditionalDeleteResult delete_result = NOT_FOUND; |
| 462 RegKey key; | 491 RegKey key; |
| 463 base::string16 actual_value; | 492 base::string16 actual_value; |
| 464 if (key.Open(root_key, key_to_test_path.c_str(), | 493 if (key.Open(root_key, key_to_test_path.c_str(), |
| 465 KEY_QUERY_VALUE) == ERROR_SUCCESS && | 494 KEY_QUERY_VALUE | wow64_access) == ERROR_SUCCESS && |
| 466 key.ReadValue(value_name, &actual_value) == ERROR_SUCCESS && | 495 key.ReadValue(value_name, &actual_value) == ERROR_SUCCESS && |
| 467 predicate.Evaluate(actual_value)) { | 496 predicate.Evaluate(actual_value)) { |
| 468 key.Close(); | 497 key.Close(); |
| 469 delete_result = DeleteRegistryKey(root_key, key_to_delete_path) | 498 delete_result = DeleteRegistryKey(root_key, |
| 499 key_to_delete_path, |
| 500 wow64_access) |
| 470 ? DELETED : DELETE_FAILED; | 501 ? DELETED : DELETE_FAILED; |
| 471 } | 502 } |
| 472 return delete_result; | 503 return delete_result; |
| 473 } | 504 } |
| 474 | 505 |
| 475 // static | 506 // static |
| 476 InstallUtil::ConditionalDeleteResult InstallUtil::DeleteRegistryValueIf( | 507 InstallUtil::ConditionalDeleteResult InstallUtil::DeleteRegistryValueIf( |
| 477 HKEY root_key, | 508 HKEY root_key, |
| 478 const wchar_t* key_path, | 509 const wchar_t* key_path, |
| 510 REGSAM wow64_access, |
| 479 const wchar_t* value_name, | 511 const wchar_t* value_name, |
| 480 const RegistryValuePredicate& predicate) { | 512 const RegistryValuePredicate& predicate) { |
| 481 DCHECK(root_key); | 513 DCHECK(root_key); |
| 482 DCHECK(key_path); | 514 DCHECK(key_path); |
| 483 ConditionalDeleteResult delete_result = NOT_FOUND; | 515 ConditionalDeleteResult delete_result = NOT_FOUND; |
| 484 RegKey key; | 516 RegKey key; |
| 485 base::string16 actual_value; | 517 base::string16 actual_value; |
| 486 if (key.Open(root_key, key_path, | 518 if (key.Open(root_key, key_path, |
| 487 KEY_QUERY_VALUE | KEY_SET_VALUE) == ERROR_SUCCESS && | 519 KEY_QUERY_VALUE | KEY_SET_VALUE | wow64_access) |
| 520 == ERROR_SUCCESS && |
| 488 key.ReadValue(value_name, &actual_value) == ERROR_SUCCESS && | 521 key.ReadValue(value_name, &actual_value) == ERROR_SUCCESS && |
| 489 predicate.Evaluate(actual_value)) { | 522 predicate.Evaluate(actual_value)) { |
| 490 LONG result = key.DeleteValue(value_name); | 523 LONG result = key.DeleteValue(value_name); |
| 491 if (result != ERROR_SUCCESS) { | 524 if (result != ERROR_SUCCESS) { |
| 492 LOG(ERROR) << "Failed to delete registry value: " | 525 LOG(ERROR) << "Failed to delete registry value: " |
| 493 << (value_name ? value_name : L"(Default)") | 526 << (value_name ? value_name : L"(Default)") |
| 494 << " error: " << result; | 527 << " error: " << result; |
| 495 delete_result = DELETE_FAILED; | 528 delete_result = DELETE_FAILED; |
| 496 } | 529 } |
| 497 delete_result = DELETED; | 530 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. | 637 // Open the program and see if it references the expected file. |
| 605 base::File file; | 638 base::File file; |
| 606 BY_HANDLE_FILE_INFORMATION info = {}; | 639 BY_HANDLE_FILE_INFORMATION info = {}; |
| 607 | 640 |
| 608 return (OpenForInfo(path, &file) && | 641 return (OpenForInfo(path, &file) && |
| 609 GetInfo(file, &info) && | 642 GetInfo(file, &info) && |
| 610 info.dwVolumeSerialNumber == file_info_.dwVolumeSerialNumber && | 643 info.dwVolumeSerialNumber == file_info_.dwVolumeSerialNumber && |
| 611 info.nFileIndexHigh == file_info_.nFileIndexHigh && | 644 info.nFileIndexHigh == file_info_.nFileIndexHigh && |
| 612 info.nFileIndexLow == file_info_.nFileIndexLow); | 645 info.nFileIndexLow == file_info_.nFileIndexLow); |
| 613 } | 646 } |
| OLD | NEW |