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

Unified Diff: extensions/renderer/resources/data_sender.js

Issue 571333002: Add serialization support to the JS DataSender and DataReceiver. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@stash-service
Patch Set: address comments Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: extensions/renderer/resources/data_sender.js
diff --git a/extensions/renderer/resources/data_sender.js b/extensions/renderer/resources/data_sender.js
index ee1abb33ab0b98d29639f21c8ae9098e500d2a24..c9270f705aea732f9f23e7a914689c3d2142932d 100644
--- a/extensions/renderer/resources/data_sender.js
+++ b/extensions/renderer/resources/data_sender.js
@@ -5,9 +5,10 @@
define('data_sender', [
'async_waiter',
'device/serial/data_stream.mojom',
+ 'device/serial/data_stream_serialization.mojom',
'mojo/public/js/bindings/core',
'mojo/public/js/bindings/router',
-], function(asyncWaiter, dataStreamMojom, core, routerModule) {
+], function(asyncWaiter, dataStreamMojom, serialization, core, routerModule) {
/**
* @module data_sender
*/
@@ -257,10 +258,70 @@ define('data_sender', [
this.sendsAwaitingAck_.pop().reportBytesSentAndError(
0, this.fatalErrorValue_);
}
- if (this.pendingCancel_) {
- this.pendingCancel_();
- this.pendingCancel_ = null;
+ this.callCancelCallback_();
+ };
+
+ /**
+ * Serializes this DataSender.
+ * @return {Promise.<?SerializedDataSender>} The serialization of this
raymes 2014/09/18 03:16:06 returns a promise that resolves to
Sam McNally 2014/09/19 04:58:46 Done.
+ * DataSender. If this DataSender has shut down, this will return null.
raymes 2014/09/18 03:16:06 It's probably worth noting that any sends in progr
Sam McNally 2014/09/19 04:58:47 Done.
+ */
+ DataSender.prototype.serialize = function() {
+ if (this.shutDown_)
+ return Promise.resolve(null);
+
+ var readyToSerialize = Promise.resolve();
+ if (this.pendingSends_.length) {
+ if (this.pendingCancel_)
+ readyToSerialize = this.cancelPromise_;
+ else
+ readyToSerialize = this.cancel(this.fatalErrorValue_);
}
+ return readyToSerialize.then(function() {
+ this.waiter_.stop();
+ var serialized = new serialization.SerializedDataSender();
+ serialized.sink = this.router_.connector_.handle_,
+ serialized.data_pipe = this.sendPipe_,
+ serialized.fatal_error_value = this.fatalErrorValue_,
+ this.router_.connector_.handle_ = null;
+ this.router_.close();
+ this.shutDown_ = true;
+ return serialized;
+ }.bind(this));
+ };
+
+ /**
+ * Deserializes a SerializedDataSender.
+ * @param {?SerializedDataSender} serialized The serialized DataSender.
+ * @return {DataSender} The deserialized DataSender.
+ */
+ DataSender.deserialize = function(serialized) {
+ var sender = $Object.create(DataSender.prototype);
+ sender.deserialize_(serialized);
+ return sender;
+ };
+
+ /**
+ * Deserializes a SerializedDataSender into this DataSender.
+ * @param {?SerializedDataSender} serialized The serialized DataSender.
+ * @private
+ */
+ DataSender.prototype.deserialize_ = function(serialized) {
+ if (!serialized) {
+ this.shutDown_ = true;
+ return;
+ }
+ this.sendPipe_ = serialized.data_pipe;
+ this.fatalErrorValue_ = serialized.fatal_error_value;
+ this.shutDown_ = false;
+ this.router_ = new routerModule.Router(serialized.sink);
+ this.sink_ = new dataStreamMojom.DataSinkProxy(this.router_);
+ this.router_.setIncomingReceiver(this);
+ this.waiter_ = new asyncWaiter.AsyncWaiter(this.sendPipe_,
+ core.HANDLE_SIGNAL_WRITABLE,
+ this.onHandleReady_.bind(this));
+ this.pendingSends_ = [];
+ this.sendsAwaitingAck_ = [];
raymes 2014/09/18 03:16:06 One downside of this approach (not calling the con
Sam McNally 2014/09/19 04:58:47 Done.
};
/**
@@ -301,9 +362,10 @@ define('data_sender', [
return Promise.resolve();
this.sink_.cancel(error);
- return new Promise(function(resolve) {
+ this.cancelPromise_ = new Promise(function(resolve) {
this.pendingCancel_ = resolve;
}.bind(this));
+ return this.cancelPromise_;
raymes 2014/09/18 03:16:06 so it's safe to have multiple things call .then()
Sam McNally 2014/09/19 04:58:47 Yes!
};
/**
@@ -337,6 +399,7 @@ define('data_sender', [
*/
DataSender.prototype.callCancelCallback_ = function() {
if (this.pendingCancel_) {
+ this.cancelPromise_ = null;
this.pendingCancel_();
this.pendingCancel_ = null;
}

Powered by Google App Engine
This is Rietveld 408576698