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_mojo_bootstrap.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_mojo_bootstrap.h')
-rw-r--r-- | ipc/mojo/ipc_mojo_bootstrap.h | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/ipc/mojo/ipc_mojo_bootstrap.h b/ipc/mojo/ipc_mojo_bootstrap.h new file mode 100644 index 0000000..a099af9 --- /dev/null +++ b/ipc/mojo/ipc_mojo_bootstrap.h @@ -0,0 +1,82 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef IPC_MOJO_IPC_MOJO_BOOTSTRAP_H_ +#define IPC_MOJO_IPC_MOJO_BOOTSTRAP_H_ + +#include "base/memory/scoped_ptr.h" +#include "base/process/process_handle.h" +#include "ipc/ipc_channel.h" +#include "ipc/ipc_listener.h" +#include "mojo/embedder/scoped_platform_handle.h" + +namespace IPC { + +// MojoBootstrap establishes a bootstrap pipe between two processes in +// Chrome. It creates a native IPC::Channel first, then sends one +// side of a newly created pipe to peer process. The pipe is intended +// to be wrapped by Mojo MessagePipe. +// +// Clients should implement MojoBootstrapDelegate to get the pipe +// from MojoBootstrap object. It should also tell the client process handle +// using OnClientLaunched(). +// +// This lives on IO thread other than Create(), which can be called from +// UI thread as Channel::Create() can be. +class IPC_MOJO_EXPORT MojoBootstrap : public Listener { + public: + class Delegate { + public: + virtual void OnPipeAvailable( + mojo::embedder::ScopedPlatformHandle handle) = 0; + virtual void OnBootstrapError() = 0; + }; + + // Create the MojoBootstrap instance. + // Instead of creating IPC::Channel, passs its ChannelHandle as |handle|, + // mode as |mode|. The result is notified to passed |delegate|. + static scoped_ptr<MojoBootstrap> Create(ChannelHandle handle, + Channel::Mode mode, + Delegate* delegate); + + MojoBootstrap(); + virtual ~MojoBootstrap(); + + // Start the handshake over the underlying platform channel. + bool Connect(); + + // Each client should call this once the process handle becomes known. + virtual void OnClientLaunched(base::ProcessHandle process) = 0; + +#if defined(OS_POSIX) && !defined(OS_NACL) + int GetClientFileDescriptor() const; + int TakeClientFileDescriptor(); +#endif // defined(OS_POSIX) && !defined(OS_NACL) + + protected: + enum State { STATE_INITIALIZED, STATE_WAITING_ACK, STATE_READY }; + + Delegate* delegate() const { return delegate_; } + bool Send(Message* message); + + State state() const { return state_; } + void set_state(State state) { state_ = state; } + + private: + void Init(scoped_ptr<Channel> channel, Delegate* delegate); + + // Listener implementations + virtual void OnBadMessageReceived(const Message& message) OVERRIDE; + virtual void OnChannelError() OVERRIDE; + + scoped_ptr<Channel> channel_; + Delegate* delegate_; + State state_; + + DISALLOW_COPY_AND_ASSIGN(MojoBootstrap); +}; + +} // namespace IPC + +#endif // IPC_MOJO_IPC_MOJO_BOOTSTRAP_H_ |