Index: ipc/mojo/ipc_channel_mojo.cc |
diff --git a/ipc/mojo/ipc_channel_mojo.cc b/ipc/mojo/ipc_channel_mojo.cc |
index 404c814516e84493b729ca7dfa930764943e3302..2957d22579c5966db6e23469b7dbc2c630379d53 100644 |
--- a/ipc/mojo/ipc_channel_mojo.cc |
+++ b/ipc/mojo/ipc_channel_mojo.cc |
@@ -20,11 +20,10 @@ |
#include "ipc/ipc_logging.h" |
#include "ipc/ipc_message_attachment_set.h" |
#include "ipc/ipc_message_macros.h" |
-#include "ipc/mojo/client_channel.mojom.h" |
#include "ipc/mojo/ipc_mojo_bootstrap.h" |
#include "ipc/mojo/ipc_mojo_handle_attachment.h" |
+#include "mojo/edk/embedder/embedder.h" |
#include "mojo/public/cpp/bindings/binding.h" |
-#include "third_party/mojo/src/mojo/edk/embedder/embedder.h" |
#if defined(OS_POSIX) && !defined(OS_NACL) |
#include "ipc/ipc_platform_file_attachment_posix.h" |
@@ -34,10 +33,6 @@ namespace IPC { |
namespace { |
-// TODO(jam): do more tests on using channel on same thread if it supports it ( |
-// i.e. with use-new-edk and Windows). Also see message_pipe_dispatcher.cc |
-bool g_use_channel_on_io_thread_only = true; |
- |
class MojoChannelFactory : public ChannelFactory { |
public: |
MojoChannelFactory(scoped_refptr<base::TaskRunner> io_runner, |
@@ -61,54 +56,24 @@ class MojoChannelFactory : public ChannelFactory { |
//------------------------------------------------------------------------------ |
-class ClientChannelMojo : public ChannelMojo, public ClientChannel { |
+class ClientChannelMojo : public ChannelMojo { |
public: |
ClientChannelMojo(scoped_refptr<base::TaskRunner> io_runner, |
const ChannelHandle& handle, |
Listener* listener) |
- : ChannelMojo(io_runner, handle, Channel::MODE_CLIENT, listener), |
- binding_(this), |
- weak_factory_(this) { |
+ : ChannelMojo(io_runner, handle, Channel::MODE_CLIENT, listener) { |
} |
~ClientChannelMojo() override {} |
// MojoBootstrap::Delegate implementation |
- void OnPipeAvailable(mojo::embedder::ScopedPlatformHandle handle, |
+ void OnPipeAvailable(mojo::edk::ScopedPlatformHandle handle, |
int32_t peer_pid) override { |
- if (base::CommandLine::ForCurrentProcess()->HasSwitch("use-new-edk")) { |
- InitMessageReader( |
- mojo::embedder::CreateChannel( |
- std::move(handle), |
- base::Callback<void(mojo::embedder::ChannelInfo*)>(), |
- scoped_refptr<base::TaskRunner>()), |
- peer_pid); |
- return; |
- } |
- CreateMessagingPipe( |
- std::move(handle), |
- base::Bind(&ClientChannelMojo::BindPipe, weak_factory_.GetWeakPtr())); |
- } |
- |
- // ClientChannel implementation |
- void Init( |
- mojo::ScopedMessagePipeHandle pipe, |
- int32_t peer_pid, |
- const mojo::Callback<void(int32_t)>& callback) override { |
- InitMessageReader(std::move(pipe), static_cast<base::ProcessId>(peer_pid)); |
- callback.Run(GetSelfPID()); |
+ InitMessageReader(mojo::edk::CreateMessagePipe(std::move(handle)), |
+ peer_pid); |
+ return; |
} |
private: |
- void BindPipe(mojo::ScopedMessagePipeHandle handle) { |
- binding_.Bind(std::move(handle)); |
- } |
- void OnConnectionError() { |
- listener()->OnChannelError(); |
- } |
- |
- mojo::Binding<ClientChannel> binding_; |
- base::WeakPtrFactory<ClientChannelMojo> weak_factory_; |
- |
DISALLOW_COPY_AND_ASSIGN(ClientChannelMojo); |
}; |
@@ -119,75 +84,26 @@ class ServerChannelMojo : public ChannelMojo { |
ServerChannelMojo(scoped_refptr<base::TaskRunner> io_runner, |
const ChannelHandle& handle, |
Listener* listener) |
- : ChannelMojo(io_runner, handle, Channel::MODE_SERVER, listener), |
- weak_factory_(this) { |
+ : ChannelMojo(io_runner, handle, Channel::MODE_SERVER, listener) { |
} |
~ServerChannelMojo() override { |
Close(); |
} |
// MojoBootstrap::Delegate implementation |
- void OnPipeAvailable(mojo::embedder::ScopedPlatformHandle handle, |
+ void OnPipeAvailable(mojo::edk::ScopedPlatformHandle handle, |
int32_t peer_pid) override { |
- if (base::CommandLine::ForCurrentProcess()->HasSwitch("use-new-edk")) { |
- message_pipe_ = mojo::embedder::CreateChannel( |
- std::move(handle), |
- base::Callback<void(mojo::embedder::ChannelInfo*)>(), |
- scoped_refptr<base::TaskRunner>()); |
- if (!message_pipe_.is_valid()) { |
- LOG(WARNING) << "mojo::CreateMessagePipe failed: "; |
- listener()->OnChannelError(); |
- return; |
- } |
- InitMessageReader(std::move(message_pipe_), peer_pid); |
- return; |
- } |
- |
- mojo::ScopedMessagePipeHandle peer; |
- MojoResult create_result = |
- mojo::CreateMessagePipe(nullptr, &message_pipe_, &peer); |
- if (create_result != MOJO_RESULT_OK) { |
- LOG(WARNING) << "mojo::CreateMessagePipe failed: " << create_result; |
+ message_pipe_ = mojo::edk::CreateMessagePipe(std::move(handle)); |
+ if (!message_pipe_.is_valid()) { |
+ LOG(WARNING) << "mojo::CreateMessagePipe failed: "; |
listener()->OnChannelError(); |
return; |
} |
- CreateMessagingPipe( |
- std::move(handle), |
- base::Bind(&ServerChannelMojo::InitClientChannel, |
- weak_factory_.GetWeakPtr(), base::Passed(&peer))); |
- } |
- // Channel override |
- void Close() override { |
- client_channel_.reset(); |
- message_pipe_.reset(); |
- ChannelMojo::Close(); |
- } |
- |
- private: |
- void InitClientChannel(mojo::ScopedMessagePipeHandle peer_handle, |
- mojo::ScopedMessagePipeHandle handle) { |
- client_channel_.Bind( |
- mojo::InterfacePtrInfo<ClientChannel>(std::move(handle), 0u)); |
- client_channel_.set_connection_error_handler(base::Bind( |
- &ServerChannelMojo::OnConnectionError, base::Unretained(this))); |
- client_channel_->Init( |
- std::move(peer_handle), static_cast<int32_t>(GetSelfPID()), |
- base::Bind(&ServerChannelMojo::ClientChannelWasInitialized, |
- base::Unretained(this))); |
- } |
- |
- void OnConnectionError() { |
- listener()->OnChannelError(); |
- } |
- // ClientChannelClient implementation |
- void ClientChannelWasInitialized(int32_t peer_pid) { |
InitMessageReader(std::move(message_pipe_), peer_pid); |
} |
- mojo::InterfacePtr<ClientChannel> client_channel_; |
mojo::ScopedMessagePipeHandle message_pipe_; |
- base::WeakPtrFactory<ServerChannelMojo> weak_factory_; |
DISALLOW_COPY_AND_ASSIGN(ServerChannelMojo); |
}; |
@@ -205,26 +121,6 @@ base::ScopedFD TakeOrDupFile(internal::PlatformFileAttachment* attachment) { |
//------------------------------------------------------------------------------ |
-ChannelMojo::ChannelInfoDeleter::ChannelInfoDeleter( |
- scoped_refptr<base::TaskRunner> io_runner) |
- : io_runner(io_runner) { |
-} |
- |
-ChannelMojo::ChannelInfoDeleter::~ChannelInfoDeleter() { |
-} |
- |
-void ChannelMojo::ChannelInfoDeleter::operator()( |
- mojo::embedder::ChannelInfo* ptr) const { |
- if (base::ThreadTaskRunnerHandle::Get() == io_runner) { |
- mojo::embedder::DestroyChannelOnIOThread(ptr); |
- } else { |
- io_runner->PostTask( |
- FROM_HERE, base::Bind(&mojo::embedder::DestroyChannelOnIOThread, ptr)); |
- } |
-} |
- |
-//------------------------------------------------------------------------------ |
- |
// static |
bool ChannelMojo::ShouldBeUsed() { |
// TODO(rockot): Investigate performance bottlenecks and hopefully reenable |
@@ -274,14 +170,12 @@ ChannelMojo::ChannelMojo(scoped_refptr<base::TaskRunner> io_runner, |
: listener_(listener), |
peer_pid_(base::kNullProcessId), |
io_runner_(io_runner), |
- channel_info_(nullptr, ChannelInfoDeleter(nullptr)), |
waiting_connect_(true), |
weak_factory_(this) { |
// Create MojoBootstrap after all members are set as it touches |
// ChannelMojo from a different thread. |
bootstrap_ = MojoBootstrap::Create(handle, mode, this); |
- if (!g_use_channel_on_io_thread_only || |
- io_runner == base::MessageLoop::current()->task_runner()) { |
+ if (io_runner == base::MessageLoop::current()->task_runner()) { |
InitOnIOThread(); |
} else { |
io_runner->PostTask(FROM_HERE, base::Bind(&ChannelMojo::InitOnIOThread, |
@@ -298,51 +192,6 @@ void ChannelMojo::InitOnIOThread() { |
new ScopedIPCSupport(base::MessageLoop::current()->task_runner())); |
} |
-void ChannelMojo::CreateMessagingPipe( |
- mojo::embedder::ScopedPlatformHandle handle, |
- const CreateMessagingPipeCallback& callback) { |
- auto return_callback = base::Bind(&ChannelMojo::OnMessagingPipeCreated, |
- weak_factory_.GetWeakPtr(), callback); |
- if (!g_use_channel_on_io_thread_only || |
- base::ThreadTaskRunnerHandle::Get() == io_runner_) { |
- CreateMessagingPipeOnIOThread(std::move(handle), |
- base::ThreadTaskRunnerHandle::Get(), |
- return_callback); |
- } else { |
- io_runner_->PostTask( |
- FROM_HERE, |
- base::Bind(&ChannelMojo::CreateMessagingPipeOnIOThread, |
- base::Passed(&handle), base::ThreadTaskRunnerHandle::Get(), |
- return_callback)); |
- } |
-} |
- |
-// static |
-void ChannelMojo::CreateMessagingPipeOnIOThread( |
- mojo::embedder::ScopedPlatformHandle handle, |
- scoped_refptr<base::TaskRunner> callback_runner, |
- const CreateMessagingPipeOnIOThreadCallback& callback) { |
- mojo::embedder::ChannelInfo* channel_info; |
- mojo::ScopedMessagePipeHandle pipe = |
- mojo::embedder::CreateChannelOnIOThread(std::move(handle), &channel_info); |
- if (base::ThreadTaskRunnerHandle::Get() == callback_runner) { |
- callback.Run(std::move(pipe), channel_info); |
- } else { |
- callback_runner->PostTask( |
- FROM_HERE, base::Bind(callback, base::Passed(&pipe), channel_info)); |
- } |
-} |
- |
-void ChannelMojo::OnMessagingPipeCreated( |
- const CreateMessagingPipeCallback& callback, |
- mojo::ScopedMessagePipeHandle handle, |
- mojo::embedder::ChannelInfo* channel_info) { |
- DCHECK(!channel_info_.get()); |
- channel_info_ = scoped_ptr<mojo::embedder::ChannelInfo, ChannelInfoDeleter>( |
- channel_info, ChannelInfoDeleter(io_runner_)); |
- callback.Run(std::move(handle)); |
-} |
- |
bool ChannelMojo::Connect() { |
DCHECK(!message_reader_); |
return bootstrap_->Connect(); |
@@ -360,7 +209,6 @@ void ChannelMojo::Close() { |
waiting_connect_ = false; |
} |
- channel_info_.reset(); |
ipc_support_.reset(); |
to_be_deleted.reset(); |
} |
@@ -495,9 +343,9 @@ MojoResult ChannelMojo::ReadFromMessageAttachmentSet( |
} |
MojoHandle wrapped_handle; |
- MojoResult wrap_result = mojo::embedder::CreatePlatformHandleWrapper( |
- mojo::embedder::ScopedPlatformHandle( |
- mojo::embedder::PlatformHandle(file.release())), |
+ MojoResult wrap_result = mojo::edk::CreatePlatformHandleWrapper( |
+ mojo::edk::ScopedPlatformHandle( |
+ mojo::edk::PlatformHandle(file.release())), |
&wrapped_handle); |
if (MOJO_RESULT_OK != wrap_result) { |
LOG(WARNING) << "Pipe failed to wrap handles. Closing: " |