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

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

Issue 728613002: Make the embedder API use the ChannelManager. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: review comments Created 6 years, 1 month 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/channel_info_forward.h ('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 "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 14 matching lines...) Expand all
25 MOJO_SYSTEM_IMPL_EXPORT void Init(scoped_ptr<PlatformSupport> platform_support); 25 MOJO_SYSTEM_IMPL_EXPORT void Init(scoped_ptr<PlatformSupport> platform_support);
26 26
27 // Returns the global configuration. In general there should be no need to 27 // Returns the global configuration. In general there should be no need to
28 // change the configuration, but if you do so this must be done before calling 28 // change the configuration, but if you do so this must be done before calling
29 // |Init()|. 29 // |Init()|.
30 MOJO_SYSTEM_IMPL_EXPORT Configuration* GetConfiguration(); 30 MOJO_SYSTEM_IMPL_EXPORT Configuration* GetConfiguration();
31 31
32 // A "channel" is a connection on top of an OS "pipe", on top of which Mojo 32 // A "channel" is a connection on top of an OS "pipe", on top of which Mojo
33 // message pipes (etc.) can be multiplexed. It must "live" on some I/O thread. 33 // message pipes (etc.) can be multiplexed. It must "live" on some I/O thread.
34 // 34 //
35 // There are two "channel" creation/destruction APIs: the synchronous 35 // There are two channel creation APIs: |CreateChannelOnIOThread()| creates a
36 // |CreateChannelOnIOThread()|/|DestroyChannelOnIOThread()|, which must be 36 // channel synchronously and must be called from the I/O thread, while
37 // called from the I/O thread, and the asynchronous 37 // |CreateChannel()| is asynchronous and may be called from any thread.
38 // |CreateChannel()|/|DestroyChannel()|, which may be called from any thread. 38 // |DestroyChannel()| is used to destroy the channel in either case and may be
39 // called from any thread, but completes synchronously when called from the I/O
40 // thread.
39 // 41 //
40 // Both creation functions have a |platform_handle| argument, which should be an 42 // Both creation functions have a |platform_handle| argument, which should be an
41 // OS-dependent handle to one side of a suitable bidirectional OS "pipe" (e.g., 43 // OS-dependent handle to one side of a suitable bidirectional OS "pipe" (e.g.,
42 // a file descriptor to a socket on POSIX, a handle to a named pipe on Windows); 44 // a file descriptor to a socket on POSIX, a handle to a named pipe on Windows);
43 // this "pipe" should be connected and ready for operation (e.g., to be written 45 // this "pipe" should be connected and ready for operation (e.g., to be written
44 // to or read from). 46 // to or read from).
45 // 47 //
46 // Both (synchronously) return a handle to the bootstrap message pipe on the 48 // Both (synchronously) return a handle to the bootstrap message pipe on the
47 // channel that was (or is to be) created, or |MOJO_HANDLE_INVALID| on error 49 // channel that was (or is to be) created, or |MOJO_HANDLE_INVALID| on error
48 // (but note that this will happen only if, e.g., the handle table is full). 50 // (but note that this will happen only if, e.g., the handle table is full).
(...skipping 11 matching lines...) Expand all
60 // Both also produce a |ChannelInfo*| (a pointer to an opaque object) -- the 62 // Both also produce a |ChannelInfo*| (a pointer to an opaque object) -- the
61 // first synchronously and second asynchronously. 63 // first synchronously and second asynchronously.
62 // 64 //
63 // The destruction functions are similarly synchronous and asynchronous, 65 // The destruction functions are similarly synchronous and asynchronous,
64 // respectively, and take the |ChannelInfo*| produced by the creation functions. 66 // respectively, and take the |ChannelInfo*| produced by the creation functions.
65 // 67 //
66 // TODO(vtl): Figure out channel teardown. 68 // TODO(vtl): Figure out channel teardown.
67 69
68 // Creates a channel; must only be called from the I/O thread. |platform_handle| 70 // 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), 71 // should be a handle to a connected OS "pipe". Eventually (even on failure),
70 // the "out" value |*channel_info| should be passed to 72 // the "out" value |*channel_info| should be passed to |DestoryChannel()| to
71 // |DestroyChannelOnIOThread()| (or |DestoryChannel()|) to tear down the 73 // tear down the 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 74 MOJO_SYSTEM_IMPL_EXPORT ScopedMessagePipeHandle
74 CreateChannelOnIOThread(ScopedPlatformHandle platform_handle, 75 CreateChannelOnIOThread(ScopedPlatformHandle platform_handle,
75 ChannelInfo** channel_info); 76 ChannelInfo** channel_info);
76 77
77 typedef base::Callback<void(ChannelInfo*)> DidCreateChannelCallback; 78 typedef base::Callback<void(ChannelInfo*)> DidCreateChannelCallback;
78 // Creates a channel asynchronously; may be called from any thread. 79 // Creates a channel asynchronously; may be called from any thread.
79 // |platform_handle| should be a handle to a connected OS "pipe". 80 // |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. 81 // |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 82 // |callback| should be the callback to call with the |ChannelInfo*|, which
82 // should eventually be passed to |DestroyChannel()| (or 83 // should eventually be passed to |DestroyChannel()| to tear down the channel;
83 // |DestroyChannelOnIOThread()|) to tear down the channel; the callback will be 84 // the callback will be called using |callback_thread_task_runner| if that is
84 // called using |callback_thread_task_runner| if that is non-null, or otherwise 85 // non-null, or otherwise it will be called using |io_thread_task_runner|.
85 // it will be called using |io_thread_task_runner|. Returns a handle to the 86 // Returns a handle to the 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 |CreateChannel()|; may be called
yzshen1 2014/11/13 22:48:32 It seems nice if the comment also covers CreateCha
94 // or |CreateChannel()|; must only be called from the I/O thread. |channel_info| 94 // from any thread. |channel_info| should be the value provided to the callback
95 // should be the "out" value from |CreateChannelOnIOThread()| or the value 95 // to |CreateChannel()|. If called from the I/O thread, this will complete
96 // provided to the callback to |CreateChannel()|. 96 // synchronously (in particular, it will post no tasks).
97 MOJO_SYSTEM_IMPL_EXPORT void DestroyChannelOnIOThread(
98 ChannelInfo* channel_info);
99
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
102 // the callback to |CreateChannel()|.
103 MOJO_SYSTEM_IMPL_EXPORT void DestroyChannel(ChannelInfo* channel_info); 97 MOJO_SYSTEM_IMPL_EXPORT void DestroyChannel(ChannelInfo* channel_info);
104 98
105 // Inform the channel that it will soon be destroyed (doing so is optional). 99 // 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 100 // This may be called from any thread, but the caller must ensure that this is
107 // called before |DestroyChannel()| or |DestroyChannelOnIOThread()|. 101 // called before |DestroyChannel()|.
108 MOJO_SYSTEM_IMPL_EXPORT void WillDestroyChannelSoon(ChannelInfo* channel_info); 102 MOJO_SYSTEM_IMPL_EXPORT void WillDestroyChannelSoon(ChannelInfo* channel_info);
109 103
110 // Creates a |MojoHandle| that wraps the given |PlatformHandle| (taking 104 // Creates a |MojoHandle| that wraps the given |PlatformHandle| (taking
111 // ownership of it). This |MojoHandle| can then, e.g., be passed through message 105 // 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 106 // 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 107 // failure, which is different from what you'd expect from a Mojo API, but it
114 // makes for a more convenient embedder API. 108 // makes for a more convenient embedder API.
115 MOJO_SYSTEM_IMPL_EXPORT MojoResult 109 MOJO_SYSTEM_IMPL_EXPORT MojoResult
116 CreatePlatformHandleWrapper(ScopedPlatformHandle platform_handle, 110 CreatePlatformHandleWrapper(ScopedPlatformHandle platform_handle,
117 MojoHandle* platform_handle_wrapper_handle); 111 MojoHandle* platform_handle_wrapper_handle);
118 // Retrieves the |PlatformHandle| that was wrapped into a |MojoHandle| (using 112 // Retrieves the |PlatformHandle| that was wrapped into a |MojoHandle| (using
119 // |CreatePlatformHandleWrapper()| above). Note that the |MojoHandle| must still 113 // |CreatePlatformHandleWrapper()| above). Note that the |MojoHandle| must still
120 // be closed separately. 114 // be closed separately.
121 MOJO_SYSTEM_IMPL_EXPORT MojoResult 115 MOJO_SYSTEM_IMPL_EXPORT MojoResult
122 PassWrappedPlatformHandle(MojoHandle platform_handle_wrapper_handle, 116 PassWrappedPlatformHandle(MojoHandle platform_handle_wrapper_handle,
123 ScopedPlatformHandle* platform_handle); 117 ScopedPlatformHandle* platform_handle);
124 118
125 } // namespace embedder 119 } // namespace embedder
126 } // namespace mojo 120 } // namespace mojo
127 121
128 #endif // MOJO_EDK_EMBEDDER_EMBEDDER_H_ 122 #endif // MOJO_EDK_EMBEDDER_EMBEDDER_H_
OLDNEW
« no previous file with comments | « mojo/edk/embedder/channel_info_forward.h ('k') | mojo/edk/embedder/embedder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698