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 // This file contains common utilities to find video/audio elements on a page | 5 // This file contains common utilities to find video/audio elements on a page |
6 // and collect metrics for each. | 6 // and collect metrics for each. |
7 | 7 |
8 (function() { | 8 (function() { |
9 // MediaMetric class responsible for collecting metrics on a media element. | 9 // MediaMetric class responsible for collecting metrics on a media element. |
10 // It attaches required event listeners in order to collect different metrics. | 10 // It attaches required event listeners in order to collect different metrics. |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 this.start_ = 0; | 142 this.start_ = 0; |
143 this.start(); | 143 this.start(); |
144 } | 144 } |
145 | 145 |
146 Timer.prototype = { | 146 Timer.prototype = { |
147 start: function() { | 147 start: function() { |
148 this.start_ = getCurrentTime(); | 148 this.start_ = getCurrentTime(); |
149 }, | 149 }, |
150 | 150 |
151 stop: function() { | 151 stop: function() { |
152 // Return delta time since start in secs. | 152 // Return delta time since start in millisecs. |
153 return ((getCurrentTime() - this.start_) / 1000).toFixed(3); | 153 return ((getCurrentTime() - this.start_)).toFixed(3); |
154 } | 154 } |
155 }; | 155 }; |
156 | 156 |
157 function checkElementIsNotBound(element) { | 157 function checkElementIsNotBound(element) { |
158 if (!element) | 158 if (!element) |
159 return; | 159 return; |
160 for (var i = 0; i < window.__mediaMetrics.length; i++) { | 160 for (var i = 0; i < window.__mediaMetrics.length; i++) { |
161 if (window.__mediaMetrics[i].element == element) | 161 if (window.__mediaMetrics[i].element == element) |
162 throw new Error('Can not create MediaMetric for same element twice.'); | 162 throw new Error('Can not create MediaMetric for same element twice.'); |
163 } | 163 } |
(...skipping 24 matching lines...) Expand all Loading... |
188 for (var i = 0; i < window.__mediaMetrics.length; i++) | 188 for (var i = 0; i < window.__mediaMetrics.length; i++) |
189 metrics.push(window.__mediaMetrics[i].getSummary()); | 189 metrics.push(window.__mediaMetrics[i].getSummary()); |
190 return metrics; | 190 return metrics; |
191 } | 191 } |
192 | 192 |
193 window.__globalCounter = 0; | 193 window.__globalCounter = 0; |
194 window.__mediaMetrics = []; | 194 window.__mediaMetrics = []; |
195 window.__getAllMetrics = getAllMetrics; | 195 window.__getAllMetrics = getAllMetrics; |
196 window.__createMediaMetricsForDocument = createMediaMetricsForDocument; | 196 window.__createMediaMetricsForDocument = createMediaMetricsForDocument; |
197 })(); | 197 })(); |
OLD | NEW |