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

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

Issue 2820783002: Add associated interfaces & bindings. (Closed)
Patch Set: Remove changes to vibration-iframe-expected.txt because it was removed in master. Created 3 years, 8 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
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.controlMessageHandler_ = new PipeControlMessageHandler(this); 75 this.controlMessageHandler_ = new PipeControlMessageHandler(this);
76 this.controlMessageProxy_ = new PipeControlMessageProxy(this.connector_); 76 this.controlMessageProxy_ = new PipeControlMessageProxy(this.connector_);
77 this.nextInterfaceIdValue = 1; 77 this.nextInterfaceIdValue_ = 1;
78 this.encounteredError_ = false; 78 this.encounteredError_ = false;
79 this.endpoints_ = new Map(); 79 this.endpoints_ = new Map();
80 } 80 }
81 81
82 Router.prototype.associateInterface = function(handleToSend) {
83 if (!handleToSend.pendingAssociation()) {
84 return types.kInvalidInterfaceId;
85 }
86
87 var id = 0;
88 do {
89 if (this.nextInterfaceIdValue_ >= types.kInterfaceIdNamespaceMask) {
90 this.nextInterfaceIdValue_ = 1;
91 }
92 id = this.nextInterfaceIdValue_++;
93 if (this.setInterfaceIdNamespaceBit_) {
94 id += types.kInterfaceIdNamespaceMask;
95 }
96 } while (this.endpoints_.has(id));
97
98 var endpoint = new InterfaceEndpoint(this, id);
99 this.endpoints_.set(id, endpoint);
100 if (this.encounteredError_) {
101 this.updateEndpointStateMayRemove(endpoint,
102 EndpointStateUpdateType.PEER_ENDPOINT_CLOSED);
103 }
104 endpoint.handleCreated = true;
105
106 if (!handleToSend.notifyAssociation(id, this)) {
107 // The peer handle of |handleToSend|, which is supposed to join this
108 // associated group, has been closed.
109 if (endpoint) {
yzshen1 2017/04/19 21:11:34 No need to check "if (endpoint)".
wangjimmy 2017/04/20 15:36:44 Done.
110 this.updateEndpointStateMayRemove(endpoint,
111 EndpointStateUpdateType.ENDPOINT_CLOSED);
112 }
113 pipeControlMessageproxy.notifyPeerEndpointClosed(id,
114 handleToSend.disconnectReason());
115 }
116
117 return id;
118 };
119
82 Router.prototype.attachEndpointClient = function( 120 Router.prototype.attachEndpointClient = function(
83 interfaceEndpointHandle, interfaceEndpointClient) { 121 interfaceEndpointHandle, interfaceEndpointClient) {
84 check(types.isValidInterfaceId(interfaceEndpointHandle.id())); 122 check(types.isValidInterfaceId(interfaceEndpointHandle.id()));
85 check(interfaceEndpointClient); 123 check(interfaceEndpointClient);
86 124
87 var endpoint = this.endpoints_.get(interfaceEndpointHandle.id()); 125 var endpoint = this.endpoints_.get(interfaceEndpointHandle.id());
88 check(endpoint); 126 check(endpoint);
89 check(!endpoint.client); 127 check(!endpoint.client);
90 check(!endpoint.closed); 128 check(!endpoint.closed);
91 endpoint.client = interfaceEndpointClient; 129 endpoint.client = interfaceEndpointClient;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 return new InterfaceEndpointHandle(interfaceId, this); 180 return new InterfaceEndpointHandle(interfaceId, this);
143 }; 181 };
144 182
145 Router.prototype.accept = function(message) { 183 Router.prototype.accept = function(message) {
146 var messageValidator = new Validator(message); 184 var messageValidator = new Validator(message);
147 var err = messageValidator.validateMessageHeader(); 185 var err = messageValidator.validateMessageHeader();
148 186
149 var ok = false; 187 var ok = false;
150 if (err !== validator.validationError.NONE) { 188 if (err !== validator.validationError.NONE) {
151 validator.reportValidationError(err); 189 validator.reportValidationError(err);
152 } else if (controlMessageHandler.isPipeControlMessage(message)) {
153 ok = this.controlMessageHandler_.accept(message);
154 } else { 190 } else {
155 var interfaceId = message.getInterfaceId(); 191 if (!message.deserializeAssociatedEndpointHandles(this)) {
156 var endpoint = this.endpoints_.get(interfaceId); 192 return false;
yzshen1 2017/04/19 21:11:34 Do we need to also run the logic of line 213 - 215
wangjimmy 2017/04/20 15:36:44 In the C++ code bool Connector::ReadSingleMessage
yzshen1 2017/04/20 18:12:13 Please note that these two "return false" means di
157 if (!endpoint || endpoint.closed) {
158 return true;
159 } 193 }
160 194
161 if (!endpoint.client) { 195 if (controlMessageHandler.isPipeControlMessage(message)) {
162 // We need to wait until a client is attached in order to dispatch 196 ok = this.controlMessageHandler_.accept(message);
163 // further messages. 197 } else {
164 return false; 198 var interfaceId = message.getInterfaceId();
199 var endpoint = this.endpoints_.get(interfaceId);
200 if (!endpoint || endpoint.closed) {
201 return true;
202 }
203
204 if (!endpoint.client) {
205 // We need to wait until a client is attached in order to dispatch
206 // further messages.
yzshen1 2017/04/19 21:11:34 In this case, you are dropping the message. Inste
yzshen1 2017/04/20 18:12:13 In case you didn't notice: this comment has not be
207 return false;
208 }
209 ok = endpoint.client.handleIncomingMessage_(message, messageValidator);
165 } 210 }
166 ok = endpoint.client.handleIncomingMessage_(message);
167 } 211 }
168 212
169 if (!ok) { 213 if (!ok) {
170 this.handleInvalidIncomingMessage_(); 214 this.handleInvalidIncomingMessage_();
171 } 215 }
172 return ok; 216 return ok;
173 }; 217 };
174 218
175 Router.prototype.close = function() { 219 Router.prototype.close = function() {
176 this.connector_.close(); 220 this.connector_.close();
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 } 304 }
261 if (endpoint.closed && endpoint.peerClosed) { 305 if (endpoint.closed && endpoint.peerClosed) {
262 this.endpoints_.delete(endpoint.id); 306 this.endpoints_.delete(endpoint.id);
263 } 307 }
264 }; 308 };
265 309
266 var exports = {}; 310 var exports = {};
267 exports.Router = Router; 311 exports.Router = Router;
268 return exports; 312 return exports;
269 }); 313 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698