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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "mojo/edk/embedder/pending_process_connection.h"
6
7 #include "mojo/edk/embedder/embedder.h"
8 #include "mojo/edk/embedder/embedder_internal.h"
9 #include "mojo/edk/system/core.h"
10
11 namespace mojo {
12 namespace edk {
13
14 PendingProcessConnection::PendingProcessConnection()
15 : process_token_(GenerateRandomToken()) {
16 DCHECK(internal::g_core);
17 }
18
19 PendingProcessConnection::~PendingProcessConnection() {
20 if (has_message_pipes_ && !connected_) {
21 DCHECK(internal::g_core);
22 internal::g_core->ChildLaunchFailed(process_token_);
23 }
24 }
25
26 ScopedMessagePipeHandle PendingProcessConnection::CreateMessagePipe(
27 std::string* token) {
28 has_message_pipes_ = true;
29 DCHECK(internal::g_core);
30 *token = GenerateRandomToken();
31 return internal::g_core->CreateParentMessagePipe(*token, process_token_);
32 }
33
34 void PendingProcessConnection::Connect(
35 base::ProcessHandle process,
36 ScopedPlatformHandle channel,
37 const ProcessErrorCallback& error_callback) {
38 // It's now safe to avoid cleanup in the destructor, as the lifetime of any
39 // associated resources is effectively bound to the |channel| passed to
40 // AddChild() below.
41 DCHECK(!connected_);
42 connected_ = true;
43
44 DCHECK(internal::g_core);
45 internal::g_core->AddChild(process, std::move(channel), process_token_,
46 error_callback);
47 }
48
49 } // namespace edk
50 } // namespace mojo
OLDNEW
« 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