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

Unified Diff: chrome/browser/resources/media_internals/cache_entry.js

Issue 7972028: Display active media players on chrome://media-internals. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src
Patch Set: forgot some changes Created 9 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/media_internals/cache_entry.js
diff --git a/chrome/browser/resources/media_internals/cache_entry.js b/chrome/browser/resources/media_internals/cache_entry.js
index 60deab4cfe29a91628d454fd9895f01746a647e6..b9fd5ad7beeab7b1b0229476c2ceb6cb8a07cb38 100644
--- a/chrome/browser/resources/media_internals/cache_entry.js
+++ b/chrome/browser/resources/media_internals/cache_entry.js
@@ -3,12 +3,7 @@
// found in the LICENSE file.
cr.define('media', function() {
-
- /**
- * The width and height of a CacheEntry canvas in pixels.
- */
- var CANVAS_WIDTH = 500;
- var CANVAS_HEIGHT = 31;
+ 'use strict';
/**
* This class represents a file cached by net.
@@ -50,19 +45,19 @@ cr.define('media', function() {
clearControl.textContent = '(clear entry)';
controls.appendChild(clearControl);
- // The canvas upon which to draw the cached sections of a file.
- this.canvas_ = document.createElement('canvas');
- this.canvas_.width = CANVAS_WIDTH;
- this.canvas_.height = CANVAS_HEIGHT;
- summary.appendChild(this.canvas_);
-
this.details_.appendChild(summary);
+ // The canvas upon which to draw the cached sections of a file.
+ this.canvas = document.createElement('canvas');
+ this.canvas.width = media.BAR_WIDTH;
+ this.canvas.height = 2 * media.BAR_HEIGHT + 1;
+ this.details_.appendChild(this.canvas);
+
// A tabular representation of the data in the above canvas.
this.detailTable_ = document.createElement('table');
this.detailTable_.className = 'cache-table';
this.details_.appendChild(this.detailTable_);
- };
+ }
CacheEntry.prototype = {
/**
@@ -115,7 +110,7 @@ cr.define('media', function() {
},
/**
- * Redraw this.canvas_.
+ * Redraw this.canvas.
* It should consist of two horizontal bars with highlighted sections to
* represent which parts of a file have been read from (top) and written to
* (bottom) the cache.
@@ -123,19 +118,21 @@ cr.define('media', function() {
* |-----xxxxx-------|
*/
generateCanvas: function() {
- var context = this.canvas_.getContext('2d');
+ var width = this.canvas.width;
+ var height = this.canvas.height;
+ var context = this.canvas.getContext('2d');
context.textAlign = 'center';
context.textBaseline = 'middle';
context.fillStyle = '#aaa';
- context.fillRect(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT);
+ context.fillRect(0, 0, width, height);
if (this.size) {
var fileSize = this.size;
- drawRange = function(start, end, top) {
- var left = start / fileSize * CANVAS_WIDTH;
- var right = end / fileSize * CANVAS_WIDTH;
- context.fillRect(left, top, right - left, top + CANVAS_HEIGHT / 2);
+ var drawRange = function(start, end, top) {
+ var left = start / fileSize * width;
+ var right = end / fileSize * width;
+ context.fillRect(left, top, right - left, top + height / 2);
};
context.fillStyle = '#0a0';
@@ -145,26 +142,22 @@ cr.define('media', function() {
context.fillStyle = '#00a';
this.written_.map(function(start, end) {
- drawRange(start, end, CANVAS_HEIGHT / 2);
+ drawRange(start, end, height / 2);
});
// Overlay a description of each bar.
context.fillStyle = '#fff';
- context.fillText('Read from cache.', CANVAS_WIDTH / 2,
- CANVAS_HEIGHT / 4 - 0.5);
- context.fillText('Written to cache.', CANVAS_WIDTH / 2,
- CANVAS_HEIGHT * 3 / 4 + 0.5);
-
- // Add a 1px separator line.
- context.moveTo(0, CANVAS_HEIGHT / 2);
- context.lineTo(CANVAS_WIDTH, CANVAS_HEIGHT / 2);
- context.strokeStyle = '#fff';
- context.stroke();
+ context.fillText('Read from cache.', width / 2,
+ height / 4 - 0.5);
+ context.fillText('Written to cache.', width / 2,
+ height * 3 / 4 + 0.5);
+
+ media.drawLine(context, height / 2);
} else {
// We can't draw bars if we don't know how big the file is.
context.fillStyle = '#fff';
context.fillText('Unknown file size. See details below.',
- CANVAS_WIDTH / 2, CANVAS_HEIGHT / 2);
+ width / 2, height / 2);
}
},
@@ -173,12 +166,6 @@ cr.define('media', function() {
* this file.
*/
generateDetails: function() {
- function makeElement(type, content) {
- var element = document.createElement(type);
- element.textContent = content;
- return element;
- };
-
this.details_.id = this.key;
this.summaryText_.textContent = this.key || 'Unknown File';
@@ -191,8 +178,8 @@ cr.define('media', function() {
this.detailTable_.appendChild(body);
var headerRow = document.createElement('tr');
- headerRow.appendChild(makeElement('th', 'Read From Cache'));
- headerRow.appendChild(makeElement('th', 'Written To Cache'));
+ headerRow.appendChild(media.makeElement('th', 'Read From Cache'));
+ headerRow.appendChild(media.makeElement('th', 'Written To Cache'));
header.appendChild(headerRow);
var footerRow = document.createElement('tr');
@@ -212,8 +199,8 @@ cr.define('media', function() {
var length = Math.max(read.length, written.length);
for (var i = 0; i < length; i++) {
var row = document.createElement('tr');
- row.appendChild(makeElement('td', read[i] || ''));
- row.appendChild(makeElement('td', written[i] || ''));
+ row.appendChild(media.makeElement('td', read[i] || ''));
+ row.appendChild(media.makeElement('td', written[i] || ''));
body.appendChild(row);
}

Powered by Google App Engine
This is Rietveld 408576698