Cleanup: Get rid of base::ASCIIToWide().
BUG=23581 Review URL: https://codereview.chromium.org/768973003 Cr-Commit-Position: refs/heads/master@{#307333}
This commit is contained in:
@@ -494,10 +494,10 @@ TEST(StringUtilTest, ConvertASCII) {
|
|||||||
const char chars_with_nul[] = "test\0string";
|
const char chars_with_nul[] = "test\0string";
|
||||||
const int length_with_nul = arraysize(chars_with_nul) - 1;
|
const int length_with_nul = arraysize(chars_with_nul) - 1;
|
||||||
std::string string_with_nul(chars_with_nul, length_with_nul);
|
std::string string_with_nul(chars_with_nul, length_with_nul);
|
||||||
std::wstring wide_with_nul = ASCIIToWide(string_with_nul);
|
base::string16 string16_with_nul = ASCIIToUTF16(string_with_nul);
|
||||||
EXPECT_EQ(static_cast<std::wstring::size_type>(length_with_nul),
|
EXPECT_EQ(static_cast<base::string16::size_type>(length_with_nul),
|
||||||
wide_with_nul.length());
|
string16_with_nul.length());
|
||||||
std::string narrow_with_nul = UTF16ToASCII(WideToUTF16(wide_with_nul));
|
std::string narrow_with_nul = UTF16ToASCII(string16_with_nul);
|
||||||
EXPECT_EQ(static_cast<std::string::size_type>(length_with_nul),
|
EXPECT_EQ(static_cast<std::string::size_type>(length_with_nul),
|
||||||
narrow_with_nul.length());
|
narrow_with_nul.length());
|
||||||
EXPECT_EQ(0, string_with_nul.compare(narrow_with_nul));
|
EXPECT_EQ(0, string_with_nul.compare(narrow_with_nul));
|
||||||
|
@@ -209,11 +209,6 @@ std::string UTF16ToUTF8(const string16& utf16) {
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::wstring ASCIIToWide(const StringPiece& ascii) {
|
|
||||||
DCHECK(IsStringASCII(ascii)) << ascii;
|
|
||||||
return std::wstring(ascii.begin(), ascii.end());
|
|
||||||
}
|
|
||||||
|
|
||||||
string16 ASCIIToUTF16(const StringPiece& ascii) {
|
string16 ASCIIToUTF16(const StringPiece& ascii) {
|
||||||
DCHECK(IsStringASCII(ascii)) << ascii;
|
DCHECK(IsStringASCII(ascii)) << ascii;
|
||||||
return string16(ascii.begin(), ascii.end());
|
return string16(ascii.begin(), ascii.end());
|
||||||
|
@@ -39,9 +39,8 @@ BASE_EXPORT bool UTF16ToUTF8(const char16* src, size_t src_len,
|
|||||||
std::string* output);
|
std::string* output);
|
||||||
BASE_EXPORT std::string UTF16ToUTF8(const string16& utf16);
|
BASE_EXPORT std::string UTF16ToUTF8(const string16& utf16);
|
||||||
|
|
||||||
// These convert an ASCII string, typically a hardcoded constant, to a
|
// This converts an ASCII string, typically a hardcoded constant, to a UTF16
|
||||||
// UTF16/Wide string.
|
// string.
|
||||||
BASE_EXPORT std::wstring ASCIIToWide(const StringPiece& ascii);
|
|
||||||
BASE_EXPORT string16 ASCIIToUTF16(const StringPiece& ascii);
|
BASE_EXPORT string16 ASCIIToUTF16(const StringPiece& ascii);
|
||||||
|
|
||||||
// Converts to 7-bit ASCII by truncating. The result must be known to be ASCII
|
// Converts to 7-bit ASCII by truncating. The result must be known to be ASCII
|
||||||
|
@@ -21,10 +21,10 @@
|
|||||||
#include "rlz/win/lib/registry_util.h"
|
#include "rlz/win/lib/registry_util.h"
|
||||||
#include "rlz/win/lib/rlz_value_store_registry.h"
|
#include "rlz/win/lib/rlz_value_store_registry.h"
|
||||||
|
|
||||||
const wchar_t kDccValueName[] = L"DCC";
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
const wchar_t kDccValueName[] = L"DCC";
|
||||||
|
|
||||||
// Current DCC can only uses [a-zA-Z0-9_-!@$*();.<>,:]
|
// Current DCC can only uses [a-zA-Z0-9_-!@$*();.<>,:]
|
||||||
// We will be more liberal and allow some additional chars, but not url meta
|
// We will be more liberal and allow some additional chars, but not url meta
|
||||||
// chars.
|
// chars.
|
||||||
@@ -117,7 +117,7 @@ bool GetResponseValue(const std::string& response_line,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace anonymous
|
} // namespace
|
||||||
|
|
||||||
namespace rlz_lib {
|
namespace rlz_lib {
|
||||||
|
|
||||||
@@ -150,7 +150,7 @@ bool MachineDealCode::Set(const char* dcc) {
|
|||||||
|
|
||||||
// Write the DCC to HKLM. Note that we need to include the null character
|
// Write the DCC to HKLM. Note that we need to include the null character
|
||||||
// when writing the string.
|
// when writing the string.
|
||||||
if (!RegKeyWriteValue(hklm_key, kDccValueName, normalized_dcc)) {
|
if (!RegKeyWriteValue(&hklm_key, kDccValueName, normalized_dcc)) {
|
||||||
ASSERT_STRING("MachineDealCode::Set: Could not write the DCC value");
|
ASSERT_STRING("MachineDealCode::Set: Could not write the DCC value");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
namespace rlz_lib {
|
namespace rlz_lib {
|
||||||
|
|
||||||
bool RegKeyReadValue(base::win::RegKey& key, const wchar_t* name,
|
bool RegKeyReadValue(const base::win::RegKey& key, const wchar_t* name,
|
||||||
char* value, size_t* value_size) {
|
char* value, size_t* value_size) {
|
||||||
value[0] = 0;
|
value[0] = 0;
|
||||||
|
|
||||||
@@ -36,10 +36,10 @@ bool RegKeyReadValue(base::win::RegKey& key, const wchar_t* name,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RegKeyWriteValue(base::win::RegKey& key, const wchar_t* name,
|
bool RegKeyWriteValue(base::win::RegKey* key, const wchar_t* name,
|
||||||
const char* value) {
|
const char* value) {
|
||||||
std::wstring value_string(base::ASCIIToWide(value));
|
base::string16 value_string(base::ASCIIToUTF16(value));
|
||||||
return key.WriteValue(name, value_string.c_str()) == ERROR_SUCCESS;
|
return key->WriteValue(name, value_string.c_str()) == ERROR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HasUserKeyAccess(bool write_access) {
|
bool HasUserKeyAccess(bool write_access) {
|
||||||
|
@@ -13,12 +13,12 @@ class RegKey;
|
|||||||
|
|
||||||
namespace rlz_lib {
|
namespace rlz_lib {
|
||||||
|
|
||||||
bool RegKeyReadValue(base::win::RegKey& key,
|
bool RegKeyReadValue(const base::win::RegKey& key,
|
||||||
const wchar_t* name,
|
const wchar_t* name,
|
||||||
char* value,
|
char* value,
|
||||||
size_t* value_size);
|
size_t* value_size);
|
||||||
|
|
||||||
bool RegKeyWriteValue(base::win::RegKey& key,
|
bool RegKeyWriteValue(base::win::RegKey* key,
|
||||||
const wchar_t* name,
|
const wchar_t* name,
|
||||||
const char* value);
|
const char* value);
|
||||||
|
|
||||||
|
@@ -13,7 +13,7 @@
|
|||||||
#include "rlz/lib/string_utils.h"
|
#include "rlz/lib/string_utils.h"
|
||||||
#include "rlz/win/lib/registry_util.h"
|
#include "rlz/win/lib/registry_util.h"
|
||||||
|
|
||||||
using base::ASCIIToWide;
|
using base::ASCIIToUTF16;
|
||||||
|
|
||||||
namespace rlz_lib {
|
namespace rlz_lib {
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@ const char kStatefulEventsSubkeyName[] = "StatefulEvents";
|
|||||||
const char kPingTimesSubkeyName[] = "PTimes";
|
const char kPingTimesSubkeyName[] = "PTimes";
|
||||||
|
|
||||||
std::wstring GetWideProductName(Product product) {
|
std::wstring GetWideProductName(Product product) {
|
||||||
return ASCIIToWide(GetProductName(product));
|
return ASCIIToUTF16(GetProductName(product));
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppendBrandToString(std::string* str) {
|
void AppendBrandToString(std::string* str) {
|
||||||
@@ -61,16 +61,13 @@ bool GetRegKey(const char* name, REGSAM access, base::win::RegKey* key) {
|
|||||||
std::string key_location;
|
std::string key_location;
|
||||||
base::StringAppendF(&key_location, "%s\\%s", kLibKeyName, name);
|
base::StringAppendF(&key_location, "%s\\%s", kLibKeyName, name);
|
||||||
AppendBrandToString(&key_location);
|
AppendBrandToString(&key_location);
|
||||||
|
base::string16 key_location16 = ASCIIToUTF16(key_location);
|
||||||
|
|
||||||
LONG ret = ERROR_SUCCESS;
|
LONG ret;
|
||||||
if (access & (KEY_SET_VALUE | KEY_CREATE_SUB_KEY | KEY_CREATE_LINK)) {
|
if (access & (KEY_SET_VALUE | KEY_CREATE_SUB_KEY | KEY_CREATE_LINK))
|
||||||
ret = key->Create(HKEY_CURRENT_USER, ASCIIToWide(key_location).c_str(),
|
ret = key->Create(HKEY_CURRENT_USER, key_location16.c_str(), access);
|
||||||
access);
|
else
|
||||||
} else {
|
ret = key->Open(HKEY_CURRENT_USER, key_location16.c_str(), access);
|
||||||
ret = key->Open(HKEY_CURRENT_USER, ASCIIToWide(key_location).c_str(),
|
|
||||||
access);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret == ERROR_SUCCESS;
|
return ret == ERROR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,16 +91,13 @@ bool GetEventsRegKey(const char* event_type,
|
|||||||
|
|
||||||
base::StringAppendF(&key_location, "\\%s", product_name.c_str());
|
base::StringAppendF(&key_location, "\\%s", product_name.c_str());
|
||||||
}
|
}
|
||||||
|
base::string16 key_location16 = ASCIIToUTF16(key_location);
|
||||||
|
|
||||||
LONG ret = ERROR_SUCCESS;
|
LONG ret;
|
||||||
if (access & (KEY_SET_VALUE | KEY_CREATE_SUB_KEY | KEY_CREATE_LINK)) {
|
if (access & (KEY_SET_VALUE | KEY_CREATE_SUB_KEY | KEY_CREATE_LINK))
|
||||||
ret = key->Create(HKEY_CURRENT_USER, ASCIIToWide(key_location).c_str(),
|
ret = key->Create(HKEY_CURRENT_USER, key_location16.c_str(), access);
|
||||||
access);
|
else
|
||||||
} else {
|
ret = key->Open(HKEY_CURRENT_USER, key_location16.c_str(), access);
|
||||||
ret = key->Open(HKEY_CURRENT_USER, ASCIIToWide(key_location).c_str(),
|
|
||||||
access);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret == ERROR_SUCCESS;
|
return ret == ERROR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,7 +154,7 @@ bool DeleteKeyIfEmpty(HKEY root_key, const wchar_t* key_name) {
|
|||||||
|
|
||||||
// static
|
// static
|
||||||
std::wstring RlzValueStoreRegistry::GetWideLibKeyName() {
|
std::wstring RlzValueStoreRegistry::GetWideLibKeyName() {
|
||||||
return ASCIIToWide(kLibKeyName);
|
return ASCIIToUTF16(kLibKeyName);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RlzValueStoreRegistry::HasAccess(AccessType type) {
|
bool RlzValueStoreRegistry::HasAccess(AccessType type) {
|
||||||
@@ -207,11 +201,11 @@ bool RlzValueStoreRegistry::WriteAccessPointRlz(AccessPoint access_point,
|
|||||||
if (!access_point_name)
|
if (!access_point_name)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
std::wstring access_point_name_wide(ASCIIToWide(access_point_name));
|
base::string16 access_point_name16(ASCIIToUTF16(access_point_name));
|
||||||
base::win::RegKey key;
|
base::win::RegKey key;
|
||||||
GetAccessPointRlzsRegKey(KEY_WRITE, &key);
|
GetAccessPointRlzsRegKey(KEY_WRITE, &key);
|
||||||
|
|
||||||
if (!RegKeyWriteValue(key, access_point_name_wide.c_str(), new_rlz)) {
|
if (!RegKeyWriteValue(&key, access_point_name16.c_str(), new_rlz)) {
|
||||||
ASSERT_STRING("SetAccessPointRlz: Could not write the new RLZ value");
|
ASSERT_STRING("SetAccessPointRlz: Could not write the new RLZ value");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -228,8 +222,8 @@ bool RlzValueStoreRegistry::ReadAccessPointRlz(AccessPoint access_point,
|
|||||||
size_t size = rlz_size;
|
size_t size = rlz_size;
|
||||||
base::win::RegKey key;
|
base::win::RegKey key;
|
||||||
GetAccessPointRlzsRegKey(KEY_READ, &key);
|
GetAccessPointRlzsRegKey(KEY_READ, &key);
|
||||||
if (!RegKeyReadValue(key, ASCIIToWide(access_point_name).c_str(),
|
base::string16 access_point_name16 = ASCIIToUTF16(access_point_name);
|
||||||
rlz, &size)) {
|
if (!RegKeyReadValue(key, access_point_name16.c_str(), rlz, &size)) {
|
||||||
rlz[0] = 0;
|
rlz[0] = 0;
|
||||||
if (size > rlz_size) {
|
if (size > rlz_size) {
|
||||||
ASSERT_STRING("GetAccessPointRlz: Insufficient buffer size");
|
ASSERT_STRING("GetAccessPointRlz: Insufficient buffer size");
|
||||||
@@ -244,16 +238,15 @@ bool RlzValueStoreRegistry::ClearAccessPointRlz(AccessPoint access_point) {
|
|||||||
if (!access_point_name)
|
if (!access_point_name)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
std::wstring access_point_name_wide(ASCIIToWide(access_point_name));
|
base::string16 access_point_name16(ASCIIToUTF16(access_point_name));
|
||||||
base::win::RegKey key;
|
base::win::RegKey key;
|
||||||
GetAccessPointRlzsRegKey(KEY_WRITE, &key);
|
GetAccessPointRlzsRegKey(KEY_WRITE, &key);
|
||||||
|
|
||||||
key.DeleteValue(access_point_name_wide.c_str());
|
key.DeleteValue(access_point_name16.c_str());
|
||||||
|
|
||||||
// Verify deletion.
|
// Verify deletion.
|
||||||
DWORD value;
|
DWORD value;
|
||||||
if (key.ReadValueDW(access_point_name_wide.c_str(), &value) ==
|
if (key.ReadValueDW(access_point_name16.c_str(), &value) == ERROR_SUCCESS) {
|
||||||
ERROR_SUCCESS) {
|
|
||||||
ASSERT_STRING("SetAccessPointRlz: Could not clear the RLZ value.");
|
ASSERT_STRING("SetAccessPointRlz: Could not clear the RLZ value.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -262,10 +255,10 @@ bool RlzValueStoreRegistry::ClearAccessPointRlz(AccessPoint access_point) {
|
|||||||
|
|
||||||
bool RlzValueStoreRegistry::AddProductEvent(Product product,
|
bool RlzValueStoreRegistry::AddProductEvent(Product product,
|
||||||
const char* event_rlz) {
|
const char* event_rlz) {
|
||||||
std::wstring event_rlz_wide(ASCIIToWide(event_rlz));
|
base::string16 event_rlz16(ASCIIToUTF16(event_rlz));
|
||||||
base::win::RegKey reg_key;
|
base::win::RegKey reg_key;
|
||||||
GetEventsRegKey(kEventsSubkeyName, &product, KEY_WRITE, ®_key);
|
GetEventsRegKey(kEventsSubkeyName, &product, KEY_WRITE, ®_key);
|
||||||
if (reg_key.WriteValue(event_rlz_wide.c_str(), 1) != ERROR_SUCCESS) {
|
if (reg_key.WriteValue(event_rlz16.c_str(), 1) != ERROR_SUCCESS) {
|
||||||
ASSERT_STRING("AddProductEvent: Could not write the new event value");
|
ASSERT_STRING("AddProductEvent: Could not write the new event value");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -301,14 +294,14 @@ bool RlzValueStoreRegistry::ReadProductEvents(Product product,
|
|||||||
|
|
||||||
bool RlzValueStoreRegistry::ClearProductEvent(Product product,
|
bool RlzValueStoreRegistry::ClearProductEvent(Product product,
|
||||||
const char* event_rlz) {
|
const char* event_rlz) {
|
||||||
std::wstring event_rlz_wide(ASCIIToWide(event_rlz));
|
base::string16 event_rlz16(ASCIIToUTF16(event_rlz));
|
||||||
base::win::RegKey key;
|
base::win::RegKey key;
|
||||||
GetEventsRegKey(kEventsSubkeyName, &product, KEY_WRITE, &key);
|
GetEventsRegKey(kEventsSubkeyName, &product, KEY_WRITE, &key);
|
||||||
key.DeleteValue(event_rlz_wide.c_str());
|
key.DeleteValue(event_rlz16.c_str());
|
||||||
|
|
||||||
// Verify deletion.
|
// Verify deletion.
|
||||||
DWORD value;
|
DWORD value;
|
||||||
if (key.ReadValueDW(event_rlz_wide.c_str(), &value) == ERROR_SUCCESS) {
|
if (key.ReadValueDW(event_rlz16.c_str(), &value) == ERROR_SUCCESS) {
|
||||||
ASSERT_STRING("ClearProductEvent: Could not delete the event value.");
|
ASSERT_STRING("ClearProductEvent: Could not delete the event value.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -323,9 +316,9 @@ bool RlzValueStoreRegistry::ClearAllProductEvents(Product product) {
|
|||||||
bool RlzValueStoreRegistry::AddStatefulEvent(Product product,
|
bool RlzValueStoreRegistry::AddStatefulEvent(Product product,
|
||||||
const char* event_rlz) {
|
const char* event_rlz) {
|
||||||
base::win::RegKey key;
|
base::win::RegKey key;
|
||||||
std::wstring event_rlz_wide(ASCIIToWide(event_rlz));
|
base::string16 event_rlz16(ASCIIToUTF16(event_rlz));
|
||||||
if (!GetEventsRegKey(kStatefulEventsSubkeyName, &product, KEY_WRITE, &key) ||
|
if (!GetEventsRegKey(kStatefulEventsSubkeyName, &product, KEY_WRITE, &key) ||
|
||||||
key.WriteValue(event_rlz_wide.c_str(), 1) != ERROR_SUCCESS) {
|
key.WriteValue(event_rlz16.c_str(), 1) != ERROR_SUCCESS) {
|
||||||
ASSERT_STRING(
|
ASSERT_STRING(
|
||||||
"AddStatefulEvent: Could not write the new stateful event");
|
"AddStatefulEvent: Could not write the new stateful event");
|
||||||
return false;
|
return false;
|
||||||
@@ -339,8 +332,8 @@ bool RlzValueStoreRegistry::IsStatefulEvent(Product product,
|
|||||||
DWORD value;
|
DWORD value;
|
||||||
base::win::RegKey key;
|
base::win::RegKey key;
|
||||||
GetEventsRegKey(kStatefulEventsSubkeyName, &product, KEY_READ, &key);
|
GetEventsRegKey(kStatefulEventsSubkeyName, &product, KEY_READ, &key);
|
||||||
std::wstring event_rlz_wide(ASCIIToWide(event_rlz));
|
base::string16 event_rlz16(ASCIIToUTF16(event_rlz));
|
||||||
return key.ReadValueDW(event_rlz_wide.c_str(), &value) == ERROR_SUCCESS;
|
return key.ReadValueDW(event_rlz16.c_str(), &value) == ERROR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RlzValueStoreRegistry::ClearAllStatefulEvents(Product product) {
|
bool RlzValueStoreRegistry::ClearAllStatefulEvents(Product product) {
|
||||||
@@ -349,7 +342,7 @@ bool RlzValueStoreRegistry::ClearAllStatefulEvents(Product product) {
|
|||||||
|
|
||||||
void RlzValueStoreRegistry::CollectGarbage() {
|
void RlzValueStoreRegistry::CollectGarbage() {
|
||||||
// Delete each of the known subkeys if empty.
|
// Delete each of the known subkeys if empty.
|
||||||
const char* subkeys[] = {
|
const char* const subkeys[] = {
|
||||||
kRlzsSubkeyName,
|
kRlzsSubkeyName,
|
||||||
kEventsSubkeyName,
|
kEventsSubkeyName,
|
||||||
kStatefulEventsSubkeyName,
|
kStatefulEventsSubkeyName,
|
||||||
@@ -360,9 +353,9 @@ void RlzValueStoreRegistry::CollectGarbage() {
|
|||||||
std::string subkey_name;
|
std::string subkey_name;
|
||||||
base::StringAppendF(&subkey_name, "%s\\%s", kLibKeyName, subkeys[i]);
|
base::StringAppendF(&subkey_name, "%s\\%s", kLibKeyName, subkeys[i]);
|
||||||
AppendBrandToString(&subkey_name);
|
AppendBrandToString(&subkey_name);
|
||||||
|
base::string16 subkey_name16 = ASCIIToUTF16(subkey_name);
|
||||||
|
|
||||||
VERIFY(DeleteKeyIfEmpty(HKEY_CURRENT_USER,
|
VERIFY(DeleteKeyIfEmpty(HKEY_CURRENT_USER, subkey_name16.c_str()));
|
||||||
ASCIIToWide(subkey_name).c_str()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete the library key and its parents too now if empty.
|
// Delete the library key and its parents too now if empty.
|
||||||
|
Reference in New Issue
Block a user