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

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

Issue 1350023003: Add a Mojo EDK for Chrome that uses one OS pipe per message pipe. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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
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 <string>
9
10 #include "base/callback.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/task_runner.h"
14 #include "mojo/edk/embedder/process_type.h"
15 #include "mojo/edk/embedder/scoped_platform_handle.h"
16 #include "mojo/edk/system/system_impl_export.h"
17 #include "mojo/public/cpp/system/message_pipe.h"
18
19 namespace mojo {
20 namespace embedder {
21
22 struct Configuration;
23 class PlatformSupport;
24 class ProcessDelegate;
25
26 // Basic configuration/initialization ------------------------------------------
27
28 // |Init()| sets up the basic Mojo system environment, making the |Mojo...()|
29 // functions available and functional. This is never shut down (except in tests
30 // -- see test_embedder.h).
31
32 // Returns the global configuration. In general, you should not need to change
33 // the configuration, but if you do you must do it before calling |Init()|.
34 MOJO_SYSTEM_IMPL_EXPORT Configuration* GetConfiguration();
35
36 // Must be called first, or just after setting configuration parameters, to
37 // initialize the (global, singleton) system.
38 MOJO_SYSTEM_IMPL_EXPORT void Init(scoped_ptr<PlatformSupport> platform_support);
39
40 // Basic functions -------------------------------------------------------------
41
42 // The functions in this section are available once |Init()| has been called.
43
44 // Start waiting on the handle asynchronously. On success, |callback| will be
45 // called exactly once, when |handle| satisfies a signal in |signals| or it
46 // becomes known that it will never do so. |callback| will be executed on an
47 // arbitrary thread, so it must not call any Mojo system or embedder functions.
48 MOJO_SYSTEM_IMPL_EXPORT MojoResult
49 AsyncWait(MojoHandle handle,
50 MojoHandleSignals signals,
51 const base::Callback<void(MojoResult)>& callback);
52
53 // Creates a |MojoHandle| that wraps the given |PlatformHandle| (taking
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
56 // failure, which is different from what you'd expect from a Mojo API, but it
57 // makes for a more convenient embedder API.
58 MOJO_SYSTEM_IMPL_EXPORT MojoResult
59 CreatePlatformHandleWrapper(ScopedPlatformHandle platform_handle,
60 MojoHandle* platform_handle_wrapper_handle);
61
62 // Retrieves the |PlatformHandle| that was wrapped into a |MojoHandle| (using
63 // |CreatePlatformHandleWrapper()| above). Note that the |MojoHandle| must still
64 // be closed separately.
65 MOJO_SYSTEM_IMPL_EXPORT MojoResult
66 PassWrappedPlatformHandle(MojoHandle platform_handle_wrapper_handle,
67 ScopedPlatformHandle* platform_handle);
68
69 // Initialialization/shutdown for interprocess communication (IPC) -------------
70
71 // |InitIPCSupport()| sets up the subsystem for interprocess communication,
72 // making the IPC functions (in the following section) available and functional.
73 // (This may only be done after |Init()|.)
74 //
75 // This subsystem may be shut down, using |ShutdownIPCSupportOnIOThread()| or
76 // |ShutdownIPCSupport()|. None of the IPC functions may be called while or
77 // after either of these is called.
78
79 // Initializes a process of the given type; to be called after |Init()|.
80 // - |process_delegate| must be a process delegate of the appropriate type
81 // corresponding to |process_type|; its methods will be called on
82 // |delegate_thread_task_runner|.
83 // - |delegate_thread_task_runner|, |process_delegate|, and
84 // |io_thread_task_runner| should live at least until
85 // |ShutdownIPCSupport()|'s callback has been run or
86 // |ShutdownIPCSupportOnIOThread()| has completed.
87 // - For slave processes (i.e., |process_type| is |ProcessType::SLAVE|),
88 // |platform_handle| should be connected to the handle passed to
89 // |ConnectToSlave()| (in the master process). For other processes,
90 // |platform_handle| is ignored (and should not be valid).
91 MOJO_SYSTEM_IMPL_EXPORT void InitIPCSupport(
92 ProcessType process_type,
93 scoped_refptr<base::TaskRunner> delegate_thread_task_runner,
94 ProcessDelegate* process_delegate,
95 scoped_refptr<base::TaskRunner> io_thread_task_runner,
96 ScopedPlatformHandle platform_handle);
97
98 // Shuts down the subsystem initialized by |InitIPCSupport()|. This must be
99 // called on the I/O thread (given to |InitIPCSupport()|). This completes
100 // synchronously and does not result in a call to the process delegate's
101 // |OnShutdownComplete()|.
102 MOJO_SYSTEM_IMPL_EXPORT void ShutdownIPCSupportOnIOThread();
103
104 // Like |ShutdownIPCSupportOnIOThread()|, but may be called from any thread,
105 // signalling shutdown completion via the process delegate's
106 // |OnShutdownComplete()|.
107 MOJO_SYSTEM_IMPL_EXPORT void ShutdownIPCSupport();
108
109 // Like above, but doesn't call |OnShutdownComplete| until all channels are
110 // gone.
111 // TODO(jam): this should be the default behavior.
112 MOJO_SYSTEM_IMPL_EXPORT void ShutdownIPCSupportAndWaitForNoChannels();
113
114 // Creates a message pipe from a platform handle. Safe to call from any thread.
115 MOJO_SYSTEM_IMPL_EXPORT ScopedMessagePipeHandle
116 CreateMessagePipe(ScopedPlatformHandle platform_handle);
117
118 } // namespace embedder
119 } // namespace mojo
120
121 #endif // MOJO_EDK_EMBEDDER_EMBEDDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698