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

Side by Side Diff: extensions/renderer/resources/serial_service.js

Issue 628763002: Mojo JS bindings: simplify mojo.connectToService() usage - Part 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
OLDNEW
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 'mojo/public/js/bindings/core', 10 'mojo/public/js/bindings/core',
11 'mojo/public/js/bindings/router', 11 'mojo/public/js/bindings/router',
12 ], function(serviceProvider, 12 ], function(serviceProvider,
13 dataReceiver, 13 dataReceiver,
14 dataSender, 14 dataSender,
15 serialMojom, 15 serialMojom,
16 core, 16 core,
17 routerModule) { 17 routerModule) {
18 /** 18 /**
19 * A Javascript client for the serial service and connection Mojo services. 19 * A Javascript client for the serial service and connection Mojo services.
20 * 20 *
21 * This provides a thick client around the Mojo services, exposing a JS-style 21 * This provides a thick client around the Mojo services, exposing a JS-style
22 * interface to serial connections and information about serial devices. This 22 * interface to serial connections and information about serial devices. This
23 * converts parameters and result between the Apps serial API types and the 23 * converts parameters and result between the Apps serial API types and the
24 * Mojo types. 24 * Mojo types.
25 */ 25 */
26 26
27 var service = new serialMojom.SerialServiceProxy(new routerModule.Router( 27 var service = new serialMojom.SerialService.proxyClass(
28 serviceProvider.connectToService(serialMojom.SerialServiceProxy.NAME_))); 28 new routerModule.Router(
29 serviceProvider.connectToService(serialMojom.SerialService.name)));
29 30
30 function getDevices() { 31 function getDevices() {
31 return service.getDevices().then(function(response) { 32 return service.getDevices().then(function(response) {
32 return $Array.map(response.devices, function(device) { 33 return $Array.map(response.devices, function(device) {
33 var result = {path: device.path}; 34 var result = {path: device.path};
34 if (device.has_vendor_id) 35 if (device.has_vendor_id)
35 result.vendorId = device.vendor_id; 36 result.vendorId = device.vendor_id;
36 if (device.has_product_id) 37 if (device.has_product_id)
37 result.productId = device.product_id; 38 result.productId = device.product_id;
38 if (device.display_name) 39 if (device.display_name)
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 var serviceOptions = getServiceOptions(options); 166 var serviceOptions = getServiceOptions(options);
166 var pipe = core.createMessagePipe(); 167 var pipe = core.createMessagePipe();
167 var sendPipe = core.createMessagePipe(); 168 var sendPipe = core.createMessagePipe();
168 var receivePipe = core.createMessagePipe(); 169 var receivePipe = core.createMessagePipe();
169 service.connect(path, 170 service.connect(path,
170 serviceOptions, 171 serviceOptions,
171 pipe.handle0, 172 pipe.handle0,
172 sendPipe.handle0, 173 sendPipe.handle0,
173 receivePipe.handle0); 174 receivePipe.handle0);
174 var router = new routerModule.Router(pipe.handle1); 175 var router = new routerModule.Router(pipe.handle1);
175 var connection = new serialMojom.ConnectionProxy(router); 176 var connection = new serialMojom.Connection.proxyClass(router);
176 return connection.getInfo().then(convertServiceInfo).then(function(info) { 177 return connection.getInfo().then(convertServiceInfo).then(function(info) {
177 return Promise.all([info, allocateConnectionId()]); 178 return Promise.all([info, allocateConnectionId()]);
178 }).catch(function(e) { 179 }).catch(function(e) {
179 router.close(); 180 router.close();
180 core.close(sendPipe.handle1); 181 core.close(sendPipe.handle1);
181 core.close(receivePipe.handle1); 182 core.close(receivePipe.handle1);
182 throw e; 183 throw e;
183 }).then(function(results) { 184 }).then(function(results) {
184 var info = results[0]; 185 var info = results[0];
185 var id = results[1]; 186 var id = results[1];
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 418
418 return { 419 return {
419 getDevices: getDevices, 420 getDevices: getDevices,
420 createConnection: Connection.create, 421 createConnection: Connection.create,
421 getConnection: getConnection, 422 getConnection: getConnection,
422 getConnections: getConnections, 423 getConnections: getConnections,
423 // For testing. 424 // For testing.
424 Connection: Connection, 425 Connection: Connection,
425 }; 426 };
426 }); 427 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698