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" |
(...skipping 11 matching lines...) Expand all Loading... |
22 path_(path), | 22 path_(path), |
23 wow64_access_(wow64_access) { | 23 wow64_access_(wow64_access) { |
24 DCHECK(predefined_root); | 24 DCHECK(predefined_root); |
25 // 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. |
26 DCHECK(!path.empty()); | 26 DCHECK(!path.empty()); |
27 DCHECK(wow64_access == 0 || | 27 DCHECK(wow64_access == 0 || |
28 wow64_access == KEY_WOW64_32KEY || | 28 wow64_access == KEY_WOW64_32KEY || |
29 wow64_access == KEY_WOW64_64KEY); | 29 wow64_access == KEY_WOW64_64KEY); |
30 } | 30 } |
31 | 31 |
32 bool DeleteRegKeyWorkItem::DoImpl() { | 32 bool DeleteRegKeyWorkItem::Do() { |
33 DCHECK(!backup_initialized_); | |
34 | |
35 if (path_.empty()) | 33 if (path_.empty()) |
36 return false; | 34 return false; |
37 | 35 |
38 // Only try to make a backup if rollback is enabled. | 36 RegistryKeyBackup backup; |
39 if (rollback_enabled()) { | 37 |
40 if (!backup_.Initialize(predefined_root_, path_.c_str(), wow64_access_)) { | 38 // Only try to make a backup if we're not configured to ignore failures. |
| 39 if (!ignore_failure_) { |
| 40 if (!backup.Initialize(predefined_root_, path_.c_str(), wow64_access_)) { |
41 LOG(ERROR) << "Failed to backup destination for registry key copy."; | 41 LOG(ERROR) << "Failed to backup destination for registry key copy."; |
42 return false; | 42 return false; |
43 } | 43 } |
44 backup_initialized_ = true; | |
45 } | 44 } |
46 | 45 |
47 // Delete the key. | 46 // Delete the key. |
48 if (!InstallUtil::DeleteRegistryKey( | 47 if (!InstallUtil::DeleteRegistryKey( |
49 predefined_root_, path_.c_str(), wow64_access_)) { | 48 predefined_root_, path_.c_str(), wow64_access_)) { |
50 return false; | 49 return ignore_failure_; |
51 } | 50 } |
52 | 51 |
| 52 // We've succeeded, so remember any backup we may have made. |
| 53 backup_.swap(backup); |
| 54 |
53 return true; | 55 return true; |
54 } | 56 } |
55 | 57 |
56 void DeleteRegKeyWorkItem::RollbackImpl() { | 58 void DeleteRegKeyWorkItem::Rollback() { |
57 if (!backup_initialized_) | 59 if (ignore_failure_) |
58 return; | 60 return; |
59 | 61 |
60 // 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 |
61 // put new data in the key after Do(). | 63 // put new data in the key after Do(). |
62 InstallUtil::DeleteRegistryKey(predefined_root_, | 64 InstallUtil::DeleteRegistryKey(predefined_root_, |
63 path_.c_str(), | 65 path_.c_str(), |
64 wow64_access_); | 66 wow64_access_); |
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(), wow64_access_)) | 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 |