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

Side by Side Diff: third_party/WebKit/LayoutTests/shapedetection/resources/mock-facedetection.js

Issue 2818563006: ShapeDetection: Holding all of mock service to prevent GC (Closed)
Patch Set: ShapeDetection: Holding the MockFaceDetection to prevent Binding Object to be GCd Created 3 years, 7 months 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
« no previous file with comments | « third_party/WebKit/LayoutTests/TestExpectations ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 "use strict"; 1 "use strict";
2 2
3 let mockFaceDetectionProviderReady = define( 3 let mockFaceDetectionProviderReady = define(
4 'mockFaceDetectionProvider', 4 'mockFaceDetectionProvider',
5 ['services/shape_detection/public/interfaces/facedetection.mojom', 5 ['services/shape_detection/public/interfaces/facedetection.mojom',
6 'services/shape_detection/public/interfaces/facedetection_provider.mojom', 6 'services/shape_detection/public/interfaces/facedetection_provider.mojom',
7 'mojo/public/js/bindings', 7 'mojo/public/js/bindings',
8 'mojo/public/js/core', 8 'mojo/public/js/core',
9 'content/public/renderer/interfaces', 9 'content/public/renderer/interfaces',
10 ], (faceDetection, faceDetectionProvider, bindings, mojo, interfaces) => { 10 ], (faceDetection, faceDetectionProvider, bindings, mojo, interfaces) => {
11 11
12 class MockFaceDetectionProvider { 12 class MockFaceDetectionProvider {
13 constructor() { 13 constructor() {
14 this.bindingSet_ = new bindings.BindingSet( 14 this.bindingSet_ = new bindings.BindingSet(
15 faceDetectionProvider.FaceDetectionProvider); 15 faceDetectionProvider.FaceDetectionProvider);
16 16
17 interfaces.addInterfaceOverrideForTesting( 17 interfaces.addInterfaceOverrideForTesting(
18 faceDetectionProvider.FaceDetectionProvider.name, 18 faceDetectionProvider.FaceDetectionProvider.name,
19 handle => this.bindingSet_.addBinding(this, handle)); 19 handle => this.bindingSet_.addBinding(this, handle));
20
21 this.serviceArray_ = [];
Ken Rockot(use gerrit already) 2017/05/03 16:48:54 nit: how about "mockServiceInstances_" instead of
22 this.buffer_data_ = [];
20 } 23 }
21 24
22 createFaceDetection(request, options) { 25 createFaceDetection(request, options) {
23 this.mock_service_ = new MockFaceDetection(request, options); 26 this.maxDetectedFaces_ = options.max_detected_faces;
Ken Rockot(use gerrit already) 2017/05/03 16:48:54 Doesn't this effectively cause the same problem as
27 this.fastMode_ = options.fast_mode;
28
29 let mock_service = new MockFaceDetection(request, options, this);
Ken Rockot(use gerrit already) 2017/05/03 16:48:54 nit: Please either just delete this unnecessary li
30 this.serviceArray_.push(mock_service);
24 } 31 }
25 32
26 getFrameData() { 33 getFrameData() {
27 return this.mock_service_.buffer_data_; 34 return this.buffer_data_;
Ken Rockot(use gerrit already) 2017/05/03 16:48:54 nit: While you're here, please fix the naming styl
28 } 35 }
29 36
30 getMaxDetectedFaces() { 37 getMaxDetectedFaces() {
31 return this.mock_service_.maxDetectedFaces_; 38 return this.maxDetectedFaces_;
32 } 39 }
33 40
34 getFastMode () { 41 getFastMode () {
35 return this.mock_service_.fastMode_; 42 return this.fastMode_;
36 } 43 }
37 } 44 }
38 45
39 class MockFaceDetection { 46 class MockFaceDetection {
40 constructor(request, options) { 47 constructor(request, options, provider) {
41 this.maxDetectedFaces_ = options.max_detected_faces; 48 this.provider_ = provider;
42 this.fastMode_ = options.fast_mode;
43 this.binding_ = new bindings.Binding(faceDetection.FaceDetection, this, 49 this.binding_ = new bindings.Binding(faceDetection.FaceDetection, this,
44 request); 50 request);
45 } 51 }
46 52
47 detect(frame_data, width, height) { 53 detect(frame_data, width, height) {
48 let receivedStruct = mojo.mapBuffer(frame_data, 0, width*height*4, 0); 54 let receivedStruct = mojo.mapBuffer(frame_data, 0, width*height*4, 0);
49 this.buffer_data_ = new Uint32Array(receivedStruct.buffer); 55 this.provider_.buffer_data_ = new Uint32Array(receivedStruct.buffer);
50 return Promise.resolve({ 56 return Promise.resolve({
51 result: { 57 result: {
52 bounding_boxes: [ 58 bounding_boxes: [
53 { x : 1.0, y: 1.0, width: 100.0, height: 100.0 }, 59 { x : 1.0, y: 1.0, width: 100.0, height: 100.0 },
54 { x : 2.0, y: 2.0, width: 200.0, height: 200.0 }, 60 { x : 2.0, y: 2.0, width: 200.0, height: 200.0 },
55 { x : 3.0, y: 3.0, width: 300.0, height: 300.0 }, 61 { x : 3.0, y: 3.0, width: 300.0, height: 300.0 },
56 ] 62 ]
57 } 63 }
58 }); 64 });
59 mojo.unmapBuffer(receivedStruct.buffer); 65 mojo.unmapBuffer(receivedStruct.buffer);
60 } 66 }
61 } 67 }
62 return new MockFaceDetectionProvider(); 68 return new MockFaceDetectionProvider();
63 }); 69 });
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/TestExpectations ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698