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

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: 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..8aa9ad9db90355c1e7c30b5eaaad39b04c474df0 100644
--- a/extensions/renderer/resources/data_sender.js
+++ b/extensions/renderer/resources/data_sender.js
@@ -257,10 +257,50 @@ define('data_sender', [
this.sendsAwaitingAck_.pop().reportBytesSentAndError(
0, this.fatalErrorValue_);
}
- if (this.pendingCancel_) {
- this.pendingCancel_();
- this.pendingCancel_ = null;
+ this.callCancelCallback_();
+ };
+
+ DataSender.prototype.serialize = function() {
+ 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 = {
+ sink: this.router_.connector_.handle_,
+ data_pipe: this.sendPipe_,
+ fatal_error_value: this.fatalErrorValue_,
+ shut_down: this.shutDown_,
+ };
+ this.router_.connector_.handle_ = null;
+ this.router_.close();
+ this.shutDown_ = true;
+ return serialized;
+ }.bind(this));
+ };
+
+ DataSender.deserialize = function(serialized) {
+ var sender = $Object.create(DataSender.prototype);
+ sender.deserialize_(serialized);
+ return sender;
+ };
+
+ DataSender.prototype.deserialize_ = function(serialized) {
+ this.sendPipe_ = serialized.data_pipe;
+ this.fatalErrorValue_ = serialized.fatal_error_value;
+ this.shutDown_ = serialized.shut_down;
+ 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_ = [];
};
/**
@@ -301,9 +341,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_;
};
/**
@@ -337,6 +378,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