| Index: ipc/mojo/ipc_channel_mojo.cc
|
| diff --git a/ipc/mojo/ipc_channel_mojo.cc b/ipc/mojo/ipc_channel_mojo.cc
|
| index cdb928175dabcfda3104553ad88846b026b952b6..c4de3114a843011656c52b35c5c8cf8410858ded 100644
|
| --- a/ipc/mojo/ipc_channel_mojo.cc
|
| +++ b/ipc/mojo/ipc_channel_mojo.cc
|
| @@ -8,6 +8,7 @@
|
| #include "base/bind_helpers.h"
|
| #include "base/lazy_instance.h"
|
| #include "ipc/ipc_listener.h"
|
| +#include "ipc/mojo/ipc_mojo_bootstrap.h"
|
| #include "mojo/embedder/embedder.h"
|
|
|
| #if defined(OS_POSIX) && !defined(OS_NACL)
|
| @@ -40,8 +41,6 @@ class NullListener : public Listener {
|
| }
|
| };
|
|
|
| -base::LazyInstance<NullListener> g_null_listener = LAZY_INSTANCE_INITIALIZER;
|
| -
|
| class MojoChannelFactory : public ChannelFactory {
|
| public:
|
| MojoChannelFactory(
|
| @@ -71,17 +70,6 @@ class MojoChannelFactory : public ChannelFactory {
|
| scoped_refptr<base::TaskRunner> io_thread_task_runner_;
|
| };
|
|
|
| -mojo::embedder::PlatformHandle ToPlatformHandle(
|
| - const ChannelHandle& handle) {
|
| -#if defined(OS_POSIX) && !defined(OS_NACL)
|
| - return mojo::embedder::PlatformHandle(handle.socket.fd);
|
| -#elif defined(OS_WIN)
|
| - return mojo::embedder::PlatformHandle(handle.pipe.handle);
|
| -#else
|
| -#error "Unsupported Platform!"
|
| -#endif
|
| -}
|
| -
|
| //------------------------------------------------------------------------------
|
|
|
| // TODO(morrita): This should be built using higher-level Mojo construct
|
| @@ -458,9 +446,8 @@ void ChannelMojo::ChannelInfoDeleter::operator()(
|
| scoped_ptr<ChannelMojo> ChannelMojo::Create(
|
| const ChannelHandle &channel_handle, Mode mode, Listener* listener,
|
| scoped_refptr<base::TaskRunner> io_thread_task_runner) {
|
| - return make_scoped_ptr(new ChannelMojo(
|
| - Channel::Create(channel_handle, mode, g_null_listener.Pointer()),
|
| - mode, listener, io_thread_task_runner));
|
| + return make_scoped_ptr(
|
| + new ChannelMojo(channel_handle, mode, listener, io_thread_task_runner));
|
| }
|
|
|
| // static
|
| @@ -473,19 +460,21 @@ scoped_ptr<ChannelFactory> ChannelMojo::CreateFactory(
|
| io_thread_task_runner)).PassAs<ChannelFactory>();
|
| }
|
|
|
| -ChannelMojo::ChannelMojo(
|
| - scoped_ptr<Channel> bootstrap, Mode mode, Listener* listener,
|
| - scoped_refptr<base::TaskRunner> io_thread_task_runner)
|
| - : bootstrap_(bootstrap.Pass()),
|
| - mode_(mode), listener_(listener),
|
| +ChannelMojo::ChannelMojo(ChannelHandle handle,
|
| + Mode mode,
|
| + Listener* listener,
|
| + scoped_refptr<base::TaskRunner> io_thread_task_runner)
|
| + : mode_(mode),
|
| + listener_(listener),
|
| peer_pid_(base::kNullProcessId),
|
| weak_factory_(this) {
|
| if (base::MessageLoopProxy::current() == io_thread_task_runner.get()) {
|
| - InitOnIOThread();
|
| + InitBootstrap(handle);
|
| } else {
|
| - io_thread_task_runner->PostTask(FROM_HERE,
|
| - base::Bind(&ChannelMojo::InitOnIOThread,
|
| - weak_factory_.GetWeakPtr()));
|
| + io_thread_task_runner->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(
|
| + &ChannelMojo::InitBootstrap, weak_factory_.GetWeakPtr(), handle));
|
| }
|
| }
|
|
|
| @@ -493,13 +482,17 @@ ChannelMojo::~ChannelMojo() {
|
| Close();
|
| }
|
|
|
| -void ChannelMojo::InitOnIOThread() {
|
| +void ChannelMojo::InitBootstrap(ChannelHandle handle) {
|
| + DCHECK(base::MessageLoopForIO::IsCurrent());
|
| + bootstrap_ = MojoBootstrap::Create(handle, mode_, this);
|
| +}
|
| +
|
| +void ChannelMojo::InitControlReader(
|
| + mojo::embedder::ScopedPlatformHandle handle) {
|
| + DCHECK(base::MessageLoopForIO::IsCurrent());
|
| mojo::embedder::ChannelInfo* channel_info;
|
| mojo::ScopedMessagePipeHandle control_pipe =
|
| - mojo::embedder::CreateChannelOnIOThread(
|
| - mojo::embedder::ScopedPlatformHandle(
|
| - ToPlatformHandle(bootstrap_->TakePipeHandle())),
|
| - &channel_info);
|
| + mojo::embedder::CreateChannelOnIOThread(handle.Pass(), &channel_info);
|
| channel_info_.reset(channel_info);
|
|
|
| switch (mode_) {
|
| @@ -517,7 +510,8 @@ void ChannelMojo::InitOnIOThread() {
|
|
|
| bool ChannelMojo::Connect() {
|
| DCHECK(!message_reader_);
|
| - return control_reader_->Connect();
|
| + DCHECK(!control_reader_);
|
| + return bootstrap_->Connect();
|
| }
|
|
|
| void ChannelMojo::Close() {
|
| @@ -526,6 +520,15 @@ void ChannelMojo::Close() {
|
| channel_info_.reset();
|
| }
|
|
|
| +void ChannelMojo::OnPipeAvailable(mojo::embedder::ScopedPlatformHandle handle) {
|
| + InitControlReader(handle.Pass());
|
| + control_reader_->Connect();
|
| +}
|
| +
|
| +void ChannelMojo::OnBootstrapError() {
|
| + listener_->OnChannelError();
|
| +}
|
| +
|
| void ChannelMojo::OnConnected(mojo::ScopedMessagePipeHandle pipe) {
|
| message_reader_ = make_scoped_ptr(new MessageReader(pipe.Pass(), this));
|
|
|
| @@ -562,11 +565,16 @@ base::ProcessId ChannelMojo::GetPeerPID() const {
|
| }
|
|
|
| base::ProcessId ChannelMojo::GetSelfPID() const {
|
| - return bootstrap_->GetSelfPID();
|
| + return base::GetCurrentProcId();
|
| }
|
|
|
| ChannelHandle ChannelMojo::TakePipeHandle() {
|
| - return bootstrap_->TakePipeHandle();
|
| + NOTREACHED();
|
| + return ChannelHandle();
|
| +}
|
| +
|
| +void ChannelMojo::OnClientLaunched(base::ProcessHandle handle) {
|
| + bootstrap_->OnClientLaunched(handle);
|
| }
|
|
|
| void ChannelMojo::OnMessageReceived(Message& message) {
|
|
|