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

Unified Diff: mojo/public/js/router.js

Issue 2820783002: Add associated interfaces & bindings. (Closed)
Patch Set: Change Router.prototype.accept. Add a TODO for endpoint client not attached. Created 3 years, 8 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/js/new_bindings/lib/control_message_proxy.js ('k') | mojo/public/js/validator.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/js/router.js
diff --git a/mojo/public/js/router.js b/mojo/public/js/router.js
index 89d9a2f66b596f120c296aabb6e141c20f4a93d1..401a22278958e0736eb7375bf6f458b7fd0c7d19 100644
--- a/mojo/public/js/router.js
+++ b/mojo/public/js/router.js
@@ -74,11 +74,48 @@ define("mojo/public/js/router", [
this.setInterfaceIdNamespaceBit_ = setInterfaceIdNamespaceBit;
this.controlMessageHandler_ = new PipeControlMessageHandler(this);
this.controlMessageProxy_ = new PipeControlMessageProxy(this.connector_);
- this.nextInterfaceIdValue = 1;
+ this.nextInterfaceIdValue_ = 1;
this.encounteredError_ = false;
this.endpoints_ = new Map();
}
+ Router.prototype.associateInterface = function(handleToSend) {
+ if (!handleToSend.pendingAssociation()) {
+ return types.kInvalidInterfaceId;
+ }
+
+ var id = 0;
+ do {
+ if (this.nextInterfaceIdValue_ >= types.kInterfaceIdNamespaceMask) {
+ this.nextInterfaceIdValue_ = 1;
+ }
+ id = this.nextInterfaceIdValue_++;
+ if (this.setInterfaceIdNamespaceBit_) {
+ id += types.kInterfaceIdNamespaceMask;
+ }
+ } while (this.endpoints_.has(id));
+
+ var endpoint = new InterfaceEndpoint(this, id);
+ this.endpoints_.set(id, endpoint);
+ if (this.encounteredError_) {
+ this.updateEndpointStateMayRemove(endpoint,
+ EndpointStateUpdateType.PEER_ENDPOINT_CLOSED);
+ }
+ endpoint.handleCreated = true;
+
+ if (!handleToSend.notifyAssociation(id, this)) {
+ // The peer handle of |handleToSend|, which is supposed to join this
+ // associated group, has been closed.
+ this.updateEndpointStateMayRemove(endpoint,
+ EndpointStateUpdateType.ENDPOINT_CLOSED);
+
+ pipeControlMessageproxy.notifyPeerEndpointClosed(id,
+ handleToSend.disconnectReason());
+ }
+
+ return id;
+ };
+
Router.prototype.attachEndpointClient = function(
interfaceEndpointHandle, interfaceEndpointClient) {
check(types.isValidInterfaceId(interfaceEndpointHandle.id()));
@@ -149,21 +186,25 @@ define("mojo/public/js/router", [
var ok = false;
if (err !== validator.validationError.NONE) {
validator.reportValidationError(err);
- } else if (controlMessageHandler.isPipeControlMessage(message)) {
- ok = this.controlMessageHandler_.accept(message);
- } else {
- var interfaceId = message.getInterfaceId();
- var endpoint = this.endpoints_.get(interfaceId);
- if (!endpoint || endpoint.closed) {
- return true;
- }
-
- if (!endpoint.client) {
- // We need to wait until a client is attached in order to dispatch
- // further messages.
- return false;
+ } else if (message.deserializeAssociatedEndpointHandles(this)) {
+ if (controlMessageHandler.isPipeControlMessage(message)) {
+ ok = this.controlMessageHandler_.accept(message);
+ } else {
+ var interfaceId = message.getInterfaceId();
+ var endpoint = this.endpoints_.get(interfaceId);
+ if (!endpoint || endpoint.closed) {
+ return true;
+ }
+
+ if (!endpoint.client) {
+ // We need to wait until a client is attached in order to dispatch
+ // further messages.
+ // TODO(wangjimmy): Cache the message and send when the appropriate
+ // endpoint client is attached.
+ return false;
+ }
+ ok = endpoint.client.handleIncomingMessage(message, messageValidator);
}
- ok = endpoint.client.handleIncomingMessage_(message);
}
if (!ok) {
« no previous file with comments | « mojo/public/js/new_bindings/lib/control_message_proxy.js ('k') | mojo/public/js/validator.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698