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 'device/serial/serial.mojom', | 7 'device/serial/serial.mojom', |
8 'mojo/public/js/bindings/core', | 8 'mojo/public/js/bindings/core', |
9 'mojo/public/js/bindings/router', | 9 'mojo/public/js/bindings/router', |
10 ], function(serviceProvider, serialMojom, core, routerModule) { | 10 ], function(serviceProvider, serialMojom, core, routerModule) { |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 for (var key in DEFAULT_CLIENT_OPTIONS) { | 115 for (var key in DEFAULT_CLIENT_OPTIONS) { |
116 this.options_[key] = DEFAULT_CLIENT_OPTIONS[key]; | 116 this.options_[key] = DEFAULT_CLIENT_OPTIONS[key]; |
117 } | 117 } |
118 this.setClientOptions_(options); | 118 this.setClientOptions_(options); |
119 } | 119 } |
120 | 120 |
121 Connection.create = function(path, options) { | 121 Connection.create = function(path, options) { |
122 options = options || {}; | 122 options = options || {}; |
123 var serviceOptions = getServiceOptions(options); | 123 var serviceOptions = getServiceOptions(options); |
124 var pipe = core.createMessagePipe(); | 124 var pipe = core.createMessagePipe(); |
125 service.connect(path, serviceOptions, pipe.handle0); | 125 // Note: These two are created and closed because the service implementation |
| 126 // requires that we provide valid message pipes for the data source and |
| 127 // sink. Currently the client handles are immediately closed; the real |
| 128 // implementation will come later. |
| 129 var sendPipe = core.createMessagePipe(); |
| 130 var receivePipe = core.createMessagePipe(); |
| 131 service.connect(path, |
| 132 serviceOptions, |
| 133 pipe.handle0, |
| 134 sendPipe.handle0, |
| 135 receivePipe.handle0); |
| 136 core.close(sendPipe.handle1); |
| 137 core.close(receivePipe.handle1); |
126 var router = new routerModule.Router(pipe.handle1); | 138 var router = new routerModule.Router(pipe.handle1); |
127 var connection = new serialMojom.ConnectionProxy(router); | 139 var connection = new serialMojom.ConnectionProxy(router); |
128 return connection.getInfo().then(convertServiceInfo).then( | 140 return connection.getInfo().then(convertServiceInfo).then( |
129 function(info) { | 141 function(info) { |
130 return Promise.all([info, allocateConnectionId()]); | 142 return Promise.all([info, allocateConnectionId()]); |
131 }).catch(function(e) { | 143 }).catch(function(e) { |
132 router.close(); | 144 router.close(); |
133 throw e; | 145 throw e; |
134 }).then(function(results) { | 146 }).then(function(results) { |
135 var info = results[0]; | 147 var info = results[0]; |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 return Promise.resolve(nextConnectionId_++); | 277 return Promise.resolve(nextConnectionId_++); |
266 } | 278 } |
267 | 279 |
268 return { | 280 return { |
269 getDevices: getDevices, | 281 getDevices: getDevices, |
270 createConnection: Connection.create, | 282 createConnection: Connection.create, |
271 getConnection: getConnection, | 283 getConnection: getConnection, |
272 getConnections: getConnections, | 284 getConnections: getConnections, |
273 }; | 285 }; |
274 }); | 286 }); |
OLD | NEW |