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

Side by Side Diff: third_party/WebKit/Source/modules/shapedetection/BarcodeDetector.cpp

Issue 2557513003: ShapeDetection: Eliminate DetectorType enum in ShapeDetector.cpp (Closed)
Patch Set: Remove state info from parent class, add doDetect() pure virtual method. Created 4 years 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "modules/shapedetection/BarcodeDetector.h" 5 #include "modules/shapedetection/BarcodeDetector.h"
6 6
7 #include "core/dom/DOMException.h" 7 #include "core/dom/DOMException.h"
8 #include "core/dom/DOMRect.h"
8 #include "core/frame/LocalDOMWindow.h" 9 #include "core/frame/LocalDOMWindow.h"
9 #include "core/frame/LocalFrame.h" 10 #include "core/frame/LocalFrame.h"
10 #include "core/html/canvas/CanvasImageSource.h" 11 #include "core/html/canvas/CanvasImageSource.h"
12 #include "modules/shapedetection/DetectedBarcode.h"
13 #include "public/platform/InterfaceProvider.h"
11 14
12 namespace blink { 15 namespace blink {
13 16
14 BarcodeDetector* BarcodeDetector::create(Document& document) { 17 BarcodeDetector* BarcodeDetector::create(Document& document) {
15 return new BarcodeDetector(*document.frame()); 18 return new BarcodeDetector(*document.frame());
16 } 19 }
17 20
18 BarcodeDetector::BarcodeDetector(LocalFrame& frame) : ShapeDetector(frame) {} 21 BarcodeDetector::BarcodeDetector(LocalFrame& frame) : ShapeDetector(frame) {
22 DCHECK(!m_barcodeService.is_bound());
Reilly Grant (use Gerrit) 2016/12/06 20:40:12 Just DCHECK(!m_barcodeService), though in the cons
xianglu 2016/12/06 22:31:56 Done.
23 frame.interfaceProvider()->getInterface(mojo::GetProxy(&m_barcodeService));
24 m_barcodeService.set_connection_error_handler(convertToBaseCallback(
25 WTF::bind(&BarcodeDetector::onBarcodeServiceConnectionError,
26 wrapWeakPersistent(this))));
27 }
19 28
20 ScriptPromise BarcodeDetector::detect( 29 ScriptPromise BarcodeDetector::doDetect(
21 ScriptState* scriptState, 30 ScriptPromiseResolver* resolver,
22 const CanvasImageSourceUnion& imageSource) { 31 mojo::ScopedSharedBufferHandle sharedBufferHandle,
23 return detectShapes(scriptState, ShapeDetector::DetectorType::Barcode, 32 int imageWidth,
24 imageSource); 33 int imageHeight) {
34 ScriptPromise promise = resolver->promise();
35 if (!m_barcodeService) {
36 resolver->reject(DOMException::create(
37 NotSupportedError, "Barcode detection service unavailable."));
38 return promise;
39 }
40 m_barcodeServiceRequests.add(resolver);
41 m_barcodeService->Detect(
42 std::move(sharedBufferHandle), imageWidth, imageHeight,
43 convertToBaseCallback(WTF::bind(&BarcodeDetector::onDetectBarcodes,
44 wrapPersistent(this),
45 wrapPersistent(resolver))));
46 sharedBufferHandle.reset();
Reilly Grant (use Gerrit) 2016/12/06 20:40:12 This line should be a no-op because std::move(shar
xianglu 2016/12/06 22:31:56 Done.
47 return promise;
48 }
49
50 void BarcodeDetector::onDetectBarcodes(
51 ScriptPromiseResolver* resolver,
52 Vector<mojom::blink::BarcodeDetectionResultPtr> barcodeDetectionResults) {
53 DCHECK(m_barcodeServiceRequests.contains(resolver));
54 m_barcodeServiceRequests.remove(resolver);
55
56 HeapVector<Member<DetectedBarcode>> detectedBarcodes;
57 for (const auto& barcode : barcodeDetectionResults) {
58 detectedBarcodes.append(DetectedBarcode::create(
59 barcode->raw_value,
60 DOMRect::create(barcode->bounding_box->x, barcode->bounding_box->y,
61 barcode->bounding_box->width,
62 barcode->bounding_box->height)));
63 }
64
65 resolver->resolve(detectedBarcodes);
66 }
67
68 void BarcodeDetector::onBarcodeServiceConnectionError() {
69 for (const auto& request : m_barcodeServiceRequests) {
70 request->reject(DOMException::create(NotSupportedError,
71 "Barcode Detection not implemented."));
72 }
73 m_barcodeServiceRequests.clear();
74 m_barcodeService.reset();
25 } 75 }
26 76
27 DEFINE_TRACE(BarcodeDetector) { 77 DEFINE_TRACE(BarcodeDetector) {
28 ShapeDetector::trace(visitor); 78 ShapeDetector::trace(visitor);
79 visitor->trace(m_barcodeServiceRequests);
29 } 80 }
30 81
31 } // namespace blink 82 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698