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

Unified Diff: content/browser/mojo/mojo_shell_client_host.cc

Issue 1748973003: Revert of Bootstrap Mojo IPC independent of Chrome IPC (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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/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 0bdd217e713f0ea6923b63214ace3648d5a31df3..2cc0da645cdc0014345896ca8abdcabad2e5b599 100644
--- a/content/browser/mojo/mojo_shell_client_host.cc
+++ b/content/browser/mojo/mojo_shell_client_host.cc
@@ -11,6 +11,7 @@
#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"
@@ -18,7 +19,8 @@
#include "ipc/ipc_sender.h"
#include "mojo/converters/network/network_type_converters.h"
#include "mojo/edk/embedder/embedder.h"
-#include "mojo/public/cpp/system/message_pipe.h"
+#include "mojo/edk/embedder/platform_channel_pair.h"
+#include "mojo/edk/embedder/scoped_platform_handle.h"
#include "mojo/shell/public/cpp/connector.h"
#include "mojo/shell/public/interfaces/application_manager.mojom.h"
@@ -26,11 +28,16 @@
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:
- explicit InstanceURL(const std::string& instance_url)
- : instance_url_(instance_url) {}
+ InstanceURL(const std::string& instance_url) : instance_url_(instance_url) {}
~InstanceURL() override {}
std::string get() const { return instance_url_; }
@@ -41,10 +48,30 @@
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 {
@@ -83,21 +110,28 @@
} // namespace
-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();
+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);
+
mojo::ScopedMessagePipeHandle request_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::edk::CreateMessagePipe(std::move(parent_pipe));
mojo::shell::mojom::ApplicationManagerPtr application_manager;
MojoShellConnection::Get()->GetConnector()->ConnectToInterface(
@@ -127,8 +161,6 @@
// 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(
@@ -138,4 +170,15 @@
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
« no previous file with comments | « content/browser/mojo/mojo_shell_client_host.h ('k') | content/browser/renderer_host/render_process_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698