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

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 (!connected_) {
21 DCHECK(internal::g_core);
22 internal::g_core->ChildLaunchFailed(process_token_);
23 }
24 }
25
26 ScopedMessagePipeHandle PendingProcessConnection::CreateMessagePipe(
27 std::string* token) const {
28 DCHECK(internal::g_core);
29 *token = GenerateRandomToken();
30 return internal::g_core->CreateParentMessagePipe(*token, process_token_);
31 }
32
33 void PendingProcessConnection::Connect(
34 base::ProcessHandle process,
35 ScopedPlatformHandle channel,
36 const ProcessErrorCallback& error_callback) {
37 // It's now safe to avoid cleanup in the destructor, as the lifetime of any
38 // associated resources is effectively bound to the |channel| passed to
39 // AddChild() below.
40 DCHECK(!connected_);
41 connected_ = true;
42
43 DCHECK(internal::g_core);
44 internal::g_core->AddChild(process, std::move(channel), process_token_,
45 error_callback);
46 }
47
48 } // namespace edk
49 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698