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