Commit 39dc9d7c authored by tfarina@chromium.org's avatar tfarina@chromium.org

base/win: Add documentation to RegKey::Read/Write functions.

R=maruel@chromium.org,willchan@chromium.org,grt@chromium.org

Review URL: http://codereview.chromium.org/8344004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@106869 0039d316-1c4b-4281-b951-d872f2087c98
parent 726843ee
...@@ -142,17 +142,42 @@ LONG RegKey::DeleteValue(const wchar_t* value_name) { ...@@ -142,17 +142,42 @@ LONG RegKey::DeleteValue(const wchar_t* value_name) {
return result; return result;
} }
LONG RegKey::ReadValue(const wchar_t* name, void* data, DWORD* dsize, LONG RegKey::ReadValueDW(const wchar_t* name, DWORD* out_value) const {
DWORD* dtype) const { DCHECK(out_value);
base::ThreadRestrictions::AssertIOAllowed(); DWORD type = REG_DWORD;
LONG result = RegQueryValueEx(key_, name, 0, dtype, DWORD size = sizeof(DWORD);
reinterpret_cast<LPBYTE>(data), dsize); DWORD local_value = 0;
LONG result = ReadValue(name, &local_value, &size, &type);
if (result == ERROR_SUCCESS) {
if ((type == REG_DWORD || type == REG_BINARY) && size == sizeof(DWORD))
*out_value = local_value;
else
result = ERROR_CANTREAD;
}
return result;
}
LONG RegKey::ReadInt64(const wchar_t* name, int64* out_value) const {
DCHECK(out_value);
DWORD type = REG_QWORD;
int64 local_value = 0;
DWORD size = sizeof(local_value);
LONG result = ReadValue(name, &local_value, &size, &type);
if (result == ERROR_SUCCESS) {
if ((type == REG_QWORD || type == REG_BINARY) &&
size == sizeof(local_value))
*out_value = local_value;
else
result = ERROR_CANTREAD;
}
return result; return result;
} }
LONG RegKey::ReadValue(const wchar_t* name, std::wstring* value) const { LONG RegKey::ReadValue(const wchar_t* name, std::wstring* out_value) const {
base::ThreadRestrictions::AssertIOAllowed(); base::ThreadRestrictions::AssertIOAllowed();
DCHECK(value); DCHECK(out_value);
const size_t kMaxStringLength = 1024; // This is after expansion. 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. // Use the one of the other forms of ReadValue if 1024 is too small for you.
wchar_t raw_value[kMaxStringLength]; wchar_t raw_value[kMaxStringLength];
...@@ -160,7 +185,7 @@ LONG RegKey::ReadValue(const wchar_t* name, std::wstring* value) const { ...@@ -160,7 +185,7 @@ LONG RegKey::ReadValue(const wchar_t* name, std::wstring* value) const {
LONG result = ReadValue(name, raw_value, &size, &type); LONG result = ReadValue(name, raw_value, &size, &type);
if (result == ERROR_SUCCESS) { if (result == ERROR_SUCCESS) {
if (type == REG_SZ) { if (type == REG_SZ) {
*value = raw_value; *out_value = raw_value;
} else if (type == REG_EXPAND_SZ) { } else if (type == REG_EXPAND_SZ) {
wchar_t expanded[kMaxStringLength]; wchar_t expanded[kMaxStringLength];
size = ExpandEnvironmentStrings(raw_value, expanded, kMaxStringLength); size = ExpandEnvironmentStrings(raw_value, expanded, kMaxStringLength);
...@@ -170,7 +195,7 @@ LONG RegKey::ReadValue(const wchar_t* name, std::wstring* value) const { ...@@ -170,7 +195,7 @@ LONG RegKey::ReadValue(const wchar_t* name, std::wstring* value) const {
if (size == 0 || size > kMaxStringLength) { if (size == 0 || size > kMaxStringLength) {
result = ERROR_MORE_DATA; result = ERROR_MORE_DATA;
} else { } else {
*value = expanded; *out_value = expanded;
} }
} else { } else {
// Not a string. Oops. // Not a string. Oops.
...@@ -181,43 +206,30 @@ LONG RegKey::ReadValue(const wchar_t* name, std::wstring* value) const { ...@@ -181,43 +206,30 @@ LONG RegKey::ReadValue(const wchar_t* name, std::wstring* value) const {
return result; return result;
} }
LONG RegKey::ReadValueDW(const wchar_t* name, DWORD* value) const { LONG RegKey::ReadValue(const wchar_t* name,
DCHECK(value); void* data,
DWORD type = REG_DWORD; DWORD* dsize,
DWORD size = sizeof(DWORD); DWORD* dtype) const {
DWORD local_value = 0; base::ThreadRestrictions::AssertIOAllowed();
LONG result = ReadValue(name, &local_value, &size, &type); LONG result = RegQueryValueEx(key_, name, 0, dtype,
if (result == ERROR_SUCCESS) { reinterpret_cast<LPBYTE>(data), dsize);
if ((type == REG_DWORD || type == REG_BINARY) && size == sizeof(DWORD)) {
*value = local_value;
} else {
result = ERROR_CANTREAD;
}
}
return result; return result;
} }
LONG RegKey::ReadInt64(const wchar_t* name, int64* value) const { LONG RegKey::WriteValue(const wchar_t* name, DWORD in_value) {
DCHECK(value); return WriteValue(
DWORD type = REG_QWORD; name, &in_value, static_cast<DWORD>(sizeof(in_value)), REG_DWORD);
int64 local_value = 0; }
DWORD size = sizeof(local_value);
LONG result = ReadValue(name, &local_value, &size, &type);
if (result == ERROR_SUCCESS) {
if ((type == REG_QWORD || type == REG_BINARY) &&
size == sizeof(local_value)) {
*value = local_value;
} else {
result = ERROR_CANTREAD;
}
}
return result; LONG RegKey::WriteValue(const wchar_t * name, const wchar_t* in_value) {
return WriteValue(name, in_value,
static_cast<DWORD>(sizeof(*in_value) * (wcslen(in_value) + 1)), REG_SZ);
} }
LONG RegKey::WriteValue(const wchar_t* name, const void * data, LONG RegKey::WriteValue(const wchar_t* name,
DWORD dsize, DWORD dtype) { const void* data,
DWORD dsize,
DWORD dtype) {
base::ThreadRestrictions::AssertIOAllowed(); base::ThreadRestrictions::AssertIOAllowed();
DCHECK(data || !dsize); DCHECK(data || !dsize);
...@@ -226,15 +238,6 @@ LONG RegKey::WriteValue(const wchar_t* name, const void * data, ...@@ -226,15 +238,6 @@ LONG RegKey::WriteValue(const wchar_t* name, const void * data,
return result; return result;
} }
LONG RegKey::WriteValue(const wchar_t * name, const wchar_t* value) {
return WriteValue(name, value,
static_cast<DWORD>(sizeof(*value) * (wcslen(value) + 1)), REG_SZ);
}
LONG RegKey::WriteValue(const wchar_t* name, DWORD value) {
return WriteValue(name, &value, static_cast<DWORD>(sizeof(value)), REG_DWORD);
}
LONG RegKey::StartWatching() { LONG RegKey::StartWatching() {
DCHECK(key_); DCHECK(key_);
if (!watch_event_) if (!watch_event_)
......
...@@ -66,16 +66,40 @@ class BASE_EXPORT RegKey { ...@@ -66,16 +66,40 @@ class BASE_EXPORT RegKey {
// Deletes a single value within the key. // Deletes a single value within the key.
LONG DeleteValue(const wchar_t* name); LONG DeleteValue(const wchar_t* name);
LONG ReadValue(const wchar_t* name, void* data, DWORD* dsize, // Getters:
// Returns an int32 value. If |name| is NULL or empty, returns the default
// value, if any.
LONG ReadValueDW(const wchar_t* name, DWORD* out_value) const;
// Returns an int64 value. If |name| is NULL or empty, returns the default
// value, if any.
LONG ReadInt64(const wchar_t* name, int64* out_value) const;
// Returns a string value. If |name| is NULL or empty, returns the default
// value, if any.
LONG ReadValue(const wchar_t* name, std::wstring* out_value) const;
// Returns raw data. If |name| is NULL or empty, returns the default
// value, if any.
LONG ReadValue(const wchar_t* name,
void* data,
DWORD* dsize,
DWORD* dtype) const; DWORD* dtype) const;
LONG ReadValue(const wchar_t* name, std::wstring* value) const;
LONG ReadValueDW(const wchar_t* name, DWORD* value) const;
LONG ReadInt64(const wchar_t* name, int64* value) const;
LONG WriteValue(const wchar_t* name, const void* data, DWORD dsize, // Setters:
// Sets an int32 value.
LONG WriteValue(const wchar_t* name, DWORD in_value);
// Sets a string value.
LONG WriteValue(const wchar_t* name, const wchar_t* in_value);
// Sets raw data, including type.
LONG WriteValue(const wchar_t* name,
const void* data,
DWORD dsize,
DWORD dtype); DWORD dtype);
LONG WriteValue(const wchar_t* name, const wchar_t* value);
LONG WriteValue(const wchar_t* name, DWORD value);
// Starts watching the key to see if any of its values have changed. // Starts watching the key to see if any of its values have changed.
// The key must have been opened with the KEY_NOTIFY access privilege. // The key must have been opened with the KEY_NOTIFY access privilege.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment