Chromium Code Reviews| 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/delete_reg_key_work_item.h" | 5 #include "chrome/installer/util/delete_reg_key_work_item.h" |
| 6 | 6 |
| 7 #include <shlwapi.h> | 7 #include <shlwapi.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/win/registry.h" | 10 #include "base/win/registry.h" |
| 11 #include "chrome/installer/util/install_util.h" | |
| 11 | 12 |
| 12 using base::win::RegKey; | 13 using base::win::RegKey; |
| 13 | 14 |
| 14 DeleteRegKeyWorkItem::~DeleteRegKeyWorkItem() { | 15 DeleteRegKeyWorkItem::~DeleteRegKeyWorkItem() { |
| 15 } | 16 } |
| 16 | 17 |
| 17 DeleteRegKeyWorkItem::DeleteRegKeyWorkItem(HKEY predefined_root, | 18 DeleteRegKeyWorkItem::DeleteRegKeyWorkItem(HKEY predefined_root, |
| 18 const std::wstring& path) | 19 const std::wstring& path, |
| 20 REGSAM wow64_access) | |
| 19 : predefined_root_(predefined_root), | 21 : predefined_root_(predefined_root), |
| 20 path_(path) { | 22 path_(path), |
| 23 wow64_access_(wow64_access) { | |
| 21 DCHECK(predefined_root); | 24 DCHECK(predefined_root); |
| 22 // It's a safe bet that we don't want to delete one of the root trees. | 25 // It's a safe bet that we don't want to delete one of the root trees. |
| 23 DCHECK(!path.empty()); | 26 DCHECK(!path.empty()); |
| 27 DCHECK(wow64_access == 0 || | |
| 28 wow64_access == KEY_WOW64_32KEY || | |
| 29 wow64_access == KEY_WOW64_64KEY); | |
| 24 } | 30 } |
| 25 | 31 |
| 26 bool DeleteRegKeyWorkItem::Do() { | 32 bool DeleteRegKeyWorkItem::Do() { |
| 27 if (path_.empty()) | 33 if (path_.empty()) |
| 28 return false; | 34 return false; |
| 29 | 35 |
| 30 RegistryKeyBackup backup; | 36 RegistryKeyBackup backup; |
| 31 | 37 |
| 32 // Only try to make a backup if we're not configured to ignore failures. | 38 // Only try to make a backup if we're not configured to ignore failures. |
| 33 if (!ignore_failure_) { | 39 if (!ignore_failure_) { |
| 34 if (!backup.Initialize(predefined_root_, path_.c_str())) { | 40 if (!backup.Initialize(predefined_root_, path_.c_str(), wow64_access_)) { |
| 35 LOG(ERROR) << "Failed to backup destination for registry key copy."; | 41 LOG(ERROR) << "Failed to backup destination for registry key copy."; |
| 36 return false; | 42 return false; |
| 37 } | 43 } |
| 38 } | 44 } |
| 39 | 45 |
| 40 // Delete the key. | 46 // Delete the key. |
| 41 LONG result = SHDeleteKey(predefined_root_, path_.c_str()); | 47 if (!InstallUtil::DeleteRegistryKey(predefined_root_, |
| 42 if (result != ERROR_SUCCESS && result != ERROR_FILE_NOT_FOUND) { | 48 path_.c_str(), |
| 43 LOG(ERROR) << "Failed to delete key at " << path_ << ", result: " | 49 wow64_access_)) |
| 44 << result; | |
| 45 return ignore_failure_; | 50 return ignore_failure_; |
|
grt (UTC plus 2)
2014/05/22 22:17:23
did "git cl format" do this? i always thought we n
Will Harris
2014/05/22 22:23:29
git cl format seemed happy with this even with the
| |
| 46 } | |
| 47 | 51 |
| 48 // We've succeeded, so remember any backup we may have made. | 52 // We've succeeded, so remember any backup we may have made. |
| 49 backup_.swap(backup); | 53 backup_.swap(backup); |
| 50 | 54 |
| 51 return true; | 55 return true; |
| 52 } | 56 } |
| 53 | 57 |
| 54 void DeleteRegKeyWorkItem::Rollback() { | 58 void DeleteRegKeyWorkItem::Rollback() { |
| 55 if (ignore_failure_) | 59 if (ignore_failure_) |
| 56 return; | 60 return; |
| 57 | 61 |
| 58 // Delete anything in the key before restoring the backup in case someone else | 62 // Delete anything in the key before restoring the backup in case someone else |
| 59 // put new data in the key after Do(). | 63 // put new data in the key after Do(). |
| 60 LONG result = SHDeleteKey(predefined_root_, path_.c_str()); | 64 InstallUtil::DeleteRegistryKey(predefined_root_, |
| 61 if (result != ERROR_SUCCESS && result != ERROR_FILE_NOT_FOUND) { | 65 path_.c_str(), |
| 62 LOG(ERROR) << "Failed to delete key at " << path_ << " in rollback, " | 66 wow64_access_); |
| 63 "result: " << result; | |
| 64 } | |
| 65 | 67 |
| 66 // Restore the old contents. The restoration takes on its default security | 68 // Restore the old contents. The restoration takes on its default security |
| 67 // attributes; any custom attributes are lost. | 69 // attributes; any custom attributes are lost. |
| 68 if (!backup_.WriteTo(predefined_root_, path_.c_str())) | 70 if (!backup_.WriteTo(predefined_root_, path_.c_str(), wow64_access_)) |
| 69 LOG(ERROR) << "Failed to restore key in rollback."; | 71 LOG(ERROR) << "Failed to restore key in rollback."; |
| 70 } | 72 } |
| OLD | NEW |