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

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

Issue 814543006: Move //mojo/{public, edk} underneath //third_party (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 11 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/configuration.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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef MOJO_EDK_EMBEDDER_EMBEDDER_H_
6 #define MOJO_EDK_EMBEDDER_EMBEDDER_H_
7
8 #include "base/callback.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/task_runner.h"
12 #include "mojo/edk/embedder/channel_info_forward.h"
13 #include "mojo/edk/embedder/scoped_platform_handle.h"
14 #include "mojo/edk/system/system_impl_export.h"
15 #include "mojo/public/cpp/system/message_pipe.h"
16
17 namespace mojo {
18 namespace embedder {
19
20 struct Configuration;
21 class PlatformSupport;
22
23 // Must be called first, or just after setting configuration parameters,
24 // to initialize the (global, singleton) system.
25 MOJO_SYSTEM_IMPL_EXPORT void Init(scoped_ptr<PlatformSupport> platform_support);
26
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
29 // |Init()|.
30 MOJO_SYSTEM_IMPL_EXPORT Configuration* GetConfiguration();
31
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.
34 //
35 // There are two channel creation APIs: |CreateChannelOnIOThread()| creates a
36 // channel synchronously and must be called from the I/O thread, while
37 // |CreateChannel()| is asynchronous and 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.
41 //
42 // Both creation functions have a |platform_handle| argument, which should be an
43 // OS-dependent handle to one side of a suitable bidirectional OS "pipe" (e.g.,
44 // a file descriptor to a socket on POSIX, a handle to a named pipe on Windows);
45 // this "pipe" should be connected and ready for operation (e.g., to be written
46 // to or read from).
47 //
48 // Both (synchronously) return a handle to the bootstrap message pipe on the
49 // channel that was (or is to be) created, or |MOJO_HANDLE_INVALID| on error
50 // (but note that this will happen only if, e.g., the handle table is full).
51 // This message pipe may be used immediately, but since channel operation
52 // actually begins asynchronously, other errors may still occur (e.g., if the
53 // other end of the "pipe" is closed) and be reported in the usual way to the
54 // returned handle.
55 //
56 // (E.g., a message written immediately to the returned handle will be queued
57 // and the handle immediately closed, before the channel begins operation. In
58 // this case, the channel should connect as usual, send the queued message, and
59 // report that the handle was closed to the other side. The message sent may
60 // have other handles, so there may still be message pipes "on" this channel.)
61 //
62 // Both also produce a |ChannelInfo*| (a pointer to an opaque object) -- the
63 // first synchronously and second asynchronously.
64 //
65 // The destruction functions are similarly synchronous and asynchronous,
66 // respectively, and take the |ChannelInfo*| produced by the creation functions.
67 //
68 // TODO(vtl): Figure out channel teardown.
69
70 // Creates a channel; must only be called from the I/O thread. |platform_handle|
71 // should be a handle to a connected OS "pipe". Eventually (even on failure),
72 // the "out" value |*channel_info| should be passed to |DestoryChannel()| to
73 // tear down the channel. Returns a handle to the bootstrap message pipe.
74 MOJO_SYSTEM_IMPL_EXPORT ScopedMessagePipeHandle
75 CreateChannelOnIOThread(ScopedPlatformHandle platform_handle,
76 ChannelInfo** channel_info);
77
78 typedef base::Callback<void(ChannelInfo*)> DidCreateChannelCallback;
79 // Creates a channel asynchronously; may be called from any thread.
80 // |platform_handle| should be a handle to a connected OS "pipe".
81 // |io_thread_task_runner| should be the |TaskRunner| for the I/O thread.
82 // |callback| should be the callback to call with the |ChannelInfo*|, which
83 // should eventually be passed to |DestroyChannel()| to tear down the channel;
84 // the callback will be called using |callback_thread_task_runner| if that is
85 // non-null, or otherwise it will be called using |io_thread_task_runner|.
86 // Returns a handle to the bootstrap message pipe.
87 MOJO_SYSTEM_IMPL_EXPORT ScopedMessagePipeHandle
88 CreateChannel(ScopedPlatformHandle platform_handle,
89 scoped_refptr<base::TaskRunner> io_thread_task_runner,
90 DidCreateChannelCallback callback,
91 scoped_refptr<base::TaskRunner> callback_thread_task_runner);
92
93 // Destroys a channel that was created using |CreateChannel()| (or
94 // |CreateChannelOnIOThread()|); may be called from any thread. |channel_info|
95 // should be the value provided to the callback to |CreateChannel()| (or
96 // returned by |CreateChannelOnIOThread()|). If called from the I/O thread, this
97 // will complete synchronously (in particular, it will post no tasks).
98 MOJO_SYSTEM_IMPL_EXPORT void DestroyChannel(ChannelInfo* channel_info);
99
100 // Inform the channel that it will soon be destroyed (doing so is optional).
101 // This may be called from any thread, but the caller must ensure that this is
102 // called before |DestroyChannel()|.
103 MOJO_SYSTEM_IMPL_EXPORT void WillDestroyChannelSoon(ChannelInfo* channel_info);
104
105 // Creates a |MojoHandle| that wraps the given |PlatformHandle| (taking
106 // ownership of it). This |MojoHandle| can then, e.g., be passed through message
107 // pipes. Note: This takes ownership (and thus closes) |platform_handle| even on
108 // failure, which is different from what you'd expect from a Mojo API, but it
109 // makes for a more convenient embedder API.
110 MOJO_SYSTEM_IMPL_EXPORT MojoResult
111 CreatePlatformHandleWrapper(ScopedPlatformHandle platform_handle,
112 MojoHandle* platform_handle_wrapper_handle);
113 // Retrieves the |PlatformHandle| that was wrapped into a |MojoHandle| (using
114 // |CreatePlatformHandleWrapper()| above). Note that the |MojoHandle| must still
115 // be closed separately.
116 MOJO_SYSTEM_IMPL_EXPORT MojoResult
117 PassWrappedPlatformHandle(MojoHandle platform_handle_wrapper_handle,
118 ScopedPlatformHandle* platform_handle);
119
120 // Start waiting the handle asynchronously. On success, |callback| will be
121 // called exactly once, when |handle| satisfies a signal in |signals| or it
122 // becomes known that it will never do so. |callback| will be executed on an
123 // arbitrary thread. It must not call any Mojo system or embedder functions.
124 MOJO_SYSTEM_IMPL_EXPORT MojoResult
125 AsyncWait(MojoHandle handle,
126 MojoHandleSignals signals,
127 base::Callback<void(MojoResult)> callback);
128
129 } // namespace embedder
130 } // namespace mojo
131
132 #endif // MOJO_EDK_EMBEDDER_EMBEDDER_H_
OLDNEW
« no previous file with comments | « mojo/edk/embedder/configuration.h ('k') | mojo/edk/embedder/embedder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698