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 "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 // respectively, and take the |ChannelInfo*| produced by the creation functions. | 64 // respectively, and take the |ChannelInfo*| produced by the creation functions. |
65 // | 65 // |
66 // TODO(vtl): Figure out channel teardown. | 66 // TODO(vtl): Figure out channel teardown. |
67 | 67 |
68 // Creates a channel; must only be called from the I/O thread. |platform_handle| | 68 // Creates a channel; must only be called from the I/O thread. |platform_handle| |
69 // should be a handle to a connected OS "pipe". Eventually (even on failure), | 69 // should be a handle to a connected OS "pipe". Eventually (even on failure), |
70 // the "out" value |*channel_info| should be passed to | 70 // the "out" value |*channel_info| should be passed to |
71 // |DestroyChannelOnIOThread()| (or |DestoryChannel()|) to tear down the | 71 // |DestroyChannelOnIOThread()| (or |DestoryChannel()|) to tear down the |
72 // channel. Returns a handle to the bootstrap message pipe. | 72 // channel. Returns a handle to the bootstrap message pipe. |
73 MOJO_SYSTEM_IMPL_EXPORT ScopedMessagePipeHandle | 73 MOJO_SYSTEM_IMPL_EXPORT ScopedMessagePipeHandle |
74 CreateChannelOnIOThread(ScopedPlatformHandle platform_handle, | 74 CreateChannelOnIOThread(ScopedPlatformHandle platform_handle, |
75 ChannelInfo** channel_info); | 75 ChannelInfo** channel_info); |
76 | 76 |
77 typedef base::Callback<void(ChannelInfo*)> DidCreateChannelCallback; | 77 typedef base::Callback<void(ChannelInfo*)> DidCreateChannelCallback; |
78 // Creates a channel asynchronously; may be called from any thread. | 78 // Creates a channel asynchronously; may be called from any thread. |
79 // |platform_handle| should be a handle to a connected OS "pipe". | 79 // |platform_handle| should be a handle to a connected OS "pipe". |
80 // |io_thread_task_runner| should be the |TaskRunner| for the I/O thread. | 80 // |io_thread_task_runner| should be the |TaskRunner| for the I/O thread. |
81 // |callback| should be the callback to call with the |ChannelInfo*|, which | 81 // |callback| should be the callback to call with the |ChannelInfo*|, which |
82 // should eventually be passed to |DestroyChannel()| (or | 82 // should eventually be passed to |DestroyChannel()| (or |
83 // |DestroyChannelOnIOThread()|) to tear down the channel; the callback will be | 83 // |DestroyChannelOnIOThread()|) to tear down the channel; the callback will be |
84 // called using |callback_thread_task_runner| if that is non-null, or otherwise | 84 // called using |callback_thread_task_runner| if that is non-null, or otherwise |
85 // it will be called using |io_thread_task_runner|. Returns a handle to the | 85 // it will be called using |io_thread_task_runner|. Returns a handle to the |
86 // bootstrap message pipe. | 86 // bootstrap message pipe. |
87 MOJO_SYSTEM_IMPL_EXPORT ScopedMessagePipeHandle | 87 MOJO_SYSTEM_IMPL_EXPORT ScopedMessagePipeHandle |
88 CreateChannel(ScopedPlatformHandle platform_handle, | 88 CreateChannel(ScopedPlatformHandle platform_handle, |
89 scoped_refptr<base::TaskRunner> io_thread_task_runner, | 89 scoped_refptr<base::TaskRunner> io_thread_task_runner, |
90 DidCreateChannelCallback callback, | 90 DidCreateChannelCallback callback, |
91 scoped_refptr<base::TaskRunner> callback_thread_task_runner); | 91 scoped_refptr<base::TaskRunner> callback_thread_task_runner); |
92 | 92 |
93 // Destroys a channel that was created using either |CreateChannelOnIOThread()| | 93 // Destroys a channel that was created using either |CreateChannelOnIOThread()| |
94 // or |CreateChannel()|; must only be called from the I/O thread. |channel_info| | 94 // or |CreateChannel()|; must only be called from the I/O thread. |channel_info| |
95 // should be the "out" value from |CreateChannelOnIOThread()| or the value | 95 // should be the "out" value from |CreateChannelOnIOThread()| or the value |
96 // provided to the callback to |CreateChannel()|. | 96 // provided to the callback to |CreateChannel()|. |
97 MOJO_SYSTEM_IMPL_EXPORT void DestroyChannelOnIOThread( | 97 MOJO_SYSTEM_IMPL_EXPORT void DestroyChannelOnIOThread( |
98 ChannelInfo* channel_info); | 98 ChannelInfo* channel_info); |
99 | 99 |
100 // Destroys a channel (asynchronously) that was created using |CreateChannel()|; | 100 // Destroys a channel (asynchronously) that was created using |CreateChannel()|; |
101 // may be called from any thread. |channel_info| should be the value provided to | 101 // may be called from any thread. |channel_info| should be the value provided to |
102 // the callback to |CreateChannel()|. | 102 // the callback to |CreateChannel()|. |
103 MOJO_SYSTEM_IMPL_EXPORT void DestroyChannel(ChannelInfo* channel_info); | 103 MOJO_SYSTEM_IMPL_EXPORT void DestroyChannel(ChannelInfo* channel_info); |
104 | 104 |
105 // Inform the channel that it will soon be destroyed (doing so is optional). | 105 // Inform the channel that it will soon be destroyed (doing so is optional). |
106 // This may be called from any thread, but the caller must ensure that this is | 106 // This may be called from any thread, but the caller must ensure that this is |
107 // called before |DestroyChannel()| or |DestroyChannelOnIOThread()|. | 107 // called before |DestroyChannel()| or |DestroyChannelOnIOThread()|. |
108 MOJO_SYSTEM_IMPL_EXPORT void WillDestroyChannelSoon(ChannelInfo* channel_info); | 108 MOJO_SYSTEM_IMPL_EXPORT void WillDestroyChannelSoon(ChannelInfo* channel_info); |
109 | 109 |
110 // Creates a |MojoHandle| that wraps the given |PlatformHandle| (taking | 110 // Creates a |MojoHandle| that wraps the given |PlatformHandle| (taking |
111 // ownership of it). This |MojoHandle| can then, e.g., be passed through message | 111 // ownership of it). This |MojoHandle| can then, e.g., be passed through message |
112 // pipes. Note: This takes ownership (and thus closes) |platform_handle| even on | 112 // pipes. Note: This takes ownership (and thus closes) |platform_handle| even on |
113 // failure, which is different from what you'd expect from a Mojo API, but it | 113 // failure, which is different from what you'd expect from a Mojo API, but it |
114 // makes for a more convenient embedder API. | 114 // makes for a more convenient embedder API. |
115 MOJO_SYSTEM_IMPL_EXPORT MojoResult | 115 MOJO_SYSTEM_IMPL_EXPORT MojoResult |
116 CreatePlatformHandleWrapper(ScopedPlatformHandle platform_handle, | 116 CreatePlatformHandleWrapper(ScopedPlatformHandle platform_handle, |
117 MojoHandle* platform_handle_wrapper_handle); | 117 MojoHandle* platform_handle_wrapper_handle); |
118 // Retrieves the |PlatformHandle| that was wrapped into a |MojoHandle| (using | 118 // Retrieves the |PlatformHandle| that was wrapped into a |MojoHandle| (using |
119 // |CreatePlatformHandleWrapper()| above). Note that the |MojoHandle| must still | 119 // |CreatePlatformHandleWrapper()| above). Note that the |MojoHandle| must still |
120 // be closed separately. | 120 // be closed separately. |
121 MOJO_SYSTEM_IMPL_EXPORT MojoResult | 121 MOJO_SYSTEM_IMPL_EXPORT MojoResult |
122 PassWrappedPlatformHandle(MojoHandle platform_handle_wrapper_handle, | 122 PassWrappedPlatformHandle(MojoHandle platform_handle_wrapper_handle, |
123 ScopedPlatformHandle* platform_handle); | 123 ScopedPlatformHandle* platform_handle); |
124 | 124 |
125 } // namespace embedder | 125 } // namespace embedder |
126 } // namespace mojo | 126 } // namespace mojo |
127 | 127 |
128 #endif // MOJO_EDK_EMBEDDER_EMBEDDER_H_ | 128 #endif // MOJO_EDK_EMBEDDER_EMBEDDER_H_ |
OLD | NEW |