Index: content/browser/mojo/mojo_shell_client_host.cc |
diff --git a/content/browser/mojo/mojo_shell_client_host.cc b/content/browser/mojo/mojo_shell_client_host.cc |
index 2cc0da645cdc0014345896ca8abdcabad2e5b599..0bdd217e713f0ea6923b63214ace3648d5a31df3 100644 |
--- a/content/browser/mojo/mojo_shell_client_host.cc |
+++ b/content/browser/mojo/mojo_shell_client_host.cc |
@@ -11,7 +11,6 @@ |
#include "base/strings/stringprintf.h" |
#include "base/thread_task_runner_handle.h" |
#include "build/build_config.h" |
-#include "content/common/mojo/mojo_messages.h" |
#include "content/public/browser/browser_thread.h" |
#include "content/public/browser/render_process_host.h" |
#include "content/public/browser/render_process_host_observer.h" |
@@ -19,8 +18,7 @@ |
#include "ipc/ipc_sender.h" |
#include "mojo/converters/network/network_type_converters.h" |
#include "mojo/edk/embedder/embedder.h" |
-#include "mojo/edk/embedder/platform_channel_pair.h" |
-#include "mojo/edk/embedder/scoped_platform_handle.h" |
+#include "mojo/public/cpp/system/message_pipe.h" |
#include "mojo/shell/public/cpp/connector.h" |
#include "mojo/shell/public/interfaces/application_manager.mojom.h" |
@@ -28,16 +26,11 @@ namespace content { |
namespace { |
const char kMojoShellInstanceURL[] = "mojo_shell_instance_url"; |
-const char kMojoPlatformFile[] = "mojo_platform_file"; |
- |
-base::PlatformFile PlatformFileFromScopedPlatformHandle( |
- mojo::edk::ScopedPlatformHandle handle) { |
- return handle.release().handle; |
-} |
class InstanceURL : public base::SupportsUserData::Data { |
public: |
- InstanceURL(const std::string& instance_url) : instance_url_(instance_url) {} |
+ explicit InstanceURL(const std::string& instance_url) |
+ : instance_url_(instance_url) {} |
~InstanceURL() override {} |
std::string get() const { return instance_url_; } |
@@ -48,32 +41,12 @@ class InstanceURL : public base::SupportsUserData::Data { |
DISALLOW_COPY_AND_ASSIGN(InstanceURL); |
}; |
-class InstanceShellHandle : public base::SupportsUserData::Data { |
- public: |
- InstanceShellHandle(base::PlatformFile shell_handle) |
- : shell_handle_(shell_handle) {} |
- ~InstanceShellHandle() override {} |
- |
- base::PlatformFile get() const { return shell_handle_; } |
- |
- private: |
- base::PlatformFile shell_handle_; |
- |
- DISALLOW_COPY_AND_ASSIGN(InstanceShellHandle); |
-}; |
- |
void SetMojoApplicationInstanceURL(RenderProcessHost* render_process_host, |
const std::string& instance_url) { |
render_process_host->SetUserData(kMojoShellInstanceURL, |
new InstanceURL(instance_url)); |
} |
-void SetMojoPlatformFile(RenderProcessHost* render_process_host, |
- base::PlatformFile platform_file) { |
- render_process_host->SetUserData(kMojoPlatformFile, |
- new InstanceShellHandle(platform_file)); |
-} |
- |
class PIDSender : public RenderProcessHostObserver { |
public: |
PIDSender( |
@@ -110,28 +83,21 @@ class PIDSender : public RenderProcessHostObserver { |
} // namespace |
-void RegisterChildWithExternalShell(int child_process_id, |
- int instance_id, |
- RenderProcessHost* render_process_host) { |
- // Some process types get created before the main message loop. |
- if (!MojoShellConnection::Get()) |
- return; |
- |
- // Create the channel to be shared with the target process. |
- mojo::edk::HandlePassingInformation handle_passing_info; |
- mojo::edk::PlatformChannelPair platform_channel_pair; |
- |
- // Give one end to the shell so that it can create an instance. |
- mojo::edk::ScopedPlatformHandle parent_pipe = |
- platform_channel_pair.PassServerHandle(); |
- |
- // Send the other end to the child via Chrome IPC. |
- base::PlatformFile client_file = PlatformFileFromScopedPlatformHandle( |
- platform_channel_pair.PassClientHandle()); |
- SetMojoPlatformFile(render_process_host, client_file); |
- |
+std::string RegisterChildWithExternalShell( |
+ int child_process_id, |
+ int instance_id, |
+ RenderProcessHost* render_process_host) { |
+ // Generate a token and create a pipe which is bound to it. This pipe is |
+ // passed to the shell if one is available. |
+ std::string pipe_token = mojo::edk::GenerateRandomToken(); |
mojo::ScopedMessagePipeHandle request_pipe = |
- mojo::edk::CreateMessagePipe(std::move(parent_pipe)); |
+ mojo::edk::CreateParentMessagePipe(pipe_token); |
+ |
+ // Some process types get created before the main message loop. In this case |
+ // the shell request pipe will simply be closed, and the child can detect |
+ // this. |
+ if (!MojoShellConnection::Get()) |
+ return pipe_token; |
mojo::shell::mojom::ApplicationManagerPtr application_manager; |
MojoShellConnection::Get()->GetConnector()->ConnectToInterface( |
@@ -161,6 +127,8 @@ void RegisterChildWithExternalShell(int child_process_id, |
// Store the URL on the RPH so client code can access it later via |
// GetMojoApplicationInstanceURL(). |
SetMojoApplicationInstanceURL(render_process_host, url); |
+ |
+ return pipe_token; |
} |
std::string GetMojoApplicationInstanceURL( |
@@ -170,15 +138,4 @@ std::string GetMojoApplicationInstanceURL( |
return instance_url ? instance_url->get() : std::string(); |
} |
-void SendExternalMojoShellHandleToChild( |
- base::ProcessHandle process_handle, |
- RenderProcessHost* render_process_host) { |
- InstanceShellHandle* client_file = static_cast<InstanceShellHandle*>( |
- render_process_host->GetUserData(kMojoPlatformFile)); |
- if (!client_file) |
- return; |
- render_process_host->Send(new MojoMsg_BindExternalMojoShellHandle( |
- IPC::GetFileHandleForProcess(client_file->get(), process_handle, true))); |
-} |
- |
} // namespace content |