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

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

Issue 2820783002: Add associated interfaces & bindings. (Closed)
Patch Set: Remove changes to vibration-iframe-expected.txt because it was removed in master. 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
Index: mojo/public/js/router.js
diff --git a/mojo/public/js/router.js b/mojo/public/js/router.js
index 89d9a2f66b596f120c296aabb6e141c20f4a93d1..b4bd85c98451f89deb2299fe833969189b6a6478 100644
--- a/mojo/public/js/router.js
+++ b/mojo/public/js/router.js
@@ -74,11 +74,49 @@ 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.
+ if (endpoint) {
yzshen1 2017/04/19 21:11:34 No need to check "if (endpoint)".
wangjimmy 2017/04/20 15:36:44 Done.
+ 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 +187,27 @@ 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 (!message.deserializeAssociatedEndpointHandles(this)) {
+ return false;
yzshen1 2017/04/19 21:11:34 Do we need to also run the logic of line 213 - 215
wangjimmy 2017/04/20 15:36:44 In the C++ code bool Connector::ReadSingleMessage
yzshen1 2017/04/20 18:12:13 Please note that these two "return false" means di
}
- if (!endpoint.client) {
- // We need to wait until a client is attached in order to dispatch
- // further messages.
- return false;
+ 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.
yzshen1 2017/04/19 21:11:34 In this case, you are dropping the message. Inste
yzshen1 2017/04/20 18:12:13 In case you didn't notice: this comment has not be
+ return false;
+ }
+ ok = endpoint.client.handleIncomingMessage_(message, messageValidator);
}
- ok = endpoint.client.handleIncomingMessage_(message);
}
if (!ok) {

Powered by Google App Engine
This is Rietveld 408576698