Chromium Code Reviews| Index: mojo/public/bindings/js/connector.js |
| diff --git a/mojo/public/bindings/js/connector.js b/mojo/public/bindings/js/connector.js |
| index 9a1bfc7d9a8fbeb64ecf7a19abe20f01ef268a7f..ff9abf04f67d30846af5d42ec0d5db8fe730f073 100644 |
| --- a/mojo/public/bindings/js/connector.js |
| +++ b/mojo/public/bindings/js/connector.js |
| @@ -10,9 +10,12 @@ define("mojo/public/bindings/js/connector", [ |
| function Connector(handle) { |
| this.handle_ = handle; |
| + this.dropWrites_ = false; |
| this.error_ = false; |
| this.incomingReceiver_ = null; |
| this.readWaitCookie_ = null; |
| + |
| + this.waitToReadMore_(); |
| } |
| Connector.prototype.close = function() { |
| @@ -29,27 +32,39 @@ define("mojo/public/bindings/js/connector", [ |
| Connector.prototype.accept = function(message) { |
| if (this.error_) |
| return false; |
| - this.write_(message); |
| - return !this.error_; |
| - }; |
| - Connector.prototype.setIncomingReceiver = function(receiver) { |
| - this.incomingReceiver_ = receiver; |
| - if (this.incomingReceiver_) |
| - this.waitToReadMore_(); |
| - }; |
| + if (this.dropWrites_) |
| + return true; |
| - Connector.prototype.write_ = function(message) { |
| var result = core.writeMessage(this.handle_, |
| message.memory, |
| message.handles, |
| core.WRITE_MESSAGE_FLAG_NONE); |
| - if (result != core.RESULT_OK) { |
| - this.error_ = true |
| - return; |
| + |
| + switch (result) { |
| + case core.RESULT_OK: |
| + // The handles were successfully transferred, so we don't own them |
| + // anymore. |
| + message.handles = []; |
| + break; |
| + case core.RESULT_FAILED_PRECONDITION: |
| + // There's no point in continuing to write to this pipe since the other |
| + // end is gone. Avoid writing any future messages. Hide write failures |
| + // from the caller since we'd like them to continue consuming any |
| + // backlog of incoming messages before regarding the message pipe as |
| + // closed. |
| + dropWrites_ = true; |
|
abarth-chromium
2014/03/26 18:26:32
Sorry for being unclear. You need to write "this.
|
| + break; |
| + default: |
| + // This particular write was rejected, presumably because of bad input. |
| + // The pipe is not necessarily in a bad state. |
| + return false; |
| } |
| - // The handles were successfully transferred, so we don't own them anymore. |
| - message.handles = []; |
| + return true; |
| + }; |
| + |
| + Connector.prototype.setIncomingReceiver = function(receiver) { |
| + this.incomingReceiver_ = receiver; |
| }; |
| Connector.prototype.waitToReadMore_ = function() { |
| @@ -73,25 +88,12 @@ define("mojo/public/bindings/js/connector", [ |
| // TODO(abarth): Should core.readMessage return a Uint8Array? |
| var memory = new Uint8Array(read.buffer); |
| var message = new codec.Message(memory, read.handles); |
| - this.incomingReceiver_.accept(message); |
| + if (this.incomingReceiver_) |
| + this.incomingReceiver_.accept(message); |
| } |
| }; |
| - function Connection(handle, localFactory, remoteFactory) { |
| - this.connector_ = new Connector(handle); |
| - this.remote = new remoteFactory(this.connector_); |
| - this.local = new localFactory(this.remote); |
| - this.connector_.setIncomingReceiver(this.local); |
| - } |
| - |
| - Connection.prototype.close = function() { |
| - this.connector_.close(); |
| - this.connector_ = null; |
| - this.local = null; |
| - this.remote = null; |
| - }; |
| - |
| var exports = {}; |
| - exports.Connection = Connection; |
| + exports.Connector = Connector; |
| return exports; |
| }); |