Chromium Code Reviews| Index: chrome/installer/util/set_reg_value_work_item.cc |
| diff --git a/chrome/installer/util/set_reg_value_work_item.cc b/chrome/installer/util/set_reg_value_work_item.cc |
| index 596fe7c8895ecd81944ddf262f16f4386b63a92c..a9e25aedb5bb66f2ece8b63f78238653da96ed2a 100644 |
| --- a/chrome/installer/util/set_reg_value_work_item.cc |
| +++ b/chrome/installer/util/set_reg_value_work_item.cc |
| @@ -9,6 +9,16 @@ |
| #include "base/win/registry.h" |
| #include "chrome/installer/util/logging_installer.h" |
| +namespace { |
| + |
| +void StringToBinaryData(const std::wstring& str_value, |
|
grt (UTC plus 2)
2015/06/29 15:37:48
nit: add a comment
gab
2015/06/29 20:11:01
Done.
|
| + std::vector<uint8>* binary_data) { |
| + const uint8* data = reinterpret_cast<const uint8*>(str_value.c_str()); |
| + binary_data->assign(data, data + (str_value.length() + 1) * sizeof(wchar_t)); |
| +} |
| + |
| +} // namespace |
| + |
| SetRegValueWorkItem::~SetRegValueWorkItem() { |
| } |
| @@ -29,8 +39,7 @@ SetRegValueWorkItem::SetRegValueWorkItem(HKEY predefined_root, |
| DCHECK(wow64_access == 0 || |
| wow64_access == KEY_WOW64_32KEY || |
| wow64_access == KEY_WOW64_64KEY); |
| - const uint8* data = reinterpret_cast<const uint8*>(value_data.c_str()); |
| - value_.assign(data, data + (value_data.length() + 1) * sizeof(wchar_t)); |
| + StringToBinaryData(value_data, &value_); |
| } |
| SetRegValueWorkItem::SetRegValueWorkItem(HKEY predefined_root, |
| @@ -75,6 +84,27 @@ SetRegValueWorkItem::SetRegValueWorkItem(HKEY predefined_root, |
| value_.assign(data, data + sizeof(value_data)); |
| } |
| +SetRegValueWorkItem::SetRegValueWorkItem( |
| + HKEY predefined_root, |
| + const std::wstring& key_path, |
| + REGSAM wow64_access, |
| + const std::wstring& value_name, |
| + const GetValueFromExistingCallback& get_value_callback) |
| + : predefined_root_(predefined_root), |
| + key_path_(key_path), |
| + value_name_(value_name), |
| + get_value_callback_(get_value_callback), |
| + overwrite_(true), |
| + wow64_access_(wow64_access), |
| + status_(SET_VALUE), |
| + type_(REG_SZ), |
| + previous_type_(0) { |
| + DCHECK(wow64_access == 0 || |
| + wow64_access == KEY_WOW64_32KEY || |
| + wow64_access == KEY_WOW64_64KEY); |
| + // Nothing to do, |get_value_callback| will fill |value_| later. |
| +} |
| + |
| bool SetRegValueWorkItem::Do() { |
| LONG result = ERROR_SUCCESS; |
| base::win::RegKey key; |
| @@ -118,6 +148,18 @@ bool SetRegValueWorkItem::Do() { |
| } |
| } |
| + if (!get_value_callback_.is_null()) { |
| + // Although this could be made more generic, for now this assumes the |
| + // |type_| of |value_| is REG_SZ. |
| + DCHECK(type_ == REG_SZ); |
|
grt (UTC plus 2)
2015/06/29 15:37:48
DCHECK_EQ(REG_SZ, type_);
gab
2015/06/29 20:11:01
I tried that put it would require a cast or:
d:\s
grt (UTC plus 2)
2015/06/30 20:26:42
I think the cast is worth it so that failures cont
gab
2015/07/01 02:55:19
Done.
|
| + |
| + const std::wstring previous_value_str( |
| + (previous_type_ == REG_SZ && previous_value_.size() >= sizeof(wchar_t)) |
| + ? reinterpret_cast<wchar_t*>(&previous_value_[0]) |
|
grt (UTC plus 2)
2015/06/29 15:37:48
there is no guarantee that previous_value_ is null
gab
2015/06/29 20:11:01
Indeed, great great point sir!
grt (UTC plus 2)
2015/06/30 20:26:42
If the callback is meant to take the true registry
gab
2015/07/01 02:55:19
Acknowledged.
gab
2015/07/06 20:56:02
Actually registry.cc's ReadValue() [1] does assume
grt (UTC plus 2)
2015/07/10 19:10:52
That's a bug. The one in mini_installer.cc does so
|
| + : L""); |
| + StringToBinaryData(get_value_callback_.Run(previous_value_str), &value_); |
| + } |
| + |
| result = key.WriteValue(value_name_.c_str(), &value_[0], |
| static_cast<DWORD>(value_.size()), type_); |
| if (result != ERROR_SUCCESS) { |