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

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

Issue 2832303002: Fifo order should be preserved for messages on associated interfaces. (Closed)
Patch Set: If target endpoint closed, discard cache message and connector resume processing incoming messages. 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 401a22278958e0736eb7375bf6f458b7fd0c7d19..0634cdeeaea5d27b2ac21cd4334bdd5caababca2 100644
--- a/mojo/public/js/router.js
+++ b/mojo/public/js/router.js
@@ -72,6 +72,9 @@ define("mojo/public/js/router", [
});
this.setInterfaceIdNamespaceBit_ = setInterfaceIdNamespaceBit;
+ // |cachedMessageData| caches infomation about a message, so it can be
+ // processed later if a client is not yet attached to the target endpoint.
+ this.cachedMessageData = null;
this.controlMessageHandler_ = new PipeControlMessageHandler(this);
this.controlMessageProxy_ = new PipeControlMessageProxy(this.connector_);
this.nextInterfaceIdValue_ = 1;
@@ -132,6 +135,30 @@ define("mojo/public/js/router", [
endpoint.client.notifyError.bind(endpoint.client));
}
+ if (this.cachedMessageData && interfaceEndpointHandle.id() ===
+ this.cachedMessageData.message.getInterfaceId()) {
+ timer.createOneShot(0, (function() {
+ if (!this.cachedMessageData) {
+ return;
+ }
+
+ var targetEndpoint = this.endpoints_.get(
+ this.cachedMessageData.message.getInterfaceId());
+ // Check that the target endpoint's client still exists.
+ if (targetEndpoint && targetEndpoint.client) {
+ var ok = endpoint.client.handleIncomingMessage(
+ this.cachedMessageData.message,
yzshen1 2017/04/26 16:40:00 nit: please move the contents of cachedMessageData
wangjimmy 2017/04/26 17:54:07 Done.
+ this.cachedMessageData.messageValidator);
+
+ if (!ok) {
+ this.handleInvalidIncomingMessage_();
+ }
+ this.cachedMessageData = null;
+ this.connector_.resumeIncomingMethodCallProcessing();
+ }
+ }).bind(this));
+ }
+
return endpoint;
};
@@ -199,9 +226,10 @@ define("mojo/public/js/router", [
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;
+ this.cachedMessageData = {message: message,
+ messageValidator: messageValidator};
+ this.connector_.pauseIncomingMethodCallProcessing();
+ return true;
}
ok = endpoint.client.handleIncomingMessage(message, messageValidator);
}
@@ -290,6 +318,14 @@ define("mojo/public/js/router", [
if (!types.isMasterInterfaceId(interfaceId) || reason) {
this.controlMessageProxy_.notifyPeerEndpointClosed(interfaceId, reason);
}
+
+ if (this.cachedMessageData && interfaceId ===
+ this.cachedMessageData.message.getInterfaceId()) {
+ timer.createOneShot(0, (function() {
yzshen1 2017/04/26 16:40:00 no need to use timer: resumeIncomingMethodCallProc
wangjimmy 2017/04/26 17:54:07 Done.
+ this.cachedMessageData = null;
+ this.connector_.resumeIncomingMethodCallProcessing();
+ }).bind(this));
+ }
};
Router.prototype.updateEndpointStateMayRemove = function(endpoint,

Powered by Google App Engine
This is Rietveld 408576698