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

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

Issue 7273089: Display active audio streams on chrome://media-internals. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Restructuring. Created 9 years, 6 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/item_store.js
diff --git a/chrome/browser/resources/media_internals/item_store.js b/chrome/browser/resources/media_internals/item_store.js
new file mode 100644
index 0000000000000000000000000000000000000000..596e0c2959c624fc3dab5027171f668447fc52d9
--- /dev/null
+++ b/chrome/browser/resources/media_internals/item_store.js
@@ -0,0 +1,91 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+////////////////////////////////////////////////////////////////////////////////
+//
+// ItemStore
+//
+////////////////////////////////////////////////////////////////////////////////
+
+// This class stores hashes by their id field. It provides methods for rendering
+// them into html.
+function ItemStore() {
+ this.items_ = {};
+};
+
+// Gets a sorted list of ids.
+ItemStore.prototype.ids = function() {
+ var ids = [];
+ for (var i in this.items_)
+ ids.push(i);
+ return ids.sort();
+};
+
+// Adds an item to the store.
+ItemStore.prototype.addItem = function(item) {
+ this.items_[item.id] = item;
+};
+
+// Adds a hash of items to the store.
+ItemStore.prototype.addItems = function(items) {
+ for (id in items)
+ this.addItem(items[id]);
+};
+
+// Removes an item from the store.
+ItemStore.prototype.removeItem = function(id) {
+ delete this.items_[id];
+};
+
+// Produces an html rendering of items_[|id|].
+// Overridden for each type of item.
+ItemStore.prototype.printItem = null;
+
+// Produces an html rendering of the item store.
+// Overridden for each type of item.
+ItemStore.prototype.print = null;
+
+// Concatenates the html representations of the items together, sorted by ids
+// and separated by |separator|.
+ItemStore.prototype.joinItems = function(separator) {
+ var ids = this.ids();
+ var items = [];
+ for (var i = 0; i < ids.length; i++)
+ items[i] = this.printItem(ids[i]);
+
+ return items.join(separator);
+};
+
+////////////////////////////////////////////////////////////////////////////////
+//
+// AudioStreamStore
+//
+////////////////////////////////////////////////////////////////////////////////
+
+function AudioStreamStore() {
+ this.items_ = {};
+};
+
+// Inherit from ItemStore.
+AudioStreamStore.prototype = new ItemStore();
Scott Franklin 2011/07/02 00:57:20 I'm tempted to ditch the inheritance and do someth
scherkus (not reviewing) 2011/07/07 20:57:30 from what I've experienced/read JS + inheritance i
Scott Franklin 2011/07/09 00:33:22 Yeah, I think I'll ditch the inheritance altogethe
+
+// Prints a stream as a list item.
+AudioStreamStore.prototype.printItem = function(id) {
+ var stream = this.items_[id];
+ var out = '<li id=' + id + ' class="audio-stream-' + stream.status + '">';
+ out += 'Audio stream ' + stream.id.split('.')[1];
+ out += ' is ' + (stream.playing ? 'playing' : 'paused');
+ out += ' at ' + Math.round(stream.volume * 100) + '% volume.';
+ out += '</li>';
+ return out;
+};
+
+// Produces a ul of all audio streams.
+AudioStreamStore.prototype.print = function() {
+ var out = '<h2>Active audio streams:</h2>';
+ out += '<ul>';
+ out += this.joinItems('');
+ out += '</ul>';
+ return out;
+};

Powered by Google App Engine
This is Rietveld 408576698