Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(177)

Unified Diff: content/common/mojo/channel_init.cc

Issue 954643002: Update mojo sdk to rev 3d23dae011859a2aae49f1d1adde705c8e85d819 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: use run_renderer_in_process() Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/common/mojo/channel_init.h ('k') | content/content_common.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/common/mojo/channel_init.cc
diff --git a/content/common/mojo/channel_init.cc b/content/common/mojo/channel_init.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1599eb11d12dda89890fbc95a70bfab41a69eb96
--- /dev/null
+++ b/content/common/mojo/channel_init.cc
@@ -0,0 +1,80 @@
+// Copyright 2015 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.
+
+#include "content/common/mojo/channel_init.h"
+
+#include "base/bind.h"
+#include "base/bind_helpers.h"
+#include "base/lazy_instance.h"
+#include "base/message_loop/message_loop.h"
+#include "third_party/mojo/src/mojo/edk/embedder/embedder.h"
+
+namespace content {
+
+namespace {
+
+base::LazyInstance<scoped_refptr<base::TaskRunner>>
+ g_single_process_task_runner = LAZY_INSTANCE_INITIALIZER;
+
+} // namespace
+
+ChannelInit::ChannelInit() : channel_info_(nullptr), weak_factory_(this) {}
+
+ChannelInit::~ChannelInit() {
+ if (channel_info_)
+ mojo::embedder::DestroyChannel(channel_info_,
+ base::Bind(&base::DoNothing), nullptr);
+}
+
+mojo::ScopedMessagePipeHandle ChannelInit::Init(
+ base::PlatformFile file,
+ scoped_refptr<base::TaskRunner> io_thread_task_runner) {
+ scoped_ptr<IPC::ScopedIPCSupport> ipc_support(
+ new IPC::ScopedIPCSupport(io_thread_task_runner));
+ mojo::ScopedMessagePipeHandle message_pipe =
+ mojo::embedder::CreateChannel(
+ mojo::embedder::ScopedPlatformHandle(
+ mojo::embedder::PlatformHandle(file)),
+ io_thread_task_runner,
+ base::Bind(&ChannelInit::OnCreatedChannel,
+ weak_factory_.GetWeakPtr(),
+ base::Passed(&ipc_support)),
+ base::MessageLoop::current()->task_runner()).Pass();
+ return message_pipe.Pass();
+}
+
+void ChannelInit::WillDestroySoon() {
+ if (channel_info_)
+ mojo::embedder::WillDestroyChannelSoon(channel_info_);
+}
+
+// static
+scoped_refptr<base::TaskRunner> ChannelInit::GetSingleProcessIOTaskRunner() {
+ return g_single_process_task_runner.Get();
+}
+
+// static
+void ChannelInit::SetSingleProcessIOTaskRunner(
+ scoped_refptr<base::TaskRunner> io_task_runner) {
+ g_single_process_task_runner.Get() = io_task_runner;
+}
+
+// static
+void ChannelInit::OnCreatedChannel(
+ base::WeakPtr<ChannelInit> self,
+ scoped_ptr<IPC::ScopedIPCSupport> ipc_support,
+ mojo::embedder::ChannelInfo* channel) {
+ // If |self| was already destroyed, shut the channel down.
+ if (!self) {
+ mojo::embedder::DestroyChannel(channel,
+ base::Bind(&base::DoNothing), nullptr);
+ return;
+ }
+
+ DCHECK(!self->channel_info_);
+ self->channel_info_ = channel;
+ self->ipc_support_ = ipc_support.Pass();
+}
+
+} // namespace content
« no previous file with comments | « content/common/mojo/channel_init.h ('k') | content/content_common.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698