Commit 9a039c57 authored by Gyuyoung Kim's avatar Gyuyoung Kim Committed by Commit Bot

Migrate FaceDetectionProvider to the new Mojo types

This CL applies pending_receiver to CreateFaceDetection()
in FaceDetectionProvider interface.

Bug: 955171
Change-Id: I13702984c7b183eb0f58a994fbd8d00a1ba8db40
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1792032
Commit-Queue: Gyuyoung Kim <gyuyoung@igalia.com>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarOksana Zhuravlova <oksamyt@chromium.org>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#695061}
parent fadca688
......@@ -9,7 +9,7 @@
namespace shape_detection {
void FaceDetectionProviderImpl::CreateFaceDetection(
shape_detection::mojom::FaceDetectionRequest request,
mojo::PendingReceiver<shape_detection::mojom::FaceDetection> receiver,
shape_detection::mojom::FaceDetectorOptionsPtr options) {
DLOG(ERROR) << "Platform not supported for Face Detection Service.";
}
......
......@@ -22,7 +22,7 @@ class FaceDetectionProviderImpl
}
void CreateFaceDetection(
shape_detection::mojom::FaceDetectionRequest request,
mojo::PendingReceiver<shape_detection::mojom::FaceDetection> receiver,
shape_detection::mojom::FaceDetectorOptionsPtr options) override;
};
......
......@@ -22,7 +22,7 @@ class FaceDetectionProviderMac
// mojom::FaceDetectionProvider.
static void Create(mojom::FaceDetectionProviderRequest request);
void CreateFaceDetection(mojom::FaceDetectionRequest request,
void CreateFaceDetection(mojo::PendingReceiver<mojom::FaceDetection> receiver,
mojom::FaceDetectorOptionsPtr options) override;
private:
......
......@@ -7,7 +7,7 @@
#include <memory>
#include <utility>
#include "mojo/public/cpp/bindings/strong_binding.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_vision.h"
......@@ -25,7 +25,7 @@ void FaceDetectionProviderMac::Create(
}
void FaceDetectionProviderMac::CreateFaceDetection(
mojom::FaceDetectionRequest request,
mojo::PendingReceiver<mojom::FaceDetection> receiver,
mojom::FaceDetectorOptionsPtr options) {
// Vision Framework needs at least MAC OS X 10.13.
if (@available(macOS 10.13, *)) {
......@@ -34,15 +34,16 @@ void FaceDetectionProviderMac::CreateFaceDetection(
if (!options->fast_mode) {
auto impl = std::make_unique<FaceDetectionImplMacVision>();
auto* impl_ptr = impl.get();
impl_ptr->SetBinding(
mojo::MakeStrongBinding(std::move(impl), std::move(request)));
impl_ptr->SetBinding(mojo::MakeStrongBinding(
std::move(impl),
mojo::InterfaceRequest<mojom::FaceDetection>(receiver)));
return;
}
}
mojo::MakeStrongBinding(
mojo::MakeSelfOwnedReceiver(
std::make_unique<FaceDetectionImplMac>(std::move(options)),
std::move(request));
std::move(receiver));
}
} // namespace shape_detection
......@@ -47,7 +47,7 @@ BitmapPixelFormat GetPreferredPixelFormat(IFaceDetectorStatics* factory) {
} // namespace
void FaceDetectionProviderWin::CreateFaceDetection(
shape_detection::mojom::FaceDetectionRequest request,
mojo::PendingReceiver<shape_detection::mojom::FaceDetection> receiver,
shape_detection::mojom::FaceDetectorOptionsPtr options) {
// FaceDetector class is only available in Win 10 onwards (v10.0.10240.0).
if (base::win::GetVersion() < base::win::Version::WIN10) {
......@@ -99,7 +99,7 @@ void FaceDetectionProviderWin::CreateFaceDetection(
hr = base::win::PostAsyncResults(
std::move(async_op),
base::BindOnce(&FaceDetectionProviderWin::OnFaceDetectorCreated,
weak_factory_.GetWeakPtr(), std::move(request),
weak_factory_.GetWeakPtr(), std::move(receiver),
pixel_format));
if (FAILED(hr)) {
DLOG(ERROR) << "Begin async operation failed: "
......@@ -119,7 +119,7 @@ FaceDetectionProviderWin::FaceDetectionProviderWin() {}
FaceDetectionProviderWin::~FaceDetectionProviderWin() = default;
void FaceDetectionProviderWin::OnFaceDetectorCreated(
shape_detection::mojom::FaceDetectionRequest request,
mojo::PendingReceiver<shape_detection::mojom::FaceDetection> receiver,
BitmapPixelFormat pixel_format,
ComPtr<IFaceDetector> face_detector) {
binding_->ResumeIncomingMethodCallProcessing();
......@@ -140,8 +140,9 @@ void FaceDetectionProviderWin::OnFaceDetectorCreated(
auto impl = std::make_unique<FaceDetectionImplWin>(
std::move(face_detector), std::move(bitmap_factory), pixel_format);
auto* impl_ptr = impl.get();
impl_ptr->SetBinding(
mojo::MakeStrongBinding(std::move(impl), std::move(request)));
impl_ptr->SetBinding(mojo::MakeStrongBinding(
std::move(impl),
mojo::InterfaceRequest<shape_detection::mojom::FaceDetection>(receiver)));
}
} // namespace shape_detection
......@@ -34,12 +34,12 @@ class FaceDetectionProviderWin
}
void CreateFaceDetection(
shape_detection::mojom::FaceDetectionRequest request,
mojo::PendingReceiver<shape_detection::mojom::FaceDetection> receiver,
shape_detection::mojom::FaceDetectorOptionsPtr options) override;
private:
void OnFaceDetectorCreated(
shape_detection::mojom::FaceDetectionRequest request,
mojo::PendingReceiver<shape_detection::mojom::FaceDetection> receiver,
ABI::Windows::Graphics::Imaging::BitmapPixelFormat pixel_format,
Microsoft::WRL::ComPtr<ABI::Windows::Media::FaceAnalysis::IFaceDetector>
face_detector);
......
......@@ -9,5 +9,6 @@ module shape_detection.mojom;
import "services/shape_detection/public/mojom/facedetection.mojom";
interface FaceDetectionProvider {
CreateFaceDetection(FaceDetection& request, FaceDetectorOptions options);
CreateFaceDetection(pending_receiver<FaceDetection> receiver,
FaceDetectorOptions options);
};
......@@ -44,10 +44,11 @@ FaceDetector::FaceDetector(ExecutionContext* context,
if (auto* interface_provider = context->GetInterfaceProvider()) {
interface_provider->GetInterface(std::move(request));
}
provider->CreateFaceDetection(mojo::MakeRequest(&face_service_, task_runner),
std::move(face_detector_options));
provider->CreateFaceDetection(
face_service_.BindNewPipeAndPassReceiver(task_runner),
std::move(face_detector_options));
face_service_.set_connection_error_handler(WTF::Bind(
face_service_.set_disconnect_handler(WTF::Bind(
&FaceDetector::OnFaceServiceConnectionError, WrapWeakPersistent(this)));
}
......
......@@ -5,6 +5,7 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_SHAPEDETECTION_FACE_DETECTOR_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_SHAPEDETECTION_FACE_DETECTOR_H_
#include "mojo/public/cpp/bindings/remote.h"
#include "services/shape_detection/public/mojom/facedetection.mojom-blink.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h"
......@@ -36,7 +37,7 @@ class MODULES_EXPORT FaceDetector final : public ShapeDetector {
Vector<shape_detection::mojom::blink::FaceDetectionResultPtr>);
void OnFaceServiceConnectionError();
shape_detection::mojom::blink::FaceDetectionPtr face_service_;
mojo::Remote<shape_detection::mojom::blink::FaceDetection> face_service_;
HeapHashSet<Member<ScriptPromiseResolver>> face_service_requests_;
};
......
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