Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Side by Side Diff: chrome/installer/util/delete_reg_key_work_item.cc

Issue 1882923003: Add best-effort/allow rollback flags on WorkItem. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@simple_list_tests
Patch Set: fix build error Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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::Do() { 32 bool DeleteRegKeyWorkItem::DoImpl() {
33 DCHECK(!backup_initialized_);
34
33 if (path_.empty()) 35 if (path_.empty())
34 return false; 36 return false;
35 37
36 RegistryKeyBackup backup; 38 // Only try to make a backup if rollback is enabled.
37 39 if (rollback_enabled()) {
38 // Only try to make a backup if we're not configured to ignore failures. 40 if (!backup_.Initialize(predefined_root_, path_.c_str(), wow64_access_)) {
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;
44 } 45 }
45 46
46 // Delete the key. 47 // Delete the key.
47 if (!InstallUtil::DeleteRegistryKey( 48 if (!InstallUtil::DeleteRegistryKey(
48 predefined_root_, path_.c_str(), wow64_access_)) { 49 predefined_root_, path_.c_str(), wow64_access_)) {
49 return ignore_failure_; 50 return false;
50 } 51 }
51 52
52 // We've succeeded, so remember any backup we may have made.
53 backup_.swap(backup);
54
55 return true; 53 return true;
56 } 54 }
57 55
58 void DeleteRegKeyWorkItem::Rollback() { 56 void DeleteRegKeyWorkItem::RollbackImpl() {
59 if (ignore_failure_) 57 if (!backup_initialized_)
60 return; 58 return;
61 59
62 // Delete anything in the key before restoring the backup in case someone else 60 // Delete anything in the key before restoring the backup in case someone else
63 // put new data in the key after Do(). 61 // put new data in the key after Do().
64 InstallUtil::DeleteRegistryKey(predefined_root_, 62 InstallUtil::DeleteRegistryKey(predefined_root_,
65 path_.c_str(), 63 path_.c_str(),
66 wow64_access_); 64 wow64_access_);
67 65
68 // Restore the old contents. The restoration takes on its default security 66 // Restore the old contents. The restoration takes on its default security
69 // attributes; any custom attributes are lost. 67 // attributes; any custom attributes are lost.
70 if (!backup_.WriteTo(predefined_root_, path_.c_str(), wow64_access_)) 68 if (!backup_.WriteTo(predefined_root_, path_.c_str(), wow64_access_))
71 LOG(ERROR) << "Failed to restore key in rollback."; 69 LOG(ERROR) << "Failed to restore key in rollback.";
72 } 70 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698