| 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/service_manager/service_manager_context.h" | 5 #include "content/browser/service_manager/service_manager_context.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 | 46 |
| 47 namespace content { | 47 namespace content { |
| 48 | 48 |
| 49 namespace { | 49 namespace { |
| 50 | 50 |
| 51 base::LazyInstance<std::unique_ptr<service_manager::Connector>>::Leaky | 51 base::LazyInstance<std::unique_ptr<service_manager::Connector>>::Leaky |
| 52 g_io_thread_connector = LAZY_INSTANCE_INITIALIZER; | 52 g_io_thread_connector = LAZY_INSTANCE_INITIALIZER; |
| 53 | 53 |
| 54 void DestroyConnectorOnIOThread() { g_io_thread_connector.Get().reset(); } | 54 void DestroyConnectorOnIOThread() { g_io_thread_connector.Get().reset(); } |
| 55 | 55 |
| 56 void StartUtilityProcessOnIOThread( | 56 void StartServiceInUtilityProcess( |
| 57 service_manager::mojom::ServiceFactoryRequest request, | 57 const std::string& service_name, |
| 58 const base::string16& process_name, | 58 const base::string16& process_name, |
| 59 bool use_sandbox) { | 59 bool use_sandbox, |
| 60 service_manager::mojom::ServiceRequest request) { |
| 61 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 60 UtilityProcessHost* process_host = | 62 UtilityProcessHost* process_host = |
| 61 UtilityProcessHost::Create(nullptr, nullptr); | 63 UtilityProcessHost::Create(nullptr, nullptr); |
| 62 process_host->SetName(process_name); | 64 process_host->SetName(process_name); |
| 63 if (!use_sandbox) | 65 if (!use_sandbox) |
| 64 process_host->DisableSandbox(); | 66 process_host->DisableSandbox(); |
| 65 process_host->Start(); | 67 process_host->Start(); |
| 66 process_host->GetRemoteInterfaces()->GetInterface(std::move(request)); | |
| 67 } | |
| 68 | |
| 69 void StartServiceInUtilityProcess( | |
| 70 const std::string& service_name, | |
| 71 const base::string16& process_name, | |
| 72 bool use_sandbox, | |
| 73 service_manager::mojom::ServiceRequest request) { | |
| 74 service_manager::mojom::ServiceFactoryPtr service_factory; | 68 service_manager::mojom::ServiceFactoryPtr service_factory; |
| 75 BrowserThread::PostTask( | 69 process_host->GetRemoteInterfaces()->GetInterface( |
| 76 BrowserThread::IO, FROM_HERE, | 70 mojo::MakeRequest(&service_factory)); |
| 77 base::Bind(&StartUtilityProcessOnIOThread, | |
| 78 base::Passed(MakeRequest(&service_factory)), process_name, | |
| 79 use_sandbox)); | |
| 80 service_factory->CreateService(std::move(request), service_name); | 71 service_factory->CreateService(std::move(request), service_name); |
| 81 } | 72 } |
| 82 | 73 |
| 83 #if (ENABLE_MOJO_MEDIA_IN_GPU_PROCESS) | 74 #if (ENABLE_MOJO_MEDIA_IN_GPU_PROCESS) |
| 84 | 75 |
| 85 // Request service_manager::mojom::ServiceFactory from GPU process host. Must be | 76 // Request service_manager::mojom::ServiceFactory from GPU process host. Must be |
| 86 // called on | 77 // called on IO thread. |
| 87 // IO thread. | 78 void StartServiceInGpuProcess(const std::string& service_name, |
| 88 void RequestGpuServiceFactory( | 79 service_manager::mojom::ServiceRequest request) { |
| 89 service_manager::mojom::ServiceFactoryRequest request) { | 80 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 90 GpuProcessHost* process_host = | 81 GpuProcessHost* process_host = |
| 91 GpuProcessHost::Get(GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED); | 82 GpuProcessHost::Get(GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED); |
| 92 if (!process_host) { | 83 if (!process_host) { |
| 93 DLOG(ERROR) << "GPU process host not available."; | 84 DLOG(ERROR) << "GPU process host not available."; |
| 94 return; | 85 return; |
| 95 } | 86 } |
| 96 | 87 |
| 88 service_manager::mojom::ServiceFactoryPtr service_factory; |
| 97 // TODO(xhwang): It's possible that |process_host| is non-null, but the actual | 89 // TODO(xhwang): It's possible that |process_host| is non-null, but the actual |
| 98 // process is dead. In that case, |request| will be dropped and application | 90 // process is dead. In that case, |request| will be dropped and application |
| 99 // load requests through ServiceFactory will also fail. Make sure we handle | 91 // load requests through ServiceFactory will also fail. Make sure we handle |
| 100 // these cases correctly. | 92 // these cases correctly. |
| 101 process_host->GetRemoteInterfaces()->GetInterface(std::move(request)); | 93 process_host->GetRemoteInterfaces()->GetInterface( |
| 102 } | 94 mojo::MakeRequest(&service_factory)); |
| 103 | |
| 104 void StartServiceInGpuProcess(const std::string& service_name, | |
| 105 service_manager::mojom::ServiceRequest request) { | |
| 106 service_manager::mojom::ServiceFactoryPtr service_factory; | |
| 107 BrowserThread::PostTask( | |
| 108 BrowserThread::IO, FROM_HERE, | |
| 109 base::Bind(&RequestGpuServiceFactory, | |
| 110 base::Passed(MakeRequest(&service_factory)))); | |
| 111 service_factory->CreateService(std::move(request), service_name); | 95 service_factory->CreateService(std::move(request), service_name); |
| 112 } | 96 } |
| 113 | 97 |
| 114 #endif // ENABLE_MOJO_MEDIA_IN_GPU_PROCESS | 98 #endif // ENABLE_MOJO_MEDIA_IN_GPU_PROCESS |
| 115 | 99 |
| 116 // A ManifestProvider which resolves application names to builtin manifest | 100 // A ManifestProvider which resolves application names to builtin manifest |
| 117 // resources for the catalog service to consume. | 101 // resources for the catalog service to consume. |
| 118 class BuiltinManifestProvider : public catalog::ManifestProvider { | 102 class BuiltinManifestProvider : public catalog::ManifestProvider { |
| 119 public: | 103 public: |
| 120 BuiltinManifestProvider() {} | 104 BuiltinManifestProvider() {} |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 mojo::MakeRequest(&root_browser_service), | 278 mojo::MakeRequest(&root_browser_service), |
| 295 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO))); | 279 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO))); |
| 296 | 280 |
| 297 service_manager::mojom::PIDReceiverPtr pid_receiver; | 281 service_manager::mojom::PIDReceiverPtr pid_receiver; |
| 298 packaged_services_connection_->GetConnector()->StartService( | 282 packaged_services_connection_->GetConnector()->StartService( |
| 299 service_manager::Identity(mojom::kBrowserServiceName, | 283 service_manager::Identity(mojom::kBrowserServiceName, |
| 300 service_manager::mojom::kRootUserID), | 284 service_manager::mojom::kRootUserID), |
| 301 std::move(root_browser_service), mojo::MakeRequest(&pid_receiver)); | 285 std::move(root_browser_service), mojo::MakeRequest(&pid_receiver)); |
| 302 pid_receiver->SetPID(base::GetCurrentProcId()); | 286 pid_receiver->SetPID(base::GetCurrentProcId()); |
| 303 | 287 |
| 304 packaged_services_connection_->Start(); | |
| 305 ServiceManagerConnection::GetForProcess()->Start(); | |
| 306 | 288 |
| 307 ServiceInfo device_info; | 289 ServiceInfo device_info; |
| 308 device_info.factory = | 290 device_info.factory = |
| 309 base::Bind(&device::CreateDeviceService, | 291 base::Bind(&device::CreateDeviceService, |
| 310 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE)); | 292 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE)); |
| 293 device_info.task_runner = base::ThreadTaskRunnerHandle::Get(); |
| 311 packaged_services_connection_->AddEmbeddedService(device::mojom::kServiceName, | 294 packaged_services_connection_->AddEmbeddedService(device::mojom::kServiceName, |
| 312 device_info); | 295 device_info); |
| 313 | 296 |
| 314 ContentBrowserClient::StaticServiceMap services; | 297 ContentBrowserClient::StaticServiceMap services; |
| 315 GetContentClient()->browser()->RegisterInProcessServices(&services); | 298 GetContentClient()->browser()->RegisterInProcessServices(&services); |
| 316 for (const auto& entry : services) { | 299 for (const auto& entry : services) { |
| 317 packaged_services_connection_->AddEmbeddedService(entry.first, | 300 packaged_services_connection_->AddEmbeddedService(entry.first, |
| 318 entry.second); | 301 entry.second); |
| 319 } | 302 } |
| 320 | 303 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 344 for (const auto& service : unsandboxed_services) { | 327 for (const auto& service : unsandboxed_services) { |
| 345 packaged_services_connection_->AddServiceRequestHandler( | 328 packaged_services_connection_->AddServiceRequestHandler( |
| 346 service.first, base::Bind(&StartServiceInUtilityProcess, service.first, | 329 service.first, base::Bind(&StartServiceInUtilityProcess, service.first, |
| 347 service.second, false /* use_sandbox */)); | 330 service.second, false /* use_sandbox */)); |
| 348 } | 331 } |
| 349 | 332 |
| 350 #if (ENABLE_MOJO_MEDIA_IN_GPU_PROCESS) | 333 #if (ENABLE_MOJO_MEDIA_IN_GPU_PROCESS) |
| 351 packaged_services_connection_->AddServiceRequestHandler( | 334 packaged_services_connection_->AddServiceRequestHandler( |
| 352 "media", base::Bind(&StartServiceInGpuProcess, "media")); | 335 "media", base::Bind(&StartServiceInGpuProcess, "media")); |
| 353 #endif | 336 #endif |
| 337 packaged_services_connection_->Start(); |
| 338 ServiceManagerConnection::GetForProcess()->Start(); |
| 354 } | 339 } |
| 355 | 340 |
| 356 ServiceManagerContext::~ServiceManagerContext() { | 341 ServiceManagerContext::~ServiceManagerContext() { |
| 357 // NOTE: The in-process ServiceManager MUST be destroyed before the browser | 342 // NOTE: The in-process ServiceManager MUST be destroyed before the browser |
| 358 // process-wide ServiceManagerConnection. Otherwise it's possible for the | 343 // process-wide ServiceManagerConnection. Otherwise it's possible for the |
| 359 // ServiceManager to receive connection requests for service:content_browser | 344 // ServiceManager to receive connection requests for service:content_browser |
| 360 // which it may attempt to service by launching a new instance of the browser. | 345 // which it may attempt to service by launching a new instance of the browser. |
| 361 if (in_process_context_) | 346 if (in_process_context_) |
| 362 in_process_context_->ShutDown(); | 347 in_process_context_->ShutDown(); |
| 363 if (ServiceManagerConnection::GetForProcess()) | 348 if (ServiceManagerConnection::GetForProcess()) |
| 364 ServiceManagerConnection::DestroyForProcess(); | 349 ServiceManagerConnection::DestroyForProcess(); |
| 365 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 350 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 366 base::Bind(&DestroyConnectorOnIOThread)); | 351 base::Bind(&DestroyConnectorOnIOThread)); |
| 367 } | 352 } |
| 368 | 353 |
| 369 // static | 354 // static |
| 370 service_manager::Connector* ServiceManagerContext::GetConnectorForIOThread() { | 355 service_manager::Connector* ServiceManagerContext::GetConnectorForIOThread() { |
| 371 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 356 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 372 return g_io_thread_connector.Get().get(); | 357 return g_io_thread_connector.Get().get(); |
| 373 } | 358 } |
| 374 | 359 |
| 375 } // namespace content | 360 } // namespace content |
| OLD | NEW |