Index: content/browser/resources/media/new/player_manager.js |
diff --git a/content/browser/resources/media/new/player_manager.js b/content/browser/resources/media/new/player_manager.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0384c861c9b489e9777041b3a5c46f23785ed51f |
--- /dev/null |
+++ b/content/browser/resources/media/new/player_manager.js |
@@ -0,0 +1,103 @@ |
+// Copyright (c) 2012 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. |
+ |
+ |
+/** |
+ * @fileoverview Keeps track of all the existing |
+ * PlayerProperty objects and is the entry-point for messages from the backend. |
+ */ |
+var PlayerManager = (function () { |
+ "use strict"; |
+ |
+ function PlayerManager() { |
+ this.players = {}; |
+ this.renderman = new RenderManager(this); |
+ |
+ var removeCheckbox = document.querySelector("#removal-checkbox"); |
+ this.shouldRemovePlayer = function () { |
+ return removeCheckbox.checked; |
+ }; |
+ removeCheckbox.onclick = function () { |
+ if (removeCheckbox.checked) { |
+ goog.object.forEach(this.players, function (playerInfo, id) { |
+ if (playerInfo.toRemove) { |
+ this.removePlayer(id); |
+ } |
+ }, this); |
+ } |
+ }.bind(this); |
+ } |
+ |
+ |
+ /** |
+ * Adds a player to the list of players to manage. |
+ */ |
+ PlayerManager.prototype.addPlayer = function (id) { |
+ if (this.players[id]) { |
+ return; |
+ } |
+ // Make the PlayerProperty and add it to the mapping |
+ this.players[id] = new PlayerInfo(id); |
+ |
+ this.renderman.redrawList(); |
+ }; |
+ |
+ PlayerManager.prototype.removePlayer = function (id) { |
+ if (this.shouldRemovePlayer()) { |
+ delete this.players[id]; |
+ } else if (this.players[id]) { |
+ this.players[id].toRemove = true; |
+ } |
+ this.renderman.redrawList(); |
+ }; |
+ |
+ |
+ PlayerManager.prototype.selectPlayer = function (id) { |
+ if (!this.players[id]) { |
+ throw new Error("[selectPlayer] Id " + id + " does not exist."); |
+ } |
+ |
+ this.renderman.select(id); |
+ }; |
+ |
+ PlayerManager.prototype.updatePlayerInfoNoRecord = |
+ function (id, timestamp, key, value) { |
+ if (!this.players[id]) { |
+ console.error("[updatePlayerInfo] Id " + id + |
+ " does not exist"); |
+ return; |
+ } |
+ |
+ this.players[id].addPropertyNoRecord(timestamp, key, value); |
+ |
+ |
+ // If we can potentially rename the player, do so. |
+ if (key === 'name' || key === 'url') { |
+ this.renderman.redrawList(); |
+ } |
+ |
+ this.renderman.update(); |
+ }; |
+ |
+ PlayerManager.prototype.updatePlayerInfo = |
+ function (id, timestamp, key, value) { |
+ if (!this.players[id]) { |
+ console.error("[updatePlayerInfo] Id " + id + |
+ " does not exist"); |
+ return; |
+ } |
+ |
+ this.players[id].addProperty(timestamp, key, value); |
+ |
+ |
+ // If we can potentially rename the player, do so. |
+ if (key === 'name' || key === 'url') { |
+ this.renderman.redrawList(); |
+ } |
+ |
+ this.renderman.update(); |
+ }; |
+ |
+ return PlayerManager; |
+}()); |