OLD | NEW |
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_shell_context.h" | 5 #include "content/browser/mojo/mojo_shell_context.h" |
6 | 6 |
7 #include <unordered_map> | 7 #include <unordered_map> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 #include "mojo/edk/embedder/embedder.h" | 30 #include "mojo/edk/embedder/embedder.h" |
31 #include "mojo/public/cpp/bindings/interface_request.h" | 31 #include "mojo/public/cpp/bindings/interface_request.h" |
32 #include "mojo/public/cpp/bindings/string.h" | 32 #include "mojo/public/cpp/bindings/string.h" |
33 #include "services/catalog/catalog.h" | 33 #include "services/catalog/catalog.h" |
34 #include "services/catalog/manifest_provider.h" | 34 #include "services/catalog/manifest_provider.h" |
35 #include "services/catalog/store.h" | 35 #include "services/catalog/store.h" |
36 #include "services/shell/connect_params.h" | 36 #include "services/shell/connect_params.h" |
37 #include "services/shell/native_runner.h" | 37 #include "services/shell/native_runner.h" |
38 #include "services/shell/public/cpp/connector.h" | 38 #include "services/shell/public/cpp/connector.h" |
39 #include "services/shell/public/cpp/identity.h" | 39 #include "services/shell/public/cpp/identity.h" |
40 #include "services/shell/public/cpp/shell_client.h" | 40 #include "services/shell/public/cpp/service.h" |
41 #include "services/shell/public/interfaces/connector.mojom.h" | 41 #include "services/shell/public/interfaces/connector.mojom.h" |
42 #include "services/shell/public/interfaces/shell_client.mojom.h" | 42 #include "services/shell/public/interfaces/service.mojom.h" |
43 #include "services/shell/public/interfaces/shell_client_factory.mojom.h" | 43 #include "services/shell/public/interfaces/service_factory.mojom.h" |
44 #include "services/shell/runner/common/client_util.h" | 44 #include "services/shell/runner/common/client_util.h" |
45 #include "services/shell/runner/host/in_process_native_runner.h" | 45 #include "services/shell/runner/host/in_process_native_runner.h" |
46 #include "services/user/public/cpp/constants.h" | 46 #include "services/user/public/cpp/constants.h" |
47 | 47 |
48 namespace content { | 48 namespace content { |
49 | 49 |
50 namespace { | 50 namespace { |
51 | 51 |
52 using ConnectorPtr = base::ThreadLocalPointer<shell::Connector>; | 52 using ConnectorPtr = base::ThreadLocalPointer<shell::Connector>; |
53 | 53 |
(...skipping 25 matching lines...) Expand all Loading... |
79 } | 79 } |
80 | 80 |
81 void OnApplicationLoaded(const std::string& name, bool success) { | 81 void OnApplicationLoaded(const std::string& name, bool success) { |
82 if (!success) | 82 if (!success) |
83 LOG(ERROR) << "Failed to launch Mojo application for " << name; | 83 LOG(ERROR) << "Failed to launch Mojo application for " << name; |
84 } | 84 } |
85 | 85 |
86 void LaunchAppInUtilityProcess(const std::string& app_name, | 86 void LaunchAppInUtilityProcess(const std::string& app_name, |
87 const base::string16& process_name, | 87 const base::string16& process_name, |
88 bool use_sandbox, | 88 bool use_sandbox, |
89 shell::mojom::ShellClientRequest request) { | 89 shell::mojom::ServiceRequest request) { |
90 mojom::ProcessControlPtr process_control; | 90 mojom::ProcessControlPtr process_control; |
91 mojom::ProcessControlRequest process_request = | 91 mojom::ProcessControlRequest process_request = |
92 mojo::GetProxy(&process_control); | 92 mojo::GetProxy(&process_control); |
93 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 93 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
94 base::Bind(&StartUtilityProcessOnIOThread, | 94 base::Bind(&StartUtilityProcessOnIOThread, |
95 base::Passed(&process_request), | 95 base::Passed(&process_request), |
96 process_name, use_sandbox)); | 96 process_name, use_sandbox)); |
97 process_control->LoadApplication(app_name, std::move(request), | 97 process_control->LoadApplication(app_name, std::move(request), |
98 base::Bind(&OnApplicationLoaded, app_name)); | 98 base::Bind(&OnApplicationLoaded, app_name)); |
99 } | 99 } |
(...skipping 14 matching lines...) Expand all Loading... |
114 | 114 |
115 // TODO(xhwang): It's possible that |process_host| is non-null, but the actual | 115 // TODO(xhwang): It's possible that |process_host| is non-null, but the actual |
116 // process is dead. In that case, |request| will be dropped and application | 116 // process is dead. In that case, |request| will be dropped and application |
117 // load requests through mojom::ProcessControl will also fail. Make sure we | 117 // load requests through mojom::ProcessControl will also fail. Make sure we |
118 // handle | 118 // handle |
119 // these cases correctly. | 119 // these cases correctly. |
120 process_host->GetRemoteInterfaces()->GetInterface(std::move(request)); | 120 process_host->GetRemoteInterfaces()->GetInterface(std::move(request)); |
121 } | 121 } |
122 | 122 |
123 void LaunchAppInGpuProcess(const std::string& app_name, | 123 void LaunchAppInGpuProcess(const std::string& app_name, |
124 shell::mojom::ShellClientRequest request) { | 124 shell::mojom::ServiceRequest request) { |
125 mojom::ProcessControlPtr process_control; | 125 mojom::ProcessControlPtr process_control; |
126 mojom::ProcessControlRequest process_request = | 126 mojom::ProcessControlRequest process_request = |
127 mojo::GetProxy(&process_control); | 127 mojo::GetProxy(&process_control); |
128 BrowserThread::PostTask( | 128 BrowserThread::PostTask( |
129 BrowserThread::IO, FROM_HERE, | 129 BrowserThread::IO, FROM_HERE, |
130 base::Bind(&RequestGpuProcessControl, base::Passed(&process_request))); | 130 base::Bind(&RequestGpuProcessControl, base::Passed(&process_request))); |
131 process_control->LoadApplication(app_name, std::move(request), | 131 process_control->LoadApplication(app_name, std::move(request), |
132 base::Bind(&OnApplicationLoaded, app_name)); | 132 base::Bind(&OnApplicationLoaded, app_name)); |
133 } | 133 } |
134 | 134 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 manifest_provider_->AddManifestResource(kUtilityMojoApplicationName, | 255 manifest_provider_->AddManifestResource(kUtilityMojoApplicationName, |
256 IDR_MOJO_CONTENT_UTILITY_MANIFEST); | 256 IDR_MOJO_CONTENT_UTILITY_MANIFEST); |
257 manifest_provider_->AddManifestResource("mojo:catalog", | 257 manifest_provider_->AddManifestResource("mojo:catalog", |
258 IDR_MOJO_CATALOG_MANIFEST); | 258 IDR_MOJO_CATALOG_MANIFEST); |
259 manifest_provider_->AddManifestResource(user_service::kUserServiceName, | 259 manifest_provider_->AddManifestResource(user_service::kUserServiceName, |
260 IDR_MOJO_PROFILE_MANIFEST); | 260 IDR_MOJO_PROFILE_MANIFEST); |
261 | 261 |
262 catalog_.reset(new catalog::Catalog(file_task_runner.get(), nullptr, | 262 catalog_.reset(new catalog::Catalog(file_task_runner.get(), nullptr, |
263 manifest_provider_.get())); | 263 manifest_provider_.get())); |
264 | 264 |
265 shell::mojom::ShellClientRequest request; | 265 shell::mojom::ServiceRequest request; |
266 if (shell::ShellIsRemote()) { | 266 if (shell::ShellIsRemote()) { |
267 mojo::edk::SetParentPipeHandleFromCommandLine(); | 267 mojo::edk::SetParentPipeHandleFromCommandLine(); |
268 request = shell::GetShellClientRequestFromCommandLine(); | 268 request = shell::GetServiceRequestFromCommandLine(); |
269 } else { | 269 } else { |
270 shell_.reset(new shell::Shell(std::move(native_runner_factory), | 270 shell_.reset(new shell::Shell(std::move(native_runner_factory), |
271 catalog_->TakeShellClient())); | 271 catalog_->TakeService())); |
272 request = shell_->InitInstanceForEmbedder(kBrowserMojoApplicationName); | 272 request = shell_->InitInstanceForEmbedder(kBrowserMojoApplicationName); |
273 } | 273 } |
274 MojoShellConnection::SetForProcess( | 274 MojoShellConnection::SetForProcess( |
275 MojoShellConnection::Create(std::move(request))); | 275 MojoShellConnection::Create(std::move(request))); |
276 | 276 |
277 std::unique_ptr<shell::Connector> io_connector = | 277 std::unique_ptr<shell::Connector> io_connector = |
278 MojoShellConnection::GetForProcess()->GetConnector()->Clone(); | 278 MojoShellConnection::GetForProcess()->GetConnector()->Clone(); |
279 BrowserThread::PostTask( | 279 BrowserThread::PostTask( |
280 BrowserThread::IO, FROM_HERE, | 280 BrowserThread::IO, FROM_HERE, |
281 base::Bind(&SetConnectorOnIOThread, base::Passed(&io_connector))); | 281 base::Bind(&SetConnectorOnIOThread, base::Passed(&io_connector))); |
282 | 282 |
283 ContentBrowserClient::StaticMojoApplicationMap apps; | 283 ContentBrowserClient::StaticMojoApplicationMap apps; |
284 GetContentClient()->browser()->RegisterInProcessMojoApplications(&apps); | 284 GetContentClient()->browser()->RegisterInProcessMojoApplications(&apps); |
285 for (const auto& entry : apps) { | 285 for (const auto& entry : apps) { |
286 MojoShellConnection::GetForProcess()->AddEmbeddedService(entry.first, | 286 MojoShellConnection::GetForProcess()->AddEmbeddedService(entry.first, |
287 entry.second); | 287 entry.second); |
288 } | 288 } |
289 | 289 |
290 ContentBrowserClient::OutOfProcessMojoApplicationMap sandboxed_apps; | 290 ContentBrowserClient::OutOfProcessMojoApplicationMap sandboxed_apps; |
291 GetContentClient() | 291 GetContentClient() |
292 ->browser() | 292 ->browser() |
293 ->RegisterOutOfProcessMojoApplications(&sandboxed_apps); | 293 ->RegisterOutOfProcessMojoApplications(&sandboxed_apps); |
294 for (const auto& app : sandboxed_apps) { | 294 for (const auto& app : sandboxed_apps) { |
295 MojoShellConnection::GetForProcess()->AddShellClientRequestHandler( | 295 MojoShellConnection::GetForProcess()->AddServiceRequestHandler( |
296 app.first, | 296 app.first, |
297 base::Bind(&LaunchAppInUtilityProcess, app.first, app.second, | 297 base::Bind(&LaunchAppInUtilityProcess, app.first, app.second, |
298 true /* use_sandbox */)); | 298 true /* use_sandbox */)); |
299 } | 299 } |
300 | 300 |
301 ContentBrowserClient::OutOfProcessMojoApplicationMap unsandboxed_apps; | 301 ContentBrowserClient::OutOfProcessMojoApplicationMap unsandboxed_apps; |
302 GetContentClient() | 302 GetContentClient() |
303 ->browser() | 303 ->browser() |
304 ->RegisterUnsandboxedOutOfProcessMojoApplications(&unsandboxed_apps); | 304 ->RegisterUnsandboxedOutOfProcessMojoApplications(&unsandboxed_apps); |
305 for (const auto& app : unsandboxed_apps) { | 305 for (const auto& app : unsandboxed_apps) { |
306 MojoShellConnection::GetForProcess()->AddShellClientRequestHandler( | 306 MojoShellConnection::GetForProcess()->AddServiceRequestHandler( |
307 app.first, | 307 app.first, |
308 base::Bind(&LaunchAppInUtilityProcess, app.first, app.second, | 308 base::Bind(&LaunchAppInUtilityProcess, app.first, app.second, |
309 false /* use_sandbox */)); | 309 false /* use_sandbox */)); |
310 } | 310 } |
311 | 311 |
312 #if (ENABLE_MOJO_MEDIA_IN_GPU_PROCESS) | 312 #if (ENABLE_MOJO_MEDIA_IN_GPU_PROCESS) |
313 MojoShellConnection::GetForProcess()->AddShellClientRequestHandler( | 313 MojoShellConnection::GetForProcess()->AddServiceRequestHandler( |
314 "mojo:media", base::Bind(&LaunchAppInGpuProcess, "mojo:media")); | 314 "mojo:media", base::Bind(&LaunchAppInGpuProcess, "mojo:media")); |
315 #endif | 315 #endif |
316 } | 316 } |
317 | 317 |
318 MojoShellContext::~MojoShellContext() { | 318 MojoShellContext::~MojoShellContext() { |
319 if (MojoShellConnection::GetForProcess()) | 319 if (MojoShellConnection::GetForProcess()) |
320 MojoShellConnection::DestroyForProcess(); | 320 MojoShellConnection::DestroyForProcess(); |
321 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 321 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
322 base::Bind(&DestroyConnectorOnIOThread)); | 322 base::Bind(&DestroyConnectorOnIOThread)); |
323 catalog_.reset(); | 323 catalog_.reset(); |
(...skipping 29 matching lines...) Expand all Loading... |
353 shell::Identity source_id(requestor_name, user_id); | 353 shell::Identity source_id(requestor_name, user_id); |
354 params->set_source(source_id); | 354 params->set_source(source_id); |
355 params->set_target(shell::Identity(name, user_id)); | 355 params->set_target(shell::Identity(name, user_id)); |
356 params->set_remote_interfaces(std::move(request)); | 356 params->set_remote_interfaces(std::move(request)); |
357 params->set_local_interfaces(std::move(exposed_services)); | 357 params->set_local_interfaces(std::move(exposed_services)); |
358 params->set_connect_callback(callback); | 358 params->set_connect_callback(callback); |
359 shell_->Connect(std::move(params)); | 359 shell_->Connect(std::move(params)); |
360 } | 360 } |
361 | 361 |
362 } // namespace content | 362 } // namespace content |
OLD | NEW |