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

Side by Side Diff: Source/devtools/front_end/network/NetworkTimeCalculator.js

Issue 1116003002: [DevTools] Simplify getting back to default network order. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2008, 2009 Anthony Ricaud <rik@webkit.org> 3 * Copyright (C) 2008, 2009 Anthony Ricaud <rik@webkit.org>
4 * Copyright (C) 2011 Google Inc. All rights reserved. 4 * Copyright (C) 2011 Google Inc. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 9 *
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 { 48 {
49 return (this.minimum === other.minimum) && (this.maximum === other.maxim um); 49 return (this.minimum === other.minimum) && (this.maximum === other.maxim um);
50 } 50 }
51 } 51 }
52 52
53 /** 53 /**
54 * @constructor 54 * @constructor
55 * @extends {WebInspector.Object} 55 * @extends {WebInspector.Object}
56 * @implements {WebInspector.TimelineGrid.Calculator} 56 * @implements {WebInspector.TimelineGrid.Calculator}
57 */ 57 */
58 WebInspector.NetworkTimeCalculator = function(startAtZero) 58 WebInspector.NetworkTimeCalculator = function()
59 { 59 {
60 this.startAtZero = startAtZero;
61 this._boundryChangedEventThrottler = new WebInspector.Throttler(0); 60 this._boundryChangedEventThrottler = new WebInspector.Throttler(0);
62 /** @type {?WebInspector.NetworkTimeBoundary} */ 61 /** @type {?WebInspector.NetworkTimeBoundary} */
63 this._window = null; 62 this._window = null;
64 } 63 }
65 64
66 /** @enum {string} */ 65 /** @enum {string} */
67 WebInspector.NetworkTimeCalculator.Events = { 66 WebInspector.NetworkTimeCalculator.Events = {
68 BoundariesChanged: "BoundariesChanged" 67 BoundariesChanged: "BoundariesChanged"
69 } 68 }
70 69
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 }, 118 },
120 119
121 /** 120 /**
122 * @override 121 * @override
123 * @param {number} value 122 * @param {number} value
124 * @param {number=} precision 123 * @param {number=} precision
125 * @return {string} 124 * @return {string}
126 */ 125 */
127 formatTime: function(value, precision) 126 formatTime: function(value, precision)
128 { 127 {
129 return Number.secondsToString(value); 128 return Number.secondsToString(value - this.zeroTime());
130 }, 129 },
131 130
132 /** 131 /**
133 * @override 132 * @override
134 * @return {number} 133 * @return {number}
135 */ 134 */
136 minimumBoundary: function() 135 minimumBoundary: function()
137 { 136 {
138 return this._window ? this._window.minimum : this._minimumBoundary; 137 return this._window ? this._window.minimum : this._minimumBoundary;
139 }, 138 },
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 { 194 {
196 this._workingArea = clientWidth; 195 this._workingArea = clientWidth;
197 }, 196 },
198 197
199 /** 198 /**
200 * @param {!WebInspector.NetworkRequest} request 199 * @param {!WebInspector.NetworkRequest} request
201 * @return {!{start: number, middle: number, end: number}} 200 * @return {!{start: number, middle: number, end: number}}
202 */ 201 */
203 computeBarGraphPercentages: function(request) 202 computeBarGraphPercentages: function(request)
204 { 203 {
205 if (request.startTime !== -1) 204 var start = (request.startTime === -1) ? 0 : ((request.startTime - this. minimumBoundary()) / this.boundarySpan()) * 100;
206 var start = ((request.startTime - this.minimumBoundary()) / this.bou ndarySpan()) * 100; 205 var middle = (request.responseReceivedTime === -1) ? 100 :((request.resp onseReceivedTime - this.minimumBoundary()) / this.boundarySpan()) * 100;
207 else 206 var end = (request.endTime !== -1) ? 100 : ((request.endTime - this.min imumBoundary()) / this.boundarySpan()) * 100;
208 var start = 0;
209
210 if (request.responseReceivedTime !== -1)
211 var middle = ((request.responseReceivedTime - this.minimumBoundary() ) / this.boundarySpan()) * 100;
212 else
213 var middle = (this.startAtZero ? start : 100);
214
215 if (request.endTime !== -1)
216 var end = ((request.endTime - this.minimumBoundary()) / this.boundar ySpan()) * 100;
217 else
218 var end = (this.startAtZero ? middle : 100);
219
220 if (this.startAtZero) {
221 end -= start;
222 middle -= start;
223 start = 0;
224 }
225
226 return {start: start, middle: middle, end: end}; 207 return {start: start, middle: middle, end: end};
227 }, 208 },
228 209
229 /** 210 /**
230 * @param {number} eventTime 211 * @param {number} eventTime
231 * @return {number} 212 * @return {number}
232 */ 213 */
233 computePercentageFromEventTime: function(eventTime) 214 computePercentageFromEventTime: function(eventTime)
234 { 215 {
235 // This function computes a percentage in terms of the total loading tim e 216 return (eventTime === -1) ? 0 : ((eventTime - this.minimumBoundary()) / this.boundarySpan()) * 100;
236 // of a specific event. If startAtZero is set, then this is useless, and we
237 // want to return 0.
238 if (eventTime !== -1 && !this.startAtZero)
239 return ((eventTime - this.minimumBoundary()) / this.boundarySpan()) * 100;
240
241 return 0;
242 }, 217 },
243 218
244 /** 219 /**
245 * @param {number} percentage 220 * @param {number} percentage
246 * @return {number} 221 * @return {number}
247 */ 222 */
248 percentageToTime: function(percentage) 223 percentageToTime: function(percentage)
249 { 224 {
250 return percentage * this.boundarySpan() / 100 + this.minimumBoundary(); 225 return percentage * this.boundarySpan() / 100 + this.minimumBoundary();
251 }, 226 },
252 227
253 _boundaryChanged: function() 228 _boundaryChanged: function()
254 { 229 {
255 this._boundryChangedEventThrottler.schedule(this.dispatchEventToListener s.bind(this, WebInspector.NetworkTimeCalculator.Events.BoundariesChanged)); 230 this._boundryChangedEventThrottler.schedule(this.dispatchEventToListener s.bind(this, WebInspector.NetworkTimeCalculator.Events.BoundariesChanged));
256 }, 231 },
257 232
258 /** 233 /**
259 * @param {number} eventTime 234 * @param {number} eventTime
260 */ 235 */
261 updateBoundariesForEventTime: function(eventTime) 236 updateBoundariesForEventTime: function(eventTime)
262 { 237 {
263 if (eventTime === -1 || this.startAtZero) 238 if (eventTime === -1)
264 return; 239 return;
265 240
266 if (this._maximumBoundary === undefined || eventTime > this._maximumBoun dary) { 241 if (this._maximumBoundary === undefined || eventTime > this._maximumBoun dary) {
267 this._maximumBoundary = eventTime; 242 this._maximumBoundary = eventTime;
268 this._boundaryChanged(); 243 this._boundaryChanged();
269 } 244 }
270 }, 245 },
271 246
272 /** 247 /**
273 * @param {!WebInspector.NetworkRequest} request 248 * @param {!WebInspector.NetworkRequest} request
(...skipping 28 matching lines...) Expand all
302 else if (request.cached()) 277 else if (request.cached())
303 tooltip = WebInspector.NetworkTimeCalculator._fromCacheFormat.format (tooltip); 278 tooltip = WebInspector.NetworkTimeCalculator._fromCacheFormat.format (tooltip);
304 return {left: leftLabel, right: rightLabel, tooltip: tooltip}; 279 return {left: leftLabel, right: rightLabel, tooltip: tooltip};
305 }, 280 },
306 281
307 /** 282 /**
308 * @param {!WebInspector.NetworkRequest} request 283 * @param {!WebInspector.NetworkRequest} request
309 */ 284 */
310 updateBoundaries: function(request) 285 updateBoundaries: function(request)
311 { 286 {
312 var lowerBound; 287 var lowerBound = this._lowerBound(request);
313 if (this.startAtZero)
314 lowerBound = 0;
315 else
316 lowerBound = this._lowerBound(request);
317 288
318 if (lowerBound !== -1 && (typeof this._minimumBoundary === "undefined" | | lowerBound < this._minimumBoundary)) { 289 if (lowerBound !== -1 && (typeof this._minimumBoundary === "undefined" | | lowerBound < this._minimumBoundary)) {
319 this._minimumBoundary = lowerBound; 290 this._minimumBoundary = lowerBound;
320 this._boundaryChanged(); 291 this._boundaryChanged();
321 } 292 }
322 293
323 var upperBound = this._upperBound(request); 294 var upperBound = this._upperBound(request);
324 if (upperBound !== -1 && (typeof this._maximumBoundary === "undefined" | | upperBound > this._maximumBoundary)) { 295 if (upperBound !== -1 && (typeof this._maximumBoundary === "undefined" | | upperBound > this._maximumBoundary)) {
325 this._maximumBoundary = upperBound; 296 this._maximumBoundary = upperBound;
326 this._boundaryChanged(); 297 this._boundaryChanged();
327 } 298 }
328 }, 299 },
329 300
330 /** 301 /**
331 * @param {!WebInspector.NetworkRequest} request 302 * @param {!WebInspector.NetworkRequest} request
332 * @return {number} 303 * @return {number}
333 */ 304 */
334 _lowerBound: function(request) 305 _lowerBound: function(request)
335 { 306 {
336 return 0;
337 },
338
339 /**
340 * @param {!WebInspector.NetworkRequest} request
341 * @return {number}
342 */
343 _upperBound: function(request)
344 {
345 return 0;
346 },
347
348 __proto__: WebInspector.Object.prototype
349 }
350
351 /**
352 * @constructor
353 * @extends {WebInspector.NetworkTimeCalculator}
354 */
355 WebInspector.NetworkTransferTimeCalculator = function()
356 {
357 WebInspector.NetworkTimeCalculator.call(this, false);
358 }
359
360 WebInspector.NetworkTransferTimeCalculator.prototype = {
361 /**
362 * @override
363 * @param {number} value
364 * @param {number=} precision
365 * @return {string}
366 */
367 formatTime: function(value, precision)
368 {
369 return Number.secondsToString(value - this.zeroTime());
370 },
371
372 /**
373 * @override
374 * @param {!WebInspector.NetworkRequest} request
375 * @return {number}
376 */
377 _lowerBound: function(request)
378 {
379 return request.startTime; 307 return request.startTime;
380 }, 308 },
381 309
382 /** 310 /**
383 * @override
384 * @param {!WebInspector.NetworkRequest} request 311 * @param {!WebInspector.NetworkRequest} request
385 * @return {number} 312 * @return {number}
386 */ 313 */
387 _upperBound: function(request) 314 _upperBound: function(request)
388 { 315 {
389 return request.endTime; 316 return request.endTime;
390 }, 317 },
391 318
392 __proto__: WebInspector.NetworkTimeCalculator.prototype 319 __proto__: WebInspector.Object.prototype
393 } 320 }
394
395 /**
396 * @constructor
397 * @extends {WebInspector.NetworkTimeCalculator}
398 */
399 WebInspector.NetworkTransferDurationCalculator = function()
400 {
401 WebInspector.NetworkTimeCalculator.call(this, true);
402 }
403
404 WebInspector.NetworkTransferDurationCalculator.prototype = {
405 /**
406 * @override
407 * @param {number} value
408 * @param {number=} precision
409 * @return {string}
410 */
411 formatTime: function(value, precision)
412 {
413 return Number.secondsToString(value);
414 },
415
416 /**
417 * @override
418 * @param {!WebInspector.NetworkRequest} request
419 * @return {number}
420 */
421 _upperBound: function(request)
422 {
423 return request.duration;
424 },
425
426 __proto__: WebInspector.NetworkTimeCalculator.prototype
427 }
OLDNEW
« no previous file with comments | « Source/devtools/front_end/network/NetworkPanel.js ('k') | Source/devtools/front_end/network/networkLogView.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698