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

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

Issue 1483823004: EDK: Move {platform_handle,scoped_platform_handle}.* to //mojo/edk/platform. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years 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 <functional> 8 #include <functional>
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
11 11
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "mojo/edk/embedder/channel_info_forward.h" 13 #include "mojo/edk/embedder/channel_info_forward.h"
14 #include "mojo/edk/embedder/process_type.h" 14 #include "mojo/edk/embedder/process_type.h"
15 #include "mojo/edk/embedder/scoped_platform_handle.h"
16 #include "mojo/edk/embedder/slave_info.h" 15 #include "mojo/edk/embedder/slave_info.h"
16 #include "mojo/edk/platform/scoped_platform_handle.h"
17 #include "mojo/edk/platform/task_runner.h" 17 #include "mojo/edk/platform/task_runner.h"
18 #include "mojo/public/cpp/system/message_pipe.h" 18 #include "mojo/public/cpp/system/message_pipe.h"
19 19
20 namespace mojo { 20 namespace mojo {
21 namespace embedder { 21 namespace embedder {
22 22
23 struct Configuration; 23 struct Configuration;
24 class PlatformSupport; 24 class PlatformSupport;
25 class ProcessDelegate; 25 class ProcessDelegate;
26 26
(...skipping 22 matching lines...) Expand all
49 MojoResult AsyncWait(MojoHandle handle, 49 MojoResult AsyncWait(MojoHandle handle,
50 MojoHandleSignals signals, 50 MojoHandleSignals signals,
51 const std::function<void(MojoResult)>& callback); 51 const std::function<void(MojoResult)>& callback);
52 52
53 // Creates a |MojoHandle| that wraps the given |PlatformHandle| (taking 53 // Creates a |MojoHandle| that wraps the given |PlatformHandle| (taking
54 // ownership of it). This |MojoHandle| can then, e.g., be passed through message 54 // ownership of it). This |MojoHandle| can then, e.g., be passed through message
55 // pipes. Note: This takes ownership (and thus closes) |platform_handle| even on 55 // pipes. Note: This takes ownership (and thus closes) |platform_handle| even on
56 // failure, which is different from what you'd expect from a Mojo API, but it 56 // failure, which is different from what you'd expect from a Mojo API, but it
57 // makes for a more convenient embedder API. 57 // makes for a more convenient embedder API.
58 MojoResult CreatePlatformHandleWrapper( 58 MojoResult CreatePlatformHandleWrapper(
59 ScopedPlatformHandle platform_handle, 59 platform::ScopedPlatformHandle platform_handle,
60 MojoHandle* platform_handle_wrapper_handle); 60 MojoHandle* platform_handle_wrapper_handle);
61 61
62 // Retrieves the |PlatformHandle| that was wrapped into a |MojoHandle| (using 62 // Retrieves the |PlatformHandle| that was wrapped into a |MojoHandle| (using
63 // |CreatePlatformHandleWrapper()| above). Note that the |MojoHandle| must still 63 // |CreatePlatformHandleWrapper()| above). Note that the |MojoHandle| must still
64 // be closed separately. 64 // be closed separately.
65 MojoResult PassWrappedPlatformHandle(MojoHandle platform_handle_wrapper_handle, 65 MojoResult PassWrappedPlatformHandle(
66 ScopedPlatformHandle* platform_handle); 66 MojoHandle platform_handle_wrapper_handle,
67 platform::ScopedPlatformHandle* platform_handle);
67 68
68 // Initialialization/shutdown for interprocess communication (IPC) ------------- 69 // Initialialization/shutdown for interprocess communication (IPC) -------------
69 70
70 // |InitIPCSupport()| sets up the subsystem for interprocess communication, 71 // |InitIPCSupport()| sets up the subsystem for interprocess communication,
71 // making the IPC functions (in the following section) available and functional. 72 // making the IPC functions (in the following section) available and functional.
72 // (This may only be done after |Init()|.) 73 // (This may only be done after |Init()|.)
73 // 74 //
74 // This subsystem may be shut down, using |ShutdownIPCSupportOnIOThread()| or 75 // This subsystem may be shut down, using |ShutdownIPCSupportOnIOThread()| or
75 // |ShutdownIPCSupport()|. None of the IPC functions may be called while or 76 // |ShutdownIPCSupport()|. None of the IPC functions may be called while or
76 // after either of these is called. 77 // after either of these is called.
77 78
78 // Initializes a process of the given type; to be called after |Init()|. 79 // Initializes a process of the given type; to be called after |Init()|.
79 // - |process_delegate| must be a process delegate of the appropriate type 80 // - |process_delegate| must be a process delegate of the appropriate type
80 // corresponding to |process_type|; its methods will be called on 81 // corresponding to |process_type|; its methods will be called on
81 // |delegate_thread_task_runner|. 82 // |delegate_thread_task_runner|.
82 // - |delegate_thread_task_runner|, |process_delegate|, and 83 // - |delegate_thread_task_runner|, |process_delegate|, and
83 // |io_thread_task_runner| should live at least until 84 // |io_thread_task_runner| should live at least until
84 // |ShutdownIPCSupport()|'s callback has been run or 85 // |ShutdownIPCSupport()|'s callback has been run or
85 // |ShutdownIPCSupportOnIOThread()| has completed. 86 // |ShutdownIPCSupportOnIOThread()| has completed.
86 // - For slave processes (i.e., |process_type| is |ProcessType::SLAVE|), 87 // - For slave processes (i.e., |process_type| is |ProcessType::SLAVE|),
87 // |platform_handle| should be connected to the handle passed to 88 // |platform_handle| should be connected to the handle passed to
88 // |ConnectToSlave()| (in the master process). For other processes, 89 // |ConnectToSlave()| (in the master process). For other processes,
89 // |platform_handle| is ignored (and should not be valid). 90 // |platform_handle| is ignored (and should not be valid).
90 void InitIPCSupport( 91 void InitIPCSupport(
91 ProcessType process_type, 92 ProcessType process_type,
92 util::RefPtr<platform::TaskRunner>&& delegate_thread_task_runner, 93 util::RefPtr<platform::TaskRunner>&& delegate_thread_task_runner,
93 ProcessDelegate* process_delegate, 94 ProcessDelegate* process_delegate,
94 util::RefPtr<platform::TaskRunner>&& io_thread_task_runner, 95 util::RefPtr<platform::TaskRunner>&& io_thread_task_runner,
95 ScopedPlatformHandle platform_handle); 96 platform::ScopedPlatformHandle platform_handle);
96 97
97 // Shuts down the subsystem initialized by |InitIPCSupport()|. This must be 98 // Shuts down the subsystem initialized by |InitIPCSupport()|. This must be
98 // called on the I/O thread (given to |InitIPCSupport()|). This completes 99 // called on the I/O thread (given to |InitIPCSupport()|). This completes
99 // synchronously and does not result in a call to the process delegate's 100 // synchronously and does not result in a call to the process delegate's
100 // |OnShutdownComplete()|. 101 // |OnShutdownComplete()|.
101 void ShutdownIPCSupportOnIOThread(); 102 void ShutdownIPCSupportOnIOThread();
102 103
103 // Like |ShutdownIPCSupportOnIOThread()|, but may be called from any thread, 104 // Like |ShutdownIPCSupportOnIOThread()|, but may be called from any thread,
104 // signaling shutdown completion via the process delegate's 105 // signaling shutdown completion via the process delegate's
105 // |OnShutdownComplete()|. 106 // |OnShutdownComplete()|.
(...skipping 17 matching lines...) Expand all
123 // |DestroyChannel()|/|DestroyChannelOnIOThread()|, but only after 124 // |DestroyChannel()|/|DestroyChannelOnIOThread()|, but only after
124 // |did_connect_to_slave_callback| has been run. 125 // |did_connect_to_slave_callback| has been run.
125 // 126 //
126 // |did_connect_to_slave_callback| will be run either using 127 // |did_connect_to_slave_callback| will be run either using
127 // |did_connect_to_slave_runner| (if non-null) or on the I/O thread, once the 128 // |did_connect_to_slave_runner| (if non-null) or on the I/O thread, once the
128 // |ChannelInfo*| is valid. 129 // |ChannelInfo*| is valid.
129 // 130 //
130 // TODO(vtl): The API is a little crazy with respect to the |ChannelInfo*|. 131 // TODO(vtl): The API is a little crazy with respect to the |ChannelInfo*|.
131 ScopedMessagePipeHandle ConnectToSlave( 132 ScopedMessagePipeHandle ConnectToSlave(
132 SlaveInfo slave_info, 133 SlaveInfo slave_info,
133 ScopedPlatformHandle platform_handle, 134 platform::ScopedPlatformHandle platform_handle,
134 const base::Closure& did_connect_to_slave_callback, 135 const base::Closure& did_connect_to_slave_callback,
135 util::RefPtr<platform::TaskRunner>&& did_connect_to_slave_runner, 136 util::RefPtr<platform::TaskRunner>&& did_connect_to_slave_runner,
136 std::string* platform_connection_id, 137 std::string* platform_connection_id,
137 ChannelInfo** channel_info); 138 ChannelInfo** channel_info);
138 139
139 // Called in a slave process to connect it to the IPC system. (This should only 140 // Called in a slave process to connect it to the IPC system. (This should only
140 // be called in a process initialized (using |InitIPCSupport()|) with process 141 // be called in a process initialized (using |InitIPCSupport()|) with process
141 // type |ProcessType::SLAVE|.) This should be called exactly once in each slave 142 // type |ProcessType::SLAVE|.) This should be called exactly once in each slave
142 // process. 143 // process.
143 // 144 //
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 // first synchronously and second asynchronously. 187 // first synchronously and second asynchronously.
187 // 188 //
188 // The destruction functions are similarly synchronous and asynchronous, 189 // The destruction functions are similarly synchronous and asynchronous,
189 // respectively, and take the |ChannelInfo*| produced by the creation functions. 190 // respectively, and take the |ChannelInfo*| produced by the creation functions.
190 191
191 // Creates a channel; must only be called from the I/O thread. |platform_handle| 192 // Creates a channel; must only be called from the I/O thread. |platform_handle|
192 // should be a handle to a connected OS "pipe". Eventually (even on failure), 193 // should be a handle to a connected OS "pipe". Eventually (even on failure),
193 // the "out" value |*channel_info| should be passed to |DestoryChannel()| to 194 // the "out" value |*channel_info| should be passed to |DestoryChannel()| to
194 // tear down the channel. Returns a handle to the bootstrap message pipe. 195 // tear down the channel. Returns a handle to the bootstrap message pipe.
195 ScopedMessagePipeHandle CreateChannelOnIOThread( 196 ScopedMessagePipeHandle CreateChannelOnIOThread(
196 ScopedPlatformHandle platform_handle, 197 platform::ScopedPlatformHandle platform_handle,
197 ChannelInfo** channel_info); 198 ChannelInfo** channel_info);
198 199
199 // Creates a channel asynchronously; may be called from any thread. 200 // Creates a channel asynchronously; may be called from any thread.
200 // |platform_handle| should be a handle to a connected OS "pipe". 201 // |platform_handle| should be a handle to a connected OS "pipe".
201 // |did_create_channel_callback| should be the callback to call with the 202 // |did_create_channel_callback| should be the callback to call with the
202 // |ChannelInfo*|, which should eventually be passed to |DestroyChannel()| to 203 // |ChannelInfo*|, which should eventually be passed to |DestroyChannel()| to
203 // tear down the channel; the callback will be called using 204 // tear down the channel; the callback will be called using
204 // |did_create_channel_runner| if that is non-null, or otherwise it will be 205 // |did_create_channel_runner| if that is non-null, or otherwise it will be
205 // posted to the I/O thread. Returns a handle to the bootstrap message pipe. 206 // posted to the I/O thread. Returns a handle to the bootstrap message pipe.
206 // 207 //
207 // Note: This should only be used to establish a channel with a process of type 208 // Note: This should only be used to establish a channel with a process of type
208 // |ProcessType::NONE|. This function may be removed in the future. 209 // |ProcessType::NONE|. This function may be removed in the future.
209 ScopedMessagePipeHandle CreateChannel( 210 ScopedMessagePipeHandle CreateChannel(
210 ScopedPlatformHandle platform_handle, 211 platform::ScopedPlatformHandle platform_handle,
211 const base::Callback<void(ChannelInfo*)>& did_create_channel_callback, 212 const base::Callback<void(ChannelInfo*)>& did_create_channel_callback,
212 util::RefPtr<platform::TaskRunner>&& did_create_channel_runner); 213 util::RefPtr<platform::TaskRunner>&& did_create_channel_runner);
213 214
214 // Destroys a channel that was created using |ConnectToMaster()|, 215 // Destroys a channel that was created using |ConnectToMaster()|,
215 // |ConnectToSlave()|, |CreateChannel()|, or |CreateChannelOnIOThread()|; must 216 // |ConnectToSlave()|, |CreateChannel()|, or |CreateChannelOnIOThread()|; must
216 // be called from the channel's I'O thread. Completes synchronously (and posts 217 // be called from the channel's I'O thread. Completes synchronously (and posts
217 // no tasks). 218 // no tasks).
218 void DestroyChannelOnIOThread(ChannelInfo* channel_info); 219 void DestroyChannelOnIOThread(ChannelInfo* channel_info);
219 220
220 // Like |DestroyChannelOnIOThread()|, but asynchronous and may be called from 221 // Like |DestroyChannelOnIOThread()|, but asynchronous and may be called from
221 // any thread. The callback will be called using |did_destroy_channel_runner| 222 // any thread. The callback will be called using |did_destroy_channel_runner|
222 // if that is non-null, or otherwise it will be called on the "channel thread". 223 // if that is non-null, or otherwise it will be called on the "channel thread".
223 // The "channel thread" must remain alive and continue to process tasks until 224 // The "channel thread" must remain alive and continue to process tasks until
224 // the callback has been executed. 225 // the callback has been executed.
225 void DestroyChannel( 226 void DestroyChannel(
226 ChannelInfo* channel_info, 227 ChannelInfo* channel_info,
227 const base::Closure& did_destroy_channel_callback, 228 const base::Closure& did_destroy_channel_callback,
228 util::RefPtr<platform::TaskRunner>&& did_destroy_channel_runner); 229 util::RefPtr<platform::TaskRunner>&& did_destroy_channel_runner);
229 230
230 // Inform the channel that it will soon be destroyed (doing so is optional). 231 // Inform the channel that it will soon be destroyed (doing so is optional).
231 // This may be called from any thread, but the caller must ensure that this is 232 // This may be called from any thread, but the caller must ensure that this is
232 // called before |DestroyChannel()|. 233 // called before |DestroyChannel()|.
233 void WillDestroyChannelSoon(ChannelInfo* channel_info); 234 void WillDestroyChannelSoon(ChannelInfo* channel_info);
234 235
235 } // namespace embedder 236 } // namespace embedder
236 } // namespace mojo 237 } // namespace mojo
237 238
238 #endif // MOJO_EDK_EMBEDDER_EMBEDDER_H_ 239 #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