| 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', |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 if ('name' in options) | 127 if ('name' in options) |
| 128 clientOptions.name = options.name; | 128 clientOptions.name = options.name; |
| 129 if ('receiveTimeout' in options) | 129 if ('receiveTimeout' in options) |
| 130 clientOptions.receiveTimeout = options.receiveTimeout; | 130 clientOptions.receiveTimeout = options.receiveTimeout; |
| 131 if ('sendTimeout' in options) | 131 if ('sendTimeout' in options) |
| 132 clientOptions.sendTimeout = options.sendTimeout; | 132 clientOptions.sendTimeout = options.sendTimeout; |
| 133 if ('bufferSize' in options) | 133 if ('bufferSize' in options) |
| 134 clientOptions.bufferSize = options.bufferSize; | 134 clientOptions.bufferSize = options.bufferSize; |
| 135 }; | 135 }; |
| 136 | 136 |
| 137 function Connection(connection, router, receivePipe, sendPipe, id, options) { | 137 function Connection(connection, router, receivePipe, receiveClientPipe, |
| 138 sendPipe, id, options) { |
| 138 var state = new serialization.ConnectionState(); | 139 var state = new serialization.ConnectionState(); |
| 139 state.connectionId = id; | 140 state.connectionId = id; |
| 140 updateClientOptions(state, options); | 141 updateClientOptions(state, options); |
| 141 var receiver = new dataReceiver.DataReceiver( | 142 var receiver = new dataReceiver.DataReceiver( |
| 142 receivePipe, state.bufferSize, serialMojom.ReceiveError.DISCONNECTED); | 143 receivePipe, receiveClientPipe, state.bufferSize, |
| 143 var sender = new dataSender.DataSender( | 144 serialMojom.ReceiveError.DISCONNECTED); |
| 144 sendPipe, state.bufferSize, serialMojom.SendError.DISCONNECTED); | 145 var sender = new dataSender.DataSender(sendPipe, state.bufferSize, |
| 146 serialMojom.SendError.DISCONNECTED); |
| 145 this.init_(state, | 147 this.init_(state, |
| 146 connection, | 148 connection, |
| 147 router, | 149 router, |
| 148 receiver, | 150 receiver, |
| 149 sender, | 151 sender, |
| 150 null, | 152 null, |
| 151 serialMojom.ReceiveError.NONE); | 153 serialMojom.ReceiveError.NONE); |
| 152 connections_.set(id, this); | 154 connections_.set(id, this); |
| 153 this.startReceive_(); | 155 this.startReceive_(); |
| 154 } | 156 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 181 this.sendPipe_ = sender; | 183 this.sendPipe_ = sender; |
| 182 this.sendInProgress_ = false; | 184 this.sendInProgress_ = false; |
| 183 }; | 185 }; |
| 184 | 186 |
| 185 Connection.create = function(path, options) { | 187 Connection.create = function(path, options) { |
| 186 options = options || {}; | 188 options = options || {}; |
| 187 var serviceOptions = getServiceOptions(options); | 189 var serviceOptions = getServiceOptions(options); |
| 188 var pipe = core.createMessagePipe(); | 190 var pipe = core.createMessagePipe(); |
| 189 var sendPipe = core.createMessagePipe(); | 191 var sendPipe = core.createMessagePipe(); |
| 190 var receivePipe = core.createMessagePipe(); | 192 var receivePipe = core.createMessagePipe(); |
| 193 var receivePipeClient = core.createMessagePipe(); |
| 191 service.connect(path, | 194 service.connect(path, |
| 192 serviceOptions, | 195 serviceOptions, |
| 193 pipe.handle0, | 196 pipe.handle0, |
| 194 sendPipe.handle0, | 197 sendPipe.handle0, |
| 195 receivePipe.handle0); | 198 receivePipe.handle0, |
| 199 receivePipeClient.handle0); |
| 196 var router = new routerModule.Router(pipe.handle1); | 200 var router = new routerModule.Router(pipe.handle1); |
| 197 var connection = new serialMojom.Connection.proxyClass(router); | 201 var connection = new serialMojom.Connection.proxyClass(router); |
| 198 return connection.getInfo().then(convertServiceInfo).then(function(info) { | 202 return connection.getInfo().then(convertServiceInfo).then(function(info) { |
| 199 return Promise.all([info, allocateConnectionId()]); | 203 return Promise.all([info, allocateConnectionId()]); |
| 200 }).catch(function(e) { | 204 }).catch(function(e) { |
| 201 router.close(); | 205 router.close(); |
| 202 core.close(sendPipe.handle1); | 206 core.close(sendPipe.handle1); |
| 203 core.close(receivePipe.handle1); | 207 core.close(receivePipe.handle1); |
| 208 core.close(receivePipeClient.handle1); |
| 204 throw e; | 209 throw e; |
| 205 }).then(function(results) { | 210 }).then(function(results) { |
| 206 var info = results[0]; | 211 var info = results[0]; |
| 207 var id = results[1]; | 212 var id = results[1]; |
| 208 var serialConnectionClient = new Connection(connection, | 213 var serialConnectionClient = new Connection(connection, |
| 209 router, | 214 router, |
| 210 receivePipe.handle1, | 215 receivePipe.handle1, |
| 216 receivePipeClient.handle1, |
| 211 sendPipe.handle1, | 217 sendPipe.handle1, |
| 212 id, | 218 id, |
| 213 options); | 219 options); |
| 214 var clientInfo = serialConnectionClient.getClientInfo_(); | 220 var clientInfo = serialConnectionClient.getClientInfo_(); |
| 215 for (var key in clientInfo) { | 221 for (var key in clientInfo) { |
| 216 info[key] = clientInfo[key]; | 222 info[key] = clientInfo[key]; |
| 217 } | 223 } |
| 218 return { | 224 return { |
| 219 connection: serialConnectionClient, | 225 connection: serialConnectionClient, |
| 220 info: info, | 226 info: info, |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 | 512 |
| 507 return { | 513 return { |
| 508 getDevices: getDevices, | 514 getDevices: getDevices, |
| 509 createConnection: Connection.create, | 515 createConnection: Connection.create, |
| 510 getConnection: getConnection, | 516 getConnection: getConnection, |
| 511 getConnections: getConnections, | 517 getConnections: getConnections, |
| 512 // For testing. | 518 // For testing. |
| 513 Connection: Connection, | 519 Connection: Connection, |
| 514 }; | 520 }; |
| 515 }); | 521 }); |
| OLD | NEW |