| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "services/shape_detection/shape_detection_service.h" | 5 #include "services/shape_detection/shape_detection_service.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "services/service_manager/public/cpp/interface_registry.h" | |
| 9 #include "services/service_manager/public/cpp/service_context.h" | 8 #include "services/service_manager/public/cpp/service_context.h" |
| 10 #include "services/shape_detection/barcode_detection_impl.h" | 9 #include "services/shape_detection/barcode_detection_impl.h" |
| 11 #include "services/shape_detection/face_detection_provider_impl.h" | 10 #include "services/shape_detection/face_detection_provider_impl.h" |
| 12 #include "services/shape_detection/text_detection_impl.h" | 11 #include "services/shape_detection/text_detection_impl.h" |
| 13 | 12 |
| 14 namespace shape_detection { | 13 namespace shape_detection { |
| 15 | 14 |
| 16 namespace { | |
| 17 | |
| 18 void OnConnectionLost(std::unique_ptr<service_manager::ServiceContextRef> ref) { | |
| 19 // No-op. This merely takes ownership of |ref| so it can be destroyed when | |
| 20 // this function is invoked. | |
| 21 } | |
| 22 } | |
| 23 | |
| 24 std::unique_ptr<service_manager::Service> ShapeDetectionService::Create() { | 15 std::unique_ptr<service_manager::Service> ShapeDetectionService::Create() { |
| 25 return base::MakeUnique<ShapeDetectionService>(); | 16 return base::MakeUnique<ShapeDetectionService>(); |
| 26 } | 17 } |
| 27 | 18 |
| 28 ShapeDetectionService::ShapeDetectionService() = default; | 19 ShapeDetectionService::ShapeDetectionService() = default; |
| 29 | 20 |
| 30 ShapeDetectionService::~ShapeDetectionService() = default; | 21 ShapeDetectionService::~ShapeDetectionService() = default; |
| 31 | 22 |
| 32 void ShapeDetectionService::OnStart() { | 23 void ShapeDetectionService::OnStart() { |
| 33 ref_factory_.reset(new service_manager::ServiceContextRefFactory( | 24 ref_factory_.reset(new service_manager::ServiceContextRefFactory( |
| 34 base::Bind(&service_manager::ServiceContext::RequestQuit, | 25 base::Bind(&service_manager::ServiceContext::RequestQuit, |
| 35 base::Unretained(context())))); | 26 base::Unretained(context())))); |
| 27 registry_.AddInterface(base::Bind(&BarcodeDetectionImpl::Create)); |
| 28 registry_.AddInterface(base::Bind(&FaceDetectionProviderImpl::Create)); |
| 29 registry_.AddInterface(base::Bind(&TextDetectionImpl::Create)); |
| 36 } | 30 } |
| 37 | 31 |
| 38 bool ShapeDetectionService::OnConnect( | 32 void ShapeDetectionService::OnBindInterface( |
| 39 const service_manager::ServiceInfo& remote_info, | 33 const service_manager::ServiceInfo& source_info, |
| 40 service_manager::InterfaceRegistry* registry) { | 34 const std::string& interface_name, |
| 41 // Add a reference to the service and tie it to the lifetime of the | 35 mojo::ScopedMessagePipeHandle interface_pipe) { |
| 42 // InterfaceRegistry's connection. | 36 registry_.BindInterface(source_info.identity, interface_name, |
| 43 std::unique_ptr<service_manager::ServiceContextRef> connection_ref = | 37 std::move(interface_pipe)); |
| 44 ref_factory_->CreateRef(); | |
| 45 registry->AddConnectionLostClosure( | |
| 46 base::Bind(&OnConnectionLost, base::Passed(&connection_ref))); | |
| 47 registry->AddInterface(base::Bind(&BarcodeDetectionImpl::Create)); | |
| 48 registry->AddInterface(base::Bind(&FaceDetectionProviderImpl::Create)); | |
| 49 registry->AddInterface(base::Bind(&TextDetectionImpl::Create)); | |
| 50 return true; | |
| 51 } | 38 } |
| 52 | 39 |
| 53 } // namespace shape_detection | 40 } // namespace shape_detection |
| OLD | NEW |