OLD | NEW |
(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/scoped_platform_handle.h" |
| 15 #include "mojo/edk/system/system_impl_export.h" |
| 16 #include "mojo/public/cpp/system/message_pipe.h" |
| 17 |
| 18 namespace mojo { |
| 19 namespace edk { |
| 20 |
| 21 class ProcessDelegate; |
| 22 |
| 23 // Basic configuration/initialization ------------------------------------------ |
| 24 |
| 25 // |Init()| sets up the basic Mojo system environment, making the |Mojo...()| |
| 26 // functions available and functional. This is never shut down (except in tests |
| 27 // -- see test_embedder.h). |
| 28 |
| 29 // Allows changing the default max message size. Must be called before Init. |
| 30 MOJO_SYSTEM_IMPL_EXPORT void SetMaxMessageSize(size_t bytes); |
| 31 |
| 32 // Must be called first, or just after setting configuration parameters, to |
| 33 // initialize the (global, singleton) system. |
| 34 MOJO_SYSTEM_IMPL_EXPORT void Init(); |
| 35 |
| 36 // Basic functions ------------------------------------------------------------- |
| 37 |
| 38 // The functions in this section are available once |Init()| has been called. |
| 39 |
| 40 // Start waiting on the handle asynchronously. On success, |callback| will be |
| 41 // called exactly once, when |handle| satisfies a signal in |signals| or it |
| 42 // becomes known that it will never do so. |callback| will be executed on an |
| 43 // arbitrary thread, so it must not call any Mojo system or embedder functions. |
| 44 MOJO_SYSTEM_IMPL_EXPORT MojoResult |
| 45 AsyncWait(MojoHandle handle, |
| 46 MojoHandleSignals signals, |
| 47 const base::Callback<void(MojoResult)>& callback); |
| 48 |
| 49 // Creates a |MojoHandle| that wraps the given |PlatformHandle| (taking |
| 50 // ownership of it). This |MojoHandle| can then, e.g., be passed through message |
| 51 // pipes. Note: This takes ownership (and thus closes) |platform_handle| even on |
| 52 // failure, which is different from what you'd expect from a Mojo API, but it |
| 53 // makes for a more convenient embedder API. |
| 54 MOJO_SYSTEM_IMPL_EXPORT MojoResult |
| 55 CreatePlatformHandleWrapper(ScopedPlatformHandle platform_handle, |
| 56 MojoHandle* platform_handle_wrapper_handle); |
| 57 |
| 58 // Retrieves the |PlatformHandle| that was wrapped into a |MojoHandle| (using |
| 59 // |CreatePlatformHandleWrapper()| above). Note that the |MojoHandle| must still |
| 60 // be closed separately. |
| 61 MOJO_SYSTEM_IMPL_EXPORT MojoResult |
| 62 PassWrappedPlatformHandle(MojoHandle platform_handle_wrapper_handle, |
| 63 ScopedPlatformHandle* platform_handle); |
| 64 |
| 65 // Initialialization/shutdown for interprocess communication (IPC) ------------- |
| 66 |
| 67 // |InitIPCSupport()| sets up the subsystem for interprocess communication, |
| 68 // making the IPC functions (in the following section) available and functional. |
| 69 // (This may only be done after |Init()|.) |
| 70 // |
| 71 // This subsystem may be shut down, using |ShutdownIPCSupportOnIOThread()| or |
| 72 // |ShutdownIPCSupport()|. None of the IPC functions may be called while or |
| 73 // after either of these is called. |
| 74 |
| 75 // Initializes a process of the given type; to be called after |Init()|. |
| 76 // - |process_delegate| must be a process delegate of the appropriate type |
| 77 // corresponding to |process_type|; its methods will be called on |
| 78 // |delegate_thread_task_runner|. |
| 79 // - |delegate_thread_task_runner|, |process_delegate|, and |
| 80 // |io_thread_task_runner| should live at least until |
| 81 // |ShutdownIPCSupport()|'s callback has been run or |
| 82 // |ShutdownIPCSupportOnIOThread()| has completed. |
| 83 MOJO_SYSTEM_IMPL_EXPORT void InitIPCSupport( |
| 84 scoped_refptr<base::TaskRunner> delegate_thread_task_runner, |
| 85 ProcessDelegate* process_delegate, |
| 86 scoped_refptr<base::TaskRunner> io_thread_task_runner); |
| 87 |
| 88 // Shuts down the subsystem initialized by |InitIPCSupport()|. This must be |
| 89 // called on the I/O thread (given to |InitIPCSupport()|). This completes |
| 90 // synchronously and does not result in a call to the process delegate's |
| 91 // |OnShutdownComplete()|. |
| 92 MOJO_SYSTEM_IMPL_EXPORT void ShutdownIPCSupportOnIOThread(); |
| 93 |
| 94 // Like |ShutdownIPCSupportOnIOThread()|, but may be called from any thread, |
| 95 // signalling shutdown completion via the process delegate's |
| 96 // |OnShutdownComplete()|. |
| 97 MOJO_SYSTEM_IMPL_EXPORT void ShutdownIPCSupport(); |
| 98 |
| 99 // Like above, but doesn't call |OnShutdownComplete| until all channels are |
| 100 // gone. |
| 101 // TODO(jam): this should be the default behavior. |
| 102 MOJO_SYSTEM_IMPL_EXPORT void ShutdownIPCSupportAndWaitForNoChannels(); |
| 103 |
| 104 // Creates a message pipe from a platform handle. Safe to call from any thread. |
| 105 MOJO_SYSTEM_IMPL_EXPORT ScopedMessagePipeHandle |
| 106 CreateMessagePipe(ScopedPlatformHandle platform_handle); |
| 107 |
| 108 } // namespace edk |
| 109 } // namespace mojo |
| 110 |
| 111 #endif // MOJO_EDK_EMBEDDER_EMBEDDER_H_ |
OLD | NEW |