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

Side by Side Diff: mojo/edk/embedder/embedder.h

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
« no previous file with comments | « mojo/edk/embedder/BUILD.gn ('k') | mojo/edk/embedder/embedder.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MOJO_EDK_EMBEDDER_EMBEDDER_H_ 5 #ifndef MOJO_EDK_EMBEDDER_EMBEDDER_H_
6 #define MOJO_EDK_EMBEDDER_EMBEDDER_H_ 6 #define MOJO_EDK_EMBEDDER_EMBEDDER_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <memory> 10 #include <memory>
11 #include <string> 11 #include <string>
12 12
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "base/memory/shared_memory_handle.h" 16 #include "base/memory/shared_memory_handle.h"
17 #include "base/process/process_handle.h" 17 #include "base/process/process_handle.h"
18 #include "base/task_runner.h" 18 #include "base/task_runner.h"
19 #include "mojo/edk/embedder/pending_process_connection.h"
19 #include "mojo/edk/embedder/scoped_platform_handle.h" 20 #include "mojo/edk/embedder/scoped_platform_handle.h"
20 #include "mojo/edk/system/system_impl_export.h" 21 #include "mojo/edk/system/system_impl_export.h"
21 #include "mojo/public/cpp/system/message_pipe.h" 22 #include "mojo/public/cpp/system/message_pipe.h"
22 23
23 namespace base { 24 namespace base {
24 class PortProvider; 25 class PortProvider;
25 } 26 }
26 27
27 namespace mojo { 28 namespace mojo {
28 namespace edk { 29 namespace edk {
29 30
30 using ProcessErrorCallback = base::Callback<void(const std::string& error)>;
31
32 // Basic configuration/initialization ------------------------------------------ 31 // Basic configuration/initialization ------------------------------------------
33 32
34 // |Init()| sets up the basic Mojo system environment, making the |Mojo...()| 33 // |Init()| sets up the basic Mojo system environment, making the |Mojo...()|
35 // functions available and functional. This is never shut down (except in tests 34 // functions available and functional. This is never shut down (except in tests
36 // -- see test_embedder.h). 35 // -- see test_embedder.h).
37 36
38 // Allows changing the default max message size. Must be called before Init. 37 // Allows changing the default max message size. Must be called before Init.
39 MOJO_SYSTEM_IMPL_EXPORT void SetMaxMessageSize(size_t bytes); 38 MOJO_SYSTEM_IMPL_EXPORT void SetMaxMessageSize(size_t bytes);
40 39
41 // Called in the parent process for each child process that is launched. 40 // Should be called as early as possible in a child process with a handle to the
42 MOJO_SYSTEM_IMPL_EXPORT void ChildProcessLaunched( 41 // other end of a pipe provided in the parent to
43 base::ProcessHandle child_process, 42 // PendingProcessConnection::Connect.
44 ScopedPlatformHandle server_pipe,
45 const std::string& child_token);
46
47 // Called in the parent process for each child process that is launched.
48 // |process_error_callback| is called if the system becomes aware of some
49 // internal error related to this process, e.g., if the system is notified of a
50 // bad message from this process via the |MojoNotifyBadMessage()| API.
51 MOJO_SYSTEM_IMPL_EXPORT void ChildProcessLaunched(
52 base::ProcessHandle child_process,
53 ScopedPlatformHandle server_pipe,
54 const std::string& child_token,
55 const ProcessErrorCallback& error_callback);
56
57 // Called in the parent process when a child process fails to launch.
58 // Exactly one of ChildProcessLaunched() or ChildProcessLaunchFailed() must be
59 // called per child process launch attempt.
60 MOJO_SYSTEM_IMPL_EXPORT void ChildProcessLaunchFailed(
61 const std::string& child_token);
62
63 // Should be called as early as possible in the child process with the handle
64 // that the parent received from ChildProcessLaunched.
65 MOJO_SYSTEM_IMPL_EXPORT void SetParentPipeHandle(ScopedPlatformHandle pipe); 43 MOJO_SYSTEM_IMPL_EXPORT void SetParentPipeHandle(ScopedPlatformHandle pipe);
66 44
67 // Same as above but extracts the pipe handle from the command line. See 45 // Same as above but extracts the pipe handle from the command line. See
68 // PlatformChannelPair for details. 46 // PlatformChannelPair for details.
69 MOJO_SYSTEM_IMPL_EXPORT void SetParentPipeHandleFromCommandLine(); 47 MOJO_SYSTEM_IMPL_EXPORT void SetParentPipeHandleFromCommandLine();
70 48
71 // Called to connect to a peer process. This should be called only if there 49 // Called to connect to a peer process. This should be called only if there
72 // is no common ancestor for the processes involved within this mojo system. 50 // is no common ancestor for the processes involved within this mojo system.
73 // Both processes must call this function, each passing one end of a platform 51 // Both processes must call this function, each passing one end of a platform
74 // channel. This returns one end of a message pipe to each process. 52 // channel. This returns one end of a message pipe to each process.
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 // arbitrary thread. 141 // arbitrary thread.
164 MOJO_SYSTEM_IMPL_EXPORT void ShutdownIPCSupport(const base::Closure& callback); 142 MOJO_SYSTEM_IMPL_EXPORT void ShutdownIPCSupport(const base::Closure& callback);
165 143
166 #if defined(OS_MACOSX) && !defined(OS_IOS) 144 #if defined(OS_MACOSX) && !defined(OS_IOS)
167 // Set the |base::PortProvider| for this process. Can be called on any thread, 145 // Set the |base::PortProvider| for this process. Can be called on any thread,
168 // but must be set in the root process before any Mach ports can be transferred. 146 // but must be set in the root process before any Mach ports can be transferred.
169 MOJO_SYSTEM_IMPL_EXPORT void SetMachPortProvider( 147 MOJO_SYSTEM_IMPL_EXPORT void SetMachPortProvider(
170 base::PortProvider* port_provider); 148 base::PortProvider* port_provider);
171 #endif 149 #endif
172 150
173 // Creates a message pipe from a token. A child embedder must also have this 151 // Creates a message pipe from a token in a child process. This token must have
174 // token and call CreateChildMessagePipe() with it in order for the pipe to get 152 // been acquired by a corresponding call to
175 // connected. |child_token| identifies the child process and should be the same 153 // PendingProcessConnection::CreateMessagePipe.
176 // as the token passed into ChildProcessLaunched(). If they are different, the
177 // returned message pipe will not be signaled of peer closure if the child
178 // process dies before establishing connection to the pipe.
179 MOJO_SYSTEM_IMPL_EXPORT ScopedMessagePipeHandle
180 CreateParentMessagePipe(const std::string& token,
181 const std::string& child_token);
182
183 // Creates a message pipe from a token in a child process. The parent must also
184 // have this token and call CreateParentMessagePipe() with it in order for the
185 // pipe to get connected.
186 MOJO_SYSTEM_IMPL_EXPORT ScopedMessagePipeHandle 154 MOJO_SYSTEM_IMPL_EXPORT ScopedMessagePipeHandle
187 CreateChildMessagePipe(const std::string& token); 155 CreateChildMessagePipe(const std::string& token);
188 156
189 // Generates a random ASCII token string for use with CreateParentMessagePipe() 157 // Generates a random ASCII token string for use with various APIs that expect
190 // and CreateChildMessagePipe() above. The generated token is suitably random so 158 // a globally unique token string.
191 // as to not have to worry about collisions with other generated tokens.
192 MOJO_SYSTEM_IMPL_EXPORT std::string GenerateRandomToken(); 159 MOJO_SYSTEM_IMPL_EXPORT std::string GenerateRandomToken();
193 160
194 // Sets system properties that can be read by the MojoGetProperty() API. See the 161 // Sets system properties that can be read by the MojoGetProperty() API. See the
195 // documentation for MojoPropertyType for supported property types and their 162 // documentation for MojoPropertyType for supported property types and their
196 // corresponding value type. 163 // corresponding value type.
197 // 164 //
198 // Default property values: 165 // Default property values:
199 // |MOJO_PROPERTY_TYPE_SYNC_CALL_ALLOWED| - true 166 // |MOJO_PROPERTY_TYPE_SYNC_CALL_ALLOWED| - true
200 MOJO_SYSTEM_IMPL_EXPORT MojoResult SetProperty(MojoPropertyType type, 167 MOJO_SYSTEM_IMPL_EXPORT MojoResult SetProperty(MojoPropertyType type,
201 const void* value); 168 const void* value);
202 169
203 } // namespace edk 170 } // namespace edk
204 } // namespace mojo 171 } // namespace mojo
205 172
206 #endif // MOJO_EDK_EMBEDDER_EMBEDDER_H_ 173 #endif // MOJO_EDK_EMBEDDER_EMBEDDER_H_
OLDNEW
« no previous file with comments | « mojo/edk/embedder/BUILD.gn ('k') | mojo/edk/embedder/embedder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698