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

Unified Diff: mojo/edk/embedder/pending_process_connection.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 | « mojo/edk/embedder/pending_process_connection.h ('k') | mojo/edk/test/multiprocess_test_helper.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/edk/embedder/pending_process_connection.cc
diff --git a/mojo/edk/embedder/pending_process_connection.cc b/mojo/edk/embedder/pending_process_connection.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8ab58727931f98a93f77735ac6eb37b654ada07b
--- /dev/null
+++ b/mojo/edk/embedder/pending_process_connection.cc
@@ -0,0 +1,50 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "mojo/edk/embedder/pending_process_connection.h"
+
+#include "mojo/edk/embedder/embedder.h"
+#include "mojo/edk/embedder/embedder_internal.h"
+#include "mojo/edk/system/core.h"
+
+namespace mojo {
+namespace edk {
+
+PendingProcessConnection::PendingProcessConnection()
+ : process_token_(GenerateRandomToken()) {
+ DCHECK(internal::g_core);
+}
+
+PendingProcessConnection::~PendingProcessConnection() {
+ if (has_message_pipes_ && !connected_) {
+ DCHECK(internal::g_core);
+ internal::g_core->ChildLaunchFailed(process_token_);
+ }
+}
+
+ScopedMessagePipeHandle PendingProcessConnection::CreateMessagePipe(
+ std::string* token) {
+ has_message_pipes_ = true;
+ DCHECK(internal::g_core);
+ *token = GenerateRandomToken();
+ return internal::g_core->CreateParentMessagePipe(*token, process_token_);
+}
+
+void PendingProcessConnection::Connect(
+ base::ProcessHandle process,
+ ScopedPlatformHandle channel,
+ const ProcessErrorCallback& error_callback) {
+ // It's now safe to avoid cleanup in the destructor, as the lifetime of any
+ // associated resources is effectively bound to the |channel| passed to
+ // AddChild() below.
+ DCHECK(!connected_);
+ connected_ = true;
+
+ DCHECK(internal::g_core);
+ internal::g_core->AddChild(process, std::move(channel), process_token_,
+ error_callback);
+}
+
+} // namespace edk
+} // namespace mojo
« no previous file with comments | « mojo/edk/embedder/pending_process_connection.h ('k') | mojo/edk/test/multiprocess_test_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698