OLD | NEW |
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/platform_task_runner.h" | |
15 #include "mojo/edk/embedder/process_type.h" | 14 #include "mojo/edk/embedder/process_type.h" |
16 #include "mojo/edk/embedder/scoped_platform_handle.h" | 15 #include "mojo/edk/embedder/scoped_platform_handle.h" |
17 #include "mojo/edk/embedder/slave_info.h" | 16 #include "mojo/edk/embedder/slave_info.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 |
27 // Basic configuration/initialization ------------------------------------------ | 27 // Basic configuration/initialization ------------------------------------------ |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 // - |delegate_thread_task_runner|, |process_delegate|, and | 82 // - |delegate_thread_task_runner|, |process_delegate|, and |
83 // |io_thread_task_runner| should live at least until | 83 // |io_thread_task_runner| should live at least until |
84 // |ShutdownIPCSupport()|'s callback has been run or | 84 // |ShutdownIPCSupport()|'s callback has been run or |
85 // |ShutdownIPCSupportOnIOThread()| has completed. | 85 // |ShutdownIPCSupportOnIOThread()| has completed. |
86 // - For slave processes (i.e., |process_type| is |ProcessType::SLAVE|), | 86 // - For slave processes (i.e., |process_type| is |ProcessType::SLAVE|), |
87 // |platform_handle| should be connected to the handle passed to | 87 // |platform_handle| should be connected to the handle passed to |
88 // |ConnectToSlave()| (in the master process). For other processes, | 88 // |ConnectToSlave()| (in the master process). For other processes, |
89 // |platform_handle| is ignored (and should not be valid). | 89 // |platform_handle| is ignored (and should not be valid). |
90 void InitIPCSupport( | 90 void InitIPCSupport( |
91 ProcessType process_type, | 91 ProcessType process_type, |
92 util::RefPtr<PlatformTaskRunner>&& delegate_thread_task_runner, | 92 util::RefPtr<platform::TaskRunner>&& delegate_thread_task_runner, |
93 ProcessDelegate* process_delegate, | 93 ProcessDelegate* process_delegate, |
94 util::RefPtr<PlatformTaskRunner>&& io_thread_task_runner, | 94 util::RefPtr<platform::TaskRunner>&& io_thread_task_runner, |
95 ScopedPlatformHandle platform_handle); | 95 ScopedPlatformHandle platform_handle); |
96 | 96 |
97 // Shuts down the subsystem initialized by |InitIPCSupport()|. This must be | 97 // Shuts down the subsystem initialized by |InitIPCSupport()|. This must be |
98 // called on the I/O thread (given to |InitIPCSupport()|). This completes | 98 // 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 | 99 // synchronously and does not result in a call to the process delegate's |
100 // |OnShutdownComplete()|. | 100 // |OnShutdownComplete()|. |
101 void ShutdownIPCSupportOnIOThread(); | 101 void ShutdownIPCSupportOnIOThread(); |
102 | 102 |
103 // Like |ShutdownIPCSupportOnIOThread()|, but may be called from any thread, | 103 // Like |ShutdownIPCSupportOnIOThread()|, but may be called from any thread, |
104 // signaling shutdown completion via the process delegate's | 104 // signaling shutdown completion via the process delegate's |
(...skipping 20 matching lines...) Expand all Loading... |
125 // | 125 // |
126 // |did_connect_to_slave_callback| will be run either using | 126 // |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 | 127 // |did_connect_to_slave_runner| (if non-null) or on the I/O thread, once the |
128 // |ChannelInfo*| is valid. | 128 // |ChannelInfo*| is valid. |
129 // | 129 // |
130 // TODO(vtl): The API is a little crazy with respect to the |ChannelInfo*|. | 130 // TODO(vtl): The API is a little crazy with respect to the |ChannelInfo*|. |
131 ScopedMessagePipeHandle ConnectToSlave( | 131 ScopedMessagePipeHandle ConnectToSlave( |
132 SlaveInfo slave_info, | 132 SlaveInfo slave_info, |
133 ScopedPlatformHandle platform_handle, | 133 ScopedPlatformHandle platform_handle, |
134 const base::Closure& did_connect_to_slave_callback, | 134 const base::Closure& did_connect_to_slave_callback, |
135 util::RefPtr<PlatformTaskRunner>&& did_connect_to_slave_runner, | 135 util::RefPtr<platform::TaskRunner>&& did_connect_to_slave_runner, |
136 std::string* platform_connection_id, | 136 std::string* platform_connection_id, |
137 ChannelInfo** channel_info); | 137 ChannelInfo** channel_info); |
138 | 138 |
139 // Called in a slave process to connect it to the IPC system. (This should only | 139 // 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 | 140 // be called in a process initialized (using |InitIPCSupport()|) with process |
141 // type |ProcessType::SLAVE|.) This should be called exactly once in each slave | 141 // type |ProcessType::SLAVE|.) This should be called exactly once in each slave |
142 // process. | 142 // process. |
143 // | 143 // |
144 // See |ConnectToSlave()| for details. (Note that if this fails in any way, | 144 // See |ConnectToSlave()| for details. (Note that if this fails in any way, |
145 // e.g., if |platform_connection_id| is invalid, this will CHECK-fail and | 145 // e.g., if |platform_connection_id| is invalid, this will CHECK-fail and |
146 // terminate the process.) |channel_info|, |did_connect_to_master_callback|, and | 146 // terminate the process.) |channel_info|, |did_connect_to_master_callback|, and |
147 // |did_connect_to_master_runner| are analagous to in |ConnectToSlave()|. | 147 // |did_connect_to_master_runner| are analagous to in |ConnectToSlave()|. |
148 // | 148 // |
149 // TODO(vtl): The API is a little crazy with respect to the |ChannelInfo*|. | 149 // TODO(vtl): The API is a little crazy with respect to the |ChannelInfo*|. |
150 ScopedMessagePipeHandle ConnectToMaster( | 150 ScopedMessagePipeHandle ConnectToMaster( |
151 const std::string& platform_connection_id, | 151 const std::string& platform_connection_id, |
152 const base::Closure& did_connect_to_master_callback, | 152 const base::Closure& did_connect_to_master_callback, |
153 util::RefPtr<PlatformTaskRunner>&& did_connect_to_master_runner, | 153 util::RefPtr<platform::TaskRunner>&& did_connect_to_master_runner, |
154 ChannelInfo** channel_info); | 154 ChannelInfo** channel_info); |
155 | 155 |
156 // A "channel" is a connection on top of an OS "pipe", on top of which Mojo | 156 // A "channel" is a connection on top of an OS "pipe", on top of which Mojo |
157 // message pipes (etc.) can be multiplexed. It must "live" on some I/O thread. | 157 // message pipes (etc.) can be multiplexed. It must "live" on some I/O thread. |
158 // | 158 // |
159 // There are two channel creation APIs: |CreateChannelOnIOThread()| creates a | 159 // There are two channel creation APIs: |CreateChannelOnIOThread()| creates a |
160 // channel synchronously and must be called from the I/O thread, while | 160 // channel synchronously and must be called from the I/O thread, while |
161 // |CreateChannel()| is asynchronous and may be called from any thread. | 161 // |CreateChannel()| is asynchronous and may be called from any thread. |
162 // |DestroyChannel()| is used to destroy the channel in either case and may be | 162 // |DestroyChannel()| is used to destroy the channel in either case and may be |
163 // called from any thread, but completes synchronously when called from the I/O | 163 // called from any thread, but completes synchronously when called from the I/O |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 // |ChannelInfo*|, which should eventually be passed to |DestroyChannel()| to | 202 // |ChannelInfo*|, which should eventually be passed to |DestroyChannel()| to |
203 // tear down the channel; the callback will be called using | 203 // 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 | 204 // |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. | 205 // posted to the I/O thread. Returns a handle to the bootstrap message pipe. |
206 // | 206 // |
207 // Note: This should only be used to establish a channel with a process of type | 207 // 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. | 208 // |ProcessType::NONE|. This function may be removed in the future. |
209 ScopedMessagePipeHandle CreateChannel( | 209 ScopedMessagePipeHandle CreateChannel( |
210 ScopedPlatformHandle platform_handle, | 210 ScopedPlatformHandle platform_handle, |
211 const base::Callback<void(ChannelInfo*)>& did_create_channel_callback, | 211 const base::Callback<void(ChannelInfo*)>& did_create_channel_callback, |
212 util::RefPtr<PlatformTaskRunner>&& did_create_channel_runner); | 212 util::RefPtr<platform::TaskRunner>&& did_create_channel_runner); |
213 | 213 |
214 // Destroys a channel that was created using |ConnectToMaster()|, | 214 // Destroys a channel that was created using |ConnectToMaster()|, |
215 // |ConnectToSlave()|, |CreateChannel()|, or |CreateChannelOnIOThread()|; must | 215 // |ConnectToSlave()|, |CreateChannel()|, or |CreateChannelOnIOThread()|; must |
216 // be called from the channel's I'O thread. Completes synchronously (and posts | 216 // be called from the channel's I'O thread. Completes synchronously (and posts |
217 // no tasks). | 217 // no tasks). |
218 void DestroyChannelOnIOThread(ChannelInfo* channel_info); | 218 void DestroyChannelOnIOThread(ChannelInfo* channel_info); |
219 | 219 |
220 // Like |DestroyChannelOnIOThread()|, but asynchronous and may be called from | 220 // Like |DestroyChannelOnIOThread()|, but asynchronous and may be called from |
221 // any thread. The callback will be called using |did_destroy_channel_runner| | 221 // 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". | 222 // 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 | 223 // The "channel thread" must remain alive and continue to process tasks until |
224 // the callback has been executed. | 224 // the callback has been executed. |
225 void DestroyChannel( | 225 void DestroyChannel( |
226 ChannelInfo* channel_info, | 226 ChannelInfo* channel_info, |
227 const base::Closure& did_destroy_channel_callback, | 227 const base::Closure& did_destroy_channel_callback, |
228 util::RefPtr<PlatformTaskRunner>&& did_destroy_channel_runner); | 228 util::RefPtr<platform::TaskRunner>&& did_destroy_channel_runner); |
229 | 229 |
230 // Inform the channel that it will soon be destroyed (doing so is optional). | 230 // 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 | 231 // This may be called from any thread, but the caller must ensure that this is |
232 // called before |DestroyChannel()|. | 232 // called before |DestroyChannel()|. |
233 void WillDestroyChannelSoon(ChannelInfo* channel_info); | 233 void WillDestroyChannelSoon(ChannelInfo* channel_info); |
234 | 234 |
235 } // namespace embedder | 235 } // namespace embedder |
236 } // namespace mojo | 236 } // namespace mojo |
237 | 237 |
238 #endif // MOJO_EDK_EMBEDDER_EMBEDDER_H_ | 238 #endif // MOJO_EDK_EMBEDDER_EMBEDDER_H_ |
OLD | NEW |