Chromium Code Reviews| Index: ipc/mojo/ipc_mojo_bootstrap.h |
| diff --git a/ipc/mojo/ipc_mojo_bootstrap.h b/ipc/mojo/ipc_mojo_bootstrap.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..0f6e50e85c576237ae92045096d30f0955e38174 |
| --- /dev/null |
| +++ b/ipc/mojo/ipc_mojo_bootstrap.h |
| @@ -0,0 +1,111 @@ |
| +// 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 "ipc/ipc_listener.h" |
| +#include "ipc/mojo/ipc_mojo_bootstrap_delegate.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(). |
| +class IPC_MOJO_EXPORT MojoBootstrap : public Listener { |
| + public: |
| + typedef MojoBootstrapDelegate Delegate; |
| + |
| + // 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); |
| + |
| + explicit MojoBootstrap(); |
|
viettrungluu
2014/09/15 20:19:44
nit: no need for explicit
Hajime Morrita
2014/09/15 22:01:37
Done.
|
| + 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); |
| +}; |
| + |
| +// MojoBootstrap for the server process. You should create the instance |
|
viettrungluu
2014/09/15 20:19:44
Does this (and MojoClientBootstrap) need to be in
Hajime Morrita
2014/09/15 22:01:37
Good point. Moved to .cc file.
|
| +// using MojoBootstrap::Create() |
| +class IPC_MOJO_EXPORT MojoServerBootstrap : public MojoBootstrap { |
| + public: |
| + explicit MojoServerBootstrap(); |
|
viettrungluu
2014/09/15 20:19:44
no explicit
Hajime Morrita
2014/09/15 22:01:37
Done.
|
| + |
| + virtual void OnClientLaunched(base::ProcessHandle process) OVERRIDE; |
| + |
| + private: |
| + void SendClientPipe(); |
| + void SendClientPipeIfReady(); |
| + |
| + // Listener implementations |
| + virtual bool OnMessageReceived(const Message&) OVERRIDE; |
|
viettrungluu
2014/09/15 20:19:44
nit: include the name of the argument ("message",
Hajime Morrita
2014/09/15 22:01:37
Done.
|
| + virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; |
| + |
| + mojo::embedder::ScopedPlatformHandle server_pipe_; |
| + base::ProcessHandle client_process_; |
| + bool connected_; |
| +}; |
|
viettrungluu
2014/09/15 20:19:44
nit: DISALLOW_COPY_AND_ASSIGN
Hajime Morrita
2014/09/15 22:01:37
Done.
|
| + |
| +// MojoBootstrap for client processes. You should create the instance |
| +// using MojoBootstrap::Create() |
| +class IPC_MOJO_EXPORT MojoClientBootstrap : public MojoBootstrap { |
| + public: |
| + explicit MojoClientBootstrap(); |
|
viettrungluu
2014/09/15 20:19:44
no explicit
Hajime Morrita
2014/09/15 22:01:37
Done.
|
| + |
| + virtual void OnClientLaunched(base::ProcessHandle process) OVERRIDE; |
| + |
| + private: |
| + // Listener implementations |
| + virtual bool OnMessageReceived(const Message&) OVERRIDE; |
|
viettrungluu
2014/09/15 20:19:44
nit: include the name of the argument ("message",
Hajime Morrita
2014/09/15 22:01:37
Done.
|
| + virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; |
| +}; |
|
viettrungluu
2014/09/15 20:19:44
nit: DISALLOW_COPY_AND_ASSIGN
Hajime Morrita
2014/09/15 22:01:37
Done.
|
| + |
| +} // namespace IPC |
| + |
| +#endif // IPC_MOJO_IPC_MOJO_BOOTSTRAP_H_ |