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('data_receiver', [ | 5 define('data_receiver', [ |
6 'async_waiter', | 6 'async_waiter', |
7 'device/serial/data_stream.mojom', | 7 'device/serial/data_stream.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(asyncWaiter, dataStream, core, router) { | 10 ], function(asyncWaiter, dataStream, core, router) { |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
185 this.shutDown_ = true; | 185 this.shutDown_ = true; |
186 this.router_.close(); | 186 this.router_.close(); |
187 this.waiter_.stop(); | 187 this.waiter_.stop(); |
188 core.close(this.receivePipe_); | 188 core.close(this.receivePipe_); |
189 if (this.receive_) { | 189 if (this.receive_) { |
190 this.receive_.dispatchFatalError(this.fatalErrorValue_); | 190 this.receive_.dispatchFatalError(this.fatalErrorValue_); |
191 this.receive_ = null; | 191 this.receive_ = null; |
192 } | 192 } |
193 }; | 193 }; |
194 | 194 |
195 DataReceiver.prototype.serialize = function() { | |
raymes
2014/09/17 02:05:04
Please add comments to these :)
Sam McNally
2014/09/17 08:07:14
Done.
| |
196 this.waiter_.stop(); | |
197 if (this.receive_) { | |
198 this.receive_.dispatchFatalError(this.fatalErrorValue_); | |
199 this.receive_ = null; | |
200 } | |
201 var serialized = { | |
202 source: this.router_.connector_.handle_, | |
203 data_pipe: this.receivePipe_, | |
204 fatal_error_value: this.fatalErrorValue_, | |
205 bytes_received: this.bytesReceived_, | |
206 paused: this.paused_, | |
207 shut_down: this.shutDown_, | |
208 }; | |
209 this.router_.connector_.handle_ = null; | |
210 this.router_.close(); | |
211 this.shutDown_ = true; | |
212 return Promise.resolve(serialized); | |
213 }; | |
214 | |
215 DataReceiver.deserialize = function(serialized) { | |
216 var receiver = $Object.create(DataReceiver.prototype); | |
217 receiver.deserialize_(serialized); | |
218 return receiver; | |
219 }; | |
220 | |
221 DataReceiver.prototype.deserialize_ = function(serialized) { | |
222 this.receivePipe_ = serialized.data_pipe; | |
223 this.fatalErrorValue_ = serialized.fatal_error_value; | |
224 this.bytesReceived_ = serialized.bytes_received; | |
225 this.paused_ = serialized.paused; | |
226 this.shutDown_ = serialized.shut_down; | |
227 this.router_ = new router.Router(serialized.source); | |
228 this.router_.setIncomingReceiver(this); | |
229 this.source_ = new dataStream.DataSourceProxy(this.router_); | |
230 this.waiter_ = new asyncWaiter.AsyncWaiter(this.receivePipe_, | |
231 core.HANDLE_SIGNAL_READABLE, | |
232 this.onHandleReady_.bind(this)); | |
233 }; | |
234 | |
195 /** | 235 /** |
196 * Receive data from the DataSource. | 236 * Receive data from the DataSource. |
197 * @return {Promise.<ArrayBuffer>} A promise to the received data. If an error | 237 * @return {Promise.<ArrayBuffer>} A promise to the received data. If an error |
198 * occurs, the promise will reject with an Error object with a property | 238 * occurs, the promise will reject with an Error object with a property |
199 * error containing the error code. | 239 * error containing the error code. |
200 * @throws Will throw if this has encountered a fatal error or another receive | 240 * @throws Will throw if this has encountered a fatal error or another receive |
201 * is in progress. | 241 * is in progress. |
202 */ | 242 */ |
203 DataReceiver.prototype.receive = function() { | 243 DataReceiver.prototype.receive = function() { |
204 if (this.shutDown_) | 244 if (this.shutDown_) |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
268 this.receive_ = null; | 308 this.receive_ = null; |
269 this.waiter_.stop(); | 309 this.waiter_.stop(); |
270 this.paused_ = true; | 310 this.paused_ = true; |
271 return; | 311 return; |
272 } | 312 } |
273 this.pendingError_ = pendingError; | 313 this.pendingError_ = pendingError; |
274 }; | 314 }; |
275 | 315 |
276 return {DataReceiver: DataReceiver}; | 316 return {DataReceiver: DataReceiver}; |
277 }); | 317 }); |
OLD | NEW |