Move Shape Detection off Service Manager
This service is run in the GPU process and its interfaces are bound only by the browser, brokering unfiltered requests from renderers. Logic is simplified by removing all dependencies on Service Manager APIs, in favor of the browser's brokering logic talking directly to GpuProcessHost and maintaining a persistent connection to the service. Bug: 977637 Change-Id: I9047889de659b8ff61df4bae40867d3b81d8127f Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1761689 Commit-Queue: Ken Rockot <rockot@google.com> Reviewed-by: Avi Drissman <avi@chromium.org> Reviewed-by: Reilly Grant <reillyg@chromium.org> Reviewed-by: Robert Sesek <rsesek@chromium.org> Cr-Commit-Position: refs/heads/master@{#688616}
This commit is contained in:
content
browser
BUILD.gnbrowser_child_process_host_impl.hbuiltin_service_manifests.cc
gpu
renderer_interface_binders.ccservice_manager
child
gpu
utility
services/shape_detection
@ -175,7 +175,6 @@ jumbo_source_set("browser") {
|
||||
"//services/service_manager/public/mojom",
|
||||
"//services/service_manager/zygote:zygote_buildflags",
|
||||
"//services/shape_detection:lib",
|
||||
"//services/shape_detection/public/cpp:manifest",
|
||||
"//services/shape_detection/public/mojom",
|
||||
"//services/tracing:lib",
|
||||
"//services/tracing:manifest",
|
||||
|
@ -19,6 +19,8 @@
|
||||
#include "base/synchronization/waitable_event_watcher.h"
|
||||
#include "build/build_config.h"
|
||||
#include "content/browser/child_process_launcher.h"
|
||||
#include "content/common/child_process.mojom.h"
|
||||
#include "content/common/child_process_host_impl.h"
|
||||
#include "content/public/browser/browser_child_process_host.h"
|
||||
#include "content/public/browser/child_process_data.h"
|
||||
#include "content/public/common/child_process_host_delegate.h"
|
||||
@ -132,6 +134,11 @@ class CONTENT_EXPORT BrowserChildProcessHostImpl
|
||||
|
||||
IPC::Channel* child_channel() const { return channel_; }
|
||||
|
||||
mojom::ChildProcess* child_process() const {
|
||||
return static_cast<ChildProcessHostImpl*>(child_process_host_.get())
|
||||
->child_process();
|
||||
}
|
||||
|
||||
typedef std::list<BrowserChildProcessHostImpl*> BrowserChildProcessList;
|
||||
private:
|
||||
friend class BrowserChildProcessHostIterator;
|
||||
|
@ -27,7 +27,6 @@
|
||||
#include "services/network/public/cpp/manifest.h"
|
||||
#include "services/resource_coordinator/public/cpp/manifest.h"
|
||||
#include "services/service_manager/public/cpp/manifest_builder.h"
|
||||
#include "services/shape_detection/public/cpp/manifest.h"
|
||||
#include "services/tracing/manifest.h"
|
||||
|
||||
namespace content {
|
||||
@ -75,7 +74,6 @@ const std::vector<service_manager::Manifest>& GetBuiltinServiceManifests() {
|
||||
: service_manager::Manifest::ExecutionMode::
|
||||
kOutOfProcessBuiltin),
|
||||
resource_coordinator::GetManifest(),
|
||||
shape_detection::GetManifest(),
|
||||
tracing::GetManifest(),
|
||||
}};
|
||||
return *manifests;
|
||||
|
@ -43,6 +43,7 @@
|
||||
#include "content/browser/gpu/gpu_memory_buffer_manager_singleton.h"
|
||||
#include "content/browser/gpu/shader_cache_factory.h"
|
||||
#include "content/browser/service_manager/service_manager_context.h"
|
||||
#include "content/common/child_process.mojom.h"
|
||||
#include "content/common/child_process_host_impl.h"
|
||||
#include "content/common/in_process_child_thread_params.h"
|
||||
#include "content/common/service_manager/child_connection.h"
|
||||
@ -1066,6 +1067,10 @@ void GpuProcessHost::ForceShutdown() {
|
||||
process_->ForceShutdown();
|
||||
}
|
||||
|
||||
void GpuProcessHost::RunService(mojo::GenericPendingReceiver receiver) {
|
||||
process_->child_process()->BindServiceInterface(std::move(receiver));
|
||||
}
|
||||
|
||||
bool GpuProcessHost::LaunchGpuProcess() {
|
||||
const base::CommandLine& browser_command_line =
|
||||
*base::CommandLine::ForCurrentProcess();
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include "gpu/ipc/common/surface_handle.h"
|
||||
#include "ipc/ipc_sender.h"
|
||||
#include "mojo/public/cpp/bindings/binding.h"
|
||||
#include "mojo/public/cpp/bindings/generic_pending_receiver.h"
|
||||
#include "services/viz/privileged/mojom/compositing/frame_sink_manager.mojom.h"
|
||||
#include "services/viz/privileged/mojom/gl/gpu_host.mojom.h"
|
||||
#include "services/viz/privileged/mojom/gl/gpu_service.mojom.h"
|
||||
@ -97,6 +98,10 @@ class GpuProcessHost : public BrowserChildProcessHostDelegate,
|
||||
// Forcefully terminates the GPU process.
|
||||
void ForceShutdown();
|
||||
|
||||
// Asks the GPU process to run a service instance corresponding to the
|
||||
// specific interface receiver type carried by |receiver|.
|
||||
void RunService(mojo::GenericPendingReceiver receiver);
|
||||
|
||||
CONTENT_EXPORT viz::mojom::GpuService* gpu_service();
|
||||
|
||||
CONTENT_EXPORT int GetIDForTesting() const;
|
||||
|
@ -10,9 +10,11 @@
|
||||
#include "base/bind.h"
|
||||
#include "base/command_line.h"
|
||||
#include "base/no_destructor.h"
|
||||
#include "base/task/post_task.h"
|
||||
#include "content/browser/child_process_security_policy_impl.h"
|
||||
#include "content/browser/content_index/content_index_service_impl.h"
|
||||
#include "content/browser/cookie_store/cookie_store_context.h"
|
||||
#include "content/browser/gpu/gpu_process_host.h"
|
||||
#include "content/browser/locks/lock_manager.h"
|
||||
#include "content/browser/native_file_system/native_file_system_manager_impl.h"
|
||||
#include "content/browser/notifications/platform_notification_context_impl.h"
|
||||
@ -23,6 +25,7 @@
|
||||
#include "content/browser/storage_partition_impl.h"
|
||||
#include "content/browser/websockets/websocket_connector_impl.h"
|
||||
#include "content/public/browser/browser_context.h"
|
||||
#include "content/public/browser/browser_task_traits.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "content/public/browser/content_browser_client.h"
|
||||
#include "content/public/browser/render_frame_host.h"
|
||||
@ -31,14 +34,16 @@
|
||||
#include "content/public/common/content_switches.h"
|
||||
#include "media/mojo/mojom/video_decode_perf_history.mojom.h"
|
||||
#include "media/mojo/services/video_decode_perf_history.h"
|
||||
#include "mojo/public/cpp/bindings/pending_receiver.h"
|
||||
#include "mojo/public/cpp/bindings/remote.h"
|
||||
#include "mojo/public/cpp/bindings/strong_binding.h"
|
||||
#include "services/device/public/mojom/constants.mojom.h"
|
||||
#include "services/device/public/mojom/vibration_manager.mojom.h"
|
||||
#include "services/service_manager/public/cpp/binder_registry.h"
|
||||
#include "services/service_manager/public/cpp/connector.h"
|
||||
#include "services/shape_detection/public/mojom/barcodedetection_provider.mojom.h"
|
||||
#include "services/shape_detection/public/mojom/constants.mojom.h"
|
||||
#include "services/shape_detection/public/mojom/facedetection_provider.mojom.h"
|
||||
#include "services/shape_detection/public/mojom/shape_detection_service.mojom.h"
|
||||
#include "services/shape_detection/public/mojom/textdetection.mojom.h"
|
||||
#include "third_party/blink/public/common/features.h"
|
||||
#include "third_party/blink/public/mojom/cache_storage/cache_storage.mojom.h"
|
||||
@ -94,6 +99,48 @@ class RendererInterfaceBinders {
|
||||
parameterized_binder_registry_;
|
||||
};
|
||||
|
||||
void BindShapeDetectionServiceOnIOThread(
|
||||
mojo::PendingReceiver<shape_detection::mojom::ShapeDetectionService>
|
||||
receiver) {
|
||||
auto* gpu = GpuProcessHost::Get();
|
||||
if (gpu)
|
||||
gpu->RunService(std::move(receiver));
|
||||
}
|
||||
|
||||
shape_detection::mojom::ShapeDetectionService* GetShapeDetectionService() {
|
||||
static base::NoDestructor<
|
||||
mojo::Remote<shape_detection::mojom::ShapeDetectionService>>
|
||||
remote;
|
||||
if (!*remote) {
|
||||
base::PostTask(FROM_HERE, {BrowserThread::IO},
|
||||
base::BindOnce(&BindShapeDetectionServiceOnIOThread,
|
||||
remote->BindNewPipeAndPassReceiver()));
|
||||
remote->reset_on_disconnect();
|
||||
}
|
||||
|
||||
return remote->get();
|
||||
}
|
||||
|
||||
void BindBarcodeDetectionProvider(
|
||||
shape_detection::mojom::BarcodeDetectionProviderRequest request,
|
||||
RenderProcessHost* host,
|
||||
const url::Origin& origin) {
|
||||
GetShapeDetectionService()->BindBarcodeDetectionProvider(std::move(request));
|
||||
}
|
||||
|
||||
void BindFaceDetectionProvider(
|
||||
shape_detection::mojom::FaceDetectionProviderRequest request,
|
||||
RenderProcessHost* host,
|
||||
const url::Origin& origin) {
|
||||
GetShapeDetectionService()->BindFaceDetectionProvider(std::move(request));
|
||||
}
|
||||
|
||||
void BindTextDetection(shape_detection::mojom::TextDetectionRequest request,
|
||||
RenderProcessHost* host,
|
||||
const url::Origin& origin) {
|
||||
GetShapeDetectionService()->BindTextDetection(std::move(request));
|
||||
}
|
||||
|
||||
// Forwards service requests to Service Manager since the renderer cannot launch
|
||||
// out-of-process services on is own.
|
||||
template <typename Interface>
|
||||
@ -112,15 +159,13 @@ void ForwardServiceRequest(const char* service_name,
|
||||
// interface requests from frames, binders registered on the frame itself
|
||||
// override binders registered here.
|
||||
void RendererInterfaceBinders::InitializeParameterizedBinderRegistry() {
|
||||
parameterized_binder_registry_.AddInterface(base::Bind(
|
||||
&ForwardServiceRequest<shape_detection::mojom::BarcodeDetectionProvider>,
|
||||
shape_detection::mojom::kServiceName));
|
||||
parameterized_binder_registry_.AddInterface(base::Bind(
|
||||
&ForwardServiceRequest<shape_detection::mojom::FaceDetectionProvider>,
|
||||
shape_detection::mojom::kServiceName));
|
||||
parameterized_binder_registry_.AddInterface(
|
||||
base::Bind(&ForwardServiceRequest<shape_detection::mojom::TextDetection>,
|
||||
shape_detection::mojom::kServiceName));
|
||||
base::BindRepeating(&BindBarcodeDetectionProvider));
|
||||
parameterized_binder_registry_.AddInterface(
|
||||
base::BindRepeating(&BindFaceDetectionProvider));
|
||||
parameterized_binder_registry_.AddInterface(
|
||||
base::BindRepeating(&BindTextDetection));
|
||||
|
||||
parameterized_binder_registry_.AddInterface(
|
||||
base::Bind(&ForwardServiceRequest<device::mojom::VibrationManager>,
|
||||
device::mojom::kServiceName));
|
||||
|
@ -82,7 +82,6 @@
|
||||
#include "services/service_manager/service_manager.h"
|
||||
#include "services/service_manager/service_process_host.h"
|
||||
#include "services/service_manager/service_process_launcher.h"
|
||||
#include "services/shape_detection/public/mojom/constants.mojom.h"
|
||||
#include "services/tracing/public/cpp/tracing_features.h"
|
||||
#include "services/tracing/public/mojom/constants.mojom.h"
|
||||
#include "services/tracing/tracing_service.h"
|
||||
@ -428,8 +427,6 @@ class BrowserServiceManagerDelegate
|
||||
if (identity.name() == media::mojom::kMediaServiceName)
|
||||
run_in_gpu_process = true;
|
||||
#endif
|
||||
if (identity.name() == shape_detection::mojom::kServiceName)
|
||||
run_in_gpu_process = true;
|
||||
return std::make_unique<ContentChildServiceProcessHost>(run_in_gpu_process,
|
||||
child_flags);
|
||||
}
|
||||
|
@ -358,7 +358,13 @@ class ChildProcessImpl : public mojom::ChildProcess {
|
||||
|
||||
void BindServiceInterface(mojo::GenericPendingReceiver receiver) override {
|
||||
if (service_binder_)
|
||||
service_binder_.Run(std::move(receiver));
|
||||
service_binder_.Run(&receiver);
|
||||
|
||||
if (receiver) {
|
||||
main_thread_task_runner_->PostTask(
|
||||
FROM_HERE, base::BindOnce(&ChildThreadImpl::BindServiceInterface,
|
||||
weak_main_thread_, std::move(receiver)));
|
||||
}
|
||||
}
|
||||
|
||||
void BindReceiver(mojo::GenericPendingReceiver receiver) override {
|
||||
@ -878,6 +884,12 @@ void ChildThreadImpl::RunService(
|
||||
DLOG(ERROR) << "Ignoring unhandled request to run service: " << service_name;
|
||||
}
|
||||
|
||||
void ChildThreadImpl::BindServiceInterface(
|
||||
mojo::GenericPendingReceiver receiver) {
|
||||
DLOG(ERROR) << "Ignoring unhandled request to bind service interface: "
|
||||
<< *receiver.interface_name();
|
||||
}
|
||||
|
||||
void ChildThreadImpl::OnBindReceiver(mojo::GenericPendingReceiver receiver) {}
|
||||
|
||||
ChildThreadImpl* ChildThreadImpl::current() {
|
||||
|
@ -143,6 +143,8 @@ class CONTENT_EXPORT ChildThreadImpl
|
||||
const std::string& service_name,
|
||||
mojo::PendingReceiver<service_manager::mojom::Service> receiver);
|
||||
|
||||
virtual void BindServiceInterface(mojo::GenericPendingReceiver receiver);
|
||||
|
||||
virtual void OnBindReceiver(mojo::GenericPendingReceiver receiver);
|
||||
|
||||
protected:
|
||||
@ -274,7 +276,7 @@ struct ChildThreadImpl::Options {
|
||||
scoped_refptr<base::SingleThreadTaskRunner> ipc_task_runner;
|
||||
|
||||
using ServiceBinder =
|
||||
base::RepeatingCallback<void(mojo::GenericPendingReceiver)>;
|
||||
base::RepeatingCallback<void(mojo::GenericPendingReceiver*)>;
|
||||
ServiceBinder service_binder;
|
||||
|
||||
private:
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "base/callback_helpers.h"
|
||||
#include "base/command_line.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "base/no_destructor.h"
|
||||
#include "base/run_loop.h"
|
||||
#include "base/sequenced_task_runner.h"
|
||||
#include "base/threading/thread_checker.h"
|
||||
@ -34,6 +35,8 @@
|
||||
#include "media/gpu/ipc/service/media_gpu_channel_manager.h"
|
||||
#include "services/service_manager/public/cpp/binder_registry.h"
|
||||
#include "services/service_manager/public/cpp/connector.h"
|
||||
#include "services/shape_detection/public/mojom/shape_detection_service.mojom.h"
|
||||
#include "services/shape_detection/shape_detection_service.h"
|
||||
#include "services/viz/privileged/mojom/gl/gpu_service.mojom.h"
|
||||
#include "third_party/skia/include/core/SkGraphics.h"
|
||||
|
||||
@ -288,6 +291,16 @@ void GpuChildThread::RunService(
|
||||
service_factory_->RunService(service_name, std::move(receiver));
|
||||
}
|
||||
|
||||
void GpuChildThread::BindServiceInterface(
|
||||
mojo::GenericPendingReceiver receiver) {
|
||||
if (auto shape_detection_receiver =
|
||||
receiver.As<shape_detection::mojom::ShapeDetectionService>()) {
|
||||
static base::NoDestructor<shape_detection::ShapeDetectionService> service{
|
||||
std::move(shape_detection_receiver)};
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void GpuChildThread::OnAssociatedInterfaceRequest(
|
||||
const std::string& name,
|
||||
mojo::ScopedInterfaceEndpointHandle handle) {
|
||||
|
@ -74,6 +74,7 @@ class GpuChildThread : public ChildThreadImpl,
|
||||
void RunService(
|
||||
const std::string& service_name,
|
||||
mojo::PendingReceiver<service_manager::mojom::Service> receiver) override;
|
||||
void BindServiceInterface(mojo::GenericPendingReceiver receiver) override;
|
||||
|
||||
// IPC::Listener implementation via ChildThreadImpl:
|
||||
void OnAssociatedInterfaceRequest(
|
||||
|
@ -9,8 +9,6 @@
|
||||
#include "base/task/post_task.h"
|
||||
#include "base/threading/thread_task_runner_handle.h"
|
||||
#include "build/build_config.h"
|
||||
#include "services/shape_detection/public/mojom/constants.mojom.h"
|
||||
#include "services/shape_detection/shape_detection_service.h"
|
||||
|
||||
#if BUILDFLAG(ENABLE_MOJO_MEDIA_IN_GPU_PROCESS)
|
||||
#include "base/bind.h"
|
||||
@ -84,13 +82,6 @@ void GpuServiceFactory::RunService(
|
||||
return;
|
||||
}
|
||||
#endif // BUILDFLAG(ENABLE_MOJO_MEDIA_IN_GPU_PROCESS)
|
||||
|
||||
if (service_name == shape_detection::mojom::kServiceName) {
|
||||
service_manager::Service::RunAsyncUntilTermination(
|
||||
std::make_unique<shape_detection::ShapeDetectionService>(
|
||||
std::move(request)));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace content
|
||||
|
@ -46,18 +46,18 @@ class ServiceBinderImpl {
|
||||
: main_thread_task_runner_(std::move(main_thread_task_runner)) {}
|
||||
~ServiceBinderImpl() = default;
|
||||
|
||||
void BindServiceInterface(mojo::GenericPendingReceiver receiver) {
|
||||
void BindServiceInterface(mojo::GenericPendingReceiver* receiver) {
|
||||
// We watch for and terminate on PEER_CLOSED, but we also terminate if the
|
||||
// watcher is cancelled (meaning the local endpoint was closed rather than
|
||||
// the peer). Hence any breakage of the service pipe leads to termination.
|
||||
auto watcher = std::make_unique<mojo::SimpleWatcher>(
|
||||
FROM_HERE, mojo::SimpleWatcher::ArmingPolicy::AUTOMATIC);
|
||||
watcher->Watch(receiver.pipe(), MOJO_HANDLE_SIGNAL_PEER_CLOSED,
|
||||
watcher->Watch(receiver->pipe(), MOJO_HANDLE_SIGNAL_PEER_CLOSED,
|
||||
MOJO_TRIGGER_CONDITION_SIGNALS_SATISFIED,
|
||||
base::BindRepeating(&ServiceBinderImpl::OnServicePipeClosed,
|
||||
base::Unretained(this), watcher.get()));
|
||||
service_pipe_watchers_.insert(std::move(watcher));
|
||||
HandleServiceRequestOnIOThread(std::move(receiver),
|
||||
HandleServiceRequestOnIOThread(std::move(*receiver),
|
||||
main_thread_task_runner_.get());
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,6 @@ source_set("lib") {
|
||||
public_deps = [
|
||||
"//base",
|
||||
"//media/capture",
|
||||
"//services/service_manager/public/cpp",
|
||||
"//services/shape_detection/public/mojom",
|
||||
]
|
||||
|
||||
@ -105,8 +104,6 @@ if (is_android) {
|
||||
"//mojo/public/java:bindings_java",
|
||||
"//mojo/public/java:system_java",
|
||||
"//mojo/public/java/system:system_impl_java",
|
||||
"//services/service_manager/public/java:service_manager_java",
|
||||
"//services/service_manager/public/mojom:mojom_java",
|
||||
"//services/shape_detection/public/mojom:mojom_java",
|
||||
"//skia/public/mojom:mojom_java",
|
||||
"//ui/gfx/geometry/mojom:mojom_java",
|
||||
|
@ -11,7 +11,6 @@ import org.chromium.base.ContextUtils;
|
||||
import org.chromium.base.Log;
|
||||
import org.chromium.mojo.bindings.InterfaceRequest;
|
||||
import org.chromium.mojo.system.MojoException;
|
||||
import org.chromium.services.service_manager.InterfaceFactory;
|
||||
import org.chromium.shape_detection.mojom.BarcodeDetection;
|
||||
import org.chromium.shape_detection.mojom.BarcodeDetectionProvider;
|
||||
import org.chromium.shape_detection.mojom.BarcodeDetectorOptions;
|
||||
@ -50,21 +49,13 @@ public class BarcodeDetectionProviderImpl implements BarcodeDetectionProvider {
|
||||
@Override
|
||||
public void onConnectionError(MojoException e) {}
|
||||
|
||||
/**
|
||||
* A factory class to register BarcodeDetectionProvider interface.
|
||||
*/
|
||||
public static class Factory implements InterfaceFactory<BarcodeDetectionProvider> {
|
||||
public Factory() {}
|
||||
|
||||
@Override
|
||||
public BarcodeDetectionProvider createImpl() {
|
||||
if (GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(
|
||||
ContextUtils.getApplicationContext())
|
||||
!= ConnectionResult.SUCCESS) {
|
||||
Log.e(TAG, "Google Play Services not available");
|
||||
return null;
|
||||
}
|
||||
return new BarcodeDetectionProviderImpl();
|
||||
public static BarcodeDetectionProvider create() {
|
||||
if (GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(
|
||||
ContextUtils.getApplicationContext())
|
||||
!= ConnectionResult.SUCCESS) {
|
||||
Log.e(TAG, "Google Play Services not available");
|
||||
return null;
|
||||
}
|
||||
return new BarcodeDetectionProviderImpl();
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ import com.google.android.gms.common.GoogleApiAvailability;
|
||||
import org.chromium.base.ContextUtils;
|
||||
import org.chromium.mojo.bindings.InterfaceRequest;
|
||||
import org.chromium.mojo.system.MojoException;
|
||||
import org.chromium.services.service_manager.InterfaceFactory;
|
||||
import org.chromium.shape_detection.mojom.FaceDetection;
|
||||
import org.chromium.shape_detection.mojom.FaceDetectionProvider;
|
||||
import org.chromium.shape_detection.mojom.FaceDetectorOptions;
|
||||
@ -41,16 +40,4 @@ public class FaceDetectionProviderImpl implements FaceDetectionProvider {
|
||||
|
||||
@Override
|
||||
public void onConnectionError(MojoException e) {}
|
||||
|
||||
/**
|
||||
* A factory class to register FaceDetectionProvider interface.
|
||||
*/
|
||||
public static class Factory implements InterfaceFactory<FaceDetectionProvider> {
|
||||
public Factory() {}
|
||||
|
||||
@Override
|
||||
public FaceDetectionProvider createImpl() {
|
||||
return new FaceDetectionProviderImpl();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,24 +6,37 @@ package org.chromium.shape_detection;
|
||||
|
||||
import org.chromium.base.annotations.CalledByNative;
|
||||
import org.chromium.base.annotations.JNINamespace;
|
||||
import org.chromium.mojo.system.MessagePipeHandle;
|
||||
import org.chromium.mojo.system.impl.CoreImpl;
|
||||
import org.chromium.services.service_manager.InterfaceRegistry;
|
||||
import org.chromium.shape_detection.mojom.BarcodeDetectionProvider;
|
||||
import org.chromium.shape_detection.mojom.FaceDetectionProvider;
|
||||
import org.chromium.shape_detection.mojom.TextDetection;
|
||||
|
||||
@JNINamespace("shape_detection")
|
||||
class InterfaceRegistrar {
|
||||
static MessagePipeHandle messagePipeHandleFromNative(int nativeHandle) {
|
||||
return CoreImpl.getInstance().acquireNativeHandle(nativeHandle).toMessagePipeHandle();
|
||||
}
|
||||
|
||||
@CalledByNative
|
||||
static void createInterfaceRegistryForContext(int nativeHandle) {
|
||||
// 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(
|
||||
BarcodeDetectionProvider.MANAGER, new BarcodeDetectionProviderImpl.Factory());
|
||||
registry.addInterface(
|
||||
FaceDetectionProvider.MANAGER, new FaceDetectionProviderImpl.Factory());
|
||||
registry.addInterface(TextDetection.MANAGER, new TextDetectionImpl.Factory());
|
||||
static void bindBarcodeDetectionProvider(int nativeHandle) {
|
||||
BarcodeDetectionProvider impl = BarcodeDetectionProviderImpl.create();
|
||||
if (impl != null) {
|
||||
BarcodeDetectionProvider.MANAGER.bind(impl, messagePipeHandleFromNative(nativeHandle));
|
||||
}
|
||||
}
|
||||
|
||||
@CalledByNative
|
||||
static void bindFaceDetectionProvider(int nativeHandle) {
|
||||
FaceDetectionProvider.MANAGER.bind(
|
||||
new FaceDetectionProviderImpl(), messagePipeHandleFromNative(nativeHandle));
|
||||
}
|
||||
|
||||
@CalledByNative
|
||||
static void bindTextDetection(int nativeHandle) {
|
||||
TextDetection impl = TextDetectionImpl.create();
|
||||
if (impl != null) {
|
||||
TextDetection.MANAGER.bind(impl, messagePipeHandleFromNative(nativeHandle));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,6 @@ import org.chromium.base.Log;
|
||||
import org.chromium.gfx.mojom.PointF;
|
||||
import org.chromium.gfx.mojom.RectF;
|
||||
import org.chromium.mojo.system.MojoException;
|
||||
import org.chromium.services.service_manager.InterfaceFactory;
|
||||
import org.chromium.shape_detection.mojom.TextDetection;
|
||||
import org.chromium.shape_detection.mojom.TextDetectionResult;
|
||||
|
||||
@ -89,21 +88,13 @@ public class TextDetectionImpl implements TextDetection {
|
||||
close();
|
||||
}
|
||||
|
||||
/**
|
||||
* A factory class to register TextDetection interface.
|
||||
*/
|
||||
public static class Factory implements InterfaceFactory<TextDetection> {
|
||||
public Factory() {}
|
||||
|
||||
@Override
|
||||
public TextDetection createImpl() {
|
||||
if (GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(
|
||||
ContextUtils.getApplicationContext())
|
||||
!= ConnectionResult.SUCCESS) {
|
||||
Log.e(TAG, "Google Play Services not available");
|
||||
return null;
|
||||
}
|
||||
return new TextDetectionImpl();
|
||||
public static TextDetection create() {
|
||||
if (GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(
|
||||
ContextUtils.getApplicationContext())
|
||||
!= ConnectionResult.SUCCESS) {
|
||||
Log.e(TAG, "Google Play Services not available");
|
||||
return null;
|
||||
}
|
||||
return new TextDetectionImpl();
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +0,0 @@
|
||||
# Copyright 2019 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.
|
||||
|
||||
source_set("manifest") {
|
||||
sources = [
|
||||
"manifest.cc",
|
||||
"manifest.h",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//base",
|
||||
"//services/service_manager/public/cpp",
|
||||
"//services/shape_detection/public/mojom",
|
||||
]
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
per-file manifest.cc=set noparent
|
||||
per-file manifest.cc=file://ipc/SECURITY_OWNERS
|
||||
per-file manifest.h=set noparent
|
||||
per-file manifest.h=file://ipc/SECURITY_OWNERS
|
@ -1,42 +0,0 @@
|
||||
// Copyright 2019 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.
|
||||
|
||||
#include "services/shape_detection/public/cpp/manifest.h"
|
||||
|
||||
#include "base/no_destructor.h"
|
||||
#include "services/service_manager/public/cpp/manifest_builder.h"
|
||||
#include "services/shape_detection/public/mojom/barcodedetection_provider.mojom.h"
|
||||
#include "services/shape_detection/public/mojom/constants.mojom.h"
|
||||
#include "services/shape_detection/public/mojom/facedetection_provider.mojom.h"
|
||||
#include "services/shape_detection/public/mojom/textdetection.mojom.h"
|
||||
|
||||
namespace shape_detection {
|
||||
|
||||
const service_manager::Manifest& GetManifest() {
|
||||
static base::NoDestructor<service_manager::Manifest> manifest{
|
||||
service_manager::ManifestBuilder()
|
||||
.WithServiceName(mojom::kServiceName)
|
||||
.WithDisplayName("Shape Detection Service")
|
||||
.WithOptions(
|
||||
service_manager::ManifestOptionsBuilder()
|
||||
.WithExecutionMode(service_manager::Manifest::ExecutionMode::
|
||||
kOutOfProcessBuiltin)
|
||||
.WithInstanceSharingPolicy(
|
||||
service_manager::Manifest::InstanceSharingPolicy::
|
||||
kSharedAcrossGroups)
|
||||
.Build())
|
||||
.ExposeCapability("barcode_detection",
|
||||
service_manager::Manifest::InterfaceList<
|
||||
mojom::BarcodeDetectionProvider>())
|
||||
.ExposeCapability("face_detection",
|
||||
service_manager::Manifest::InterfaceList<
|
||||
mojom::FaceDetectionProvider>())
|
||||
.ExposeCapability(
|
||||
"text_detection",
|
||||
service_manager::Manifest::InterfaceList<mojom::TextDetection>())
|
||||
.Build()};
|
||||
return *manifest;
|
||||
}
|
||||
|
||||
} // namespace shape_detection
|
@ -1,16 +0,0 @@
|
||||
// Copyright 2019 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.
|
||||
|
||||
#ifndef SERVICES_SHAPE_DETECTION_PUBLIC_CPP_MANIFEST_H_
|
||||
#define SERVICES_SHAPE_DETECTION_PUBLIC_CPP_MANIFEST_H_
|
||||
|
||||
#include "services/service_manager/public/cpp/manifest.h"
|
||||
|
||||
namespace shape_detection {
|
||||
|
||||
const service_manager::Manifest& GetManifest();
|
||||
|
||||
} // namespace shape_detection
|
||||
|
||||
#endif // SERVICES_SHAPE_DETECTION_PUBLIC_CPP_MANIFEST_H_
|
@ -8,9 +8,9 @@ mojom("mojom") {
|
||||
sources = [
|
||||
"barcodedetection.mojom",
|
||||
"barcodedetection_provider.mojom",
|
||||
"constants.mojom",
|
||||
"facedetection.mojom",
|
||||
"facedetection_provider.mojom",
|
||||
"shape_detection_service.mojom",
|
||||
"textdetection.mojom",
|
||||
]
|
||||
|
||||
|
@ -1,9 +0,0 @@
|
||||
// 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.
|
||||
|
||||
// https://wicg.github.io/shape-detection-api/#api
|
||||
|
||||
module shape_detection.mojom;
|
||||
|
||||
const string kServiceName = "shape_detection";
|
@ -0,0 +1,22 @@
|
||||
// Copyright 2019 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.
|
||||
|
||||
module shape_detection.mojom;
|
||||
|
||||
import "services/shape_detection/public/mojom/barcodedetection_provider.mojom";
|
||||
import "services/shape_detection/public/mojom/facedetection_provider.mojom";
|
||||
import "services/shape_detection/public/mojom/textdetection.mojom";
|
||||
|
||||
// The main interface to the Shape Detection service.
|
||||
interface ShapeDetectionService {
|
||||
// Binds an endpoint which can be used to detect barcodes in images.
|
||||
BindBarcodeDetectionProvider(
|
||||
pending_receiver<BarcodeDetectionProvider> receiver);
|
||||
|
||||
// Binds an endpoint which can be used to detect faces in images.
|
||||
BindFaceDetectionProvider(pending_receiver<FaceDetectionProvider> receiver);
|
||||
|
||||
// Binds an endpoint which can be used to detect text in images.
|
||||
BindTextDetection(pending_receiver<TextDetection> receiver);
|
||||
};
|
@ -30,8 +30,8 @@
|
||||
namespace shape_detection {
|
||||
|
||||
ShapeDetectionService::ShapeDetectionService(
|
||||
service_manager::mojom::ServiceRequest request)
|
||||
: service_binding_(this, std::move(request)) {
|
||||
mojo::PendingReceiver<mojom::ShapeDetectionService> receiver)
|
||||
: receiver_(this, std::move(receiver)) {
|
||||
#if defined(OS_MACOSX)
|
||||
if (__builtin_available(macOS 10.13, *)) {
|
||||
vision_framework_ =
|
||||
@ -49,51 +49,43 @@ ShapeDetectionService::~ShapeDetectionService() {
|
||||
#endif
|
||||
}
|
||||
|
||||
void ShapeDetectionService::OnStart() {
|
||||
void ShapeDetectionService::BindBarcodeDetectionProvider(
|
||||
mojo::PendingReceiver<mojom::BarcodeDetectionProvider> receiver) {
|
||||
#if defined(OS_ANDROID)
|
||||
registry_.AddInterface(
|
||||
GetJavaInterfaces()
|
||||
->CreateInterfaceFactory<mojom::BarcodeDetectionProvider>());
|
||||
registry_.AddInterface(
|
||||
GetJavaInterfaces()
|
||||
->CreateInterfaceFactory<mojom::FaceDetectionProvider>());
|
||||
registry_.AddInterface(
|
||||
GetJavaInterfaces()->CreateInterfaceFactory<mojom::TextDetection>());
|
||||
#elif defined(OS_WIN)
|
||||
registry_.AddInterface(base::Bind(&BarcodeDetectionProviderImpl::Create));
|
||||
registry_.AddInterface(base::Bind(&TextDetectionImpl::Create));
|
||||
registry_.AddInterface(base::Bind(&FaceDetectionProviderWin::Create));
|
||||
Java_InterfaceRegistrar_bindBarcodeDetectionProvider(
|
||||
base::android::AttachCurrentThread(),
|
||||
receiver.PassPipe().release().value());
|
||||
#elif defined(OS_MACOSX)
|
||||
registry_.AddInterface(base::Bind(&BarcodeDetectionProviderMac::Create));
|
||||
registry_.AddInterface(base::Bind(&TextDetectionImpl::Create));
|
||||
registry_.AddInterface(base::Bind(&FaceDetectionProviderMac::Create));
|
||||
BarcodeDetectionProviderMac::Create(std::move(receiver));
|
||||
#else
|
||||
registry_.AddInterface(base::Bind(&BarcodeDetectionProviderImpl::Create));
|
||||
registry_.AddInterface(base::Bind(&FaceDetectionProviderImpl::Create));
|
||||
registry_.AddInterface(base::Bind(&TextDetectionImpl::Create));
|
||||
BarcodeDetectionProviderImpl::Create(std::move(receiver));
|
||||
#endif
|
||||
}
|
||||
|
||||
void ShapeDetectionService::OnBindInterface(
|
||||
const service_manager::BindSourceInfo& source_info,
|
||||
const std::string& interface_name,
|
||||
mojo::ScopedMessagePipeHandle interface_pipe) {
|
||||
registry_.BindInterface(interface_name, std::move(interface_pipe));
|
||||
}
|
||||
|
||||
void ShapeDetectionService::BindFaceDetectionProvider(
|
||||
mojo::PendingReceiver<mojom::FaceDetectionProvider> receiver) {
|
||||
#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());
|
||||
java_interface_provider_ =
|
||||
std::make_unique<service_manager::InterfaceProvider>();
|
||||
java_interface_provider_->Bind(std::move(provider));
|
||||
}
|
||||
return java_interface_provider_.get();
|
||||
}
|
||||
Java_InterfaceRegistrar_bindFaceDetectionProvider(
|
||||
base::android::AttachCurrentThread(),
|
||||
receiver.PassPipe().release().value());
|
||||
#elif defined(OS_MACOSX)
|
||||
FaceDetectionProviderMac::Create(std::move(receiver));
|
||||
#elif defined(OS_WIN)
|
||||
FaceDetectionProviderWin::Create(std::move(receiver));
|
||||
#else
|
||||
FaceDetectionProviderImpl::Create(std::move(receiver));
|
||||
#endif
|
||||
}
|
||||
|
||||
void ShapeDetectionService::BindTextDetection(
|
||||
mojo::PendingReceiver<mojom::TextDetection> receiver) {
|
||||
#if defined(OS_ANDROID)
|
||||
Java_InterfaceRegistrar_bindTextDetection(
|
||||
base::android::AttachCurrentThread(),
|
||||
receiver.PassPipe().release().value());
|
||||
#else
|
||||
TextDetectionImpl::Create(std::move(receiver));
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace shape_detection
|
||||
|
@ -10,39 +10,33 @@
|
||||
#include "base/callback.h"
|
||||
#include "base/macros.h"
|
||||
#include "build/build_config.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_binding.h"
|
||||
#include "services/service_manager/public/mojom/service.mojom.h"
|
||||
#include "mojo/public/cpp/bindings/pending_receiver.h"
|
||||
#include "mojo/public/cpp/bindings/receiver.h"
|
||||
#include "services/shape_detection/public/mojom/shape_detection_service.mojom.h"
|
||||
|
||||
namespace shape_detection {
|
||||
|
||||
class ShapeDetectionService : public service_manager::Service {
|
||||
class ShapeDetectionService : public mojom::ShapeDetectionService {
|
||||
public:
|
||||
explicit ShapeDetectionService(
|
||||
service_manager::mojom::ServiceRequest request);
|
||||
mojo::PendingReceiver<mojom::ShapeDetectionService> receiver);
|
||||
~ShapeDetectionService() override;
|
||||
|
||||
void OnStart() override;
|
||||
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();
|
||||
// mojom::ShapeDetectionService implementation:
|
||||
void BindBarcodeDetectionProvider(
|
||||
mojo::PendingReceiver<mojom::BarcodeDetectionProvider> receiver) override;
|
||||
void BindFaceDetectionProvider(
|
||||
mojo::PendingReceiver<mojom::FaceDetectionProvider> receiver) override;
|
||||
void BindTextDetection(
|
||||
mojo::PendingReceiver<mojom::TextDetection> receiver) override;
|
||||
|
||||
// InterfaceProvider that is bound to the Java-side interface registry.
|
||||
std::unique_ptr<service_manager::InterfaceProvider> java_interface_provider_;
|
||||
#elif defined(OS_MACOSX)
|
||||
private:
|
||||
mojo::Receiver<mojom::ShapeDetectionService> receiver_;
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
void* vision_framework_;
|
||||
#endif
|
||||
|
||||
service_manager::ServiceBinding service_binding_;
|
||||
service_manager::BinderRegistry registry_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(ShapeDetectionService);
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user