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

Side by Side Diff: services/shape_detection/shape_detection_service.cc

Issue 2855203003: Shape Detection: move {BarcodeDetectionImpl,TextDetectionImpl}.java to //services/shape_detection (Closed)
Patch Set: Make |java_interface_provider_| a std::unique_ptr<> Created 3 years, 7 months 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
« no previous file with comments | « services/shape_detection/shape_detection_service.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_) {
58 service_manager::mojom::InterfaceProviderPtr provider;
59 Java_InterfaceRegistrar_createInterfaceRegistryForContext(
60 base::android::AttachCurrentThread(),
61 mojo::MakeRequest(&provider).PassMessagePipe().release().value(),
62 base::android::GetApplicationContext());
63 java_interface_provider_ =
64 base::MakeUnique<service_manager::InterfaceProvider>();
65 java_interface_provider_->Bind(std::move(provider));
66 }
67 return java_interface_provider_.get();
68 }
69 #endif
70
40 } // namespace shape_detection 71 } // namespace shape_detection
OLDNEW
« no previous file with comments | « services/shape_detection/shape_detection_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698