Index: content/browser/child_process_launcher_helper.cc |
diff --git a/content/browser/child_process_launcher_helper.cc b/content/browser/child_process_launcher_helper.cc |
index 9aa83459ba904dbf4e7db6a08f125a156cdda4a9..0adaf64e13cf5cc13a51e41fa828b264e19be0e5 100644 |
--- a/content/browser/child_process_launcher_helper.cc |
+++ b/content/browser/child_process_launcher_helper.cc |
@@ -54,15 +54,18 @@ ChildProcessLauncherHelper::ChildProcessLauncherHelper( |
BrowserThread::ID client_thread_id, |
std::unique_ptr<base::CommandLine> command_line, |
std::unique_ptr<SandboxedProcessLauncherDelegate> delegate, |
+ std::unique_ptr<mojo::edk::PendingProcessConnection> pending_connection, |
+ const mojo::edk::ProcessErrorCallback& process_error_callback, |
const base::WeakPtr<ChildProcessLauncher>& child_process_launcher, |
bool terminate_on_shutdown) |
: child_process_id_(child_process_id), |
client_thread_id_(client_thread_id), |
command_line_(std::move(command_line)), |
delegate_(std::move(delegate)), |
+ pending_connection_(std::move(pending_connection)), |
+ process_error_callback_(process_error_callback), |
child_process_launcher_(child_process_launcher), |
- terminate_on_shutdown_(terminate_on_shutdown) { |
-} |
+ terminate_on_shutdown_(terminate_on_shutdown) {} |
ChildProcessLauncherHelper::~ChildProcessLauncherHelper() { |
} |
@@ -72,19 +75,24 @@ void ChildProcessLauncherHelper::StartLaunchOnClientThread() { |
BeforeLaunchOnClientThread(); |
- mojo_server_handle_ = PrepareMojoPipeHandlesOnClientThread(); |
- if (!mojo_server_handle_.is_valid()) { |
+ mojo::edk::ScopedPlatformHandle server_handle = |
+ PrepareMojoPipeHandlesOnClientThread(); |
+ if (!server_handle.is_valid()) { |
mojo::edk::PlatformChannelPair channel_pair; |
- mojo_server_handle_ = channel_pair.PassServerHandle(); |
+ server_handle = channel_pair.PassServerHandle(); |
mojo_client_handle_ = channel_pair.PassClientHandle(); |
} |
BrowserThread::PostTask( |
BrowserThread::PROCESS_LAUNCHER, FROM_HERE, |
- base::Bind(&ChildProcessLauncherHelper::LaunchOnLauncherThread, this)); |
+ base::Bind(&ChildProcessLauncherHelper::LaunchOnLauncherThread, this, |
+ base::Passed(&pending_connection_), |
+ base::Passed(&server_handle))); |
} |
-void ChildProcessLauncherHelper::LaunchOnLauncherThread() { |
+void ChildProcessLauncherHelper::LaunchOnLauncherThread( |
+ std::unique_ptr<mojo::edk::PendingProcessConnection> pending_connection, |
+ mojo::edk::ScopedPlatformHandle server_handle) { |
DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER); |
begin_launch_time_ = base::TimeTicks::Now(); |
@@ -96,22 +104,29 @@ void ChildProcessLauncherHelper::LaunchOnLauncherThread() { |
base::LaunchOptions options; |
BeforeLaunchOnLauncherThread(*files_to_register, &options); |
- Process process = LaunchProcessOnLauncherThread(options, |
- std::move(files_to_register), |
- &is_synchronous_launch, |
- &launch_result); |
+ Process process = LaunchProcessOnLauncherThread( |
+ options, std::move(files_to_register), &is_synchronous_launch, |
+ &launch_result, &pending_connection, &server_handle); |
AfterLaunchOnLauncherThread(process, options); |
if (is_synchronous_launch) { |
- PostLaunchOnLauncherThread(std::move(process), launch_result, false); |
+ // If launch was synchronous, the helper must not have taken ownership of |
+ // |pending_connection| or |server_handle|. |
+ DCHECK(pending_connection); |
+ DCHECK(server_handle.is_valid()); |
+ PostLaunchOnLauncherThread(std::move(process), launch_result, false, |
+ std::move(pending_connection), |
+ std::move(server_handle)); |
} |
} |
void ChildProcessLauncherHelper::PostLaunchOnLauncherThread( |
ChildProcessLauncherHelper::Process process, |
int launch_result, |
- bool post_launch_on_client_thread_called) { |
+ bool post_launch_on_client_thread_called, |
+ std::unique_ptr<mojo::edk::PendingProcessConnection> pending_connection, |
+ mojo::edk::ScopedPlatformHandle server_handle) { |
// Release the client handle now that the process has been started (the pipe |
// may not signal when the process dies otherwise and we would not detect the |
// child process died). |
@@ -120,6 +135,12 @@ void ChildProcessLauncherHelper::PostLaunchOnLauncherThread( |
if (process.process.IsValid()) { |
RecordHistogramsOnLauncherThread( |
base::TimeTicks::Now() - begin_launch_time_); |
+ |
+ DCHECK(pending_connection); |
+ DCHECK(server_handle.is_valid()); |
+ pending_connection->Connect(process.process.Handle(), |
+ std::move(server_handle), |
+ process_error_callback_); |
} |
if (!post_launch_on_client_thread_called) { |
@@ -134,8 +155,7 @@ void ChildProcessLauncherHelper::PostLaunchOnClientThread( |
ChildProcessLauncherHelper::Process process, |
int error_code) { |
if (child_process_launcher_) { |
- child_process_launcher_->Notify( |
- std::move(process), std::move(mojo_server_handle_), error_code); |
+ child_process_launcher_->Notify(std::move(process), error_code); |
} else if (process.process.IsValid() && terminate_on_shutdown_) { |
// Client is gone, terminate the process. |
ForceNormalProcessTerminationAsync(std::move(process)); |