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

Side by Side Diff: chrome/installer/util/delete_reg_value_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) 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 #include "chrome/installer/util/delete_reg_value_work_item.h" 5 #include "chrome/installer/util/delete_reg_value_work_item.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/win/registry.h" 9 #include "base/win/registry.h"
10 #include "chrome/installer/util/logging_installer.h" 10 #include "chrome/installer/util/logging_installer.h"
(...skipping 11 matching lines...) Expand all
22 status_(DELETE_VALUE), 22 status_(DELETE_VALUE),
23 previous_type_(0) { 23 previous_type_(0) {
24 DCHECK(wow64_access == 0 || 24 DCHECK(wow64_access == 0 ||
25 wow64_access == KEY_WOW64_32KEY || 25 wow64_access == KEY_WOW64_32KEY ||
26 wow64_access == KEY_WOW64_64KEY); 26 wow64_access == KEY_WOW64_64KEY);
27 } 27 }
28 28
29 DeleteRegValueWorkItem::~DeleteRegValueWorkItem() { 29 DeleteRegValueWorkItem::~DeleteRegValueWorkItem() {
30 } 30 }
31 31
32 bool DeleteRegValueWorkItem::Do() { 32 bool DeleteRegValueWorkItem::DoImpl() {
33 if (status_ != DELETE_VALUE) { 33 DCHECK_EQ(DELETE_VALUE, status_);
34 // we already did something.
35 LOG(ERROR) << "multiple calls to Do()";
36 return false;
37 }
38 34
39 status_ = VALUE_UNCHANGED; 35 status_ = VALUE_UNCHANGED;
40 36
41 RegKey key; 37 RegKey key;
42 DWORD type = 0; 38 DWORD type = 0;
43 DWORD size = 0; 39 DWORD size = 0;
44 LONG result = key.Open(predefined_root_, 40 LONG result = key.Open(predefined_root_,
45 key_path_.c_str(), 41 key_path_.c_str(),
46 KEY_READ | KEY_WRITE | wow64_access_); 42 KEY_READ | KEY_WRITE | wow64_access_);
47 if (result == ERROR_SUCCESS) 43 if (result == ERROR_SUCCESS)
48 result = key.ReadValue(value_name_.c_str(), NULL, &size, &type); 44 result = key.ReadValue(value_name_.c_str(), NULL, &size, &type);
49 45
50 if (result == ERROR_FILE_NOT_FOUND) { 46 if (result == ERROR_FILE_NOT_FOUND) {
51 LOG(INFO) << "(delete value) Key: " << key_path_ << " or Value: " 47 VLOG(1) << "(delete value) Key: " << key_path_
52 << value_name_ << " does not exist."; 48 << " or Value: " << value_name_ << " does not exist.";
53 status_ = VALUE_NOT_FOUND; 49 status_ = VALUE_NOT_FOUND;
54 return true; 50 return true;
55 } 51 }
56 52
57 if (result == ERROR_SUCCESS) { 53 if (result == ERROR_SUCCESS) {
58 if (!size) { 54 if (!size) {
59 previous_type_ = type; 55 previous_type_ = type;
60 } else { 56 } else {
61 previous_value_.resize(size); 57 previous_value_.resize(size);
62 result = key.ReadValue(value_name_.c_str(), &previous_value_[0], &size, 58 result = key.ReadValue(value_name_.c_str(), &previous_value_[0], &size,
63 &previous_type_); 59 &previous_type_);
64 if (result != ERROR_SUCCESS) { 60 if (result != ERROR_SUCCESS) {
65 previous_value_.erase(); 61 previous_value_.erase();
66 VLOG(1) << "Failed to save original value. Error: " << result; 62 VLOG(1) << "Failed to save original value. Error: " << result;
67 } 63 }
68 } 64 }
69 } 65 }
70 66
71 result = key.DeleteValue(value_name_.c_str()); 67 result = key.DeleteValue(value_name_.c_str());
72 if (result != ERROR_SUCCESS) { 68 if (result != ERROR_SUCCESS) {
73 VLOG(1) << "Failed to delete value " << value_name_ << " error: " << result; 69 VLOG(1) << "Failed to delete value " << value_name_ << " error: " << result;
74 return false; 70 return false;
75 } 71 }
76 72
77 status_ = VALUE_DELETED; 73 status_ = VALUE_DELETED;
78 return true; 74 return true;
79 } 75 }
80 76
81 void DeleteRegValueWorkItem::Rollback() { 77 void DeleteRegValueWorkItem::RollbackImpl() {
82 if (status_ == DELETE_VALUE || status_ == VALUE_ROLLED_BACK) 78 DCHECK_NE(DELETE_VALUE, status_);
83 return; 79 DCHECK_NE(VALUE_ROLLED_BACK, status_);
80
84 if (status_ == VALUE_UNCHANGED || status_ == VALUE_NOT_FOUND) { 81 if (status_ == VALUE_UNCHANGED || status_ == VALUE_NOT_FOUND) {
85 status_ = VALUE_ROLLED_BACK; 82 status_ = VALUE_ROLLED_BACK;
86 VLOG(1) << "rollback: setting unchanged, nothing to do"; 83 VLOG(1) << "rollback: setting unchanged, nothing to do";
87 return; 84 return;
88 } 85 }
89 86
90 // At this point only possible state is VALUE_DELETED. 87 // At this point only possible state is VALUE_DELETED.
88 DCHECK_EQ(VALUE_DELETED, status_);
89
91 RegKey key; 90 RegKey key;
92 LONG result = key.Open(predefined_root_, 91 LONG result = key.Open(predefined_root_,
93 key_path_.c_str(), 92 key_path_.c_str(),
94 KEY_READ | KEY_WRITE | wow64_access_); 93 KEY_READ | KEY_WRITE | wow64_access_);
95 if (result == ERROR_SUCCESS) { 94 if (result == ERROR_SUCCESS) {
96 // try to restore the previous value 95 // try to restore the previous value
97 DWORD previous_size = static_cast<DWORD>(previous_value_.size()); 96 DWORD previous_size = static_cast<DWORD>(previous_value_.size());
98 const char* previous_value = 97 const char* previous_value =
99 previous_size ? &previous_value_[0] : NULL; 98 previous_size ? &previous_value_[0] : NULL;
100 result = key.WriteValue(value_name_.c_str(), previous_value, 99 result = key.WriteValue(value_name_.c_str(), previous_value,
101 previous_size, previous_type_); 100 previous_size, previous_type_);
102 VLOG_IF(1, result != ERROR_SUCCESS) << "rollback: restoring " 101 VLOG_IF(1, result != ERROR_SUCCESS) << "rollback: restoring "
103 << value_name_ << " error: " << result; 102 << value_name_ << " error: " << result;
104 } else { 103 } else {
105 VLOG(1) << "can not open " << key_path_ << " error: " << result; 104 VLOG(1) << "can not open " << key_path_ << " error: " << result;
106 } 105 }
107 } 106 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698