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

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

Issue 195993010: Adds the ability for the renderer to create the mojo channel (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: use_mojo Created 6 years, 9 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/mojo_channel_init.h ('k') | content/common/mojo/mojo_messages.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/common/mojo/mojo_channel_init.cc
diff --git a/content/common/mojo/mojo_channel_init.cc b/content/common/mojo/mojo_channel_init.cc
new file mode 100644
index 0000000000000000000000000000000000000000..aaace7224981c744f0ee1f4e64d1de3f18f04bb6
--- /dev/null
+++ b/content/common/mojo/mojo_channel_init.cc
@@ -0,0 +1,97 @@
+// Copyright (c) 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.
+
+#include "content/common/mojo/mojo_channel_init.h"
+
+#include "base/bind.h"
+#include "base/lazy_instance.h"
+#include "base/message_loop/message_loop.h"
+#include "base/synchronization/lock.h"
+#include "mojo/system/embedder/embedder.h"
+
+namespace content {
+
+namespace {
+
+struct Initializer {
+ Initializer() {
+ mojo::embedder::Init();
+ }
+};
+
+static base::LazyInstance<Initializer>::Leaky initializer =
+ LAZY_INSTANCE_INITIALIZER;
+
+// Initializes mojo. Use a lazy instance to ensure we only do this once.
+// TODO(sky): this likely wants to move to a more central location, such as
+// startup.
+void InitMojo() {
+ initializer.Get();
+}
+
+} // namespace
+
+MojoChannelInit::MojoChannelInit()
+ : main_thread_(base::MessageLoop::current()->message_loop_proxy()),
+ channel_info_(NULL),
+ weak_factory_(this) {
+}
+
+MojoChannelInit::~MojoChannelInit() {
+ bootstrap_message_pipe_.reset();
+ if (channel_info_) {
+ io_thread_task_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(&mojo::embedder::DestroyChannelOnIOThread, channel_info_));
+ }
+}
+
+void MojoChannelInit::Init(
+ base::PlatformFile file,
+ scoped_refptr<base::TaskRunner> io_thread_task_runner) {
+ DCHECK(!io_thread_task_runner_.get()); // Should only init once.
+ io_thread_task_runner_ = io_thread_task_runner;
+ InitMojo();
+ bootstrap_message_pipe_.reset(
+ mojo::Handle(
+ mojo::embedder::CreateChannel(
+ mojo::embedder::ScopedPlatformHandle(
+ mojo::embedder::PlatformHandle(file)),
+ io_thread_task_runner,
+ base::Bind(&MojoChannelInit::OnCreatedChannelOnIOThread,
+ weak_factory_.GetWeakPtr(),
+ main_thread_,
+ io_thread_task_runner))));
+}
+
+// static
+void MojoChannelInit::OnCreatedChannelOnIOThread(
+ base::WeakPtr<MojoChannelInit> host,
+ scoped_refptr<base::TaskRunner> main_thread,
+ scoped_refptr<base::TaskRunner> io_thread,
+ mojo::embedder::ChannelInfo* channel) {
+ main_thread->PostTask(
+ FROM_HERE,
+ base::Bind(&MojoChannelInit::OnCreatedChannelOnMainThread, host,
+ io_thread, channel));
+}
+
+// static
+void MojoChannelInit::OnCreatedChannelOnMainThread(
+ base::WeakPtr<MojoChannelInit> host,
+ scoped_refptr<base::TaskRunner> io_thread,
+ mojo::embedder::ChannelInfo* channel) {
+ // By the time we get here |host| may have been destroyed. If so, shutdown the
+ // channel.
+ if (!host.get()) {
+ io_thread->PostTask(
+ FROM_HERE,
+ base::Bind(&mojo::embedder::DestroyChannelOnIOThread, channel));
+ return;
+ }
+ host->channel_info_ = channel;
+}
+
+
+} // namespace content
« no previous file with comments | « content/common/mojo/mojo_channel_init.h ('k') | content/common/mojo/mojo_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698