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

Side by Side 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, 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() {
141 if (!this.cachedMessageData) {
142 return;
143 }
144
145 var targetEndpoint = this.endpoints_.get(
146 this.cachedMessageData.message.getInterfaceId());
147 // Check that the target endpoint's client still exists.
148 if (targetEndpoint && targetEndpoint.client) {
149 var ok = endpoint.client.handleIncomingMessage(
150 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.
151 this.cachedMessageData.messageValidator);
152
153 if (!ok) {
154 this.handleInvalidIncomingMessage_();
155 }
156 this.cachedMessageData = null;
157 this.connector_.resumeIncomingMethodCallProcessing();
158 }
159 }).bind(this));
160 }
161
135 return endpoint; 162 return endpoint;
136 }; 163 };
137 164
138 Router.prototype.detachEndpointClient = function( 165 Router.prototype.detachEndpointClient = function(
139 interfaceEndpointHandle) { 166 interfaceEndpointHandle) {
140 check(types.isValidInterfaceId(interfaceEndpointHandle.id())); 167 check(types.isValidInterfaceId(interfaceEndpointHandle.id()));
141 var endpoint = this.endpoints_.get(interfaceEndpointHandle.id()); 168 var endpoint = this.endpoints_.get(interfaceEndpointHandle.id());
142 check(endpoint); 169 check(endpoint);
143 check(endpoint.client); 170 check(endpoint.client);
144 check(!endpoint.closed); 171 check(!endpoint.closed);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 } else { 219 } else {
193 var interfaceId = message.getInterfaceId(); 220 var interfaceId = message.getInterfaceId();
194 var endpoint = this.endpoints_.get(interfaceId); 221 var endpoint = this.endpoints_.get(interfaceId);
195 if (!endpoint || endpoint.closed) { 222 if (!endpoint || endpoint.closed) {
196 return true; 223 return true;
197 } 224 }
198 225
199 if (!endpoint.client) { 226 if (!endpoint.client) {
200 // We need to wait until a client is attached in order to dispatch 227 // We need to wait until a client is attached in order to dispatch
201 // further messages. 228 // further messages.
202 // TODO(wangjimmy): Cache the message and send when the appropriate 229 this.cachedMessageData = {message: message,
203 // endpoint client is attached. 230 messageValidator: messageValidator};
204 return false; 231 this.connector_.pauseIncomingMethodCallProcessing();
232 return true;
205 } 233 }
206 ok = endpoint.client.handleIncomingMessage(message, messageValidator); 234 ok = endpoint.client.handleIncomingMessage(message, messageValidator);
207 } 235 }
208 } 236 }
209 237
210 if (!ok) { 238 if (!ok) {
211 this.handleInvalidIncomingMessage_(); 239 this.handleInvalidIncomingMessage_();
212 } 240 }
213 return ok; 241 return ok;
214 }; 242 };
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 check(endpoint); 311 check(endpoint);
284 check(!endpoint.client); 312 check(!endpoint.client);
285 check(!endpoint.closed); 313 check(!endpoint.closed);
286 314
287 this.updateEndpointStateMayRemove(endpoint, 315 this.updateEndpointStateMayRemove(endpoint,
288 EndpointStateUpdateType.ENDPOINT_CLOSED); 316 EndpointStateUpdateType.ENDPOINT_CLOSED);
289 317
290 if (!types.isMasterInterfaceId(interfaceId) || reason) { 318 if (!types.isMasterInterfaceId(interfaceId) || reason) {
291 this.controlMessageProxy_.notifyPeerEndpointClosed(interfaceId, reason); 319 this.controlMessageProxy_.notifyPeerEndpointClosed(interfaceId, reason);
292 } 320 }
321
322 if (this.cachedMessageData && interfaceId ===
323 this.cachedMessageData.message.getInterfaceId()) {
324 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.
325 this.cachedMessageData = null;
326 this.connector_.resumeIncomingMethodCallProcessing();
327 }).bind(this));
328 }
293 }; 329 };
294 330
295 Router.prototype.updateEndpointStateMayRemove = function(endpoint, 331 Router.prototype.updateEndpointStateMayRemove = function(endpoint,
296 endpointStateUpdateType) { 332 endpointStateUpdateType) {
297 if (endpointStateUpdateType === EndpointStateUpdateType.ENDPOINT_CLOSED) { 333 if (endpointStateUpdateType === EndpointStateUpdateType.ENDPOINT_CLOSED) {
298 endpoint.closed = true; 334 endpoint.closed = true;
299 } else { 335 } else {
300 endpoint.peerClosed = true; 336 endpoint.peerClosed = true;
301 } 337 }
302 if (endpoint.closed && endpoint.peerClosed) { 338 if (endpoint.closed && endpoint.peerClosed) {
303 this.endpoints_.delete(endpoint.id); 339 this.endpoints_.delete(endpoint.id);
304 } 340 }
305 }; 341 };
306 342
307 var exports = {}; 343 var exports = {};
308 exports.Router = Router; 344 exports.Router = Router;
309 return exports; 345 return exports;
310 }); 346 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698