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

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 print hooks and inheritance. 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..6cb2bd63ab81d26fa473e24dacbfbc00682c41b4
--- /dev/null
+++ b/chrome/browser/resources/media_internals/item_store.js
@@ -0,0 +1,40 @@
+// 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.
+
Evan Stade 2011/07/11 21:31:52 namespace the stuff in this file via cr.define
Scott Franklin 2011/07/12 22:35:13 Somehow I missed that everything else in here was
+// This class stores hashes by their id field and provides basic methods for
+// iterating over the collection.
+function ItemStore() {
+ this.items_ = {};
+};
+
+// Gets a sorted list of ids.
+ItemStore.prototype.ids = function() {
Evan Stade 2011/07/11 21:31:52 ItemStore.prototype = { ids: function() { },
Scott Franklin 2011/07/12 22:35:13 Oh, handy. Done.
+ 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];
+};
+
+// Maps the itemStore to an Array. Items are sorted by id.
+ItemStore.prototype.map = function(mapper) {
Evan Stade 2011/07/11 21:31:52 jsdoc style documentation for functions and their
Scott Franklin 2011/07/12 22:35:13 Done.
+ var items = this.items_;
+ var ids = this.ids();
+ return ids.map(function(id) { return mapper(items[id]); });
+};

Powered by Google App Engine
This is Rietveld 408576698