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

Side by Side Diff: media/test/data/eme_player_js/utils.js

Issue 614423002: Retry license request on timeouts and errors (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change log messages Created 6 years, 2 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 | « no previous file | 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 // Utils provide logging functions and other JS functions commonly used by the 5 // Utils provide logging functions and other JS functions commonly used by the
6 // app and media players. 6 // app and media players.
7 var Utils = new function() { 7 var Utils = new function() {
8 this.titleChanged = false; 8 this.titleChanged = false;
9 }; 9 };
10 10
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 }; 207 };
208 208
209 Utils.resetTitleChange = function() { 209 Utils.resetTitleChange = function() {
210 this.titleChanged = false; 210 this.titleChanged = false;
211 document.title = ''; 211 document.title = '';
212 }; 212 };
213 213
214 Utils.sendRequest = function(requestType, responseType, message, serverURL, 214 Utils.sendRequest = function(requestType, responseType, message, serverURL,
215 onSuccessCallbackFn, forceInvalidResponse) { 215 onSuccessCallbackFn, forceInvalidResponse) {
216 var requestAttemptCount = 0; 216 var requestAttemptCount = 0;
217 var MAXIMUM_REQUEST_ATTEMPTS = 3; 217 var MAXIMUM_REQUEST_ATTEMPTS = 3;
ddorwin 2014/10/01 21:00:29 If we're seeing this sometimes requiring 3 locally
jrummell 2014/10/01 21:28:34 Removed this so we try until the framework decides
218 var REQUEST_RETRY_DELAY_MS = 3000; 218 var REQUEST_RETRY_DELAY_MS = 3000;
219 var REQUEST_TIMEOUT_MS = 1000;
219 220
220 function sendRequestAttempt() { 221 function sendRequestAttempt() {
221 requestAttemptCount++; 222 requestAttemptCount++;
222 if (requestAttemptCount == MAXIMUM_REQUEST_ATTEMPTS) { 223 if (requestAttemptCount > MAXIMUM_REQUEST_ATTEMPTS) {
223 Utils.failTest('FAILED: Exceeded maximum license request attempts.'); 224 Utils.failTest('FAILED: Exceeded maximum license request attempts.');
224 return; 225 return;
225 } 226 }
226 var xmlhttp = new XMLHttpRequest(); 227 var xmlhttp = new XMLHttpRequest();
227 xmlhttp.responseType = responseType; 228 xmlhttp.responseType = responseType;
228 xmlhttp.open(requestType, serverURL, true); 229 xmlhttp.open(requestType, serverURL, true);
229 xmlhttp.onerror = function(e) { 230 xmlhttp.onerror = function(e) {
230 Utils.timeLog('Request status: ' + this.statusText); 231 Utils.timeLog('Request status: ' + this.statusText);
231 Utils.failTest('FAILED: License request XHR failed with network error.'); 232 Utils.timeLog('FAILED: License request XHR failed with network error.');
233 Utils.timeLog('Retrying request if possible in ' +
234 REQUEST_RETRY_DELAY_MS + 'ms');
235 setTimeout(sendRequestAttempt, REQUEST_RETRY_DELAY_MS);
ddorwin 2014/10/01 21:00:28 Why do we wait? Is there an advantage to fewer ret
jrummell 2014/10/01 21:28:34 In this case the license server isn't up, so we mi
232 }; 236 };
233 xmlhttp.onload = function(e) { 237 xmlhttp.onload = function(e) {
234 if (this.status == 200) { 238 if (this.status == 200) {
235 if (onSuccessCallbackFn) 239 if (onSuccessCallbackFn)
236 onSuccessCallbackFn(this.response); 240 onSuccessCallbackFn(this.response);
237 } else { 241 } else {
238 Utils.timeLog('Bad response status: ' + this.status); 242 Utils.timeLog('Bad response status: ' + this.status);
239 Utils.timeLog('Bad response: ' + this.response); 243 Utils.timeLog('Bad response: ' + this.response);
240 Utils.timeLog('Retrying request if possible in ' + 244 Utils.timeLog('Retrying request if possible in ' +
241 REQUEST_RETRY_DELAY_MS + 'ms'); 245 REQUEST_RETRY_DELAY_MS + 'ms');
242 setTimeout(sendRequestAttempt, REQUEST_RETRY_DELAY_MS); 246 setTimeout(sendRequestAttempt, REQUEST_RETRY_DELAY_MS);
243 } 247 }
244 }; 248 };
249 xmlhttp.timeout = REQUEST_TIMEOUT_MS;
250 xmlhttp.ontimeout = function(e) {
251 Utils.timeLog('Request timeout');
252 Utils.timeLog('Retrying request if possible in ' +
253 REQUEST_RETRY_DELAY_MS + 'ms');
254 setTimeout(sendRequestAttempt, REQUEST_RETRY_DELAY_MS);
255 }
245 Utils.timeLog('Attempt (' + requestAttemptCount + 256 Utils.timeLog('Attempt (' + requestAttemptCount +
246 '): sending request to server: ' + serverURL); 257 '): sending request to server: ' + serverURL);
247 xmlhttp.send(message); 258 xmlhttp.send(message);
248 } 259 }
249 260
250 if (forceInvalidResponse) { 261 if (forceInvalidResponse) {
251 Utils.timeLog('Not sending request - forcing an invalid response.'); 262 Utils.timeLog('Not sending request - forcing an invalid response.');
252 return onSuccessCallbackFn([0xAA]); 263 return onSuccessCallbackFn([0xAA]);
253 } 264 }
254 sendRequestAttempt(); 265 sendRequestAttempt();
(...skipping 15 matching lines...) Expand all
270 var time = Utils.getCurrentTimeString(); 281 var time = Utils.getCurrentTimeString();
271 // Log to document. 282 // Log to document.
272 Utils.documentLog(arguments[0], time); 283 Utils.documentLog(arguments[0], time);
273 // Log to JS console. 284 // Log to JS console.
274 var logString = time + ' - '; 285 var logString = time + ' - ';
275 for (var i = 0; i < arguments.length; i++) { 286 for (var i = 0; i < arguments.length; i++) {
276 logString += ' ' + arguments[i]; 287 logString += ' ' + arguments[i];
277 } 288 }
278 console.log(logString); 289 console.log(logString);
279 }; 290 };
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698