OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // This file implements the Windows service controlling Me2Me host processes | 5 // This file implements the Windows service controlling Me2Me host processes |
6 // running within user sessions. | 6 // running within user sessions. |
7 | 7 |
8 #include "remoting/host/win/wts_session_process_delegate.h" | 8 #include "remoting/host/win/wts_session_process_delegate.h" |
9 | 9 |
10 #include <utility> | 10 #include <utility> |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 | 43 |
44 // A private class actually implementing the functionality provided by | 44 // A private class actually implementing the functionality provided by |
45 // |WtsSessionProcessDelegate|. This class is ref-counted and implements | 45 // |WtsSessionProcessDelegate|. This class is ref-counted and implements |
46 // asynchronous fire-and-forget shutdown. | 46 // asynchronous fire-and-forget shutdown. |
47 class WtsSessionProcessDelegate::Core | 47 class WtsSessionProcessDelegate::Core |
48 : public base::RefCountedThreadSafe<Core>, | 48 : public base::RefCountedThreadSafe<Core>, |
49 public base::MessagePumpForIO::IOHandler, | 49 public base::MessagePumpForIO::IOHandler, |
50 public IPC::Listener { | 50 public IPC::Listener { |
51 public: | 51 public: |
52 Core(scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, | 52 Core(scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, |
53 scoped_ptr<base::CommandLine> target, | 53 std::unique_ptr<base::CommandLine> target, |
54 bool launch_elevated, | 54 bool launch_elevated, |
55 const std::string& channel_security); | 55 const std::string& channel_security); |
56 | 56 |
57 // Initializes the object returning true on success. | 57 // Initializes the object returning true on success. |
58 bool Initialize(uint32_t session_id); | 58 bool Initialize(uint32_t session_id); |
59 | 59 |
60 // Stops the object asynchronously. | 60 // Stops the object asynchronously. |
61 void Stop(); | 61 void Stop(); |
62 | 62 |
63 // Mirrors WorkerProcessLauncher::Delegate. | 63 // Mirrors WorkerProcessLauncher::Delegate. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 void ReportProcessLaunched(base::win::ScopedHandle worker_process); | 104 void ReportProcessLaunched(base::win::ScopedHandle worker_process); |
105 | 105 |
106 // The task runner all public methods of this class should be called on. | 106 // The task runner all public methods of this class should be called on. |
107 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner_; | 107 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner_; |
108 | 108 |
109 // The task runner serving job object notifications. | 109 // The task runner serving job object notifications. |
110 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | 110 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
111 | 111 |
112 // The server end of the IPC channel used to communicate to the worker | 112 // The server end of the IPC channel used to communicate to the worker |
113 // process. | 113 // process. |
114 scoped_ptr<IPC::ChannelProxy> channel_; | 114 std::unique_ptr<IPC::ChannelProxy> channel_; |
115 | 115 |
116 // Security descriptor (as SDDL) to be applied to |channel_|. | 116 // Security descriptor (as SDDL) to be applied to |channel_|. |
117 std::string channel_security_; | 117 std::string channel_security_; |
118 | 118 |
119 WorkerProcessLauncher* event_handler_; | 119 WorkerProcessLauncher* event_handler_; |
120 | 120 |
121 // Pointer to GetNamedPipeClientProcessId() API if it is available. | 121 // Pointer to GetNamedPipeClientProcessId() API if it is available. |
122 typedef BOOL (WINAPI * GetNamedPipeClientProcessIdFn)(HANDLE, DWORD*); | 122 typedef BOOL (WINAPI * GetNamedPipeClientProcessIdFn)(HANDLE, DWORD*); |
123 GetNamedPipeClientProcessIdFn get_named_pipe_client_pid_; | 123 GetNamedPipeClientProcessIdFn get_named_pipe_client_pid_; |
124 | 124 |
125 // The job object used to control the lifetime of child processes. | 125 // The job object used to control the lifetime of child processes. |
126 base::win::ScopedHandle job_; | 126 base::win::ScopedHandle job_; |
127 | 127 |
128 // True if the worker process should be launched elevated. | 128 // True if the worker process should be launched elevated. |
129 bool launch_elevated_; | 129 bool launch_elevated_; |
130 | 130 |
131 // True if a laucnh attemp is pending. | 131 // True if a laucnh attemp is pending. |
132 bool launch_pending_; | 132 bool launch_pending_; |
133 | 133 |
134 // The named pipe used as the transport by |channel_|. | 134 // The named pipe used as the transport by |channel_|. |
135 base::win::ScopedHandle pipe_; | 135 base::win::ScopedHandle pipe_; |
136 | 136 |
137 // The token to be used to launch a process in a different session. | 137 // The token to be used to launch a process in a different session. |
138 base::win::ScopedHandle session_token_; | 138 base::win::ScopedHandle session_token_; |
139 | 139 |
140 // Command line of the launched process. | 140 // Command line of the launched process. |
141 scoped_ptr<base::CommandLine> target_command_; | 141 std::unique_ptr<base::CommandLine> target_command_; |
142 | 142 |
143 // The handle of the worker process, if launched. | 143 // The handle of the worker process, if launched. |
144 base::win::ScopedHandle worker_process_; | 144 base::win::ScopedHandle worker_process_; |
145 | 145 |
146 DISALLOW_COPY_AND_ASSIGN(Core); | 146 DISALLOW_COPY_AND_ASSIGN(Core); |
147 }; | 147 }; |
148 | 148 |
149 WtsSessionProcessDelegate::Core::Core( | 149 WtsSessionProcessDelegate::Core::Core( |
150 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, | 150 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, |
151 scoped_ptr<base::CommandLine> target_command, | 151 std::unique_ptr<base::CommandLine> target_command, |
152 bool launch_elevated, | 152 bool launch_elevated, |
153 const std::string& channel_security) | 153 const std::string& channel_security) |
154 : caller_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 154 : caller_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
155 io_task_runner_(io_task_runner), | 155 io_task_runner_(io_task_runner), |
156 channel_security_(channel_security), | 156 channel_security_(channel_security), |
157 event_handler_(nullptr), | 157 event_handler_(nullptr), |
158 get_named_pipe_client_pid_(nullptr), | 158 get_named_pipe_client_pid_(nullptr), |
159 launch_elevated_(launch_elevated), | 159 launch_elevated_(launch_elevated), |
160 launch_pending_(false), | 160 launch_pending_(false), |
161 target_command_(std::move(target_command)) {} | 161 target_command_(std::move(target_command)) {} |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 | 375 |
376 // Create the server end of the IPC channel. | 376 // Create the server end of the IPC channel. |
377 std::string channel_name = IPC::Channel::GenerateUniqueRandomChannelID(); | 377 std::string channel_name = IPC::Channel::GenerateUniqueRandomChannelID(); |
378 ScopedHandle pipe; | 378 ScopedHandle pipe; |
379 if (!CreateIpcChannel(channel_name, channel_security_, &pipe)) { | 379 if (!CreateIpcChannel(channel_name, channel_security_, &pipe)) { |
380 ReportFatalError(); | 380 ReportFatalError(); |
381 return; | 381 return; |
382 } | 382 } |
383 | 383 |
384 // Wrap the pipe into an IPC channel. | 384 // Wrap the pipe into an IPC channel. |
385 scoped_ptr<IPC::ChannelProxy> channel( | 385 std::unique_ptr<IPC::ChannelProxy> channel(IPC::ChannelProxy::Create( |
386 IPC::ChannelProxy::Create(IPC::ChannelHandle(pipe.Get()), | 386 IPC::ChannelHandle(pipe.Get()), IPC::Channel::MODE_SERVER, this, |
387 IPC::Channel::MODE_SERVER, | 387 io_task_runner_)); |
388 this, | |
389 io_task_runner_)); | |
390 | 388 |
391 // Pass the name of the IPC channel to use. | 389 // Pass the name of the IPC channel to use. |
392 command_line.AppendSwitchNative(kDaemonPipeSwitchName, | 390 command_line.AppendSwitchNative(kDaemonPipeSwitchName, |
393 base::UTF8ToWide(channel_name)); | 391 base::UTF8ToWide(channel_name)); |
394 | 392 |
395 // Try to launch the process. | 393 // Try to launch the process. |
396 ScopedHandle worker_process; | 394 ScopedHandle worker_process; |
397 ScopedHandle worker_thread; | 395 ScopedHandle worker_thread; |
398 if (!LaunchProcessWithToken(command_line.GetProgram(), | 396 if (!LaunchProcessWithToken(command_line.GetProgram(), |
399 command_line.GetCommandLineString(), | 397 command_line.GetCommandLineString(), |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 ReportFatalError(); | 520 ReportFatalError(); |
523 return; | 521 return; |
524 } | 522 } |
525 ScopedHandle limited_handle(temp_handle); | 523 ScopedHandle limited_handle(temp_handle); |
526 | 524 |
527 event_handler_->OnProcessLaunched(std::move(limited_handle)); | 525 event_handler_->OnProcessLaunched(std::move(limited_handle)); |
528 } | 526 } |
529 | 527 |
530 WtsSessionProcessDelegate::WtsSessionProcessDelegate( | 528 WtsSessionProcessDelegate::WtsSessionProcessDelegate( |
531 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, | 529 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, |
532 scoped_ptr<base::CommandLine> target_command, | 530 std::unique_ptr<base::CommandLine> target_command, |
533 bool launch_elevated, | 531 bool launch_elevated, |
534 const std::string& channel_security) { | 532 const std::string& channel_security) { |
535 core_ = new Core(io_task_runner, std::move(target_command), launch_elevated, | 533 core_ = new Core(io_task_runner, std::move(target_command), launch_elevated, |
536 channel_security); | 534 channel_security); |
537 } | 535 } |
538 | 536 |
539 WtsSessionProcessDelegate::~WtsSessionProcessDelegate() { | 537 WtsSessionProcessDelegate::~WtsSessionProcessDelegate() { |
540 core_->Stop(); | 538 core_->Stop(); |
541 } | 539 } |
542 | 540 |
(...skipping 12 matching lines...) Expand all Loading... |
555 | 553 |
556 void WtsSessionProcessDelegate::CloseChannel() { | 554 void WtsSessionProcessDelegate::CloseChannel() { |
557 core_->CloseChannel(); | 555 core_->CloseChannel(); |
558 } | 556 } |
559 | 557 |
560 void WtsSessionProcessDelegate::KillProcess() { | 558 void WtsSessionProcessDelegate::KillProcess() { |
561 core_->KillProcess(); | 559 core_->KillProcess(); |
562 } | 560 } |
563 | 561 |
564 } // namespace remoting | 562 } // namespace remoting |
OLD | NEW |