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

Unified Diff: mojo/runner/child_process.cc

Issue 1350023003: Add a Mojo EDK for Chrome that uses one OS pipe per message pipe. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: move to mojo::edk namespace in preparation for runtim flag Created 5 years, 3 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: mojo/runner/child_process.cc
diff --git a/mojo/runner/child_process.cc b/mojo/runner/child_process.cc
index dc9b59f2a77cbfe5ac52fe6c376847fef41178f5..4877c81dcd3d43b1fb05bbfa59b32b1806ee6904 100644
--- a/mojo/runner/child_process.cc
+++ b/mojo/runner/child_process.cc
@@ -20,11 +20,6 @@
#include "base/thread_task_runner_handle.h"
#include "base/threading/thread.h"
#include "base/threading/thread_checker.h"
-#include "mojo/edk/embedder/embedder.h"
-#include "mojo/edk/embedder/platform_channel_pair.h"
-#include "mojo/edk/embedder/process_delegate.h"
-#include "mojo/edk/embedder/scoped_platform_handle.h"
-#include "mojo/edk/embedder/simple_platform_support.h"
#include "mojo/message_pump/message_pump_mojo.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/system/core.h"
@@ -32,6 +27,20 @@
#include "mojo/runner/native_application_support.h"
#include "mojo/runner/switches.h"
+#if defined(USE_CHROME_EDK)
+#include "mojo/edk/embedder/embedder.h"
+#include "mojo/edk/embedder/platform_channel_pair.h"
+#include "mojo/edk/embedder/process_delegate.h"
+#include "mojo/edk/embedder/scoped_platform_handle.h"
+#include "mojo/edk/embedder/simple_platform_support.h"
+#else
+#include "third_party/mojo/src/mojo/edk/embedder/embedder.h"
+#include "third_party/mojo/src/mojo/edk/embedder/platform_channel_pair.h"
+#include "third_party/mojo/src/mojo/edk/embedder/process_delegate.h"
+#include "third_party/mojo/src/mojo/edk/embedder/scoped_platform_handle.h"
+#include "third_party/mojo/src/mojo/edk/embedder/simple_platform_support.h"
+#endif
+
#if defined(OS_LINUX) && !defined(OS_ANDROID)
#include "base/rand_util.h"
#include "base/sys_info.h"
@@ -92,7 +101,11 @@ class Blocker {
class ChildControllerImpl;
// Should be created and initialized on the main thread.
+#if defined(USE_CHROME_EDK)
+class AppContext : public edk::ProcessDelegate {
+#else
class AppContext : public embedder::ProcessDelegate {
+#endif
public:
AppContext()
: io_thread_("io_thread"), controller_thread_("controller_thread") {}
@@ -100,7 +113,11 @@ class AppContext : public embedder::ProcessDelegate {
void Init() {
// Initialize Mojo before starting any threads.
+#if defined(USE_CHROME_EDK)
+ edk::Init(make_scoped_ptr(new edk::SimplePlatformSupport()));
+#else
embedder::Init(make_scoped_ptr(new embedder::SimplePlatformSupport()));
+#endif
// Create and start our I/O thread.
base::Thread::Options io_thread_options(base::MessageLoop::TYPE_IO, 0);
@@ -118,10 +135,15 @@ class AppContext : public embedder::ProcessDelegate {
controller_runner_ = controller_thread_.task_runner().get();
CHECK(controller_runner_.get());
+#if defined(USE_CHROME_EDK)
+ edk::InitIPCSupport(controller_runner_, this, io_runner_,
+ edk::ScopedPlatformHandle());
+#else
// TODO(vtl): This should be SLAVE, not NONE.
embedder::InitIPCSupport(embedder::ProcessType::NONE, controller_runner_,
this, io_runner_,
embedder::ScopedPlatformHandle());
+#endif
}
void Shutdown() {
@@ -151,7 +173,11 @@ class AppContext : public embedder::ProcessDelegate {
controller_.reset();
// Next shutdown IPC. We'll unblock the main thread in OnShutdownComplete().
+#if defined(USE_CHROME_EDK)
+ edk::ShutdownIPCSupport();
+#else
embedder::ShutdownIPCSupport();
+#endif
}
// ProcessDelegate implementation.
@@ -189,7 +215,11 @@ class ChildControllerImpl : public ChildController {
// etc.
static void Init(AppContext* app_context,
base::NativeLibrary app_library,
+#if defined(USE_CHROME_EDK)
+ edk::ScopedPlatformHandle platform_channel,
+#else
embedder::ScopedPlatformHandle platform_channel,
+#endif
const Blocker::Unblocker& unblocker) {
DCHECK(app_context);
DCHECK(platform_channel.is_valid());
@@ -199,11 +229,16 @@ class ChildControllerImpl : public ChildController {
scoped_ptr<ChildControllerImpl> impl(
new ChildControllerImpl(app_context, app_library, unblocker));
+#if defined(USE_CHROME_EDK)
+ ScopedMessagePipeHandle host_message_pipe(
+ edk::CreateMessagePipe(platform_channel.Pass()));
+#else
ScopedMessagePipeHandle host_message_pipe(embedder::CreateChannel(
platform_channel.Pass(),
base::Bind(&ChildControllerImpl::DidCreateChannel,
base::Unretained(impl.get())),
base::ThreadTaskRunnerHandle::Get()));
+#endif
impl->Bind(host_message_pipe.Pass());
@@ -242,17 +277,21 @@ class ChildControllerImpl : public ChildController {
: app_context_(app_context),
app_library_(app_library),
unblocker_(unblocker),
+#if !defined(USE_CHROME_EDK)
channel_info_(nullptr),
+#endif
binding_(this) {
binding_.set_connection_error_handler([this]() { OnConnectionError(); });
}
+#if !defined(USE_CHROME_EDK)
// Callback for |embedder::CreateChannel()|.
void DidCreateChannel(embedder::ChannelInfo* channel_info) {
DVLOG(2) << "ChildControllerImpl::DidCreateChannel()";
DCHECK(thread_checker_.CalledOnValidThread());
channel_info_ = channel_info;
}
+#endif
static void StartAppOnMainThread(
base::NativeLibrary app_library,
@@ -268,7 +307,9 @@ class ChildControllerImpl : public ChildController {
Blocker::Unblocker unblocker_;
StartAppCallback on_app_complete_;
+#if !defined(USE_CHROME_EDK)
embedder::ChannelInfo* channel_info_;
+#endif
Binding<ChildController> binding_;
DISALLOW_COPY_AND_ASSIGN(ChildControllerImpl);
@@ -323,9 +364,15 @@ int ChildProcessMain() {
#endif
}
+#if defined(USE_CHROME_EDK)
+ edk::ScopedPlatformHandle platform_channel =
+ edk::PlatformChannelPair::PassClientHandleFromParentProcess(
+ command_line);
+#else
embedder::ScopedPlatformHandle platform_channel =
embedder::PlatformChannelPair::PassClientHandleFromParentProcess(
command_line);
+#endif
CHECK(platform_channel.is_valid());
DCHECK(!base::MessageLoop::current());

Powered by Google App Engine
This is Rietveld 408576698