summaryrefslogtreecommitdiffstats
path: root/content/common/mojo
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-15 22:00:07 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-15 22:00:07 +0000
commit907e1d669f44c15388e8f7183cb8ea706dae7771 (patch)
treea770cfeee5e08b24827a494a99e48f8e1df4fec4 /content/common/mojo
parente1c12bc9c1497a2081f1f23071f4d277fafabac8 (diff)
downloadchromium_src-907e1d669f44c15388e8f7183cb8ea706dae7771.zip
chromium_src-907e1d669f44c15388e8f7183cb8ea706dae7771.tar.gz
chromium_src-907e1d669f44c15388e8f7183cb8ea706dae7771.tar.bz2
Adds the ability for the renderer to create the mojo channel
This is initiated and owned by RenderProcessHost. I've added a method to RenderProcessHostImpl to create the channel. No one is calling it yet, that will come after this. RenderProcessHostImpl::CreateMojoChannel initiates the connection and sends an IPC message to the renderer. The renderer than creates its end of the connection. End to end test will come once I've added all the pieces. BUG=none TEST=none R=darin@chromium.org, tsepez@chromium.org, viettrungluu@chromium.org Review URL: https://codereview.chromium.org/195993010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@257342 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/common/mojo')
-rw-r--r--content/common/mojo/OWNERS25
-rw-r--r--content/common/mojo/mojo_channel_init.cc97
-rw-r--r--content/common/mojo/mojo_channel_init.h72
-rw-r--r--content/common/mojo/mojo_messages.h22
4 files changed, 216 insertions, 0 deletions
diff --git a/content/common/mojo/OWNERS b/content/common/mojo/OWNERS
new file mode 100644
index 0000000..182689f
--- /dev/null
+++ b/content/common/mojo/OWNERS
@@ -0,0 +1,25 @@
+# Changes to IPC messages require a security review to avoid introducing
+# new sandbox escapes.
+per-file *_message*.h=set noparent
+per-file *_message*.h=cdn@chromium.org
+per-file *_message*.h=cevans@chromium.org
+per-file *_message*.h=dcheng@chromium.org
+per-file *_message*.h=inferno@chromium.org
+per-file *_message*.h=jln@chromium.org
+per-file *_message*.h=jschuh@chromium.org
+per-file *_message*.h=kenrb@chromium.org
+per-file *_message*.h=nasko@chromium.org
+per-file *_message*.h=palmer@chromium.org
+per-file *_message*.h=tsepez@chromium.org
+
+per-file *param_traits*.h=set noparent
+per-file *param_traits*.h=cdn@chromium.org
+per-file *param_traits*.h=cevans@chromium.org
+per-file *param_traits*.h=dcheng@chromium.org
+per-file *param_traits*.h=inferno@chromium.org
+per-file *param_traits*.h=jln@chromium.org
+per-file *param_traits*.h=jschuh@chromium.org
+per-file *param_traits*.h=kenrb@chromium.org
+per-file *param_traits*.h=nasko@chromium.org
+per-file *param_traits*.h=palmer@chromium.org
+per-file *param_traits*.h=tsepez@chromium.org
diff --git a/content/common/mojo/mojo_channel_init.cc b/content/common/mojo/mojo_channel_init.cc
new file mode 100644
index 0000000..aaace72
--- /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
diff --git a/content/common/mojo/mojo_channel_init.h b/content/common/mojo/mojo_channel_init.h
new file mode 100644
index 0000000..56c6230
--- /dev/null
+++ b/content/common/mojo/mojo_channel_init.h
@@ -0,0 +1,72 @@
+// 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.
+
+#ifndef CONTENT_COMMON_MOJO_MOJO_CHANNEL_INIT_H_
+#define CONTENT_COMMON_MOJO_MOJO_CHANNEL_INIT_H_
+
+#include "base/memory/ref_counted.h"
+#include "base/memory/weak_ptr.h"
+#include "base/platform_file.h"
+#include "content/common/content_export.h"
+#include "mojo/public/system/core_cpp.h"
+
+namespace base {
+class MessageLoopProxy;
+class TaskRunner;
+}
+
+namespace mojo {
+namespace embedder {
+struct ChannelInfo;
+}
+}
+
+namespace content {
+
+// MojoChannelInit handle creation (and destruction) of the mojo channel. It is
+// expected that this class is created and destroyed on the main thread.
+class CONTENT_EXPORT MojoChannelInit {
+ public:
+ MojoChannelInit();
+ ~MojoChannelInit();
+
+ // Inits the channel. This takes ownership of |file|.
+ void Init(base::PlatformFile file,
+ scoped_refptr<base::TaskRunner> io_thread_task_runner);
+
+ bool is_handle_valid() const { return bootstrap_message_pipe_.is_valid(); }
+
+ private:
+ // Invoked on the IO thread once the channel has been established.
+ static void OnCreatedChannelOnIOThread(
+ base::WeakPtr<MojoChannelInit> host,
+ scoped_refptr<base::TaskRunner> main_thread,
+ scoped_refptr<base::TaskRunner> io_thread,
+ mojo::embedder::ChannelInfo* channel);
+
+ // Invoked on the main thread once the channel has been established.
+ static void OnCreatedChannelOnMainThread(
+ base::WeakPtr<MojoChannelInit> host,
+ scoped_refptr<base::TaskRunner> io_thread,
+ mojo::embedder::ChannelInfo* channel);
+
+ // Thread where this object lives.
+ scoped_refptr<base::TaskRunner> main_thread_;
+
+ scoped_refptr<base::TaskRunner> io_thread_task_runner_;
+
+ // If non-null the channel has been established.
+ mojo::embedder::ChannelInfo* channel_info_;
+
+ // The handle from channel creation.
+ mojo::ScopedHandle bootstrap_message_pipe_;
+
+ base::WeakPtrFactory<MojoChannelInit> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(MojoChannelInit);
+};
+
+} // namespace content
+
+#endif // CONTENT_COMMON_MOJO_MOJO_CHANNEL_INIT_H_
diff --git a/content/common/mojo/mojo_messages.h b/content/common/mojo/mojo_messages.h
new file mode 100644
index 0000000..31cea20
--- /dev/null
+++ b/content/common/mojo/mojo_messages.h
@@ -0,0 +1,22 @@
+// 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.
+
+// IPC messages for mojo.
+// Multiply-included message file, hence no include guard.
+
+#include "base/basictypes.h"
+#include "content/common/content_export.h"
+#include "content/public/common/common_param_traits.h"
+#include "ipc/ipc_message_macros.h"
+#include "ipc/ipc_message_utils.h"
+#include "ipc/ipc_param_traits.h"
+#include "ipc/param_traits_macros.h"
+
+#undef IPC_MESSAGE_EXPORT
+#define IPC_MESSAGE_EXPORT CONTENT_EXPORT
+
+#define IPC_MESSAGE_START MojoMsgStart
+
+IPC_MESSAGE_CONTROL1(MojoMsg_ChannelCreated,
+ IPC::PlatformFileForTransit /* handle */);