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

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

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

Powered by Google App Engine
This is Rietveld 408576698