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

Unified Diff: content/browser/child_process_launcher.cc

Issue 2680973006: Mojo EDK: Add safe process connection API (Closed)
Patch Set: . Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/child_process_launcher.h ('k') | content/browser/renderer_host/render_process_host_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/child_process_launcher.cc
diff --git a/content/browser/child_process_launcher.cc b/content/browser/child_process_launcher.cc
index 6970d248feaae5d83716e9eee6dee0c0d243d81a..3700f47e04cbb73127724b397919d1998f57aba2 100644
--- a/content/browser/child_process_launcher.cc
+++ b/content/browser/child_process_launcher.cc
@@ -23,13 +23,14 @@ ChildProcessLauncher::ChildProcessLauncher(
std::unique_ptr<base::CommandLine> command_line,
int child_process_id,
Client* client,
- const std::string& mojo_child_token,
+ std::unique_ptr<mojo::edk::PendingProcessConnection> pending_connection,
const mojo::edk::ProcessErrorCallback& process_error_callback,
bool terminate_on_shutdown)
: client_(client),
termination_status_(base::TERMINATION_STATUS_NORMAL_TERMINATION),
exit_code_(RESULT_CODE_NORMAL_EXIT),
starting_(true),
+ pending_connection_(std::move(pending_connection)),
process_error_callback_(process_error_callback),
#if defined(ADDRESS_SANITIZER) || defined(LEAK_SANITIZER) || \
defined(MEMORY_SANITIZER) || defined(THREAD_SANITIZER) || \
@@ -38,7 +39,6 @@ ChildProcessLauncher::ChildProcessLauncher(
#else
terminate_child_on_shutdown_(terminate_on_shutdown),
#endif
- mojo_child_token_(mojo_child_token),
weak_factory_(this) {
DCHECK(CalledOnValidThread());
CHECK(BrowserThread::GetCurrentThreadIdentifier(&client_thread_id_));
@@ -78,16 +78,21 @@ void ChildProcessLauncher::Notify(
starting_ = false;
process_ = std::move(process);
+ // Take ownership of the pending connection here so it's destroyed when
+ // we go out of scope regardless of the outcome below.
+ std::unique_ptr<mojo::edk::PendingProcessConnection> pending_connection =
+ std::move(pending_connection_);
if (process_.process.IsValid()) {
// Set up Mojo IPC to the new process.
- mojo::edk::ChildProcessLaunched(process_.process.Handle(),
- std::move(server_handle),
- mojo_child_token_,
- process_error_callback_);
+ DCHECK(pending_connection);
+ pending_connection->Connect(process_.process.Handle(),
+ std::move(server_handle),
+ process_error_callback_);
client_->OnProcessLaunched();
} else {
- mojo::edk::ChildProcessLaunchFailed(mojo_child_token_);
termination_status_ = base::TERMINATION_STATUS_LAUNCH_FAILED;
+
+ // NOTE: May delete |this|.
client_->OnProcessLaunchFailed(error_code);
}
}
« no previous file with comments | « content/browser/child_process_launcher.h ('k') | content/browser/renderer_host/render_process_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698