Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 var targetEndpoint = this.endpoints_.get( | |
| 142 this.cachedMessageData.message.getInterfaceId()); | |
|
yzshen1
2017/04/25 19:56:58
Please check whether this.cachedMessageData is nul
wangjimmy
2017/04/26 01:08:02
Done.
| |
| 143 // Check that the target endpoint's client still exists. | |
| 144 if (targetEndpoint && targetEndpoint.client) { | |
| 145 var ok = endpoint.client.handleIncomingMessage( | |
| 146 this.cachedMessageData.message, | |
| 147 this.cachedMessageData.messageValidator); | |
| 148 | |
| 149 if (!ok) { | |
| 150 this.handleInvalidIncomingMessage_(); | |
| 151 } | |
| 152 this.cachedMessageData = null; | |
| 153 this.connector_.resumeIncomingMethodCallProcessing(); | |
| 154 } | |
| 155 }).bind(this)); | |
| 156 } | |
| 157 | |
| 135 return endpoint; | 158 return endpoint; |
| 136 }; | 159 }; |
| 137 | 160 |
| 138 Router.prototype.detachEndpointClient = function( | 161 Router.prototype.detachEndpointClient = function( |
| 139 interfaceEndpointHandle) { | 162 interfaceEndpointHandle) { |
| 140 check(types.isValidInterfaceId(interfaceEndpointHandle.id())); | 163 check(types.isValidInterfaceId(interfaceEndpointHandle.id())); |
| 141 var endpoint = this.endpoints_.get(interfaceEndpointHandle.id()); | 164 var endpoint = this.endpoints_.get(interfaceEndpointHandle.id()); |
| 142 check(endpoint); | 165 check(endpoint); |
| 143 check(endpoint.client); | 166 check(endpoint.client); |
| 144 check(!endpoint.closed); | 167 check(!endpoint.closed); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 } else { | 215 } else { |
| 193 var interfaceId = message.getInterfaceId(); | 216 var interfaceId = message.getInterfaceId(); |
| 194 var endpoint = this.endpoints_.get(interfaceId); | 217 var endpoint = this.endpoints_.get(interfaceId); |
| 195 if (!endpoint || endpoint.closed) { | 218 if (!endpoint || endpoint.closed) { |
| 196 return true; | 219 return true; |
| 197 } | 220 } |
| 198 | 221 |
| 199 if (!endpoint.client) { | 222 if (!endpoint.client) { |
| 200 // We need to wait until a client is attached in order to dispatch | 223 // We need to wait until a client is attached in order to dispatch |
| 201 // further messages. | 224 // further messages. |
| 202 // TODO(wangjimmy): Cache the message and send when the appropriate | 225 this.cachedMessageData = {message: message, |
| 203 // endpoint client is attached. | 226 messageValidator: messageValidator}; |
| 204 return false; | 227 this.connector_.pauseIncomingMethodCallProcessing(); |
| 228 return true; | |
| 205 } | 229 } |
| 206 ok = endpoint.client.handleIncomingMessage(message, messageValidator); | 230 ok = endpoint.client.handleIncomingMessage(message, messageValidator); |
| 207 } | 231 } |
| 208 } | 232 } |
| 209 | 233 |
| 210 if (!ok) { | 234 if (!ok) { |
| 211 this.handleInvalidIncomingMessage_(); | 235 this.handleInvalidIncomingMessage_(); |
| 212 } | 236 } |
| 213 return ok; | 237 return ok; |
| 214 }; | 238 }; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 268 if (endpoint.client) { | 292 if (endpoint.client) { |
| 269 timer.createOneShot(0, | 293 timer.createOneShot(0, |
| 270 endpoint.client.notifyError.bind(endpoint.client, | 294 endpoint.client.notifyError.bind(endpoint.client, |
| 271 endpoint.disconnectReason)); | 295 endpoint.disconnectReason)); |
| 272 } | 296 } |
| 273 this.updateEndpointStateMayRemove(endpoint, | 297 this.updateEndpointStateMayRemove(endpoint, |
| 274 EndpointStateUpdateType.PEER_ENDPOINT_CLOSED); | 298 EndpointStateUpdateType.PEER_ENDPOINT_CLOSED); |
| 275 } | 299 } |
| 276 }; | 300 }; |
| 277 | 301 |
| 278 Router.prototype.closeEndpointHandle = function(interfaceId, reason) { | 302 Router.prototype.closeEndpointHandle = function(interfaceId, reason) { |
|
yzshen1
2017/04/25 19:56:58
If there is a cached message for this endpoint. We
wangjimmy
2017/04/26 01:08:02
Done.
| |
| 279 if (!types.isValidInterfaceId(interfaceId)) { | 303 if (!types.isValidInterfaceId(interfaceId)) { |
| 280 return; | 304 return; |
| 281 } | 305 } |
| 282 var endpoint = this.endpoints_.get(interfaceId); | 306 var endpoint = this.endpoints_.get(interfaceId); |
| 283 check(endpoint); | 307 check(endpoint); |
| 284 check(!endpoint.client); | 308 check(!endpoint.client); |
| 285 check(!endpoint.closed); | 309 check(!endpoint.closed); |
| 286 | 310 |
| 287 this.updateEndpointStateMayRemove(endpoint, | 311 this.updateEndpointStateMayRemove(endpoint, |
| 288 EndpointStateUpdateType.ENDPOINT_CLOSED); | 312 EndpointStateUpdateType.ENDPOINT_CLOSED); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 301 } | 325 } |
| 302 if (endpoint.closed && endpoint.peerClosed) { | 326 if (endpoint.closed && endpoint.peerClosed) { |
| 303 this.endpoints_.delete(endpoint.id); | 327 this.endpoints_.delete(endpoint.id); |
| 304 } | 328 } |
| 305 }; | 329 }; |
| 306 | 330 |
| 307 var exports = {}; | 331 var exports = {}; |
| 308 exports.Router = Router; | 332 exports.Router = Router; |
| 309 return exports; | 333 return exports; |
| 310 }); | 334 }); |
| OLD | NEW |