summaryrefslogtreecommitdiffstats
path: root/chromium/base/win/registry.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/base/win/registry.cc')
-rw-r--r--chromium/base/win/registry.cc148
1 files changed, 70 insertions, 78 deletions
diff --git a/chromium/base/win/registry.cc b/chromium/base/win/registry.cc
index b95b4746858..cd6208eda5f 100644
--- a/chromium/base/win/registry.cc
+++ b/chromium/base/win/registry.cc
@@ -13,6 +13,7 @@
#include "base/logging.h"
#include "base/stl_util.h"
#include "base/strings/string_util.h"
+#include "base/strings/string_util_win.h"
#include "base/threading/thread_restrictions.h"
#include "base/win/shlwapi.h"
#include "base/win/windows_version.h"
@@ -95,7 +96,7 @@ RegKey::RegKey() : key_(NULL), wow64access_(0) {
RegKey::RegKey(HKEY key) : key_(key), wow64access_(0) {
}
-RegKey::RegKey(HKEY rootkey, const char16* subkey, REGSAM access)
+RegKey::RegKey(HKEY rootkey, const wchar_t* subkey, REGSAM access)
: key_(NULL), wow64access_(0) {
if (rootkey) {
if (access & (KEY_SET_VALUE | KEY_CREATE_SUB_KEY | KEY_CREATE_LINK))
@@ -112,20 +113,20 @@ RegKey::~RegKey() {
Close();
}
-LONG RegKey::Create(HKEY rootkey, const char16* subkey, REGSAM access) {
+LONG RegKey::Create(HKEY rootkey, const wchar_t* subkey, REGSAM access) {
DWORD disposition_value;
return CreateWithDisposition(rootkey, subkey, &disposition_value, access);
}
LONG RegKey::CreateWithDisposition(HKEY rootkey,
- const char16* subkey,
+ const wchar_t* subkey,
DWORD* disposition,
REGSAM access) {
DCHECK(rootkey && subkey && access && disposition);
HKEY subhkey = NULL;
- LONG result = RegCreateKeyEx(rootkey, as_wcstr(subkey), 0, NULL,
- REG_OPTION_NON_VOLATILE, access, NULL, &subhkey,
- disposition);
+ LONG result =
+ RegCreateKeyEx(rootkey, subkey, 0, NULL, REG_OPTION_NON_VOLATILE, access,
+ NULL, &subhkey, disposition);
if (result == ERROR_SUCCESS) {
Close();
key_ = subhkey;
@@ -135,7 +136,7 @@ LONG RegKey::CreateWithDisposition(HKEY rootkey,
return result;
}
-LONG RegKey::CreateKey(const char16* name, REGSAM access) {
+LONG RegKey::CreateKey(const wchar_t* name, REGSAM access) {
DCHECK(name && access);
// After the application has accessed an alternate registry view using one of
// the [KEY_WOW64_32KEY / KEY_WOW64_64KEY] flags, all subsequent operations
@@ -147,9 +148,8 @@ LONG RegKey::CreateKey(const char16* name, REGSAM access) {
return ERROR_INVALID_PARAMETER;
}
HKEY subkey = NULL;
- LONG result =
- RegCreateKeyEx(key_, as_wcstr(name), 0, NULL, REG_OPTION_NON_VOLATILE,
- access, NULL, &subkey, NULL);
+ LONG result = RegCreateKeyEx(key_, name, 0, NULL, REG_OPTION_NON_VOLATILE,
+ access, NULL, &subkey, NULL);
if (result == ERROR_SUCCESS) {
Close();
key_ = subkey;
@@ -159,11 +159,11 @@ LONG RegKey::CreateKey(const char16* name, REGSAM access) {
return result;
}
-LONG RegKey::Open(HKEY rootkey, const char16* subkey, REGSAM access) {
+LONG RegKey::Open(HKEY rootkey, const wchar_t* subkey, REGSAM access) {
DCHECK(rootkey && subkey && access);
HKEY subhkey = NULL;
- LONG result = RegOpenKeyEx(rootkey, as_wcstr(subkey), 0, access, &subhkey);
+ LONG result = RegOpenKeyEx(rootkey, subkey, 0, access, &subhkey);
if (result == ERROR_SUCCESS) {
Close();
key_ = subhkey;
@@ -173,7 +173,7 @@ LONG RegKey::Open(HKEY rootkey, const char16* subkey, REGSAM access) {
return result;
}
-LONG RegKey::OpenKey(const char16* relative_key_name, REGSAM access) {
+LONG RegKey::OpenKey(const wchar_t* relative_key_name, REGSAM access) {
DCHECK(relative_key_name && access);
// After the application has accessed an alternate registry view using one of
// the [KEY_WOW64_32KEY / KEY_WOW64_64KEY] flags, all subsequent operations
@@ -185,8 +185,7 @@ LONG RegKey::OpenKey(const char16* relative_key_name, REGSAM access) {
return ERROR_INVALID_PARAMETER;
}
HKEY subkey = NULL;
- LONG result =
- RegOpenKeyEx(key_, as_wcstr(relative_key_name), 0, access, &subkey);
+ LONG result = RegOpenKeyEx(key_, relative_key_name, 0, access, &subkey);
// We have to close the current opened key before replacing it with the new
// one.
@@ -221,9 +220,8 @@ HKEY RegKey::Take() {
return key;
}
-bool RegKey::HasValue(const char16* name) const {
- return RegQueryValueEx(key_, as_wcstr(name), 0, NULL, NULL, NULL) ==
- ERROR_SUCCESS;
+bool RegKey::HasValue(const wchar_t* name) const {
+ return RegQueryValueEx(key_, name, 0, NULL, NULL, NULL) == ERROR_SUCCESS;
}
DWORD RegKey::GetValueCount() const {
@@ -233,26 +231,25 @@ DWORD RegKey::GetValueCount() const {
return (result == ERROR_SUCCESS) ? count : 0;
}
-LONG RegKey::GetValueNameAt(int index, string16* name) const {
- char16 buf[256];
+LONG RegKey::GetValueNameAt(int index, std::wstring* name) const {
+ wchar_t buf[256];
DWORD bufsize = size(buf);
- LONG r = ::RegEnumValue(key_, index, as_writable_wcstr(buf), &bufsize, NULL,
- NULL, NULL, NULL);
+ LONG r = ::RegEnumValue(key_, index, buf, &bufsize, NULL, NULL, NULL, NULL);
if (r == ERROR_SUCCESS)
name->assign(buf, bufsize);
return r;
}
-LONG RegKey::DeleteKey(const char16* name) {
+LONG RegKey::DeleteKey(const wchar_t* name) {
DCHECK(key_);
DCHECK(name);
HKEY subkey = NULL;
// Verify the key exists before attempting delete to replicate previous
// behavior.
- LONG result = RegOpenKeyEx(key_, as_wcstr(name), 0,
- READ_CONTROL | wow64access_, &subkey);
+ LONG result =
+ RegOpenKeyEx(key_, name, 0, READ_CONTROL | wow64access_, &subkey);
if (result != ERROR_SUCCESS)
return result;
RegCloseKey(subkey);
@@ -260,13 +257,13 @@ LONG RegKey::DeleteKey(const char16* name) {
return RegDelRecurse(key_, name, wow64access_);
}
-LONG RegKey::DeleteEmptyKey(const char16* name) {
+LONG RegKey::DeleteEmptyKey(const wchar_t* name) {
DCHECK(key_);
DCHECK(name);
HKEY target_key = NULL;
- LONG result = RegOpenKeyEx(key_, as_wcstr(name), 0, KEY_READ | wow64access_,
- &target_key);
+ LONG result =
+ RegOpenKeyEx(key_, name, 0, KEY_READ | wow64access_, &target_key);
if (result != ERROR_SUCCESS)
return result;
@@ -281,18 +278,18 @@ LONG RegKey::DeleteEmptyKey(const char16* name) {
return result;
if (count == 0)
- return RegDeleteKeyEx(key_, as_wcstr(name), wow64access_, 0);
+ return RegDeleteKeyEx(key_, name, wow64access_, 0);
return ERROR_DIR_NOT_EMPTY;
}
-LONG RegKey::DeleteValue(const char16* value_name) {
+LONG RegKey::DeleteValue(const wchar_t* value_name) {
DCHECK(key_);
- LONG result = RegDeleteValue(key_, as_wcstr(value_name));
+ LONG result = RegDeleteValue(key_, value_name);
return result;
}
-LONG RegKey::ReadValueDW(const char16* name, DWORD* out_value) const {
+LONG RegKey::ReadValueDW(const wchar_t* name, DWORD* out_value) const {
DCHECK(out_value);
DWORD type = REG_DWORD;
DWORD size = sizeof(DWORD);
@@ -308,7 +305,7 @@ LONG RegKey::ReadValueDW(const char16* name, DWORD* out_value) const {
return result;
}
-LONG RegKey::ReadInt64(const char16* name, int64_t* out_value) const {
+LONG RegKey::ReadInt64(const wchar_t* name, int64_t* out_value) const {
DCHECK(out_value);
DWORD type = REG_QWORD;
int64_t local_value = 0;
@@ -325,20 +322,19 @@ LONG RegKey::ReadInt64(const char16* name, int64_t* out_value) const {
return result;
}
-LONG RegKey::ReadValue(const char16* name, string16* out_value) const {
+LONG RegKey::ReadValue(const wchar_t* name, std::wstring* out_value) const {
DCHECK(out_value);
const size_t kMaxStringLength = 1024; // This is after expansion.
// Use the one of the other forms of ReadValue if 1024 is too small for you.
- char16 raw_value[kMaxStringLength];
+ wchar_t raw_value[kMaxStringLength];
DWORD type = REG_SZ, size = sizeof(raw_value);
- LONG result = ReadValue(name, as_writable_wcstr(raw_value), &size, &type);
+ LONG result = ReadValue(name, raw_value, &size, &type);
if (result == ERROR_SUCCESS) {
if (type == REG_SZ) {
*out_value = raw_value;
} else if (type == REG_EXPAND_SZ) {
- char16 expanded[kMaxStringLength];
- size = ExpandEnvironmentStrings(
- as_wcstr(raw_value), as_writable_wcstr(expanded), kMaxStringLength);
+ wchar_t expanded[kMaxStringLength];
+ size = ExpandEnvironmentStrings(raw_value, expanded, kMaxStringLength);
// Success: returns the number of wchar_t's copied
// Fail: buffer too small, returns the size required
// Fail: other, returns 0
@@ -356,16 +352,17 @@ LONG RegKey::ReadValue(const char16* name, string16* out_value) const {
return result;
}
-LONG RegKey::ReadValue(const char16* name,
+LONG RegKey::ReadValue(const wchar_t* name,
void* data,
DWORD* dsize,
DWORD* dtype) const {
- LONG result = RegQueryValueEx(key_, as_wcstr(name), 0, dtype,
+ LONG result = RegQueryValueEx(key_, name, 0, dtype,
reinterpret_cast<LPBYTE>(data), dsize);
return result;
}
-LONG RegKey::ReadValues(const char16* name, std::vector<string16>* values) {
+LONG RegKey::ReadValues(const wchar_t* name,
+ std::vector<std::wstring>* values) {
values->clear();
DWORD type = REG_MULTI_SZ;
@@ -377,8 +374,8 @@ LONG RegKey::ReadValues(const char16* name, std::vector<string16>* values) {
if (type != REG_MULTI_SZ)
return ERROR_CANTREAD;
- std::vector<char16> buffer(size / sizeof(char16));
- result = ReadValue(name, as_writable_wcstr(buffer.data()), &size, NULL);
+ std::vector<wchar_t> buffer(size / sizeof(wchar_t));
+ result = ReadValue(name, buffer.data(), &size, NULL);
if (result != ERROR_SUCCESS || size == 0)
return result;
@@ -395,27 +392,27 @@ LONG RegKey::ReadValues(const char16* name, std::vector<string16>* values) {
return 0;
}
-LONG RegKey::WriteValue(const char16* name, DWORD in_value) {
+LONG RegKey::WriteValue(const wchar_t* name, DWORD in_value) {
return WriteValue(
name, &in_value, static_cast<DWORD>(sizeof(in_value)), REG_DWORD);
}
-LONG RegKey::WriteValue(const char16* name, const char16* in_value) {
+LONG RegKey::WriteValue(const wchar_t* name, const wchar_t* in_value) {
return WriteValue(
name, in_value,
static_cast<DWORD>(sizeof(*in_value) *
- (std::char_traits<char16>::length(in_value) + 1)),
+ (std::char_traits<wchar_t>::length(in_value) + 1)),
REG_SZ);
}
-LONG RegKey::WriteValue(const char16* name,
+LONG RegKey::WriteValue(const wchar_t* name,
const void* data,
DWORD dsize,
DWORD dtype) {
DCHECK(data || !dsize);
LONG result =
- RegSetValueEx(key_, as_wcstr(name), 0, dtype,
+ RegSetValueEx(key_, name, 0, dtype,
reinterpret_cast<LPBYTE>(const_cast<void*>(data)), dsize);
return result;
}
@@ -431,22 +428,22 @@ bool RegKey::StartWatching(ChangeCallback callback) {
}
// static
-LONG RegKey::RegDelRecurse(HKEY root_key, const char16* name, REGSAM access) {
+LONG RegKey::RegDelRecurse(HKEY root_key, const wchar_t* name, REGSAM access) {
// First, see if the key can be deleted without having to recurse.
- LONG result = RegDeleteKeyEx(root_key, as_wcstr(name), access, 0);
+ LONG result = RegDeleteKeyEx(root_key, name, access, 0);
if (result == ERROR_SUCCESS)
return result;
HKEY target_key = NULL;
- result = RegOpenKeyEx(root_key, as_wcstr(name), 0,
- KEY_ENUMERATE_SUB_KEYS | access, &target_key);
+ result = RegOpenKeyEx(root_key, name, 0, KEY_ENUMERATE_SUB_KEYS | access,
+ &target_key);
if (result == ERROR_FILE_NOT_FOUND)
return ERROR_SUCCESS;
if (result != ERROR_SUCCESS)
return result;
- string16 subkey_name(name);
+ std::wstring subkey_name(name);
// Check for an ending slash and add one if it is missing.
if (!subkey_name.empty() && subkey_name.back() != '\\')
@@ -456,12 +453,11 @@ LONG RegKey::RegDelRecurse(HKEY root_key, const char16* name, REGSAM access) {
result = ERROR_SUCCESS;
const DWORD kMaxKeyNameLength = MAX_PATH;
const size_t base_key_length = subkey_name.length();
- string16 key_name;
+ std::wstring key_name;
while (result == ERROR_SUCCESS) {
DWORD key_size = kMaxKeyNameLength;
result =
- RegEnumKeyEx(target_key, 0,
- as_writable_wcstr(WriteInto(&key_name, kMaxKeyNameLength)),
+ RegEnumKeyEx(target_key, 0, WriteIntoW(&key_name, kMaxKeyNameLength),
&key_size, NULL, NULL, NULL, NULL);
if (result != ERROR_SUCCESS)
@@ -478,7 +474,7 @@ LONG RegKey::RegDelRecurse(HKEY root_key, const char16* name, REGSAM access) {
RegCloseKey(target_key);
// Try again to delete the key.
- result = RegDeleteKeyEx(root_key, as_wcstr(name), access, 0);
+ result = RegDeleteKeyEx(root_key, name, access, 0);
return result;
}
@@ -486,24 +482,24 @@ LONG RegKey::RegDelRecurse(HKEY root_key, const char16* name, REGSAM access) {
// RegistryValueIterator ------------------------------------------------------
RegistryValueIterator::RegistryValueIterator(HKEY root_key,
- const char16* folder_key,
+ const wchar_t* folder_key,
REGSAM wow64access)
: name_(MAX_PATH, '\0'), value_(MAX_PATH, '\0') {
Initialize(root_key, folder_key, wow64access);
}
RegistryValueIterator::RegistryValueIterator(HKEY root_key,
- const char16* folder_key)
+ const wchar_t* folder_key)
: name_(MAX_PATH, '\0'), value_(MAX_PATH, '\0') {
Initialize(root_key, folder_key, 0);
}
void RegistryValueIterator::Initialize(HKEY root_key,
- const char16* folder_key,
+ const wchar_t* folder_key,
REGSAM wow64access) {
DCHECK_EQ(wow64access & ~kWow64AccessMask, static_cast<REGSAM>(0));
- LONG result = RegOpenKeyEx(root_key, as_wcstr(folder_key), 0,
- KEY_READ | wow64access, &key_);
+ LONG result =
+ RegOpenKeyEx(root_key, folder_key, 0, KEY_READ | wow64access, &key_);
if (result != ERROR_SUCCESS) {
key_ = NULL;
} else {
@@ -551,13 +547,10 @@ bool RegistryValueIterator::Read() {
DWORD capacity = static_cast<DWORD>(name_.capacity());
DWORD name_size = capacity;
// |value_size_| is in bytes. Reserve the last character for a NUL.
- static_assert(sizeof(wchar_t) == sizeof(char16),
- "wchar_t is not the same size as base::char16");
value_size_ = static_cast<DWORD>((value_.size() - 1) * sizeof(wchar_t));
LONG result = ::RegEnumValue(
- key_, index_, as_writable_wcstr(WriteInto(&name_, name_size)),
- &name_size, NULL, &type_, reinterpret_cast<BYTE*>(value_.data()),
- &value_size_);
+ key_, index_, WriteIntoW(&name_, name_size), &name_size, NULL, &type_,
+ reinterpret_cast<BYTE*>(value_.data()), &value_size_);
if (result == ERROR_MORE_DATA) {
// Registry key names are limited to 255 characters and fit within
@@ -572,9 +565,8 @@ bool RegistryValueIterator::Read() {
value_size_ = static_cast<DWORD>((value_.size() - 1) * sizeof(wchar_t));
name_size = name_size == capacity ? MAX_REGISTRY_NAME_SIZE : capacity;
result = ::RegEnumValue(
- key_, index_, as_writable_wcstr(WriteInto(&name_, name_size)),
- &name_size, NULL, &type_, reinterpret_cast<BYTE*>(value_.data()),
- &value_size_);
+ key_, index_, WriteIntoW(&name_, name_size), &name_size, NULL, &type_,
+ reinterpret_cast<BYTE*>(value_.data()), &value_size_);
}
if (result == ERROR_SUCCESS) {
@@ -593,12 +585,12 @@ bool RegistryValueIterator::Read() {
// RegistryKeyIterator --------------------------------------------------------
RegistryKeyIterator::RegistryKeyIterator(HKEY root_key,
- const char16* folder_key) {
+ const wchar_t* folder_key) {
Initialize(root_key, folder_key, 0);
}
RegistryKeyIterator::RegistryKeyIterator(HKEY root_key,
- const char16* folder_key,
+ const wchar_t* folder_key,
REGSAM wow64access) {
Initialize(root_key, folder_key, wow64access);
}
@@ -631,8 +623,8 @@ bool RegistryKeyIterator::Read() {
if (Valid()) {
DWORD ncount = static_cast<DWORD>(size(name_));
FILETIME written;
- LONG r = ::RegEnumKeyEx(key_, index_, as_writable_wcstr(name_), &ncount,
- NULL, NULL, NULL, &written);
+ LONG r = ::RegEnumKeyEx(key_, index_, name_, &ncount, NULL, NULL, NULL,
+ &written);
if (ERROR_SUCCESS == r)
return true;
}
@@ -642,11 +634,11 @@ bool RegistryKeyIterator::Read() {
}
void RegistryKeyIterator::Initialize(HKEY root_key,
- const char16* folder_key,
+ const wchar_t* folder_key,
REGSAM wow64access) {
DCHECK_EQ(wow64access & ~kWow64AccessMask, static_cast<REGSAM>(0));
- LONG result = RegOpenKeyEx(root_key, as_wcstr(folder_key), 0,
- KEY_READ | wow64access, &key_);
+ LONG result =
+ RegOpenKeyEx(root_key, folder_key, 0, KEY_READ | wow64access, &key_);
if (result != ERROR_SUCCESS) {
key_ = NULL;
} else {