summaryrefslogtreecommitdiffstats
path: root/content/common/mojo
diff options
context:
space:
mode:
authorrockot <rockot@chromium.org>2015-03-03 08:31:04 -0800
committerCommit bot <commit-bot@chromium.org>2015-03-03 16:31:38 +0000
commitcbca72f3c9e31309a28b98624e1e0147c5dca7a1 (patch)
tree1bde2f531bed308832135e8d66a784afb0e258b1 /content/common/mojo
parent633e315de496ed52f2aed727ab36b23ea2fa3e87 (diff)
downloadchromium_src-cbca72f3c9e31309a28b98624e1e0147c5dca7a1.zip
chromium_src-cbca72f3c9e31309a28b98624e1e0147c5dca7a1.tar.gz
chromium_src-cbca72f3c9e31309a28b98624e1e0147c5dca7a1.tar.bz2
Update mojo sdk to rev 3d23dae011859a2aae49f1d1adde705c8e85d819
Highlights: - mojo::ChannelInit has been replaced with content::ChannelInit. - ScopedIPCSupport has been added so Mojo consumers can ensure the EDK is initialized. - single process mode now uses some evil tricks to get child threads to create their mojo client channels on the browser I/O thread. - several Android bits adapted to new interfaces - a number of tests have been adapted to work properly in spite of unconventional process arrangements BUG=None Review URL: https://codereview.chromium.org/954643002 Cr-Commit-Position: refs/heads/master@{#318883}
Diffstat (limited to 'content/common/mojo')
-rw-r--r--content/common/mojo/channel_init.cc80
-rw-r--r--content/common/mojo/channel_init.h64
2 files changed, 144 insertions, 0 deletions
diff --git a/content/common/mojo/channel_init.cc b/content/common/mojo/channel_init.cc
new file mode 100644
index 0000000..1599eb11
--- /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
diff --git a/content/common/mojo/channel_init.h b/content/common/mojo/channel_init.h
new file mode 100644
index 0000000..659d4bb
--- /dev/null
+++ b/content/common/mojo/channel_init.h
@@ -0,0 +1,64 @@
+// 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.
+
+#ifndef CONTENT_COMMON_MOJO_CHANNEL_INIT_H_
+#define CONTENT_COMMON_MOJO_CHANNEL_INIT_H_
+
+#include "base/files/file.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/weak_ptr.h"
+#include "content/common/content_export.h"
+#include "ipc/mojo/scoped_ipc_support.h"
+#include "third_party/mojo/src/mojo/edk/embedder/channel_info_forward.h"
+#include "third_party/mojo/src/mojo/public/cpp/system/message_pipe.h"
+
+namespace base {
+class MessageLoopProxy;
+class TaskRunner;
+}
+
+namespace content {
+
+// ChannelInit handles creation and destruction of the Mojo channel. It is not
+// thread-safe, but may be used on any single thread with a MessageLoop.
+class CONTENT_EXPORT ChannelInit {
+ public:
+ ChannelInit();
+ ~ChannelInit();
+
+ // Initializes the channel. This takes ownership of |file|. Returns the
+ // primordial MessagePipe for the channel.
+ mojo::ScopedMessagePipeHandle Init(
+ base::PlatformFile file,
+ scoped_refptr<base::TaskRunner> io_thread_task_runner);
+
+ // Notifies the channel that we (hence it) will soon be destroyed.
+ void WillDestroySoon();
+
+ // Get/Set a shared I/O TaskRunner for children to use in single process mode.
+ static scoped_refptr<base::TaskRunner> GetSingleProcessIOTaskRunner();
+ static void SetSingleProcessIOTaskRunner(
+ scoped_refptr<base::TaskRunner> io_task_runner);
+
+ private:
+ // Invoked on the thread on which this object lives once the channel has been
+ // established. This is a static method that takes a weak pointer to self,
+ // since we want to destroy the channel if we were destroyed first.
+ static void OnCreatedChannel(
+ base::WeakPtr<ChannelInit> self,
+ scoped_ptr<IPC::ScopedIPCSupport> ipc_support,
+ mojo::embedder::ChannelInfo* channel);
+
+ // If non-null the channel has been established.
+ mojo::embedder::ChannelInfo* channel_info_;
+
+ scoped_ptr<IPC::ScopedIPCSupport> ipc_support_;
+ base::WeakPtrFactory<ChannelInit> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(ChannelInit);
+};
+
+} // namespace content
+
+#endif // CONTENT_COMMON_MOJO_CHANNEL_INIT_H_