shape_detection_service.cc 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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
  3. // found in the LICENSE file.
  4. #include "services/shape_detection/shape_detection_service.h"
  5. #include <string>
  6. #include <utility>
  7. #include "base/bind.h"
  8. #include "build/branding_buildflags.h"
  9. #include "build/build_config.h"
  10. #include "services/shape_detection/text_detection_impl.h"
  11. #if BUILDFLAG(IS_ANDROID)
  12. #include "base/android/jni_android.h"
  13. #include "services/shape_detection/shape_detection_jni_headers/InterfaceRegistrar_jni.h"
  14. #endif
  15. #if BUILDFLAG(IS_MAC)
  16. #include "services/shape_detection/barcode_detection_provider_mac.h"
  17. #elif BUILDFLAG(IS_ANDROID)
  18. // No C++ code, barcode detection comes from Java.
  19. #elif BUILDFLAG(GOOGLE_CHROME_BRANDING) && BUILDFLAG(IS_CHROMEOS)
  20. #include "services/shape_detection/barcode_detection_provider_barhopper.h"
  21. #else
  22. #include "services/shape_detection/barcode_detection_provider_impl.h"
  23. #endif
  24. #if BUILDFLAG(IS_WIN)
  25. #include "services/shape_detection/face_detection_provider_win.h"
  26. #elif BUILDFLAG(IS_MAC)
  27. #include "services/shape_detection/face_detection_provider_mac.h"
  28. #elif BUILDFLAG(IS_ANDROID)
  29. // No C++ code, face detection comes from Java.
  30. #else
  31. #include "services/shape_detection/face_detection_provider_impl.h"
  32. #endif
  33. namespace shape_detection {
  34. ShapeDetectionService::ShapeDetectionService(
  35. mojo::PendingReceiver<mojom::ShapeDetectionService> receiver)
  36. : receiver_(this, std::move(receiver)) {
  37. }
  38. ShapeDetectionService::~ShapeDetectionService() = default;
  39. void ShapeDetectionService::BindBarcodeDetectionProvider(
  40. mojo::PendingReceiver<mojom::BarcodeDetectionProvider> receiver) {
  41. #if BUILDFLAG(IS_ANDROID)
  42. Java_InterfaceRegistrar_bindBarcodeDetectionProvider(
  43. base::android::AttachCurrentThread(),
  44. receiver.PassPipe().release().value());
  45. #elif BUILDFLAG(IS_MAC)
  46. BarcodeDetectionProviderMac::Create(std::move(receiver));
  47. #elif BUILDFLAG(GOOGLE_CHROME_BRANDING) && BUILDFLAG(IS_CHROMEOS)
  48. BarcodeDetectionProviderBarhopper::Create(std::move(receiver));
  49. #else
  50. BarcodeDetectionProviderImpl::Create(std::move(receiver));
  51. #endif
  52. }
  53. void ShapeDetectionService::BindFaceDetectionProvider(
  54. mojo::PendingReceiver<mojom::FaceDetectionProvider> receiver) {
  55. #if BUILDFLAG(IS_ANDROID)
  56. Java_InterfaceRegistrar_bindFaceDetectionProvider(
  57. base::android::AttachCurrentThread(),
  58. receiver.PassPipe().release().value());
  59. #elif BUILDFLAG(IS_MAC)
  60. FaceDetectionProviderMac::Create(std::move(receiver));
  61. #elif BUILDFLAG(IS_WIN)
  62. FaceDetectionProviderWin::Create(std::move(receiver));
  63. #else
  64. FaceDetectionProviderImpl::Create(std::move(receiver));
  65. #endif
  66. }
  67. void ShapeDetectionService::BindTextDetection(
  68. mojo::PendingReceiver<mojom::TextDetection> receiver) {
  69. #if BUILDFLAG(IS_ANDROID)
  70. Java_InterfaceRegistrar_bindTextDetection(
  71. base::android::AttachCurrentThread(),
  72. receiver.PassPipe().release().value());
  73. #else
  74. TextDetectionImpl::Create(std::move(receiver));
  75. #endif
  76. }
  77. } // namespace shape_detection