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

Side by Side Diff: mojo/public/js/router.js

Issue 2832303002: Fifo order should be preserved for messages on associated interfaces. (Closed)
Patch Set: Address codereview Created 3 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 define("mojo/public/js/router", [ 5 define("mojo/public/js/router", [
6 "mojo/public/js/connector", 6 "mojo/public/js/connector",
7 "mojo/public/js/core", 7 "mojo/public/js/core",
8 "mojo/public/js/interface_types", 8 "mojo/public/js/interface_types",
9 "mojo/public/js/lib/interface_endpoint_handle", 9 "mojo/public/js/lib/interface_endpoint_handle",
10 "mojo/public/js/lib/pipe_control_message_handler", 10 "mojo/public/js/lib/pipe_control_message_handler",
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 this.connector_ = new Connector(handle); 65 this.connector_ = new Connector(handle);
66 66
67 this.connector_.setIncomingReceiver({ 67 this.connector_.setIncomingReceiver({
68 accept: this.accept.bind(this), 68 accept: this.accept.bind(this),
69 }); 69 });
70 this.connector_.setErrorHandler({ 70 this.connector_.setErrorHandler({
71 onError: this.onPipeConnectionError.bind(this), 71 onError: this.onPipeConnectionError.bind(this),
72 }); 72 });
73 73
74 this.setInterfaceIdNamespaceBit_ = setInterfaceIdNamespaceBit; 74 this.setInterfaceIdNamespaceBit_ = setInterfaceIdNamespaceBit;
75 // |cachedMessageData| caches infomation about a message, so it can be
76 // processed later if a client is not yet attached to the target endpoint.
77 this.cachedMessageData = null;
75 this.controlMessageHandler_ = new PipeControlMessageHandler(this); 78 this.controlMessageHandler_ = new PipeControlMessageHandler(this);
76 this.controlMessageProxy_ = new PipeControlMessageProxy(this.connector_); 79 this.controlMessageProxy_ = new PipeControlMessageProxy(this.connector_);
77 this.nextInterfaceIdValue_ = 1; 80 this.nextInterfaceIdValue_ = 1;
78 this.encounteredError_ = false; 81 this.encounteredError_ = false;
79 this.endpoints_ = new Map(); 82 this.endpoints_ = new Map();
80 } 83 }
81 84
82 Router.prototype.associateInterface = function(handleToSend) { 85 Router.prototype.associateInterface = function(handleToSend) {
83 if (!handleToSend.pendingAssociation()) { 86 if (!handleToSend.pendingAssociation()) {
84 return types.kInvalidInterfaceId; 87 return types.kInvalidInterfaceId;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 check(endpoint); 128 check(endpoint);
126 check(!endpoint.client); 129 check(!endpoint.client);
127 check(!endpoint.closed); 130 check(!endpoint.closed);
128 endpoint.client = interfaceEndpointClient; 131 endpoint.client = interfaceEndpointClient;
129 132
130 if (endpoint.peerClosed) { 133 if (endpoint.peerClosed) {
131 timer.createOneShot(0, 134 timer.createOneShot(0,
132 endpoint.client.notifyError.bind(endpoint.client)); 135 endpoint.client.notifyError.bind(endpoint.client));
133 } 136 }
134 137
138 if (this.cachedMessageData && interfaceEndpointHandle.id() ===
139 this.cachedMessageData.message.getInterfaceId()) {
140 timer.createOneShot(0, (function() {
wangjimmy 2017/04/24 19:04:33 TODO(wangjimmy): Check endpoint client still exist
yzshen1 2017/04/24 19:21:49 I hope this could be addressed in this CL, which s
wangjimmy 2017/04/24 21:16:39 Done.
141 var ok = interfaceEndpointClient.handleIncomingMessage(
142 this.cachedMessageData.message,
143 this.cachedMessageData.messageValidator);
144
145 if (!ok) {
146 this.handleInvalidIncomingMessage_();
147 }
148 this.cachedMessageData = null;
149 this.connector_.resumeIncomingMethodCallProcessing();
150 }).bind(this));
151 }
152
135 return endpoint; 153 return endpoint;
136 }; 154 };
137 155
138 Router.prototype.detachEndpointClient = function( 156 Router.prototype.detachEndpointClient = function(
139 interfaceEndpointHandle) { 157 interfaceEndpointHandle) {
140 check(types.isValidInterfaceId(interfaceEndpointHandle.id())); 158 check(types.isValidInterfaceId(interfaceEndpointHandle.id()));
141 var endpoint = this.endpoints_.get(interfaceEndpointHandle.id()); 159 var endpoint = this.endpoints_.get(interfaceEndpointHandle.id());
142 check(endpoint); 160 check(endpoint);
143 check(endpoint.client); 161 check(endpoint.client);
144 check(!endpoint.closed); 162 check(!endpoint.closed);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 } else { 210 } else {
193 var interfaceId = message.getInterfaceId(); 211 var interfaceId = message.getInterfaceId();
194 var endpoint = this.endpoints_.get(interfaceId); 212 var endpoint = this.endpoints_.get(interfaceId);
195 if (!endpoint || endpoint.closed) { 213 if (!endpoint || endpoint.closed) {
196 return true; 214 return true;
197 } 215 }
198 216
199 if (!endpoint.client) { 217 if (!endpoint.client) {
200 // We need to wait until a client is attached in order to dispatch 218 // We need to wait until a client is attached in order to dispatch
201 // further messages. 219 // further messages.
202 // TODO(wangjimmy): Cache the message and send when the appropriate 220 this.cachedMessageData = {message: message,
203 // endpoint client is attached. 221 messageValidator: messageValidator};
204 return false; 222 this.connector_.pauseIncomingMethodCallProcessing();
223 return true;
205 } 224 }
206 ok = endpoint.client.handleIncomingMessage(message, messageValidator); 225 ok = endpoint.client.handleIncomingMessage(message, messageValidator);
207 } 226 }
208 } 227 }
209 228
210 if (!ok) { 229 if (!ok) {
211 this.handleInvalidIncomingMessage_(); 230 this.handleInvalidIncomingMessage_();
212 } 231 }
213 return ok; 232 return ok;
214 }; 233 };
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 } 320 }
302 if (endpoint.closed && endpoint.peerClosed) { 321 if (endpoint.closed && endpoint.peerClosed) {
303 this.endpoints_.delete(endpoint.id); 322 this.endpoints_.delete(endpoint.id);
304 } 323 }
305 }; 324 };
306 325
307 var exports = {}; 326 var exports = {};
308 exports.Router = Router; 327 exports.Router = Router;
309 return exports; 328 return exports;
310 }); 329 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698