| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @fileoverview A class for keeping track of the details of a player. | 6 * @fileoverview A class for keeping track of the details of a player. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 var PlayerInfo = (function() { | 9 var PlayerInfo = (function() { |
| 10 'use strict'; | 10 'use strict'; |
| 11 | 11 |
| 12 /** | 12 /** |
| 13 * A class that keeps track of properties on a media player. | 13 * A class that keeps track of properties on a media player. |
| 14 * @param id A unique id that can be used to identify this player. | 14 * @param id A unique id that can be used to identify this player. |
| 15 */ | 15 */ |
| 16 function PlayerInfo(id) { | 16 function PlayerInfo(id) { |
| 17 this.id = id; | 17 this.id = id; |
| 18 // The current value of the properties for this player. | 18 // The current value of the properties for this player. |
| 19 this.properties = {}; | 19 this.properties = {}; |
| 20 // All of the past (and present) values of the properties. | |
| 21 this.pastValues = {}; | |
| 22 | 20 |
| 23 // Every single event in the order in which they were received. | 21 // Every single event in the order in which they were received. |
| 24 this.allEvents = []; | 22 this.allEvents = []; |
| 25 this.lastRendered = 0; | 23 this.lastRendered = 0; |
| 26 | 24 |
| 27 this.firstTimestamp_ = -1; | 25 this.firstTimestamp_ = -1; |
| 28 } | 26 } |
| 29 | 27 |
| 30 PlayerInfo.prototype = { | 28 PlayerInfo.prototype = { |
| 31 /** | 29 /** |
| 32 * Adds or set a property on this player. | 30 * Adds or set a property on this player. |
| 33 * This is the default logging method as it keeps track of old values. | 31 * This is the default logging method as it keeps track of old values. |
| 34 * @param timestamp The time in milliseconds since the Epoch. | 32 * @param timestamp The time in milliseconds since the Epoch. |
| 35 * @param key A String key that describes the property. | 33 * @param key A String key that describes the property. |
| 36 * @param value The value of the property. | 34 * @param value The value of the property. |
| 37 */ | 35 */ |
| 38 addProperty: function(timestamp, key, value) { | 36 addProperty: function(timestamp, key, value) { |
| 39 // The first timestamp that we get will be recorded. | 37 // The first timestamp that we get will be recorded. |
| 40 // Then, all future timestamps are deltas of that. | 38 // Then, all future timestamps are deltas of that. |
| 41 if (this.firstTimestamp_ === -1) { | 39 if (this.firstTimestamp_ === -1) { |
| 42 this.firstTimestamp_ = timestamp; | 40 this.firstTimestamp_ = timestamp; |
| 43 } | 41 } |
| 44 | 42 |
| 45 if (typeof key !== 'string') { | 43 if (typeof key !== 'string') { |
| 46 throw new Error(typeof key + ' is not a valid key type'); | 44 throw new Error(typeof key + ' is not a valid key type'); |
| 47 } | 45 } |
| 48 | 46 |
| 49 this.properties[key] = value; | 47 this.properties[key] = value; |
| 50 | 48 |
| 51 if (!this.pastValues[key]) { | |
| 52 this.pastValues[key] = []; | |
| 53 } | |
| 54 | |
| 55 var recordValue = { | 49 var recordValue = { |
| 56 time: timestamp - this.firstTimestamp_, | 50 time: timestamp - this.firstTimestamp_, |
| 57 key: key, | 51 key: key, |
| 58 value: value | 52 value: value |
| 59 }; | 53 }; |
| 60 | 54 |
| 61 this.pastValues[key].push(recordValue); | |
| 62 this.allEvents.push(recordValue); | 55 this.allEvents.push(recordValue); |
| 63 }, | 56 }, |
| 64 | 57 |
| 65 /** | 58 /** |
| 66 * Adds or set a property on this player. | 59 * Adds or set a property on this player. |
| 67 * Does not keep track of old values. This is better for | 60 * Does not keep track of old values. This is better for |
| 68 * values that get spammed repeatedly. | 61 * values that get spammed repeatedly. |
| 69 * @param timestamp The time in milliseconds since the Epoch. | 62 * @param timestamp The time in milliseconds since the Epoch. |
| 70 * @param key A String key that describes the property. | 63 * @param key A String key that describes the property. |
| 71 * @param value The value of the property. | 64 * @param value The value of the property. |
| 72 */ | 65 */ |
| 73 addPropertyNoRecord: function(timestamp, key, value) { | 66 addPropertyNoRecord: function(timestamp, key, value) { |
| 74 this.addProperty(timestamp, key, value); | 67 this.addProperty(timestamp, key, value); |
| 75 this.allEvents.pop(); | 68 this.allEvents.pop(); |
| 76 } | 69 } |
| 77 }; | 70 }; |
| 78 | 71 |
| 79 return PlayerInfo; | 72 return PlayerInfo; |
| 80 }()); | 73 }()); |
| OLD | NEW |