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

Side by Side Diff: chrome/installer/util/set_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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/set_reg_value_work_item.h" 5 #include "chrome/installer/util/set_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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 wow64_access_(wow64_access), 122 wow64_access_(wow64_access),
123 type_(REG_SZ), 123 type_(REG_SZ),
124 previous_type_(0), 124 previous_type_(0),
125 status_(SET_VALUE) { 125 status_(SET_VALUE) {
126 DCHECK(wow64_access == 0 || 126 DCHECK(wow64_access == 0 ||
127 wow64_access == KEY_WOW64_32KEY || 127 wow64_access == KEY_WOW64_32KEY ||
128 wow64_access == KEY_WOW64_64KEY); 128 wow64_access == KEY_WOW64_64KEY);
129 // Nothing to do, |get_value_callback| will fill |value_| later. 129 // Nothing to do, |get_value_callback| will fill |value_| later.
130 } 130 }
131 131
132 bool SetRegValueWorkItem::Do() { 132 bool SetRegValueWorkItem::DoImpl() {
133 LONG result = ERROR_SUCCESS; 133 DCHECK_EQ(SET_VALUE, status_);
134 base::win::RegKey key;
135 if (status_ != SET_VALUE) {
136 // we already did something.
137 VLOG(1) << "multiple calls to Do()";
138 result = ERROR_CANTWRITE;
139 return ignore_failure_;
140 }
141 134
142 status_ = VALUE_UNCHANGED; 135 status_ = VALUE_UNCHANGED;
143 result = key.Open(predefined_root_, 136
144 key_path_.c_str(), 137 base::win::RegKey key;
145 KEY_READ | KEY_SET_VALUE | wow64_access_); 138 LONG result = key.Open(predefined_root_, key_path_.c_str(),
139 KEY_READ | KEY_SET_VALUE | wow64_access_);
146 if (result != ERROR_SUCCESS) { 140 if (result != ERROR_SUCCESS) {
147 VLOG(1) << "can not open " << key_path_ << " error: " << result; 141 VLOG(1) << "can not open " << key_path_ << " error: " << result;
148 return ignore_failure_; 142 return false;
149 } 143 }
150 144
151 DWORD type = 0; 145 DWORD type = 0;
152 DWORD size = 0; 146 DWORD size = 0;
153 result = key.ReadValue(value_name_.c_str(), NULL, &size, &type); 147 result = key.ReadValue(value_name_.c_str(), NULL, &size, &type);
154 // If the value exists but we don't want to overwrite then there's 148 // If the value exists but we don't want to overwrite then there's
155 // nothing more to do. 149 // nothing more to do.
156 if ((result != ERROR_FILE_NOT_FOUND) && !overwrite_) { 150 if ((result != ERROR_FILE_NOT_FOUND) && !overwrite_) {
157 return true; 151 return true;
158 } 152 }
(...skipping 25 matching lines...) Expand all
184 if (previous_type_ == REG_SZ) 178 if (previous_type_ == REG_SZ)
185 BinaryDataToString(previous_value_, &previous_value_str); 179 BinaryDataToString(previous_value_, &previous_value_str);
186 180
187 StringToBinaryData(get_value_callback_.Run(previous_value_str), &value_); 181 StringToBinaryData(get_value_callback_.Run(previous_value_str), &value_);
188 } 182 }
189 183
190 result = key.WriteValue(value_name_.c_str(), &value_[0], 184 result = key.WriteValue(value_name_.c_str(), &value_[0],
191 static_cast<DWORD>(value_.size()), type_); 185 static_cast<DWORD>(value_.size()), type_);
192 if (result != ERROR_SUCCESS) { 186 if (result != ERROR_SUCCESS) {
193 VLOG(1) << "Failed to write value " << key_path_ << " error: " << result; 187 VLOG(1) << "Failed to write value " << key_path_ << " error: " << result;
194 return ignore_failure_; 188 return false;
195 } 189 }
196 190
197 status_ = previous_type_ ? VALUE_OVERWRITTEN : NEW_VALUE_CREATED; 191 status_ = previous_type_ ? VALUE_OVERWRITTEN : NEW_VALUE_CREATED;
198 return true; 192 return true;
199 } 193 }
200 194
201 void SetRegValueWorkItem::Rollback() { 195 void SetRegValueWorkItem::RollbackImpl() {
202 if (ignore_failure_) 196 DCHECK_NE(SET_VALUE, status_);
203 return; 197 DCHECK_NE(VALUE_ROLL_BACK, status_);
204
205 if (status_ == SET_VALUE || status_ == VALUE_ROLL_BACK)
206 return;
207 198
208 if (status_ == VALUE_UNCHANGED) { 199 if (status_ == VALUE_UNCHANGED) {
209 status_ = VALUE_ROLL_BACK; 200 status_ = VALUE_ROLL_BACK;
210 VLOG(1) << "rollback: setting unchanged, nothing to do"; 201 VLOG(1) << "rollback: setting unchanged, nothing to do";
211 return; 202 return;
212 } 203 }
213 204
214 base::win::RegKey key; 205 base::win::RegKey key;
215 LONG result = key.Open( 206 LONG result = key.Open(
216 predefined_root_, key_path_.c_str(), KEY_SET_VALUE | wow64_access_); 207 predefined_root_, key_path_.c_str(), KEY_SET_VALUE | wow64_access_);
(...skipping 11 matching lines...) Expand all
228 result = key.WriteValue(value_name_.c_str(), previous_value, 219 result = key.WriteValue(value_name_.c_str(), previous_value,
229 static_cast<DWORD>(previous_value_.size()), 220 static_cast<DWORD>(previous_value_.size()),
230 previous_type_); 221 previous_type_);
231 VLOG(1) << "rollback: restoring " << value_name_ << " error: " << result; 222 VLOG(1) << "rollback: restoring " << value_name_ << " error: " << result;
232 } else { 223 } else {
233 NOTREACHED(); 224 NOTREACHED();
234 } 225 }
235 226
236 status_ = VALUE_ROLL_BACK; 227 status_ = VALUE_ROLL_BACK;
237 } 228 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698