Commit 5b95074f authored by mcasas's avatar mcasas Committed by Commit bot

Shape Detection: move {BarcodeDetectionImpl,TextDetectionImpl}.java to //services/shape_detection

This CL:

- moves those two fellas (BarcodeDetectionImpl.java and
TextDetectionImpl.java) from //chrome to //services/shape_detection,
with some tiny adaptations.

- changes render_process_host_impl.cc to send requests to the
said service.

- adds a needed InterfaceRegistrar.java to //services/shape_detection
and some android-specific code to shape_detection_service.cc,
following the  //services/device model (BatteryMonitor, concretely).

No new code or functionality is intended in the ...Impl.java
files (except a small change in testing for GMS presence).

BUG=718275
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.mac:mac_optional_gpu_tests_rel

Review-Url: https://codereview.chromium.org/2855203003
Cr-Commit-Position: refs/heads/master@{#469424}
parent 47e0be3e
......@@ -213,6 +213,7 @@ android_library("chrome_java") {
"//printing:printing_java",
"//services/service_manager/public/interfaces:interfaces_java",
"//services/service_manager/public/java:service_manager_java",
"//services/shape_detection:shape_detection_java",
"//services/shape_detection/public/interfaces:interfaces_java",
"//third_party/WebKit/public:android_mojo_bindings_java",
"//third_party/WebKit/public:blink_headers_java",
......
......@@ -4,20 +4,14 @@
package org.chromium.chrome.browser.mojo;
import android.content.Context;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.chrome.browser.payments.PaymentRequestFactory;
import org.chromium.chrome.browser.shapedetection.BarcodeDetectionImpl;
import org.chromium.chrome.browser.shapedetection.TextDetectionImpl;
import org.chromium.chrome.browser.webshare.ShareServiceImplementationFactory;
import org.chromium.content_public.browser.InterfaceRegistrar;
import org.chromium.content_public.browser.RenderFrameHost;
import org.chromium.content_public.browser.WebContents;
import org.chromium.payments.mojom.PaymentRequest;
import org.chromium.services.service_manager.InterfaceRegistry;
import org.chromium.shape_detection.mojom.BarcodeDetection;
import org.chromium.shape_detection.mojom.TextDetection;
import org.chromium.webshare.mojom.ShareService;
@SuppressWarnings("MultipleTopLevelClassesInFile")
......@@ -26,24 +20,12 @@ import org.chromium.webshare.mojom.ShareService;
class ChromeInterfaceRegistrar {
@CalledByNative
private static void registerMojoInterfaces() {
InterfaceRegistrar.Registry.addContextRegistrar(new ChromeContextInterfaceRegistrar());
InterfaceRegistrar.Registry.addWebContentsRegistrar(
new ChromeWebContentsInterfaceRegistrar());
InterfaceRegistrar.Registry.addRenderFrameHostRegistrar(
new ChromeRenderFrameHostInterfaceRegistrar());
}
private static class ChromeContextInterfaceRegistrar implements InterfaceRegistrar<Context> {
@Override
public void registerInterfaces(
InterfaceRegistry registry, final Context applicationContext) {
registry.addInterface(
BarcodeDetection.MANAGER, new BarcodeDetectionImpl.Factory(applicationContext));
registry.addInterface(
TextDetection.MANAGER, new TextDetectionImpl.Factory(applicationContext));
}
}
private static class ChromeWebContentsInterfaceRegistrar
implements InterfaceRegistrar<WebContents> {
@Override
......
......@@ -964,8 +964,6 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/services/gcm/GcmUma.java",
"java/src/org/chromium/chrome/browser/services/gcm/InvalidationGcmUpstreamSender.java",
"java/src/org/chromium/chrome/browser/sessions/SessionTabHelper.java",
"java/src/org/chromium/chrome/browser/shapedetection/BarcodeDetectionImpl.java",
"java/src/org/chromium/chrome/browser/shapedetection/TextDetectionImpl.java",
"java/src/org/chromium/chrome/browser/share/OptionalShareTargetsManager.java",
"java/src/org/chromium/chrome/browser/share/ShareActivity.java",
"java/src/org/chromium/chrome/browser/share/ShareDialogAdapter.java",
......
......@@ -1233,28 +1233,21 @@ void RenderProcessHostImpl::RegisterMojoInterfaces() {
registry.get(), GetGlobalJavaInterfaces()
->CreateInterfaceFactory<
shape_detection::mojom::FaceDetectionProvider>());
AddUIThreadInterface(
registry.get(),
GetGlobalJavaInterfaces()
->CreateInterfaceFactory<shape_detection::mojom::BarcodeDetection>());
AddUIThreadInterface(
registry.get(),
GetGlobalJavaInterfaces()
->CreateInterfaceFactory<shape_detection::mojom::TextDetection>());
#else
AddUIThreadInterface(
registry.get(),
base::Bind(&ForwardShapeDetectionRequest<
shape_detection::mojom::BarcodeDetectionRequest>));
shape_detection::mojom::FaceDetectionProviderRequest>));
#endif
AddUIThreadInterface(
registry.get(),
base::Bind(&ForwardShapeDetectionRequest<
shape_detection::mojom::FaceDetectionProviderRequest>));
shape_detection::mojom::BarcodeDetectionRequest>));
AddUIThreadInterface(
registry.get(),
base::Bind(&ForwardShapeDetectionRequest<
shape_detection::mojom::TextDetectionRequest>));
#endif
AddUIThreadInterface(
registry.get(),
base::Bind(&PermissionServiceContext::CreateService,
......
......@@ -47,6 +47,41 @@ source_set("lib") {
"//services/service_manager/public/cpp",
"//services/shape_detection/public/interfaces",
]
if (is_android) {
deps += [ ":shape_detection_jni_headers" ]
}
}
if (is_android) {
generate_jni("shape_detection_jni_headers") {
sources = [
"android/java/src/org/chromium/shape_detection/InterfaceRegistrar.java",
]
jni_package = "shape_detection"
}
android_library("shape_detection_java") {
java_files = [
"android/java/src/org/chromium/shape_detection/BarcodeDetectionImpl.java",
"android/java/src/org/chromium/shape_detection/InterfaceRegistrar.java",
"android/java/src/org/chromium/shape_detection/TextDetectionImpl.java",
]
deps = [
"$google_play_services_package:google_play_services_base_java",
"$google_play_services_package:google_play_services_basement_java",
"$google_play_services_package:google_play_services_vision_java",
"//base:base_java",
"//mojo/android:system_java",
"//mojo/public/java:bindings_java",
"//mojo/public/java:system_java",
"//services/service_manager/public/interfaces:interfaces_java",
"//services/service_manager/public/java:service_manager_java",
"//services/shape_detection/public/interfaces:interfaces_java",
"//ui/gfx/geometry/mojo:mojo_java",
]
}
}
service_manifest("manifest") {
......
include_rules = [
"+media/capture/video/scoped_result_callback.h",
"+jni",
"+third_party/skia/include",
"+ui/gfx/codec",
"+ui/gl/gl_switches.h"
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.shapedetection;
package org.chromium.shape_detection;
import android.content.Context;
import android.graphics.Bitmap;
......@@ -10,13 +10,13 @@ import android.graphics.Point;
import android.graphics.Rect;
import android.util.SparseArray;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;
import com.google.android.gms.vision.Frame;
import com.google.android.gms.vision.barcode.Barcode;
import com.google.android.gms.vision.barcode.BarcodeDetector;
import org.chromium.base.Log;
import org.chromium.chrome.browser.externalauth.ExternalAuthUtils;
import org.chromium.chrome.browser.externalauth.UserRecoverableErrorHandler;
import org.chromium.gfx.mojom.PointF;
import org.chromium.gfx.mojom.RectF;
import org.chromium.mojo.system.MojoException;
......@@ -45,8 +45,8 @@ public class BarcodeDetectionImpl implements BarcodeDetection {
@Override
public void detect(
SharedBufferHandle frameData, int width, int height, DetectResponse callback) {
if (!ExternalAuthUtils.getInstance().canUseGooglePlayServices(
mContext, new UserRecoverableErrorHandler.Silent())) {
if (GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(mContext)
!= ConnectionResult.SUCCESS) {
Log.e(TAG, "Google Play Services not available");
callback.call(new BarcodeDetectionResult[0]);
return;
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.shape_detection;
import android.content.Context;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.mojo.system.impl.CoreImpl;
import org.chromium.services.service_manager.InterfaceRegistry;
import org.chromium.shape_detection.mojom.BarcodeDetection;
import org.chromium.shape_detection.mojom.TextDetection;
@JNINamespace("shape_detection")
class InterfaceRegistrar {
@CalledByNative
static void createInterfaceRegistryForContext(int nativeHandle, Context applicationContext) {
// Note: The bindings code manages the lifetime of this object, so it
// is not necessary to hold on to a reference to it explicitly.
InterfaceRegistry registry = InterfaceRegistry.create(
CoreImpl.getInstance().acquireNativeHandle(nativeHandle).toMessagePipeHandle());
registry.addInterface(
BarcodeDetection.MANAGER, new BarcodeDetectionImpl.Factory(applicationContext));
registry.addInterface(
TextDetection.MANAGER, new TextDetectionImpl.Factory(applicationContext));
}
}
......@@ -2,20 +2,20 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.shapedetection;
package org.chromium.shape_detection;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.util.SparseArray;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;
import com.google.android.gms.vision.Frame;
import com.google.android.gms.vision.text.TextBlock;
import com.google.android.gms.vision.text.TextRecognizer;
import org.chromium.base.Log;
import org.chromium.chrome.browser.externalauth.ExternalAuthUtils;
import org.chromium.chrome.browser.externalauth.UserRecoverableErrorHandler;
import org.chromium.gfx.mojom.RectF;
import org.chromium.mojo.system.MojoException;
import org.chromium.mojo.system.SharedBufferHandle;
......@@ -43,8 +43,8 @@ public class TextDetectionImpl implements TextDetection {
@Override
public void detect(
SharedBufferHandle frameData, int width, int height, DetectResponse callback) {
if (!ExternalAuthUtils.getInstance().canUseGooglePlayServices(
mContext, new UserRecoverableErrorHandler.Silent())) {
if (GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(mContext)
!= ConnectionResult.SUCCESS) {
Log.e(TAG, "Google Play Services not available");
callback.call(new TextDetectionResult[0]);
return;
......
......@@ -10,6 +10,12 @@
#include "services/shape_detection/face_detection_provider_impl.h"
#include "services/shape_detection/text_detection_impl.h"
#if defined(OS_ANDROID)
#include "base/android/context_utils.h"
#include "base/android/jni_android.h"
#include "jni/InterfaceRegistrar_jni.h"
#endif
namespace shape_detection {
std::unique_ptr<service_manager::Service> ShapeDetectionService::Create() {
......@@ -24,9 +30,18 @@ void ShapeDetectionService::OnStart() {
ref_factory_.reset(new service_manager::ServiceContextRefFactory(
base::Bind(&service_manager::ServiceContext::RequestQuit,
base::Unretained(context()))));
#if defined(OS_ANDROID)
registry_.AddInterface(
GetJavaInterfaces()->CreateInterfaceFactory<mojom::BarcodeDetection>());
registry_.AddInterface(
GetJavaInterfaces()->CreateInterfaceFactory<mojom::TextDetection>());
#else
registry_.AddInterface(base::Bind(&BarcodeDetectionImpl::Create));
registry_.AddInterface(base::Bind(&FaceDetectionProviderImpl::Create));
registry_.AddInterface(base::Bind(&TextDetectionImpl::Create));
#endif
registry_.AddInterface(base::Bind(&FaceDetectionProviderImpl::Create));
}
void ShapeDetectionService::OnBindInterface(
......@@ -37,4 +52,20 @@ void ShapeDetectionService::OnBindInterface(
std::move(interface_pipe));
}
#if defined(OS_ANDROID)
service_manager::InterfaceProvider* ShapeDetectionService::GetJavaInterfaces() {
if (!java_interface_provider_) {
service_manager::mojom::InterfaceProviderPtr provider;
Java_InterfaceRegistrar_createInterfaceRegistryForContext(
base::android::AttachCurrentThread(),
mojo::MakeRequest(&provider).PassMessagePipe().release().value(),
base::android::GetApplicationContext());
java_interface_provider_ =
base::MakeUnique<service_manager::InterfaceProvider>();
java_interface_provider_->Bind(std::move(provider));
}
return java_interface_provider_.get();
}
#endif
} // namespace shape_detection
......@@ -10,6 +10,7 @@
#include "base/callback.h"
#include "base/macros.h"
#include "services/service_manager/public/cpp/binder_registry.h"
#include "services/service_manager/public/cpp/interface_provider.h"
#include "services/service_manager/public/cpp/service.h"
#include "services/service_manager/public/cpp/service_context_ref.h"
......@@ -27,8 +28,16 @@ class ShapeDetectionService : public service_manager::Service {
void OnBindInterface(const service_manager::BindSourceInfo& source_info,
const std::string& interface_name,
mojo::ScopedMessagePipeHandle interface_pipe) override;
private:
#if defined(OS_ANDROID)
// Binds |java_interface_provider_| to an interface registry that exposes
// factories for the interfaces that are provided via Java on Android.
service_manager::InterfaceProvider* GetJavaInterfaces();
// InterfaceProvider that is bound to the Java-side interface registry.
std::unique_ptr<service_manager::InterfaceProvider> java_interface_provider_;
#endif
std::unique_ptr<service_manager::ServiceContextRefFactory> ref_factory_;
service_manager::BinderRegistry registry_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment