Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(260)

Unified Diff: third_party/WebKit/Source/modules/shapedetection/ShapeDetector.cpp

Issue 2522143002: ShapeDetection: split mojom into face and barcode interfaces (Closed)
Patch Set: Smart rebase to https://crrev.com/2527503003 (FaceDetectorOptions) Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/shapedetection/ShapeDetector.cpp
diff --git a/third_party/WebKit/Source/modules/shapedetection/ShapeDetector.cpp b/third_party/WebKit/Source/modules/shapedetection/ShapeDetector.cpp
index e2ea03b5f0fec7f197639ea752e4d4e5d988ec81..ad2f9e1d349b300c21f985ec1f877c9ce1d5f519 100644
--- a/third_party/WebKit/Source/modules/shapedetection/ShapeDetector.cpp
+++ b/third_party/WebKit/Source/modules/shapedetection/ShapeDetector.cpp
@@ -44,17 +44,19 @@ static CanvasImageSource* toImageSourceInternal(
} // anonymous namespace
ShapeDetector::ShapeDetector(LocalFrame& frame) {
- DCHECK(!m_service.is_bound());
+ DCHECK(!m_faceService.is_bound());
+ DCHECK(!m_barcodeService.is_bound());
DCHECK(frame.interfaceProvider());
- frame.interfaceProvider()->getInterface(mojo::GetProxy(&m_service));
+ frame.interfaceProvider()->getInterface(mojo::GetProxy(&m_faceService));
+ frame.interfaceProvider()->getInterface(mojo::GetProxy(&m_barcodeService));
}
ShapeDetector::ShapeDetector(LocalFrame& frame,
const FaceDetectorOptions& options)
: ShapeDetector(frame) {
- m_options = mojom::blink::FaceDetectorOptions::New();
- m_options->max_detected_faces = options.maxDetectedFaces();
- m_options->fast_mode = options.fastMode();
+ m_faceDetectorOptions = mojom::blink::FaceDetectorOptions::New();
+ m_faceDetectorOptions->max_detected_faces = options.maxDetectedFaces();
+ m_faceDetectorOptions->fast_mode = options.fastMode();
}
ScriptPromise ShapeDetector::detectShapes(
@@ -163,23 +165,25 @@ ScriptPromise ShapeDetector::detectShapesOnImageElement(
return promise;
}
- if (!m_service) {
- resolver->reject(DOMException::create(
- NotSupportedError, "Shape detection service unavailable."));
- return promise;
- }
-
m_serviceRequests.add(resolver);
- DCHECK(m_service.is_bound());
if (detectorType == DetectorType::Face) {
- m_service->DetectFaces(
- std::move(sharedBufferHandle), img->naturalWidth(),
- img->naturalHeight(), m_options.Clone(),
- convertToBaseCallback(WTF::bind(&ShapeDetector::onDetectFaces,
- wrapPersistent(this),
- wrapPersistent(resolver))));
+ if (!m_faceService) {
+ resolver->reject(DOMException::create(
+ NotSupportedError, "Face detection service unavailable."));
+ return promise;
+ }
+ m_faceService->Detect(std::move(sharedBufferHandle), img->naturalWidth(),
+ img->naturalHeight(), m_faceDetectorOptions.Clone(),
+ convertToBaseCallback(WTF::bind(
+ &ShapeDetector::onDetectFaces,
+ wrapPersistent(this), wrapPersistent(resolver))));
} else if (detectorType == DetectorType::Barcode) {
- m_service->DetectBarcodes(
+ if (!m_barcodeService) {
+ resolver->reject(DOMException::create(
+ NotSupportedError, "Barcode detection service unavailable."));
+ return promise;
+ }
+ m_barcodeService->Detect(
std::move(sharedBufferHandle), img->naturalWidth(),
img->naturalHeight(),
convertToBaseCallback(WTF::bind(&ShapeDetector::onDetectBarcodes,
@@ -298,12 +302,6 @@ ScriptPromise ShapeDetector::detectShapesOnData(DetectorType detectorType,
return promise;
}
- if (!m_service) {
- resolver->reject(DOMException::create(
- NotSupportedError, "Shape detection service unavailable."));
- return promise;
- }
-
const mojo::ScopedSharedBufferMapping mappedBuffer =
sharedBufferHandle->Map(size);
DCHECK(mappedBuffer.get());
@@ -311,15 +309,24 @@ ScriptPromise ShapeDetector::detectShapesOnData(DetectorType detectorType,
memcpy(mappedBuffer.get(), data, size);
m_serviceRequests.add(resolver);
- DCHECK(m_service.is_bound());
if (detectorType == DetectorType::Face) {
- m_service->DetectFaces(
- std::move(sharedBufferHandle), width, height, m_options.Clone(),
- convertToBaseCallback(WTF::bind(&ShapeDetector::onDetectFaces,
- wrapPersistent(this),
- wrapPersistent(resolver))));
+ if (!m_faceService) {
+ resolver->reject(DOMException::create(
+ NotSupportedError, "Face detection service unavailable."));
+ return promise;
+ }
+ m_faceService->Detect(std::move(sharedBufferHandle), width, height,
+ m_faceDetectorOptions.Clone(),
+ convertToBaseCallback(WTF::bind(
+ &ShapeDetector::onDetectFaces,
+ wrapPersistent(this), wrapPersistent(resolver))));
} else if (detectorType == DetectorType::Barcode) {
- m_service->DetectBarcodes(
+ if (!m_barcodeService) {
+ resolver->reject(DOMException::create(
+ NotSupportedError, "Barcode detection service unavailable."));
+ return promise;
+ }
+ m_barcodeService->Detect(
std::move(sharedBufferHandle), width, height,
convertToBaseCallback(WTF::bind(&ShapeDetector::onDetectBarcodes,
wrapPersistent(this),
« no previous file with comments | « third_party/WebKit/Source/modules/shapedetection/ShapeDetector.h ('k') | third_party/WebKit/public/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698