Commit b84f55d8 authored by Gyuyoung Kim's avatar Gyuyoung Kim Committed by Commit Bot

Migrate BarcodeDetectionProvider to the new Mojo types

This CL applies pending_receiver to the first argument of
CreateBarcodeDetection in BarcodeDetectionProvider interface.

Bug: 955171
Change-Id: Ib86754b3d5989d555a8c0ed536df78e22b540dc1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1792212Reviewed-by: default avatarOksana Zhuravlova <oksamyt@chromium.org>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Commit-Queue: Gyuyoung Kim <gyuyoung@igalia.com>
Cr-Commit-Position: refs/heads/master@{#695518}
parent 73f8d610
......@@ -9,7 +9,7 @@
namespace shape_detection {
void BarcodeDetectionProviderImpl::CreateBarcodeDetection(
shape_detection::mojom::BarcodeDetectionRequest request,
mojo::PendingReceiver<shape_detection::mojom::BarcodeDetection> receiver,
shape_detection::mojom::BarcodeDetectorOptionsPtr options) {
DLOG(ERROR) << "Platform not supported for Barcode Detection Service.";
}
......
......@@ -25,7 +25,7 @@ class BarcodeDetectionProviderImpl
}
void CreateBarcodeDetection(
shape_detection::mojom::BarcodeDetectionRequest request,
mojo::PendingReceiver<shape_detection::mojom::BarcodeDetection> receiver,
shape_detection::mojom::BarcodeDetectorOptionsPtr options) override;
void EnumerateSupportedFormats(
EnumerateSupportedFormatsCallback callback) override;
......
......@@ -32,7 +32,7 @@ class BarcodeDetectionProviderMac
static void Create(mojom::BarcodeDetectionProviderRequest request);
void CreateBarcodeDetection(
mojom::BarcodeDetectionRequest request,
mojo::PendingReceiver<mojom::BarcodeDetection> receiver,
mojom::BarcodeDetectorOptionsPtr options) override;
void EnumerateSupportedFormats(
EnumerateSupportedFormatsCallback callback) override;
......
......@@ -8,7 +8,7 @@
#include <utility>
#include "base/logging.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "services/shape_detection/barcode_detection_impl_mac.h"
#include "services/shape_detection/barcode_detection_impl_mac_vision.h"
......@@ -29,7 +29,7 @@ void BarcodeDetectionProviderMac::Create(
}
void BarcodeDetectionProviderMac::CreateBarcodeDetection(
mojom::BarcodeDetectionRequest request,
mojo::PendingReceiver<mojom::BarcodeDetection> receiver,
mojom::BarcodeDetectorOptionsPtr options) {
if (!vision_api_)
vision_api_ = VisionAPIInterface::Create();
......@@ -40,14 +40,15 @@ void BarcodeDetectionProviderMac::CreateBarcodeDetection(
auto impl =
std::make_unique<BarcodeDetectionImplMacVision>(std::move(options));
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::BarcodeDetection>(receiver)));
return;
}
}
mojo::MakeStrongBinding(std::make_unique<BarcodeDetectionImplMac>(),
std::move(request));
mojo::MakeSelfOwnedReceiver(std::make_unique<BarcodeDetectionImplMac>(),
std::move(receiver));
}
void BarcodeDetectionProviderMac::EnumerateSupportedFormats(
......
......@@ -14,6 +14,7 @@
#include "base/run_loop.h"
#include "base/test/bind_test_util.h"
#include "base/test/task_environment.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
#include "mojo/public/cpp/test_support/test_utils.h"
#include "services/shape_detection/barcode_detection_impl_mac_vision.h"
......@@ -238,13 +239,12 @@ TEST_F(BarcodeDetectionProviderMacTest, HintFormats) {
mojo::MakeStrongBinding(CreateBarcodeProviderMac(CreateVisionAPI()),
std::move(provider_request));
mojom::BarcodeDetectionPtr impl;
auto impl_request = mojo::MakeRequest(&impl);
auto options = mojom::BarcodeDetectorOptions::New();
options->formats = {mojom::BarcodeFormat::UNKNOWN};
mojo::test::BadMessageObserver observer;
provider_ptr->CreateBarcodeDetection(std::move(impl_request),
mojo::Remote<mojom::BarcodeDetection> impl;
provider_ptr->CreateBarcodeDetection(impl.BindNewPipeAndPassReceiver(),
std::move(options));
EXPECT_EQ("Formats hint contains UNKNOWN BarcodeFormat.",
......
......@@ -14,7 +14,7 @@ struct BarcodeDetectorOptions {
};
interface BarcodeDetectionProvider {
CreateBarcodeDetection(BarcodeDetection& request,
CreateBarcodeDetection(pending_receiver<BarcodeDetection> receiver,
BarcodeDetectorOptions options);
EnumerateSupportedFormats() => (array<BarcodeFormat> supported_formats);
......
......@@ -87,9 +87,9 @@ BarcodeDetector::BarcodeDetector(ExecutionContext* context,
auto task_runner = context->GetTaskRunner(TaskType::kMiscPlatformAPI);
BarcodeDetectorStatics::From(context)->CreateBarcodeDetection(
mojo::MakeRequest(&service_, task_runner),
service_.BindNewPipeAndPassReceiver(task_runner),
std::move(barcode_detector_options));
service_.set_connection_error_handler(
service_.set_disconnect_handler(
WTF::Bind(&BarcodeDetector::OnConnectionError, WrapWeakPersistent(this)));
}
......
......@@ -5,6 +5,7 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_SHAPEDETECTION_BARCODE_DETECTOR_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_SHAPEDETECTION_BARCODE_DETECTOR_H_
#include "mojo/public/cpp/bindings/remote.h"
#include "services/shape_detection/public/mojom/barcodedetection.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"
......@@ -44,7 +45,7 @@ class MODULES_EXPORT BarcodeDetector final : public ShapeDetector {
void OnConnectionError();
shape_detection::mojom::blink::BarcodeDetectionPtr service_;
mojo::Remote<shape_detection::mojom::blink::BarcodeDetection> service_;
HeapHashSet<Member<ScriptPromiseResolver>> detect_requests_;
};
......
......@@ -34,10 +34,11 @@ BarcodeDetectorStatics::BarcodeDetectorStatics(ExecutionContext& document)
BarcodeDetectorStatics::~BarcodeDetectorStatics() = default;
void BarcodeDetectorStatics::CreateBarcodeDetection(
shape_detection::mojom::blink::BarcodeDetectionRequest request,
mojo::PendingReceiver<shape_detection::mojom::blink::BarcodeDetection>
receiver,
shape_detection::mojom::blink::BarcodeDetectorOptionsPtr options) {
EnsureServiceConnection();
service_->CreateBarcodeDetection(std::move(request), std::move(options));
service_->CreateBarcodeDetection(std::move(receiver), std::move(options));
}
ScriptPromise BarcodeDetectorStatics::EnumerateSupportedFormats(
......
......@@ -33,7 +33,7 @@ class BarcodeDetectorStatics final
~BarcodeDetectorStatics();
void CreateBarcodeDetection(
shape_detection::mojom::blink::BarcodeDetectionRequest,
mojo::PendingReceiver<shape_detection::mojom::blink::BarcodeDetection>,
shape_detection::mojom::blink::BarcodeDetectorOptionsPtr);
ScriptPromise EnumerateSupportedFormats(ScriptState*);
......
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