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

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

Issue 1585493002: [mojo] Ports EDK (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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
Index: content/common/mojo/channel_init.cc
diff --git a/content/common/mojo/channel_init.cc b/content/common/mojo/channel_init.cc
index 967fb10be605c4e8e32d7e03709e5946a02b5a87..8eb156a044ee8d3379fda026bac7cc2e7f2e9fda 100644
--- a/content/common/mojo/channel_init.cc
+++ b/content/common/mojo/channel_init.cc
@@ -8,13 +8,28 @@
#include "base/bind.h"
#include "base/bind_helpers.h"
+#include "base/command_line.h"
#include "base/lazy_instance.h"
+#include "base/memory/ref_counted.h"
#include "base/message_loop/message_loop.h"
+#include "base/task_runner.h"
#include "base/thread_task_runner_handle.h"
+#include "mojo/edk/embedder/embedder.h"
#include "third_party/mojo/src/mojo/edk/embedder/embedder.h"
namespace content {
+namespace {
+
+void CallMessagePipeCallbackOnThread(
+ const base::Callback<void(mojo::ScopedMessagePipeHandle)>& callback,
+ scoped_refptr<base::TaskRunner> task_runner,
+ mojo::ScopedMessagePipeHandle pipe) {
+ task_runner->PostTask(FROM_HERE, base::Bind(callback, base::Passed(&pipe)));
+}
+
+} // namespace
+
ChannelInit::ChannelInit() : channel_info_(nullptr), weak_factory_(this) {}
ChannelInit::~ChannelInit() {
@@ -23,18 +38,30 @@ ChannelInit::~ChannelInit() {
base::Bind(&base::DoNothing), nullptr);
}
-mojo::ScopedMessagePipeHandle ChannelInit::Init(
+void ChannelInit::Init(
base::PlatformFile file,
- scoped_refptr<base::TaskRunner> io_thread_task_runner) {
+ scoped_refptr<base::TaskRunner> io_thread_task_runner,
+ const base::Callback<void(mojo::ScopedMessagePipeHandle)>& callback) {
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)),
- base::Bind(&ChannelInit::OnCreatedChannel, weak_factory_.GetWeakPtr(),
- base::Passed(&ipc_support)),
- base::ThreadTaskRunnerHandle::Get());
- return message_pipe;
+ if (base::CommandLine::ForCurrentProcess()->HasSwitch("use-new-edk")) {
+ mojo::edk::CreateMessagePipe(
+ mojo::edk::ScopedPlatformHandle(mojo::edk::PlatformHandle(file)),
+ base::Bind(&CallMessagePipeCallbackOnThread,
+ base::Bind(&ChannelInit::OnCreateMessagePipe,
+ weak_factory_.GetWeakPtr(),
+ base::Passed(&ipc_support),
+ callback),
+ base::ThreadTaskRunnerHandle::Get()));
+ } else {
+ mojo::ScopedMessagePipeHandle message_pipe = mojo::embedder::CreateChannel(
+ mojo::embedder::ScopedPlatformHandle(
+ mojo::embedder::PlatformHandle(file)),
+ base::Bind(&ChannelInit::OnCreatedChannel, weak_factory_.GetWeakPtr(),
+ base::Passed(&ipc_support)),
+ base::ThreadTaskRunnerHandle::Get());
+ callback.Run(std::move(message_pipe));
+ }
}
void ChannelInit::WillDestroySoon() {
@@ -59,4 +86,12 @@ void ChannelInit::OnCreatedChannel(
self->ipc_support_ = std::move(ipc_support);
}
+void ChannelInit::OnCreateMessagePipe(
+ scoped_ptr<IPC::ScopedIPCSupport> ipc_support,
+ const base::Callback<void(mojo::ScopedMessagePipeHandle)>& callback,
+ mojo::ScopedMessagePipeHandle pipe) {
+ ipc_support_ = std::move(ipc_support);
+ callback.Run(std::move(pipe));
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698