Commit b2765d8f authored by Mario Sanchez Prada's avatar Mario Sanchez Prada Committed by Commit Bot

Migrate references of shape_detection::mojom::FaceDetection[Provider]

Convert the remaining bits in both the implementation and clients from the
browser and renderer processes for the mojom.FaceDetection[Provider]
interface, and adapt tests.

Bug: 955171, 978694
Change-Id: I97c5ebebb2d3e3df24a4fe481987042ce0dff9de
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1827279Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarMatt Falkenhagen <falken@chromium.org>
Reviewed-by: default avatarOksana Zhuravlova <oksamyt@chromium.org>
Commit-Queue: Mario Sanchez Prada <mario@igalia.com>
Cr-Commit-Position: refs/heads/master@{#701268}
parent 3856dbea
...@@ -122,10 +122,11 @@ void BindBarcodeDetectionProvider( ...@@ -122,10 +122,11 @@ void BindBarcodeDetectionProvider(
} }
void BindFaceDetectionProvider( void BindFaceDetectionProvider(
shape_detection::mojom::FaceDetectionProviderRequest request, mojo::PendingReceiver<shape_detection::mojom::FaceDetectionProvider>
receiver,
RenderProcessHost* host, RenderProcessHost* host,
const url::Origin& origin) { const url::Origin& origin) {
GetShapeDetectionService()->BindFaceDetectionProvider(std::move(request)); GetShapeDetectionService()->BindFaceDetectionProvider(std::move(receiver));
} }
void BindTextDetection( void BindTextDetection(
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#include "base/mac/sdk_forward_declarations.h" #include "base/mac/sdk_forward_declarations.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "mojo/public/cpp/bindings/strong_binding.h" #include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "services/shape_detection/detection_utils_mac.h" #include "services/shape_detection/detection_utils_mac.h"
#include "services/shape_detection/public/mojom/facedetection.mojom.h" #include "services/shape_detection/public/mojom/facedetection.mojom.h"
...@@ -31,8 +31,8 @@ class API_AVAILABLE(macos(10.13)) FaceDetectionImplMacVision ...@@ -31,8 +31,8 @@ class API_AVAILABLE(macos(10.13)) FaceDetectionImplMacVision
void Detect(const SkBitmap& bitmap, void Detect(const SkBitmap& bitmap,
mojom::FaceDetection::DetectCallback callback) override; mojom::FaceDetection::DetectCallback callback) override;
void SetBinding(mojo::StrongBindingPtr<mojom::FaceDetection> binding) { void SetReceiver(mojo::SelfOwnedReceiverRef<mojom::FaceDetection> receiver) {
binding_ = std::move(binding); receiver_ = std::move(receiver);
} }
private: private:
...@@ -41,7 +41,7 @@ class API_AVAILABLE(macos(10.13)) FaceDetectionImplMacVision ...@@ -41,7 +41,7 @@ class API_AVAILABLE(macos(10.13)) FaceDetectionImplMacVision
CGSize image_size_; CGSize image_size_;
std::unique_ptr<VisionAPIAsyncRequestMac> landmarks_async_request_; std::unique_ptr<VisionAPIAsyncRequestMac> landmarks_async_request_;
DetectCallback detected_callback_; DetectCallback detected_callback_;
mojo::StrongBindingPtr<mojom::FaceDetection> binding_; mojo::SelfOwnedReceiverRef<mojom::FaceDetection> receiver_;
base::WeakPtrFactory<FaceDetectionImplMacVision> weak_factory_; base::WeakPtrFactory<FaceDetectionImplMacVision> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(FaceDetectionImplMacVision); DISALLOW_COPY_AND_ASSIGN(FaceDetectionImplMacVision);
......
...@@ -63,14 +63,14 @@ void FaceDetectionImplMacVision::Detect(const SkBitmap& bitmap, ...@@ -63,14 +63,14 @@ void FaceDetectionImplMacVision::Detect(const SkBitmap& bitmap,
detected_callback_ = std::move(callback); detected_callback_ = std::move(callback);
// This prevents the Detect function from being called before the // This prevents the Detect function from being called before the
// VisionAPIAsyncRequestMac completes. // VisionAPIAsyncRequestMac completes.
if (binding_) // Can be unbound in unit testing. if (receiver_) // Can be unbound in unit testing.
binding_->PauseIncomingMethodCallProcessing(); receiver_->PauseIncomingMethodCallProcessing();
} }
void FaceDetectionImplMacVision::OnFacesDetected(VNRequest* request, void FaceDetectionImplMacVision::OnFacesDetected(VNRequest* request,
NSError* error) { NSError* error) {
if (binding_) // Can be unbound in unit testing. if (receiver_) // Can be unbound in unit testing.
binding_->ResumeIncomingMethodCallProcessing(); receiver_->ResumeIncomingMethodCallProcessing();
if (![request.results count] || error) { if (![request.results count] || error) {
std::move(detected_callback_).Run({}); std::move(detected_callback_).Run({});
......
...@@ -47,7 +47,7 @@ void FaceDetectionImplWin::Detect(const SkBitmap& bitmap, ...@@ -47,7 +47,7 @@ void FaceDetectionImplWin::Detect(const SkBitmap& bitmap,
detected_face_callback_ = std::move(callback); detected_face_callback_ = std::move(callback);
// This prevents the Detect function from being called before the // This prevents the Detect function from being called before the
// AsyncOperation completes. // AsyncOperation completes.
binding_->PauseIncomingMethodCallProcessing(); receiver_->PauseIncomingMethodCallProcessing();
} }
HRESULT FaceDetectionImplWin::BeginDetect(const SkBitmap& bitmap) { HRESULT FaceDetectionImplWin::BeginDetect(const SkBitmap& bitmap) {
...@@ -122,7 +122,7 @@ void FaceDetectionImplWin::OnFaceDetected( ...@@ -122,7 +122,7 @@ void FaceDetectionImplWin::OnFaceDetected(
ComPtr<IVector<DetectedFace*>> result) { ComPtr<IVector<DetectedFace*>> result) {
std::move(detected_face_callback_) std::move(detected_face_callback_)
.Run(BuildFaceDetectionResult(std::move(result))); .Run(BuildFaceDetectionResult(std::move(result)));
binding_->ResumeIncomingMethodCallProcessing(); receiver_->ResumeIncomingMethodCallProcessing();
} }
} // namespace shape_detection } // namespace shape_detection
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "mojo/public/cpp/bindings/strong_binding.h" #include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "services/shape_detection/public/mojom/facedetection.mojom.h" #include "services/shape_detection/public/mojom/facedetection.mojom.h"
class SkBitmap; class SkBitmap;
...@@ -34,8 +34,8 @@ class FaceDetectionImplWin : public mojom::FaceDetection { ...@@ -34,8 +34,8 @@ class FaceDetectionImplWin : public mojom::FaceDetection {
ABI::Windows::Graphics::Imaging::BitmapPixelFormat pixel_format); ABI::Windows::Graphics::Imaging::BitmapPixelFormat pixel_format);
~FaceDetectionImplWin() override; ~FaceDetectionImplWin() override;
void SetBinding(mojo::StrongBindingPtr<mojom::FaceDetection> binding) { void SetReceiver(mojo::SelfOwnedReceiverRef<mojom::FaceDetection> receiver) {
binding_ = std::move(binding); receiver_ = std::move(receiver);
} }
// mojom::FaceDetection implementation. // mojom::FaceDetection implementation.
...@@ -62,7 +62,7 @@ class FaceDetectionImplWin : public mojom::FaceDetection { ...@@ -62,7 +62,7 @@ class FaceDetectionImplWin : public mojom::FaceDetection {
ABI::Windows::Graphics::Imaging::BitmapPixelFormat pixel_format_; ABI::Windows::Graphics::Imaging::BitmapPixelFormat pixel_format_;
DetectCallback detected_face_callback_; DetectCallback detected_face_callback_;
mojo::StrongBindingPtr<mojom::FaceDetection> binding_; mojo::SelfOwnedReceiverRef<mojom::FaceDetection> receiver_;
base::WeakPtrFactory<FaceDetectionImplWin> weak_factory_{this}; base::WeakPtrFactory<FaceDetectionImplWin> weak_factory_{this};
......
...@@ -5,7 +5,8 @@ ...@@ -5,7 +5,8 @@
#ifndef SERVICES_SHAPE_DETECTION_FACE_DETECTION_PROVIDER_IMPL_H_ #ifndef SERVICES_SHAPE_DETECTION_FACE_DETECTION_PROVIDER_IMPL_H_
#define SERVICES_SHAPE_DETECTION_FACE_DETECTION_PROVIDER_IMPL_H_ #define SERVICES_SHAPE_DETECTION_FACE_DETECTION_PROVIDER_IMPL_H_
#include "mojo/public/cpp/bindings/strong_binding.h" #include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "services/shape_detection/public/mojom/facedetection_provider.mojom.h" #include "services/shape_detection/public/mojom/facedetection_provider.mojom.h"
namespace shape_detection { namespace shape_detection {
...@@ -16,9 +17,10 @@ class FaceDetectionProviderImpl ...@@ -16,9 +17,10 @@ class FaceDetectionProviderImpl
~FaceDetectionProviderImpl() override = default; ~FaceDetectionProviderImpl() override = default;
static void Create( static void Create(
shape_detection::mojom::FaceDetectionProviderRequest request) { mojo::PendingReceiver<shape_detection::mojom::FaceDetectionProvider>
mojo::MakeStrongBinding(std::make_unique<FaceDetectionProviderImpl>(), receiver) {
std::move(request)); mojo::MakeSelfOwnedReceiver(std::make_unique<FaceDetectionProviderImpl>(),
std::move(receiver));
} }
void CreateFaceDetection( void CreateFaceDetection(
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define SERVICES_SHAPE_DETECTION_FACE_DETECTION_PROVIDER_MAC_H_ #define SERVICES_SHAPE_DETECTION_FACE_DETECTION_PROVIDER_MAC_H_
#include "base/macros.h" #include "base/macros.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "services/shape_detection/public/mojom/facedetection_provider.mojom.h" #include "services/shape_detection/public/mojom/facedetection_provider.mojom.h"
namespace shape_detection { namespace shape_detection {
...@@ -18,9 +19,10 @@ class FaceDetectionProviderMac ...@@ -18,9 +19,10 @@ class FaceDetectionProviderMac
FaceDetectionProviderMac(); FaceDetectionProviderMac();
~FaceDetectionProviderMac() override; ~FaceDetectionProviderMac() override;
// Binds FaceDetection provider request to the implementation of // Binds FaceDetection provider receiver to the implementation of
// mojom::FaceDetectionProvider. // mojom::FaceDetectionProvider.
static void Create(mojom::FaceDetectionProviderRequest request); static void Create(
mojo::PendingReceiver<mojom::FaceDetectionProvider> receiver);
void CreateFaceDetection(mojo::PendingReceiver<mojom::FaceDetection> receiver, void CreateFaceDetection(mojo::PendingReceiver<mojom::FaceDetection> receiver,
mojom::FaceDetectorOptionsPtr options) override; mojom::FaceDetectorOptionsPtr options) override;
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <memory> #include <memory>
#include <utility> #include <utility>
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h" #include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "services/shape_detection/face_detection_impl_mac.h" #include "services/shape_detection/face_detection_impl_mac.h"
#include "services/shape_detection/face_detection_impl_mac_vision.h" #include "services/shape_detection/face_detection_impl_mac_vision.h"
...@@ -19,9 +20,9 @@ FaceDetectionProviderMac::~FaceDetectionProviderMac() = default; ...@@ -19,9 +20,9 @@ FaceDetectionProviderMac::~FaceDetectionProviderMac() = default;
// static // static
void FaceDetectionProviderMac::Create( void FaceDetectionProviderMac::Create(
mojom::FaceDetectionProviderRequest request) { mojo::PendingReceiver<mojom::FaceDetectionProvider> receiver) {
mojo::MakeStrongBinding(std::make_unique<FaceDetectionProviderMac>(), mojo::MakeSelfOwnedReceiver(std::make_unique<FaceDetectionProviderMac>(),
std::move(request)); std::move(receiver));
} }
void FaceDetectionProviderMac::CreateFaceDetection( void FaceDetectionProviderMac::CreateFaceDetection(
...@@ -34,9 +35,8 @@ void FaceDetectionProviderMac::CreateFaceDetection( ...@@ -34,9 +35,8 @@ void FaceDetectionProviderMac::CreateFaceDetection(
if (!options->fast_mode) { if (!options->fast_mode) {
auto impl = std::make_unique<FaceDetectionImplMacVision>(); auto impl = std::make_unique<FaceDetectionImplMacVision>();
auto* impl_ptr = impl.get(); auto* impl_ptr = impl.get();
impl_ptr->SetBinding(mojo::MakeStrongBinding( impl_ptr->SetReceiver(
std::move(impl), mojo::MakeSelfOwnedReceiver(std::move(impl), std::move(receiver)));
mojo::InterfaceRequest<mojom::FaceDetection>(std::move(receiver))));
return; return;
} }
} }
......
...@@ -13,7 +13,8 @@ ...@@ -13,7 +13,8 @@
#include "base/win/post_async_results.h" #include "base/win/post_async_results.h"
#include "base/win/scoped_hstring.h" #include "base/win/scoped_hstring.h"
#include "base/win/windows_version.h" #include "base/win/windows_version.h"
#include "mojo/public/cpp/bindings/strong_binding.h" #include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
namespace shape_detection { namespace shape_detection {
...@@ -111,7 +112,7 @@ void FaceDetectionProviderWin::CreateFaceDetection( ...@@ -111,7 +112,7 @@ void FaceDetectionProviderWin::CreateFaceDetection(
// the message pipe, then the callback OnFaceDetectorCreated will be not // the message pipe, then the callback OnFaceDetectorCreated will be not
// called. This prevents this object from being destroyed before the // called. This prevents this object from being destroyed before the
// AsyncOperation completes. // AsyncOperation completes.
binding_->PauseIncomingMethodCallProcessing(); receiver_->PauseIncomingMethodCallProcessing();
} }
FaceDetectionProviderWin::FaceDetectionProviderWin() {} FaceDetectionProviderWin::FaceDetectionProviderWin() {}
...@@ -122,7 +123,7 @@ void FaceDetectionProviderWin::OnFaceDetectorCreated( ...@@ -122,7 +123,7 @@ void FaceDetectionProviderWin::OnFaceDetectorCreated(
mojo::PendingReceiver<shape_detection::mojom::FaceDetection> receiver, mojo::PendingReceiver<shape_detection::mojom::FaceDetection> receiver,
BitmapPixelFormat pixel_format, BitmapPixelFormat pixel_format,
ComPtr<IFaceDetector> face_detector) { ComPtr<IFaceDetector> face_detector) {
binding_->ResumeIncomingMethodCallProcessing(); receiver_->ResumeIncomingMethodCallProcessing();
if (!face_detector) if (!face_detector)
return; return;
...@@ -140,10 +141,8 @@ void FaceDetectionProviderWin::OnFaceDetectorCreated( ...@@ -140,10 +141,8 @@ void FaceDetectionProviderWin::OnFaceDetectorCreated(
auto impl = std::make_unique<FaceDetectionImplWin>( auto impl = std::make_unique<FaceDetectionImplWin>(
std::move(face_detector), std::move(bitmap_factory), pixel_format); std::move(face_detector), std::move(bitmap_factory), pixel_format);
auto* impl_ptr = impl.get(); auto* impl_ptr = impl.get();
impl_ptr->SetBinding(mojo::MakeStrongBinding( impl_ptr->SetReceiver(
std::move(impl), mojo::MakeSelfOwnedReceiver(std::move(impl), std::move(receiver)));
mojo::InterfaceRequest<shape_detection::mojom::FaceDetection>(
std::move(receiver))));
} }
} // namespace shape_detection } // namespace shape_detection
...@@ -13,7 +13,8 @@ ...@@ -13,7 +13,8 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "mojo/public/cpp/bindings/strong_binding.h" #include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "services/shape_detection/face_detection_impl_win.h" #include "services/shape_detection/face_detection_impl_win.h"
#include "services/shape_detection/public/mojom/facedetection_provider.mojom.h" #include "services/shape_detection/public/mojom/facedetection_provider.mojom.h"
...@@ -26,11 +27,12 @@ class FaceDetectionProviderWin ...@@ -26,11 +27,12 @@ class FaceDetectionProviderWin
~FaceDetectionProviderWin() override; ~FaceDetectionProviderWin() override;
static void Create( static void Create(
shape_detection::mojom::FaceDetectionProviderRequest request) { mojo::PendingReceiver<shape_detection::mojom::FaceDetectionProvider>
receiver) {
auto provider = std::make_unique<FaceDetectionProviderWin>(); auto provider = std::make_unique<FaceDetectionProviderWin>();
auto* provider_ptr = provider.get(); auto* provider_ptr = provider.get();
provider_ptr->binding_ = provider_ptr->receiver_ =
mojo::MakeStrongBinding(std::move(provider), std::move(request)); mojo::MakeSelfOwnedReceiver(std::move(provider), std::move(receiver));
} }
void CreateFaceDetection( void CreateFaceDetection(
...@@ -44,7 +46,7 @@ class FaceDetectionProviderWin ...@@ -44,7 +46,7 @@ class FaceDetectionProviderWin
Microsoft::WRL::ComPtr<ABI::Windows::Media::FaceAnalysis::IFaceDetector> Microsoft::WRL::ComPtr<ABI::Windows::Media::FaceAnalysis::IFaceDetector>
face_detector); face_detector);
mojo::StrongBindingPtr<mojom::FaceDetectionProvider> binding_; mojo::SelfOwnedReceiverRef<mojom::FaceDetectionProvider> receiver_;
base::WeakPtrFactory<FaceDetectionProviderWin> weak_factory_{this}; base::WeakPtrFactory<FaceDetectionProviderWin> weak_factory_{this};
DISALLOW_COPY_AND_ASSIGN(FaceDetectionProviderWin); DISALLOW_COPY_AND_ASSIGN(FaceDetectionProviderWin);
......
...@@ -37,12 +37,12 @@ FaceDetector::FaceDetector(ExecutionContext* context, ...@@ -37,12 +37,12 @@ FaceDetector::FaceDetector(ExecutionContext* context,
face_detector_options->max_detected_faces = options->maxDetectedFaces(); face_detector_options->max_detected_faces = options->maxDetectedFaces();
face_detector_options->fast_mode = options->fastMode(); face_detector_options->fast_mode = options->fastMode();
shape_detection::mojom::blink::FaceDetectionProviderPtr provider; mojo::Remote<shape_detection::mojom::blink::FaceDetectionProvider> provider;
// See https://bit.ly/2S0zRAS for task types. // See https://bit.ly/2S0zRAS for task types.
auto task_runner = context->GetTaskRunner(TaskType::kMiscPlatformAPI); auto task_runner = context->GetTaskRunner(TaskType::kMiscPlatformAPI);
auto request = mojo::MakeRequest(&provider, task_runner);
if (auto* interface_provider = context->GetInterfaceProvider()) { if (auto* interface_provider = context->GetInterfaceProvider()) {
interface_provider->GetInterface(std::move(request)); interface_provider->GetInterface(
provider.BindNewPipeAndPassReceiver(task_runner));
} }
provider->CreateFaceDetection( provider->CreateFaceDetection(
face_service_.BindNewPipeAndPassReceiver(task_runner), face_service_.BindNewPipeAndPassReceiver(task_runner),
......
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