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 <memory> |
10 #include <utility> | 11 #include <utility> |
11 | 12 |
12 #include "base/bind.h" | 13 #include "base/bind.h" |
13 #include "base/command_line.h" | 14 #include "base/command_line.h" |
14 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
15 #include "base/logging.h" | 16 #include "base/logging.h" |
16 #include "base/macros.h" | 17 #include "base/macros.h" |
17 #include "base/memory/ptr_util.h" | 18 #include "base/memory/ptr_util.h" |
18 #include "base/message_loop/message_loop.h" | 19 #include "base/message_loop/message_loop.h" |
19 #include "base/process/process_handle.h" | 20 #include "base/process/process_handle.h" |
20 #include "base/single_thread_task_runner.h" | 21 #include "base/single_thread_task_runner.h" |
21 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
22 #include "base/threading/thread_task_runner_handle.h" | 23 #include "base/threading/thread_task_runner_handle.h" |
23 #include "base/win/scoped_handle.h" | 24 #include "base/win/scoped_handle.h" |
24 #include "ipc/ipc_channel.h" | 25 #include "ipc/ipc_channel.h" |
25 #include "ipc/ipc_channel_proxy.h" | 26 #include "ipc/ipc_channel_proxy.h" |
26 #include "ipc/ipc_listener.h" | 27 #include "ipc/ipc_listener.h" |
27 #include "ipc/ipc_message.h" | 28 #include "ipc/ipc_message.h" |
28 #include "mojo/edk/embedder/embedder.h" | 29 #include "mojo/edk/embedder/embedder.h" |
29 #include "mojo/edk/embedder/named_platform_channel_pair.h" | 30 #include "mojo/edk/embedder/named_platform_channel_pair.h" |
| 31 #include "mojo/edk/embedder/pending_process_connection.h" |
30 #include "mojo/edk/embedder/platform_channel_pair.h" | 32 #include "mojo/edk/embedder/platform_channel_pair.h" |
31 #include "mojo/edk/embedder/platform_handle_utils.h" | 33 #include "mojo/edk/embedder/platform_handle_utils.h" |
32 #include "mojo/edk/embedder/scoped_platform_handle.h" | 34 #include "mojo/edk/embedder/scoped_platform_handle.h" |
33 #include "remoting/host/host_main.h" | 35 #include "remoting/host/host_main.h" |
34 #include "remoting/host/ipc_constants.h" | 36 #include "remoting/host/ipc_constants.h" |
35 #include "remoting/host/switches.h" | 37 #include "remoting/host/switches.h" |
36 #include "remoting/host/win/launch_process_with_token.h" | 38 #include "remoting/host/win/launch_process_with_token.h" |
37 #include "remoting/host/win/security_descriptor.h" | 39 #include "remoting/host/win/security_descriptor.h" |
38 #include "remoting/host/win/worker_process_launcher.h" | 40 #include "remoting/host/win/worker_process_launcher.h" |
39 #include "remoting/host/win/wts_terminal_monitor.h" | 41 #include "remoting/host/win/wts_terminal_monitor.h" |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 // If launching elevated, this holds the server handle after launch, until | 150 // If launching elevated, this holds the server handle after launch, until |
149 // the final process launches. | 151 // the final process launches. |
150 mojo::edk::ScopedPlatformHandle elevated_server_handle_; | 152 mojo::edk::ScopedPlatformHandle elevated_server_handle_; |
151 | 153 |
152 // If launching elevated, this is the pid of the launcher process. | 154 // If launching elevated, this is the pid of the launcher process. |
153 base::ProcessId elevated_launcher_pid_ = base::kNullProcessId; | 155 base::ProcessId elevated_launcher_pid_ = base::kNullProcessId; |
154 | 156 |
155 // Tracks the id of the worker process. | 157 // Tracks the id of the worker process. |
156 base::ProcessId worker_process_pid_ = base::kNullProcessId; | 158 base::ProcessId worker_process_pid_ = base::kNullProcessId; |
157 | 159 |
158 // The mojo child token for the process being launched. | 160 // The pending process connection for the process being launched. |
159 std::string mojo_child_token_; | 161 std::unique_ptr<mojo::edk::PendingProcessConnection> process_connection_; |
160 | 162 |
161 DISALLOW_COPY_AND_ASSIGN(Core); | 163 DISALLOW_COPY_AND_ASSIGN(Core); |
162 }; | 164 }; |
163 | 165 |
164 WtsSessionProcessDelegate::Core::Core( | 166 WtsSessionProcessDelegate::Core::Core( |
165 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, | 167 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, |
166 std::unique_ptr<base::CommandLine> target_command, | 168 std::unique_ptr<base::CommandLine> target_command, |
167 bool launch_elevated, | 169 bool launch_elevated, |
168 const std::string& channel_security) | 170 const std::string& channel_security) |
169 : caller_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 171 : caller_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 void WtsSessionProcessDelegate::Core::CloseChannel() { | 252 void WtsSessionProcessDelegate::Core::CloseChannel() { |
251 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 253 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
252 | 254 |
253 if (!channel_) { | 255 if (!channel_) { |
254 return; | 256 return; |
255 } | 257 } |
256 | 258 |
257 channel_.reset(); | 259 channel_.reset(); |
258 elevated_server_handle_.reset(); | 260 elevated_server_handle_.reset(); |
259 elevated_launcher_pid_ = base::kNullProcessId; | 261 elevated_launcher_pid_ = base::kNullProcessId; |
260 if (!mojo_child_token_.empty()) { | 262 process_connection_.reset(); |
261 mojo::edk::ChildProcessLaunchFailed(mojo_child_token_); | |
262 mojo_child_token_.clear(); | |
263 } | |
264 } | 263 } |
265 | 264 |
266 void WtsSessionProcessDelegate::Core::KillProcess() { | 265 void WtsSessionProcessDelegate::Core::KillProcess() { |
267 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 266 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
268 | 267 |
269 CloseChannel(); | 268 CloseChannel(); |
270 | 269 |
271 event_handler_ = nullptr; | 270 event_handler_ = nullptr; |
272 launch_pending_ = false; | 271 launch_pending_ = false; |
273 | 272 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 return; | 383 return; |
385 } | 384 } |
386 | 385 |
387 // Create the command line passing the name of the IPC channel to use and | 386 // Create the command line passing the name of the IPC channel to use and |
388 // copying known switches from the caller's command line. | 387 // copying known switches from the caller's command line. |
389 command_line.SetProgram(helper_binary); | 388 command_line.SetProgram(helper_binary); |
390 command_line.AppendSwitchPath(kElevateSwitchName, | 389 command_line.AppendSwitchPath(kElevateSwitchName, |
391 target_command_->GetProgram()); | 390 target_command_->GetProgram()); |
392 } | 391 } |
393 | 392 |
394 const std::string mojo_message_pipe_token = mojo::edk::GenerateRandomToken(); | 393 std::string mojo_pipe_token; |
395 mojo_child_token_ = mojo::edk::GenerateRandomToken(); | 394 process_connection_ = base::MakeUnique<mojo::edk::PendingProcessConnection>(); |
396 std::unique_ptr<IPC::ChannelProxy> channel = IPC::ChannelProxy::Create( | 395 std::unique_ptr<IPC::ChannelProxy> channel = IPC::ChannelProxy::Create( |
397 mojo::edk::CreateParentMessagePipe(mojo_message_pipe_token, | 396 process_connection_->CreateMessagePipe(&mojo_pipe_token).release(), |
398 mojo_child_token_) | |
399 .release(), | |
400 IPC::Channel::MODE_SERVER, this, io_task_runner_); | 397 IPC::Channel::MODE_SERVER, this, io_task_runner_); |
401 command_line.AppendSwitchASCII(kMojoPipeToken, mojo_message_pipe_token); | 398 command_line.AppendSwitchASCII(kMojoPipeToken, mojo_pipe_token); |
402 | 399 |
403 std::unique_ptr<mojo::edk::PlatformChannelPair> normal_mojo_channel; | 400 std::unique_ptr<mojo::edk::PlatformChannelPair> normal_mojo_channel; |
404 std::unique_ptr<mojo::edk::NamedPlatformChannelPair> elevated_mojo_channel; | 401 std::unique_ptr<mojo::edk::NamedPlatformChannelPair> elevated_mojo_channel; |
405 base::HandlesToInheritVector handles_to_inherit; | 402 base::HandlesToInheritVector handles_to_inherit; |
406 if (launch_elevated_) { | 403 if (launch_elevated_) { |
407 // Pass the name of the IPC channel to use. | 404 // Pass the name of the IPC channel to use. |
408 mojo::edk::NamedPlatformChannelPair::Options options; | 405 mojo::edk::NamedPlatformChannelPair::Options options; |
409 options.security_descriptor = base::UTF8ToUTF16(channel_security_); | 406 options.security_descriptor = base::UTF8ToUTF16(channel_security_); |
410 elevated_mojo_channel = | 407 elevated_mojo_channel = |
411 base::MakeUnique<mojo::edk::NamedPlatformChannelPair>(options); | 408 base::MakeUnique<mojo::edk::NamedPlatformChannelPair>(options); |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 event_handler_ = nullptr; | 548 event_handler_ = nullptr; |
552 event_handler->OnFatalError(); | 549 event_handler->OnFatalError(); |
553 } | 550 } |
554 | 551 |
555 void WtsSessionProcessDelegate::Core::ReportProcessLaunched( | 552 void WtsSessionProcessDelegate::Core::ReportProcessLaunched( |
556 base::win::ScopedHandle worker_process, | 553 base::win::ScopedHandle worker_process, |
557 mojo::edk::ScopedPlatformHandle server_handle) { | 554 mojo::edk::ScopedPlatformHandle server_handle) { |
558 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 555 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
559 DCHECK(!worker_process_.IsValid()); | 556 DCHECK(!worker_process_.IsValid()); |
560 | 557 |
561 mojo::edk::ChildProcessLaunched(worker_process.Get(), | 558 process_connection_->Connect(worker_process.Get(), std::move(server_handle)); |
562 std::move(server_handle), | 559 process_connection_.reset(); |
563 mojo_child_token_); | |
564 mojo_child_token_.clear(); | |
565 worker_process_ = std::move(worker_process); | 560 worker_process_ = std::move(worker_process); |
566 | 561 |
567 // Report a handle that can be used to wait for the worker process completion, | 562 // Report a handle that can be used to wait for the worker process completion, |
568 // query information about the process and duplicate handles. | 563 // query information about the process and duplicate handles. |
569 DWORD desired_access = | 564 DWORD desired_access = |
570 SYNCHRONIZE | PROCESS_DUP_HANDLE | PROCESS_QUERY_INFORMATION; | 565 SYNCHRONIZE | PROCESS_DUP_HANDLE | PROCESS_QUERY_INFORMATION; |
571 HANDLE temp_handle; | 566 HANDLE temp_handle; |
572 if (!DuplicateHandle(GetCurrentProcess(), worker_process_.Get(), | 567 if (!DuplicateHandle(GetCurrentProcess(), worker_process_.Get(), |
573 GetCurrentProcess(), &temp_handle, desired_access, FALSE, | 568 GetCurrentProcess(), &temp_handle, desired_access, FALSE, |
574 0)) { | 569 0)) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
609 | 604 |
610 void WtsSessionProcessDelegate::CloseChannel() { | 605 void WtsSessionProcessDelegate::CloseChannel() { |
611 core_->CloseChannel(); | 606 core_->CloseChannel(); |
612 } | 607 } |
613 | 608 |
614 void WtsSessionProcessDelegate::KillProcess() { | 609 void WtsSessionProcessDelegate::KillProcess() { |
615 core_->KillProcess(); | 610 core_->KillProcess(); |
616 } | 611 } |
617 | 612 |
618 } // namespace remoting | 613 } // namespace remoting |
OLD | NEW |