diff options
author | alexeypa@chromium.org <alexeypa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-07 01:32:58 +0000 |
---|---|---|
committer | alexeypa@chromium.org <alexeypa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-07 01:32:58 +0000 |
commit | a11dbe9b75e6ec3e4fd8d9878526fa27426d59ad (patch) | |
tree | abe85be335ec148e1d232be881033776c2c20f48 | |
parent | cdd4234611a47a064a8b15c2f3a7f47676286cef (diff) | |
download | chromium_src-a11dbe9b75e6ec3e4fd8d9878526fa27426d59ad.zip chromium_src-a11dbe9b75e6ec3e4fd8d9878526fa27426d59ad.tar.gz chromium_src-a11dbe9b75e6ec3e4fd8d9878526fa27426d59ad.tar.bz2 |
Cleaned up usage of std::wstring in src/remoting. Added presubmit warning supressions for the remaning instances because they depend on hard-to-change public APIs.
BUG=133003
Review URL: https://chromiumcodereview.appspot.com/10824166
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@150224 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | PRESUBMIT.py | 11 | ||||
-rw-r--r-- | remoting/base/breakpad_win.cc | 13 | ||||
-rw-r--r-- | remoting/host/host_event_logger_win.cc | 30 | ||||
-rw-r--r-- | remoting/host/plugin/daemon_installer_win.cc | 11 | ||||
-rw-r--r-- | remoting/host/policy_hack/policy_watcher_win.cc | 3 | ||||
-rw-r--r-- | remoting/host/usage_stats_consent_win.cc | 2 | ||||
-rw-r--r-- | remoting/host/win/host_service.cc | 5 | ||||
-rw-r--r-- | remoting/host/win/host_service.h | 3 | ||||
-rw-r--r-- | remoting/host/win/launch_process_with_token.cc | 25 | ||||
-rw-r--r-- | remoting/host/win/launch_process_with_token.h | 3 | ||||
-rw-r--r-- | remoting/host/win/wts_session_process_launcher.cc | 19 |
11 files changed, 69 insertions, 56 deletions
diff --git a/PRESUBMIT.py b/PRESUBMIT.py index 4195f5a..3352574 100644 --- a/PRESUBMIT.py +++ b/PRESUBMIT.py @@ -292,14 +292,21 @@ def _CheckNoNewWStrings(input_api, output_api): f.LocalPath().endswith('test.cc')): continue + allowWString = False for line_num, line in f.ChangedContents(): - if 'wstring' in line: + if 'presubmit: allow wstring' in line: + allowWString = True + elif not allowWString and 'wstring' in line: problems.append(' %s:%d' % (f.LocalPath(), line_num)) + allowWString = False + else: + allowWString = False if not problems: return [] return [output_api.PresubmitPromptWarning('New code should not use wstrings.' - ' If you are calling an API that accepts a wstring, fix the API.\n' + + ' If you are calling a cross-platform API that accepts a wstring, ' + 'fix the API.\n' + '\n'.join(problems))] diff --git a/remoting/base/breakpad_win.cc b/remoting/base/breakpad_win.cc index 05f1866..ef16a24 100644 --- a/remoting/base/breakpad_win.cc +++ b/remoting/base/breakpad_win.cc @@ -153,14 +153,15 @@ google_breakpad::CustomClientInfo* BreakpadWin::GetCustomInfo() { scoped_ptr<FileVersionInfo> version_info( FileVersionInfo::CreateFileVersionInfoForModule(binary)); - std::wstring version; - if (version_info.get()) - version = UTF16ToWide(version_info->product_version()); - if (version.empty()) - version = kBreakpadVersionDefault; + static wchar_t version[64]; + if (version_info.get()) { + wcscpy_s(version, UTF16ToWide(version_info->product_version()).c_str()); + } else { + wcscpy_s(version, kBreakpadVersionDefault); + } static google_breakpad::CustomInfoEntry ver_entry( - kBreakpadVersionEntry, version.c_str()); + kBreakpadVersionEntry, version); static google_breakpad::CustomInfoEntry prod_entry( kBreakpadProdEntry, kBreakpadProductName); static google_breakpad::CustomInfoEntry plat_entry( diff --git a/remoting/host/host_event_logger_win.cc b/remoting/host/host_event_logger_win.cc index afad08c..85f31d2 100644 --- a/remoting/host/host_event_logger_win.cc +++ b/remoting/host/host_event_logger_win.cc @@ -25,8 +25,7 @@ namespace { class HostEventLoggerWin : public HostEventLogger, public HostStatusObserver { public: - HostEventLoggerWin(ChromotingHost* host, - const std::string& application_name); + HostEventLoggerWin(ChromotingHost* host, const std::string& application_name); virtual ~HostEventLoggerWin(); @@ -43,7 +42,7 @@ class HostEventLoggerWin : public HostEventLogger, public HostStatusObserver { private: void LogString(WORD type, DWORD event_id, const std::string& string); - void Log(WORD type, DWORD event_id, const std::vector<string16>& strings); + void Log(WORD type, DWORD event_id, const std::vector<std::string>& strings); scoped_refptr<ChromotingHost> host_; @@ -60,7 +59,7 @@ HostEventLoggerWin::HostEventLoggerWin(ChromotingHost* host, : host_(host), event_log_(NULL) { event_log_ = RegisterEventSourceW(NULL, - ASCIIToUTF16(application_name).c_str()); + UTF8ToUTF16(application_name).c_str()); if (event_log_ != NULL) { host_->AddStatusObserver(this); } else { @@ -92,13 +91,12 @@ void HostEventLoggerWin::OnClientRouteChange( const std::string& jid, const std::string& channel_name, const protocol::TransportRoute& route) { - std::vector<string16> strings(5); - strings[0] = ASCIIToUTF16(jid); - strings[1] = ASCIIToUTF16(route.remote_address.ToString()); - strings[2] = ASCIIToUTF16(route.local_address.ToString()); - strings[3] = ASCIIToUTF16(channel_name); - strings[4] = ASCIIToUTF16( - protocol::TransportRoute::GetTypeString(route.type)); + std::vector<std::string> strings(5); + strings[0] = jid; + strings[1] = route.remote_address.ToString(); + strings[2] = route.local_address.ToString(); + strings[3] = channel_name; + strings[4] = protocol::TransportRoute::GetTypeString(route.type); Log(EVENTLOG_INFORMATION_TYPE, MSG_HOST_CLIENT_ROUTING_CHANGED, strings); } @@ -107,15 +105,17 @@ void HostEventLoggerWin::OnShutdown() { void HostEventLoggerWin::Log(WORD type, DWORD event_id, - const std::vector<string16>& strings) { + const std::vector<std::string>& strings) { if (event_log_ == NULL) return; // ReportEventW() takes an array of raw string pointers. They should stay // valid for the duration of the call. std::vector<const WCHAR*> raw_strings(strings.size()); + std::vector<string16> utf16_strings(strings.size()); for (size_t i = 0; i < strings.size(); ++i) { - raw_strings[i] = strings[i].c_str(); + utf16_strings[i] = UTF8ToUTF16(strings[i]); + raw_strings[i] = utf16_strings[i].c_str(); } if (!ReportEventW(event_log_, @@ -134,8 +134,8 @@ void HostEventLoggerWin::Log(WORD type, void HostEventLoggerWin::LogString(WORD type, DWORD event_id, const std::string& string) { - std::vector<string16> strings; - strings.push_back(ASCIIToUTF16(string)); + std::vector<std::string> strings; + strings.push_back(string); Log(type, event_id, strings); } diff --git a/remoting/host/plugin/daemon_installer_win.cc b/remoting/host/plugin/daemon_installer_win.cc index a545432..606c1c8 100644 --- a/remoting/host/plugin/daemon_installer_win.cc +++ b/remoting/host/plugin/daemon_installer_win.cc @@ -285,24 +285,23 @@ void DaemonCommandLineInstallerWin::Install() { return; } + // presubmit: allow wstring std::wstring google_update; - result = update_key.ReadValue(kOmahaPathValueName, - &google_update); + result = update_key.ReadValue(kOmahaPathValueName, &google_update); if (result != ERROR_SUCCESS) { Done(HRESULT_FROM_WIN32(result)); return; } // Launch the updater process and wait for its termination. - std::wstring command_line = + string16 command_line = WideToUTF16( StringPrintf(kGoogleUpdateCommandLineFormat, google_update.c_str(), kHostOmahaAppid, - kOmahaLanguage); + kOmahaLanguage)); base::LaunchOptions options; - if (!base::LaunchProcess(WideToUTF16(command_line), options, - process_.Receive())) { + if (!base::LaunchProcess(command_line, options, process_.Receive())) { result = GetLastError(); Done(HRESULT_FROM_WIN32(result)); return; diff --git a/remoting/host/policy_hack/policy_watcher_win.cc b/remoting/host/policy_hack/policy_watcher_win.cc index fba75f0..a333911 100644 --- a/remoting/host/policy_hack/policy_watcher_win.cc +++ b/remoting/host/policy_hack/policy_watcher_win.cc @@ -114,7 +114,9 @@ class PolicyWatcherWin : bool GetRegistryPolicyString(const std::string& value_name, std::string* result) const { + // presubmit: allow wstring std::wstring value_name_wide = UTF8ToWide(value_name); + // presubmit: allow wstring std::wstring value; RegKey policy_key(HKEY_LOCAL_MACHINE, kRegistrySubKey, KEY_READ); if (policy_key.ReadValue(value_name_wide.c_str(), &value) == @@ -136,6 +138,7 @@ class PolicyWatcherWin : bool GetRegistryPolicyInteger(const std::string& value_name, uint32* result) const { + // presubmit: allow wstring std::wstring value_name_wide = UTF8ToWide(value_name); DWORD value = 0; RegKey policy_key(HKEY_LOCAL_MACHINE, kRegistrySubKey, KEY_READ); diff --git a/remoting/host/usage_stats_consent_win.cc b/remoting/host/usage_stats_consent_win.cc index cefb1cf..f0d0a1d 100644 --- a/remoting/host/usage_stats_consent_win.cc +++ b/remoting/host/usage_stats_consent_win.cc @@ -24,6 +24,7 @@ const wchar_t kOmahaClientStateMedium[] = L"ClientStateMedium"; const wchar_t kOmahaUsagestatsValue[] = L"usagestats"; LONG ReadUsageStatsValue(const wchar_t* state_key, DWORD* usagestats_out) { + // presubmit: allow wstring std::wstring client_state = StringPrintf(kOmahaClientStateKeyFormat, state_key, remoting::kHostOmahaAppid); @@ -71,6 +72,7 @@ bool IsUsageStatsAllowed() { bool SetUsageStatsConsent(bool allowed) { DWORD value = allowed; + // presubmit: allow wstring std::wstring client_state = StringPrintf(kOmahaClientStateKeyFormat, kOmahaClientStateMedium, kHostOmahaAppid); diff --git a/remoting/host/win/host_service.cc b/remoting/host/win/host_service.cc index 3523921..0c6ccb5 100644 --- a/remoting/host/win/host_service.cc +++ b/remoting/host/win/host_service.cc @@ -91,7 +91,6 @@ namespace remoting { HostService::HostService() : console_session_id_(kInvalidSessionId), run_routine_(&HostService::RunAsService), - service_name_(kWindowsServiceName), service_status_handle_(0), stopped_event_(true, false) { } @@ -228,7 +227,7 @@ void HostService::RunMessageLoop(MessageLoop* message_loop) { int HostService::RunAsService() { SERVICE_TABLE_ENTRYW dispatch_table[] = { - { const_cast<LPWSTR>(service_name_.c_str()), &HostService::ServiceMain }, + { const_cast<LPWSTR>(kWindowsServiceName), &HostService::ServiceMain }, { NULL, NULL } }; @@ -348,7 +347,7 @@ VOID WINAPI HostService::ServiceMain(DWORD argc, WCHAR* argv[]) { // Register the service control handler. self->service_status_handle_ = - RegisterServiceCtrlHandlerExW(self->service_name_.c_str(), + RegisterServiceCtrlHandlerExW(kWindowsServiceName, &HostService::ServiceControlHandler, self); if (self->service_status_handle_ == 0) { diff --git a/remoting/host/win/host_service.h b/remoting/host/win/host_service.h index ed49f5f..5ff5a79 100644 --- a/remoting/host/win/host_service.h +++ b/remoting/host/win/host_service.h @@ -100,9 +100,6 @@ class HostService : public WtsConsoleMonitor { // The action routine to be executed. int (HostService::*run_routine_)(); - // The service name. - std::wstring service_name_; - // The service status handle. SERVICE_STATUS_HANDLE service_status_handle_; diff --git a/remoting/host/win/launch_process_with_token.cc b/remoting/host/win/launch_process_with_token.cc index 0dfbb4d..800d936 100644 --- a/remoting/host/win/launch_process_with_token.cc +++ b/remoting/host/win/launch_process_with_token.cc @@ -20,8 +20,8 @@ using base::win::ScopedHandle; namespace { -const wchar_t kCreateProcessDefaultPipeNameFormat[] = - L"\\\\.\\Pipe\\TerminalServer\\SystemExecSrvr\\%d"; +const char kCreateProcessDefaultPipeNameFormat[] = + "\\\\.\\Pipe\\TerminalServer\\SystemExecSrvr\\%d"; // Undocumented WINSTATIONINFOCLASS value causing // winsta!WinStationQueryInformationW() to return the name of the pipe for @@ -38,20 +38,20 @@ const int kMaxLaunchDelaySeconds = 60; const int kMinLaunchDelaySeconds = 1; // Name of the default session desktop. -wchar_t kDefaultDesktopName[] = L"winsta0\\default"; +const char kDefaultDesktopName[] = "winsta0\\default"; // Requests the execution server to create a process in the specified session // using the default (i.e. Winlogon) token. This routine relies on undocumented // OS functionality and will likely not work on anything but XP or W2K3. bool CreateRemoteSessionProcess( uint32 session_id, - const std::wstring& application_name, - const std::wstring& command_line, + const FilePath::StringType& application_name, + const CommandLine::StringType& command_line, PROCESS_INFORMATION* process_information_out) { DCHECK(base::win::GetVersion() == base::win::VERSION_XP); - std::wstring pipe_name; + string16 pipe_name; // Use winsta!WinStationQueryInformationW() to determine the process creation // pipe name for the session. @@ -77,7 +77,8 @@ bool CreateRemoteSessionProcess( // Use the default pipe name if we couldn't query its name. if (pipe_name.empty()) { - pipe_name = StringPrintf(kCreateProcessDefaultPipeNameFormat, session_id); + pipe_name = UTF8ToUTF16( + StringPrintf(kCreateProcessDefaultPipeNameFormat, session_id)); } // Try to connect to the named pipe. @@ -111,7 +112,7 @@ bool CreateRemoteSessionProcess( return false; } - std::wstring desktop_name(kDefaultDesktopName); + string16 desktop_name(UTF8ToUTF16(kDefaultDesktopName)); // |CreateProcessRequest| structure passes the same parameters to // the execution server as CreateProcessAsUser() function does. Strings are @@ -244,17 +245,19 @@ bool CreateRemoteSessionProcess( namespace remoting { bool LaunchProcessWithToken(const FilePath& binary, - const std::wstring& command_line, + const CommandLine::StringType& command_line, HANDLE user_token, base::Process* process_out) { - std::wstring application_name = binary.value(); + FilePath::StringType application_name = binary.value(); base::win::ScopedProcessInformation process_info; STARTUPINFOW startup_info; + string16 desktop_name(UTF8ToUTF16(kDefaultDesktopName)); + memset(&startup_info, 0, sizeof(startup_info)); startup_info.cb = sizeof(startup_info); - startup_info.lpDesktop = kDefaultDesktopName; + startup_info.lpDesktop = const_cast<char16*>(desktop_name.c_str()); BOOL result = CreateProcessAsUser(user_token, application_name.c_str(), diff --git a/remoting/host/win/launch_process_with_token.h b/remoting/host/win/launch_process_with_token.h index 8234aae..d0f737b 100644 --- a/remoting/host/win/launch_process_with_token.h +++ b/remoting/host/win/launch_process_with_token.h @@ -8,6 +8,7 @@ #include <windows.h> #include <string> +#include "base/command_line.h" #include "base/file_path.h" #include "base/process_util.h" @@ -16,7 +17,7 @@ namespace remoting { // Launches |binary| in the security context of the user represented by // |user_token|. The session ID specified by the token is respected as well. bool LaunchProcessWithToken(const FilePath& binary, - const std::wstring& command_line, + const CommandLine::StringType& command_line, HANDLE user_token, base::Process* process_out); diff --git a/remoting/host/win/wts_session_process_launcher.cc b/remoting/host/win/wts_session_process_launcher.cc index 1a32789..4e79505 100644 --- a/remoting/host/win/wts_session_process_launcher.cc +++ b/remoting/host/win/wts_session_process_launcher.cc @@ -23,6 +23,7 @@ #include "base/process_util.h" #include "base/rand_util.h" #include "base/stringprintf.h" +#include "base/utf_string_conversions.h" #include "base/win/scoped_handle.h" #include "ipc/ipc_channel_proxy.h" #include "ipc/ipc_message.h" @@ -47,7 +48,7 @@ const FilePath::CharType kMe2meHostBinaryName[] = FILE_PATH_LITERAL("remoting_me2me_host.exe"); // Match the pipe name prefix used by Chrome IPC channels. -const wchar_t kChromePipeNamePrefix[] = L"\\\\.\\pipe\\chrome."; +const char kChromePipeNamePrefix[] = "\\\\.\\pipe\\chrome."; // The IPC channel name is passed to the host in the command line. const char kChromotingIpcSwitchName[] = "chromoting-ipc"; @@ -150,8 +151,8 @@ bool CreateSessionToken(uint32 session_id, // Generates random channel ID. // N.B. Stolen from src/content/common/child_process_host_impl.cc -std::wstring GenerateRandomChannelId(void* instance) { - return base::StringPrintf(L"%d.%p.%d", +std::string GenerateRandomChannelId(void* instance) { + return base::StringPrintf("%d.%p.%d", base::GetCurrentProcId(), instance, base::RandInt(0, std::numeric_limits<int>::max())); } @@ -159,7 +160,7 @@ std::wstring GenerateRandomChannelId(void* instance) { // Creates the server end of the Chromoting IPC channel. // N.B. This code is based on IPC::Channel's implementation. bool CreatePipeForIpcChannel(void* instance, - std::wstring* channel_name_out, + std::string* channel_name_out, ScopedHandle* pipe_out) { // Create security descriptor for the channel. SECURITY_ATTRIBUTES security_attributes; @@ -179,15 +180,15 @@ bool CreatePipeForIpcChannel(void* instance, } // Generate a random channel name. - std::wstring channel_name(GenerateRandomChannelId(instance)); + std::string channel_name(GenerateRandomChannelId(instance)); // Convert it to the pipe name. - std::wstring pipe_name(kChromePipeNamePrefix); + std::string pipe_name(kChromePipeNamePrefix); pipe_name.append(channel_name); // Create the server end of the pipe. This code should match the code in // IPC::Channel with exception of passing a non-default security descriptor. - HANDLE pipe = CreateNamedPipeW(pipe_name.c_str(), + HANDLE pipe = CreateNamedPipeW(UTF8ToUTF16(pipe_name).c_str(), PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED | FILE_FLAG_FIRST_PIPE_INSTANCE, PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, @@ -259,7 +260,7 @@ void WtsSessionProcessLauncher::LaunchProcess() { } FilePath host_binary = dir_path.Append(kMe2meHostBinaryName); - std::wstring channel_name; + std::string channel_name; ScopedHandle pipe; if (CreatePipeForIpcChannel(this, &channel_name, &pipe)) { // Wrap the pipe into an IPC channel. @@ -272,7 +273,7 @@ void WtsSessionProcessLauncher::LaunchProcess() { // Create the host process command line passing the name of the IPC channel // to use and copying known switches from the service's command line. CommandLine command_line(host_binary); - command_line.AppendSwitchNative(kChromotingIpcSwitchName, channel_name); + command_line.AppendSwitchASCII(kChromotingIpcSwitchName, channel_name); command_line.CopySwitchesFrom(*CommandLine::ForCurrentProcess(), kCopiedSwitchNames, _countof(kCopiedSwitchNames)); |