Commit 8322a04a authored by Ken Rockot's avatar Ken Rockot Committed by Commit Bot

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: default avatarAvi Drissman <avi@chromium.org>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Cr-Commit-Position: refs/heads/master@{#688616}
parent eae7834a
...@@ -175,7 +175,6 @@ jumbo_source_set("browser") { ...@@ -175,7 +175,6 @@ jumbo_source_set("browser") {
"//services/service_manager/public/mojom", "//services/service_manager/public/mojom",
"//services/service_manager/zygote:zygote_buildflags", "//services/service_manager/zygote:zygote_buildflags",
"//services/shape_detection:lib", "//services/shape_detection:lib",
"//services/shape_detection/public/cpp:manifest",
"//services/shape_detection/public/mojom", "//services/shape_detection/public/mojom",
"//services/tracing:lib", "//services/tracing:lib",
"//services/tracing:manifest", "//services/tracing:manifest",
......
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
#include "base/synchronization/waitable_event_watcher.h" #include "base/synchronization/waitable_event_watcher.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "content/browser/child_process_launcher.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/browser_child_process_host.h"
#include "content/public/browser/child_process_data.h" #include "content/public/browser/child_process_data.h"
#include "content/public/common/child_process_host_delegate.h" #include "content/public/common/child_process_host_delegate.h"
...@@ -132,6 +134,11 @@ class CONTENT_EXPORT BrowserChildProcessHostImpl ...@@ -132,6 +134,11 @@ class CONTENT_EXPORT BrowserChildProcessHostImpl
IPC::Channel* child_channel() const { return channel_; } 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; typedef std::list<BrowserChildProcessHostImpl*> BrowserChildProcessList;
private: private:
friend class BrowserChildProcessHostIterator; friend class BrowserChildProcessHostIterator;
......
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
#include "services/network/public/cpp/manifest.h" #include "services/network/public/cpp/manifest.h"
#include "services/resource_coordinator/public/cpp/manifest.h" #include "services/resource_coordinator/public/cpp/manifest.h"
#include "services/service_manager/public/cpp/manifest_builder.h" #include "services/service_manager/public/cpp/manifest_builder.h"
#include "services/shape_detection/public/cpp/manifest.h"
#include "services/tracing/manifest.h" #include "services/tracing/manifest.h"
namespace content { namespace content {
...@@ -75,7 +74,6 @@ const std::vector<service_manager::Manifest>& GetBuiltinServiceManifests() { ...@@ -75,7 +74,6 @@ const std::vector<service_manager::Manifest>& GetBuiltinServiceManifests() {
: service_manager::Manifest::ExecutionMode:: : service_manager::Manifest::ExecutionMode::
kOutOfProcessBuiltin), kOutOfProcessBuiltin),
resource_coordinator::GetManifest(), resource_coordinator::GetManifest(),
shape_detection::GetManifest(),
tracing::GetManifest(), tracing::GetManifest(),
}}; }};
return *manifests; return *manifests;
......
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
#include "content/browser/gpu/gpu_memory_buffer_manager_singleton.h" #include "content/browser/gpu/gpu_memory_buffer_manager_singleton.h"
#include "content/browser/gpu/shader_cache_factory.h" #include "content/browser/gpu/shader_cache_factory.h"
#include "content/browser/service_manager/service_manager_context.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/child_process_host_impl.h"
#include "content/common/in_process_child_thread_params.h" #include "content/common/in_process_child_thread_params.h"
#include "content/common/service_manager/child_connection.h" #include "content/common/service_manager/child_connection.h"
...@@ -1066,6 +1067,10 @@ void GpuProcessHost::ForceShutdown() { ...@@ -1066,6 +1067,10 @@ void GpuProcessHost::ForceShutdown() {
process_->ForceShutdown(); process_->ForceShutdown();
} }
void GpuProcessHost::RunService(mojo::GenericPendingReceiver receiver) {
process_->child_process()->BindServiceInterface(std::move(receiver));
}
bool GpuProcessHost::LaunchGpuProcess() { bool GpuProcessHost::LaunchGpuProcess() {
const base::CommandLine& browser_command_line = const base::CommandLine& browser_command_line =
*base::CommandLine::ForCurrentProcess(); *base::CommandLine::ForCurrentProcess();
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "gpu/ipc/common/surface_handle.h" #include "gpu/ipc/common/surface_handle.h"
#include "ipc/ipc_sender.h" #include "ipc/ipc_sender.h"
#include "mojo/public/cpp/bindings/binding.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/compositing/frame_sink_manager.mojom.h"
#include "services/viz/privileged/mojom/gl/gpu_host.mojom.h" #include "services/viz/privileged/mojom/gl/gpu_host.mojom.h"
#include "services/viz/privileged/mojom/gl/gpu_service.mojom.h" #include "services/viz/privileged/mojom/gl/gpu_service.mojom.h"
...@@ -97,6 +98,10 @@ class GpuProcessHost : public BrowserChildProcessHostDelegate, ...@@ -97,6 +98,10 @@ class GpuProcessHost : public BrowserChildProcessHostDelegate,
// Forcefully terminates the GPU process. // Forcefully terminates the GPU process.
void ForceShutdown(); 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 viz::mojom::GpuService* gpu_service();
CONTENT_EXPORT int GetIDForTesting() const; CONTENT_EXPORT int GetIDForTesting() const;
......
...@@ -10,9 +10,11 @@ ...@@ -10,9 +10,11 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/no_destructor.h" #include "base/no_destructor.h"
#include "base/task/post_task.h"
#include "content/browser/child_process_security_policy_impl.h" #include "content/browser/child_process_security_policy_impl.h"
#include "content/browser/content_index/content_index_service_impl.h" #include "content/browser/content_index/content_index_service_impl.h"
#include "content/browser/cookie_store/cookie_store_context.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/locks/lock_manager.h"
#include "content/browser/native_file_system/native_file_system_manager_impl.h" #include "content/browser/native_file_system/native_file_system_manager_impl.h"
#include "content/browser/notifications/platform_notification_context_impl.h" #include "content/browser/notifications/platform_notification_context_impl.h"
...@@ -23,6 +25,7 @@ ...@@ -23,6 +25,7 @@
#include "content/browser/storage_partition_impl.h" #include "content/browser/storage_partition_impl.h"
#include "content/browser/websockets/websocket_connector_impl.h" #include "content/browser/websockets/websocket_connector_impl.h"
#include "content/public/browser/browser_context.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/browser_thread.h"
#include "content/public/browser/content_browser_client.h" #include "content/public/browser/content_browser_client.h"
#include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_frame_host.h"
...@@ -31,14 +34,16 @@ ...@@ -31,14 +34,16 @@
#include "content/public/common/content_switches.h" #include "content/public/common/content_switches.h"
#include "media/mojo/mojom/video_decode_perf_history.mojom.h" #include "media/mojo/mojom/video_decode_perf_history.mojom.h"
#include "media/mojo/services/video_decode_perf_history.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 "mojo/public/cpp/bindings/strong_binding.h"
#include "services/device/public/mojom/constants.mojom.h" #include "services/device/public/mojom/constants.mojom.h"
#include "services/device/public/mojom/vibration_manager.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/binder_registry.h"
#include "services/service_manager/public/cpp/connector.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/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/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 "services/shape_detection/public/mojom/textdetection.mojom.h"
#include "third_party/blink/public/common/features.h" #include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/mojom/cache_storage/cache_storage.mojom.h" #include "third_party/blink/public/mojom/cache_storage/cache_storage.mojom.h"
...@@ -94,6 +99,48 @@ class RendererInterfaceBinders { ...@@ -94,6 +99,48 @@ class RendererInterfaceBinders {
parameterized_binder_registry_; 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 // Forwards service requests to Service Manager since the renderer cannot launch
// out-of-process services on is own. // out-of-process services on is own.
template <typename Interface> template <typename Interface>
...@@ -112,15 +159,13 @@ void ForwardServiceRequest(const char* service_name, ...@@ -112,15 +159,13 @@ void ForwardServiceRequest(const char* service_name,
// interface requests from frames, binders registered on the frame itself // interface requests from frames, binders registered on the frame itself
// override binders registered here. // override binders registered here.
void RendererInterfaceBinders::InitializeParameterizedBinderRegistry() { 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( parameterized_binder_registry_.AddInterface(
base::Bind(&ForwardServiceRequest<shape_detection::mojom::TextDetection>, base::BindRepeating(&BindBarcodeDetectionProvider));
shape_detection::mojom::kServiceName)); parameterized_binder_registry_.AddInterface(
base::BindRepeating(&BindFaceDetectionProvider));
parameterized_binder_registry_.AddInterface(
base::BindRepeating(&BindTextDetection));
parameterized_binder_registry_.AddInterface( parameterized_binder_registry_.AddInterface(
base::Bind(&ForwardServiceRequest<device::mojom::VibrationManager>, base::Bind(&ForwardServiceRequest<device::mojom::VibrationManager>,
device::mojom::kServiceName)); device::mojom::kServiceName));
......
...@@ -82,7 +82,6 @@ ...@@ -82,7 +82,6 @@
#include "services/service_manager/service_manager.h" #include "services/service_manager/service_manager.h"
#include "services/service_manager/service_process_host.h" #include "services/service_manager/service_process_host.h"
#include "services/service_manager/service_process_launcher.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/cpp/tracing_features.h"
#include "services/tracing/public/mojom/constants.mojom.h" #include "services/tracing/public/mojom/constants.mojom.h"
#include "services/tracing/tracing_service.h" #include "services/tracing/tracing_service.h"
...@@ -428,8 +427,6 @@ class BrowserServiceManagerDelegate ...@@ -428,8 +427,6 @@ class BrowserServiceManagerDelegate
if (identity.name() == media::mojom::kMediaServiceName) if (identity.name() == media::mojom::kMediaServiceName)
run_in_gpu_process = true; run_in_gpu_process = true;
#endif #endif
if (identity.name() == shape_detection::mojom::kServiceName)
run_in_gpu_process = true;
return std::make_unique<ContentChildServiceProcessHost>(run_in_gpu_process, return std::make_unique<ContentChildServiceProcessHost>(run_in_gpu_process,
child_flags); child_flags);
} }
......
...@@ -358,7 +358,13 @@ class ChildProcessImpl : public mojom::ChildProcess { ...@@ -358,7 +358,13 @@ class ChildProcessImpl : public mojom::ChildProcess {
void BindServiceInterface(mojo::GenericPendingReceiver receiver) override { void BindServiceInterface(mojo::GenericPendingReceiver receiver) override {
if (service_binder_) 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 { void BindReceiver(mojo::GenericPendingReceiver receiver) override {
...@@ -878,6 +884,12 @@ void ChildThreadImpl::RunService( ...@@ -878,6 +884,12 @@ void ChildThreadImpl::RunService(
DLOG(ERROR) << "Ignoring unhandled request to run service: " << service_name; 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) {} void ChildThreadImpl::OnBindReceiver(mojo::GenericPendingReceiver receiver) {}
ChildThreadImpl* ChildThreadImpl::current() { ChildThreadImpl* ChildThreadImpl::current() {
......
...@@ -143,6 +143,8 @@ class CONTENT_EXPORT ChildThreadImpl ...@@ -143,6 +143,8 @@ class CONTENT_EXPORT ChildThreadImpl
const std::string& service_name, const std::string& service_name,
mojo::PendingReceiver<service_manager::mojom::Service> receiver); mojo::PendingReceiver<service_manager::mojom::Service> receiver);
virtual void BindServiceInterface(mojo::GenericPendingReceiver receiver);
virtual void OnBindReceiver(mojo::GenericPendingReceiver receiver); virtual void OnBindReceiver(mojo::GenericPendingReceiver receiver);
protected: protected:
...@@ -274,7 +276,7 @@ struct ChildThreadImpl::Options { ...@@ -274,7 +276,7 @@ struct ChildThreadImpl::Options {
scoped_refptr<base::SingleThreadTaskRunner> ipc_task_runner; scoped_refptr<base::SingleThreadTaskRunner> ipc_task_runner;
using ServiceBinder = using ServiceBinder =
base::RepeatingCallback<void(mojo::GenericPendingReceiver)>; base::RepeatingCallback<void(mojo::GenericPendingReceiver*)>;
ServiceBinder service_binder; ServiceBinder service_binder;
private: private:
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "base/callback_helpers.h" #include "base/callback_helpers.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/no_destructor.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/sequenced_task_runner.h" #include "base/sequenced_task_runner.h"
#include "base/threading/thread_checker.h" #include "base/threading/thread_checker.h"
...@@ -34,6 +35,8 @@ ...@@ -34,6 +35,8 @@
#include "media/gpu/ipc/service/media_gpu_channel_manager.h" #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/binder_registry.h"
#include "services/service_manager/public/cpp/connector.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 "services/viz/privileged/mojom/gl/gpu_service.mojom.h"
#include "third_party/skia/include/core/SkGraphics.h" #include "third_party/skia/include/core/SkGraphics.h"
...@@ -288,6 +291,16 @@ void GpuChildThread::RunService( ...@@ -288,6 +291,16 @@ void GpuChildThread::RunService(
service_factory_->RunService(service_name, std::move(receiver)); 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( void GpuChildThread::OnAssociatedInterfaceRequest(
const std::string& name, const std::string& name,
mojo::ScopedInterfaceEndpointHandle handle) { mojo::ScopedInterfaceEndpointHandle handle) {
......
...@@ -74,6 +74,7 @@ class GpuChildThread : public ChildThreadImpl, ...@@ -74,6 +74,7 @@ class GpuChildThread : public ChildThreadImpl,
void RunService( void RunService(
const std::string& service_name, const std::string& service_name,
mojo::PendingReceiver<service_manager::mojom::Service> receiver) override; mojo::PendingReceiver<service_manager::mojom::Service> receiver) override;
void BindServiceInterface(mojo::GenericPendingReceiver receiver) override;
// IPC::Listener implementation via ChildThreadImpl: // IPC::Listener implementation via ChildThreadImpl:
void OnAssociatedInterfaceRequest( void OnAssociatedInterfaceRequest(
......
...@@ -9,8 +9,6 @@ ...@@ -9,8 +9,6 @@
#include "base/task/post_task.h" #include "base/task/post_task.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "build/build_config.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) #if BUILDFLAG(ENABLE_MOJO_MEDIA_IN_GPU_PROCESS)
#include "base/bind.h" #include "base/bind.h"
...@@ -84,13 +82,6 @@ void GpuServiceFactory::RunService( ...@@ -84,13 +82,6 @@ void GpuServiceFactory::RunService(
return; return;
} }
#endif // BUILDFLAG(ENABLE_MOJO_MEDIA_IN_GPU_PROCESS) #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 } // namespace content
...@@ -46,18 +46,18 @@ class ServiceBinderImpl { ...@@ -46,18 +46,18 @@ class ServiceBinderImpl {
: main_thread_task_runner_(std::move(main_thread_task_runner)) {} : main_thread_task_runner_(std::move(main_thread_task_runner)) {}
~ServiceBinderImpl() = default; ~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 // 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 // watcher is cancelled (meaning the local endpoint was closed rather than
// the peer). Hence any breakage of the service pipe leads to termination. // the peer). Hence any breakage of the service pipe leads to termination.
auto watcher = std::make_unique<mojo::SimpleWatcher>( auto watcher = std::make_unique<mojo::SimpleWatcher>(
FROM_HERE, mojo::SimpleWatcher::ArmingPolicy::AUTOMATIC); 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, MOJO_TRIGGER_CONDITION_SIGNALS_SATISFIED,
base::BindRepeating(&ServiceBinderImpl::OnServicePipeClosed, base::BindRepeating(&ServiceBinderImpl::OnServicePipeClosed,
base::Unretained(this), watcher.get())); base::Unretained(this), watcher.get()));
service_pipe_watchers_.insert(std::move(watcher)); service_pipe_watchers_.insert(std::move(watcher));
HandleServiceRequestOnIOThread(std::move(receiver), HandleServiceRequestOnIOThread(std::move(*receiver),
main_thread_task_runner_.get()); main_thread_task_runner_.get());
} }
......
...@@ -67,7 +67,6 @@ source_set("lib") { ...@@ -67,7 +67,6 @@ source_set("lib") {
public_deps = [ public_deps = [
"//base", "//base",
"//media/capture", "//media/capture",
"//services/service_manager/public/cpp",
"//services/shape_detection/public/mojom", "//services/shape_detection/public/mojom",
] ]
...@@ -105,8 +104,6 @@ if (is_android) { ...@@ -105,8 +104,6 @@ if (is_android) {
"//mojo/public/java:bindings_java", "//mojo/public/java:bindings_java",
"//mojo/public/java:system_java", "//mojo/public/java:system_java",
"//mojo/public/java/system:system_impl_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", "//services/shape_detection/public/mojom:mojom_java",
"//skia/public/mojom:mojom_java", "//skia/public/mojom:mojom_java",
"//ui/gfx/geometry/mojom:mojom_java", "//ui/gfx/geometry/mojom:mojom_java",
......
...@@ -11,7 +11,6 @@ import org.chromium.base.ContextUtils; ...@@ -11,7 +11,6 @@ import org.chromium.base.ContextUtils;
import org.chromium.base.Log; import org.chromium.base.Log;
import org.chromium.mojo.bindings.InterfaceRequest; import org.chromium.mojo.bindings.InterfaceRequest;
import org.chromium.mojo.system.MojoException; 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.BarcodeDetection;
import org.chromium.shape_detection.mojom.BarcodeDetectionProvider; import org.chromium.shape_detection.mojom.BarcodeDetectionProvider;
import org.chromium.shape_detection.mojom.BarcodeDetectorOptions; import org.chromium.shape_detection.mojom.BarcodeDetectorOptions;
...@@ -50,21 +49,13 @@ public class BarcodeDetectionProviderImpl implements BarcodeDetectionProvider { ...@@ -50,21 +49,13 @@ public class BarcodeDetectionProviderImpl implements BarcodeDetectionProvider {
@Override @Override
public void onConnectionError(MojoException e) {} public void onConnectionError(MojoException e) {}
/** public static BarcodeDetectionProvider create() {
* A factory class to register BarcodeDetectionProvider interface. if (GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(
*/ ContextUtils.getApplicationContext())
public static class Factory implements InterfaceFactory<BarcodeDetectionProvider> { != ConnectionResult.SUCCESS) {
public Factory() {} Log.e(TAG, "Google Play Services not available");
return null;
@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();
} }
return new BarcodeDetectionProviderImpl();
} }
} }
...@@ -10,7 +10,6 @@ import com.google.android.gms.common.GoogleApiAvailability; ...@@ -10,7 +10,6 @@ import com.google.android.gms.common.GoogleApiAvailability;
import org.chromium.base.ContextUtils; import org.chromium.base.ContextUtils;
import org.chromium.mojo.bindings.InterfaceRequest; import org.chromium.mojo.bindings.InterfaceRequest;
import org.chromium.mojo.system.MojoException; 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.FaceDetection;
import org.chromium.shape_detection.mojom.FaceDetectionProvider; import org.chromium.shape_detection.mojom.FaceDetectionProvider;
import org.chromium.shape_detection.mojom.FaceDetectorOptions; import org.chromium.shape_detection.mojom.FaceDetectorOptions;
...@@ -41,16 +40,4 @@ public class FaceDetectionProviderImpl implements FaceDetectionProvider { ...@@ -41,16 +40,4 @@ public class FaceDetectionProviderImpl implements FaceDetectionProvider {
@Override @Override
public void onConnectionError(MojoException e) {} 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; ...@@ -6,24 +6,37 @@ package org.chromium.shape_detection;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.mojo.system.MessagePipeHandle;
import org.chromium.mojo.system.impl.CoreImpl; 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.BarcodeDetectionProvider;
import org.chromium.shape_detection.mojom.FaceDetectionProvider; import org.chromium.shape_detection.mojom.FaceDetectionProvider;
import org.chromium.shape_detection.mojom.TextDetection; import org.chromium.shape_detection.mojom.TextDetection;
@JNINamespace("shape_detection") @JNINamespace("shape_detection")
class InterfaceRegistrar { class InterfaceRegistrar {
static MessagePipeHandle messagePipeHandleFromNative(int nativeHandle) {
return CoreImpl.getInstance().acquireNativeHandle(nativeHandle).toMessagePipeHandle();
}
@CalledByNative
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 @CalledByNative
static void createInterfaceRegistryForContext(int nativeHandle) { static void bindTextDetection(int nativeHandle) {
// Note: The bindings code manages the lifetime of this object, so it TextDetection impl = TextDetectionImpl.create();
// is not necessary to hold on to a reference to it explicitly. if (impl != null) {
InterfaceRegistry registry = InterfaceRegistry.create( TextDetection.MANAGER.bind(impl, messagePipeHandleFromNative(nativeHandle));
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());
} }
} }
...@@ -19,7 +19,6 @@ import org.chromium.base.Log; ...@@ -19,7 +19,6 @@ import org.chromium.base.Log;
import org.chromium.gfx.mojom.PointF; import org.chromium.gfx.mojom.PointF;
import org.chromium.gfx.mojom.RectF; import org.chromium.gfx.mojom.RectF;
import org.chromium.mojo.system.MojoException; 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.TextDetection;
import org.chromium.shape_detection.mojom.TextDetectionResult; import org.chromium.shape_detection.mojom.TextDetectionResult;
...@@ -89,21 +88,13 @@ public class TextDetectionImpl implements TextDetection { ...@@ -89,21 +88,13 @@ public class TextDetectionImpl implements TextDetection {
close(); close();
} }
/** public static TextDetection create() {
* A factory class to register TextDetection interface. if (GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(
*/ ContextUtils.getApplicationContext())
public static class Factory implements InterfaceFactory<TextDetection> { != ConnectionResult.SUCCESS) {
public Factory() {} Log.e(TAG, "Google Play Services not available");
return null;
@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();
} }
return new TextDetectionImpl();
} }
} }
# 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",
]
}
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
// 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
// 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") { ...@@ -8,9 +8,9 @@ mojom("mojom") {
sources = [ sources = [
"barcodedetection.mojom", "barcodedetection.mojom",
"barcodedetection_provider.mojom", "barcodedetection_provider.mojom",
"constants.mojom",
"facedetection.mojom", "facedetection.mojom",
"facedetection_provider.mojom", "facedetection_provider.mojom",
"shape_detection_service.mojom",
"textdetection.mojom", "textdetection.mojom",
] ]
......
// 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";
// 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 @@ ...@@ -30,8 +30,8 @@
namespace shape_detection { namespace shape_detection {
ShapeDetectionService::ShapeDetectionService( ShapeDetectionService::ShapeDetectionService(
service_manager::mojom::ServiceRequest request) mojo::PendingReceiver<mojom::ShapeDetectionService> receiver)
: service_binding_(this, std::move(request)) { : receiver_(this, std::move(receiver)) {
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
if (__builtin_available(macOS 10.13, *)) { if (__builtin_available(macOS 10.13, *)) {
vision_framework_ = vision_framework_ =
...@@ -49,51 +49,43 @@ ShapeDetectionService::~ShapeDetectionService() { ...@@ -49,51 +49,43 @@ ShapeDetectionService::~ShapeDetectionService() {
#endif #endif
} }
void ShapeDetectionService::OnStart() { void ShapeDetectionService::BindBarcodeDetectionProvider(
mojo::PendingReceiver<mojom::BarcodeDetectionProvider> receiver) {
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
registry_.AddInterface( Java_InterfaceRegistrar_bindBarcodeDetectionProvider(
GetJavaInterfaces() base::android::AttachCurrentThread(),
->CreateInterfaceFactory<mojom::BarcodeDetectionProvider>()); receiver.PassPipe().release().value());
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));
#elif defined(OS_MACOSX) #elif defined(OS_MACOSX)
registry_.AddInterface(base::Bind(&BarcodeDetectionProviderMac::Create)); BarcodeDetectionProviderMac::Create(std::move(receiver));
registry_.AddInterface(base::Bind(&TextDetectionImpl::Create));
registry_.AddInterface(base::Bind(&FaceDetectionProviderMac::Create));
#else #else
registry_.AddInterface(base::Bind(&BarcodeDetectionProviderImpl::Create)); BarcodeDetectionProviderImpl::Create(std::move(receiver));
registry_.AddInterface(base::Bind(&FaceDetectionProviderImpl::Create));
registry_.AddInterface(base::Bind(&TextDetectionImpl::Create));
#endif #endif
} }
void ShapeDetectionService::OnBindInterface( void ShapeDetectionService::BindFaceDetectionProvider(
const service_manager::BindSourceInfo& source_info, mojo::PendingReceiver<mojom::FaceDetectionProvider> receiver) {
const std::string& interface_name, #if defined(OS_ANDROID)
mojo::ScopedMessagePipeHandle interface_pipe) { Java_InterfaceRegistrar_bindFaceDetectionProvider(
registry_.BindInterface(interface_name, std::move(interface_pipe)); 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) #if defined(OS_ANDROID)
service_manager::InterfaceProvider* ShapeDetectionService::GetJavaInterfaces() { Java_InterfaceRegistrar_bindTextDetection(
if (!java_interface_provider_) { base::android::AttachCurrentThread(),
service_manager::mojom::InterfaceProviderPtr provider; receiver.PassPipe().release().value());
Java_InterfaceRegistrar_createInterfaceRegistryForContext( #else
base::android::AttachCurrentThread(), TextDetectionImpl::Create(std::move(receiver));
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();
}
#endif #endif
}
} // namespace shape_detection } // namespace shape_detection
...@@ -10,39 +10,33 @@ ...@@ -10,39 +10,33 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/macros.h" #include "base/macros.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "services/service_manager/public/cpp/binder_registry.h" #include "mojo/public/cpp/bindings/pending_receiver.h"
#include "services/service_manager/public/cpp/interface_provider.h" #include "mojo/public/cpp/bindings/receiver.h"
#include "services/service_manager/public/cpp/service.h" #include "services/shape_detection/public/mojom/shape_detection_service.mojom.h"
#include "services/service_manager/public/cpp/service_binding.h"
#include "services/service_manager/public/mojom/service.mojom.h"
namespace shape_detection { namespace shape_detection {
class ShapeDetectionService : public service_manager::Service { class ShapeDetectionService : public mojom::ShapeDetectionService {
public: public:
explicit ShapeDetectionService( explicit ShapeDetectionService(
service_manager::mojom::ServiceRequest request); mojo::PendingReceiver<mojom::ShapeDetectionService> receiver);
~ShapeDetectionService() override; ~ShapeDetectionService() override;
void OnStart() override; // mojom::ShapeDetectionService implementation:
void OnBindInterface(const service_manager::BindSourceInfo& source_info, void BindBarcodeDetectionProvider(
const std::string& interface_name, mojo::PendingReceiver<mojom::BarcodeDetectionProvider> receiver) override;
mojo::ScopedMessagePipeHandle interface_pipe) override; void BindFaceDetectionProvider(
mojo::PendingReceiver<mojom::FaceDetectionProvider> receiver) override;
void BindTextDetection(
mojo::PendingReceiver<mojom::TextDetection> receiver) override;
private: private:
#if defined(OS_ANDROID) mojo::Receiver<mojom::ShapeDetectionService> receiver_;
// Binds |java_interface_provider_| to an interface registry that exposes
// factories for the interfaces that are provided via Java on Android. #if defined(OS_MACOSX)
service_manager::InterfaceProvider* GetJavaInterfaces();
// InterfaceProvider that is bound to the Java-side interface registry.
std::unique_ptr<service_manager::InterfaceProvider> java_interface_provider_;
#elif defined(OS_MACOSX)
void* vision_framework_; void* vision_framework_;
#endif #endif
service_manager::ServiceBinding service_binding_;
service_manager::BinderRegistry registry_;
DISALLOW_COPY_AND_ASSIGN(ShapeDetectionService); DISALLOW_COPY_AND_ASSIGN(ShapeDetectionService);
}; };
......
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