OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 define('serial_service', [ | 5 define('serial_service', [ |
6 'content/public/renderer/service_provider', | 6 'content/public/renderer/service_provider', |
7 'data_receiver', | 7 'data_receiver', |
8 'data_sender', | 8 'data_sender', |
9 'device/serial/serial.mojom', | 9 'device/serial/serial.mojom', |
10 'device/serial/serial_serialization.mojom', | 10 'device/serial/serial_serialization.mojom', |
11 'mojo/public/js/bindings/core', | 11 'mojo/public/js/bindings/core', |
12 'mojo/public/js/bindings/router', | 12 'mojo/public/js/bindings/router', |
13 ], function(serviceProvider, | 13 ], function(serviceProvider, |
14 dataReceiver, | 14 dataReceiver, |
15 dataSender, | 15 dataSender, |
16 serialMojom, | 16 serialMojom, |
17 serialization, | 17 serialization, |
18 core, | 18 core, |
19 routerModule) { | 19 routerModule) { |
20 /** | 20 /** |
21 * A Javascript client for the serial service and connection Mojo services. | 21 * A Javascript client for the serial service and connection Mojo services. |
22 * | 22 * |
23 * This provides a thick client around the Mojo services, exposing a JS-style | 23 * This provides a thick client around the Mojo services, exposing a JS-style |
24 * interface to serial connections and information about serial devices. This | 24 * interface to serial connections and information about serial devices. This |
25 * converts parameters and result between the Apps serial API types and the | 25 * converts parameters and result between the Apps serial API types and the |
26 * Mojo types. | 26 * Mojo types. |
27 */ | 27 */ |
28 | 28 |
29 var service = new serialMojom.SerialServiceProxy(new routerModule.Router( | 29 var service = new serialMojom.SerialService.proxyClass( |
30 serviceProvider.connectToService(serialMojom.SerialServiceProxy.NAME_))); | 30 new routerModule.Router( |
| 31 serviceProvider.connectToService(serialMojom.SerialService.name))); |
31 | 32 |
32 function getDevices() { | 33 function getDevices() { |
33 return service.getDevices().then(function(response) { | 34 return service.getDevices().then(function(response) { |
34 return $Array.map(response.devices, function(device) { | 35 return $Array.map(response.devices, function(device) { |
35 var result = {path: device.path}; | 36 var result = {path: device.path}; |
36 if (device.has_vendor_id) | 37 if (device.has_vendor_id) |
37 result.vendorId = device.vendor_id; | 38 result.vendorId = device.vendor_id; |
38 if (device.has_product_id) | 39 if (device.has_product_id) |
39 result.productId = device.product_id; | 40 result.productId = device.product_id; |
40 if (device.display_name) | 41 if (device.display_name) |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 var serviceOptions = getServiceOptions(options); | 187 var serviceOptions = getServiceOptions(options); |
187 var pipe = core.createMessagePipe(); | 188 var pipe = core.createMessagePipe(); |
188 var sendPipe = core.createMessagePipe(); | 189 var sendPipe = core.createMessagePipe(); |
189 var receivePipe = core.createMessagePipe(); | 190 var receivePipe = core.createMessagePipe(); |
190 service.connect(path, | 191 service.connect(path, |
191 serviceOptions, | 192 serviceOptions, |
192 pipe.handle0, | 193 pipe.handle0, |
193 sendPipe.handle0, | 194 sendPipe.handle0, |
194 receivePipe.handle0); | 195 receivePipe.handle0); |
195 var router = new routerModule.Router(pipe.handle1); | 196 var router = new routerModule.Router(pipe.handle1); |
196 var connection = new serialMojom.ConnectionProxy(router); | 197 var connection = new serialMojom.Connection.proxyClass(router); |
197 return connection.getInfo().then(convertServiceInfo).then(function(info) { | 198 return connection.getInfo().then(convertServiceInfo).then(function(info) { |
198 return Promise.all([info, allocateConnectionId()]); | 199 return Promise.all([info, allocateConnectionId()]); |
199 }).catch(function(e) { | 200 }).catch(function(e) { |
200 router.close(); | 201 router.close(); |
201 core.close(sendPipe.handle1); | 202 core.close(sendPipe.handle1); |
202 core.close(receivePipe.handle1); | 203 core.close(receivePipe.handle1); |
203 throw e; | 204 throw e; |
204 }).then(function(results) { | 205 }).then(function(results) { |
205 var info = results[0]; | 206 var info = results[0]; |
206 var id = results[1]; | 207 var id = results[1]; |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 | 506 |
506 return { | 507 return { |
507 getDevices: getDevices, | 508 getDevices: getDevices, |
508 createConnection: Connection.create, | 509 createConnection: Connection.create, |
509 getConnection: getConnection, | 510 getConnection: getConnection, |
510 getConnections: getConnections, | 511 getConnections: getConnections, |
511 // For testing. | 512 // For testing. |
512 Connection: Connection, | 513 Connection: Connection, |
513 }; | 514 }; |
514 }); | 515 }); |
OLD | NEW |