Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(636)

Side by Side Diff: content/browser/service_manager/service_manager_context.cc

Issue 2528743002: Shape Detection: Implement FaceDetection on Mac as out-of-process service (Closed)
Patch Set: avi@ comments, rebase Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/json/json_reader.h" 12 #include "base/json/json_reader.h"
13 #include "base/lazy_instance.h" 13 #include "base/lazy_instance.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/ptr_util.h" 15 #include "base/memory/ptr_util.h"
16 #include "base/single_thread_task_runner.h" 16 #include "base/single_thread_task_runner.h"
17 #include "base/strings/utf_string_conversions.h"
17 #include "content/browser/gpu/gpu_process_host.h" 18 #include "content/browser/gpu/gpu_process_host.h"
18 #include "content/browser/service_manager/merge_dictionary.h" 19 #include "content/browser/service_manager/merge_dictionary.h"
19 #include "content/common/service_manager/service_manager_connection_impl.h" 20 #include "content/common/service_manager/service_manager_connection_impl.h"
20 #include "content/grit/content_resources.h" 21 #include "content/grit/content_resources.h"
21 #include "content/public/browser/browser_thread.h" 22 #include "content/public/browser/browser_thread.h"
22 #include "content/public/browser/content_browser_client.h" 23 #include "content/public/browser/content_browser_client.h"
23 #include "content/public/browser/utility_process_host.h" 24 #include "content/public/browser/utility_process_host.h"
24 #include "content/public/browser/utility_process_host_client.h" 25 #include "content/public/browser/utility_process_host_client.h"
25 #include "content/public/common/content_client.h" 26 #include "content/public/common/content_client.h"
26 #include "content/public/common/service_manager_connection.h" 27 #include "content/public/common/service_manager_connection.h"
27 #include "content/public/common/service_names.mojom.h" 28 #include "content/public/common/service_names.mojom.h"
28 #include "mojo/edk/embedder/embedder.h" 29 #include "mojo/edk/embedder/embedder.h"
29 #include "services/catalog/catalog.h" 30 #include "services/catalog/catalog.h"
30 #include "services/catalog/manifest_provider.h" 31 #include "services/catalog/manifest_provider.h"
31 #include "services/catalog/public/interfaces/constants.mojom.h" 32 #include "services/catalog/public/interfaces/constants.mojom.h"
32 #include "services/catalog/store.h" 33 #include "services/catalog/store.h"
33 #include "services/file/public/interfaces/constants.mojom.h" 34 #include "services/file/public/interfaces/constants.mojom.h"
34 #include "services/service_manager/connect_params.h" 35 #include "services/service_manager/connect_params.h"
35 #include "services/service_manager/public/cpp/connector.h" 36 #include "services/service_manager/public/cpp/connector.h"
36 #include "services/service_manager/public/cpp/service.h" 37 #include "services/service_manager/public/cpp/service.h"
37 #include "services/service_manager/public/interfaces/service.mojom.h" 38 #include "services/service_manager/public/interfaces/service.mojom.h"
38 #include "services/service_manager/runner/common/client_util.h" 39 #include "services/service_manager/runner/common/client_util.h"
39 #include "services/service_manager/service_manager.h" 40 #include "services/service_manager/service_manager.h"
41 #include "services/shape_detection/public/interfaces/constants.mojom.h"
40 42
41 namespace content { 43 namespace content {
42 44
43 namespace { 45 namespace {
44 46
45 base::LazyInstance<std::unique_ptr<service_manager::Connector>>::Leaky 47 base::LazyInstance<std::unique_ptr<service_manager::Connector>>::Leaky
46 g_io_thread_connector = LAZY_INSTANCE_INITIALIZER; 48 g_io_thread_connector = LAZY_INSTANCE_INITIALIZER;
47 49
48 void DestroyConnectorOnIOThread() { g_io_thread_connector.Get().reset(); } 50 void DestroyConnectorOnIOThread() { g_io_thread_connector.Get().reset(); }
49 51
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
277 ContentBrowserClient::StaticServiceMap services; 279 ContentBrowserClient::StaticServiceMap services;
278 GetContentClient()->browser()->RegisterInProcessServices(&services); 280 GetContentClient()->browser()->RegisterInProcessServices(&services);
279 for (const auto& entry : services) { 281 for (const auto& entry : services) {
280 ServiceManagerConnection::GetForProcess()->AddEmbeddedService(entry.first, 282 ServiceManagerConnection::GetForProcess()->AddEmbeddedService(entry.first,
281 entry.second); 283 entry.second);
284 DLOG(ERROR) << entry.first;
282 } 285 }
283 286
284 // This is safe to assign directly from any thread, because 287 // This is safe to assign directly from any thread, because
285 // ServiceManagerContext must be constructed before anyone can call 288 // ServiceManagerContext must be constructed before anyone can call
286 // GetConnectorForIOThread(). 289 // GetConnectorForIOThread().
287 g_io_thread_connector.Get() = 290 g_io_thread_connector.Get() =
288 ServiceManagerConnection::GetForProcess()->GetConnector()->Clone(); 291 ServiceManagerConnection::GetForProcess()->GetConnector()->Clone();
289 292
290 ServiceManagerConnection::GetForProcess()->Start(); 293 ServiceManagerConnection::GetForProcess()->Start();
291 294
292 ContentBrowserClient::OutOfProcessServiceMap sandboxed_services; 295 ContentBrowserClient::OutOfProcessServiceMap sandboxed_services;
293 GetContentClient() 296 GetContentClient()
294 ->browser() 297 ->browser()
295 ->RegisterOutOfProcessServices(&sandboxed_services); 298 ->RegisterOutOfProcessServices(&sandboxed_services);
296 for (const auto& service : sandboxed_services) { 299 for (const auto& service : sandboxed_services) {
297 ServiceManagerConnection::GetForProcess()->AddServiceRequestHandler( 300 ServiceManagerConnection::GetForProcess()->AddServiceRequestHandler(
298 service.first, 301 service.first,
299 base::Bind(&StartServiceInUtilityProcess, service.first, service.second, 302 base::Bind(&StartServiceInUtilityProcess, service.first, service.second,
300 true /* use_sandbox */)); 303 true /* use_sandbox */));
304 DLOG(ERROR) << service.first;
301 } 305 }
302 306
303 ContentBrowserClient::OutOfProcessServiceMap unsandboxed_services; 307 ContentBrowserClient::OutOfProcessServiceMap unsandboxed_services;
304 GetContentClient() 308 GetContentClient()
305 ->browser() 309 ->browser()
306 ->RegisterUnsandboxedOutOfProcessServices(&unsandboxed_services); 310 ->RegisterUnsandboxedOutOfProcessServices(&unsandboxed_services);
311 DLOG(ERROR) << "Register shape_detection in content browser";
312 unsandboxed_services.insert(
313 std::make_pair(shape_detection::mojom::kServiceName,
314 base::ASCIIToUTF16("Shape Detection Service")));
307 for (const auto& service : unsandboxed_services) { 315 for (const auto& service : unsandboxed_services) {
308 ServiceManagerConnection::GetForProcess()->AddServiceRequestHandler( 316 ServiceManagerConnection::GetForProcess()->AddServiceRequestHandler(
309 service.first, 317 service.first,
310 base::Bind(&StartServiceInUtilityProcess, service.first, service.second, 318 base::Bind(&StartServiceInUtilityProcess, service.first, service.second,
311 false /* use_sandbox */)); 319 false /* use_sandbox */));
320 DLOG(ERROR) << service.first;
312 } 321 }
313 322
314 #if (ENABLE_MOJO_MEDIA_IN_GPU_PROCESS) 323 #if (ENABLE_MOJO_MEDIA_IN_GPU_PROCESS)
315 ServiceManagerConnection::GetForProcess()->AddServiceRequestHandler( 324 ServiceManagerConnection::GetForProcess()->AddServiceRequestHandler(
316 "media", base::Bind(&StartServiceInGpuProcess, "media")); 325 "media", base::Bind(&StartServiceInGpuProcess, "media"));
317 #endif 326 #endif
318 } 327 }
319 328
320 ServiceManagerContext::~ServiceManagerContext() { 329 ServiceManagerContext::~ServiceManagerContext() {
321 // NOTE: The in-process ServiceManager MUST be destroyed before the browser 330 // NOTE: The in-process ServiceManager MUST be destroyed before the browser
322 // process-wide ServiceManagerConnection. Otherwise it's possible for the 331 // process-wide ServiceManagerConnection. Otherwise it's possible for the
323 // ServiceManager to receive connection requests for service:content_browser 332 // ServiceManager to receive connection requests for service:content_browser
324 // which it may attempt to service by launching a new instance of the browser. 333 // which it may attempt to service by launching a new instance of the browser.
325 if (in_process_context_) 334 if (in_process_context_)
326 in_process_context_->ShutDown(); 335 in_process_context_->ShutDown();
327 if (ServiceManagerConnection::GetForProcess()) 336 if (ServiceManagerConnection::GetForProcess())
328 ServiceManagerConnection::DestroyForProcess(); 337 ServiceManagerConnection::DestroyForProcess();
329 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 338 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
330 base::Bind(&DestroyConnectorOnIOThread)); 339 base::Bind(&DestroyConnectorOnIOThread));
331 } 340 }
332 341
333 // static 342 // static
334 service_manager::Connector* ServiceManagerContext::GetConnectorForIOThread() { 343 service_manager::Connector* ServiceManagerContext::GetConnectorForIOThread() {
335 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 344 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
336 return g_io_thread_connector.Get().get(); 345 return g_io_thread_connector.Get().get();
337 } 346 }
338 347
339 } // namespace content 348 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698