Commit 0cf1e27f authored by Jan Wilken Dörrie's avatar Jan Wilken Dörrie Committed by Commit Bot

[string16] Use explicit std::wstring in //base/win

This change makes std::wstring usage explicit in //base/win. Exposing
std::wstring in the //base/win interfaces will make it easier to
prepare other Windows only code for a future where base::string16 is
no longer std::wstring.

Bug: 911896
Change-Id: I7f214d0ea1d72d80f8b510eb9e22ae7ef1a2f988
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1789388
Commit-Queue: Jan Wilken Dörrie <jdoerrie@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#695547}
parent 80bbdd4d
......@@ -269,6 +269,24 @@ inline const char16* as_u16cstr(const wchar_t* str) {
inline const char16* as_u16cstr(WStringPiece str) {
return reinterpret_cast<const char16*>(str.data());
}
// Utility functions to convert between base::WStringPiece and
// base::StringPiece16.
inline WStringPiece AsWStringPiece(StringPiece16 str) {
return WStringPiece(as_wcstr(str.data()), str.size());
}
inline StringPiece16 AsStringPiece16(WStringPiece str) {
return StringPiece16(as_u16cstr(str.data()), str.size());
}
inline std::wstring AsWString(StringPiece16 str) {
return std::wstring(as_wcstr(str.data()), str.size());
}
inline string16 AsString16(WStringPiece str) {
return string16(as_u16cstr(str.data()), str.size());
}
#endif // defined(WCHAR_T_IS_UTF16)
// Trims any whitespace from either end of the input string.
......
......@@ -34,7 +34,7 @@ namespace {
std::string* g_event_source_name = nullptr;
uint16_t g_category = 0;
uint32_t g_event_id = 0;
base::string16* g_user_sid = nullptr;
std::wstring* g_user_sid = nullptr;
} // namespace
......@@ -46,7 +46,7 @@ void SetEventSource(const std::string& name,
g_category = category;
g_event_id = event_id;
DCHECK_EQ(nullptr, g_user_sid);
g_user_sid = new base::string16();
g_user_sid = new std::wstring();
base::win::GetUserSidString(g_user_sid);
}
......@@ -102,7 +102,7 @@ EventLogMessage::~EventLogMessage() {
}
LPCSTR strings[1] = {message.data()};
PSID user_sid = nullptr;
if (!::ConvertStringSidToSid(base::as_wcstr(*g_user_sid), &user_sid)) {
if (!::ConvertStringSidToSid(g_user_sid->c_str(), &user_sid)) {
stream() << " !!ERROR GETTING USER SID!!";
}
......
......@@ -171,9 +171,9 @@ SysInfo::HardwareInfo SysInfo::GetHardwareInfoSync() {
win::WmiComputerSystemInfo wmi_info = win::WmiComputerSystemInfo::Get();
HardwareInfo info;
info.manufacturer = UTF16ToUTF8(wmi_info.manufacturer());
info.model = UTF16ToUTF8(wmi_info.model());
info.serial_number = UTF16ToUTF8(wmi_info.serial_number());
info.manufacturer = WideToUTF8(wmi_info.manufacturer());
info.model = WideToUTF8(wmi_info.model());
info.serial_number = WideToUTF8(wmi_info.serial_number());
DCHECK(IsStringUTF8(info.manufacturer));
DCHECK(IsStringUTF8(info.model));
DCHECK(IsStringUTF8(info.serial_number));
......
......@@ -9,6 +9,7 @@
#include "base/guid.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
......@@ -21,12 +22,11 @@ namespace registry_util {
namespace {
const base::char16 kTimestampDelimiter[] = STRING16_LITERAL("$");
const base::char16 kTempTestKeyPath[] =
STRING16_LITERAL("Software\\Chromium\\TempTestKeys");
constexpr base::char16 kTimestampDelimiter[] = STRING16_LITERAL("$");
constexpr wchar_t kTempTestKeyPath[] = L"Software\\Chromium\\TempTestKeys";
void DeleteStaleTestKeys(const base::Time& now,
const base::string16& test_key_root) {
const std::wstring& test_key_root) {
base::win::RegKey test_root_key;
if (test_root_key.Open(HKEY_CURRENT_USER,
test_key_root.c_str(),
......@@ -38,10 +38,10 @@ void DeleteStaleTestKeys(const base::Time& now,
base::win::RegistryKeyIterator iterator_test_root_key(HKEY_CURRENT_USER,
test_key_root.c_str());
for (; iterator_test_root_key.Valid(); ++iterator_test_root_key) {
base::string16 key_name = iterator_test_root_key.Name();
std::vector<base::string16> tokens = base::SplitString(
key_name, kTimestampDelimiter, base::KEEP_WHITESPACE,
base::SPLIT_WANT_NONEMPTY);
std::wstring key_name = iterator_test_root_key.Name();
std::vector<base::StringPiece16> tokens = base::SplitStringPiece(
base::AsStringPiece16(key_name), kTimestampDelimiter,
base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
if (tokens.empty())
continue;
int64_t key_name_as_number = 0;
......@@ -59,27 +59,25 @@ void DeleteStaleTestKeys(const base::Time& now,
}
}
base::string16 GenerateTempKeyPath(const base::string16& test_key_root,
const base::Time& timestamp) {
base::string16 key_path = test_key_root;
key_path += STRING16_LITERAL("\\") +
base::NumberToString16(timestamp.ToInternalValue());
key_path += kTimestampDelimiter + base::ASCIIToUTF16(base::GenerateGUID());
return key_path;
std::wstring GenerateTempKeyPath(const std::wstring& test_key_root,
const base::Time& timestamp) {
return base::AsWString(base::StrCat(
{base::AsStringPiece16(test_key_root), STRING16_LITERAL("\\"),
base::NumberToString16(timestamp.ToInternalValue()), kTimestampDelimiter,
base::ASCIIToUTF16(base::GenerateGUID())}));
}
} // namespace
RegistryOverrideManager::ScopedRegistryKeyOverride::ScopedRegistryKeyOverride(
HKEY override,
const base::string16& key_path)
const std::wstring& key_path)
: override_(override), key_path_(key_path) {}
RegistryOverrideManager::
ScopedRegistryKeyOverride::~ScopedRegistryKeyOverride() {
::RegOverridePredefKey(override_, NULL);
base::win::RegKey(HKEY_CURRENT_USER, STRING16_LITERAL(""), KEY_QUERY_VALUE)
base::win::RegKey(HKEY_CURRENT_USER, L"", KEY_QUERY_VALUE)
.DeleteKey(key_path_.c_str());
}
......@@ -90,7 +88,7 @@ RegistryOverrideManager::RegistryOverrideManager()
RegistryOverrideManager::RegistryOverrideManager(
const base::Time& timestamp,
const base::string16& test_key_root)
const std::wstring& test_key_root)
: timestamp_(timestamp), test_key_root_(test_key_root) {
DeleteStaleTestKeys(timestamp_, test_key_root_);
}
......@@ -102,8 +100,8 @@ void RegistryOverrideManager::OverrideRegistry(HKEY override) {
}
void RegistryOverrideManager::OverrideRegistry(HKEY override,
base::string16* override_path) {
base::string16 key_path = GenerateTempKeyPath(test_key_root_, timestamp_);
std::wstring* override_path) {
std::wstring key_path = GenerateTempKeyPath(test_key_root_, timestamp_);
base::win::RegKey temp_key;
ASSERT_EQ(ERROR_SUCCESS, temp_key.Create(HKEY_CURRENT_USER, key_path.c_str(),
......@@ -116,9 +114,8 @@ void RegistryOverrideManager::OverrideRegistry(HKEY override,
override_path->assign(key_path);
}
base::string16 GenerateTempKeyPath() {
return GenerateTempKeyPath(base::string16(kTempTestKeyPath),
base::Time::Now());
std::wstring GenerateTempKeyPath() {
return GenerateTempKeyPath(kTempTestKeyPath, base::Time::Now());
}
} // namespace registry_util
......@@ -7,10 +7,10 @@
// Registry utility functions used only by tests.
#include <memory>
#include <string>
#include <vector>
#include "base/macros.h"
#include "base/strings/string16.h"
#include "base/time/time.h"
#include "base/win/registry.h"
......@@ -42,7 +42,7 @@ class RegistryOverrideManager {
// Calls to these functions must be wrapped in ASSERT_NO_FATAL_FAILURE to
// ensure that tests do not proceeed in case of failure to override.
void OverrideRegistry(HKEY override);
void OverrideRegistry(HKEY override, base::string16* override_path);
void OverrideRegistry(HKEY override, std::wstring* override_path);
private:
friend class RegistryOverrideManagerTest;
......@@ -50,24 +50,24 @@ class RegistryOverrideManager {
// Keeps track of one override.
class ScopedRegistryKeyOverride {
public:
ScopedRegistryKeyOverride(HKEY override, const base::string16& key_path);
ScopedRegistryKeyOverride(HKEY override, const std::wstring& key_path);
~ScopedRegistryKeyOverride();
private:
HKEY override_;
base::string16 key_path_;
std::wstring key_path_;
DISALLOW_COPY_AND_ASSIGN(ScopedRegistryKeyOverride);
};
// Used for testing only.
RegistryOverrideManager(const base::Time& timestamp,
const base::string16& test_key_root);
const std::wstring& test_key_root);
base::Time timestamp_;
base::string16 guid_;
std::wstring guid_;
base::string16 test_key_root_;
std::wstring test_key_root_;
std::vector<std::unique_ptr<ScopedRegistryKeyOverride>> overrides_;
DISALLOW_COPY_AND_ASSIGN(RegistryOverrideManager);
......@@ -75,7 +75,7 @@ class RegistryOverrideManager {
// Generates a temporary key path that will be eventually deleted
// automatically if the process crashes.
base::string16 GenerateTempKeyPath();
std::wstring GenerateTempKeyPath();
} // namespace registry_util
......
......@@ -8,6 +8,7 @@
#include "base/compiler_specific.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -15,9 +16,8 @@
namespace registry_util {
namespace {
const base::char16 kTestKeyPath[] =
STRING16_LITERAL("Software\\Chromium\\Foo\\Baz\\TestKey");
const base::char16 kTestValueName[] = STRING16_LITERAL("TestValue");
const wchar_t kTestKeyPath[] = L"Software\\Chromium\\Foo\\Baz\\TestKey";
const wchar_t kTestValueName[] = L"TestValue";
} // namespace
class RegistryOverrideManagerTest : public testing::Test {
......@@ -40,29 +40,29 @@ class RegistryOverrideManagerTest : public testing::Test {
key.DeleteKey(fake_test_key_root_.c_str());
}
void AssertKeyExists(const base::string16& key_path) {
void AssertKeyExists(const std::wstring& key_path) {
base::win::RegKey key;
ASSERT_EQ(ERROR_SUCCESS,
key.Open(HKEY_CURRENT_USER, key_path.c_str(), KEY_READ))
<< key_path << " does not exist.";
}
void AssertKeyAbsent(const base::string16& key_path) {
void AssertKeyAbsent(const std::wstring& key_path) {
base::win::RegKey key;
ASSERT_NE(ERROR_SUCCESS,
key.Open(HKEY_CURRENT_USER, key_path.c_str(), KEY_READ))
<< key_path << " exists but it should not.";
}
void CreateKey(const base::string16& key_path) {
void CreateKey(const std::wstring& key_path) {
base::win::RegKey key;
ASSERT_EQ(ERROR_SUCCESS,
key.Create(HKEY_CURRENT_USER, key_path.c_str(), KEY_ALL_ACCESS));
}
base::string16 FakeOverrideManagerPath(const base::Time& time) {
return fake_test_key_root_ + STRING16_LITERAL("\\") +
base::NumberToString16(time.ToInternalValue());
std::wstring FakeOverrideManagerPath(const base::Time& time) {
return fake_test_key_root_ + L"\\" +
base::AsWString(base::NumberToString16(time.ToInternalValue()));
}
void CreateManager(const base::Time& timestamp) {
......@@ -70,7 +70,7 @@ class RegistryOverrideManagerTest : public testing::Test {
manager_->OverrideRegistry(HKEY_CURRENT_USER);
}
base::string16 fake_test_key_root_;
std::wstring fake_test_key_root_;
std::unique_ptr<RegistryOverrideManager> manager_;
};
......@@ -105,15 +105,14 @@ TEST_F(RegistryOverrideManagerTest, DeleteStaleKeys) {
base::Time kTestTime;
EXPECT_TRUE(base::Time::FromUTCExploded(kTestTimeExploded, &kTestTime));
base::string16 path_garbage =
fake_test_key_root_ + STRING16_LITERAL("\\Blah");
base::string16 path_very_stale =
std::wstring path_garbage = fake_test_key_root_ + L"\\Blah";
std::wstring path_very_stale =
FakeOverrideManagerPath(kTestTime - base::TimeDelta::FromDays(100));
base::string16 path_stale =
std::wstring path_stale =
FakeOverrideManagerPath(kTestTime - base::TimeDelta::FromDays(5));
base::string16 path_current =
std::wstring path_current =
FakeOverrideManagerPath(kTestTime - base::TimeDelta::FromMinutes(1));
base::string16 path_future =
std::wstring path_future =
FakeOverrideManagerPath(kTestTime + base::TimeDelta::FromMinutes(1));
ASSERT_NO_FATAL_FAILURE(CreateKey(path_garbage));
......
......@@ -22,8 +22,8 @@ namespace win {
void ValidatePathsAreEqual(const FilePath& expected_path,
const FilePath& actual_path) {
char16 long_expected_path_chars[MAX_PATH] = {0};
char16 long_actual_path_chars[MAX_PATH] = {0};
wchar_t long_expected_path_chars[MAX_PATH] = {0};
wchar_t long_actual_path_chars[MAX_PATH] = {0};
// If |expected_path| is empty confirm immediately that |actual_path| is also
// empty.
......@@ -34,16 +34,14 @@ void ValidatePathsAreEqual(const FilePath& expected_path,
// Proceed with LongPathName matching which will also confirm the paths exist.
EXPECT_NE(0U, ::GetLongPathName(as_wcstr(expected_path.value()),
as_writable_wcstr(long_expected_path_chars),
MAX_PATH))
long_expected_path_chars, MAX_PATH))
<< "Failed to get LongPathName of " << expected_path.value();
EXPECT_NE(0U, ::GetLongPathName(as_wcstr(actual_path.value()),
as_writable_wcstr(long_actual_path_chars),
MAX_PATH))
long_actual_path_chars, MAX_PATH))
<< "Failed to get LongPathName of " << actual_path.value();
FilePath long_expected_path(long_expected_path_chars);
FilePath long_actual_path(long_actual_path_chars);
FilePath long_expected_path(AsStringPiece16(long_expected_path_chars));
FilePath long_actual_path(AsStringPiece16(long_actual_path_chars));
EXPECT_FALSE(long_expected_path.empty());
EXPECT_FALSE(long_actual_path.empty());
......@@ -55,11 +53,11 @@ void ValidateShortcut(const FilePath& shortcut_path,
Microsoft::WRL::ComPtr<IShellLink> i_shell_link;
Microsoft::WRL::ComPtr<IPersistFile> i_persist_file;
char16 read_target[MAX_PATH] = {0};
char16 read_working_dir[MAX_PATH] = {0};
char16 read_arguments[MAX_PATH] = {0};
char16 read_description[MAX_PATH] = {0};
char16 read_icon[MAX_PATH] = {0};
wchar_t read_target[MAX_PATH] = {0};
wchar_t read_working_dir[MAX_PATH] = {0};
wchar_t read_arguments[MAX_PATH] = {0};
wchar_t read_description[MAX_PATH] = {0};
wchar_t read_icon[MAX_PATH] = {0};
int read_icon_index = 0;
HRESULT hr;
......@@ -84,33 +82,36 @@ void ValidateShortcut(const FilePath& shortcut_path,
return;
if (properties.options & ShortcutProperties::PROPERTIES_TARGET) {
EXPECT_TRUE(SUCCEEDED(i_shell_link->GetPath(
as_writable_wcstr(read_target), MAX_PATH, NULL, SLGP_SHORTPATH)));
ValidatePathsAreEqual(properties.target, FilePath(read_target));
EXPECT_TRUE(SUCCEEDED(
i_shell_link->GetPath(read_target, MAX_PATH, NULL, SLGP_SHORTPATH)));
ValidatePathsAreEqual(properties.target,
FilePath(AsStringPiece16(read_target)));
}
if (properties.options & ShortcutProperties::PROPERTIES_WORKING_DIR) {
EXPECT_TRUE(SUCCEEDED(i_shell_link->GetWorkingDirectory(
as_writable_wcstr(read_working_dir), MAX_PATH)));
ValidatePathsAreEqual(properties.working_dir, FilePath(read_working_dir));
EXPECT_TRUE(SUCCEEDED(
i_shell_link->GetWorkingDirectory(read_working_dir, MAX_PATH)));
ValidatePathsAreEqual(properties.working_dir,
FilePath(AsStringPiece16(read_working_dir)));
}
if (properties.options & ShortcutProperties::PROPERTIES_ARGUMENTS) {
EXPECT_TRUE(SUCCEEDED(i_shell_link->GetArguments(
as_writable_wcstr(read_arguments), MAX_PATH)));
EXPECT_TRUE(
SUCCEEDED(i_shell_link->GetArguments(read_arguments, MAX_PATH)));
EXPECT_EQ(properties.arguments, read_arguments);
}
if (properties.options & ShortcutProperties::PROPERTIES_DESCRIPTION) {
EXPECT_TRUE(SUCCEEDED(i_shell_link->GetDescription(
as_writable_wcstr(read_description), MAX_PATH)));
EXPECT_TRUE(
SUCCEEDED(i_shell_link->GetDescription(read_description, MAX_PATH)));
EXPECT_EQ(properties.description, read_description);
}
if (properties.options & ShortcutProperties::PROPERTIES_ICON) {
EXPECT_TRUE(SUCCEEDED(i_shell_link->GetIconLocation(
as_writable_wcstr(read_icon), MAX_PATH, &read_icon_index)));
ValidatePathsAreEqual(properties.icon, FilePath(read_icon));
EXPECT_TRUE(SUCCEEDED(
i_shell_link->GetIconLocation(read_icon, MAX_PATH, &read_icon_index)));
ValidatePathsAreEqual(properties.icon,
FilePath(AsStringPiece16(read_icon)));
EXPECT_EQ(properties.icon_index, read_icon_index);
}
......@@ -129,7 +130,7 @@ void ValidateShortcut(const FilePath& shortcut_path,
EXPECT_TRUE(properties.app_id.empty());
break;
case VT_LPWSTR:
EXPECT_EQ(properties.app_id, WideToUTF16(pv_app_id.get().pwszVal));
EXPECT_EQ(properties.app_id, pv_app_id.get().pwszVal);
break;
default:
ADD_FAILURE() << "Unexpected variant type: " << pv_app_id.get().vt;
......
......@@ -259,13 +259,11 @@ TEST(TimeTicks, TSCTicksPerSecond) {
// Read the CPU frequency from the registry.
base::win::RegKey processor_key(
HKEY_LOCAL_MACHINE,
STRING16_LITERAL("Hardware\\Description\\System\\CentralProcessor\\0"),
KEY_QUERY_VALUE);
L"Hardware\\Description\\System\\CentralProcessor\\0", KEY_QUERY_VALUE);
ASSERT_TRUE(processor_key.Valid());
DWORD processor_mhz_from_registry;
ASSERT_EQ(ERROR_SUCCESS,
processor_key.ReadValueDW(STRING16_LITERAL("~MHz"),
&processor_mhz_from_registry));
processor_key.ReadValueDW(L"~MHz", &processor_mhz_from_registry));
// Expect the measured TSC frequency to be similar to the processor
// frequency from the registry (0.5% error).
......
This diff is collapsed.
......@@ -8,13 +8,13 @@
#ifndef BASE_WIN_EMBEDDED_I18N_LANGUAGE_SELECTOR_H_
#define BASE_WIN_EMBEDDED_I18N_LANGUAGE_SELECTOR_H_
#include <string>
#include <utility>
#include <vector>
#include "base/base_export.h"
#include "base/containers/span.h"
#include "base/macros.h"
#include "base/strings/string16.h"
#include "base/strings/string_piece.h"
namespace base {
......@@ -26,7 +26,7 @@ namespace i18n {
// override selection should a corresponding translation be available.
class BASE_EXPORT LanguageSelector {
public:
using LangToOffset = std::pair<base::StringPiece16, int>;
using LangToOffset = std::pair<WStringPiece, int>;
// Constructor to be used for users of this class that will provide the actual
// language offsets that will be used.
......@@ -36,8 +36,8 @@ class BASE_EXPORT LanguageSelector {
// |languages_to_offset_begin| and |languages_to_offset_end| point to a sorted
// array of language identifiers (and their offsets) for which translations
// are available.
LanguageSelector(base::StringPiece16 preferred_language,
base::span<const LangToOffset> languages_to_offset);
LanguageSelector(WStringPiece preferred_language,
span<const LangToOffset> languages_to_offset);
// Constructor for testing purposes.
// |candidates| is a list of all candiate languages that can be used to
......@@ -45,8 +45,8 @@ class BASE_EXPORT LanguageSelector {
// |languages_to_offset_begin| and |languages_to_offset_end| point to a sorted
// array of language identifiers (and their offsets) for which translations
// are available.
LanguageSelector(const std::vector<base::string16>& candidates,
base::span<const LangToOffset> languages_to_offset);
LanguageSelector(const std::vector<std::wstring>& candidates,
span<const LangToOffset> languages_to_offset);
~LanguageSelector();
......@@ -54,16 +54,16 @@ class BASE_EXPORT LanguageSelector {
int offset() const { return selected_offset_; }
// The full name of the candidate language for which a match was found.
const base::string16& matched_candidate() const { return matched_candidate_; }
const std::wstring& matched_candidate() const { return matched_candidate_; }
// The name of the selected translation.
const base::string16& selected_translation() const {
const std::wstring& selected_translation() const {
return selected_language_;
}
private:
base::string16 matched_candidate_;
base::string16 selected_language_;
std::wstring matched_candidate_;
std::wstring selected_language_;
int selected_offset_;
DISALLOW_COPY_AND_ASSIGN(LanguageSelector);
......
......@@ -16,7 +16,7 @@ typedef decltype(::GetSystemPreferredUILanguages)* GetPreferredUILanguages_Fn;
bool GetPreferredUILanguageList(GetPreferredUILanguages_Fn function,
ULONG flags,
std::vector<base::string16>* languages) {
std::vector<std::wstring>* languages) {
DCHECK_EQ((flags & (MUI_LANGUAGE_ID | MUI_LANGUAGE_NAME)), 0U);
const ULONG call_flags = flags | MUI_LANGUAGE_NAME;
ULONG language_count = 0;
......@@ -27,18 +27,21 @@ bool GetPreferredUILanguageList(GetPreferredUILanguages_Fn function,
return false;
}
base::string16 buffer(buffer_length, '\0');
if (!function(call_flags, &language_count, base::as_writable_wcstr(buffer),
std::wstring buffer(buffer_length, '\0');
if (!function(call_flags, &language_count, base::data(buffer),
&buffer_length) ||
!language_count) {
DPCHECK(!language_count) << "Failed getting preferred UI languages.";
return false;
}
languages->clear();
// Split string on NUL characters.
*languages =
base::SplitString(buffer, base::string16(1, '\0'), base::KEEP_WHITESPACE,
base::SPLIT_WANT_NONEMPTY);
for (const auto& token : base::SplitStringPiece(
base::AsStringPiece16(buffer), base::string16(1, '\0'),
base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY)) {
languages->push_back(base::AsWString(token));
}
DCHECK_EQ(languages->size(), language_count);
return true;
}
......@@ -49,13 +52,13 @@ namespace base {
namespace win {
namespace i18n {
bool GetUserPreferredUILanguageList(std::vector<base::string16>* languages) {
bool GetUserPreferredUILanguageList(std::vector<std::wstring>* languages) {
DCHECK(languages);
return GetPreferredUILanguageList(::GetUserPreferredUILanguages, 0,
languages);
}
bool GetThreadPreferredUILanguageList(std::vector<base::string16>* languages) {
bool GetThreadPreferredUILanguageList(std::vector<std::wstring>* languages) {
DCHECK(languages);
return GetPreferredUILanguageList(
::GetThreadPreferredUILanguages,
......
......@@ -5,10 +5,10 @@
#ifndef BASE_WIN_I18N_H_
#define BASE_WIN_I18N_H_
#include <string>
#include <vector>
#include "base/base_export.h"
#include "base/strings/string16.h"
namespace base {
namespace win {
......@@ -18,13 +18,13 @@ namespace i18n {
// available, falling-back on the user default UI language otherwise. Returns
// true if at least one language is added.
BASE_EXPORT bool GetUserPreferredUILanguageList(
std::vector<base::string16>* languages);
std::vector<std::wstring>* languages);
// Adds to |languages| the list of thread, process, user, and system preferred
// UI languages from MUI, if available, falling-back on the user default UI
// language otherwise. Returns true if at least one language is added.
BASE_EXPORT bool GetThreadPreferredUILanguageList(
std::vector<base::string16>* languages);
std::vector<std::wstring>* languages);
} // namespace i18n
} // namespace win
......
......@@ -19,24 +19,24 @@ namespace i18n {
// Tests that at least one user preferred UI language can be obtained.
TEST(I18NTest, GetUserPreferredUILanguageList) {
std::vector<base::string16> languages;
std::vector<std::wstring> languages;
EXPECT_TRUE(GetUserPreferredUILanguageList(&languages));
EXPECT_FALSE(languages.empty());
for (const auto& language : languages) {
EXPECT_FALSE(language.empty());
// Ensure there's no extra trailing 0 characters.
EXPECT_EQ(language.size(), wcslen(base::as_wcstr(language)));
EXPECT_EQ(language.size(), wcslen(language.c_str()));
}
}
// Tests that at least one thread preferred UI language can be obtained.
TEST(I18NTest, GetThreadPreferredUILanguageList) {
std::vector<base::string16> languages;
std::vector<std::wstring> languages;
EXPECT_TRUE(GetThreadPreferredUILanguageList(&languages));
EXPECT_FALSE(languages.empty());
for (const auto& language : languages) {
EXPECT_FALSE(language.empty());
EXPECT_EQ(language.size(), wcslen(base::as_wcstr(language)));
EXPECT_EQ(language.size(), wcslen(language.c_str()));
}
}
......
This diff is collapsed.
......@@ -8,12 +8,12 @@
#include <stdint.h>
#include <memory>
#include <string>
#include <vector>
#include "base/base_export.h"
#include "base/callback.h"
#include "base/macros.h"
#include "base/strings/string16.h"
#include "base/win/object_watcher.h"
#include "base/win/scoped_handle.h"
#include "base/win/windows_types.h"
......@@ -37,24 +37,24 @@ class BASE_EXPORT RegKey {
RegKey();
explicit RegKey(HKEY key);
RegKey(HKEY rootkey, const char16* subkey, REGSAM access);
RegKey(HKEY rootkey, const wchar_t* subkey, REGSAM access);
~RegKey();
LONG Create(HKEY rootkey, const char16* subkey, REGSAM access);
LONG Create(HKEY rootkey, const wchar_t* subkey, REGSAM access);
LONG CreateWithDisposition(HKEY rootkey,
const char16* subkey,
const wchar_t* subkey,
DWORD* disposition,
REGSAM access);
// Creates a subkey or open it if it already exists.
LONG CreateKey(const char16* name, REGSAM access);
LONG CreateKey(const wchar_t* name, REGSAM access);
// Opens an existing reg key.
LONG Open(HKEY rootkey, const char16* subkey, REGSAM access);
LONG Open(HKEY rootkey, const wchar_t* subkey, REGSAM access);
// Opens an existing reg key, given the relative key name.
LONG OpenKey(const char16* relative_key_name, REGSAM access);
LONG OpenKey(const wchar_t* relative_key_name, REGSAM access);
// Closes this reg key.
void Close();
......@@ -67,51 +67,51 @@ class BASE_EXPORT RegKey {
// Returns false if this key does not have the specified value, or if an error
// occurrs while attempting to access it.
bool HasValue(const char16* value_name) const;
bool HasValue(const wchar_t* value_name) const;
// Returns the number of values for this key, or 0 if the number cannot be
// determined.
DWORD GetValueCount() const;
// Determines the nth value's name.
LONG GetValueNameAt(int index, string16* name) const;
LONG GetValueNameAt(int index, std::wstring* name) const;
// True while the key is valid.
bool Valid() const { return key_ != NULL; }
// Kills a key and everything that lives below it; please be careful when
// using it.
LONG DeleteKey(const char16* name);
LONG DeleteKey(const wchar_t* name);
// Deletes an empty subkey. If the subkey has subkeys or values then this
// will fail.
LONG DeleteEmptyKey(const char16* name);
LONG DeleteEmptyKey(const wchar_t* name);
// Deletes a single value within the key.
LONG DeleteValue(const char16* name);
LONG DeleteValue(const wchar_t* name);
// Getters:
// Reads a REG_DWORD (uint32_t) into |out_value|. If |name| is null or empty,
// reads the key's default value, if any.
LONG ReadValueDW(const char16* name, DWORD* out_value) const;
LONG ReadValueDW(const wchar_t* name, DWORD* out_value) const;
// Reads a REG_QWORD (int64_t) into |out_value|. If |name| is null or empty,
// reads the key's default value, if any.
LONG ReadInt64(const char16* name, int64_t* out_value) const;
LONG ReadInt64(const wchar_t* name, int64_t* out_value) const;
// Reads a string into |out_value|. If |name| is null or empty, reads
// the key's default value, if any.
LONG ReadValue(const char16* name, string16* out_value) const;
LONG ReadValue(const wchar_t* name, std::wstring* out_value) const;
// Reads a REG_MULTI_SZ registry field into a vector of strings. Clears
// |values| initially and adds further strings to the list. Returns
// ERROR_CANTREAD if type is not REG_MULTI_SZ.
LONG ReadValues(const char16* name, std::vector<string16>* values);
LONG ReadValues(const wchar_t* name, std::vector<std::wstring>* values);
// Reads raw data into |data|. If |name| is null or empty, reads the key's
// default value, if any.
LONG ReadValue(const char16* name,
LONG ReadValue(const wchar_t* name,
void* data,
DWORD* dsize,
DWORD* dtype) const;
......@@ -119,13 +119,13 @@ class BASE_EXPORT RegKey {
// Setters:
// Sets an int32_t value.
LONG WriteValue(const char16* name, DWORD in_value);
LONG WriteValue(const wchar_t* name, DWORD in_value);
// Sets a string value.
LONG WriteValue(const char16* name, const char16* in_value);
LONG WriteValue(const wchar_t* name, const wchar_t* in_value);
// Sets raw data, including type.
LONG WriteValue(const char16* name,
LONG WriteValue(const wchar_t* name,
const void* data,
DWORD dsize,
DWORD dtype);
......@@ -143,7 +143,7 @@ class BASE_EXPORT RegKey {
class Watcher;
// Recursively deletes a key and all of its subkeys.
static LONG RegDelRecurse(HKEY root_key, const char16* name, REGSAM access);
static LONG RegDelRecurse(HKEY root_key, const wchar_t* name, REGSAM access);
HKEY key_; // The registry key being iterated.
REGSAM wow64access_;
......@@ -156,7 +156,7 @@ class BASE_EXPORT RegKey {
class BASE_EXPORT RegistryValueIterator {
public:
// Constructs a Registry Value Iterator with default WOW64 access.
RegistryValueIterator(HKEY root_key, const char16* folder_key);
RegistryValueIterator(HKEY root_key, const wchar_t* folder_key);
// Constructs a Registry Key Iterator with specific WOW64 access, one of
// KEY_WOW64_32KEY or KEY_WOW64_64KEY, or 0.
......@@ -164,7 +164,7 @@ class BASE_EXPORT RegistryValueIterator {
// previously, or a predefined key (e.g. HKEY_LOCAL_MACHINE).
// See http://msdn.microsoft.com/en-us/library/windows/desktop/aa384129.aspx.
RegistryValueIterator(HKEY root_key,
const char16* folder_key,
const wchar_t* folder_key,
REGSAM wow64access);
~RegistryValueIterator();
......@@ -177,8 +177,8 @@ class BASE_EXPORT RegistryValueIterator {
// Advances to the next registry entry.
void operator++();
const char16* Name() const { return name_.c_str(); }
const char16* Value() const { return value_.data(); }
const wchar_t* Name() const { return name_.c_str(); }
const wchar_t* Value() const { return value_.data(); }
// ValueSize() is in bytes.
DWORD ValueSize() const { return value_size_; }
DWORD Type() const { return type_; }
......@@ -189,7 +189,7 @@ class BASE_EXPORT RegistryValueIterator {
// Reads in the current values.
bool Read();
void Initialize(HKEY root_key, const char16* folder_key, REGSAM wow64access);
void Initialize(HKEY root_key, const wchar_t* folder_key, REGSAM wow64access);
// The registry key being iterated.
HKEY key_;
......@@ -198,8 +198,8 @@ class BASE_EXPORT RegistryValueIterator {
int index_;
// Current values.
string16 name_;
std::vector<char16> value_;
std::wstring name_;
std::vector<wchar_t> value_;
DWORD value_size_;
DWORD type_;
......@@ -209,7 +209,7 @@ class BASE_EXPORT RegistryValueIterator {
class BASE_EXPORT RegistryKeyIterator {
public:
// Constructs a Registry Key Iterator with default WOW64 access.
RegistryKeyIterator(HKEY root_key, const char16* folder_key);
RegistryKeyIterator(HKEY root_key, const wchar_t* folder_key);
// Constructs a Registry Value Iterator with specific WOW64 access, one of
// KEY_WOW64_32KEY or KEY_WOW64_64KEY, or 0.
......@@ -217,7 +217,7 @@ class BASE_EXPORT RegistryKeyIterator {
// previously, or a predefined key (e.g. HKEY_LOCAL_MACHINE).
// See http://msdn.microsoft.com/en-us/library/windows/desktop/aa384129.aspx.
RegistryKeyIterator(HKEY root_key,
const char16* folder_key,
const wchar_t* folder_key,
REGSAM wow64access);
~RegistryKeyIterator();
......@@ -230,7 +230,7 @@ class BASE_EXPORT RegistryKeyIterator {
// Advances to the next entry in the folder.
void operator++();
const char16* Name() const { return name_; }
const wchar_t* Name() const { return name_; }
int Index() const { return index_; }
......@@ -238,7 +238,7 @@ class BASE_EXPORT RegistryKeyIterator {
// Reads in the current values.
bool Read();
void Initialize(HKEY root_key, const char16* folder_key, REGSAM wow64access);
void Initialize(HKEY root_key, const wchar_t* folder_key, REGSAM wow64access);
// The registry key being iterated.
HKEY key_;
......@@ -246,7 +246,7 @@ class BASE_EXPORT RegistryKeyIterator {
// Current index of the iteration.
int index_;
char16 name_[MAX_PATH];
wchar_t name_[MAX_PATH];
DISALLOW_COPY_AND_ASSIGN(RegistryKeyIterator);
};
......
This diff is collapsed.
......@@ -16,8 +16,8 @@ namespace win {
namespace {
BSTR AllocBstrOrDie(StringPiece16 non_bstr) {
BSTR result = ::SysAllocStringLen(as_wcstr(non_bstr),
BSTR AllocBstrOrDie(WStringPiece non_bstr) {
BSTR result = ::SysAllocStringLen(non_bstr.data(),
checked_cast<UINT>(non_bstr.length()));
if (!result) {
base::TerminateBecauseOutOfMemory((non_bstr.length() + 1) *
......@@ -35,7 +35,7 @@ BSTR AllocBstrBytesOrDie(size_t bytes) {
} // namespace
ScopedBstr::ScopedBstr(StringPiece16 non_bstr)
ScopedBstr::ScopedBstr(WStringPiece non_bstr)
: bstr_(AllocBstrOrDie(non_bstr)) {}
ScopedBstr::~ScopedBstr() {
......@@ -68,7 +68,7 @@ BSTR* ScopedBstr::Receive() {
return &bstr_;
}
BSTR ScopedBstr::Allocate(StringPiece16 str) {
BSTR ScopedBstr::Allocate(WStringPiece str) {
Reset(AllocBstrOrDie(str));
return bstr_;
}
......
......@@ -12,7 +12,6 @@
#include "base/base_export.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/strings/string16.h"
#include "base/strings/string_piece.h"
namespace base {
......@@ -28,7 +27,7 @@ class BASE_EXPORT ScopedBstr {
//
// NOTE: Do not pass a BSTR to this constructor expecting ownership to
// be transferred - even though it compiles! ;-)
explicit ScopedBstr(StringPiece16 non_bstr);
explicit ScopedBstr(WStringPiece non_bstr);
~ScopedBstr();
// Give ScopedBstr ownership over an already allocated BSTR or null.
......@@ -44,7 +43,7 @@ class BASE_EXPORT ScopedBstr {
// ScopedBstr instance, call |reset| instead.
//
// Returns a pointer to the new BSTR.
BSTR Allocate(StringPiece16 str);
BSTR Allocate(WStringPiece str);
// Allocates a new BSTR with the specified number of bytes.
// Returns a pointer to the new BSTR.
......
......@@ -7,8 +7,6 @@
#include <stddef.h>
#include "base/stl_util.h"
#include "base/strings/string16.h"
#include "base/strings/string_util.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace base {
......@@ -16,8 +14,8 @@ namespace win {
namespace {
static const char16 kTestString1[] = STRING16_LITERAL("123");
static const char16 kTestString2[] = STRING16_LITERAL("456789");
static const wchar_t kTestString1[] = L"123";
static const wchar_t kTestString2[] = L"456789";
size_t test1_len = size(kTestString1) - 1;
size_t test2_len = size(kTestString2) - 1;
......@@ -35,7 +33,7 @@ void DumbBstrTests() {
}
void GiveMeABstr(BSTR* ret) {
*ret = SysAllocString(as_wcstr(kTestString1));
*ret = SysAllocString(kTestString1);
}
void BasicBstrTests() {
......@@ -47,10 +45,10 @@ void BasicBstrTests() {
b1.Swap(b2);
EXPECT_EQ(test1_len, b2.Length());
EXPECT_EQ(0u, b1.Length());
EXPECT_STREQ(b2, as_wcstr(kTestString1));
EXPECT_STREQ(b2, kTestString1);
BSTR tmp = b2.Release();
EXPECT_TRUE(tmp != NULL);
EXPECT_STREQ(tmp, as_wcstr(kTestString1));
EXPECT_STREQ(tmp, kTestString1);
EXPECT_TRUE(b2 == NULL);
SysFreeString(tmp);
......@@ -60,7 +58,7 @@ void BasicBstrTests() {
EXPECT_TRUE(b2.AllocateBytes(100) != NULL);
EXPECT_EQ(100u, b2.ByteLength());
EXPECT_EQ(100 / sizeof(kTestString1[0]), b2.Length());
lstrcpy(static_cast<BSTR>(b2), as_wcstr(kTestString1));
lstrcpy(static_cast<BSTR>(b2), kTestString1);
EXPECT_EQ(test1_len, static_cast<size_t>(lstrlen(b2)));
EXPECT_EQ(100 / sizeof(kTestString1[0]), b2.Length());
b2.SetByteLen(lstrlen(b2) * sizeof(kTestString2[0]));
......
......@@ -115,7 +115,7 @@ bool CreateOrUpdateShortcutLink(const FilePath& shortcut_path,
}
if (properties.options & ShortcutProperties::PROPERTIES_ARGUMENTS) {
if (FAILED(i_shell_link->SetArguments(as_wcstr(properties.arguments))))
if (FAILED(i_shell_link->SetArguments(properties.arguments.c_str())))
return false;
} else if (old_i_persist_file.Get()) {
wchar_t current_arguments[MAX_PATH] = {0};
......@@ -126,7 +126,7 @@ bool CreateOrUpdateShortcutLink(const FilePath& shortcut_path,
}
if ((properties.options & ShortcutProperties::PROPERTIES_DESCRIPTION) &&
FAILED(i_shell_link->SetDescription(as_wcstr(properties.description)))) {
FAILED(i_shell_link->SetDescription(properties.description.c_str()))) {
return false;
}
......@@ -225,42 +225,39 @@ bool ResolveShortcutProperties(const FilePath& shortcut_path,
// Reset |properties|.
properties->options = 0;
char16 temp[MAX_PATH];
wchar_t temp[MAX_PATH];
if (options & ShortcutProperties::PROPERTIES_TARGET) {
if (FAILED(i_shell_link->GetPath(as_writable_wcstr(temp), MAX_PATH, NULL,
SLGP_UNCPRIORITY))) {
if (FAILED(i_shell_link->GetPath(temp, MAX_PATH, NULL, SLGP_UNCPRIORITY))) {
return false;
}
properties->set_target(FilePath(temp));
properties->set_target(FilePath(AsStringPiece16(temp)));
}
if (options & ShortcutProperties::PROPERTIES_WORKING_DIR) {
if (FAILED(i_shell_link->GetWorkingDirectory(as_writable_wcstr(temp),
MAX_PATH)))
if (FAILED(i_shell_link->GetWorkingDirectory(temp, MAX_PATH)))
return false;
properties->set_working_dir(FilePath(temp));
properties->set_working_dir(FilePath(AsStringPiece16(temp)));
}
if (options & ShortcutProperties::PROPERTIES_ARGUMENTS) {
if (FAILED(i_shell_link->GetArguments(as_writable_wcstr(temp), MAX_PATH)))
if (FAILED(i_shell_link->GetArguments(temp, MAX_PATH)))
return false;
properties->set_arguments(temp);
}
if (options & ShortcutProperties::PROPERTIES_DESCRIPTION) {
// Note: description length constrained by MAX_PATH.
if (FAILED(i_shell_link->GetDescription(as_writable_wcstr(temp), MAX_PATH)))
if (FAILED(i_shell_link->GetDescription(temp, MAX_PATH)))
return false;
properties->set_description(temp);
}
if (options & ShortcutProperties::PROPERTIES_ICON) {
int temp_index;
if (FAILED(i_shell_link->GetIconLocation(as_writable_wcstr(temp), MAX_PATH,
&temp_index))) {
if (FAILED(i_shell_link->GetIconLocation(temp, MAX_PATH, &temp_index))) {
return false;
}
properties->set_icon(FilePath(temp), temp_index);
properties->set_icon(FilePath(AsStringPiece16(temp)), temp_index);
}
if (options & (ShortcutProperties::PROPERTIES_APP_ID |
......@@ -278,10 +275,10 @@ bool ResolveShortcutProperties(const FilePath& shortcut_path,
}
switch (pv_app_id.get().vt) {
case VT_EMPTY:
properties->set_app_id(string16());
properties->set_app_id(std::wstring());
break;
case VT_LPWSTR:
properties->set_app_id(WideToUTF16(pv_app_id.get().pwszVal));
properties->set_app_id(pv_app_id.get().pwszVal);
break;
default:
NOTREACHED() << "Unexpected variant type: " << pv_app_id.get().vt;
......@@ -336,7 +333,7 @@ bool ResolveShortcutProperties(const FilePath& shortcut_path,
bool ResolveShortcut(const FilePath& shortcut_path,
FilePath* target_path,
string16* args) {
std::wstring* args) {
uint32_t options = 0;
if (target_path)
options |= ShortcutProperties::PROPERTIES_TARGET;
......
......@@ -11,7 +11,6 @@
#include "base/base_export.h"
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/strings/string16.h"
namespace base {
namespace win {
......@@ -62,14 +61,14 @@ struct BASE_EXPORT ShortcutProperties {
options |= PROPERTIES_WORKING_DIR;
}
void set_arguments(const string16& arguments_in) {
void set_arguments(const std::wstring& arguments_in) {
// Size restriction as per MSDN at http://goo.gl/TJ7q5.
DCHECK(arguments_in.size() < MAX_PATH);
arguments = arguments_in;
options |= PROPERTIES_ARGUMENTS;
}
void set_description(const string16& description_in) {
void set_description(const std::wstring& description_in) {
// Size restriction as per MSDN at http://goo.gl/OdNQq.
DCHECK(description_in.size() < MAX_PATH);
description = description_in;
......@@ -82,7 +81,7 @@ struct BASE_EXPORT ShortcutProperties {
options |= PROPERTIES_ICON;
}
void set_app_id(const string16& app_id_in) {
void set_app_id(const std::wstring& app_id_in) {
app_id = app_id_in;
options |= PROPERTIES_APP_ID;
}
......@@ -104,16 +103,16 @@ struct BASE_EXPORT ShortcutProperties {
FilePath working_dir;
// The arguments to be applied to |target| when launching from this shortcut.
// The length of this string must be less than MAX_PATH.
string16 arguments;
std::wstring arguments;
// The localized description of the shortcut.
// The length of this string must be less than MAX_PATH.
string16 description;
std::wstring description;
// The path to the icon (can be a dll or exe, in which case |icon_index| is
// the resource id).
FilePath icon;
int icon_index;
// The app model id for the shortcut.
string16 app_id;
std::wstring app_id;
// Whether this is a dual mode shortcut (Win8+).
bool dual_mode;
// The CLSID of the COM object registered with the OS via the shortcut. This
......@@ -159,7 +158,7 @@ BASE_EXPORT bool ResolveShortcutProperties(const FilePath& shortcut_path,
// |shortcut_path| and |target_path|.
BASE_EXPORT bool ResolveShortcut(const FilePath& shortcut_path,
FilePath* target_path,
string16* args);
std::wstring* args);
// Pin to taskbar is only supported on Windows 7 and Windows 8. Returns true on
// those platforms.
......
......@@ -12,7 +12,6 @@
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/stl_util.h"
#include "base/strings/string16.h"
#include "base/test/test_file_util.h"
#include "base/test/test_shortcut_win.h"
#include "base/win/scoped_com_initializer.h"
......@@ -42,10 +41,10 @@ class ShortcutTest : public testing::Test {
link_properties_.set_target(target_file);
link_properties_.set_working_dir(temp_dir_.GetPath());
link_properties_.set_arguments(STRING16_LITERAL("--magic --awesome"));
link_properties_.set_description(STRING16_LITERAL("Chrome is awesome."));
link_properties_.set_arguments(L"--magic --awesome");
link_properties_.set_description(L"Chrome is awesome.");
link_properties_.set_icon(link_properties_.target, 4);
link_properties_.set_app_id(STRING16_LITERAL("Chrome"));
link_properties_.set_app_id(L"Chrome");
link_properties_.set_dual_mode(false);
// The CLSID below was randomly selected.
......@@ -68,12 +67,10 @@ class ShortcutTest : public testing::Test {
link_properties_2_.set_target(target_file_2);
link_properties_2_.set_working_dir(temp_dir_2_.GetPath());
link_properties_2_.set_arguments(STRING16_LITERAL("--super --crazy"));
link_properties_2_.set_description(
STRING16_LITERAL("The best in the west."));
link_properties_2_.set_arguments(L"--super --crazy");
link_properties_2_.set_description(L"The best in the west.");
link_properties_2_.set_icon(icon_path_2, 0);
link_properties_2_.set_app_id(
STRING16_LITERAL("Chrome.UserLevelCrazySuffix"));
link_properties_2_.set_app_id(L"Chrome.UserLevelCrazySuffix");
link_properties_2_.set_dual_mode(true);
link_properties_2_.set_toast_activator_clsid(CLSID_NULL);
}
......@@ -133,11 +130,11 @@ TEST_F(ShortcutTest, CreateAndResolveShortcutProperties) {
ValidatePathsAreEqual(only_target_properties.target,
properties_read_2.target);
ValidatePathsAreEqual(FilePath(), properties_read_2.working_dir);
EXPECT_EQ(STRING16_LITERAL(""), properties_read_2.arguments);
EXPECT_EQ(STRING16_LITERAL(""), properties_read_2.description);
EXPECT_EQ(L"", properties_read_2.arguments);
EXPECT_EQ(L"", properties_read_2.description);
ValidatePathsAreEqual(FilePath(), properties_read_2.icon);
EXPECT_EQ(0, properties_read_2.icon_index);
EXPECT_EQ(STRING16_LITERAL(""), properties_read_2.app_id);
EXPECT_EQ(L"", properties_read_2.app_id);
EXPECT_FALSE(properties_read_2.dual_mode);
EXPECT_EQ(CLSID_NULL, properties_read_2.toast_activator_clsid);
}
......@@ -162,7 +159,7 @@ TEST_F(ShortcutTest, ResolveShortcutWithArgs) {
link_file_, link_properties_, SHORTCUT_CREATE_ALWAYS));
FilePath resolved_name;
string16 args;
std::wstring args;
EXPECT_TRUE(ResolveShortcut(link_file_, &resolved_name, &args));
char read_contents[base::size(kFileContents)];
......@@ -260,14 +257,14 @@ TEST_F(ShortcutTest, UpdateShortcutClearArguments) {
link_file_, link_properties_, SHORTCUT_CREATE_ALWAYS));
ShortcutProperties clear_arguments_properties;
clear_arguments_properties.set_arguments(string16());
clear_arguments_properties.set_arguments(std::wstring());
ASSERT_TRUE(CreateOrUpdateShortcutLink(
link_file_, clear_arguments_properties,
SHORTCUT_UPDATE_EXISTING));
ShortcutProperties expected_properties = link_properties_;
expected_properties.set_arguments(string16());
expected_properties.set_arguments(std::wstring());
ValidateShortcut(link_file_, expected_properties);
}
......@@ -303,7 +300,7 @@ TEST_F(ShortcutTest, ReplaceShortcutSomeProperties) {
ShortcutProperties expected_properties(new_properties);
expected_properties.set_working_dir(FilePath());
expected_properties.set_icon(FilePath(), 0);
expected_properties.set_app_id(string16());
expected_properties.set_app_id(std::wstring());
expected_properties.set_dual_mode(false);
ValidateShortcut(link_file_, expected_properties);
}
......
......@@ -40,6 +40,7 @@
#include "base/macros.h"
#include "base/scoped_native_library.h"
#include "base/strings/string_util.h"
#include "base/strings/string_util_win.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/scoped_thread_priority.h"
......@@ -334,20 +335,20 @@ bool IsKeyboardPresentOnSlate(std::string* reason, HWND hwnd) {
break;
// Get the device ID.
char16 device_id[MAX_DEVICE_ID_LEN];
CONFIGRET status =
CM_Get_Device_ID(device_info_data.DevInst, as_writable_wcstr(device_id),
MAX_DEVICE_ID_LEN, 0);
wchar_t device_id[MAX_DEVICE_ID_LEN];
CONFIGRET status = CM_Get_Device_ID(device_info_data.DevInst, device_id,
MAX_DEVICE_ID_LEN, 0);
if (status == CR_SUCCESS) {
// To reduce the scope of the hack we only look for ACPI and HID\\VID
// prefixes in the keyboard device ids.
if (StartsWith(device_id, STRING16_LITERAL("ACPI"),
if (StartsWith(base::AsStringPiece16(device_id), STRING16_LITERAL("ACPI"),
CompareCase::INSENSITIVE_ASCII) ||
StartsWith(device_id, STRING16_LITERAL("HID\\VID"),
StartsWith(base::AsStringPiece16(device_id),
STRING16_LITERAL("HID\\VID"),
CompareCase::INSENSITIVE_ASCII)) {
if (reason) {
*reason += "device: ";
*reason += UTF16ToUTF8(device_id);
*reason += WideToUTF8(device_id);
*reason += '\n';
}
// The heuristic we are using is to check the count of keyboards and
......@@ -374,7 +375,7 @@ void GetNonClientMetrics(NONCLIENTMETRICS_XP* metrics) {
DCHECK(success);
}
bool GetUserSidString(string16* user_sid) {
bool GetUserSidString(std::wstring* user_sid) {
// Get the current token.
HANDLE token = NULL;
if (!::OpenProcessToken(::GetCurrentProcess(), TOKEN_QUERY, &token))
......@@ -396,7 +397,7 @@ bool GetUserSidString(string16* user_sid) {
if (!::ConvertSidToStringSid(user->User.Sid, &sid_string))
return false;
*user_sid = as_u16cstr(sid_string);
*user_sid = sid_string;
::LocalFree(sid_string);
......@@ -409,14 +410,11 @@ bool UserAccountControlIsEnabled() {
// http://code.google.com/p/chromium/issues/detail?id=61644
ThreadRestrictions::ScopedAllowIO allow_io;
RegKey key(
HKEY_LOCAL_MACHINE,
STRING16_LITERAL(
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System"),
KEY_READ);
RegKey key(HKEY_LOCAL_MACHINE,
L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System",
KEY_READ);
DWORD uac_enabled;
if (key.ReadValueDW(STRING16_LITERAL("EnableLUA"), &uac_enabled) !=
ERROR_SUCCESS) {
if (key.ReadValueDW(L"EnableLUA", &uac_enabled) != ERROR_SUCCESS) {
return true;
}
// Users can set the EnableLUA value to something arbitrary, like 2, which
......@@ -440,9 +438,9 @@ bool SetBooleanValueForPropertyStore(IPropertyStore* property_store,
bool SetStringValueForPropertyStore(IPropertyStore* property_store,
const PROPERTYKEY& property_key,
const char16* property_string_value) {
const wchar_t* property_string_value) {
ScopedPropVariant property_value;
if (FAILED(InitPropVariantFromString(as_wcstr(property_string_value),
if (FAILED(InitPropVariantFromString(property_string_value,
property_value.Receive()))) {
return false;
}
......@@ -466,36 +464,37 @@ bool SetClsidForPropertyStore(IPropertyStore* property_store,
}
bool SetAppIdForPropertyStore(IPropertyStore* property_store,
const char16* app_id) {
const wchar_t* app_id) {
// App id should be less than 64 chars and contain no space. And recommended
// format is CompanyName.ProductName[.SubProduct.ProductNumber].
// See http://msdn.microsoft.com/en-us/library/dd378459%28VS.85%29.aspx
DCHECK_LT(lstrlen(as_wcstr(app_id)), 64);
DCHECK_EQ(wcschr(as_wcstr(app_id), L' '), nullptr);
DCHECK_LT(lstrlen(app_id), 64);
DCHECK_EQ(wcschr(app_id, L' '), nullptr);
return SetStringValueForPropertyStore(property_store,
PKEY_AppUserModel_ID,
app_id);
}
static const char16 kAutoRunKeyPath[] =
STRING16_LITERAL("Software\\Microsoft\\Windows\\CurrentVersion\\Run");
static const wchar_t kAutoRunKeyPath[] =
L"Software\\Microsoft\\Windows\\CurrentVersion\\Run";
bool AddCommandToAutoRun(HKEY root_key, const string16& name,
const string16& command) {
bool AddCommandToAutoRun(HKEY root_key,
const std::wstring& name,
const std::wstring& command) {
RegKey autorun_key(root_key, kAutoRunKeyPath, KEY_SET_VALUE);
return (autorun_key.WriteValue(name.c_str(), command.c_str()) ==
ERROR_SUCCESS);
}
bool RemoveCommandFromAutoRun(HKEY root_key, const string16& name) {
bool RemoveCommandFromAutoRun(HKEY root_key, const std::wstring& name) {
RegKey autorun_key(root_key, kAutoRunKeyPath, KEY_SET_VALUE);
return (autorun_key.DeleteValue(name.c_str()) == ERROR_SUCCESS);
}
bool ReadCommandFromAutoRun(HKEY root_key,
const string16& name,
string16* command) {
const std::wstring& name,
std::wstring* command) {
RegKey autorun_key(root_key, kAutoRunKeyPath, KEY_QUERY_VALUE);
return (autorun_key.ReadValue(name.c_str(), command) == ERROR_SUCCESS);
}
......@@ -766,9 +765,9 @@ void* GetUser32FunctionPointer(const char* function_name,
return nullptr;
}
string16 GetWindowObjectName(HANDLE handle) {
std::wstring GetWindowObjectName(HANDLE handle) {
// Get the size of the name.
string16 object_name;
std::wstring object_name;
DWORD size = 0;
::GetUserObjectInformation(handle, UOI_NAME, nullptr, 0, &size);
......@@ -781,7 +780,7 @@ string16 GetWindowObjectName(HANDLE handle) {
// Query the name of the object.
if (!::GetUserObjectInformation(
handle, UOI_NAME, WriteInto(&object_name, size / sizeof(wchar_t)),
handle, UOI_NAME, WriteIntoW(&object_name, size / sizeof(wchar_t)),
size, &size)) {
DPCHECK(false);
}
......@@ -789,13 +788,14 @@ string16 GetWindowObjectName(HANDLE handle) {
return object_name;
}
bool IsRunningUnderDesktopName(StringPiece16 desktop_name) {
bool IsRunningUnderDesktopName(WStringPiece desktop_name) {
HDESK thread_desktop = ::GetThreadDesktop(::GetCurrentThreadId());
if (!thread_desktop)
return false;
string16 current_desktop_name = GetWindowObjectName(thread_desktop);
return EqualsCaseInsensitiveASCII(current_desktop_name, desktop_name);
std::wstring current_desktop_name = GetWindowObjectName(thread_desktop);
return EqualsCaseInsensitiveASCII(AsStringPiece16(current_desktop_name),
AsStringPiece16(desktop_name));
}
// This method is used to detect whether current session is a remote session.
......@@ -810,14 +810,13 @@ bool IsCurrentSessionRemote() {
if (!::ProcessIdToSessionId(::GetCurrentProcessId(), &current_session_id))
return false;
static constexpr char16 kRdpSettingsKeyName[] =
STRING16_LITERAL("SYSTEM\\CurrentControlSet\\Control\\Terminal Server");
static constexpr wchar_t kRdpSettingsKeyName[] =
L"SYSTEM\\CurrentControlSet\\Control\\Terminal Server";
RegKey key(HKEY_LOCAL_MACHINE, kRdpSettingsKeyName, KEY_READ);
if (!key.Valid())
return false;
static constexpr char16 kGlassSessionIdValueName[] =
STRING16_LITERAL("GlassSessionId");
static constexpr wchar_t kGlassSessionIdValueName[] = L"GlassSessionId";
DWORD glass_session_id = 0;
if (key.ReadValueDW(kGlassSessionIdValueName, &glass_session_id) !=
ERROR_SUCCESS)
......
......@@ -58,7 +58,7 @@ inline HANDLE Uint32ToHandle(uint32_t h) {
// Returns the string representing the current user sid. Does not modify
// |user_sid| on failure.
BASE_EXPORT bool GetUserSidString(string16* user_sid);
BASE_EXPORT bool GetUserSidString(std::wstring* user_sid);
// Returns false if user account control (UAC) has been disabled with the
// EnableLUA registry flag. Returns true if user account control is enabled.
......@@ -78,7 +78,7 @@ BASE_EXPORT bool SetBooleanValueForPropertyStore(
BASE_EXPORT bool SetStringValueForPropertyStore(
IPropertyStore* property_store,
const PROPERTYKEY& property_key,
const char16* property_string_value);
const wchar_t* property_string_value);
// Sets the CLSID value for a given key in a given IPropertyStore.
BASE_EXPORT bool SetClsidForPropertyStore(IPropertyStore* property_store,
......@@ -89,22 +89,23 @@ BASE_EXPORT bool SetClsidForPropertyStore(IPropertyStore* property_store,
// for tagging application/chromium shortcut, browser window and jump list for
// Win7.
BASE_EXPORT bool SetAppIdForPropertyStore(IPropertyStore* property_store,
const char16* app_id);
const wchar_t* app_id);
// Adds the specified |command| using the specified |name| to the AutoRun key.
// |root_key| could be HKCU or HKLM or the root of any user hive.
BASE_EXPORT bool AddCommandToAutoRun(HKEY root_key,
const string16& name,
const string16& command);
const std::wstring& name,
const std::wstring& command);
// Removes the command specified by |name| from the AutoRun key. |root_key|
// could be HKCU or HKLM or the root of any user hive.
BASE_EXPORT bool RemoveCommandFromAutoRun(HKEY root_key, const string16& name);
BASE_EXPORT bool RemoveCommandFromAutoRun(HKEY root_key,
const std::wstring& name);
// Reads the command specified by |name| from the AutoRun key. |root_key|
// could be HKCU or HKLM or the root of any user hive. Used for unit-tests.
BASE_EXPORT bool ReadCommandFromAutoRun(HKEY root_key,
const string16& name,
string16* command);
const std::wstring& name,
std::wstring* command);
// Sets whether to crash the process during exit. This is inspected by DLLMain
// and used to intercept unexpected terminations of the process (via calls to
......@@ -216,12 +217,12 @@ BASE_EXPORT void* GetUser32FunctionPointer(
NativeLibraryLoadError* error = nullptr);
// Returns the name of a desktop or a window station.
BASE_EXPORT string16 GetWindowObjectName(HANDLE handle);
BASE_EXPORT std::wstring GetWindowObjectName(HANDLE handle);
// Checks if the calling thread is running under a desktop with the name
// given by |desktop_name|. |desktop_name| is ASCII case insensitive (non-ASCII
// characters will be compared with exact matches).
BASE_EXPORT bool IsRunningUnderDesktopName(StringPiece16 desktop_name);
BASE_EXPORT bool IsRunningUnderDesktopName(WStringPiece desktop_name);
// Returns true if current session is a remote session.
BASE_EXPORT bool IsCurrentSessionRemote();
......
......@@ -43,7 +43,7 @@ TEST(BaseWinUtilTest, TestIsUACEnabled) {
}
TEST(BaseWinUtilTest, TestGetUserSidString) {
string16 user_sid;
std::wstring user_sid;
EXPECT_TRUE(GetUserSidString(&user_sid));
EXPECT_TRUE(!user_sid.empty());
}
......@@ -101,9 +101,9 @@ TEST(BaseWinUtilTest, String16FromGUID) {
}
TEST(BaseWinUtilTest, GetWindowObjectName) {
base::string16 created_desktop_name(STRING16_LITERAL("test_desktop"));
std::wstring created_desktop_name(L"test_desktop");
HDESK desktop_handle =
::CreateDesktop(as_wcstr(created_desktop_name), nullptr, nullptr, 0,
::CreateDesktop(created_desktop_name.c_str(), nullptr, nullptr, 0,
DESKTOP_CREATEWINDOW | DESKTOP_READOBJECTS |
READ_CONTROL | WRITE_DAC | WRITE_OWNER,
nullptr);
......@@ -117,13 +117,15 @@ TEST(BaseWinUtilTest, IsRunningUnderDesktopName) {
HDESK thread_desktop = ::GetThreadDesktop(::GetCurrentThreadId());
ASSERT_NE(thread_desktop, nullptr);
base::string16 desktop_name = GetWindowObjectName(thread_desktop);
std::wstring desktop_name = GetWindowObjectName(thread_desktop);
EXPECT_TRUE(IsRunningUnderDesktopName(desktop_name));
EXPECT_TRUE(IsRunningUnderDesktopName(base::ToLowerASCII(desktop_name)));
EXPECT_TRUE(IsRunningUnderDesktopName(base::ToUpperASCII(desktop_name)));
EXPECT_FALSE(IsRunningUnderDesktopName(
desktop_name + STRING16_LITERAL("_non_existent_desktop_name")));
EXPECT_TRUE(IsRunningUnderDesktopName(
AsWString(ToLowerASCII(AsStringPiece16(desktop_name)))));
EXPECT_TRUE(IsRunningUnderDesktopName(
AsWString(ToUpperASCII(AsStringPiece16(desktop_name)))));
EXPECT_FALSE(
IsRunningUnderDesktopName(desktop_name + L"_non_existent_desktop_name"));
}
} // namespace win
......
......@@ -14,7 +14,6 @@
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/no_destructor.h"
#include "base/strings/string16.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/win/registry.h"
......@@ -34,8 +33,8 @@ namespace {
// The values under the CurrentVersion registry hive are mirrored under
// the corresponding Wow6432 hive.
constexpr char16 kRegKeyWindowsNTCurrentVersion[] =
STRING16_LITERAL("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion");
constexpr wchar_t kRegKeyWindowsNTCurrentVersion[] =
L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion";
// Returns the "UBR" (Windows 10 patch number) and "ReleaseId" (Windows 10
// release number) from the registry. "UBR" is an undocumented value and will be
......@@ -43,16 +42,16 @@ constexpr char16 kRegKeyWindowsNTCurrentVersion[] =
// value is not found.
std::pair<int, std::string> GetVersionData() {
DWORD ubr = 0;
string16 release_id;
std::wstring release_id;
RegKey key;
if (key.Open(HKEY_LOCAL_MACHINE, kRegKeyWindowsNTCurrentVersion,
KEY_QUERY_VALUE) == ERROR_SUCCESS) {
key.ReadValueDW(STRING16_LITERAL("UBR"), &ubr);
key.ReadValue(STRING16_LITERAL("ReleaseId"), &release_id);
key.ReadValueDW(L"UBR", &ubr);
key.ReadValue(L"ReleaseId", &release_id);
}
return std::make_pair(static_cast<int>(ubr), UTF16ToUTF8(release_id));
return std::make_pair(static_cast<int>(ubr), WideToUTF8(release_id));
}
const _SYSTEM_INFO& GetSystemInfoStorage() {
......@@ -230,12 +229,12 @@ base::Version OSInfo::Kernel32BaseVersion() const {
std::string OSInfo::processor_model_name() {
if (processor_model_name_.empty()) {
const char16 kProcessorNameString[] =
STRING16_LITERAL("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0");
const wchar_t kProcessorNameString[] =
L"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0";
RegKey key(HKEY_LOCAL_MACHINE, kProcessorNameString, KEY_READ);
string16 value;
key.ReadValue(STRING16_LITERAL("ProcessorNameString"), &value);
processor_model_name_ = UTF16ToUTF8(value);
std::wstring value;
key.ReadValue(L"ProcessorNameString", &value);
processor_model_name_ = WideToUTF8(value);
}
return processor_model_name_;
}
......
......@@ -36,9 +36,9 @@ bool CreateLocalWmiConnection(bool set_blanket,
return false;
ComPtr<IWbemServices> wmi_services_r;
hr = wmi_locator->ConnectServer(ScopedBstr(STRING16_LITERAL("ROOT\\CIMV2")),
nullptr, nullptr, nullptr, 0, nullptr,
nullptr, &wmi_services_r);
hr =
wmi_locator->ConnectServer(ScopedBstr(L"ROOT\\CIMV2"), nullptr, nullptr,
nullptr, 0, nullptr, nullptr, &wmi_services_r);
if (FAILED(hr))
return false;
......@@ -55,8 +55,8 @@ bool CreateLocalWmiConnection(bool set_blanket,
}
bool CreateWmiClassMethodObject(IWbemServices* wmi_services,
StringPiece16 class_name,
StringPiece16 method_name,
WStringPiece class_name,
WStringPiece method_name,
ComPtr<IWbemClassObject>* class_instance) {
// We attempt to instantiate a COM object that represents a WMI object plus
// a method rolled into one entity.
......@@ -90,20 +90,20 @@ bool CreateWmiClassMethodObject(IWbemServices* wmi_services,
// NOTE: The documentation for the Create method suggests that the ProcessId
// parameter and return value are of type uint32_t, but when we call the method
// the values in the returned out_params, are VT_I4, which is int32_t.
bool WmiLaunchProcess(const string16& command_line, int* process_id) {
bool WmiLaunchProcess(const std::wstring& command_line, int* process_id) {
ComPtr<IWbemServices> wmi_local;
if (!CreateLocalWmiConnection(true, &wmi_local))
return false;
static constexpr char16 class_name[] = STRING16_LITERAL("Win32_Process");
static constexpr char16 method_name[] = STRING16_LITERAL("Create");
static constexpr wchar_t class_name[] = L"Win32_Process";
static constexpr wchar_t method_name[] = L"Create";
ComPtr<IWbemClassObject> process_create;
if (!CreateWmiClassMethodObject(wmi_local.Get(), class_name, method_name,
&process_create)) {
return false;
}
ScopedVariant b_command_line(as_wcstr(command_line));
ScopedVariant b_command_line(command_line.c_str());
if (FAILED(process_create->Put(L"CommandLine", 0, b_command_line.AsInput(),
0))) {
......@@ -151,14 +151,14 @@ WmiComputerSystemInfo WmiComputerSystemInfo::Get() {
void WmiComputerSystemInfo::PopulateModelAndManufacturer(
const ComPtr<IWbemServices>& services) {
static constexpr StringPiece16 query_computer_system =
STRING16_LITERAL("SELECT Manufacturer,Model FROM Win32_ComputerSystem");
static constexpr WStringPiece query_computer_system =
L"SELECT Manufacturer,Model FROM Win32_ComputerSystem";
ComPtr<IEnumWbemClassObject> enumerator_computer_system;
HRESULT hr = services->ExecQuery(
ScopedBstr(STRING16_LITERAL("WQL")), ScopedBstr(query_computer_system),
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, nullptr,
&enumerator_computer_system);
HRESULT hr =
services->ExecQuery(ScopedBstr(L"WQL"), ScopedBstr(query_computer_system),
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
nullptr, &enumerator_computer_system);
if (FAILED(hr) || !enumerator_computer_system.Get())
return;
......@@ -172,27 +172,26 @@ void WmiComputerSystemInfo::PopulateModelAndManufacturer(
ScopedVariant manufacturer;
hr = class_object->Get(L"Manufacturer", 0, manufacturer.Receive(), 0, 0);
if (SUCCEEDED(hr) && manufacturer.type() == VT_BSTR) {
WideToUTF16(V_BSTR(manufacturer.ptr()),
::SysStringLen(V_BSTR(manufacturer.ptr())), &manufacturer_);
manufacturer_.assign(V_BSTR(manufacturer.ptr()),
::SysStringLen(V_BSTR(manufacturer.ptr())));
}
ScopedVariant model;
hr = class_object->Get(L"Model", 0, model.Receive(), 0, 0);
if (SUCCEEDED(hr) && model.type() == VT_BSTR) {
WideToUTF16(V_BSTR(model.ptr()), ::SysStringLen(V_BSTR(model.ptr())),
&model_);
model_.assign(V_BSTR(model.ptr()), ::SysStringLen(V_BSTR(model.ptr())));
}
}
void WmiComputerSystemInfo::PopulateSerialNumber(
const ComPtr<IWbemServices>& services) {
static constexpr StringPiece16 query_bios =
STRING16_LITERAL("SELECT SerialNumber FROM Win32_Bios");
static constexpr WStringPiece query_bios =
L"SELECT SerialNumber FROM Win32_Bios";
ComPtr<IEnumWbemClassObject> enumerator_bios;
HRESULT hr = services->ExecQuery(
ScopedBstr(STRING16_LITERAL("WQL")), ScopedBstr(query_bios),
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, nullptr,
&enumerator_bios);
HRESULT hr =
services->ExecQuery(ScopedBstr(L"WQL"), ScopedBstr(query_bios),
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
nullptr, &enumerator_bios);
if (FAILED(hr) || !enumerator_bios.Get())
return;
......@@ -205,8 +204,8 @@ void WmiComputerSystemInfo::PopulateSerialNumber(
ScopedVariant serial_number;
hr = class_obj->Get(L"SerialNumber", 0, serial_number.Receive(), 0, 0);
if (SUCCEEDED(hr) && serial_number.type() == VT_BSTR) {
WideToUTF16(V_BSTR(serial_number.ptr()),
::SysStringLen(V_BSTR(serial_number.ptr())), &serial_number_);
serial_number_.assign(V_BSTR(serial_number.ptr()),
::SysStringLen(V_BSTR(serial_number.ptr())));
}
}
......
......@@ -24,7 +24,6 @@
#include <wrl/client.h>
#include "base/base_export.h"
#include "base/strings/string16.h"
#include "base/strings/string_piece.h"
namespace base {
......@@ -47,8 +46,8 @@ BASE_EXPORT bool CreateLocalWmiConnection(
// WMI method that you can fill with parameter values using SetParameter.
BASE_EXPORT bool CreateWmiClassMethodObject(
IWbemServices* wmi_services,
StringPiece16 class_name,
StringPiece16 method_name,
WStringPiece class_name,
WStringPiece method_name,
Microsoft::WRL::ComPtr<IWbemClassObject>* class_instance);
// Creates a new process from |command_line|. The advantage over CreateProcess
......@@ -61,7 +60,7 @@ BASE_EXPORT bool CreateWmiClassMethodObject(
// Processes created this way are children of wmiprvse.exe and run with the
// caller credentials.
// More info: http://msdn2.microsoft.com/en-us/library/aa394372(VS.85).aspx
BASE_EXPORT bool WmiLaunchProcess(const string16& command_line,
BASE_EXPORT bool WmiLaunchProcess(const std::wstring& command_line,
int* process_id);
// An encapsulation of information retrieved from the 'Win32_ComputerSystem' and
......@@ -72,9 +71,9 @@ class BASE_EXPORT WmiComputerSystemInfo {
public:
static WmiComputerSystemInfo Get();
const string16& manufacturer() const { return manufacturer_; }
const string16& model() const { return model_; }
const string16& serial_number() const { return serial_number_; }
const std::wstring& manufacturer() const { return manufacturer_; }
const std::wstring& model() const { return model_; }
const std::wstring& serial_number() const { return serial_number_; }
private:
void PopulateModelAndManufacturer(
......@@ -82,9 +81,9 @@ class BASE_EXPORT WmiComputerSystemInfo {
void PopulateSerialNumber(
const Microsoft::WRL::ComPtr<IWbemServices>& services);
string16 manufacturer_;
string16 model_;
string16 serial_number_;
std::wstring manufacturer_;
std::wstring model_;
std::wstring serial_number_;
};
} // namespace win
......
......@@ -42,8 +42,7 @@ TEST_F(WMITest, TestCreateClassMethod) {
ASSERT_NE(wmi_services.Get(), nullptr);
ComPtr<IWbemClassObject> class_method = nullptr;
EXPECT_TRUE(CreateWmiClassMethodObject(
wmi_services.Get(), STRING16_LITERAL("Win32_ShortcutFile"),
STRING16_LITERAL("Rename"), &class_method));
wmi_services.Get(), L"Win32_ShortcutFile", L"Rename", &class_method));
ASSERT_NE(class_method.Get(), nullptr);
ULONG refs = class_method.Reset();
EXPECT_EQ(0u, refs);
......@@ -54,8 +53,7 @@ TEST_F(WMITest, TestCreateClassMethod) {
// Creates an instance of cmd which executes 'echo' and exits immediately.
TEST_F(WMITest, TestLaunchProcess) {
int pid = 0;
bool result =
WmiLaunchProcess(STRING16_LITERAL("cmd.exe /c echo excelent!"), &pid);
bool result = WmiLaunchProcess(L"cmd.exe /c echo excelent!", &pid);
EXPECT_TRUE(result);
EXPECT_GT(pid, 0);
}
......
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