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

Unified Diff: mojo/public/bindings/js/connector.js

Issue 207503004: Mojo: add javascript bindings for request/response (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: --similarity=15 Created 6 years, 9 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
« no previous file with comments | « mojo/public/bindings/js/connection.js ('k') | mojo/public/bindings/js/router.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..2aa9a9f23f428a67518c5d7bd317adab15a1ba29 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,29 +32,45 @@ 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.
+ this.dropWrites_ = true;
+ 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.encounteredError = function() {
+ return this.error_;
+ }
+
Connector.prototype.waitToReadMore_ = function() {
this.readWaitCookie_ = support.asyncWait(this.handle_,
core.WAIT_FLAG_READABLE,
@@ -73,25 +92,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;
});
« no previous file with comments | « mojo/public/bindings/js/connection.js ('k') | mojo/public/bindings/js/router.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698