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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 this.start(); | 148 this.start(); |
149 } | 149 } |
150 | 150 |
151 Timer.prototype = { | 151 Timer.prototype = { |
152 start: function() { | 152 start: function() { |
153 this.start_ = getCurrentTime(); | 153 this.start_ = getCurrentTime(); |
154 }, | 154 }, |
155 | 155 |
156 stop: function() { | 156 stop: function() { |
157 // Return delta time since start in millisecs. | 157 // Return delta time since start in millisecs. |
158 return ((getCurrentTime() - this.start_)).toFixed(3); | 158 return Math.round((getCurrentTime() - this.start_) * 1000) / 1000; |
159 } | 159 } |
160 }; | 160 }; |
161 | 161 |
162 function checkElementIsNotBound(element) { | 162 function checkElementIsNotBound(element) { |
163 if (!element) | 163 if (!element) |
164 return; | 164 return; |
165 if (getMediaMetric(element)) | 165 if (getMediaMetric(element)) |
166 throw new Error('Can not create MediaMetric for same element twice.'); | 166 throw new Error('Can not create MediaMetric for same element twice.'); |
167 } | 167 } |
168 | 168 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 metrics.push(window.__mediaMetrics[i].getSummary()); | 200 metrics.push(window.__mediaMetrics[i].getSummary()); |
201 return metrics; | 201 return metrics; |
202 } | 202 } |
203 | 203 |
204 window.__globalCounter = 0; | 204 window.__globalCounter = 0; |
205 window.__mediaMetrics = []; | 205 window.__mediaMetrics = []; |
206 window.__getMediaMetric = getMediaMetric; | 206 window.__getMediaMetric = getMediaMetric; |
207 window.__getAllMetrics = getAllMetrics; | 207 window.__getAllMetrics = getAllMetrics; |
208 window.__createMediaMetricsForDocument = createMediaMetricsForDocument; | 208 window.__createMediaMetricsForDocument = createMediaMetricsForDocument; |
209 })(); | 209 })(); |
OLD | NEW |