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

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

Issue 215883004: Revert of Mojo: add javascript bindings for request/response (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 2aa9a9f23f428a67518c5d7bd317adab15a1ba29..9a1bfc7d9a8fbeb64ecf7a19abe20f01ef268a7f 100644
--- a/mojo/public/bindings/js/connector.js
+++ b/mojo/public/bindings/js/connector.js
@@ -10,12 +10,9 @@
function Connector(handle) {
this.handle_ = handle;
- this.dropWrites_ = false;
this.error_ = false;
this.incomingReceiver_ = null;
this.readWaitCookie_ = null;
-
- this.waitToReadMore_();
}
Connector.prototype.close = function() {
@@ -32,44 +29,28 @@
Connector.prototype.accept = function(message) {
if (this.error_)
return false;
+ this.write_(message);
+ return !this.error_;
+ };
- if (this.dropWrites_)
- return true;
+ Connector.prototype.setIncomingReceiver = function(receiver) {
+ this.incomingReceiver_ = receiver;
+ if (this.incomingReceiver_)
+ this.waitToReadMore_();
+ };
+ Connector.prototype.write_ = function(message) {
var result = core.writeMessage(this.handle_,
message.memory,
message.handles,
core.WRITE_MESSAGE_FLAG_NONE);
-
- 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;
+ if (result != core.RESULT_OK) {
+ this.error_ = true
+ return;
}
- return true;
+ // The handles were successfully transferred, so we don't own them anymore.
+ message.handles = [];
};
-
- 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_,
@@ -92,12 +73,25 @@
// TODO(abarth): Should core.readMessage return a Uint8Array?
var memory = new Uint8Array(read.buffer);
var message = new codec.Message(memory, read.handles);
- if (this.incomingReceiver_)
- this.incomingReceiver_.accept(message);
+ 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.Connector = Connector;
+ exports.Connection = Connection;
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