Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(311)

Side by Side Diff: content/browser/child_process_launcher.cc

Issue 1893313003: [mojo] Use a pipe path to initialise Mojo in elevated utility processes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
28 #include "mojo/edk/embedder/scoped_platform_handle.h" 30 #include "mojo/edk/embedder/scoped_platform_handle.h"
29 31
30 #if defined(OS_WIN) 32 #if defined(OS_WIN)
31 #include "base/files/file_path.h" 33 #include "base/files/file_path.h"
32 #include "base/win/scoped_handle.h" 34 #include "base/win/scoped_handle.h"
33 #include "base/win/win_util.h" 35 #include "base/win/win_util.h"
34 #include "content/common/sandbox_win.h" 36 #include "content/common/sandbox_win.h"
35 #include "content/public/common/sandbox_init.h" 37 #include "content/public/common/sandbox_init.h"
36 #include "sandbox/win/src/sandbox_types.h" 38 #include "sandbox/win/src/sandbox_types.h"
37 #elif defined(OS_MACOSX) 39 #elif defined(OS_MACOSX)
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 #elif defined(OS_POSIX) && !defined(OS_ANDROID) 137 #elif defined(OS_POSIX) && !defined(OS_ANDROID)
136 base::EnvironmentMap env = delegate->GetEnvironment(); 138 base::EnvironmentMap env = delegate->GetEnvironment();
137 base::ScopedFD ipcfd = delegate->TakeIpcFd(); 139 base::ScopedFD ipcfd = delegate->TakeIpcFd();
138 #endif 140 #endif
139 std::unique_ptr<base::CommandLine> cmd_line_deleter(cmd_line); 141 std::unique_ptr<base::CommandLine> cmd_line_deleter(cmd_line);
140 base::TimeTicks begin_launch_time = base::TimeTicks::Now(); 142 base::TimeTicks begin_launch_time = base::TimeTicks::Now();
141 143
142 base::Process process; 144 base::Process process;
143 #if defined(OS_WIN) 145 #if defined(OS_WIN)
144 if (launch_elevated) { 146 if (launch_elevated) {
145 // TODO(rockot): We may want to support Mojo IPC to elevated processes as 147 // When establishing a Mojo connection, the pipe path has already been added
146 // well, but this isn't currently feasible without sharing a pipe path on 148 // to the command line.
147 // the command line as elevated process launch goes through ShellExecuteEx.
148 base::LaunchOptions options; 149 base::LaunchOptions options;
149 options.start_hidden = true; 150 options.start_hidden = true;
150 process = base::LaunchElevatedProcess(*cmd_line, options); 151 process = base::LaunchElevatedProcess(*cmd_line, options);
151 } else { 152 } else {
152 base::HandlesToInheritVector handles; 153 base::HandlesToInheritVector handles;
153 handles.push_back(client_handle.get().handle); 154 handles.push_back(client_handle.get().handle);
154 cmd_line->AppendSwitchASCII( 155 cmd_line->AppendSwitchASCII(
155 mojo::edk::PlatformChannelPair::kMojoPlatformChannelHandleSwitch, 156 mojo::edk::PlatformChannelPair::kMojoPlatformChannelHandleSwitch,
156 base::UintToString(base::win::HandleToUint32(handles[0]))); 157 base::UintToString(base::win::HandleToUint32(handles[0])));
157 launch_result = 158 launch_result =
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 !cmd_line->HasSwitch(switches::kNoSandbox)); 448 !cmd_line->HasSwitch(switches::kNoSandbox));
448 449
449 // We need to close the client end of the IPC channel to reliably detect 450 // We need to close the client end of the IPC channel to reliably detect
450 // child termination. We will close this fd after we create the child 451 // child termination. We will close this fd after we create the child
451 // process which is asynchronous on Android. 452 // process which is asynchronous on Android.
452 base::ScopedFD ipcfd(delegate->TakeIpcFd().release()); 453 base::ScopedFD ipcfd(delegate->TakeIpcFd().release());
453 #endif 454 #endif
454 NotifyCallback reply_callback(base::Bind(&ChildProcessLauncher::DidLaunch, 455 NotifyCallback reply_callback(base::Bind(&ChildProcessLauncher::DidLaunch,
455 weak_factory_.GetWeakPtr(), 456 weak_factory_.GetWeakPtr(),
456 terminate_child_on_shutdown_)); 457 terminate_child_on_shutdown_));
457 mojo::edk::ScopedPlatformHandle client_handle = 458 mojo::edk::ScopedPlatformHandle client_handle;
458 mojo_platform_channel_.PassClientHandle(); 459 #if defined(OS_WIN)
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 }
459 BrowserThread::PostTask( 471 BrowserThread::PostTask(
460 BrowserThread::PROCESS_LAUNCHER, FROM_HERE, 472 BrowserThread::PROCESS_LAUNCHER, FROM_HERE,
461 base::Bind(&LaunchOnLauncherThread, reply_callback, client_thread_id_, 473 base::Bind(&LaunchOnLauncherThread, reply_callback, client_thread_id_,
462 child_process_id, delegate, 474 child_process_id, delegate,
463 #if defined(OS_ANDROID) 475 #if defined(OS_ANDROID)
464 base::Passed(&ipcfd), 476 base::Passed(&ipcfd),
465 #endif 477 #endif
466 base::Passed(&client_handle), cmd_line)); 478 base::Passed(&client_handle), cmd_line));
467 } 479 }
468 480
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 #endif 550 #endif
539 base::Process process, 551 base::Process process,
540 int error_code) { 552 int error_code) {
541 DCHECK(CalledOnValidThread()); 553 DCHECK(CalledOnValidThread());
542 starting_ = false; 554 starting_ = false;
543 process_ = std::move(process); 555 process_ = std::move(process);
544 556
545 if (process_.IsValid()) { 557 if (process_.IsValid()) {
546 // Set up Mojo IPC to the new process. 558 // Set up Mojo IPC to the new process.
547 mojo::edk::ChildProcessLaunched(process_.Handle(), 559 mojo::edk::ChildProcessLaunched(process_.Handle(),
548 mojo_platform_channel_.PassServerHandle()); 560 std::move(mojo_host_platform_handle_));
549 } 561 }
550 562
551 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) 563 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
552 zygote_ = zygote; 564 zygote_ = zygote;
553 #endif 565 #endif
554 if (process_.IsValid()) { 566 if (process_.IsValid()) {
555 client_->OnProcessLaunched(); 567 client_->OnProcessLaunched();
556 } else { 568 } else {
557 termination_status_ = base::TERMINATION_STATUS_LAUNCH_FAILED; 569 termination_status_ = base::TERMINATION_STATUS_LAUNCH_FAILED;
558 client_->OnProcessLaunchFailed(error_code); 570 client_->OnProcessLaunchFailed(error_code);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 } 611 }
600 612
601 ChildProcessLauncher::Client* ChildProcessLauncher::ReplaceClientForTest( 613 ChildProcessLauncher::Client* ChildProcessLauncher::ReplaceClientForTest(
602 Client* client) { 614 Client* client) {
603 Client* ret = client_; 615 Client* ret = client_;
604 client_ = client; 616 client_ = client;
605 return ret; 617 return ret;
606 } 618 }
607 619
608 } // namespace content 620 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/child_process_launcher.h ('k') | content/browser/utility_process_host_impl_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698