Chromium Code Reviews| 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 ad2f9e1d349b300c21f985ec1f877c9ce1d5f519..7aa5851b8621d62790b8a3078f7faf258dee45e0 100644 |
| --- a/third_party/WebKit/Source/modules/shapedetection/ShapeDetector.cpp |
| +++ b/third_party/WebKit/Source/modules/shapedetection/ShapeDetector.cpp |
| @@ -49,6 +49,11 @@ ShapeDetector::ShapeDetector(LocalFrame& frame) { |
| DCHECK(frame.interfaceProvider()); |
| frame.interfaceProvider()->getInterface(mojo::GetProxy(&m_faceService)); |
| frame.interfaceProvider()->getInterface(mojo::GetProxy(&m_barcodeService)); |
| + m_faceService.set_connection_error_handler(convertToBaseCallback(WTF::bind( |
| + &ShapeDetector::onFaceServiceConnectionError, wrapWeakPersistent(this)))); |
| + m_barcodeService.set_connection_error_handler(convertToBaseCallback( |
| + WTF::bind(&ShapeDetector::onBarcodeServiceConnectionError, |
| + wrapWeakPersistent(this)))); |
| } |
| ShapeDetector::ShapeDetector(LocalFrame& frame, |
| @@ -165,24 +170,17 @@ ScriptPromise ShapeDetector::detectShapesOnImageElement( |
| return promise; |
| } |
| - m_serviceRequests.add(resolver); |
| if (detectorType == DetectorType::Face) { |
| - if (!m_faceService) { |
| - resolver->reject(DOMException::create( |
| - NotSupportedError, "Face detection service unavailable.")); |
| - return promise; |
| - } |
| + DCHECK(m_faceService); |
|
Reilly Grant (use Gerrit)
2016/11/30 21:43:28
We should still have the code to reject the promis
mcasas
2016/11/30 21:49:51
Done.
|
| + m_faceServiceRequests.add(resolver); |
| 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) { |
| - if (!m_barcodeService) { |
| - resolver->reject(DOMException::create( |
| - NotSupportedError, "Barcode detection service unavailable.")); |
| - return promise; |
| - } |
| + DCHECK(m_barcodeService); |
| + m_barcodeServiceRequests.add(resolver); |
| m_barcodeService->Detect( |
| std::move(sharedBufferHandle), img->naturalWidth(), |
| img->naturalHeight(), |
| @@ -308,24 +306,17 @@ ScriptPromise ShapeDetector::detectShapesOnData(DetectorType detectorType, |
| memcpy(mappedBuffer.get(), data, size); |
| - m_serviceRequests.add(resolver); |
| if (detectorType == DetectorType::Face) { |
| - if (!m_faceService) { |
| - resolver->reject(DOMException::create( |
| - NotSupportedError, "Face detection service unavailable.")); |
| - return promise; |
| - } |
| + DCHECK(m_faceService); |
| + m_faceServiceRequests.add(resolver); |
| 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) { |
| - if (!m_barcodeService) { |
| - resolver->reject(DOMException::create( |
| - NotSupportedError, "Barcode detection service unavailable.")); |
| - return promise; |
| - } |
| + DCHECK(m_barcodeService); |
| + m_barcodeServiceRequests.add(resolver); |
| m_barcodeService->Detect( |
| std::move(sharedBufferHandle), width, height, |
| convertToBaseCallback(WTF::bind(&ShapeDetector::onDetectBarcodes, |
| @@ -341,8 +332,9 @@ ScriptPromise ShapeDetector::detectShapesOnData(DetectorType detectorType, |
| void ShapeDetector::onDetectFaces( |
| ScriptPromiseResolver* resolver, |
| mojom::blink::FaceDetectionResultPtr faceDetectionResult) { |
| - if (!m_serviceRequests.contains(resolver)) |
| + if (!m_faceServiceRequests.contains(resolver)) |
| return; |
| + m_faceServiceRequests.remove(resolver); |
| HeapVector<Member<DOMRect>> detectedFaces; |
| for (const auto& boundingBox : faceDetectionResult->bounding_boxes) { |
| @@ -352,15 +344,14 @@ void ShapeDetector::onDetectFaces( |
| } |
| resolver->resolve(detectedFaces); |
| - m_serviceRequests.remove(resolver); |
| } |
| void ShapeDetector::onDetectBarcodes( |
| ScriptPromiseResolver* resolver, |
| Vector<mojom::blink::BarcodeDetectionResultPtr> barcodeDetectionResults) { |
| - if (!m_serviceRequests.contains(resolver)) |
| + if (!m_barcodeServiceRequests.contains(resolver)) |
| return; |
| - m_serviceRequests.remove(resolver); |
| + m_barcodeServiceRequests.remove(resolver); |
| HeapVector<Member<DetectedBarcode>> detectedBarcodes; |
| for (const auto& barcode : barcodeDetectionResults) { |
| @@ -374,8 +365,25 @@ void ShapeDetector::onDetectBarcodes( |
| resolver->resolve(detectedBarcodes); |
| } |
| +void ShapeDetector::onFaceServiceConnectionError() { |
| + for (const auto& request : m_faceServiceRequests) { |
| + request->reject(DOMException::create(NotSupportedError, |
| + "Face Detection not implemented.")); |
| + } |
| + m_faceServiceRequests.clear(); |
|
Reilly Grant (use Gerrit)
2016/11/30 21:43:28
Reset m_faceService so that code above knows the c
mcasas
2016/11/30 21:49:51
Done.
|
| +} |
| + |
| +void ShapeDetector::onBarcodeServiceConnectionError() { |
| + for (const auto& request : m_barcodeServiceRequests) { |
| + request->reject(DOMException::create(NotSupportedError, |
| + "Barcode Detection not implemented.")); |
| + } |
| + m_barcodeServiceRequests.clear(); |
| +} |
| + |
| DEFINE_TRACE(ShapeDetector) { |
| - visitor->trace(m_serviceRequests); |
| + visitor->trace(m_faceServiceRequests); |
| + visitor->trace(m_barcodeServiceRequests); |
| } |
| } // namespace blink |