| 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/service_context.h" | 8 #include "services/service_manager/public/cpp/service_context.h" |
| 9 #include "services/shape_detection/barcode_detection_impl.h" | 9 #include "services/shape_detection/barcode_detection_impl.h" |
| 10 #include "services/shape_detection/face_detection_provider_impl.h" | 10 #include "services/shape_detection/face_detection_provider_impl.h" |
| 11 #include "services/shape_detection/text_detection_impl.h" | 11 #include "services/shape_detection/text_detection_impl.h" |
| 12 | 12 |
| 13 #if defined(OS_ANDROID) |
| 14 #include "base/android/context_utils.h" |
| 15 #include "base/android/jni_android.h" |
| 16 #include "jni/InterfaceRegistrar_jni.h" |
| 17 #endif |
| 18 |
| 13 namespace shape_detection { | 19 namespace shape_detection { |
| 14 | 20 |
| 15 std::unique_ptr<service_manager::Service> ShapeDetectionService::Create() { | 21 std::unique_ptr<service_manager::Service> ShapeDetectionService::Create() { |
| 16 return base::MakeUnique<ShapeDetectionService>(); | 22 return base::MakeUnique<ShapeDetectionService>(); |
| 17 } | 23 } |
| 18 | 24 |
| 19 ShapeDetectionService::ShapeDetectionService() = default; | 25 ShapeDetectionService::ShapeDetectionService() = default; |
| 20 | 26 |
| 21 ShapeDetectionService::~ShapeDetectionService() = default; | 27 ShapeDetectionService::~ShapeDetectionService() = default; |
| 22 | 28 |
| 23 void ShapeDetectionService::OnStart() { | 29 void ShapeDetectionService::OnStart() { |
| 24 ref_factory_.reset(new service_manager::ServiceContextRefFactory( | 30 ref_factory_.reset(new service_manager::ServiceContextRefFactory( |
| 25 base::Bind(&service_manager::ServiceContext::RequestQuit, | 31 base::Bind(&service_manager::ServiceContext::RequestQuit, |
| 26 base::Unretained(context())))); | 32 base::Unretained(context())))); |
| 33 |
| 34 #if defined(OS_ANDROID) |
| 35 registry_.AddInterface( |
| 36 GetJavaInterfaces()->CreateInterfaceFactory<mojom::BarcodeDetection>()); |
| 37 registry_.AddInterface( |
| 38 GetJavaInterfaces()->CreateInterfaceFactory<mojom::TextDetection>()); |
| 39 #else |
| 27 registry_.AddInterface(base::Bind(&BarcodeDetectionImpl::Create)); | 40 registry_.AddInterface(base::Bind(&BarcodeDetectionImpl::Create)); |
| 41 registry_.AddInterface(base::Bind(&TextDetectionImpl::Create)); |
| 42 #endif |
| 43 |
| 28 registry_.AddInterface(base::Bind(&FaceDetectionProviderImpl::Create)); | 44 registry_.AddInterface(base::Bind(&FaceDetectionProviderImpl::Create)); |
| 29 registry_.AddInterface(base::Bind(&TextDetectionImpl::Create)); | |
| 30 } | 45 } |
| 31 | 46 |
| 32 void ShapeDetectionService::OnBindInterface( | 47 void ShapeDetectionService::OnBindInterface( |
| 33 const service_manager::BindSourceInfo& source_info, | 48 const service_manager::BindSourceInfo& source_info, |
| 34 const std::string& interface_name, | 49 const std::string& interface_name, |
| 35 mojo::ScopedMessagePipeHandle interface_pipe) { | 50 mojo::ScopedMessagePipeHandle interface_pipe) { |
| 36 registry_.BindInterface(source_info, interface_name, | 51 registry_.BindInterface(source_info, interface_name, |
| 37 std::move(interface_pipe)); | 52 std::move(interface_pipe)); |
| 38 } | 53 } |
| 39 | 54 |
| 55 #if defined(OS_ANDROID) |
| 56 service_manager::InterfaceProvider* ShapeDetectionService::GetJavaInterfaces() { |
| 57 if (!java_interface_provider_initialized_) { |
| 58 service_manager::mojom::InterfaceProviderPtr provider; |
| 59 JNIEnv* env = base::android::AttachCurrentThread(); |
| 60 Java_InterfaceRegistrar_createInterfaceRegistryForContext( |
| 61 env, mojo::MakeRequest(&provider).PassMessagePipe().release().value(), |
| 62 base::android::GetApplicationContext()); |
| 63 java_interface_provider_.Bind(std::move(provider)); |
| 64 |
| 65 java_interface_provider_initialized_ = true; |
| 66 } |
| 67 |
| 68 return &java_interface_provider_; |
| 69 } |
| 70 #endif |
| 71 |
| 40 } // namespace shape_detection | 72 } // namespace shape_detection |
| OLD | NEW |