| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 process_host->SetName(process_name); | 64 process_host->SetName(process_name); |
| 65 if (!use_sandbox) | 65 if (!use_sandbox) |
| 66 process_host->DisableSandbox(); | 66 process_host->DisableSandbox(); |
| 67 process_host->Start(); | 67 process_host->Start(); |
| 68 service_manager::mojom::ServiceFactoryPtr service_factory; | 68 service_manager::mojom::ServiceFactoryPtr service_factory; |
| 69 process_host->GetRemoteInterfaces()->GetInterface( | 69 process_host->GetRemoteInterfaces()->GetInterface( |
| 70 mojo::MakeRequest(&service_factory)); | 70 mojo::MakeRequest(&service_factory)); |
| 71 service_factory->CreateService(std::move(request), service_name); | 71 service_factory->CreateService(std::move(request), service_name); |
| 72 } | 72 } |
| 73 | 73 |
| 74 #if (ENABLE_MOJO_MEDIA_IN_GPU_PROCESS) |
| 75 |
| 74 // Request service_manager::mojom::ServiceFactory from GPU process host. Must be | 76 // Request service_manager::mojom::ServiceFactory from GPU process host. Must be |
| 75 // called on IO thread. | 77 // called on IO thread. |
| 76 void StartServiceInGpuProcess(const std::string& service_name, | 78 void StartServiceInGpuProcess(const std::string& service_name, |
| 77 service_manager::mojom::ServiceRequest request) { | 79 service_manager::mojom::ServiceRequest request) { |
| 78 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 80 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 79 GpuProcessHost* process_host = | 81 GpuProcessHost* process_host = |
| 80 GpuProcessHost::Get(GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED); | 82 GpuProcessHost::Get(GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED); |
| 81 if (!process_host) { | 83 if (!process_host) { |
| 82 DLOG(ERROR) << "GPU process host not available."; | 84 DLOG(ERROR) << "GPU process host not available."; |
| 83 return; | 85 return; |
| 84 } | 86 } |
| 85 | 87 |
| 86 service_manager::mojom::ServiceFactoryPtr service_factory; | 88 service_manager::mojom::ServiceFactoryPtr service_factory; |
| 87 // 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 |
| 88 // 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 |
| 89 // load requests through ServiceFactory will also fail. Make sure we handle | 91 // load requests through ServiceFactory will also fail. Make sure we handle |
| 90 // these cases correctly. | 92 // these cases correctly. |
| 91 process_host->GetRemoteInterfaces()->GetInterface( | 93 process_host->GetRemoteInterfaces()->GetInterface( |
| 92 mojo::MakeRequest(&service_factory)); | 94 mojo::MakeRequest(&service_factory)); |
| 93 service_factory->CreateService(std::move(request), service_name); | 95 service_factory->CreateService(std::move(request), service_name); |
| 94 } | 96 } |
| 95 | 97 |
| 98 #endif // ENABLE_MOJO_MEDIA_IN_GPU_PROCESS |
| 99 |
| 96 // A ManifestProvider which resolves application names to builtin manifest | 100 // A ManifestProvider which resolves application names to builtin manifest |
| 97 // resources for the catalog service to consume. | 101 // resources for the catalog service to consume. |
| 98 class BuiltinManifestProvider : public catalog::ManifestProvider { | 102 class BuiltinManifestProvider : public catalog::ManifestProvider { |
| 99 public: | 103 public: |
| 100 BuiltinManifestProvider() {} | 104 BuiltinManifestProvider() {} |
| 101 ~BuiltinManifestProvider() override {} | 105 ~BuiltinManifestProvider() override {} |
| 102 | 106 |
| 103 void AddServiceManifest(base::StringPiece name, int resource_id) { | 107 void AddServiceManifest(base::StringPiece name, int resource_id) { |
| 104 std::string contents = | 108 std::string contents = |
| 105 GetContentClient() | 109 GetContentClient() |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 for (const auto& service : sandboxed_services) { | 314 for (const auto& service : sandboxed_services) { |
| 311 packaged_services_connection_->AddServiceRequestHandler( | 315 packaged_services_connection_->AddServiceRequestHandler( |
| 312 service.first, base::Bind(&StartServiceInUtilityProcess, service.first, | 316 service.first, base::Bind(&StartServiceInUtilityProcess, service.first, |
| 313 service.second, true /* use_sandbox */)); | 317 service.second, true /* use_sandbox */)); |
| 314 } | 318 } |
| 315 | 319 |
| 316 ContentBrowserClient::OutOfProcessServiceMap unsandboxed_services; | 320 ContentBrowserClient::OutOfProcessServiceMap unsandboxed_services; |
| 317 GetContentClient() | 321 GetContentClient() |
| 318 ->browser() | 322 ->browser() |
| 319 ->RegisterUnsandboxedOutOfProcessServices(&unsandboxed_services); | 323 ->RegisterUnsandboxedOutOfProcessServices(&unsandboxed_services); |
| 324 unsandboxed_services.insert( |
| 325 std::make_pair(shape_detection::mojom::kServiceName, |
| 326 base::ASCIIToUTF16("Shape Detection Service"))); |
| 320 for (const auto& service : unsandboxed_services) { | 327 for (const auto& service : unsandboxed_services) { |
| 321 packaged_services_connection_->AddServiceRequestHandler( | 328 packaged_services_connection_->AddServiceRequestHandler( |
| 322 service.first, base::Bind(&StartServiceInUtilityProcess, service.first, | 329 service.first, base::Bind(&StartServiceInUtilityProcess, service.first, |
| 323 service.second, false /* use_sandbox */)); | 330 service.second, false /* use_sandbox */)); |
| 324 } | 331 } |
| 325 | 332 |
| 326 #if (ENABLE_MOJO_MEDIA_IN_GPU_PROCESS) | 333 #if (ENABLE_MOJO_MEDIA_IN_GPU_PROCESS) |
| 327 packaged_services_connection_->AddServiceRequestHandler( | 334 packaged_services_connection_->AddServiceRequestHandler( |
| 328 "media", base::Bind(&StartServiceInGpuProcess, "media")); | 335 "media", base::Bind(&StartServiceInGpuProcess, "media")); |
| 329 #endif | 336 #endif |
| 330 | |
| 331 packaged_services_connection_->AddServiceRequestHandler( | |
| 332 shape_detection::mojom::kServiceName, | |
| 333 base::Bind(&StartServiceInGpuProcess, | |
| 334 shape_detection::mojom::kServiceName)); | |
| 335 | |
| 336 packaged_services_connection_->Start(); | 337 packaged_services_connection_->Start(); |
| 337 ServiceManagerConnection::GetForProcess()->Start(); | 338 ServiceManagerConnection::GetForProcess()->Start(); |
| 338 } | 339 } |
| 339 | 340 |
| 340 ServiceManagerContext::~ServiceManagerContext() { | 341 ServiceManagerContext::~ServiceManagerContext() { |
| 341 // NOTE: The in-process ServiceManager MUST be destroyed before the browser | 342 // NOTE: The in-process ServiceManager MUST be destroyed before the browser |
| 342 // process-wide ServiceManagerConnection. Otherwise it's possible for the | 343 // process-wide ServiceManagerConnection. Otherwise it's possible for the |
| 343 // ServiceManager to receive connection requests for service:content_browser | 344 // ServiceManager to receive connection requests for service:content_browser |
| 344 // 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. |
| 345 if (in_process_context_) | 346 if (in_process_context_) |
| 346 in_process_context_->ShutDown(); | 347 in_process_context_->ShutDown(); |
| 347 if (ServiceManagerConnection::GetForProcess()) | 348 if (ServiceManagerConnection::GetForProcess()) |
| 348 ServiceManagerConnection::DestroyForProcess(); | 349 ServiceManagerConnection::DestroyForProcess(); |
| 349 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 350 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 350 base::Bind(&DestroyConnectorOnIOThread)); | 351 base::Bind(&DestroyConnectorOnIOThread)); |
| 351 } | 352 } |
| 352 | 353 |
| 353 // static | 354 // static |
| 354 service_manager::Connector* ServiceManagerContext::GetConnectorForIOThread() { | 355 service_manager::Connector* ServiceManagerContext::GetConnectorForIOThread() { |
| 355 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 356 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 356 return g_io_thread_connector.Get().get(); | 357 return g_io_thread_connector.Get().get(); |
| 357 } | 358 } |
| 358 | 359 |
| 359 } // namespace content | 360 } // namespace content |
| OLD | NEW |