Chromium Code Reviews| Index: remoting/host/win/wts_session_process_delegate.cc |
| diff --git a/remoting/host/win/wts_session_process_delegate.cc b/remoting/host/win/wts_session_process_delegate.cc |
| index 54fc92c2b5faa88aa12264f714ee26395e4caed0..fb18287eedf05da89cae77c9c10b8f4202fa012b 100644 |
| --- a/remoting/host/win/wts_session_process_delegate.cc |
| +++ b/remoting/host/win/wts_session_process_delegate.cc |
| @@ -7,9 +7,6 @@ |
| #include "remoting/host/win/wts_session_process_delegate.h" |
| -#include <sddl.h> |
| -#include <limits> |
| - |
| #include "base/base_switches.h" |
| #include "base/bind.h" |
| #include "base/bind_helpers.h" |
| @@ -21,8 +18,6 @@ |
| #include "base/message_loop.h" |
| #include "base/path_service.h" |
| #include "base/single_thread_task_runner.h" |
| -#include "base/time.h" |
| -#include "base/timer.h" |
| #include "base/utf_string_conversions.h" |
| #include "base/win/scoped_handle.h" |
| #include "base/win/windows_version.h" |
| @@ -35,14 +30,13 @@ |
| #include "remoting/host/win/wts_console_monitor.h" |
| #include "remoting/host/worker_process_ipc_delegate.h" |
| -using base::TimeDelta; |
| using base::win::ScopedHandle; |
| const FilePath::CharType kDaemonBinaryName[] = |
| FILE_PATH_LITERAL("remoting_daemon.exe"); |
| // The command line switch specifying the name of the daemon IPC endpoint. |
| -const char kDaemonIpcSwitchName[] = "daemon-pipe"; |
| +const char kDaemonPipeSwitchName[] = "daemon-pipe"; |
| const char kElevateSwitchName[] = "elevate"; |
| @@ -66,18 +60,22 @@ class WtsSessionProcessDelegate::Core |
| Core(scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
| scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, |
| const FilePath& binary_path, |
| - bool launch_elevated); |
| + bool launch_elevated, |
| + const std::string& channel_security); |
| // base::MessagePumpForIO::IOHandler implementation. |
| virtual void OnIOCompleted(base::MessagePumpForIO::IOContext* context, |
| DWORD bytes_transferred, |
| DWORD error) OVERRIDE; |
| + // IPC::Sender implementation. |
| + virtual bool Send(IPC::Message* message) OVERRIDE; |
| + |
| // WorkerProcessLauncher::Delegate implementation. |
| virtual DWORD GetExitCode() OVERRIDE; |
| virtual void KillProcess(DWORD exit_code) OVERRIDE; |
| virtual bool LaunchProcess( |
| - const std::string& channel_name, |
| + IPC::Listener* delegate, |
| base::win::ScopedHandle* process_exit_event_out) OVERRIDE; |
| // Initializes the object returning true on success. |
| @@ -116,6 +114,13 @@ class WtsSessionProcessDelegate::Core |
| // Path to the worker process binary. |
| FilePath binary_path_; |
| + // The server end of the IPC channel used to commonicate to the worker |
|
simonmorris
2012/10/12 16:31:13
commonicate -> communicate
alexeypa (please no reviews)
2012/10/12 18:44:39
Done.
|
| + // process. |
| + scoped_ptr<IPC::ChannelProxy> channel_; |
| + |
| + // Security descriptor (as SDDL) to be applied to |channel_|. |
| + std::string channel_security_; |
| + |
| // The job object used to control the lifetime of child processes. |
| base::win::ScopedHandle job_; |
| @@ -142,10 +147,12 @@ WtsSessionProcessDelegate::Core::Core( |
| scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
| scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, |
| const FilePath& binary_path, |
| - bool launch_elevated) |
| + bool launch_elevated, |
| + const std::string& channel_security) |
| : main_task_runner_(main_task_runner), |
| io_task_runner_(io_task_runner), |
| binary_path_(binary_path), |
| + channel_security_(channel_security), |
| launch_elevated_(launch_elevated), |
| stopping_(false) { |
| DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| @@ -164,6 +171,17 @@ void WtsSessionProcessDelegate::Core::OnIOCompleted( |
| reinterpret_cast<DWORD>(context))); |
| } |
| +bool WtsSessionProcessDelegate::Core::Send(IPC::Message* message) { |
| + DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| + |
| + if (channel_.get()) { |
| + return channel_->Send(message); |
| + } else { |
| + delete message; |
| + return false; |
| + } |
| +} |
| + |
| DWORD WtsSessionProcessDelegate::Core::GetExitCode() { |
| DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| @@ -182,6 +200,8 @@ DWORD WtsSessionProcessDelegate::Core::GetExitCode() { |
| void WtsSessionProcessDelegate::Core::KillProcess(DWORD exit_code) { |
| DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| + channel_.reset(); |
| + |
| if (launch_elevated_) { |
| if (job_.IsValid()) { |
| TerminateJobObject(job_, exit_code); |
| @@ -194,7 +214,7 @@ void WtsSessionProcessDelegate::Core::KillProcess(DWORD exit_code) { |
| } |
| bool WtsSessionProcessDelegate::Core::LaunchProcess( |
| - const std::string& channel_name, |
| + IPC::Listener* delegate, |
| ScopedHandle* process_exit_event_out) { |
| DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| @@ -223,9 +243,16 @@ bool WtsSessionProcessDelegate::Core::LaunchProcess( |
| command_line.SetProgram(binary_path_); |
| } |
| + // Create the server end of the IPC channel. |
| + scoped_ptr<IPC::ChannelProxy> channel; |
| + std::string channel_name = GenerateIpcChannelName(this); |
| + if (!CreateIpcChannel(channel_name, channel_security_, io_task_runner_, |
| + delegate, &channel)) |
| + return false; |
| + |
| // Create the command line passing the name of the IPC channel to use and |
| // copying known switches from the caller's command line. |
| - command_line.AppendSwitchNative(kDaemonIpcSwitchName, |
| + command_line.AppendSwitchNative(kDaemonPipeSwitchName, |
| UTF8ToWide(channel_name)); |
| command_line.CopySwitchesFrom(*CommandLine::ForCurrentProcess(), |
| kCopiedSwitchNames, |
| @@ -237,6 +264,7 @@ bool WtsSessionProcessDelegate::Core::LaunchProcess( |
| if (!LaunchProcessWithToken(command_line.GetProgram(), |
| command_line.GetCommandLineString(), |
| session_token_, |
| + false, |
| CREATE_SUSPENDED | CREATE_BREAKAWAY_FROM_JOB, |
| &worker_process, |
| &worker_thread)) { |
| @@ -279,6 +307,7 @@ bool WtsSessionProcessDelegate::Core::LaunchProcess( |
| return false; |
| } |
| + channel_ = channel.Pass(); |
| *process_exit_event_out = process_exit_event.Pass(); |
| return true; |
| } |
| @@ -419,9 +448,10 @@ WtsSessionProcessDelegate::WtsSessionProcessDelegate( |
| scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, |
| const FilePath& binary_path, |
| uint32 session_id, |
| - bool launch_elevated) { |
| + bool launch_elevated, |
| + const std::string& channel_security) { |
| core_ = new Core(main_task_runner, io_task_runner, binary_path, |
| - launch_elevated); |
| + launch_elevated, channel_security); |
| if (!core_->Initialize(session_id)) { |
| core_->Stop(); |
| core_ = NULL; |
| @@ -432,6 +462,10 @@ WtsSessionProcessDelegate::~WtsSessionProcessDelegate() { |
| core_->Stop(); |
| } |
| +bool WtsSessionProcessDelegate::Send(IPC::Message* message) { |
| + return core_->Send(message); |
| +} |
| + |
| DWORD WtsSessionProcessDelegate::GetExitCode() { |
| if (!core_) |
| return CONTROL_C_EXIT; |
| @@ -446,12 +480,12 @@ void WtsSessionProcessDelegate::KillProcess(DWORD exit_code) { |
| } |
| bool WtsSessionProcessDelegate::LaunchProcess( |
| - const std::string& channel_name, |
| + IPC::Listener* delegate, |
| base::win::ScopedHandle* process_exit_event_out) { |
| if (!core_) |
| return false; |
| - return core_->LaunchProcess(channel_name, process_exit_event_out); |
| + return core_->LaunchProcess(delegate, process_exit_event_out); |
| } |
| } // namespace remoting |