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