Chromium Code Reviews| 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 1bc85b51f168de0d8bc05c6909e59fe1d5f3771c..ffafa4b66446cdf896a3caa7e3aa0b262ec038c5 100644 |
| --- a/content/browser/mojo/mojo_shell_client_host.cc |
| +++ b/content/browser/mojo/mojo_shell_client_host.cc |
| @@ -20,6 +20,7 @@ namespace content { |
| namespace { |
| const char kMojoShellInstanceURL[] = "mojo_shell_instance_url"; |
| +const char kMojoPlatformFile[] = "mojo_platform_file"; |
| void DidCreateChannel(mojo::embedder::ChannelInfo* info) {} |
| @@ -45,16 +46,35 @@ 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)); |
| +} |
| + |
| } // namespace |
| void RegisterChildWithExternalShell(int child_process_id, |
| - base::ProcessHandle process_handle, |
| RenderProcessHost* render_process_host) { |
| // Some process types get created before the main message loop. |
| if (!MojoShellConnection::Get()) |
| @@ -88,8 +108,7 @@ void RegisterChildWithExternalShell(int child_process_id, |
| // Send the other end to the child via Chrome IPC. |
| base::PlatformFile client_file = PlatformFileFromScopedPlatformHandle( |
| platform_channel_pair.PassClientHandle()); |
| - render_process_host->Send(new MojoMsg_BindExternalMojoShellHandle( |
| - IPC::GetFileHandleForProcess(client_file, process_handle, true))); |
| + SetMojoPlatformFile(render_process_host, client_file); |
|
Ben Goodger (Google)
2015/11/25 04:07:28
Instead of structuring it this way, I'd do this:
Fady Samuel
2015/11/25 17:45:52
I think this structuring is necessary. The mojo sh
|
| // Store the URL on the RPH so client code can access it later via |
| // GetMojoApplicationInstanceURL(). |
| @@ -103,4 +122,14 @@ std::string GetMojoApplicationInstanceURL( |
| return instance_url ? instance_url->get() : std::string(); |
| } |
| +void BindExternalMojoShellHandle(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 |