Index: content/child/child_thread_impl.cc |
diff --git a/content/child/child_thread_impl.cc b/content/child/child_thread_impl.cc |
index 685fded9b0544f075196d5d6b3c2448775452f26..013d1d51302d1920edcbe76ec7b463357789c8f5 100644 |
--- a/content/child/child_thread_impl.cc |
+++ b/content/child/child_thread_impl.cc |
@@ -56,6 +56,7 @@ |
#include "ipc/ipc_sync_channel.h" |
#include "ipc/ipc_sync_message_filter.h" |
#include "ipc/mojo/ipc_channel_mojo.h" |
+#include "ipc/mojo/scoped_ipc_support.h" |
#if defined(OS_WIN) |
#include "content/common/handle_enumerator_win.h" |
@@ -204,6 +205,45 @@ |
return ChildThreadImpl::current(); |
} |
+// Mojo client channel delegate to be used in single process mode. |
+class ChildThreadImpl::SingleProcessChannelDelegate |
+ : public IPC::ChannelMojo::Delegate { |
+ public: |
+ explicit SingleProcessChannelDelegate( |
+ scoped_refptr<base::SequencedTaskRunner> io_runner) |
+ : io_runner_(io_runner), weak_factory_(this) {} |
+ |
+ ~SingleProcessChannelDelegate() override {} |
+ |
+ base::WeakPtr<IPC::ChannelMojo::Delegate> ToWeakPtr() override { |
+ return weak_factory_.GetWeakPtr(); |
+ } |
+ |
+ scoped_refptr<base::TaskRunner> GetIOTaskRunner() override { |
+ return io_runner_; |
+ } |
+ |
+ void OnChannelCreated(base::WeakPtr<IPC::ChannelMojo> channel) override {} |
+ |
+ void DeleteSoon() { |
+ io_runner_->PostTask( |
+ FROM_HERE, |
+ base::Bind(&base::DeletePointer<SingleProcessChannelDelegate>, |
+ base::Unretained(this))); |
+ } |
+ |
+ private: |
+ scoped_refptr<base::SequencedTaskRunner> io_runner_; |
+ base::WeakPtrFactory<IPC::ChannelMojo::Delegate> weak_factory_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(SingleProcessChannelDelegate); |
+}; |
+ |
+void ChildThreadImpl::SingleProcessChannelDelegateDeleter::operator()( |
+ SingleProcessChannelDelegate* delegate) const { |
+ delegate->DeleteSoon(); |
+} |
+ |
ChildThreadImpl::Options::Options() |
: channel_name(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
switches::kProcessChannelID)), |
@@ -281,9 +321,15 @@ |
VLOG(1) << "Mojo is enabled on child"; |
scoped_refptr<base::SequencedTaskRunner> io_task_runner = GetIOTaskRunner(); |
DCHECK(io_task_runner); |
- channel_->Init(IPC::ChannelMojo::CreateClientFactory( |
- nullptr, io_task_runner, channel_name_), |
- create_pipe_now); |
+ if (IsInBrowserProcess()) |
+ single_process_channel_delegate_.reset( |
+ new SingleProcessChannelDelegate(io_task_runner)); |
+ ipc_support_.reset(new IPC::ScopedIPCSupport(io_task_runner)); |
+ channel_->Init( |
+ IPC::ChannelMojo::CreateClientFactory( |
+ single_process_channel_delegate_.get(), |
+ channel_name_), |
+ create_pipe_now); |
return; |
} |