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

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: Removing silliness. Created 9 years, 5 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..8c3e9b25ec47c07d8de58a2fbdfead863c0c2935
--- /dev/null
+++ b/chrome/browser/resources/media_internals/item_store.js
@@ -0,0 +1,70 @@
+// 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.
+
+cr.define('media', function() {
+
+ /**
+ * This class stores hashes by their id field and provides basic methods for
+ * iterating over the collection.
+ * @constructor
+ */
+ function ItemStore() {
+ this.items_ = {};
+ };
+
+ ItemStore.prototype = {
+ /**
+ * Get a sorted list of item ids.
+ * @return {Array} A sorted array of ids.
+ */
+ ids: function() {
+ var ids = [];
+ for (var i in this.items_)
+ ids.push(i);
+ return ids.sort();
+ },
+
+ /**
+ * Add an item to the store.
+ * @param {Object} item The item to be added.
+ * @param {string} item.id The id of the item.
+ */
+ addItem: function(item) {
+ this.items_[item.id] = item;
+ },
+
+ /**
+ * Add a dictionary of items to the store.
+ * @param {Object} items A dictionary of individual items. The keys are
+ * irrelevant but each must have an id field.
+ */
+ addItems: function(items) {
+ for (id in items)
+ this.addItem(items[id]);
+ },
+
+ /**
+ * Remove an item from the store.
+ * @param {string} id The id of the item to be removed.
+ */
+ removeItem: function(id) {
+ delete this.items_[id];
+ },
+
+ /**
+ * Map this itemStore to an Array. Items are sorted by id.
+ * @param {function(*)} mapper The mapping function applied to each item.
+ * @return {Array} An array of mapped items.
+ */
+ map: function(mapper) {
+ var items = this.items_;
+ var ids = this.ids();
+ return ids.map(function(id) { return mapper(items[id]); });
+ }
+ };
+
+ return {
+ ItemStore: ItemStore
+ };
+});
« no previous file with comments | « chrome/browser/resources/media_internals.html ('k') | chrome/browser/resources/media_internals/media_internals.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698