OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 #include "content/browser/child_process_launcher.h" | 5 #include "content/browser/child_process_launcher.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
13 #include "base/i18n/icu_util.h" | 13 #include "base/i18n/icu_util.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
16 #include "base/process/launch.h" | 16 #include "base/process/launch.h" |
17 #include "base/process/process.h" | 17 #include "base/process/process.h" |
18 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
19 #include "base/synchronization/lock.h" | 19 #include "base/synchronization/lock.h" |
20 #include "base/threading/thread.h" | 20 #include "base/threading/thread.h" |
21 #include "build/build_config.h" | 21 #include "build/build_config.h" |
22 #include "content/public/browser/content_browser_client.h" | 22 #include "content/public/browser/content_browser_client.h" |
23 #include "content/public/common/content_descriptors.h" | 23 #include "content/public/common/content_descriptors.h" |
24 #include "content/public/common/content_switches.h" | 24 #include "content/public/common/content_switches.h" |
25 #include "content/public/common/result_codes.h" | 25 #include "content/public/common/result_codes.h" |
26 #include "content/public/common/sandboxed_process_launcher_delegate.h" | 26 #include "content/public/common/sandboxed_process_launcher_delegate.h" |
27 #include "mojo/edk/embedder/embedder.h" | 27 #include "mojo/edk/embedder/embedder.h" |
28 #include "mojo/edk/embedder/named_platform_channel_pair.h" | |
29 #include "mojo/edk/embedder/platform_channel_pair.h" | |
30 #include "mojo/edk/embedder/scoped_platform_handle.h" | 28 #include "mojo/edk/embedder/scoped_platform_handle.h" |
31 | 29 |
32 #if defined(OS_WIN) | 30 #if defined(OS_WIN) |
33 #include "base/files/file_path.h" | 31 #include "base/files/file_path.h" |
34 #include "base/win/scoped_handle.h" | 32 #include "base/win/scoped_handle.h" |
35 #include "base/win/win_util.h" | 33 #include "base/win/win_util.h" |
36 #include "content/common/sandbox_win.h" | 34 #include "content/common/sandbox_win.h" |
37 #include "content/public/common/sandbox_init.h" | 35 #include "content/public/common/sandbox_init.h" |
38 #include "sandbox/win/src/sandbox_types.h" | 36 #include "sandbox/win/src/sandbox_types.h" |
39 #elif defined(OS_MACOSX) | 37 #elif defined(OS_MACOSX) |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 #elif defined(OS_POSIX) && !defined(OS_ANDROID) | 135 #elif defined(OS_POSIX) && !defined(OS_ANDROID) |
138 base::EnvironmentMap env = delegate->GetEnvironment(); | 136 base::EnvironmentMap env = delegate->GetEnvironment(); |
139 base::ScopedFD ipcfd = delegate->TakeIpcFd(); | 137 base::ScopedFD ipcfd = delegate->TakeIpcFd(); |
140 #endif | 138 #endif |
141 std::unique_ptr<base::CommandLine> cmd_line_deleter(cmd_line); | 139 std::unique_ptr<base::CommandLine> cmd_line_deleter(cmd_line); |
142 base::TimeTicks begin_launch_time = base::TimeTicks::Now(); | 140 base::TimeTicks begin_launch_time = base::TimeTicks::Now(); |
143 | 141 |
144 base::Process process; | 142 base::Process process; |
145 #if defined(OS_WIN) | 143 #if defined(OS_WIN) |
146 if (launch_elevated) { | 144 if (launch_elevated) { |
147 // When establishing a Mojo connection, the pipe path has already been added | 145 // TODO(rockot): We may want to support Mojo IPC to elevated processes as |
148 // to the command line. | 146 // well, but this isn't currently feasible without sharing a pipe path on |
| 147 // the command line as elevated process launch goes through ShellExecuteEx. |
149 base::LaunchOptions options; | 148 base::LaunchOptions options; |
150 options.start_hidden = true; | 149 options.start_hidden = true; |
151 process = base::LaunchElevatedProcess(*cmd_line, options); | 150 process = base::LaunchElevatedProcess(*cmd_line, options); |
152 } else { | 151 } else { |
153 base::HandlesToInheritVector handles; | 152 base::HandlesToInheritVector handles; |
154 handles.push_back(client_handle.get().handle); | 153 handles.push_back(client_handle.get().handle); |
155 cmd_line->AppendSwitchASCII( | 154 cmd_line->AppendSwitchASCII( |
156 mojo::edk::PlatformChannelPair::kMojoPlatformChannelHandleSwitch, | 155 mojo::edk::PlatformChannelPair::kMojoPlatformChannelHandleSwitch, |
157 base::UintToString(base::win::HandleToUint32(handles[0]))); | 156 base::UintToString(base::win::HandleToUint32(handles[0]))); |
158 launch_result = | 157 launch_result = |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 !cmd_line->HasSwitch(switches::kNoSandbox)); | 447 !cmd_line->HasSwitch(switches::kNoSandbox)); |
449 | 448 |
450 // We need to close the client end of the IPC channel to reliably detect | 449 // We need to close the client end of the IPC channel to reliably detect |
451 // child termination. We will close this fd after we create the child | 450 // child termination. We will close this fd after we create the child |
452 // process which is asynchronous on Android. | 451 // process which is asynchronous on Android. |
453 base::ScopedFD ipcfd(delegate->TakeIpcFd().release()); | 452 base::ScopedFD ipcfd(delegate->TakeIpcFd().release()); |
454 #endif | 453 #endif |
455 NotifyCallback reply_callback(base::Bind(&ChildProcessLauncher::DidLaunch, | 454 NotifyCallback reply_callback(base::Bind(&ChildProcessLauncher::DidLaunch, |
456 weak_factory_.GetWeakPtr(), | 455 weak_factory_.GetWeakPtr(), |
457 terminate_child_on_shutdown_)); | 456 terminate_child_on_shutdown_)); |
458 mojo::edk::ScopedPlatformHandle client_handle; | 457 mojo::edk::ScopedPlatformHandle client_handle = |
459 #if defined(OS_WIN) | 458 mojo_platform_channel_.PassClientHandle(); |
460 if (delegate->ShouldLaunchElevated()) { | |
461 mojo::edk::NamedPlatformChannelPair named_pair; | |
462 mojo_host_platform_handle_ = named_pair.PassServerHandle(); | |
463 named_pair.PrepareToPassClientHandleToChildProcess(cmd_line); | |
464 } else | |
465 #endif | |
466 { | |
467 mojo::edk::PlatformChannelPair channel_pair; | |
468 mojo_host_platform_handle_ = channel_pair.PassServerHandle(); | |
469 client_handle = channel_pair.PassClientHandle(); | |
470 } | |
471 BrowserThread::PostTask( | 459 BrowserThread::PostTask( |
472 BrowserThread::PROCESS_LAUNCHER, FROM_HERE, | 460 BrowserThread::PROCESS_LAUNCHER, FROM_HERE, |
473 base::Bind(&LaunchOnLauncherThread, reply_callback, client_thread_id_, | 461 base::Bind(&LaunchOnLauncherThread, reply_callback, client_thread_id_, |
474 child_process_id, delegate, | 462 child_process_id, delegate, |
475 #if defined(OS_ANDROID) | 463 #if defined(OS_ANDROID) |
476 base::Passed(&ipcfd), | 464 base::Passed(&ipcfd), |
477 #endif | 465 #endif |
478 base::Passed(&client_handle), cmd_line)); | 466 base::Passed(&client_handle), cmd_line)); |
479 } | 467 } |
480 | 468 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 #endif | 538 #endif |
551 base::Process process, | 539 base::Process process, |
552 int error_code) { | 540 int error_code) { |
553 DCHECK(CalledOnValidThread()); | 541 DCHECK(CalledOnValidThread()); |
554 starting_ = false; | 542 starting_ = false; |
555 process_ = std::move(process); | 543 process_ = std::move(process); |
556 | 544 |
557 if (process_.IsValid()) { | 545 if (process_.IsValid()) { |
558 // Set up Mojo IPC to the new process. | 546 // Set up Mojo IPC to the new process. |
559 mojo::edk::ChildProcessLaunched(process_.Handle(), | 547 mojo::edk::ChildProcessLaunched(process_.Handle(), |
560 std::move(mojo_host_platform_handle_)); | 548 mojo_platform_channel_.PassServerHandle()); |
561 } | 549 } |
562 | 550 |
563 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) | 551 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
564 zygote_ = zygote; | 552 zygote_ = zygote; |
565 #endif | 553 #endif |
566 if (process_.IsValid()) { | 554 if (process_.IsValid()) { |
567 client_->OnProcessLaunched(); | 555 client_->OnProcessLaunched(); |
568 } else { | 556 } else { |
569 termination_status_ = base::TERMINATION_STATUS_LAUNCH_FAILED; | 557 termination_status_ = base::TERMINATION_STATUS_LAUNCH_FAILED; |
570 client_->OnProcessLaunchFailed(error_code); | 558 client_->OnProcessLaunchFailed(error_code); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 } | 599 } |
612 | 600 |
613 ChildProcessLauncher::Client* ChildProcessLauncher::ReplaceClientForTest( | 601 ChildProcessLauncher::Client* ChildProcessLauncher::ReplaceClientForTest( |
614 Client* client) { | 602 Client* client) { |
615 Client* ret = client_; | 603 Client* ret = client_; |
616 client_ = client; | 604 client_ = client; |
617 return ret; | 605 return ret; |
618 } | 606 } |
619 | 607 |
620 } // namespace content | 608 } // namespace content |
OLD | NEW |