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

Side by Side Diff: mojo/public/js/lib/interface_endpoint_client.js

Issue 2840333002: Add encounteredError() to AssociatedInterfacePtrController. (Closed)
Patch Set: 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/associated_bindings.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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/lib/interface_endpoint_client", [ 5 define("mojo/public/js/lib/interface_endpoint_client", [
6 "console", 6 "console",
7 "mojo/public/js/codec", 7 "mojo/public/js/codec",
8 "mojo/public/js/lib/control_message_handler", 8 "mojo/public/js/lib/control_message_handler",
9 "mojo/public/js/lib/control_message_proxy", 9 "mojo/public/js/lib/control_message_proxy",
10 "mojo/public/js/lib/interface_endpoint_handle", 10 "mojo/public/js/lib/interface_endpoint_handle",
11 "mojo/public/js/validator", 11 "mojo/public/js/validator",
12 "timer", 12 "timer",
13 ], function(console, 13 ], function(console,
14 codec, 14 codec,
15 controlMessageHandler, 15 controlMessageHandler,
16 controlMessageProxy, 16 controlMessageProxy,
17 interfaceEndpointHandle, 17 interfaceEndpointHandle,
18 validator, 18 validator,
19 timer) { 19 timer) {
20 20
21 var ControlMessageHandler = controlMessageHandler.ControlMessageHandler; 21 var ControlMessageHandler = controlMessageHandler.ControlMessageHandler;
22 var ControlMessageProxy = controlMessageProxy.ControlMessageProxy; 22 var ControlMessageProxy = controlMessageProxy.ControlMessageProxy;
23 var MessageReader = codec.MessageReader; 23 var MessageReader = codec.MessageReader;
24 var InterfaceEndpointHandle = interfaceEndpointHandle.InterfaceEndpointHandle; 24 var InterfaceEndpointHandle = interfaceEndpointHandle.InterfaceEndpointHandle;
25 var AssociationEvent = interfaceEndpointHandle.AssociationEvent; 25 var AssociationEvent = interfaceEndpointHandle.AssociationEvent;
26 26
27 function InterfaceEndpointClient(interfaceEndpointHandle, receiver, 27 function InterfaceEndpointClient(interfaceEndpointHandle, receiver,
28 interfaceVersion) { 28 interfaceVersion) {
29 this.controller_ = null; 29 this.controller_ = null;
30 this.encounteredError_ = false; 30 this.encounteredError = false;
Ken Rockot(use gerrit already) 2017/04/27 15:03:27 I would prefer that we keep this value "private".
31 this.handle_ = interfaceEndpointHandle; 31 this.handle_ = interfaceEndpointHandle;
32 this.incomingReceiver_ = receiver; 32 this.incomingReceiver_ = receiver;
33 33
34 if (interfaceVersion !== undefined) { 34 if (interfaceVersion !== undefined) {
35 this.controlMessageHandler_ = new ControlMessageHandler( 35 this.controlMessageHandler_ = new ControlMessageHandler(
36 interfaceVersion); 36 interfaceVersion);
37 } else { 37 } else {
38 this.controlMessageProxy_ = new ControlMessageProxy(this); 38 this.controlMessageProxy_ = new ControlMessageProxy(this);
39 } 39 }
40 40
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 var handle = this.passHandle(); 92 var handle = this.passHandle();
93 handle.reset(reason); 93 handle.reset(reason);
94 }; 94 };
95 95
96 InterfaceEndpointClient.prototype.accept = function(message) { 96 InterfaceEndpointClient.prototype.accept = function(message) {
97 if (message.associatedEndpointHandles.length > 0) { 97 if (message.associatedEndpointHandles.length > 0) {
98 message.serializeAssociatedEndpointHandles( 98 message.serializeAssociatedEndpointHandles(
99 this.handle_.groupController()); 99 this.handle_.groupController());
100 } 100 }
101 101
102 if (this.encounteredError_) { 102 if (this.encounteredError) {
103 return false; 103 return false;
104 } 104 }
105 105
106 this.initControllerIfNecessary_(); 106 this.initControllerIfNecessary_();
107 return this.controller_.sendMessage(message); 107 return this.controller_.sendMessage(message);
108 }; 108 };
109 109
110 InterfaceEndpointClient.prototype.acceptAndExpectResponse = function( 110 InterfaceEndpointClient.prototype.acceptAndExpectResponse = function(
111 message) { 111 message) {
112 if (message.associatedEndpointHandles.length > 0) { 112 if (message.associatedEndpointHandles.length > 0) {
113 message.serializeAssociatedEndpointHandles( 113 message.serializeAssociatedEndpointHandles(
114 this.handle_.groupController()); 114 this.handle_.groupController());
115 } 115 }
116 116
117 if (this.encounteredError_) { 117 if (this.encounteredError) {
118 return Promise.reject(); 118 return Promise.reject();
119 } 119 }
120 120
121 this.initControllerIfNecessary_(); 121 this.initControllerIfNecessary_();
122 122
123 // Reserve 0 in case we want it to convey special meaning in the future. 123 // Reserve 0 in case we want it to convey special meaning in the future.
124 var requestID = this.nextRequestID_++; 124 var requestID = this.nextRequestID_++;
125 if (requestID === 0) 125 if (requestID === 0)
126 requestID = this.nextRequestID_++; 126 requestID = this.nextRequestID_++;
127 127
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 return false; 166 return false;
167 } 167 }
168 }; 168 };
169 169
170 InterfaceEndpointClient.prototype.handleValidIncomingMessage_ = function( 170 InterfaceEndpointClient.prototype.handleValidIncomingMessage_ = function(
171 message) { 171 message) {
172 if (validator.isTestingMode()) { 172 if (validator.isTestingMode()) {
173 return true; 173 return true;
174 } 174 }
175 175
176 if (this.encounteredError_) { 176 if (this.encounteredError) {
177 return false; 177 return false;
178 } 178 }
179 179
180 var ok = false; 180 var ok = false;
181 181
182 if (message.expectsResponse()) { 182 if (message.expectsResponse()) {
183 if (controlMessageHandler.isControlMessage(message) && 183 if (controlMessageHandler.isControlMessage(message) &&
184 this.controlMessageHandler_) { 184 this.controlMessageHandler_) {
185 ok = this.controlMessageHandler_.acceptWithResponder(message, this); 185 ok = this.controlMessageHandler_.acceptWithResponder(message, this);
186 } else if (this.incomingReceiver_) { 186 } else if (this.incomingReceiver_) {
(...skipping 15 matching lines...) Expand all
202 this.controlMessageHandler_) { 202 this.controlMessageHandler_) {
203 ok = this.controlMessageHandler_.accept(message); 203 ok = this.controlMessageHandler_.accept(message);
204 } else if (this.incomingReceiver_) { 204 } else if (this.incomingReceiver_) {
205 ok = this.incomingReceiver_.accept(message); 205 ok = this.incomingReceiver_.accept(message);
206 } 206 }
207 } 207 }
208 return ok; 208 return ok;
209 }; 209 };
210 210
211 InterfaceEndpointClient.prototype.notifyError = function(reason) { 211 InterfaceEndpointClient.prototype.notifyError = function(reason) {
212 if (this.encounteredError_) { 212 if (this.encounteredError) {
213 return; 213 return;
214 } 214 }
215 this.encounteredError_ = true; 215 this.encounteredError = true;
216 216
217 this.completers_.forEach(function(value) { 217 this.completers_.forEach(function(value) {
218 value.reject(); 218 value.reject();
219 }); 219 });
220 this.completers_.clear(); // Drop any responders. 220 this.completers_.clear(); // Drop any responders.
221 221
222 if (this.connectionErrorHandler_) { 222 if (this.connectionErrorHandler_) {
223 this.connectionErrorHandler_(reason); 223 this.connectionErrorHandler_(reason);
224 } 224 }
225 }; 225 };
226 226
227 InterfaceEndpointClient.prototype.queryVersion = function() { 227 InterfaceEndpointClient.prototype.queryVersion = function() {
228 return this.controlMessageProxy_.queryVersion(); 228 return this.controlMessageProxy_.queryVersion();
229 }; 229 };
230 230
231 InterfaceEndpointClient.prototype.requireVersion = function(version) { 231 InterfaceEndpointClient.prototype.requireVersion = function(version) {
232 this.controlMessageProxy_.requireVersion(version); 232 this.controlMessageProxy_.requireVersion(version);
233 }; 233 };
234 234
235 var exports = {}; 235 var exports = {};
236 exports.InterfaceEndpointClient = InterfaceEndpointClient; 236 exports.InterfaceEndpointClient = InterfaceEndpointClient;
237 237
238 return exports; 238 return exports;
239 }); 239 });
OLDNEW
« no previous file with comments | « mojo/public/js/associated_bindings.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698