[crashpad] Prepare crashpad for base::string16 switch

This change prepares crashpad for the upcoming switch of base::string16
to std::u16string on all platforms. It does so by replacing Windows-only
instances of base::string16 with std::wstring, and using appropriate
string utility functions.

Bug: chromium:911896
Change-Id: Ibb0b8a4e4dc7fae1d24d18823f8dbb6da31f8239
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/2332402
Commit-Queue: Jan Wilken Dörrie <jdoerrie@chromium.org>
Reviewed-by: Mark Mentovai <mark@chromium.org>
This commit is contained in:
Jan Wilken Dörrie 2020-09-12 09:20:14 +02:00 committed by Commit Bot
parent 90344b24ed
commit a98ee20e57
38 changed files with 185 additions and 165 deletions

View File

@ -50,7 +50,7 @@ bool CrashReportDatabase::NewReport::Initialize(
} }
#if defined(OS_WIN) #if defined(OS_WIN)
const std::wstring uuid_string = uuid_.ToString16(); const std::wstring uuid_string = uuid_.ToWString();
#else #else
const std::string uuid_string = uuid_.ToString(); const std::string uuid_string = uuid_.ToString();
#endif #endif

View File

@ -25,7 +25,6 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/numerics/safe_math.h" #include "base/numerics/safe_math.h"
#include "base/strings/string16.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "client/settings.h" #include "client/settings.h"
@ -66,9 +65,8 @@ uint32_t AddStringToTable(std::string* string_table, const std::string& str) {
// Converts |str| to UTF8, adds the result to the string table and returns the // Converts |str| to UTF8, adds the result to the string table and returns the
// byte index where it was added. // byte index where it was added.
uint32_t AddStringToTable(std::string* string_table, uint32_t AddStringToTable(std::string* string_table, const std::wstring& str) {
const base::string16& str) { return AddStringToTable(string_table, base::WideToUTF8(str));
return AddStringToTable(string_table, base::UTF16ToUTF8(str));
} }
// Reads from the current file position to EOF and returns as a string of bytes. // Reads from the current file position to EOF and returns as a string of bytes.
@ -183,7 +181,7 @@ ReportDisk::ReportDisk(const MetadataFileReportRecord& record,
: Report() { : Report() {
uuid = record.uuid; uuid = record.uuid;
file_path = report_dir.Append( file_path = report_dir.Append(
base::UTF8ToUTF16(&string_table[record.file_path_index])); base::UTF8ToWide(&string_table[record.file_path_index]));
id = &string_table[record.id_index]; id = &string_table[record.id_index];
creation_time = record.creation_time; creation_time = record.creation_time;
last_upload_attempt_time = record.last_upload_attempt_time; last_upload_attempt_time = record.last_upload_attempt_time;
@ -540,7 +538,7 @@ void Metadata::Write() {
const base::FilePath& path = report.file_path; const base::FilePath& path = report.file_path;
if (path.DirName() != report_dir_) { if (path.DirName() != report_dir_) {
LOG(ERROR) << path.value().c_str() << " expected to start with " LOG(ERROR) << path.value().c_str() << " expected to start with "
<< base::UTF16ToUTF8(report_dir_.value()); << base::WideToUTF8(report_dir_.value());
return; return;
} }
records.push_back(MetadataFileReportRecord(report, &string_table)); records.push_back(MetadataFileReportRecord(report, &string_table));
@ -584,12 +582,11 @@ OperationStatus Metadata::VerifyReport(const ReportDisk& report_disk,
bool EnsureDirectory(const base::FilePath& path) { bool EnsureDirectory(const base::FilePath& path) {
DWORD fileattr = GetFileAttributes(path.value().c_str()); DWORD fileattr = GetFileAttributes(path.value().c_str());
if (fileattr == INVALID_FILE_ATTRIBUTES) { if (fileattr == INVALID_FILE_ATTRIBUTES) {
PLOG(ERROR) << "GetFileAttributes " << base::UTF16ToUTF8(path.value()); PLOG(ERROR) << "GetFileAttributes " << base::WideToUTF8(path.value());
return false; return false;
} }
if ((fileattr & FILE_ATTRIBUTE_DIRECTORY) == 0) { if ((fileattr & FILE_ATTRIBUTE_DIRECTORY) == 0) {
LOG(ERROR) << "GetFileAttributes " LOG(ERROR) << "GetFileAttributes " << base::WideToUTF8(path.value())
<< base::UTF16ToUTF8(path.value())
<< ": not a directory"; << ": not a directory";
return false; return false;
} }
@ -606,7 +603,7 @@ bool CreateDirectoryIfNecessary(const base::FilePath& path) {
if (CreateDirectory(path.value().c_str(), nullptr)) if (CreateDirectory(path.value().c_str(), nullptr))
return true; return true;
if (GetLastError() != ERROR_ALREADY_EXISTS) { if (GetLastError() != ERROR_ALREADY_EXISTS) {
PLOG(ERROR) << "CreateDirectory " << base::UTF16ToUTF8(path.value()); PLOG(ERROR) << "CreateDirectory " << base::WideToUTF8(path.value());
return false; return false;
} }
return EnsureDirectory(path); return EnsureDirectory(path);
@ -675,7 +672,7 @@ base::FilePath CrashReportDatabaseWin::AttachmentsRootPath() {
} }
base::FilePath CrashReportDatabaseWin::AttachmentsPath(const UUID& uuid) { base::FilePath CrashReportDatabaseWin::AttachmentsPath(const UUID& uuid) {
const std::wstring uuid_string = uuid.ToString16(); const std::wstring uuid_string = uuid.ToWString();
return base_dir_.Append(kAttachmentsDirectory).Append(uuid_string); return base_dir_.Append(kAttachmentsDirectory).Append(uuid_string);
} }
@ -691,7 +688,7 @@ FileWriter* CrashReportDatabase::NewReport::AddAttachment(
return nullptr; return nullptr;
} }
base::FilePath path = attachments_dir.Append(base::UTF8ToUTF16(name)); base::FilePath path = attachments_dir.Append(base::UTF8ToWide(name));
auto writer = std::make_unique<FileWriter>(); auto writer = std::make_unique<FileWriter>();
if (!writer->Open( if (!writer->Open(
@ -727,7 +724,7 @@ void CrashReportDatabase::UploadReport::InitializeAttachments() {
continue; continue;
} }
attachment_readers_.emplace_back(std::move(file_reader)); attachment_readers_.emplace_back(std::move(file_reader));
attachment_map_[base::UTF16ToUTF8(filename.value())] = attachment_map_[base::WideToUTF8(filename.value())] =
attachment_readers_.back().get(); attachment_readers_.back().get();
} }
} }
@ -925,8 +922,7 @@ OperationStatus CrashReportDatabaseWin::DeleteReport(const UUID& uuid) {
return os; return os;
if (!DeleteFile(report_path.value().c_str())) { if (!DeleteFile(report_path.value().c_str())) {
PLOG(ERROR) << "DeleteFile " PLOG(ERROR) << "DeleteFile " << base::WideToUTF8(report_path.value());
<< base::UTF16ToUTF8(report_path.value());
return kFileSystemError; return kFileSystemError;
} }
@ -1096,7 +1092,7 @@ void CrashReportDatabaseWin::CleanOrphanedAttachments() {
// Remove attachments if corresponding report doen't exist. // Remove attachments if corresponding report doen't exist.
base::FilePath report_path = base::FilePath report_path =
reports_dir.Append(uuid.ToString16() + kCrashReportFileExtension); reports_dir.Append(uuid.ToWString() + kCrashReportFileExtension);
if (!IsRegularFile(report_path)) { if (!IsRegularFile(report_path)) {
RemoveAttachmentsByUUID(uuid); RemoveAttachmentsByUUID(uuid);
} }

View File

@ -26,7 +26,6 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/scoped_generic.h" #include "base/scoped_generic.h"
#include "base/strings/string16.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/synchronization/lock.h" #include "base/synchronization/lock.h"
@ -200,7 +199,7 @@ void HandleAbortSignal(int signum) {
std::wstring FormatArgumentString(const std::string& name, std::wstring FormatArgumentString(const std::string& name,
const std::wstring& value) { const std::wstring& value) {
return std::wstring(L"--") + base::UTF8ToUTF16(name) + L"=" + value; return std::wstring(L"--") + base::UTF8ToWide(name) + L"=" + value;
} }
struct ScopedProcThreadAttributeListTraits { struct ScopedProcThreadAttributeListTraits {
@ -282,7 +281,7 @@ void CreatePipe(std::wstring* pipe_name, ScopedFileHANDLE* pipe_instance) {
#endif #endif
GetCurrentProcessId()); GetCurrentProcessId());
do { do {
*pipe_name = base::UTF8ToUTF16(pipe_name_base + RandomString()); *pipe_name = base::UTF8ToWide(pipe_name_base + RandomString());
pipe_instance->reset(CreateNamedPipeInstance(*pipe_name, true)); pipe_instance->reset(CreateNamedPipeInstance(*pipe_name, true));
@ -362,7 +361,7 @@ bool StartHandlerProcess(
std::wstring command_line; std::wstring command_line;
AppendCommandLineArgument(data->handler.value(), &command_line); AppendCommandLineArgument(data->handler.value(), &command_line);
for (const std::string& argument : data->arguments) { for (const std::string& argument : data->arguments) {
AppendCommandLineArgument(base::UTF8ToUTF16(argument), &command_line); AppendCommandLineArgument(base::UTF8ToWide(argument), &command_line);
} }
if (!data->database.value().empty()) { if (!data->database.value().empty()) {
AppendCommandLineArgument( AppendCommandLineArgument(
@ -376,13 +375,13 @@ bool StartHandlerProcess(
} }
if (!data->url.empty()) { if (!data->url.empty()) {
AppendCommandLineArgument( AppendCommandLineArgument(
FormatArgumentString("url", base::UTF8ToUTF16(data->url)), FormatArgumentString("url", base::UTF8ToWide(data->url)),
&command_line); &command_line);
} }
for (const auto& kv : data->annotations) { for (const auto& kv : data->annotations) {
AppendCommandLineArgument( AppendCommandLineArgument(
FormatArgumentString("annotation", FormatArgumentString("annotation",
base::UTF8ToUTF16(kv.first + '=' + kv.second)), base::UTF8ToWide(kv.first + '=' + kv.second)),
&command_line); &command_line);
} }
for (const base::FilePath& attachment : data->attachments) { for (const base::FilePath& attachment : data->attachments) {
@ -408,8 +407,8 @@ bool StartHandlerProcess(
FromPointerCast<WinVMAddress>(&g_non_crash_exception_information), FromPointerCast<WinVMAddress>(&g_non_crash_exception_information),
FromPointerCast<WinVMAddress>(&g_critical_section_with_debug_info)); FromPointerCast<WinVMAddress>(&g_critical_section_with_debug_info));
AppendCommandLineArgument( AppendCommandLineArgument(
base::UTF8ToUTF16(std::string("--initial-client-data=") + base::UTF8ToWide(std::string("--initial-client-data=") +
initial_client_data.StringRepresentation()), initial_client_data.StringRepresentation()),
&command_line); &command_line);
BOOL rv; BOOL rv;
@ -495,7 +494,7 @@ bool StartHandlerProcess(
// invalid command line where the first argument needed by rundll32 is not in // invalid command line where the first argument needed by rundll32 is not in
// the correct format as required in: // the correct format as required in:
// https://support.microsoft.com/en-ca/help/164787/info-windows-rundll-and-rundll32-interface // https://support.microsoft.com/en-ca/help/164787/info-windows-rundll-and-rundll32-interface
const base::StringPiece16 kRunDll32Exe(L"rundll32.exe"); const base::WStringPiece kRunDll32Exe(L"rundll32.exe");
bool is_embedded_in_dll = false; bool is_embedded_in_dll = false;
if (data->handler.value().size() >= kRunDll32Exe.size() && if (data->handler.value().size() >= kRunDll32Exe.size() &&
_wcsicmp(data->handler.value() _wcsicmp(data->handler.value()

View File

@ -1097,7 +1097,7 @@ int HandlerMain(int argc,
ExceptionHandlerServer exception_handler_server(!options.pipe_name.empty()); ExceptionHandlerServer exception_handler_server(!options.pipe_name.empty());
if (!options.pipe_name.empty()) { if (!options.pipe_name.empty()) {
exception_handler_server.SetPipeName(base::UTF8ToUTF16(options.pipe_name)); exception_handler_server.SetPipeName(base::UTF8ToWide(options.pipe_name));
} }
#elif defined(OS_LINUX) || defined(OS_CHROMEOS) || defined(OS_ANDROID) #elif defined(OS_LINUX) || defined(OS_CHROMEOS) || defined(OS_ANDROID)
ExceptionHandlerServer exception_handler_server; ExceptionHandlerServer exception_handler_server;

View File

@ -126,7 +126,7 @@ unsigned int CrashReportExceptionHandler::ExceptionHandlerServerException(
base::FilePath filename = attachment.BaseName(); base::FilePath filename = attachment.BaseName();
FileWriter* file_writer = FileWriter* file_writer =
new_report->AddAttachment(base::UTF16ToUTF8(filename.value())); new_report->AddAttachment(base::WideToUTF8(filename.value()));
if (file_writer == nullptr) { if (file_writer == nullptr) {
LOG(ERROR) << "attachment " << filename.value().c_str() LOG(ERROR) << "attachment " << filename.value().c_str()
<< " couldn't be created, skipping"; << " couldn't be created, skipping";

View File

@ -310,7 +310,7 @@ void MinidumpMiscInfoWriter::SetTimeZone(uint32_t time_zone_id,
misc_info_.TimeZone.Bias = bias; misc_info_.TimeZone.Bias = bias;
internal::MinidumpWriterUtil::AssignUTF8ToUTF16( internal::MinidumpWriterUtil::AssignUTF8ToUTF16(
misc_info_.TimeZone.StandardName, AsU16CStr(misc_info_.TimeZone.StandardName),
base::size(misc_info_.TimeZone.StandardName), base::size(misc_info_.TimeZone.StandardName),
standard_name); standard_name);
@ -318,7 +318,7 @@ void MinidumpMiscInfoWriter::SetTimeZone(uint32_t time_zone_id,
misc_info_.TimeZone.StandardBias = standard_bias; misc_info_.TimeZone.StandardBias = standard_bias;
internal::MinidumpWriterUtil::AssignUTF8ToUTF16( internal::MinidumpWriterUtil::AssignUTF8ToUTF16(
misc_info_.TimeZone.DaylightName, AsU16CStr(misc_info_.TimeZone.DaylightName),
base::size(misc_info_.TimeZone.DaylightName), base::size(misc_info_.TimeZone.DaylightName),
daylight_name); daylight_name);
@ -336,9 +336,11 @@ void MinidumpMiscInfoWriter::SetBuildString(
misc_info_.Flags1 |= MINIDUMP_MISC4_BUILDSTRING; misc_info_.Flags1 |= MINIDUMP_MISC4_BUILDSTRING;
internal::MinidumpWriterUtil::AssignUTF8ToUTF16( internal::MinidumpWriterUtil::AssignUTF8ToUTF16(
misc_info_.BuildString, base::size(misc_info_.BuildString), build_string); AsU16CStr(misc_info_.BuildString),
base::size(misc_info_.BuildString),
build_string);
internal::MinidumpWriterUtil::AssignUTF8ToUTF16( internal::MinidumpWriterUtil::AssignUTF8ToUTF16(
misc_info_.DbgBldStr, AsU16CStr(misc_info_.DbgBldStr),
base::size(misc_info_.DbgBldStr), base::size(misc_info_.DbgBldStr),
debug_build_string); debug_build_string);
} }

View File

@ -20,10 +20,13 @@
#include <stdint.h> #include <stdint.h>
#include <sys/types.h> #include <sys/types.h>
#include <time.h> #include <time.h>
#include <wchar.h>
#include <string> #include <string>
#include "base/macros.h" #include "base/macros.h"
#include "base/strings/string16.h"
#include "build/build_config.h"
#include "minidump/minidump_stream_writer.h" #include "minidump/minidump_stream_writer.h"
#include "minidump/minidump_writable.h" #include "minidump/minidump_writable.h"
@ -137,6 +140,26 @@ class MinidumpMiscInfoWriter final : public internal::MinidumpStreamWriter {
DISALLOW_COPY_AND_ASSIGN(MinidumpMiscInfoWriter); DISALLOW_COPY_AND_ASSIGN(MinidumpMiscInfoWriter);
}; };
//! \brief Conversion functions from a native UTF16 C-string to a base::char16
//! C-string. No-op where the native UTF16 string is base::string16.
#if defined(WCHAR_T_IS_UTF16) || DOXYGEN
inline const base::char16* AsU16CStr(const wchar_t* str) {
return reinterpret_cast<const base::char16*>(str);
}
inline base::char16* AsU16CStr(wchar_t* str) {
return reinterpret_cast<base::char16*>(str);
}
#else
inline const base::char16* AsU16CStr(const base::char16* str) {
return str;
}
inline base::char16* AsU16CStr(base::char16* str) {
return str;
}
#endif
} // namespace crashpad } // namespace crashpad
#endif // CRASHPAD_MINIDUMP_MINIDUMP_MISC_INFO_WRITER_H_ #endif // CRASHPAD_MINIDUMP_MINIDUMP_MISC_INFO_WRITER_H_

View File

@ -125,8 +125,8 @@ void ExpectMiscInfoEqual<MINIDUMP_MISC_INFO_3>(
EXPECT_EQ(observed->TimeZone.Bias, expected->TimeZone.Bias); EXPECT_EQ(observed->TimeZone.Bias, expected->TimeZone.Bias);
{ {
SCOPED_TRACE("Standard"); SCOPED_TRACE("Standard");
ExpectNULPaddedString16Equal(expected->TimeZone.StandardName, ExpectNULPaddedString16Equal(AsU16CStr(expected->TimeZone.StandardName),
observed->TimeZone.StandardName, AsU16CStr(observed->TimeZone.StandardName),
base::size(expected->TimeZone.StandardName)); base::size(expected->TimeZone.StandardName));
ExpectSystemTimeEqual(&expected->TimeZone.StandardDate, ExpectSystemTimeEqual(&expected->TimeZone.StandardDate,
&observed->TimeZone.StandardDate); &observed->TimeZone.StandardDate);
@ -134,8 +134,8 @@ void ExpectMiscInfoEqual<MINIDUMP_MISC_INFO_3>(
} }
{ {
SCOPED_TRACE("Daylight"); SCOPED_TRACE("Daylight");
ExpectNULPaddedString16Equal(expected->TimeZone.DaylightName, ExpectNULPaddedString16Equal(AsU16CStr(expected->TimeZone.DaylightName),
observed->TimeZone.DaylightName, AsU16CStr(observed->TimeZone.DaylightName),
base::size(expected->TimeZone.DaylightName)); base::size(expected->TimeZone.DaylightName));
ExpectSystemTimeEqual(&expected->TimeZone.DaylightDate, ExpectSystemTimeEqual(&expected->TimeZone.DaylightDate,
&observed->TimeZone.DaylightDate); &observed->TimeZone.DaylightDate);
@ -152,14 +152,14 @@ void ExpectMiscInfoEqual<MINIDUMP_MISC_INFO_4>(
reinterpret_cast<const MINIDUMP_MISC_INFO_3*>(observed)); reinterpret_cast<const MINIDUMP_MISC_INFO_3*>(observed));
{ {
SCOPED_TRACE("BuildString"); SCOPED_TRACE("BuildString");
ExpectNULPaddedString16Equal(expected->BuildString, ExpectNULPaddedString16Equal(AsU16CStr(expected->BuildString),
observed->BuildString, AsU16CStr(observed->BuildString),
base::size(expected->BuildString)); base::size(expected->BuildString));
} }
{ {
SCOPED_TRACE("DbgBldStr"); SCOPED_TRACE("DbgBldStr");
ExpectNULPaddedString16Equal(expected->DbgBldStr, ExpectNULPaddedString16Equal(AsU16CStr(expected->DbgBldStr),
observed->DbgBldStr, AsU16CStr(observed->DbgBldStr),
base::size(expected->DbgBldStr)); base::size(expected->DbgBldStr));
} }
} }
@ -394,7 +394,7 @@ TEST(MinidumpMiscInfoWriter, TimeZone) {
expected.TimeZoneId = kTimeZoneId; expected.TimeZoneId = kTimeZoneId;
expected.TimeZone.Bias = kBias; expected.TimeZone.Bias = kBias;
base::string16 standard_name_utf16 = base::UTF8ToUTF16(kStandardName); base::string16 standard_name_utf16 = base::UTF8ToUTF16(kStandardName);
c16lcpy(expected.TimeZone.StandardName, c16lcpy(AsU16CStr(expected.TimeZone.StandardName),
standard_name_utf16.c_str(), standard_name_utf16.c_str(),
base::size(expected.TimeZone.StandardName)); base::size(expected.TimeZone.StandardName));
memcpy(&expected.TimeZone.StandardDate, memcpy(&expected.TimeZone.StandardDate,
@ -402,7 +402,7 @@ TEST(MinidumpMiscInfoWriter, TimeZone) {
sizeof(expected.TimeZone.StandardDate)); sizeof(expected.TimeZone.StandardDate));
expected.TimeZone.StandardBias = kStandardBias; expected.TimeZone.StandardBias = kStandardBias;
base::string16 daylight_name_utf16 = base::UTF8ToUTF16(kDaylightName); base::string16 daylight_name_utf16 = base::UTF8ToUTF16(kDaylightName);
c16lcpy(expected.TimeZone.DaylightName, c16lcpy(AsU16CStr(expected.TimeZone.DaylightName),
daylight_name_utf16.c_str(), daylight_name_utf16.c_str(),
base::size(expected.TimeZone.DaylightName)); base::size(expected.TimeZone.DaylightName));
memcpy(&expected.TimeZone.DaylightDate, memcpy(&expected.TimeZone.DaylightDate,
@ -455,7 +455,7 @@ TEST(MinidumpMiscInfoWriter, TimeZoneStringsOverflow) {
expected.TimeZoneId = kTimeZoneId; expected.TimeZoneId = kTimeZoneId;
expected.TimeZone.Bias = kBias; expected.TimeZone.Bias = kBias;
base::string16 standard_name_utf16 = base::UTF8ToUTF16(standard_name); base::string16 standard_name_utf16 = base::UTF8ToUTF16(standard_name);
c16lcpy(expected.TimeZone.StandardName, c16lcpy(AsU16CStr(expected.TimeZone.StandardName),
standard_name_utf16.c_str(), standard_name_utf16.c_str(),
base::size(expected.TimeZone.StandardName)); base::size(expected.TimeZone.StandardName));
memcpy(&expected.TimeZone.StandardDate, memcpy(&expected.TimeZone.StandardDate,
@ -463,7 +463,7 @@ TEST(MinidumpMiscInfoWriter, TimeZoneStringsOverflow) {
sizeof(expected.TimeZone.StandardDate)); sizeof(expected.TimeZone.StandardDate));
expected.TimeZone.StandardBias = kStandardBias; expected.TimeZone.StandardBias = kStandardBias;
base::string16 daylight_name_utf16 = base::UTF8ToUTF16(daylight_name); base::string16 daylight_name_utf16 = base::UTF8ToUTF16(daylight_name);
c16lcpy(expected.TimeZone.DaylightName, c16lcpy(AsU16CStr(expected.TimeZone.DaylightName),
daylight_name_utf16.c_str(), daylight_name_utf16.c_str(),
base::size(expected.TimeZone.DaylightName)); base::size(expected.TimeZone.DaylightName));
memcpy(&expected.TimeZone.DaylightDate, memcpy(&expected.TimeZone.DaylightDate,
@ -494,12 +494,12 @@ TEST(MinidumpMiscInfoWriter, BuildStrings) {
MINIDUMP_MISC_INFO_4 expected = {}; MINIDUMP_MISC_INFO_4 expected = {};
expected.Flags1 = MINIDUMP_MISC4_BUILDSTRING; expected.Flags1 = MINIDUMP_MISC4_BUILDSTRING;
base::string16 build_string_utf16 = base::UTF8ToUTF16(kBuildString); base::string16 build_string_utf16 = base::UTF8ToUTF16(kBuildString);
c16lcpy(expected.BuildString, c16lcpy(AsU16CStr(expected.BuildString),
build_string_utf16.c_str(), build_string_utf16.c_str(),
base::size(expected.BuildString)); base::size(expected.BuildString));
base::string16 debug_build_string_utf16 = base::string16 debug_build_string_utf16 =
base::UTF8ToUTF16(kDebugBuildString); base::UTF8ToUTF16(kDebugBuildString);
c16lcpy(expected.DbgBldStr, c16lcpy(AsU16CStr(expected.DbgBldStr),
debug_build_string_utf16.c_str(), debug_build_string_utf16.c_str(),
base::size(expected.DbgBldStr)); base::size(expected.DbgBldStr));
@ -531,12 +531,12 @@ TEST(MinidumpMiscInfoWriter, BuildStringsOverflow) {
MINIDUMP_MISC_INFO_4 expected = {}; MINIDUMP_MISC_INFO_4 expected = {};
expected.Flags1 = MINIDUMP_MISC4_BUILDSTRING; expected.Flags1 = MINIDUMP_MISC4_BUILDSTRING;
base::string16 build_string_utf16 = base::UTF8ToUTF16(build_string); base::string16 build_string_utf16 = base::UTF8ToUTF16(build_string);
c16lcpy(expected.BuildString, c16lcpy(AsU16CStr(expected.BuildString),
build_string_utf16.c_str(), build_string_utf16.c_str(),
base::size(expected.BuildString)); base::size(expected.BuildString));
base::string16 debug_build_string_utf16 = base::string16 debug_build_string_utf16 =
base::UTF8ToUTF16(debug_build_string); base::UTF8ToUTF16(debug_build_string);
c16lcpy(expected.DbgBldStr, c16lcpy(AsU16CStr(expected.DbgBldStr),
debug_build_string_utf16.c_str(), debug_build_string_utf16.c_str(),
base::size(expected.DbgBldStr)); base::size(expected.DbgBldStr));
@ -676,7 +676,7 @@ TEST(MinidumpMiscInfoWriter, Everything) {
expected.TimeZoneId = kTimeZoneId; expected.TimeZoneId = kTimeZoneId;
expected.TimeZone.Bias = kBias; expected.TimeZone.Bias = kBias;
base::string16 standard_name_utf16 = base::UTF8ToUTF16(kStandardName); base::string16 standard_name_utf16 = base::UTF8ToUTF16(kStandardName);
c16lcpy(expected.TimeZone.StandardName, c16lcpy(AsU16CStr(expected.TimeZone.StandardName),
standard_name_utf16.c_str(), standard_name_utf16.c_str(),
base::size(expected.TimeZone.StandardName)); base::size(expected.TimeZone.StandardName));
memcpy(&expected.TimeZone.StandardDate, memcpy(&expected.TimeZone.StandardDate,
@ -684,7 +684,7 @@ TEST(MinidumpMiscInfoWriter, Everything) {
sizeof(expected.TimeZone.StandardDate)); sizeof(expected.TimeZone.StandardDate));
expected.TimeZone.StandardBias = kStandardBias; expected.TimeZone.StandardBias = kStandardBias;
base::string16 daylight_name_utf16 = base::UTF8ToUTF16(kDaylightName); base::string16 daylight_name_utf16 = base::UTF8ToUTF16(kDaylightName);
c16lcpy(expected.TimeZone.DaylightName, c16lcpy(AsU16CStr(expected.TimeZone.DaylightName),
daylight_name_utf16.c_str(), daylight_name_utf16.c_str(),
base::size(expected.TimeZone.DaylightName)); base::size(expected.TimeZone.DaylightName));
memcpy(&expected.TimeZone.DaylightDate, memcpy(&expected.TimeZone.DaylightDate,
@ -692,12 +692,12 @@ TEST(MinidumpMiscInfoWriter, Everything) {
sizeof(expected.TimeZone.DaylightDate)); sizeof(expected.TimeZone.DaylightDate));
expected.TimeZone.DaylightBias = kDaylightBias; expected.TimeZone.DaylightBias = kDaylightBias;
base::string16 build_string_utf16 = base::UTF8ToUTF16(kBuildString); base::string16 build_string_utf16 = base::UTF8ToUTF16(kBuildString);
c16lcpy(expected.BuildString, c16lcpy(AsU16CStr(expected.BuildString),
build_string_utf16.c_str(), build_string_utf16.c_str(),
base::size(expected.BuildString)); base::size(expected.BuildString));
base::string16 debug_build_string_utf16 = base::string16 debug_build_string_utf16 =
base::UTF8ToUTF16(kDebugBuildString); base::UTF8ToUTF16(kDebugBuildString);
c16lcpy(expected.DbgBldStr, c16lcpy(AsU16CStr(expected.DbgBldStr),
debug_build_string_utf16.c_str(), debug_build_string_utf16.c_str(),
base::size(expected.DbgBldStr)); base::size(expected.DbgBldStr));
@ -741,18 +741,18 @@ TEST(MinidumpMiscInfoWriter, InitializeFromSnapshot) {
expect_misc_info.ProcessorMaxMhz = 2800; expect_misc_info.ProcessorMaxMhz = 2800;
expect_misc_info.TimeZoneId = 1; expect_misc_info.TimeZoneId = 1;
expect_misc_info.TimeZone.Bias = 300; expect_misc_info.TimeZone.Bias = 300;
c16lcpy(expect_misc_info.TimeZone.StandardName, c16lcpy(AsU16CStr(expect_misc_info.TimeZone.StandardName),
standard_time_name_utf16.c_str(), standard_time_name_utf16.c_str(),
base::size(expect_misc_info.TimeZone.StandardName)); base::size(expect_misc_info.TimeZone.StandardName));
expect_misc_info.TimeZone.StandardBias = 0; expect_misc_info.TimeZone.StandardBias = 0;
c16lcpy(expect_misc_info.TimeZone.DaylightName, c16lcpy(AsU16CStr(expect_misc_info.TimeZone.DaylightName),
daylight_time_name_utf16.c_str(), daylight_time_name_utf16.c_str(),
base::size(expect_misc_info.TimeZone.DaylightName)); base::size(expect_misc_info.TimeZone.DaylightName));
expect_misc_info.TimeZone.DaylightBias = -60; expect_misc_info.TimeZone.DaylightBias = -60;
c16lcpy(expect_misc_info.BuildString, c16lcpy(AsU16CStr(expect_misc_info.BuildString),
build_string_utf16.c_str(), build_string_utf16.c_str(),
base::size(expect_misc_info.BuildString)); base::size(expect_misc_info.BuildString));
c16lcpy(expect_misc_info.DbgBldStr, c16lcpy(AsU16CStr(expect_misc_info.DbgBldStr),
debug_build_string_utf16.c_str(), debug_build_string_utf16.c_str(),
base::size(expect_misc_info.DbgBldStr)); base::size(expect_misc_info.DbgBldStr));

View File

@ -159,9 +159,9 @@ TEST(CrashpadInfoClientOptions, TwoModules) {
<< dlerror(); << dlerror();
#elif defined(OS_WIN) #elif defined(OS_WIN)
ScopedModuleHandle module(LoadLibrary(module_path.value().c_str())); ScopedModuleHandle module(LoadLibrary(module_path.value().c_str()));
ASSERT_TRUE(module.valid()) << "LoadLibrary " ASSERT_TRUE(module.valid())
<< base::UTF16ToUTF8(module_path.value()) << ": " << "LoadLibrary " << base::WideToUTF8(module_path.value()) << ": "
<< ErrorMessage(); << ErrorMessage();
#else #else
#error Port. #error Port.
#endif // OS_APPLE #endif // OS_APPLE
@ -258,7 +258,7 @@ TEST_P(CrashpadInfoSizes_ClientOptions, DifferentlySizedStruct) {
#elif defined(OS_WIN) #elif defined(OS_WIN)
ScopedModuleHandle module(LoadLibrary(module_path.value().c_str())); ScopedModuleHandle module(LoadLibrary(module_path.value().c_str()));
ASSERT_TRUE(module.valid()) ASSERT_TRUE(module.valid())
<< "LoadLibrary " << base::UTF16ToUTF8(module_path.value()) << ": " << "LoadLibrary " << base::WideToUTF8(module_path.value()) << ": "
<< ErrorMessage(); << ErrorMessage();
#else #else
#error Port. #error Port.

View File

@ -19,6 +19,7 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/notreached.h" #include "base/notreached.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "minidump/minidump_extensions.h" #include "minidump/minidump_extensions.h"
#include "snapshot/memory_map_region_snapshot.h" #include "snapshot/memory_map_region_snapshot.h"
#include "snapshot/minidump/minidump_simple_string_dictionary_reader.h" #include "snapshot/minidump/minidump_simple_string_dictionary_reader.h"
@ -312,7 +313,11 @@ bool ProcessSnapshotMinidump::InitializeMiscInfo() {
switch (stream_it->second->DataSize) { switch (stream_it->second->DataSize) {
case sizeof(MINIDUMP_MISC_INFO_5): case sizeof(MINIDUMP_MISC_INFO_5):
case sizeof(MINIDUMP_MISC_INFO_4): case sizeof(MINIDUMP_MISC_INFO_4):
#if defined(WCHAR_T_IS_UTF16)
full_version_ = base::WideToUTF8(info.BuildString);
#else
full_version_ = base::UTF16ToUTF8(info.BuildString); full_version_ = base::UTF16ToUTF8(info.BuildString);
#endif
full_version_ = full_version_.substr(0, full_version_.find(";")); full_version_ = full_version_.substr(0, full_version_.find(";"));
FALLTHROUGH; FALLTHROUGH;
case sizeof(MINIDUMP_MISC_INFO_3): case sizeof(MINIDUMP_MISC_INFO_3):

View File

@ -17,7 +17,6 @@
#include <string> #include <string>
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "client/crashpad_client.h" #include "client/crashpad_client.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"

View File

@ -58,7 +58,7 @@ bool ModuleSnapshotWin::Initialize(
if (!pe_image_reader_->Initialize(process_reader_, if (!pe_image_reader_->Initialize(process_reader_,
process_reader_module.dll_base, process_reader_module.dll_base,
process_reader_module.size, process_reader_module.size,
base::UTF16ToUTF8(name_))) { base::WideToUTF8(name_))) {
return false; return false;
} }
@ -73,7 +73,7 @@ bool ModuleSnapshotWin::Initialize(
// would do). As we don't expect to ever encounter a module that wouldn't be // would do). As we don't expect to ever encounter a module that wouldn't be
// using .PDB that we actually have symbols for, we simply set a plausible // using .PDB that we actually have symbols for, we simply set a plausible
// name here, but this will never correspond to symbols that we have. // name here, but this will never correspond to symbols that we have.
pdb_name_ = base::UTF16ToUTF8(name_); pdb_name_ = base::WideToUTF8(name_);
} }
if (!memory_range_.Initialize(process_reader_->Memory(), if (!memory_range_.Initialize(process_reader_->Memory(),
@ -110,7 +110,7 @@ void ModuleSnapshotWin::GetCrashpadOptions(CrashpadInfoClientOptions* options) {
std::string ModuleSnapshotWin::Name() const { std::string ModuleSnapshotWin::Name() const {
INITIALIZATION_STATE_DCHECK_VALID(initialized_); INITIALIZATION_STATE_DCHECK_VALID(initialized_);
return base::UTF16ToUTF8(name_); return base::WideToUTF8(name_);
} }
uint64_t ModuleSnapshotWin::Address() const { uint64_t ModuleSnapshotWin::Address() const {
@ -299,7 +299,7 @@ void ModuleSnapshotWin::GetCrashpadExtraMemoryRanges(
simple_ranges.size() * sizeof(simple_ranges[0]), simple_ranges.size() * sizeof(simple_ranges[0]),
&simple_ranges[0])) { &simple_ranges[0])) {
LOG(WARNING) << "could not read simple address_ranges from " LOG(WARNING) << "could not read simple address_ranges from "
<< base::UTF16ToUTF8(name_); << base::WideToUTF8(name_);
return; return;
} }
@ -322,7 +322,7 @@ void ModuleSnapshotWin::GetCrashpadUserMinidumpStreams(
if (!process_reader_->Memory()->Read( if (!process_reader_->Memory()->Read(
cur, sizeof(list_entry), &list_entry)) { cur, sizeof(list_entry), &list_entry)) {
LOG(WARNING) << "could not read user data stream entry from " LOG(WARNING) << "could not read user data stream entry from "
<< base::UTF16ToUTF8(name_); << base::WideToUTF8(name_);
return; return;
} }

View File

@ -99,7 +99,7 @@ void PEImageAnnotationsReader::ReadCrashpadSimpleAnnotations(
simple_annotations.size() * sizeof(simple_annotations[0]), simple_annotations.size() * sizeof(simple_annotations[0]),
&simple_annotations[0])) { &simple_annotations[0])) {
LOG(WARNING) << "could not read simple annotations from " LOG(WARNING) << "could not read simple annotations from "
<< base::UTF16ToUTF8(name_); << base::WideToUTF8(name_);
return; return;
} }
@ -110,7 +110,7 @@ void PEImageAnnotationsReader::ReadCrashpadSimpleAnnotations(
std::string value(entry.value, strnlen(entry.value, sizeof(entry.value))); std::string value(entry.value, strnlen(entry.value, sizeof(entry.value)));
if (!simple_map_annotations->insert(std::make_pair(key, value)).second) { if (!simple_map_annotations->insert(std::make_pair(key, value)).second) {
LOG(INFO) << "duplicate simple annotation " << key << " in " LOG(INFO) << "duplicate simple annotation " << key << " in "
<< base::UTF16ToUTF8(name_); << base::WideToUTF8(name_);
} }
} }
} }
@ -133,7 +133,7 @@ void PEImageAnnotationsReader::ReadCrashpadAnnotationsList(
sizeof(annotation_list_object), sizeof(annotation_list_object),
&annotation_list_object)) { &annotation_list_object)) {
LOG(WARNING) << "could not read annotations list object in " LOG(WARNING) << "could not read annotations list object in "
<< base::UTF16ToUTF8(name_); << base::WideToUTF8(name_);
return; return;
} }
@ -145,7 +145,7 @@ void PEImageAnnotationsReader::ReadCrashpadAnnotationsList(
if (!process_reader_->Memory()->Read( if (!process_reader_->Memory()->Read(
current.link_node, sizeof(current), &current)) { current.link_node, sizeof(current), &current)) {
LOG(WARNING) << "could not read annotation at index " << index << " in " LOG(WARNING) << "could not read annotation at index " << index << " in "
<< base::UTF16ToUTF8(name_); << base::WideToUTF8(name_);
return; return;
} }
@ -160,7 +160,7 @@ void PEImageAnnotationsReader::ReadCrashpadAnnotationsList(
if (!process_reader_->Memory()->Read( if (!process_reader_->Memory()->Read(
current.name, base::size(name), name)) { current.name, base::size(name), name)) {
LOG(WARNING) << "could not read annotation name at index " << index LOG(WARNING) << "could not read annotation name at index " << index
<< " in " << base::UTF16ToUTF8(name_); << " in " << base::WideToUTF8(name_);
continue; continue;
} }
@ -173,7 +173,7 @@ void PEImageAnnotationsReader::ReadCrashpadAnnotationsList(
if (!process_reader_->Memory()->Read( if (!process_reader_->Memory()->Read(
current.value, value_length, snapshot.value.data())) { current.value, value_length, snapshot.value.data())) {
LOG(WARNING) << "could not read annotation value at index " << index LOG(WARNING) << "could not read annotation value at index " << index
<< " in " << base::UTF16ToUTF8(name_); << " in " << base::WideToUTF8(name_);
continue; continue;
} }

View File

@ -62,14 +62,14 @@ TEST(PEImageReader, DebugDirectory) {
&process_reader, &process_reader,
FromPointerCast<WinVMAddress>(module_handle.get()), FromPointerCast<WinVMAddress>(module_handle.get()),
module_info.SizeOfImage, module_info.SizeOfImage,
base::UTF16ToUTF8(module_basename.value()))); base::WideToUTF8(module_basename.value())));
UUID uuid; UUID uuid;
DWORD age; DWORD age;
std::string pdbname; std::string pdbname;
ASSERT_TRUE(pe_image_reader.DebugDirectoryInformation(&uuid, &age, &pdbname)); ASSERT_TRUE(pe_image_reader.DebugDirectoryInformation(&uuid, &age, &pdbname));
std::string module_name = std::string module_name =
base::UTF16ToUTF8(module_basename.RemoveFinalExtension().value()); base::WideToUTF8(module_basename.RemoveFinalExtension().value());
EXPECT_NE(pdbname.find(module_name), std::string::npos); EXPECT_NE(pdbname.find(module_name), std::string::npos);
const std::string suffix(".pdb"); const std::string suffix(".pdb");
EXPECT_EQ( EXPECT_EQ(
@ -84,7 +84,7 @@ void TestVSFixedFileInfo(ProcessReaderWin* process_reader,
ASSERT_TRUE(pe_image_reader.Initialize(process_reader, ASSERT_TRUE(pe_image_reader.Initialize(process_reader,
module.dll_base, module.dll_base,
module.size, module.size,
base::UTF16ToUTF8(module.name))); base::WideToUTF8(module.name)));
VS_FIXEDFILEINFO observed; VS_FIXEDFILEINFO observed;
const bool observed_rv = pe_image_reader.VSFixedFileInfo(&observed); const bool observed_rv = pe_image_reader.VSFixedFileInfo(&observed);
@ -183,7 +183,7 @@ TEST(PEImageReader, VSFixedFileInfo_AllModules) {
EXPECT_GT(modules.size(), 2u); EXPECT_GT(modules.size(), 2u);
for (const auto& module : modules) { for (const auto& module : modules) {
SCOPED_TRACE(base::UTF16ToUTF8(module.name)); SCOPED_TRACE(base::WideToUTF8(module.name));
TestVSFixedFileInfo(&process_reader, module, false); TestVSFixedFileInfo(&process_reader, module, false);
} }
} }

View File

@ -214,7 +214,7 @@ std::vector<HandleSnapshot> ProcessSnapshotWin::Handles() const {
// This is probably not strictly correct, but these are not localized so we // This is probably not strictly correct, but these are not localized so we
// expect them all to be in ASCII range anyway. This will need to be more // expect them all to be in ASCII range anyway. This will need to be more
// carefully done if the object name is added. // carefully done if the object name is added.
snapshot.type_name = base::UTF16ToUTF8(handle.type_name); snapshot.type_name = base::WideToUTF8(handle.type_name);
snapshot.handle = handle.handle; snapshot.handle = handle.handle;
snapshot.attributes = handle.attributes; snapshot.attributes = handle.attributes;
snapshot.granted_access = handle.granted_access; snapshot.granted_access = handle.granted_access;
@ -333,7 +333,7 @@ void ProcessSnapshotWin::InitializeUnloadedModules() {
uet.SizeOfImage, uet.SizeOfImage,
uet.CheckSum, uet.CheckSum,
uet.TimeDateStamp, uet.TimeDateStamp,
base::UTF16ToUTF8(base::StringPiece16( base::WideToUTF8(base::WStringPiece(
uet.ImageName, uet.ImageName,
wcsnlen(uet.ImageName, base::size(uet.ImageName)))))); wcsnlen(uet.ImageName, base::size(uet.ImageName))))));
} }

View File

@ -35,7 +35,7 @@ void TestImageReaderChild(const TestPaths::Architecture architecture) {
UUID done_uuid; UUID done_uuid;
done_uuid.InitializeWithNew(); done_uuid.InitializeWithNew();
ScopedKernelHANDLE done( ScopedKernelHANDLE done(
CreateEvent(nullptr, true, false, done_uuid.ToString16().c_str())); CreateEvent(nullptr, true, false, done_uuid.ToWString().c_str()));
ASSERT_TRUE(done.is_valid()) << ErrorMessage("CreateEvent"); ASSERT_TRUE(done.is_valid()) << ErrorMessage("CreateEvent");
base::FilePath child_test_executable = base::FilePath child_test_executable =
@ -43,7 +43,7 @@ void TestImageReaderChild(const TestPaths::Architecture architecture) {
L"image_reader", L"image_reader",
TestPaths::FileType::kExecutable, TestPaths::FileType::kExecutable,
architecture); architecture);
ChildLauncher child(child_test_executable, done_uuid.ToString16()); ChildLauncher child(child_test_executable, done_uuid.ToWString());
ASSERT_NO_FATAL_FAILURE(child.Start()); ASSERT_NO_FATAL_FAILURE(child.Start());
ScopedSetEvent set_done(done.get()); ScopedSetEvent set_done(done.get());

View File

@ -410,8 +410,8 @@ void SystemSnapshotWin::TimeZone(DaylightSavingTimeStatus* dst_status,
(time_zone_information.Bias + time_zone_information.StandardBias) * -60; (time_zone_information.Bias + time_zone_information.StandardBias) * -60;
*daylight_offset_seconds = *daylight_offset_seconds =
(time_zone_information.Bias + time_zone_information.DaylightBias) * -60; (time_zone_information.Bias + time_zone_information.DaylightBias) * -60;
*standard_name = base::UTF16ToUTF8(time_zone_information.StandardName); *standard_name = base::WideToUTF8(time_zone_information.StandardName);
*daylight_name = base::UTF16ToUTF8(time_zone_information.DaylightName); *daylight_name = base::WideToUTF8(time_zone_information.DaylightName);
} }
} // namespace internal } // namespace internal

View File

@ -111,8 +111,7 @@ bool PathExists(const base::FilePath& path) {
#elif defined(OS_WIN) #elif defined(OS_WIN)
if (GetFileAttributes(path.value().c_str()) == INVALID_FILE_ATTRIBUTES) { if (GetFileAttributes(path.value().c_str()) == INVALID_FILE_ATTRIBUTES) {
EXPECT_EQ(GetLastError(), static_cast<DWORD>(ERROR_FILE_NOT_FOUND)) EXPECT_EQ(GetLastError(), static_cast<DWORD>(ERROR_FILE_NOT_FOUND))
<< ErrorMessage("GetFileAttributes ") << ErrorMessage("GetFileAttributes ") << base::WideToUTF8(path.value());
<< base::UTF16ToUTF8(path.value());
return false; return false;
} }
return true; return true;
@ -163,13 +162,13 @@ bool SetFileModificationTime(const base::FilePath& path,
flags, flags,
nullptr)); nullptr));
if (!handle.is_valid()) { if (!handle.is_valid()) {
PLOG(ERROR) << "CreateFile " << base::UTF16ToUTF8(path.value()); PLOG(ERROR) << "CreateFile " << base::WideToUTF8(path.value());
return false; return false;
} }
FILETIME filetime = TimespecToFiletimeEpoch(mtime); FILETIME filetime = TimespecToFiletimeEpoch(mtime);
if (!SetFileTime(handle.get(), nullptr, nullptr, &filetime)) { if (!SetFileTime(handle.get(), nullptr, nullptr, &filetime)) {
PLOG(ERROR) << "SetFileTime " << base::UTF16ToUTF8(path.value()); PLOG(ERROR) << "SetFileTime " << base::WideToUTF8(path.value());
return false; return false;
} }
return true; return true;

View File

@ -125,7 +125,7 @@ void MultiprocessExec::PreFork() {
command_line_.clear(); command_line_.clear();
AppendCommandLineArgument(command_.value(), &command_line_); AppendCommandLineArgument(command_.value(), &command_line_);
for (size_t i = 0; i < arguments_.size(); ++i) { for (size_t i = 0; i < arguments_.size(); ++i) {
AppendCommandLineArgument(base::UTF8ToUTF16(arguments_[i]), &command_line_); AppendCommandLineArgument(base::UTF8ToWide(arguments_[i]), &command_line_);
} }
// Make pipes for child-to-parent and parent-to-child communication. Mark them // Make pipes for child-to-parent and parent-to-child communication. Mark them

View File

@ -19,6 +19,8 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <string>
#include "base/check.h" #include "base/check.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"

View File

@ -14,10 +14,12 @@
#include "test/scoped_temp_dir.h" #include "test/scoped_temp_dir.h"
#include <wchar.h>
#include <windows.h> #include <windows.h>
#include <string>
#include "base/check.h" #include "base/check.h"
#include "base/strings/string16.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
@ -33,7 +35,7 @@ base::FilePath GenerateCandidateName() {
DWORD path_len = GetTempPath(MAX_PATH, temp_path); DWORD path_len = GetTempPath(MAX_PATH, temp_path);
PCHECK(path_len != 0) << "GetTempPath"; PCHECK(path_len != 0) << "GetTempPath";
base::FilePath system_temp_dir(temp_path); base::FilePath system_temp_dir(temp_path);
base::string16 new_dir_name = base::UTF8ToUTF16(base::StringPrintf( std::wstring new_dir_name = base::UTF8ToWide(base::StringPrintf(
"crashpad.test.%lu.%s", GetCurrentProcessId(), RandomString().c_str())); "crashpad.test.%lu.%s", GetCurrentProcessId(), RandomString().c_str()));
return system_temp_dir.Append(new_dir_name); return system_temp_dir.Append(new_dir_name);
} }

View File

@ -50,7 +50,7 @@ bool GetSwitch(const char* switch_name, std::string* value) {
switch_name_with_equals += "="; switch_name_with_equals += "=";
for (int i = 1; i < num_args; ++i) { for (int i = 1; i < num_args; ++i) {
const wchar_t* arg = args[i]; const wchar_t* arg = args[i];
std::string arg_as_utf8 = base::UTF16ToUTF8(arg); std::string arg_as_utf8 = base::WideToUTF8(arg);
if (arg_as_utf8.compare( if (arg_as_utf8.compare(
0, switch_name_with_equals.size(), switch_name_with_equals) == 0) { 0, switch_name_with_equals.size(), switch_name_with_equals) == 0) {
if (value) if (value)
@ -189,7 +189,7 @@ std::unique_ptr<WinChildProcess::Handles> WinChildProcess::Launch() {
::testing::UnitTest::GetInstance()->current_test_info(); ::testing::UnitTest::GetInstance()->current_test_info();
std::wstring command_line = std::wstring command_line =
TestPaths::Executable().value() + TestPaths::Executable().value() +
base::UTF8ToUTF16(base::StringPrintf( base::UTF8ToWide(base::StringPrintf(
" --gtest_filter=%s.%s %s=0x%x|0x%x --gtest_also_run_disabled_tests", " --gtest_filter=%s.%s %s=0x%x|0x%x --gtest_also_run_disabled_tests",
test_info->test_case_name(), test_info->test_case_name(),
test_info->name(), test_info->name(),

View File

@ -79,7 +79,7 @@ int ToolSupport::Wmain(int argc, wchar_t* argv[], int (*entry)(int, char* [])) {
std::vector<std::string> storage; std::vector<std::string> storage;
storage.reserve(argc); storage.reserve(argc);
for (int i = 0; i < argc; ++i) { for (int i = 0; i < argc; ++i) {
storage.push_back(base::UTF16ToUTF8(argv[i])); storage.push_back(base::WideToUTF8(argv[i]));
argv_as_utf8[i] = &storage[i][0]; argv_as_utf8[i] = &storage[i][0];
} }
argv_as_utf8[argc] = nullptr; argv_as_utf8[argc] = nullptr;
@ -94,7 +94,7 @@ base::FilePath::StringType ToolSupport::CommandLineArgumentToFilePathStringType(
#if defined(OS_POSIX) #if defined(OS_POSIX)
return path.as_string(); return path.as_string();
#elif defined(OS_WIN) #elif defined(OS_WIN)
return base::UTF8ToUTF16(path); return base::UTF8ToWide(path);
#endif // OS_POSIX #endif // OS_POSIX
} }
@ -104,7 +104,7 @@ std::string ToolSupport::FilePathToCommandLineArgument(
#if defined(OS_POSIX) #if defined(OS_POSIX)
return file_path.value(); return file_path.value();
#elif defined(OS_WIN) #elif defined(OS_WIN)
return base::UTF16ToUTF8(file_path.value()); return base::WideToUTF8(file_path.value());
#endif // OS_POSIX #endif // OS_POSIX
} }

View File

@ -160,7 +160,7 @@ FileHandle OpenFileForReadAndWrite(const base::FilePath& path,
FileHandle LoggingOpenFileForRead(const base::FilePath& path) { FileHandle LoggingOpenFileForRead(const base::FilePath& path) {
FileHandle file = OpenFileForRead(path); FileHandle file = OpenFileForRead(path);
PLOG_IF(ERROR, file == INVALID_HANDLE_VALUE) PLOG_IF(ERROR, file == INVALID_HANDLE_VALUE)
<< "CreateFile " << base::UTF16ToUTF8(path.value()); << "CreateFile " << base::WideToUTF8(path.value());
return file; return file;
} }
@ -169,7 +169,7 @@ FileHandle LoggingOpenFileForWrite(const base::FilePath& path,
FilePermissions permissions) { FilePermissions permissions) {
FileHandle file = OpenFileForWrite(path, mode, permissions); FileHandle file = OpenFileForWrite(path, mode, permissions);
PLOG_IF(ERROR, file == INVALID_HANDLE_VALUE) PLOG_IF(ERROR, file == INVALID_HANDLE_VALUE)
<< "CreateFile " << base::UTF16ToUTF8(path.value()); << "CreateFile " << base::WideToUTF8(path.value());
return file; return file;
} }
@ -178,7 +178,7 @@ FileHandle LoggingOpenFileForReadAndWrite(const base::FilePath& path,
FilePermissions permissions) { FilePermissions permissions) {
FileHandle file = OpenFileForReadAndWrite(path, mode, permissions); FileHandle file = OpenFileForReadAndWrite(path, mode, permissions);
PLOG_IF(ERROR, file == INVALID_HANDLE_VALUE) PLOG_IF(ERROR, file == INVALID_HANDLE_VALUE)
<< "CreateFile " << base::UTF16ToUTF8(path.value()); << "CreateFile " << base::WideToUTF8(path.value());
return file; return file;
} }

View File

@ -34,7 +34,7 @@ bool IsSymbolicLink(const base::FilePath& path) {
nullptr, nullptr,
0)); 0));
if (!handle.is_valid()) { if (!handle.is_valid()) {
PLOG(ERROR) << "FindFirstFileEx " << base::UTF16ToUTF8(path.value()); PLOG(ERROR) << "FindFirstFileEx " << base::WideToUTF8(path.value());
return false; return false;
} }
@ -44,7 +44,7 @@ bool IsSymbolicLink(const base::FilePath& path) {
bool LoggingRemoveDirectoryImpl(const base::FilePath& path) { bool LoggingRemoveDirectoryImpl(const base::FilePath& path) {
if (!RemoveDirectory(path.value().c_str())) { if (!RemoveDirectory(path.value().c_str())) {
PLOG(ERROR) << "RemoveDirectory " << base::UTF16ToUTF8(path.value()); PLOG(ERROR) << "RemoveDirectory " << base::WideToUTF8(path.value());
return false; return false;
} }
return true; return true;
@ -68,13 +68,13 @@ bool FileModificationTime(const base::FilePath& path, timespec* mtime) {
flags, flags,
nullptr)); nullptr));
if (!handle.is_valid()) { if (!handle.is_valid()) {
PLOG(ERROR) << "CreateFile " << base::UTF16ToUTF8(path.value()); PLOG(ERROR) << "CreateFile " << base::WideToUTF8(path.value());
return false; return false;
} }
FILETIME file_mtime; FILETIME file_mtime;
if (!GetFileTime(handle.get(), nullptr, nullptr, &file_mtime)) { if (!GetFileTime(handle.get(), nullptr, nullptr, &file_mtime)) {
PLOG(ERROR) << "GetFileTime " << base::UTF16ToUTF8(path.value()); PLOG(ERROR) << "GetFileTime " << base::WideToUTF8(path.value());
return false; return false;
} }
*mtime = FiletimeToTimespecEpoch(file_mtime); *mtime = FiletimeToTimespecEpoch(file_mtime);
@ -89,12 +89,12 @@ bool LoggingCreateDirectory(const base::FilePath& path,
} }
if (may_reuse && GetLastError() == ERROR_ALREADY_EXISTS) { if (may_reuse && GetLastError() == ERROR_ALREADY_EXISTS) {
if (!IsDirectory(path, true)) { if (!IsDirectory(path, true)) {
LOG(ERROR) << base::UTF16ToUTF8(path.value()) << " not a directory"; LOG(ERROR) << base::WideToUTF8(path.value()) << " not a directory";
return false; return false;
} }
return true; return true;
} }
PLOG(ERROR) << "CreateDirectory " << base::UTF16ToUTF8(path.value()); PLOG(ERROR) << "CreateDirectory " << base::WideToUTF8(path.value());
return false; return false;
} }
@ -103,8 +103,8 @@ bool MoveFileOrDirectory(const base::FilePath& source,
if (!MoveFileEx(source.value().c_str(), if (!MoveFileEx(source.value().c_str(),
dest.value().c_str(), dest.value().c_str(),
IsDirectory(source, false) ? 0 : MOVEFILE_REPLACE_EXISTING)) { IsDirectory(source, false) ? 0 : MOVEFILE_REPLACE_EXISTING)) {
PLOG(ERROR) << "MoveFileEx" << base::UTF16ToUTF8(source.value()) << ", " PLOG(ERROR) << "MoveFileEx" << base::WideToUTF8(source.value()) << ", "
<< base::UTF16ToUTF8(dest.value()); << base::WideToUTF8(dest.value());
return false; return false;
} }
return true; return true;
@ -113,7 +113,7 @@ bool MoveFileOrDirectory(const base::FilePath& source,
bool IsRegularFile(const base::FilePath& path) { bool IsRegularFile(const base::FilePath& path) {
DWORD fileattr = GetFileAttributes(path.value().c_str()); DWORD fileattr = GetFileAttributes(path.value().c_str());
if (fileattr == INVALID_FILE_ATTRIBUTES) { if (fileattr == INVALID_FILE_ATTRIBUTES) {
PLOG(ERROR) << "GetFileAttributes " << base::UTF16ToUTF8(path.value()); PLOG(ERROR) << "GetFileAttributes " << base::WideToUTF8(path.value());
return false; return false;
} }
if ((fileattr & FILE_ATTRIBUTE_DIRECTORY) != 0 || if ((fileattr & FILE_ATTRIBUTE_DIRECTORY) != 0 ||
@ -126,7 +126,7 @@ bool IsRegularFile(const base::FilePath& path) {
bool IsDirectory(const base::FilePath& path, bool allow_symlinks) { bool IsDirectory(const base::FilePath& path, bool allow_symlinks) {
DWORD fileattr = GetFileAttributes(path.value().c_str()); DWORD fileattr = GetFileAttributes(path.value().c_str());
if (fileattr == INVALID_FILE_ATTRIBUTES) { if (fileattr == INVALID_FILE_ATTRIBUTES) {
PLOG(ERROR) << "GetFileAttributes " << base::UTF16ToUTF8(path.value()); PLOG(ERROR) << "GetFileAttributes " << base::WideToUTF8(path.value());
return false; return false;
} }
if (!allow_symlinks && (fileattr & FILE_ATTRIBUTE_REPARSE_POINT) != 0) { if (!allow_symlinks && (fileattr & FILE_ATTRIBUTE_REPARSE_POINT) != 0) {
@ -145,7 +145,7 @@ bool LoggingRemoveFile(const base::FilePath& path) {
} }
if (!DeleteFile(path.value().c_str())) { if (!DeleteFile(path.value().c_str())) {
PLOG(ERROR) << "DeleteFile " << base::UTF16ToUTF8(path.value()); PLOG(ERROR) << "DeleteFile " << base::WideToUTF8(path.value());
return false; return false;
} }
return true; return true;
@ -153,7 +153,7 @@ bool LoggingRemoveFile(const base::FilePath& path) {
bool LoggingRemoveDirectory(const base::FilePath& path) { bool LoggingRemoveDirectory(const base::FilePath& path) {
if (IsSymbolicLink(path)) { if (IsSymbolicLink(path)) {
LOG(ERROR) << "Not a directory " << base::UTF16ToUTF8(path.value()); LOG(ERROR) << "Not a directory " << base::WideToUTF8(path.value());
return false; return false;
} }
return LoggingRemoveDirectoryImpl(path); return LoggingRemoveDirectoryImpl(path);

View File

@ -83,9 +83,11 @@ bool UUID::InitializeFromString(const base::StringPiece& string) {
return true; return true;
} }
bool UUID::InitializeFromString(const base::StringPiece16& string) { #if defined(OS_WIN)
return InitializeFromString(UTF16ToUTF8(string)); bool UUID::InitializeFromString(const base::WStringPiece& string) {
return InitializeFromString(WideToUTF8(string));
} }
#endif
bool UUID::InitializeWithNew() { bool UUID::InitializeWithNew() {
#if defined(OS_APPLE) #if defined(OS_APPLE)
@ -138,8 +140,8 @@ std::string UUID::ToString() const {
} }
#if defined(OS_WIN) #if defined(OS_WIN)
base::string16 UUID::ToString16() const { std::wstring UUID::ToWString() const {
return base::UTF8ToUTF16(ToString()); return base::UTF8ToWide(ToString());
} }
#endif // OS_WIN #endif // OS_WIN

View File

@ -19,7 +19,6 @@
#include <string> #include <string>
#include "base/strings/string16.h"
#include "base/strings/string_piece.h" #include "base/strings/string_piece.h"
#include "build/build_config.h" #include "build/build_config.h"
@ -63,7 +62,9 @@ struct UUID {
//! been initialized with the data. `false` if the string could not be //! been initialized with the data. `false` if the string could not be
//! parsed, with the object state untouched. //! parsed, with the object state untouched.
bool InitializeFromString(const base::StringPiece& string); bool InitializeFromString(const base::StringPiece& string);
bool InitializeFromString(const base::StringPiece16& string); #if defined(OS_WIN) || DOXYGEN
bool InitializeFromString(const base::WStringPiece& string);
#endif // OS_WIN
//! \brief Initializes the %UUID using a standard system facility to generate //! \brief Initializes the %UUID using a standard system facility to generate
//! the value. //! the value.
@ -85,8 +86,8 @@ struct UUID {
std::string ToString() const; std::string ToString() const;
#if defined(OS_WIN) || DOXYGEN #if defined(OS_WIN) || DOXYGEN
//! \brief The same as ToString, but returned as a string16. //! \brief The same as ToString, but returned as a wstring.
base::string16 ToString16() const; std::wstring ToWString() const;
#endif // OS_WIN #endif // OS_WIN
// These fields are laid out according to RFC 4122 §4.1.2. // These fields are laid out according to RFC 4122 §4.1.2.

View File

@ -215,20 +215,6 @@ TEST(UUID, FromString) {
uuid.InitializeFromString("5762C15D-50b5-4171-a2e9-7429C9EC6CAB"); uuid.InitializeFromString("5762C15D-50b5-4171-a2e9-7429C9EC6CAB");
EXPECT_EQ(uuid.ToString(), "5762c15d-50b5-4171-a2e9-7429c9ec6cab"); EXPECT_EQ(uuid.ToString(), "5762c15d-50b5-4171-a2e9-7429c9ec6cab");
// Test accepting a StringPiece16.
// clang-format off
static constexpr base::char16 kChar16UUID[] = {
'f', '3', '2', 'e', '5', 'b', 'd', 'c', '-',
'2', '6', '8', '1', '-',
'4', 'c', '7', '3', '-',
'a', '4', 'e', '6', '-',
'3', '3', '3', 'f', 'f', 'd', '3', '3', 'b', '3', '3', '3',
};
// clang-format on
EXPECT_TRUE(uuid.InitializeFromString(
base::StringPiece16(kChar16UUID, base::size(kChar16UUID))));
EXPECT_EQ(uuid.ToString(), "f32e5bdc-2681-4c73-a4e6-333ffd33b333");
#if defined(OS_WIN) #if defined(OS_WIN)
// Test accepting a StringPiece16 via L"" literals on Windows. // Test accepting a StringPiece16 via L"" literals on Windows.
EXPECT_TRUE( EXPECT_TRUE(
@ -263,7 +249,7 @@ TEST(UUID, FromSystem) {
base::ScopedGeneric<RPC_WSTR*, ScopedRpcStringFreeTraits>; base::ScopedGeneric<RPC_WSTR*, ScopedRpcStringFreeTraits>;
ScopedRpcString scoped_system_string(&system_string); ScopedRpcString scoped_system_string(&system_string);
EXPECT_EQ(uuid.ToString16(), reinterpret_cast<wchar_t*>(system_string)); EXPECT_EQ(uuid.ToWString(), reinterpret_cast<wchar_t*>(system_string));
} }
#endif // OS_WIN #endif // OS_WIN

View File

@ -42,8 +42,8 @@ namespace test {
namespace { namespace {
#if defined(OS_WIN) #if defined(OS_WIN)
std::string ToUTF8IfWin(const base::string16& x) { std::string ToUTF8IfWin(const std::wstring& x) {
return base::UTF16ToUTF8(x); return base::WideToUTF8(x);
} }
#else #else
std::string ToUTF8IfWin(const std::string& x) { std::string ToUTF8IfWin(const std::string& x) {

View File

@ -146,7 +146,7 @@ HTTPTransportWin::~HTTPTransportWin() {
} }
bool HTTPTransportWin::ExecuteSynchronously(std::string* response_body) { bool HTTPTransportWin::ExecuteSynchronously(std::string* response_body) {
ScopedHINTERNET session(WinHttpOpen(base::UTF8ToUTF16(UserAgent()).c_str(), ScopedHINTERNET session(WinHttpOpen(base::UTF8ToWide(UserAgent()).c_str(),
WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_NAME,
WINHTTP_NO_PROXY_BYPASS, WINHTTP_NO_PROXY_BYPASS,
@ -171,7 +171,7 @@ bool HTTPTransportWin::ExecuteSynchronously(std::string* response_body) {
url_components.dwHostNameLength = 1; url_components.dwHostNameLength = 1;
url_components.dwUrlPathLength = 1; url_components.dwUrlPathLength = 1;
url_components.dwExtraInfoLength = 1; url_components.dwExtraInfoLength = 1;
std::wstring url_wide(base::UTF8ToUTF16(url())); std::wstring url_wide(base::UTF8ToWide(url()));
// dwFlags = ICU_REJECT_USERPWD fails on XP. // dwFlags = ICU_REJECT_USERPWD fails on XP.
if (!WinHttpCrackUrl( if (!WinHttpCrackUrl(
url_wide.c_str(), 0, 0, &url_components)) { url_wide.c_str(), 0, 0, &url_components)) {
@ -206,7 +206,7 @@ bool HTTPTransportWin::ExecuteSynchronously(std::string* response_body) {
ScopedHINTERNET request(WinHttpOpenRequest( ScopedHINTERNET request(WinHttpOpenRequest(
connect.get(), connect.get(),
base::UTF8ToUTF16(method()).c_str(), base::UTF8ToWide(method()).c_str(),
request_target.c_str(), request_target.c_str(),
nullptr, nullptr,
WINHTTP_NO_REFERER, WINHTTP_NO_REFERER,
@ -235,8 +235,8 @@ bool HTTPTransportWin::ExecuteSynchronously(std::string* response_body) {
chunked = !base::StringToSizeT(pair.second, &content_length); chunked = !base::StringToSizeT(pair.second, &content_length);
DCHECK(!chunked); DCHECK(!chunked);
} else { } else {
std::wstring header_string = base::UTF8ToUTF16(pair.first) + L": " + std::wstring header_string = base::UTF8ToWide(pair.first) + L": " +
base::UTF8ToUTF16(pair.second) + L"\r\n"; base::UTF8ToWide(pair.second) + L"\r\n";
if (!WinHttpAddRequestHeaders( if (!WinHttpAddRequestHeaders(
request.get(), request.get(),
header_string.c_str(), header_string.c_str(),

View File

@ -28,9 +28,11 @@ namespace crashpad {
size_t c16lcpy(base::char16* destination, size_t c16lcpy(base::char16* destination,
const base::char16* source, const base::char16* source,
size_t length) { size_t length) {
HRESULT result = StringCchCopyW(destination, length, source); const wchar_t* wsource = reinterpret_cast<const wchar_t*>(source);
HRESULT result =
StringCchCopyW(reinterpret_cast<wchar_t*>(destination), length, wsource);
CHECK(result == S_OK || result == STRSAFE_E_INSUFFICIENT_BUFFER); CHECK(result == S_OK || result == STRSAFE_E_INSUFFICIENT_BUFFER);
return wcslen(source); return wcslen(wsource);
} }
#elif defined(WCHAR_T_IS_UTF32) #elif defined(WCHAR_T_IS_UTF32)

View File

@ -39,12 +39,15 @@ int C16Memcmp(const base::char16* s1, const base::char16* s2, size_t n) {
return base::c16memcmp(s1, s2, n); return base::c16memcmp(s1, s2, n);
} }
#elif defined(WCHAR_T_IS_UTF16) #elif defined(WCHAR_T_IS_UTF16)
size_t C16Len(const base::char16* s) { size_t C16Len(const base::char16* s) {
return wcslen(s); return wcslen(reinterpret_cast<const wchar_t*>(s));
} }
int C16Memcmp(const base::char16* s1, const base::char16* s2, size_t n) { int C16Memcmp(const base::char16* s1, const base::char16* s2, size_t n) {
return wmemcmp(s1, s2, n); return wmemcmp(reinterpret_cast<const wchar_t*>(s1),
reinterpret_cast<const wchar_t*>(s2),
n);
} }
#endif #endif

View File

@ -23,7 +23,7 @@ namespace internal {
FARPROC GetFunctionInternal( FARPROC GetFunctionInternal(
const wchar_t* library, const char* function, bool required) { const wchar_t* library, const char* function, bool required) {
HMODULE module = LoadLibrary(library); HMODULE module = LoadLibrary(library);
DPCHECK(!required || module) << "LoadLibrary " << base::UTF16ToUTF8(library); DPCHECK(!required || module) << "LoadLibrary " << base::WideToUTF8(library);
if (!module) { if (!module) {
return nullptr; return nullptr;
} }

View File

@ -29,14 +29,13 @@ bool GetModuleVersionAndType(const base::FilePath& path,
DWORD size = GetFileVersionInfoSize(path.value().c_str(), nullptr); DWORD size = GetFileVersionInfoSize(path.value().c_str(), nullptr);
if (!size) { if (!size) {
PLOG_IF(WARNING, GetLastError() != ERROR_RESOURCE_TYPE_NOT_FOUND) PLOG_IF(WARNING, GetLastError() != ERROR_RESOURCE_TYPE_NOT_FOUND)
<< "GetFileVersionInfoSize: " << base::UTF16ToUTF8(path.value()); << "GetFileVersionInfoSize: " << base::WideToUTF8(path.value());
return false; return false;
} }
std::unique_ptr<uint8_t[]> data(new uint8_t[size]); std::unique_ptr<uint8_t[]> data(new uint8_t[size]);
if (!GetFileVersionInfo(path.value().c_str(), 0, size, data.get())) { if (!GetFileVersionInfo(path.value().c_str(), 0, size, data.get())) {
PLOG(WARNING) << "GetFileVersionInfo: " PLOG(WARNING) << "GetFileVersionInfo: " << base::WideToUTF8(path.value());
<< base::UTF16ToUTF8(path.value());
return false; return false;
} }

View File

@ -142,7 +142,7 @@ void TestOtherProcess(TestPaths::Architecture architecture) {
done_uuid.InitializeWithNew(); done_uuid.InitializeWithNew();
ScopedKernelHANDLE done( ScopedKernelHANDLE done(
CreateEvent(nullptr, true, false, done_uuid.ToString16().c_str())); CreateEvent(nullptr, true, false, done_uuid.ToWString().c_str()));
ASSERT_TRUE(done.get()) << ErrorMessage("CreateEvent"); ASSERT_TRUE(done.get()) << ErrorMessage("CreateEvent");
base::FilePath child_test_executable = base::FilePath child_test_executable =
@ -151,7 +151,7 @@ void TestOtherProcess(TestPaths::Architecture architecture) {
TestPaths::FileType::kExecutable, TestPaths::FileType::kExecutable,
architecture); architecture);
std::wstring args; std::wstring args;
AppendCommandLineArgument(done_uuid.ToString16(), &args); AppendCommandLineArgument(done_uuid.ToWString(), &args);
ChildLauncher child(child_test_executable, args); ChildLauncher child(child_test_executable, args);
ASSERT_NO_FATAL_FAILURE(child.Start()); ASSERT_NO_FATAL_FAILURE(child.Start());
@ -559,9 +559,9 @@ TEST(ProcessInfo, Handles) {
ASSERT_TRUE(scoped_key.is_valid()); ASSERT_TRUE(scoped_key.is_valid());
std::wstring mapping_name = std::wstring mapping_name =
base::UTF8ToUTF16(base::StringPrintf("Local\\test_mapping_%lu_%s", base::UTF8ToWide(base::StringPrintf("Local\\test_mapping_%lu_%s",
GetCurrentProcessId(), GetCurrentProcessId(),
RandomString().c_str())); RandomString().c_str()));
ScopedKernelHANDLE mapping(CreateFileMapping(INVALID_HANDLE_VALUE, ScopedKernelHANDLE mapping(CreateFileMapping(INVALID_HANDLE_VALUE,
nullptr, nullptr,
PAGE_READWRITE, PAGE_READWRITE,

View File

@ -30,8 +30,7 @@ namespace crashpad {
namespace { namespace {
void* GetSecurityDescriptorWithUser(const base::char16* sddl_string, void* GetSecurityDescriptorWithUser(const wchar_t* sddl_string, size_t* size) {
size_t* size) {
if (size) if (size)
*size = 0; *size = 0;
@ -71,7 +70,7 @@ void* GetSecurityDescriptorWithUser(const base::char16* sddl_string,
} // namespace } // namespace
bool SendToCrashHandlerServer(const base::string16& pipe_name, bool SendToCrashHandlerServer(const std::wstring& pipe_name,
const ClientToServerMessage& message, const ClientToServerMessage& message,
ServerToClientMessage* response) { ServerToClientMessage* response) {
// Retry CreateFile() in a loop. If the handler isnt actively waiting in // Retry CreateFile() in a loop. If the handler isnt actively waiting in

View File

@ -18,7 +18,8 @@
#include <windows.h> #include <windows.h>
#include <stdint.h> #include <stdint.h>
#include "base/strings/string16.h" #include <string>
#include "util/win/address_types.h" #include "util/win/address_types.h"
namespace crashpad { namespace crashpad {
@ -130,7 +131,7 @@ union ServerToClientMessage {
//! CrashpadClient::SetHandler(). //! CrashpadClient::SetHandler().
//! //!
//! \sa CrashpadClient::SetHandler() //! \sa CrashpadClient::SetHandler()
bool SendToCrashHandlerServer(const base::string16& pipe_name, bool SendToCrashHandlerServer(const std::wstring& pipe_name,
const ClientToServerMessage& message, const ClientToServerMessage& message,
ServerToClientMessage* response); ServerToClientMessage* response);

View File

@ -17,13 +17,13 @@
#include <aclapi.h> #include <aclapi.h>
#include <sddl.h> #include <sddl.h>
#include <string.h> #include <string.h>
#include <wchar.h>
#include <windows.h> #include <windows.h>
#include <vector> #include <vector>
#include "base/logging.h" #include "base/logging.h"
#include "base/notreached.h" #include "base/notreached.h"
#include "base/strings/string16.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "test/errors.h" #include "test/errors.h"
#include "util/win/scoped_handle.h" #include "util/win/scoped_handle.h"
@ -33,21 +33,21 @@ namespace crashpad {
namespace test { namespace test {
namespace { namespace {
base::string16 GetStringFromSid(PSID sid) { std::wstring GetStringFromSid(PSID sid) {
LPWSTR sid_str; LPWSTR sid_str;
if (!ConvertSidToStringSid(sid, &sid_str)) { if (!ConvertSidToStringSid(sid, &sid_str)) {
PLOG(ERROR) << "ConvertSidToStringSid"; PLOG(ERROR) << "ConvertSidToStringSid";
return base::string16(); return std::wstring();
} }
ScopedLocalAlloc sid_str_ptr(sid_str); ScopedLocalAlloc sid_str_ptr(sid_str);
return sid_str; return sid_str;
} }
base::string16 GetUserSidString() { std::wstring GetUserSidString() {
HANDLE token_handle; HANDLE token_handle;
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token_handle)) { if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token_handle)) {
PLOG(ERROR) << "OpenProcessToken"; PLOG(ERROR) << "OpenProcessToken";
return base::string16(); return std::wstring();
} }
ScopedKernelHANDLE token(token_handle); ScopedKernelHANDLE token(token_handle);
@ -55,14 +55,14 @@ base::string16 GetUserSidString() {
GetTokenInformation(token.get(), TokenUser, nullptr, 0, &user_size); GetTokenInformation(token.get(), TokenUser, nullptr, 0, &user_size);
if (user_size == 0) { if (user_size == 0) {
PLOG(ERROR) << "GetTokenInformation Size"; PLOG(ERROR) << "GetTokenInformation Size";
return base::string16(); return std::wstring();
} }
std::vector<char> user(user_size); std::vector<char> user(user_size);
if (!GetTokenInformation( if (!GetTokenInformation(
token.get(), TokenUser, user.data(), user_size, &user_size)) { token.get(), TokenUser, user.data(), user_size, &user_size)) {
PLOG(ERROR) << "GetTokenInformation"; PLOG(ERROR) << "GetTokenInformation";
return base::string16(); return std::wstring();
} }
TOKEN_USER* user_ptr = reinterpret_cast<TOKEN_USER*>(user.data()); TOKEN_USER* user_ptr = reinterpret_cast<TOKEN_USER*>(user.data());
@ -73,7 +73,7 @@ void CheckAce(PACL acl,
DWORD index, DWORD index,
BYTE check_ace_type, BYTE check_ace_type,
ACCESS_MASK check_mask, ACCESS_MASK check_mask,
const base::string16& check_sid) { const std::wstring& check_sid) {
ASSERT_FALSE(check_sid.empty()); ASSERT_FALSE(check_sid.empty());
void* ace_ptr; void* ace_ptr;
ASSERT_TRUE(GetAce(acl, index, &ace_ptr)); ASSERT_TRUE(GetAce(acl, index, &ace_ptr));