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

Side by Side Diff: content/browser/mojo/mojo_child_connection.cc

Issue 1828733004: Load application manifests from resources (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/mojo/mojo_child_connection.h" 5 #include "content/browser/mojo/mojo_child_connection.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
12 #include "base/thread_task_runner_handle.h" 12 #include "base/thread_task_runner_handle.h"
13 #include "build/build_config.h" 13 #include "build/build_config.h"
14 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/content_browser_client.h"
15 #include "content/public/browser/render_process_host.h" 16 #include "content/public/browser/render_process_host.h"
16 #include "content/public/browser/render_process_host_observer.h" 17 #include "content/public/browser/render_process_host_observer.h"
17 #include "content/public/common/mojo_shell_connection.h" 18 #include "content/public/common/mojo_shell_connection.h"
18 #include "ipc/ipc_sender.h" 19 #include "ipc/ipc_sender.h"
19 #include "mojo/converters/network/network_type_converters.h" 20 #include "mojo/converters/network/network_type_converters.h"
20 #include "mojo/edk/embedder/embedder.h" 21 #include "mojo/edk/embedder/embedder.h"
21 #include "mojo/public/cpp/system/message_pipe.h" 22 #include "mojo/public/cpp/system/message_pipe.h"
22 #include "mojo/shell/public/cpp/connector.h" 23 #include "mojo/shell/public/cpp/connector.h"
23 #include "mojo/shell/public/interfaces/shell.mojom.h" 24 #include "mojo/shell/public/interfaces/shell.mojom.h"
24 #include "mojo/shell/public/interfaces/shell_client.mojom.h" 25 #include "mojo/shell/public/interfaces/shell_client.mojom.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 std::string pipe_token = mojo::edk::GenerateRandomToken(); 95 std::string pipe_token = mojo::edk::GenerateRandomToken();
95 mojo::ScopedMessagePipeHandle shell_client_pipe = 96 mojo::ScopedMessagePipeHandle shell_client_pipe =
96 mojo::edk::CreateParentMessagePipe(pipe_token); 97 mojo::edk::CreateParentMessagePipe(pipe_token);
97 98
98 // Some process types get created before the main message loop. In this case 99 // Some process types get created before the main message loop. In this case
99 // the shell request pipe will simply be closed, and the child can detect 100 // the shell request pipe will simply be closed, and the child can detect
100 // this. 101 // this.
101 if (!MojoShellConnection::Get()) 102 if (!MojoShellConnection::Get())
102 return pipe_token; 103 return pipe_token;
103 104
105 std::string child_name =
106 GetContentClient()->browser()->GetMojoApplicationNameForProcess(
107 PROCESS_TYPE_RENDERER);
108 if (child_name.empty())
109 return pipe_token;
Ben Goodger (Google) 2016/03/30 22:27:50 what happens in this case? how does the caller rea
Ken Rockot(use gerrit already) 2016/03/31 18:55:48 The caller doesn't know about any failures here, i
110
104 mojo::shell::mojom::ShellClientPtr client; 111 mojo::shell::mojom::ShellClientPtr client;
105 client.Bind(mojo::InterfacePtrInfo<mojo::shell::mojom::ShellClient>( 112 client.Bind(mojo::InterfacePtrInfo<mojo::shell::mojom::ShellClient>(
106 std::move(shell_client_pipe), 0u)); 113 std::move(shell_client_pipe), 0u));
107 mojo::shell::mojom::PIDReceiverPtr pid_receiver; 114 mojo::shell::mojom::PIDReceiverPtr pid_receiver;
108 mojo::shell::mojom::PIDReceiverRequest pid_receiver_request = 115 mojo::shell::mojom::PIDReceiverRequest pid_receiver_request =
109 GetProxy(&pid_receiver); 116 GetProxy(&pid_receiver);
110 // PIDSender manages its own lifetime. 117 // PIDSender manages its own lifetime.
111 new PIDSender(render_process_host, std::move(pid_receiver)); 118 new PIDSender(render_process_host, std::move(pid_receiver));
112 119
113 120 mojo::Identity target(child_name, mojo::shell::mojom::kInheritUserID,
114 mojo::Identity target("exe:chrome_renderer",
115 mojo::shell::mojom::kInheritUserID,
116 base::StringPrintf("%d_%d", child_process_id, 121 base::StringPrintf("%d_%d", child_process_id,
117 instance_id)); 122 instance_id));
118 mojo::Connector::ConnectParams params(target); 123 mojo::Connector::ConnectParams params(target);
119 params.set_client_process_connection(std::move(client), 124 params.set_client_process_connection(std::move(client),
120 std::move(pid_receiver_request)); 125 std::move(pid_receiver_request));
121 scoped_ptr<mojo::Connection> connection = 126 scoped_ptr<mojo::Connection> connection =
122 MojoShellConnection::Get()->GetConnector()->Connect(&params); 127 MojoShellConnection::Get()->GetConnector()->Connect(&params);
123 128
124 // Store the connection on the RPH so client code can access it later via 129 // Store the connection on the RPH so client code can access it later via
125 // GetMojoConnection(). 130 // GetMojoConnection().
126 SetMojoConnection(render_process_host, std::move(connection)); 131 SetMojoConnection(render_process_host, std::move(connection));
127 132
128 return pipe_token; 133 return pipe_token;
129 } 134 }
130 135
131 mojo::Connection* GetMojoConnection(RenderProcessHost* render_process_host) { 136 mojo::Connection* GetMojoConnection(RenderProcessHost* render_process_host) {
132 RenderProcessHostConnection* connection = 137 RenderProcessHostConnection* connection =
133 static_cast<RenderProcessHostConnection*>( 138 static_cast<RenderProcessHostConnection*>(
134 render_process_host->GetUserData(kMojoRenderProcessHostConnection)); 139 render_process_host->GetUserData(kMojoRenderProcessHostConnection));
135 return connection ? connection->get() : nullptr; 140 return connection ? connection->get() : nullptr;
136 } 141 }
137 142
138 } // namespace content 143 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698