| OLD | NEW |
| 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 Loading... |
| 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::DoImpl() { | 132 bool SetRegValueWorkItem::Do() { |
| 133 DCHECK_EQ(SET_VALUE, status_); | 133 LONG result = ERROR_SUCCESS; |
| 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 } |
| 134 | 141 |
| 135 status_ = VALUE_UNCHANGED; | 142 status_ = VALUE_UNCHANGED; |
| 136 | 143 result = key.Open(predefined_root_, |
| 137 base::win::RegKey key; | 144 key_path_.c_str(), |
| 138 LONG result = key.Open(predefined_root_, key_path_.c_str(), | 145 KEY_READ | KEY_SET_VALUE | wow64_access_); |
| 139 KEY_READ | KEY_SET_VALUE | wow64_access_); | |
| 140 if (result != ERROR_SUCCESS) { | 146 if (result != ERROR_SUCCESS) { |
| 141 VLOG(1) << "can not open " << key_path_ << " error: " << result; | 147 VLOG(1) << "can not open " << key_path_ << " error: " << result; |
| 142 return false; | 148 return ignore_failure_; |
| 143 } | 149 } |
| 144 | 150 |
| 145 DWORD type = 0; | 151 DWORD type = 0; |
| 146 DWORD size = 0; | 152 DWORD size = 0; |
| 147 result = key.ReadValue(value_name_.c_str(), NULL, &size, &type); | 153 result = key.ReadValue(value_name_.c_str(), NULL, &size, &type); |
| 148 // If the value exists but we don't want to overwrite then there's | 154 // If the value exists but we don't want to overwrite then there's |
| 149 // nothing more to do. | 155 // nothing more to do. |
| 150 if ((result != ERROR_FILE_NOT_FOUND) && !overwrite_) { | 156 if ((result != ERROR_FILE_NOT_FOUND) && !overwrite_) { |
| 151 return true; | 157 return true; |
| 152 } | 158 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 178 if (previous_type_ == REG_SZ) | 184 if (previous_type_ == REG_SZ) |
| 179 BinaryDataToString(previous_value_, &previous_value_str); | 185 BinaryDataToString(previous_value_, &previous_value_str); |
| 180 | 186 |
| 181 StringToBinaryData(get_value_callback_.Run(previous_value_str), &value_); | 187 StringToBinaryData(get_value_callback_.Run(previous_value_str), &value_); |
| 182 } | 188 } |
| 183 | 189 |
| 184 result = key.WriteValue(value_name_.c_str(), &value_[0], | 190 result = key.WriteValue(value_name_.c_str(), &value_[0], |
| 185 static_cast<DWORD>(value_.size()), type_); | 191 static_cast<DWORD>(value_.size()), type_); |
| 186 if (result != ERROR_SUCCESS) { | 192 if (result != ERROR_SUCCESS) { |
| 187 VLOG(1) << "Failed to write value " << key_path_ << " error: " << result; | 193 VLOG(1) << "Failed to write value " << key_path_ << " error: " << result; |
| 188 return false; | 194 return ignore_failure_; |
| 189 } | 195 } |
| 190 | 196 |
| 191 status_ = previous_type_ ? VALUE_OVERWRITTEN : NEW_VALUE_CREATED; | 197 status_ = previous_type_ ? VALUE_OVERWRITTEN : NEW_VALUE_CREATED; |
| 192 return true; | 198 return true; |
| 193 } | 199 } |
| 194 | 200 |
| 195 void SetRegValueWorkItem::RollbackImpl() { | 201 void SetRegValueWorkItem::Rollback() { |
| 196 DCHECK_NE(SET_VALUE, status_); | 202 if (ignore_failure_) |
| 197 DCHECK_NE(VALUE_ROLL_BACK, status_); | 203 return; |
| 204 |
| 205 if (status_ == SET_VALUE || status_ == VALUE_ROLL_BACK) |
| 206 return; |
| 198 | 207 |
| 199 if (status_ == VALUE_UNCHANGED) { | 208 if (status_ == VALUE_UNCHANGED) { |
| 200 status_ = VALUE_ROLL_BACK; | 209 status_ = VALUE_ROLL_BACK; |
| 201 VLOG(1) << "rollback: setting unchanged, nothing to do"; | 210 VLOG(1) << "rollback: setting unchanged, nothing to do"; |
| 202 return; | 211 return; |
| 203 } | 212 } |
| 204 | 213 |
| 205 base::win::RegKey key; | 214 base::win::RegKey key; |
| 206 LONG result = key.Open( | 215 LONG result = key.Open( |
| 207 predefined_root_, key_path_.c_str(), KEY_SET_VALUE | wow64_access_); | 216 predefined_root_, key_path_.c_str(), KEY_SET_VALUE | wow64_access_); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 219 result = key.WriteValue(value_name_.c_str(), previous_value, | 228 result = key.WriteValue(value_name_.c_str(), previous_value, |
| 220 static_cast<DWORD>(previous_value_.size()), | 229 static_cast<DWORD>(previous_value_.size()), |
| 221 previous_type_); | 230 previous_type_); |
| 222 VLOG(1) << "rollback: restoring " << value_name_ << " error: " << result; | 231 VLOG(1) << "rollback: restoring " << value_name_ << " error: " << result; |
| 223 } else { | 232 } else { |
| 224 NOTREACHED(); | 233 NOTREACHED(); |
| 225 } | 234 } |
| 226 | 235 |
| 227 status_ = VALUE_ROLL_BACK; | 236 status_ = VALUE_ROLL_BACK; |
| 228 } | 237 } |
| OLD | NEW |