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