OLD | NEW |
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" |
11 | 11 |
12 using base::win::RegKey; | 12 using base::win::RegKey; |
13 | 13 |
14 DeleteRegValueWorkItem::DeleteRegValueWorkItem(HKEY predefined_root, | 14 DeleteRegValueWorkItem::DeleteRegValueWorkItem(HKEY predefined_root, |
15 const std::wstring& key_path, | 15 const std::wstring& key_path, |
| 16 REGSAM wow64_access, |
16 const std::wstring& value_name) | 17 const std::wstring& value_name) |
17 : predefined_root_(predefined_root), | 18 : predefined_root_(predefined_root), |
18 key_path_(key_path), | 19 key_path_(key_path), |
19 value_name_(value_name), | 20 value_name_(value_name), |
| 21 wow64_access_(wow64_access), |
20 previous_type_(0), | 22 previous_type_(0), |
21 status_(DELETE_VALUE) { | 23 status_(DELETE_VALUE) { |
| 24 DCHECK(wow64_access == 0 || |
| 25 wow64_access == KEY_WOW64_32KEY || |
| 26 wow64_access == KEY_WOW64_64KEY); |
22 } | 27 } |
23 | 28 |
24 DeleteRegValueWorkItem::~DeleteRegValueWorkItem() { | 29 DeleteRegValueWorkItem::~DeleteRegValueWorkItem() { |
25 } | 30 } |
26 | 31 |
27 bool DeleteRegValueWorkItem::Do() { | 32 bool DeleteRegValueWorkItem::Do() { |
28 if (status_ != DELETE_VALUE) { | 33 if (status_ != DELETE_VALUE) { |
29 // we already did something. | 34 // we already did something. |
30 LOG(ERROR) << "multiple calls to Do()"; | 35 LOG(ERROR) << "multiple calls to Do()"; |
31 return false; | 36 return false; |
32 } | 37 } |
33 | 38 |
34 status_ = VALUE_UNCHANGED; | 39 status_ = VALUE_UNCHANGED; |
35 | 40 |
36 RegKey key; | 41 RegKey key; |
37 DWORD type = 0; | 42 DWORD type = 0; |
38 DWORD size = 0; | 43 DWORD size = 0; |
39 LONG result = key.Open(predefined_root_, key_path_.c_str(), | 44 LONG result = key.Open(predefined_root_, |
40 KEY_READ | KEY_WRITE); | 45 key_path_.c_str(), |
| 46 KEY_READ | KEY_WRITE | wow64_access_); |
41 if (result == ERROR_SUCCESS) | 47 if (result == ERROR_SUCCESS) |
42 result = key.ReadValue(value_name_.c_str(), NULL, &size, &type); | 48 result = key.ReadValue(value_name_.c_str(), NULL, &size, &type); |
43 | 49 |
44 if (result == ERROR_FILE_NOT_FOUND) { | 50 if (result == ERROR_FILE_NOT_FOUND) { |
45 LOG(INFO) << "(delete value) Key: " << key_path_ << " or Value: " | 51 LOG(INFO) << "(delete value) Key: " << key_path_ << " or Value: " |
46 << value_name_ << " does not exist."; | 52 << value_name_ << " does not exist."; |
47 status_ = VALUE_NOT_FOUND; | 53 status_ = VALUE_NOT_FOUND; |
48 return true; | 54 return true; |
49 } | 55 } |
50 | 56 |
(...skipping 25 matching lines...) Expand all Loading... |
76 if (status_ == DELETE_VALUE || status_ == VALUE_ROLLED_BACK) | 82 if (status_ == DELETE_VALUE || status_ == VALUE_ROLLED_BACK) |
77 return; | 83 return; |
78 if (status_ == VALUE_UNCHANGED || status_ == VALUE_NOT_FOUND) { | 84 if (status_ == VALUE_UNCHANGED || status_ == VALUE_NOT_FOUND) { |
79 status_ = VALUE_ROLLED_BACK; | 85 status_ = VALUE_ROLLED_BACK; |
80 VLOG(1) << "rollback: setting unchanged, nothing to do"; | 86 VLOG(1) << "rollback: setting unchanged, nothing to do"; |
81 return; | 87 return; |
82 } | 88 } |
83 | 89 |
84 // At this point only possible state is VALUE_DELETED. | 90 // At this point only possible state is VALUE_DELETED. |
85 RegKey key; | 91 RegKey key; |
86 LONG result = key.Open(predefined_root_, key_path_.c_str(), | 92 LONG result = key.Open(predefined_root_, |
87 KEY_READ | KEY_WRITE); | 93 key_path_.c_str(), |
| 94 KEY_READ | KEY_WRITE | wow64_access_); |
88 if (result == ERROR_SUCCESS) { | 95 if (result == ERROR_SUCCESS) { |
89 // try to restore the previous value | 96 // try to restore the previous value |
90 DWORD previous_size = static_cast<DWORD>(previous_value_.size()); | 97 DWORD previous_size = static_cast<DWORD>(previous_value_.size()); |
91 const char* previous_value = | 98 const char* previous_value = |
92 previous_size ? &previous_value_[0] : NULL; | 99 previous_size ? &previous_value_[0] : NULL; |
93 result = key.WriteValue(value_name_.c_str(), previous_value, | 100 result = key.WriteValue(value_name_.c_str(), previous_value, |
94 previous_size, previous_type_); | 101 previous_size, previous_type_); |
95 VLOG_IF(1, result != ERROR_SUCCESS) << "rollback: restoring " | 102 VLOG_IF(1, result != ERROR_SUCCESS) << "rollback: restoring " |
96 << value_name_ << " error: " << result; | 103 << value_name_ << " error: " << result; |
97 } else { | 104 } else { |
98 VLOG(1) << "can not open " << key_path_ << " error: " << result; | 105 VLOG(1) << "can not open " << key_path_ << " error: " << result; |
99 } | 106 } |
100 } | 107 } |
OLD | NEW |