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
3 // found in the LICENSE file.
5 #include "chrome/installer/util/delete_reg_key_work_item.h"
9 #include "base/logging.h"
10 #include "base/win/registry.h"
11 #include "chrome/installer/util/install_util.h"
13 using base::win::RegKey
;
15 DeleteRegKeyWorkItem::~DeleteRegKeyWorkItem() {
18 DeleteRegKeyWorkItem::DeleteRegKeyWorkItem(HKEY predefined_root
,
19 const std::wstring
& path
,
21 : predefined_root_(predefined_root
),
23 wow64_access_(wow64_access
) {
24 DCHECK(predefined_root
);
25 // It's a safe bet that we don't want to delete one of the root trees.
26 DCHECK(!path
.empty());
27 DCHECK(wow64_access
== 0 ||
28 wow64_access
== KEY_WOW64_32KEY
||
29 wow64_access
== KEY_WOW64_64KEY
);
32 bool DeleteRegKeyWorkItem::Do() {
36 RegistryKeyBackup backup
;
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.";
47 if (!InstallUtil::DeleteRegistryKey(
48 predefined_root_
, path_
.c_str(), wow64_access_
)) {
49 return ignore_failure_
;
52 // We've succeeded, so remember any backup we may have made.
58 void DeleteRegKeyWorkItem::Rollback() {
62 // Delete anything in the key before restoring the backup in case someone else
63 // put new data in the key after Do().
64 InstallUtil::DeleteRegistryKey(predefined_root_
,
68 // Restore the old contents. The restoration takes on its default security
69 // attributes; any custom attributes are lost.
70 if (!backup_
.WriteTo(predefined_root_
, path_
.c_str(), wow64_access_
))
71 LOG(ERROR
) << "Failed to restore key in rollback.";