| OLD | NEW |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 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 Utility methods for accessing chrome.metricsPrivate API. | 6 * @fileoverview Utility methods for accessing chrome.metricsPrivate API. |
| 7 * | 7 * |
| 8 * To be included as a first script in main.html | 8 * To be included as a first script in main.html |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 /** | 11 /** |
| 12 * @extends {metricsBase} | 12 * @extends {metricsBase} |
| 13 */ | 13 */ |
| 14 var metrics = metricsBase; | 14 var metrics = metricsBase; |
| 15 | 15 |
| 16 /** | 16 /** |
| 17 * Values for "VideoPlayer.CastAPIExtensionStaus" metrics. | |
| 18 * @enum {number} | |
| 19 */ | |
| 20 metrics.CAST_API_EXTENSION_STATUS = { | |
| 21 // Cast API extension is not loaded since the cast extension, which is requred | |
| 22 // by the cast API extension, is not installed or load failed. | |
| 23 SKIPPED: 0, | |
| 24 // Installation of Cast API extension is failed. | |
| 25 INSTALLATION_FAILED: 1, | |
| 26 // Load of Cast API extension is failed. | |
| 27 LOAD_FAILED: 2, | |
| 28 // Cast API extension is newly installed and loaded. | |
| 29 INSTALLED_AND_LOADED: 3, | |
| 30 // Cast API extension is loaded. | |
| 31 LOADED: 4, | |
| 32 // (sentinel) | |
| 33 MAX_VALUE: 5, | |
| 34 }; | |
| 35 | |
| 36 /** | |
| 37 * Values for "VideoPlayer.PlayType" metrics. | 17 * Values for "VideoPlayer.PlayType" metrics. |
| 38 * @enum {number} | 18 * @enum {number} |
| 39 */ | 19 */ |
| 40 metrics.PLAY_TYPE = { | 20 metrics.PLAY_TYPE = { |
| 41 LOCAL: 0, | 21 LOCAL: 0, |
| 42 CAST: 1, | 22 CAST: 1, |
| 43 MAX_VALUE: 2, | 23 MAX_VALUE: 2, |
| 44 }; | 24 }; |
| 45 | 25 |
| 46 /** | 26 /** |
| 47 * Utility function to check if the given value is in the given values. | 27 * Utility function to check if the given value is in the given values. |
| 48 * @param {!Object} values | 28 * @param {!Object} values |
| 49 * @param {*} value | 29 * @param {*} value |
| 50 * @return {boolean} True if one or more elements of the given values hash have | 30 * @return {boolean} True if one or more elements of the given values hash have |
| 51 * the given value as value. False otherwise. | 31 * the given value as value. False otherwise. |
| 52 */ | 32 */ |
| 53 metrics.hasValue_ = function(values, value) { | 33 metrics.hasValue_ = function(values, value) { |
| 54 return Object.keys(values).some(function(key) { | 34 return Object.keys(values).some(function(key) { |
| 55 return values[key] === value; | 35 return values[key] === value; |
| 56 }); | 36 }); |
| 57 }; | 37 }; |
| 58 | 38 |
| 59 /** | 39 /** |
| 60 * Record "VideoPlayer.CastAPIExtensionStatsu" metrics. | |
| 61 * @param {metrics.CAST_API_EXTENSION_STATUS} status Status to be recorded. | |
| 62 */ | |
| 63 metrics.recordCastAPIExtensionStatus = function(status) { | |
| 64 if (!metrics.hasValue_(metrics.CAST_API_EXTENSION_STATUS, status)) { | |
| 65 console.error('The given value "' + status + '" is invalid.'); | |
| 66 return; | |
| 67 } | |
| 68 | |
| 69 metrics.recordEnum('CastAPIExtensionStatus', | |
| 70 status, | |
| 71 metrics.CAST_API_EXTENSION_STATUS.MAX_VALUE); | |
| 72 }; | |
| 73 | |
| 74 /** | |
| 75 * Record "VideoPlayer.NumberOfCastDevices" metrics. | 40 * Record "VideoPlayer.NumberOfCastDevices" metrics. |
| 76 * @param {number} number Value to be recorded. | 41 * @param {number} number Value to be recorded. |
| 77 */ | 42 */ |
| 78 metrics.recordNumberOfCastDevices = function(number) { | 43 metrics.recordNumberOfCastDevices = function(number) { |
| 79 metrics.recordSmallCount('NumberOfCastDevices', number); | 44 metrics.recordSmallCount('NumberOfCastDevices', number); |
| 80 }; | 45 }; |
| 81 | 46 |
| 82 /** | 47 /** |
| 83 * Record "VideoPlayer.NumberOfOpenedFile" metrics. | 48 * Record "VideoPlayer.NumberOfOpenedFile" metrics. |
| 84 * @param {number} number Value to be recorded. | 49 * @param {number} number Value to be recorded. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 * Convert a short metric name to the full format. | 93 * Convert a short metric name to the full format. |
| 129 * | 94 * |
| 130 * @param {string} name Short metric name. | 95 * @param {string} name Short metric name. |
| 131 * @return {string} Full metric name. | 96 * @return {string} Full metric name. |
| 132 * @override | 97 * @override |
| 133 * @private | 98 * @private |
| 134 */ | 99 */ |
| 135 metrics.convertName_ = function(name) { | 100 metrics.convertName_ = function(name) { |
| 136 return 'VideoPlayer.' + name; | 101 return 'VideoPlayer.' + name; |
| 137 }; | 102 }; |
| OLD | NEW |