| 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 17 matching lines...) Expand all Loading... |
| 28 #include "content/public/common/content_client.h" | 28 #include "content/public/common/content_client.h" |
| 29 #include "content/public/common/content_switches.h" | 29 #include "content/public/common/content_switches.h" |
| 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/identity.h" | 39 #include "services/shell/public/cpp/identity.h" |
| 39 #include "services/shell/public/cpp/shell_client.h" | 40 #include "services/shell/public/cpp/shell_client.h" |
| 40 #include "services/shell/public/interfaces/connector.mojom.h" | 41 #include "services/shell/public/interfaces/connector.mojom.h" |
| 41 #include "services/shell/public/interfaces/shell_client.mojom.h" | 42 #include "services/shell/public/interfaces/shell_client.mojom.h" |
| 42 #include "services/shell/public/interfaces/shell_client_factory.mojom.h" | 43 #include "services/shell/public/interfaces/shell_client_factory.mojom.h" |
| 43 #include "services/shell/runner/common/client_util.h" | 44 #include "services/shell/runner/common/client_util.h" |
| 44 #include "services/shell/runner/host/in_process_native_runner.h" | 45 #include "services/shell/runner/host/in_process_native_runner.h" |
| 45 #include "services/user/public/cpp/constants.h" | 46 #include "services/user/public/cpp/constants.h" |
| 46 | 47 |
| 47 namespace content { | 48 namespace content { |
| 48 | 49 |
| 49 namespace { | 50 namespace { |
| 50 | 51 |
| 52 using ConnectorPtr = base::ThreadLocalPointer<shell::Connector>; |
| 53 |
| 54 base::LazyInstance<ConnectorPtr>::Leaky io_connector_tls_ptr = |
| 55 LAZY_INSTANCE_INITIALIZER; |
| 56 |
| 57 void SetConnectorOnIOThread(std::unique_ptr<shell::Connector> connector) { |
| 58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 59 io_connector_tls_ptr.Pointer()->Set(connector.release()); |
| 60 } |
| 61 |
| 62 void DestroyConnectorOnIOThread() { |
| 63 delete MojoShellContext::GetConnectorForIOThread(); |
| 64 io_connector_tls_ptr.Pointer()->Set(nullptr); |
| 65 } |
| 66 |
| 51 void StartUtilityProcessOnIOThread( | 67 void StartUtilityProcessOnIOThread( |
| 52 mojo::InterfaceRequest<mojom::ProcessControl> request, | 68 mojo::InterfaceRequest<mojom::ProcessControl> request, |
| 53 const base::string16& process_name, | 69 const base::string16& process_name, |
| 54 bool use_sandbox) { | 70 bool use_sandbox) { |
| 55 UtilityProcessHost* process_host = | 71 UtilityProcessHost* process_host = |
| 56 UtilityProcessHost::Create(nullptr, nullptr); | 72 UtilityProcessHost::Create(nullptr, nullptr); |
| 57 process_host->SetName(process_name); | 73 process_host->SetName(process_name); |
| 58 if (!use_sandbox) | 74 if (!use_sandbox) |
| 59 process_host->DisableSandbox(); | 75 process_host->DisableSandbox(); |
| 60 process_host->Start(); | 76 process_host->Start(); |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 // beyond the default ones below. | 241 // beyond the default ones below. |
| 226 std::unique_ptr<ContentBrowserClient::MojoApplicationManifestMap> manifests( | 242 std::unique_ptr<ContentBrowserClient::MojoApplicationManifestMap> manifests( |
| 227 new ContentBrowserClient::MojoApplicationManifestMap); | 243 new ContentBrowserClient::MojoApplicationManifestMap); |
| 228 GetContentClient()->browser()->RegisterMojoApplicationManifests( | 244 GetContentClient()->browser()->RegisterMojoApplicationManifests( |
| 229 manifests.get()); | 245 manifests.get()); |
| 230 | 246 |
| 231 manifest_provider_.reset(new BuiltinManifestProvider); | 247 manifest_provider_.reset(new BuiltinManifestProvider); |
| 232 manifest_provider_->AddManifests(std::move(manifests)); | 248 manifest_provider_->AddManifests(std::move(manifests)); |
| 233 manifest_provider_->AddManifestResource(kBrowserMojoApplicationName, | 249 manifest_provider_->AddManifestResource(kBrowserMojoApplicationName, |
| 234 IDR_MOJO_CONTENT_BROWSER_MANIFEST); | 250 IDR_MOJO_CONTENT_BROWSER_MANIFEST); |
| 251 manifest_provider_->AddManifestResource(kGpuMojoApplicationName, |
| 252 IDR_MOJO_CONTENT_GPU_MANIFEST); |
| 235 manifest_provider_->AddManifestResource(kRendererMojoApplicationName, | 253 manifest_provider_->AddManifestResource(kRendererMojoApplicationName, |
| 236 IDR_MOJO_CONTENT_RENDERER_MANIFEST); | 254 IDR_MOJO_CONTENT_RENDERER_MANIFEST); |
| 237 manifest_provider_->AddManifestResource("mojo:catalog", | 255 manifest_provider_->AddManifestResource("mojo:catalog", |
| 238 IDR_MOJO_CATALOG_MANIFEST); | 256 IDR_MOJO_CATALOG_MANIFEST); |
| 239 manifest_provider_->AddManifestResource(user_service::kUserServiceName, | 257 manifest_provider_->AddManifestResource(user_service::kUserServiceName, |
| 240 IDR_MOJO_PROFILE_MANIFEST); | 258 IDR_MOJO_PROFILE_MANIFEST); |
| 241 | 259 |
| 242 catalog_.reset(new catalog::Catalog(file_task_runner.get(), nullptr, | 260 catalog_.reset(new catalog::Catalog(file_task_runner.get(), nullptr, |
| 243 manifest_provider_.get())); | 261 manifest_provider_.get())); |
| 244 | 262 |
| 245 shell::mojom::ShellClientRequest request; | 263 shell::mojom::ShellClientRequest request; |
| 246 if (shell::ShellIsRemote()) { | 264 if (shell::ShellIsRemote()) { |
| 247 mojo::edk::SetParentPipeHandleFromCommandLine(); | 265 mojo::edk::SetParentPipeHandleFromCommandLine(); |
| 248 request = shell::GetShellClientRequestFromCommandLine(); | 266 request = shell::GetShellClientRequestFromCommandLine(); |
| 249 } else { | 267 } else { |
| 250 shell_.reset(new shell::Shell(std::move(native_runner_factory), | 268 shell_.reset(new shell::Shell(std::move(native_runner_factory), |
| 251 catalog_->TakeShellClient())); | 269 catalog_->TakeShellClient())); |
| 252 request = shell_->InitInstanceForEmbedder(kBrowserMojoApplicationName); | 270 request = shell_->InitInstanceForEmbedder(kBrowserMojoApplicationName); |
| 253 } | 271 } |
| 254 MojoShellConnection::SetForProcess( | 272 MojoShellConnection::SetForProcess( |
| 255 MojoShellConnection::Create(std::move(request))); | 273 MojoShellConnection::Create(std::move(request))); |
| 256 | 274 |
| 275 std::unique_ptr<shell::Connector> io_connector = |
| 276 MojoShellConnection::GetForProcess()->GetConnector()->Clone(); |
| 277 BrowserThread::PostTask( |
| 278 BrowserThread::IO, FROM_HERE, |
| 279 base::Bind(&SetConnectorOnIOThread, base::Passed(&io_connector))); |
| 280 |
| 257 ContentBrowserClient::StaticMojoApplicationMap apps; | 281 ContentBrowserClient::StaticMojoApplicationMap apps; |
| 258 GetContentClient()->browser()->RegisterInProcessMojoApplications(&apps); | 282 GetContentClient()->browser()->RegisterInProcessMojoApplications(&apps); |
| 259 for (const auto& entry : apps) { | 283 for (const auto& entry : apps) { |
| 260 MojoShellConnection::GetForProcess()->AddEmbeddedService(entry.first, | 284 MojoShellConnection::GetForProcess()->AddEmbeddedService(entry.first, |
| 261 entry.second); | 285 entry.second); |
| 262 } | 286 } |
| 263 | 287 |
| 264 ContentBrowserClient::OutOfProcessMojoApplicationMap sandboxed_apps; | 288 ContentBrowserClient::OutOfProcessMojoApplicationMap sandboxed_apps; |
| 265 GetContentClient() | 289 GetContentClient() |
| 266 ->browser() | 290 ->browser() |
| (...skipping 18 matching lines...) Expand all Loading... |
| 285 | 309 |
| 286 #if (ENABLE_MOJO_MEDIA_IN_GPU_PROCESS) | 310 #if (ENABLE_MOJO_MEDIA_IN_GPU_PROCESS) |
| 287 MojoShellConnection::GetForProcess()->AddShellClientRequestHandler( | 311 MojoShellConnection::GetForProcess()->AddShellClientRequestHandler( |
| 288 "mojo:media", base::Bind(&LaunchAppInGpuProcess, "mojo:media")); | 312 "mojo:media", base::Bind(&LaunchAppInGpuProcess, "mojo:media")); |
| 289 #endif | 313 #endif |
| 290 } | 314 } |
| 291 | 315 |
| 292 MojoShellContext::~MojoShellContext() { | 316 MojoShellContext::~MojoShellContext() { |
| 293 if (MojoShellConnection::GetForProcess()) | 317 if (MojoShellConnection::GetForProcess()) |
| 294 MojoShellConnection::DestroyForProcess(); | 318 MojoShellConnection::DestroyForProcess(); |
| 319 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 320 base::Bind(&DestroyConnectorOnIOThread)); |
| 295 catalog_.reset(); | 321 catalog_.reset(); |
| 296 } | 322 } |
| 297 | 323 |
| 298 // static | 324 // static |
| 299 void MojoShellContext::ConnectToApplication( | 325 void MojoShellContext::ConnectToApplication( |
| 300 const std::string& user_id, | 326 const std::string& user_id, |
| 301 const std::string& name, | 327 const std::string& name, |
| 302 const std::string& requestor_name, | 328 const std::string& requestor_name, |
| 303 shell::mojom::InterfaceProviderRequest request, | 329 shell::mojom::InterfaceProviderRequest request, |
| 304 shell::mojom::InterfaceProviderPtr exposed_services, | 330 shell::mojom::InterfaceProviderPtr exposed_services, |
| 305 const shell::mojom::Connector::ConnectCallback& callback) { | 331 const shell::mojom::Connector::ConnectCallback& callback) { |
| 306 proxy_.Get()->ConnectToApplication(user_id, name, requestor_name, | 332 proxy_.Get()->ConnectToApplication(user_id, name, requestor_name, |
| 307 std::move(request), | 333 std::move(request), |
| 308 std::move(exposed_services), callback); | 334 std::move(exposed_services), callback); |
| 309 } | 335 } |
| 310 | 336 |
| 337 // static |
| 338 shell::Connector* MojoShellContext::GetConnectorForIOThread() { |
| 339 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 340 return io_connector_tls_ptr.Pointer()->Get(); |
| 341 } |
| 342 |
| 311 void MojoShellContext::ConnectToApplicationOnOwnThread( | 343 void MojoShellContext::ConnectToApplicationOnOwnThread( |
| 312 const std::string& user_id, | 344 const std::string& user_id, |
| 313 const std::string& name, | 345 const std::string& name, |
| 314 const std::string& requestor_name, | 346 const std::string& requestor_name, |
| 315 shell::mojom::InterfaceProviderRequest request, | 347 shell::mojom::InterfaceProviderRequest request, |
| 316 shell::mojom::InterfaceProviderPtr exposed_services, | 348 shell::mojom::InterfaceProviderPtr exposed_services, |
| 317 const shell::mojom::Connector::ConnectCallback& callback) { | 349 const shell::mojom::Connector::ConnectCallback& callback) { |
| 318 std::unique_ptr<shell::ConnectParams> params(new shell::ConnectParams); | 350 std::unique_ptr<shell::ConnectParams> params(new shell::ConnectParams); |
| 319 shell::Identity source_id(requestor_name, user_id); | 351 shell::Identity source_id(requestor_name, user_id); |
| 320 params->set_source(source_id); | 352 params->set_source(source_id); |
| 321 params->set_target(shell::Identity(name, user_id)); | 353 params->set_target(shell::Identity(name, user_id)); |
| 322 params->set_remote_interfaces(std::move(request)); | 354 params->set_remote_interfaces(std::move(request)); |
| 323 params->set_local_interfaces(std::move(exposed_services)); | 355 params->set_local_interfaces(std::move(exposed_services)); |
| 324 params->set_connect_callback(callback); | 356 params->set_connect_callback(callback); |
| 325 shell_->Connect(std::move(params)); | 357 shell_->Connect(std::move(params)); |
| 326 } | 358 } |
| 327 | 359 |
| 328 } // namespace content | 360 } // namespace content |
| OLD | NEW |