Index: mojo/edk/system/core.h |
diff --git a/mojo/edk/system/core.h b/mojo/edk/system/core.h |
index 7c5a2357a6bb046e818ee9807f1d08834c82c635..98fe22fddf4c71f1ed41bd1544b090cdc7f18ba7 100644 |
--- a/mojo/edk/system/core.h |
+++ b/mojo/edk/system/core.h |
@@ -5,49 +5,99 @@ |
#ifndef MOJO_EDK_SYSTEM_CORE_H_ |
#define MOJO_EDK_SYSTEM_CORE_H_ |
-#include <stdint.h> |
+#include <vector> |
#include "base/callback.h" |
+#include "base/macros.h" |
#include "base/memory/ref_counted.h" |
#include "base/memory/scoped_ptr.h" |
#include "base/synchronization/lock.h" |
+#include "base/task_runner.h" |
+#include "mojo/edk/embedder/scoped_platform_handle.h" |
+#include "mojo/edk/system/dispatcher.h" |
+#include "mojo/edk/system/handle_signals_state.h" |
#include "mojo/edk/system/handle_table.h" |
#include "mojo/edk/system/mapping_table.h" |
+#include "mojo/edk/system/node_controller.h" |
#include "mojo/edk/system/system_impl_export.h" |
#include "mojo/public/c/system/buffer.h" |
#include "mojo/public/c/system/data_pipe.h" |
#include "mojo/public/c/system/message_pipe.h" |
#include "mojo/public/c/system/types.h" |
-#include "mojo/public/cpp/system/macros.h" |
+#include "mojo/public/cpp/system/message_pipe.h" |
namespace mojo { |
- |
namespace edk { |
-class Dispatcher; |
-class PlatformSupport; |
-struct HandleSignalsState; |
- |
// |Core| is an object that implements the Mojo system calls. All public methods |
// are thread-safe. |
class MOJO_SYSTEM_IMPL_EXPORT Core { |
public: |
- // --------------------------------------------------------------------------- |
- |
- // These methods are only to be used by via the embedder API (and internally): |
- |
- // |*platform_support| must outlive this object. |
- explicit Core(PlatformSupport* platform_support); |
+ explicit Core(); |
virtual ~Core(); |
- // Adds |dispatcher| to the handle table, returning the handle for it. Returns |
- // |MOJO_HANDLE_INVALID| on failure, namely if the handle table is full. |
- MojoHandle AddDispatcher(const scoped_refptr<Dispatcher>& dispatcher); |
+ // Called exactly once, shortly after construction, and before any other |
+ // methods are called on this object. |
+ void SetIOTaskRunner(scoped_refptr<base::TaskRunner> io_task_runner); |
+ |
+ // Retrieves the NodeController for the current process. |
+ NodeController* GetNodeController(); |
- // Looks up the dispatcher for the given handle. Returns null if the handle is |
- // invalid. |
scoped_refptr<Dispatcher> GetDispatcher(MojoHandle handle); |
+ // Called in the parent process any time a new child is launched. |
+ void AddChild(base::ProcessHandle process_handle, |
+ ScopedPlatformHandle platform_handle); |
+ |
+ // Called in a child process exactly once during early initialization. |
+ void InitChild(ScopedPlatformHandle platform_handle); |
+ |
+ // These each create message pipe endpoints connected to an endpoint in a |
+ // remote embedder. |platform_handle| is used as a channel to negotiate the |
+ // connection. This is only here to facilitate legacy embedder code. See |
+ // mojo::edk::CreateMessagePipe in mojo/edk/embedder/embedder.h. |
+ void CreateParentMessagePipe( |
+ ScopedPlatformHandle platform_handle, |
+ const base::Callback<void(ScopedMessagePipeHandle)>& callback); |
+ void CreateChildMessagePipe( |
+ ScopedPlatformHandle platform_handle, |
+ const base::Callback<void(ScopedMessagePipeHandle)>& callback); |
+ |
+ // Creates a message pipe endpoint associated with |token|, which a child |
+ // holding the token can later locate and connect to. |
+ void CreateParentMessagePipe( |
+ const std::string& token, |
+ const base::Callback<void(ScopedMessagePipeHandle)>& callback); |
+ |
+ // Creates a message pipe endpoint associated with |token|, which will be |
+ // passed to the parent in order to find an associated remote port and connect |
+ // to it. |
+ void CreateChildMessagePipe( |
+ const std::string& token, |
+ const base::Callback<void(ScopedMessagePipeHandle)>& callback); |
+ |
+ MojoHandle AddDispatcher(scoped_refptr<Dispatcher> dispatcher); |
+ |
+ // Adds new dispatchers for non-message-pipe handles received in a message. |
+ // |dispatchers| and |handles| should be the same size. |
+ bool AddDispatchersFromTransit( |
+ const std::vector<Dispatcher::DispatcherInTransit>& dispatchers, |
+ MojoHandle* handles); |
+ |
+ MojoResult CreatePlatformHandleWrapper(ScopedPlatformHandle platform_handle, |
+ MojoHandle* wrapper_handle); |
+ |
+ MojoResult PassWrappedPlatformHandle(MojoHandle wrapper_handle, |
+ ScopedPlatformHandle* platform_handle); |
+ |
+ // Requests that the EDK tear itself down. |callback| will be called once |
+ // the shutdown process is complete. Note that |callback| is always called |
+ // asynchronously on the calling thread if said thread is running a message |
+ // loop, and the calling thread must continue running a MessageLoop at least |
+ // until the callback is called. If there is no running loop, the |callback| |
+ // may be called from any thread. Beware! |
+ void RequestShutdown(const base::Closure& callback); |
+ |
// Watches on the given handle for the given signals, calling |callback| when |
// a signal is satisfied or when all signals become unsatisfiable. |callback| |
// must satisfy stringent requirements -- see |Awakable::Awake()| in |
@@ -56,10 +106,6 @@ class MOJO_SYSTEM_IMPL_EXPORT Core { |
MojoHandleSignals signals, |
const base::Callback<void(MojoResult)>& callback); |
- PlatformSupport* platform_support() const { |
- return platform_support_; |
- } |
- |
// --------------------------------------------------------------------------- |
// The following methods are essentially implementations of the Mojo Core |
@@ -160,31 +206,32 @@ class MOJO_SYSTEM_IMPL_EXPORT Core { |
MojoMapBufferFlags flags); |
MojoResult UnmapBuffer(void* buffer); |
- private: |
- friend bool internal::ShutdownCheckNoLeaks(Core*); |
+ void GetActiveHandlesForTest(std::vector<MojoHandle>* handles); |
- // Internal implementation of |Wait()| and |WaitMany()|; doesn't do basic |
- // validation of arguments. |*result_index| is only set if the result (whether |
- // success or failure) applies to a specific handle, so its value should be |
- // preinitialized to |static_cast<uint32_t>(-1)|. |
+ private: |
MojoResult WaitManyInternal(const MojoHandle* handles, |
const MojoHandleSignals* signals, |
uint32_t num_handles, |
MojoDeadline deadline, |
- uint32_t* result_index, |
+ uint32_t *result_index, |
HandleSignalsState* signals_states); |
- PlatformSupport* const platform_support_; |
+ // Used to pass ownership of our NodeController over to the IO thread in the |
+ // event that we're torn down before said thread. |
+ static void PassNodeControllerToIOThread( |
+ scoped_ptr<NodeController> node_controller); |
+ |
+ // This is lazily initialized on first access. Always use GetNodeController() |
+ // to access it. |
+ scoped_ptr<NodeController> node_controller_; |
- // TODO(vtl): |handle_table_lock_| should be a reader-writer lock (if only we |
- // had them). |
- base::Lock handle_table_lock_; // Protects |handle_table_|. |
- HandleTable handle_table_; |
+ base::Lock handles_lock_; |
+ HandleTable handles_; |
base::Lock mapping_table_lock_; // Protects |mapping_table_|. |
MappingTable mapping_table_; |
- MOJO_DISALLOW_COPY_AND_ASSIGN(Core); |
+ DISALLOW_COPY_AND_ASSIGN(Core); |
}; |
} // namespace edk |