Index: content/child/child_thread_impl.cc |
diff --git a/content/child/child_thread_impl.cc b/content/child/child_thread_impl.cc |
index dbf6c3be0c2d5c13d2029ae0554bf191ce8b443f..837a9d4051bea591f8e560d8828e87b7100c795d 100644 |
--- a/content/child/child_thread_impl.cc |
+++ b/content/child/child_thread_impl.cc |
@@ -23,6 +23,7 @@ |
#include "base/single_thread_task_runner.h" |
#include "base/strings/string_number_conversions.h" |
#include "base/strings/string_util.h" |
+#include "base/strings/utf_string_conversions.h" |
#include "base/synchronization/condition_variable.h" |
#include "base/synchronization/lock.h" |
#include "base/thread_task_runner_handle.h" |
@@ -52,10 +53,10 @@ |
#include "content/child/websocket_dispatcher.h" |
#include "content/common/child_process_messages.h" |
#include "content/common/in_process_child_thread_params.h" |
-#include "content/common/mojo/mojo_messages.h" |
#include "content/public/common/content_switches.h" |
#include "ipc/attachment_broker.h" |
#include "ipc/attachment_broker_unprivileged.h" |
+#include "ipc/ipc_descriptors.h" |
#include "ipc/ipc_logging.h" |
#include "ipc/ipc_platform_file.h" |
#include "ipc/ipc_switches.h" |
@@ -68,6 +69,10 @@ |
#include "ui/ozone/public/client_native_pixmap_factory.h" |
#endif |
+#if defined(OS_POSIX) |
+#include "base/posix/global_descriptors.h" |
+#endif |
+ |
#if defined(MOJO_SHELL_CLIENT) |
#include "content/common/mojo/mojo_shell_connection_impl.h" |
#endif |
@@ -248,6 +253,30 @@ void QuitClosure::PostQuitFromNonMainThread() { |
base::LazyInstance<QuitClosure> g_quit_closure = LAZY_INSTANCE_INITIALIZER; |
#endif |
+void InitializeMojoIPCChannel() { |
+ mojo::edk::ScopedPlatformHandle platform_channel; |
+#if defined(OS_WIN) |
+ std::wstring pipe_name = base::UTF8ToWide( |
+ base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
+ switches::kMojoChannelName)); |
+ std::string pipe_secret = |
+ base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
+ switches::kMojoChannelSecret); |
+ const DWORD kFlags = |
+ SECURITY_SQOS_PRESENT | SECURITY_ANONYMOUS | FILE_FLAG_OVERLAPPED; |
+ platform_channel.reset(mojo::edk::PlatformHandle( |
+ CreateFileW(pipe_name.c_str(), GENERIC_READ | GENERIC_WRITE, 0, |
+ nullptr, OPEN_EXISTING, kFlags, nullptr))); |
+ PCHECK(platform_channel.is_valid()); |
+ mojo::edk::SetParentPipeHandle(std::move(platform_channel), pipe_secret); |
+#elif defined(OS_POSIX) |
+ platform_channel.reset(mojo::edk::PlatformHandle( |
+ base::GlobalDescriptors::GetInstance()->Get(kMojoIPCChannel))); |
+ CHECK(platform_channel.is_valid()); |
+ mojo::edk::SetParentPipeHandle(std::move(platform_channel)); |
+#endif |
+} |
+ |
} // namespace |
ChildThread* ChildThread::Get() { |
@@ -387,7 +416,22 @@ void ChildThreadImpl::Init(const Options& options) { |
if (!IsInBrowserProcess()) { |
// Don't double-initialize IPC support in single-process mode. |
mojo_ipc_support_.reset(new IPC::ScopedIPCSupport(GetIOTaskRunner())); |
+ |
+ InitializeMojoIPCChannel(); |
+ } |
+ |
+#if defined(MOJO_SHELL_CLIENT) |
+ // If this process was launched with a primordial pipe token, we exchange it |
+ // for a pipe to connect to the shell. |
+ std::string pipe_token = |
+ base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
+ switches::kMojoPrimordialPipeToken); |
+ if (!pipe_token.empty() && MojoShellConnectionImpl::Get()) { |
+ mojo::ScopedMessagePipeHandle pipe = |
+ mojo::edk::CreateChildMessagePipe(pipe_token); |
+ MojoShellConnectionImpl::Get()->BindToMessagePipe(std::move(pipe)); |
} |
+#endif |
mojo_application_.reset(new MojoApplication(GetIOTaskRunner())); |
@@ -622,10 +666,6 @@ bool ChildThreadImpl::OnMessageReceived(const IPC::Message& msg) { |
OnProfilingPhaseCompleted) |
IPC_MESSAGE_HANDLER(ChildProcessMsg_SetProcessBackgrounded, |
OnProcessBackgrounded) |
- IPC_MESSAGE_HANDLER(MojoMsg_BindExternalMojoShellHandle, |
- OnBindExternalMojoShellHandle) |
- IPC_MESSAGE_HANDLER(ChildProcessMsg_SetMojoParentPipeHandle, |
- OnSetMojoParentPipeHandle) |
IPC_MESSAGE_UNHANDLED(handled = false) |
IPC_END_MESSAGE_MAP() |
@@ -680,27 +720,6 @@ void ChildThreadImpl::OnProfilingPhaseCompleted(int profiling_phase) { |
ThreadData::OnProfilingPhaseCompleted(profiling_phase); |
} |
-void ChildThreadImpl::OnBindExternalMojoShellHandle( |
- const IPC::PlatformFileForTransit& file) { |
-#if defined(MOJO_SHELL_CLIENT) |
-#if defined(OS_POSIX) |
- base::PlatformFile handle = file.fd; |
-#elif defined(OS_WIN) |
- base::PlatformFile handle = file; |
-#endif |
- mojo::ScopedMessagePipeHandle pipe = |
- mojo_shell_channel_init_.Init(handle, GetIOTaskRunner()); |
- MojoShellConnectionImpl::Get()->BindToMessagePipe(std::move(pipe)); |
-#endif // defined(MOJO_SHELL_CLIENT) |
-} |
- |
-void ChildThreadImpl::OnSetMojoParentPipeHandle( |
- const IPC::PlatformFileForTransit& file) { |
- mojo::edk::SetParentPipeHandle( |
- mojo::edk::ScopedPlatformHandle(mojo::edk::PlatformHandle( |
- IPC::PlatformFileForTransitToPlatformFile(file)))); |
-} |
- |
ChildThreadImpl* ChildThreadImpl::current() { |
return g_lazy_tls.Pointer()->Get(); |
} |