Chromium Code Reviews| 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 12 matching lines...) Expand all Loading... | |
| 23 #include "content/public/browser/utility_process_host.h" | 23 #include "content/public/browser/utility_process_host.h" |
| 24 #include "content/public/browser/utility_process_host_client.h" | 24 #include "content/public/browser/utility_process_host_client.h" |
| 25 #include "content/public/common/content_client.h" | 25 #include "content/public/common/content_client.h" |
| 26 #include "content/public/common/service_manager_connection.h" | 26 #include "content/public/common/service_manager_connection.h" |
| 27 #include "content/public/common/service_names.mojom.h" | 27 #include "content/public/common/service_names.mojom.h" |
| 28 #include "mojo/edk/embedder/embedder.h" | 28 #include "mojo/edk/embedder/embedder.h" |
| 29 #include "services/catalog/catalog.h" | 29 #include "services/catalog/catalog.h" |
| 30 #include "services/catalog/manifest_provider.h" | 30 #include "services/catalog/manifest_provider.h" |
| 31 #include "services/catalog/public/interfaces/constants.mojom.h" | 31 #include "services/catalog/public/interfaces/constants.mojom.h" |
| 32 #include "services/catalog/store.h" | 32 #include "services/catalog/store.h" |
| 33 #include "services/device/device_service.h" | |
| 34 #include "services/device/public/interfaces/constants.mojom.h" | |
| 33 #include "services/file/public/interfaces/constants.mojom.h" | 35 #include "services/file/public/interfaces/constants.mojom.h" |
| 34 #include "services/service_manager/connect_params.h" | 36 #include "services/service_manager/connect_params.h" |
| 35 #include "services/service_manager/public/cpp/connector.h" | 37 #include "services/service_manager/public/cpp/connector.h" |
| 36 #include "services/service_manager/public/cpp/service.h" | 38 #include "services/service_manager/public/cpp/service.h" |
| 37 #include "services/service_manager/public/interfaces/service.mojom.h" | 39 #include "services/service_manager/public/interfaces/service.mojom.h" |
| 38 #include "services/service_manager/runner/common/client_util.h" | 40 #include "services/service_manager/runner/common/client_util.h" |
| 39 #include "services/service_manager/service_manager.h" | 41 #include "services/service_manager/service_manager.h" |
| 40 | 42 |
| 41 namespace content { | 43 namespace content { |
| 42 | 44 |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 267 manifest_provider->AddServiceManifest(manifest.name, | 269 manifest_provider->AddServiceManifest(manifest.name, |
| 268 manifest.resource_id); | 270 manifest.resource_id); |
| 269 } | 271 } |
| 270 in_process_context_ = new InProcessServiceManagerContext; | 272 in_process_context_ = new InProcessServiceManagerContext; |
| 271 request = in_process_context_->Start(std::move(manifest_provider)); | 273 request = in_process_context_->Start(std::move(manifest_provider)); |
| 272 } | 274 } |
| 273 ServiceManagerConnection::SetForProcess(ServiceManagerConnection::Create( | 275 ServiceManagerConnection::SetForProcess(ServiceManagerConnection::Create( |
| 274 std::move(request), | 276 std::move(request), |
| 275 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO))); | 277 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO))); |
| 276 | 278 |
| 279 // Registers the singletion device service to be embedded by browser service | |
| 280 // for now. | |
| 281 ServiceInfo device_info; | |
| 282 device_info.factory = | |
| 283 base::Bind(&device::CreateDeviceService, | |
| 284 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE)); | |
| 285 ServiceManagerConnection::GetForProcess()->AddEmbeddedService( | |
| 286 device::mojom::kServiceName, device_info); | |
| 287 | |
| 277 ContentBrowserClient::StaticServiceMap services; | 288 ContentBrowserClient::StaticServiceMap services; |
| 278 GetContentClient()->browser()->RegisterInProcessServices(&services); | 289 GetContentClient()->browser()->RegisterInProcessServices(&services); |
| 279 for (const auto& entry : services) { | 290 for (const auto& entry : services) { |
| 280 ServiceManagerConnection::GetForProcess()->AddEmbeddedService(entry.first, | 291 ServiceManagerConnection::GetForProcess()->AddEmbeddedService(entry.first, |
| 281 entry.second); | 292 entry.second); |
| 282 } | 293 } |
| 283 | 294 |
| 284 // This is safe to assign directly from any thread, because | 295 // This is safe to assign directly from any thread, because |
| 285 // ServiceManagerContext must be constructed before anyone can call | 296 // ServiceManagerContext must be constructed before anyone can call |
| 286 // GetConnectorForIOThread(). | 297 // GetConnectorForIOThread(). |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 308 ServiceManagerConnection::GetForProcess()->AddServiceRequestHandler( | 319 ServiceManagerConnection::GetForProcess()->AddServiceRequestHandler( |
| 309 service.first, | 320 service.first, |
| 310 base::Bind(&StartServiceInUtilityProcess, service.first, service.second, | 321 base::Bind(&StartServiceInUtilityProcess, service.first, service.second, |
| 311 false /* use_sandbox */)); | 322 false /* use_sandbox */)); |
| 312 } | 323 } |
| 313 | 324 |
| 314 #if (ENABLE_MOJO_MEDIA_IN_GPU_PROCESS) | 325 #if (ENABLE_MOJO_MEDIA_IN_GPU_PROCESS) |
| 315 ServiceManagerConnection::GetForProcess()->AddServiceRequestHandler( | 326 ServiceManagerConnection::GetForProcess()->AddServiceRequestHandler( |
| 316 "media", base::Bind(&StartServiceInGpuProcess, "media")); | 327 "media", base::Bind(&StartServiceInGpuProcess, "media")); |
| 317 #endif | 328 #endif |
| 329 | |
| 330 // Initialiates the connection to device service to create singleton instance. | |
| 331 std::unique_ptr<service_manager::Connection> device_connection_ = | |
|
blundell
2017/01/05 16:27:08
You're aliasing the ivar here. This brings up a di
leonhsl(Using Gerrit)
2017/01/06 05:26:03
Ah.. Done and thanks!
| |
| 332 ServiceManagerConnection::GetForProcess()->GetConnector()->Connect( | |
| 333 device::mojom::kServiceName); | |
| 318 } | 334 } |
| 319 | 335 |
| 320 ServiceManagerContext::~ServiceManagerContext() { | 336 ServiceManagerContext::~ServiceManagerContext() { |
| 321 // NOTE: The in-process ServiceManager MUST be destroyed before the browser | 337 // NOTE: The in-process ServiceManager MUST be destroyed before the browser |
| 322 // process-wide ServiceManagerConnection. Otherwise it's possible for the | 338 // process-wide ServiceManagerConnection. Otherwise it's possible for the |
| 323 // ServiceManager to receive connection requests for service:content_browser | 339 // ServiceManager to receive connection requests for service:content_browser |
| 324 // which it may attempt to service by launching a new instance of the browser. | 340 // which it may attempt to service by launching a new instance of the browser. |
| 325 if (in_process_context_) | 341 if (in_process_context_) |
| 326 in_process_context_->ShutDown(); | 342 in_process_context_->ShutDown(); |
| 327 if (ServiceManagerConnection::GetForProcess()) | 343 if (ServiceManagerConnection::GetForProcess()) |
| 328 ServiceManagerConnection::DestroyForProcess(); | 344 ServiceManagerConnection::DestroyForProcess(); |
| 329 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 345 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 330 base::Bind(&DestroyConnectorOnIOThread)); | 346 base::Bind(&DestroyConnectorOnIOThread)); |
| 331 } | 347 } |
| 332 | 348 |
| 333 // static | 349 // static |
| 334 service_manager::Connector* ServiceManagerContext::GetConnectorForIOThread() { | 350 service_manager::Connector* ServiceManagerContext::GetConnectorForIOThread() { |
| 335 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 351 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 336 return g_io_thread_connector.Get().get(); | 352 return g_io_thread_connector.Get().get(); |
| 337 } | 353 } |
| 338 | 354 |
| 339 } // namespace content | 355 } // namespace content |
| OLD | NEW |