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

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

Issue 282363003: Add WOW64 support to the installer registry work items (Closed) Base URL: https://chromium.googlesource.com/chromium/src
Patch Set: nits. fix call to DeleteRegistryKey Created 6 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"
11 11
12 SetRegValueWorkItem::~SetRegValueWorkItem() { 12 SetRegValueWorkItem::~SetRegValueWorkItem() {
13 } 13 }
14 14
15 SetRegValueWorkItem::SetRegValueWorkItem(HKEY predefined_root, 15 SetRegValueWorkItem::SetRegValueWorkItem(HKEY predefined_root,
16 const std::wstring& key_path, 16 const std::wstring& key_path,
17 REGSAM wow64_access,
17 const std::wstring& value_name, 18 const std::wstring& value_name,
18 const std::wstring& value_data, 19 const std::wstring& value_data,
19 bool overwrite) 20 bool overwrite)
20 : predefined_root_(predefined_root), 21 : predefined_root_(predefined_root),
21 key_path_(key_path), 22 key_path_(key_path),
22 value_name_(value_name), 23 value_name_(value_name),
23 overwrite_(overwrite), 24 overwrite_(overwrite),
25 wow64_access_(wow64_access),
24 status_(SET_VALUE), 26 status_(SET_VALUE),
25 type_(REG_SZ), 27 type_(REG_SZ),
26 previous_type_(0) { 28 previous_type_(0) {
29 DCHECK(wow64_access == 0 ||
30 wow64_access == KEY_WOW64_32KEY ||
31 wow64_access == KEY_WOW64_64KEY);
27 const uint8* data = reinterpret_cast<const uint8*>(value_data.c_str()); 32 const uint8* data = reinterpret_cast<const uint8*>(value_data.c_str());
28 value_.assign(data, data + (value_data.length() + 1) * sizeof(wchar_t)); 33 value_.assign(data, data + (value_data.length() + 1) * sizeof(wchar_t));
29 } 34 }
30 35
31 SetRegValueWorkItem::SetRegValueWorkItem(HKEY predefined_root, 36 SetRegValueWorkItem::SetRegValueWorkItem(HKEY predefined_root,
32 const std::wstring& key_path, 37 const std::wstring& key_path,
38 REGSAM wow64_access,
33 const std::wstring& value_name, 39 const std::wstring& value_name,
34 DWORD value_data, 40 DWORD value_data,
35 bool overwrite) 41 bool overwrite)
36 : predefined_root_(predefined_root), 42 : predefined_root_(predefined_root),
37 key_path_(key_path), 43 key_path_(key_path),
38 value_name_(value_name), 44 value_name_(value_name),
39 overwrite_(overwrite), 45 overwrite_(overwrite),
46 wow64_access_(wow64_access),
40 status_(SET_VALUE), 47 status_(SET_VALUE),
41 type_(REG_DWORD), 48 type_(REG_DWORD),
42 previous_type_(0) { 49 previous_type_(0) {
50 DCHECK(wow64_access == 0 ||
51 wow64_access == KEY_WOW64_32KEY ||
52 wow64_access == KEY_WOW64_64KEY);
43 const uint8* data = reinterpret_cast<const uint8*>(&value_data); 53 const uint8* data = reinterpret_cast<const uint8*>(&value_data);
44 value_.assign(data, data + sizeof(value_data)); 54 value_.assign(data, data + sizeof(value_data));
45 } 55 }
46 56
47 SetRegValueWorkItem::SetRegValueWorkItem(HKEY predefined_root, 57 SetRegValueWorkItem::SetRegValueWorkItem(HKEY predefined_root,
48 const std::wstring& key_path, 58 const std::wstring& key_path,
59 REGSAM wow64_access,
49 const std::wstring& value_name, 60 const std::wstring& value_name,
50 int64 value_data, 61 int64 value_data,
51 bool overwrite) 62 bool overwrite)
52 : predefined_root_(predefined_root), 63 : predefined_root_(predefined_root),
53 key_path_(key_path), 64 key_path_(key_path),
54 value_name_(value_name), 65 value_name_(value_name),
55 overwrite_(overwrite), 66 overwrite_(overwrite),
67 wow64_access_(wow64_access),
56 status_(SET_VALUE), 68 status_(SET_VALUE),
57 type_(REG_QWORD), 69 type_(REG_QWORD),
58 previous_type_(0) { 70 previous_type_(0) {
71 DCHECK(wow64_access == 0 ||
72 wow64_access == KEY_WOW64_32KEY ||
73 wow64_access == KEY_WOW64_64KEY);
59 const uint8* data = reinterpret_cast<const uint8*>(&value_data); 74 const uint8* data = reinterpret_cast<const uint8*>(&value_data);
60 value_.assign(data, data + sizeof(value_data)); 75 value_.assign(data, data + sizeof(value_data));
61 } 76 }
62 77
63 bool SetRegValueWorkItem::Do() { 78 bool SetRegValueWorkItem::Do() {
64 LONG result = ERROR_SUCCESS; 79 LONG result = ERROR_SUCCESS;
65 base::win::RegKey key; 80 base::win::RegKey key;
66 if (status_ != SET_VALUE) { 81 if (status_ != SET_VALUE) {
67 // we already did something. 82 // we already did something.
68 VLOG(1) << "multiple calls to Do()"; 83 VLOG(1) << "multiple calls to Do()";
69 result = ERROR_CANTWRITE; 84 result = ERROR_CANTWRITE;
70 return ignore_failure_; 85 return ignore_failure_;
71 } 86 }
72 87
73 status_ = VALUE_UNCHANGED; 88 status_ = VALUE_UNCHANGED;
74 result = key.Open(predefined_root_, key_path_.c_str(), 89 result = key.Open(predefined_root_,
75 KEY_READ | KEY_SET_VALUE); 90 key_path_.c_str(),
91 KEY_READ | KEY_SET_VALUE | wow64_access_);
76 if (result != ERROR_SUCCESS) { 92 if (result != ERROR_SUCCESS) {
77 VLOG(1) << "can not open " << key_path_ << " error: " << result; 93 VLOG(1) << "can not open " << key_path_ << " error: " << result;
78 return ignore_failure_; 94 return ignore_failure_;
79 } 95 }
80 96
81 DWORD type = 0; 97 DWORD type = 0;
82 DWORD size = 0; 98 DWORD size = 0;
83 result = key.ReadValue(value_name_.c_str(), NULL, &size, &type); 99 result = key.ReadValue(value_name_.c_str(), NULL, &size, &type);
84 // If the value exists but we don't want to overwrite then there's 100 // If the value exists but we don't want to overwrite then there's
85 // nothing more to do. 101 // nothing more to do.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 if (status_ == SET_VALUE || status_ == VALUE_ROLL_BACK) 136 if (status_ == SET_VALUE || status_ == VALUE_ROLL_BACK)
121 return; 137 return;
122 138
123 if (status_ == VALUE_UNCHANGED) { 139 if (status_ == VALUE_UNCHANGED) {
124 status_ = VALUE_ROLL_BACK; 140 status_ = VALUE_ROLL_BACK;
125 VLOG(1) << "rollback: setting unchanged, nothing to do"; 141 VLOG(1) << "rollback: setting unchanged, nothing to do";
126 return; 142 return;
127 } 143 }
128 144
129 base::win::RegKey key; 145 base::win::RegKey key;
130 LONG result = key.Open(predefined_root_, key_path_.c_str(), KEY_SET_VALUE); 146 LONG result = key.Open(
147 predefined_root_, key_path_.c_str(), KEY_SET_VALUE | wow64_access_);
131 if (result != ERROR_SUCCESS) { 148 if (result != ERROR_SUCCESS) {
132 VLOG(1) << "rollback: can not open " << key_path_ << " error: " << result; 149 VLOG(1) << "rollback: can not open " << key_path_ << " error: " << result;
133 return; 150 return;
134 } 151 }
135 152
136 if (status_ == NEW_VALUE_CREATED) { 153 if (status_ == NEW_VALUE_CREATED) {
137 result = key.DeleteValue(value_name_.c_str()); 154 result = key.DeleteValue(value_name_.c_str());
138 VLOG(1) << "rollback: deleting " << value_name_ << " error: " << result; 155 VLOG(1) << "rollback: deleting " << value_name_ << " error: " << result;
139 } else if (status_ == VALUE_OVERWRITTEN) { 156 } else if (status_ == VALUE_OVERWRITTEN) {
140 const unsigned char* previous_value = 157 const unsigned char* previous_value =
141 previous_value_.empty() ? NULL : &previous_value_[0]; 158 previous_value_.empty() ? NULL : &previous_value_[0];
142 result = key.WriteValue(value_name_.c_str(), previous_value, 159 result = key.WriteValue(value_name_.c_str(), previous_value,
143 static_cast<DWORD>(previous_value_.size()), 160 static_cast<DWORD>(previous_value_.size()),
144 previous_type_); 161 previous_type_);
145 VLOG(1) << "rollback: restoring " << value_name_ << " error: " << result; 162 VLOG(1) << "rollback: restoring " << value_name_ << " error: " << result;
146 } else { 163 } else {
147 NOTREACHED(); 164 NOTREACHED();
148 } 165 }
149 166
150 status_ = VALUE_ROLL_BACK; 167 status_ = VALUE_ROLL_BACK;
151 } 168 }
OLDNEW
« no previous file with comments | « chrome/installer/util/set_reg_value_work_item.h ('k') | chrome/installer/util/set_reg_value_work_item_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698