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: extensions/renderer/resources/serial_service.js

Issue 873293006: Revert of Remove Client= from device/serial/data_stream.mojom. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 'device/serial/serial_serialization.mojom', 10 'device/serial/serial_serialization.mojom',
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
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, receiveClientPipe, 137 function Connection(connection, router, receivePipe, sendPipe, id, options) {
138 sendPipe, sendClientPipe, id, options) {
139 var state = new serialization.ConnectionState(); 138 var state = new serialization.ConnectionState();
140 state.connectionId = id; 139 state.connectionId = id;
141 updateClientOptions(state, options); 140 updateClientOptions(state, options);
142 var receiver = new dataReceiver.DataReceiver( 141 var receiver = new dataReceiver.DataReceiver(
143 receivePipe, receiveClientPipe, state.bufferSize, 142 receivePipe, state.bufferSize, serialMojom.ReceiveError.DISCONNECTED);
144 serialMojom.ReceiveError.DISCONNECTED); 143 var sender = new dataSender.DataSender(
145 var sender = 144 sendPipe, state.bufferSize, serialMojom.SendError.DISCONNECTED);
146 new dataSender.DataSender(sendPipe, sendClientPipe, state.bufferSize,
147 serialMojom.SendError.DISCONNECTED);
148 this.init_(state, 145 this.init_(state,
149 connection, 146 connection,
150 router, 147 router,
151 receiver, 148 receiver,
152 sender, 149 sender,
153 null, 150 null,
154 serialMojom.ReceiveError.NONE); 151 serialMojom.ReceiveError.NONE);
155 connections_.set(id, this); 152 connections_.set(id, this);
156 this.startReceive_(); 153 this.startReceive_();
157 } 154 }
(...skipping 25 matching lines...) Expand all
183 this.receivePipe_ = receiver; 180 this.receivePipe_ = receiver;
184 this.sendPipe_ = sender; 181 this.sendPipe_ = sender;
185 this.sendInProgress_ = false; 182 this.sendInProgress_ = false;
186 }; 183 };
187 184
188 Connection.create = function(path, options) { 185 Connection.create = function(path, options) {
189 options = options || {}; 186 options = options || {};
190 var serviceOptions = getServiceOptions(options); 187 var serviceOptions = getServiceOptions(options);
191 var pipe = core.createMessagePipe(); 188 var pipe = core.createMessagePipe();
192 var sendPipe = core.createMessagePipe(); 189 var sendPipe = core.createMessagePipe();
193 var sendPipeClient = core.createMessagePipe();
194 var receivePipe = core.createMessagePipe(); 190 var receivePipe = core.createMessagePipe();
195 var receivePipeClient = core.createMessagePipe();
196 service.connect(path, 191 service.connect(path,
197 serviceOptions, 192 serviceOptions,
198 pipe.handle0, 193 pipe.handle0,
199 sendPipe.handle0, 194 sendPipe.handle0,
200 sendPipeClient.handle0, 195 receivePipe.handle0);
201 receivePipe.handle0,
202 receivePipeClient.handle0);
203 var router = new routerModule.Router(pipe.handle1); 196 var router = new routerModule.Router(pipe.handle1);
204 var connection = new serialMojom.Connection.proxyClass(router); 197 var connection = new serialMojom.Connection.proxyClass(router);
205 return connection.getInfo().then(convertServiceInfo).then(function(info) { 198 return connection.getInfo().then(convertServiceInfo).then(function(info) {
206 return Promise.all([info, allocateConnectionId()]); 199 return Promise.all([info, allocateConnectionId()]);
207 }).catch(function(e) { 200 }).catch(function(e) {
208 router.close(); 201 router.close();
209 core.close(sendPipe.handle1); 202 core.close(sendPipe.handle1);
210 core.close(sendPipeClient.handle1);
211 core.close(receivePipe.handle1); 203 core.close(receivePipe.handle1);
212 core.close(receivePipeClient.handle1);
213 throw e; 204 throw e;
214 }).then(function(results) { 205 }).then(function(results) {
215 var info = results[0]; 206 var info = results[0];
216 var id = results[1]; 207 var id = results[1];
217 var serialConnectionClient = new Connection(connection, 208 var serialConnectionClient = new Connection(connection,
218 router, 209 router,
219 receivePipe.handle1, 210 receivePipe.handle1,
220 receivePipeClient.handle1,
221 sendPipe.handle1, 211 sendPipe.handle1,
222 sendPipeClient.handle1,
223 id, 212 id,
224 options); 213 options);
225 var clientInfo = serialConnectionClient.getClientInfo_(); 214 var clientInfo = serialConnectionClient.getClientInfo_();
226 for (var key in clientInfo) { 215 for (var key in clientInfo) {
227 info[key] = clientInfo[key]; 216 info[key] = clientInfo[key];
228 } 217 }
229 return { 218 return {
230 connection: serialConnectionClient, 219 connection: serialConnectionClient,
231 info: info, 220 info: info,
232 }; 221 };
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 506
518 return { 507 return {
519 getDevices: getDevices, 508 getDevices: getDevices,
520 createConnection: Connection.create, 509 createConnection: Connection.create,
521 getConnection: getConnection, 510 getConnection: getConnection,
522 getConnections: getConnections, 511 getConnections: getConnections,
523 // For testing. 512 // For testing.
524 Connection: Connection, 513 Connection: Connection,
525 }; 514 };
526 }); 515 });
OLDNEW
« no previous file with comments | « extensions/renderer/resources/data_sender.js ('k') | extensions/test/data/data_receiver_unittest.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698