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 this.cachedMessageData = null; | |
|
yzshen1
2017/04/24 17:30:46
nit: Please consider commenting on the meaning of
wangjimmy
2017/04/24 19:03:35
Done.
| |
| 75 this.controlMessageHandler_ = new PipeControlMessageHandler(this); | 76 this.controlMessageHandler_ = new PipeControlMessageHandler(this); |
| 76 this.controlMessageProxy_ = new PipeControlMessageProxy(this.connector_); | 77 this.controlMessageProxy_ = new PipeControlMessageProxy(this.connector_); |
| 77 this.nextInterfaceIdValue_ = 1; | 78 this.nextInterfaceIdValue_ = 1; |
| 78 this.encounteredError_ = false; | 79 this.encounteredError_ = false; |
| 79 this.endpoints_ = new Map(); | 80 this.endpoints_ = new Map(); |
| 80 } | 81 } |
| 81 | 82 |
| 82 Router.prototype.associateInterface = function(handleToSend) { | 83 Router.prototype.associateInterface = function(handleToSend) { |
| 83 if (!handleToSend.pendingAssociation()) { | 84 if (!handleToSend.pendingAssociation()) { |
| 84 return types.kInvalidInterfaceId; | 85 return types.kInvalidInterfaceId; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 125 check(endpoint); | 126 check(endpoint); |
| 126 check(!endpoint.client); | 127 check(!endpoint.client); |
| 127 check(!endpoint.closed); | 128 check(!endpoint.closed); |
| 128 endpoint.client = interfaceEndpointClient; | 129 endpoint.client = interfaceEndpointClient; |
| 129 | 130 |
| 130 if (endpoint.peerClosed) { | 131 if (endpoint.peerClosed) { |
| 131 timer.createOneShot(0, | 132 timer.createOneShot(0, |
| 132 endpoint.client.notifyError.bind(endpoint.client)); | 133 endpoint.client.notifyError.bind(endpoint.client)); |
| 133 } | 134 } |
| 134 | 135 |
| 136 if (this.cachedMessageData && interfaceEndpointHandle.id() === | |
| 137 this.cachedMessageData.message.getInterfaceId()) { | |
| 138 var ok = interfaceEndpointClient.handleIncomingMessage( | |
|
yzshen1
2017/04/24 17:30:45
We are not supposed to call it synchronously. Beca
wangjimmy
2017/04/24 19:03:35
Done.
| |
| 139 this.cachedMessageData.message, | |
| 140 this.cachedMessageData.messageValidator); | |
| 141 | |
| 142 if (!ok) { | |
| 143 this.handleInvalidIncomingMessage_(); | |
| 144 } | |
| 145 this.connector_.resumeIncomingMethodCallProcessing(); | |
| 146 } | |
| 147 | |
| 135 return endpoint; | 148 return endpoint; |
| 136 }; | 149 }; |
| 137 | 150 |
| 138 Router.prototype.detachEndpointClient = function( | 151 Router.prototype.detachEndpointClient = function( |
| 139 interfaceEndpointHandle) { | 152 interfaceEndpointHandle) { |
| 140 check(types.isValidInterfaceId(interfaceEndpointHandle.id())); | 153 check(types.isValidInterfaceId(interfaceEndpointHandle.id())); |
| 141 var endpoint = this.endpoints_.get(interfaceEndpointHandle.id()); | 154 var endpoint = this.endpoints_.get(interfaceEndpointHandle.id()); |
| 142 check(endpoint); | 155 check(endpoint); |
| 143 check(endpoint.client); | 156 check(endpoint.client); |
| 144 check(!endpoint.closed); | 157 check(!endpoint.closed); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 } else { | 205 } else { |
| 193 var interfaceId = message.getInterfaceId(); | 206 var interfaceId = message.getInterfaceId(); |
| 194 var endpoint = this.endpoints_.get(interfaceId); | 207 var endpoint = this.endpoints_.get(interfaceId); |
| 195 if (!endpoint || endpoint.closed) { | 208 if (!endpoint || endpoint.closed) { |
| 196 return true; | 209 return true; |
| 197 } | 210 } |
| 198 | 211 |
| 199 if (!endpoint.client) { | 212 if (!endpoint.client) { |
| 200 // We need to wait until a client is attached in order to dispatch | 213 // We need to wait until a client is attached in order to dispatch |
| 201 // further messages. | 214 // further messages. |
| 202 // TODO(wangjimmy): Cache the message and send when the appropriate | 215 this.cachedMessageData = {message: message, |
| 203 // endpoint client is attached. | 216 messageValidator: messageValidator}; |
| 217 this.connector_.pauseIncomingMethodCallProcessing(); | |
| 204 return false; | 218 return false; |
|
yzshen1
2017/04/24 17:30:45
I think we should return "true" to mean "the messa
wangjimmy
2017/04/24 19:03:35
Done.
| |
| 205 } | 219 } |
| 206 ok = endpoint.client.handleIncomingMessage(message, messageValidator); | 220 ok = endpoint.client.handleIncomingMessage(message, messageValidator); |
| 207 } | 221 } |
| 208 } | 222 } |
| 209 | 223 |
| 210 if (!ok) { | 224 if (!ok) { |
| 211 this.handleInvalidIncomingMessage_(); | 225 this.handleInvalidIncomingMessage_(); |
| 212 } | 226 } |
| 213 return ok; | 227 return ok; |
| 214 }; | 228 }; |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 301 } | 315 } |
| 302 if (endpoint.closed && endpoint.peerClosed) { | 316 if (endpoint.closed && endpoint.peerClosed) { |
| 303 this.endpoints_.delete(endpoint.id); | 317 this.endpoints_.delete(endpoint.id); |
| 304 } | 318 } |
| 305 }; | 319 }; |
| 306 | 320 |
| 307 var exports = {}; | 321 var exports = {}; |
| 308 exports.Router = Router; | 322 exports.Router = Router; |
| 309 return exports; | 323 return exports; |
| 310 }); | 324 }); |
| OLD | NEW |