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

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

Issue 2842073003: Handle error in connector and close handle and swap with dummy handle. (Closed)
Patch Set: Formatting. Add early return in HandleError if |this.handle_| is null. 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
« no previous file with comments | « mojo/public/js/connector.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 this.cachedMessageData.message.getInterfaceId()); 146 this.cachedMessageData.message.getInterfaceId());
147 // Check that the target endpoint's client still exists. 147 // Check that the target endpoint's client still exists.
148 if (targetEndpoint && targetEndpoint.client) { 148 if (targetEndpoint && targetEndpoint.client) {
149 var message = this.cachedMessageData.message; 149 var message = this.cachedMessageData.message;
150 var messageValidator = this.cachedMessageData.messageValidator; 150 var messageValidator = this.cachedMessageData.messageValidator;
151 this.cachedMessageData = null; 151 this.cachedMessageData = null;
152 this.connector_.resumeIncomingMethodCallProcessing(); 152 this.connector_.resumeIncomingMethodCallProcessing();
153 var ok = endpoint.client.handleIncomingMessage(message, 153 var ok = endpoint.client.handleIncomingMessage(message,
154 messageValidator); 154 messageValidator);
155 155
156 if (!ok) { 156 // Handle invalid cached incoming message.
157 this.handleInvalidIncomingMessage_(); 157 if (!validator.isTestingMode() && !ok) {
158 this.connector_.handleError(true, true);
158 } 159 }
159 } 160 }
160 }).bind(this)); 161 }).bind(this));
161 } 162 }
162 163
163 return endpoint; 164 return endpoint;
164 }; 165 };
165 166
166 Router.prototype.detachEndpointClient = function( 167 Router.prototype.detachEndpointClient = function(
167 interfaceEndpointHandle) { 168 interfaceEndpointHandle) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 // We need to wait until a client is attached in order to dispatch 229 // We need to wait until a client is attached in order to dispatch
229 // further messages. 230 // further messages.
230 this.cachedMessageData = {message: message, 231 this.cachedMessageData = {message: message,
231 messageValidator: messageValidator}; 232 messageValidator: messageValidator};
232 this.connector_.pauseIncomingMethodCallProcessing(); 233 this.connector_.pauseIncomingMethodCallProcessing();
233 return true; 234 return true;
234 } 235 }
235 ok = endpoint.client.handleIncomingMessage(message, messageValidator); 236 ok = endpoint.client.handleIncomingMessage(message, messageValidator);
236 } 237 }
237 } 238 }
238
239 if (!ok) {
240 this.handleInvalidIncomingMessage_();
241 }
242 return ok; 239 return ok;
243 }; 240 };
244 241
245 Router.prototype.close = function() { 242 Router.prototype.close = function() {
246 this.connector_.close(); 243 this.connector_.close();
247 // Closing the message pipe won't trigger connection error handler. 244 // Closing the message pipe won't trigger connection error handler.
248 // Explicitly call onPipeConnectionError() so that associated endpoints 245 // Explicitly call onPipeConnectionError() so that associated endpoints
249 // will get notified. 246 // will get notified.
250 this.onPipeConnectionError(); 247 this.onPipeConnectionError();
251 }; 248 };
252 249
253 Router.prototype.waitForNextMessageForTesting = function() { 250 Router.prototype.waitForNextMessageForTesting = function() {
254 this.connector_.waitForNextMessageForTesting(); 251 this.connector_.waitForNextMessageForTesting();
255 }; 252 };
256 253
257 Router.prototype.handleInvalidIncomingMessage_ = function(message) {
258 if (!validator.isTestingMode()) {
259 // TODO(yzshen): Consider notifying the embedder.
260 // TODO(yzshen): This should also trigger connection error handler.
261 // Consider making accept() return a boolean and let the connector deal
262 // with this, as the C++ code does.
263 this.close();
264 return;
265 }
266 };
267
268 Router.prototype.onPeerAssociatedEndpointClosed = function(interfaceId, 254 Router.prototype.onPeerAssociatedEndpointClosed = function(interfaceId,
269 reason) { 255 reason) {
270 check(!types.isMasterInterfaceId(interfaceId) || reason); 256 check(!types.isMasterInterfaceId(interfaceId) || reason);
271 257
272 var endpoint = this.endpoints_.get(interfaceId); 258 var endpoint = this.endpoints_.get(interfaceId);
273 if (!endpoint) { 259 if (!endpoint) {
274 endpoint = new InterfaceEndpoint(this, interfaceId); 260 endpoint = new InterfaceEndpoint(this, interfaceId);
275 this.endpoints_.set(interfaceId, endpoint); 261 this.endpoints_.set(interfaceId, endpoint);
276 } 262 }
277 263
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 } 322 }
337 if (endpoint.closed && endpoint.peerClosed) { 323 if (endpoint.closed && endpoint.peerClosed) {
338 this.endpoints_.delete(endpoint.id); 324 this.endpoints_.delete(endpoint.id);
339 } 325 }
340 }; 326 };
341 327
342 var exports = {}; 328 var exports = {};
343 exports.Router = Router; 329 exports.Router = Router;
344 return exports; 330 return exports;
345 }); 331 });
OLDNEW
« no previous file with comments | « mojo/public/js/connector.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698