diff options
author | morrita <morrita@chromium.org> | 2014-09-23 14:16:00 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-09-23 21:16:28 +0000 |
commit | 54f6f80c3623a6fb9d3049b6f5e0e23b1d76c34d (patch) | |
tree | d5188994206cd43ae680f6e7325ec5c45075b9da /ipc/mojo/ipc_channel_mojo.h | |
parent | de9555146d87d2daf5e2e1da425d46b8efc06415 (diff) | |
download | chromium_src-54f6f80c3623a6fb9d3049b6f5e0e23b1d76c34d.zip chromium_src-54f6f80c3623a6fb9d3049b6f5e0e23b1d76c34d.tar.gz chromium_src-54f6f80c3623a6fb9d3049b6f5e0e23b1d76c34d.tar.bz2 |
IPC::ChannelMojo: Introduce IPC::MojoBootstrap for Windows
ChannelMojo doesn't work on Windows with existing implementaion
and this CL fixes it.
On Windows, ChannelHandle isn't immediately usable: The handle has
to be activated through ConnectNamedPipe() windows API, which is done in
its own Connect() handlshaking phase. ChannelMojo didn't Connect()
underlying channel and took the ChannelHandle over so the handle
wasn't activated.
Instead of hijacking underlying ChannelHandle, this CL actually Connect()s
underlying channel, creates a pipe on the server side, send one side of the
pipe to the client process, and use the pipe for the MessagePipe
initialization.
These initialization task is encapsulated behind new MojoBootstrap class.
ChannelMojo creates MojoBootstrap class to get the PlatformHandle which
is already activated and usable.
BUG=377980
TEST=ipc_mojo_bootstrap_unittest.cc, ipc_channel_mojo_unittest.cc
R=viettrungluu@chromium.org, darin@chromium.org, yzshen@chromium.org
Review URL: https://codereview.chromium.org/553283002
Cr-Commit-Position: refs/heads/master@{#296248}
Diffstat (limited to 'ipc/mojo/ipc_channel_mojo.h')
-rw-r--r-- | ipc/mojo/ipc_channel_mojo.h | 43 |
1 files changed, 31 insertions, 12 deletions
diff --git a/ipc/mojo/ipc_channel_mojo.h b/ipc/mojo/ipc_channel_mojo.h index 22c56a9..9964a8f 100644 --- a/ipc/mojo/ipc_channel_mojo.h +++ b/ipc/mojo/ipc_channel_mojo.h @@ -14,6 +14,7 @@ #include "ipc/ipc_channel_factory.h" #include "ipc/ipc_export.h" #include "ipc/mojo/ipc_message_pipe_reader.h" +#include "ipc/mojo/ipc_mojo_bootstrap.h" #include "mojo/public/cpp/system/core.h" namespace mojo { @@ -31,6 +32,8 @@ class ClientControlReader; class MessageReader; } +class ChannelMojoHost; + // Mojo-based IPC::Channel implementation over a platform handle. // // ChannelMojo builds Mojo MessagePipe using underlying pipe given by @@ -55,21 +58,31 @@ class MessageReader; // TODO(morrita): Add APIs to create extra MessagePipes to let // Mojo-based objects talk over this Channel. // -class IPC_MOJO_EXPORT ChannelMojo : public Channel { +class IPC_MOJO_EXPORT ChannelMojo : public Channel, + public MojoBootstrap::Delegate { public: // Create ChannelMojo. A bootstrap channel is created as well. - static scoped_ptr<ChannelMojo> Create( - const ChannelHandle &channel_handle, Mode mode, Listener* listener, - scoped_refptr<base::TaskRunner> io_thread_task_runner); + // |host| must not be null. + static scoped_ptr<ChannelMojo> Create(ChannelMojoHost* host, + const ChannelHandle& channel_handle, + Mode mode, + Listener* listener); // Create a factory object for ChannelMojo. // The factory is used to create Mojo-based ChannelProxy family. - static scoped_ptr<ChannelFactory> CreateFactory( - const ChannelHandle &channel_handle, Mode mode, - scoped_refptr<base::TaskRunner> io_thread_task_runner); + // |host| must not be null. + static scoped_ptr<ChannelFactory> CreateServerFactory( + ChannelMojoHost* host, + const ChannelHandle& channel_handle); + + static scoped_ptr<ChannelFactory> CreateClientFactory( + const ChannelHandle& channel_handle); virtual ~ChannelMojo(); + // ChannelMojoHost tells the client handle using this API. + void OnClientLaunched(base::ProcessHandle handle); + // Channel implementation virtual bool Connect() OVERRIDE; virtual void Close() OVERRIDE; @@ -92,6 +105,11 @@ class IPC_MOJO_EXPORT ChannelMojo : public Channel { #endif // defined(OS_POSIX) && !defined(OS_NACL) + // MojoBootstrapDelegate implementation + virtual void OnPipeAvailable( + mojo::embedder::ScopedPlatformHandle handle) OVERRIDE; + virtual void OnBootstrapError() OVERRIDE; + // Called from MessagePipeReader implementations void OnMessageReceived(Message& message); void OnConnected(mojo::ScopedMessagePipeHandle pipe); @@ -100,10 +118,10 @@ class IPC_MOJO_EXPORT ChannelMojo : public Channel { void set_peer_pid(base::ProcessId pid) { peer_pid_ = pid; } protected: - ChannelMojo(const ChannelHandle& channel_handle, + ChannelMojo(ChannelMojoHost* host, + const ChannelHandle& channel_handle, Mode mode, - Listener* listener, - scoped_refptr<base::TaskRunner> io_thread_task_runner); + Listener* listener); private: struct ChannelInfoDeleter { @@ -115,9 +133,10 @@ class IPC_MOJO_EXPORT ChannelMojo : public Channel { // notifications invoked by them. typedef internal::MessagePipeReader::DelayedDeleter ReaderDeleter; - void InitOnIOThread(); + void InitControlReader(mojo::embedder::ScopedPlatformHandle handle); - scoped_ptr<Channel> bootstrap_; + scoped_ptr<MojoBootstrap> bootstrap_; + ChannelMojoHost* const host_; Mode mode_; Listener* listener_; base::ProcessId peer_pid_; |