OLD | NEW |
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/geometry/DOMRect.h" | 8 #include "core/geometry/DOMRect.h" |
9 #include "core/html/canvas/CanvasImageSource.h" | 9 #include "core/html/canvas/CanvasImageSource.h" |
10 #include "modules/imagecapture/Point2D.h" | 10 #include "modules/imagecapture/Point2D.h" |
11 #include "modules/shapedetection/DetectedBarcode.h" | 11 #include "modules/shapedetection/DetectedBarcode.h" |
12 #include "public/platform/InterfaceProvider.h" | 12 #include "public/platform/InterfaceProvider.h" |
13 #include "public/platform/Platform.h" | 13 #include "public/platform/Platform.h" |
14 | 14 |
15 namespace blink { | 15 namespace blink { |
16 | 16 |
17 BarcodeDetector* BarcodeDetector::Create() { | 17 BarcodeDetector* BarcodeDetector::Create() { |
18 return new BarcodeDetector(); | 18 return new BarcodeDetector(); |
19 } | 19 } |
20 | 20 |
21 BarcodeDetector::BarcodeDetector() : ShapeDetector() { | 21 BarcodeDetector::BarcodeDetector() : ShapeDetector() { |
22 Platform::Current()->GetInterfaceProvider()->GetInterface( | 22 Platform::Current()->GetInterfaceProvider()->GetInterface( |
23 mojo::MakeRequest(&barcode_service_)); | 23 mojo::MakeRequest(&barcode_service_)); |
24 barcode_service_.set_connection_error_handler(ConvertToBaseCallback( | 24 barcode_service_.set_connection_error_handler(ConvertToBaseCallback( |
25 WTF::Bind(&BarcodeDetector::OnBarcodeServiceConnectionError, | 25 WTF::Bind(&BarcodeDetector::OnBarcodeServiceConnectionError, |
26 WrapWeakPersistent(this)))); | 26 WrapWeakPersistent(this)))); |
27 } | 27 } |
28 | 28 |
29 ScriptPromise BarcodeDetector::DoDetect( | 29 ScriptPromise BarcodeDetector::DoDetect(ScriptPromiseResolver* resolver, |
30 ScriptPromiseResolver* resolver, | 30 skia::mojom::blink::BitmapPtr bitmap) { |
31 mojo::ScopedSharedBufferHandle shared_buffer_handle, | |
32 int image_width, | |
33 int image_height) { | |
34 ScriptPromise promise = resolver->Promise(); | 31 ScriptPromise promise = resolver->Promise(); |
35 if (!barcode_service_) { | 32 if (!barcode_service_) { |
36 resolver->Reject(DOMException::Create( | 33 resolver->Reject(DOMException::Create( |
37 kNotSupportedError, "Barcode detection service unavailable.")); | 34 kNotSupportedError, "Barcode detection service unavailable.")); |
38 return promise; | 35 return promise; |
39 } | 36 } |
40 barcode_service_requests_.insert(resolver); | 37 barcode_service_requests_.insert(resolver); |
41 barcode_service_->Detect( | 38 barcode_service_->Detect( |
42 std::move(shared_buffer_handle), image_width, image_height, | 39 std::move(bitmap), ConvertToBaseCallback(WTF::Bind( |
43 ConvertToBaseCallback(WTF::Bind(&BarcodeDetector::OnDetectBarcodes, | 40 &BarcodeDetector::OnDetectBarcodes, |
44 WrapPersistent(this), | 41 WrapPersistent(this), WrapPersistent(resolver)))); |
45 WrapPersistent(resolver)))); | |
46 return promise; | 42 return promise; |
47 } | 43 } |
48 | 44 |
49 void BarcodeDetector::OnDetectBarcodes( | 45 void BarcodeDetector::OnDetectBarcodes( |
50 ScriptPromiseResolver* resolver, | 46 ScriptPromiseResolver* resolver, |
51 Vector<shape_detection::mojom::blink::BarcodeDetectionResultPtr> | 47 Vector<shape_detection::mojom::blink::BarcodeDetectionResultPtr> |
52 barcode_detection_results) { | 48 barcode_detection_results) { |
53 DCHECK(barcode_service_requests_.Contains(resolver)); | 49 DCHECK(barcode_service_requests_.Contains(resolver)); |
54 barcode_service_requests_.erase(resolver); | 50 barcode_service_requests_.erase(resolver); |
55 | 51 |
(...skipping 25 matching lines...) Expand all Loading... |
81 barcode_service_requests_.clear(); | 77 barcode_service_requests_.clear(); |
82 barcode_service_.reset(); | 78 barcode_service_.reset(); |
83 } | 79 } |
84 | 80 |
85 DEFINE_TRACE(BarcodeDetector) { | 81 DEFINE_TRACE(BarcodeDetector) { |
86 ShapeDetector::Trace(visitor); | 82 ShapeDetector::Trace(visitor); |
87 visitor->Trace(barcode_service_requests_); | 83 visitor->Trace(barcode_service_requests_); |
88 } | 84 } |
89 | 85 |
90 } // namespace blink | 86 } // namespace blink |
OLD | NEW |