OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 /** |
| 6 * @fileoverview Utility methods for accessing chrome.metricsPrivate API. |
| 7 * |
| 8 * To be included as a first script in main.html |
| 9 */ |
| 10 |
| 11 /** |
| 12 * @extends {metricsBase} |
| 13 */ |
| 14 var metrics = metricsBase; |
| 15 |
| 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: 4, |
| 34 }; |
| 35 |
| 36 /** |
| 37 * Values for "VideoPlayer.PlayType" metrics. |
| 38 * @enum {number} |
| 39 */ |
| 40 metrics.PLAY_TYPE = { |
| 41 LOCAL: 0, |
| 42 CAST: 1, |
| 43 MAX_VALUE: 1, |
| 44 }; |
| 45 |
| 46 /** |
| 47 * Utility function to check if the given value is in the given values. |
| 48 * @param {Object} values |
| 49 * @param {*} value |
| 50 * @reutrn {boolean} True if one or more elements of the given values hash have |
| 51 * the given value as value. False otherwise. |
| 52 */ |
| 53 metrics.hasValue_ = function(values, value) { |
| 54 return Object.keys(values).some(function(key) { |
| 55 return values[key] === value; |
| 56 }); |
| 57 }; |
| 58 |
| 59 /** |
| 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. |
| 76 * @param {number} number Value to be recorded. |
| 77 */ |
| 78 metrics.recordNumberOfCastDevices = function(number) { |
| 79 metrics.recordSmallCount('NumberOfCastDevices', number); |
| 80 }; |
| 81 |
| 82 /** |
| 83 * Record "VideoPlayer.NumberOfOpenedFile" metrics. |
| 84 * @param {number} number Value to be recorded. |
| 85 */ |
| 86 metrics.recordNumberOfOpenedFiles = function(number) { |
| 87 metrics.recordSmallCount('NumberOfOpenedFiles', number); |
| 88 }; |
| 89 |
| 90 /** |
| 91 * Record "VideoPlayer.CastedVideoLength" metrics. |
| 92 * @param {number} seconds Value to be recorded. |
| 93 */ |
| 94 metrics.recordCastedVideoLength = function(seconds) { |
| 95 metrics.recordMediumCount('CastedVideoLength', seconds); |
| 96 }; |
| 97 |
| 98 /** |
| 99 * Record "VideoPlayer.CastVideoError" metrics. |
| 100 */ |
| 101 metrics.recordCastVideoErrorAction = function() { |
| 102 metrics.recordUserAction('CastVideoError'); |
| 103 }; |
| 104 |
| 105 /** |
| 106 * Record "VideoPlayer.OpenVideoPlayer" action. |
| 107 */ |
| 108 metrics.recordOpenVideoPlayerAction = function() { |
| 109 metrics.recordUserAction('OpenVideoPlayer'); |
| 110 }; |
| 111 |
| 112 /** |
| 113 * Record "VideoPlayer.PlayType" metrics. |
| 114 * @param {metrics.PLAY_TYPE} type Value to be recorded. |
| 115 */ |
| 116 metrics.recordPlayType = function(type) { |
| 117 if (!metrics.hasValue_(metrics.PLAY_TYPE, type)) { |
| 118 console.error('The given value "' + status + '" is invalid.'); |
| 119 return; |
| 120 } |
| 121 |
| 122 metrics.recordEnum('PlayType', |
| 123 type, |
| 124 metrics.PLAY_TYPE.MAX_VALUE); |
| 125 }; |
| 126 |
| 127 /** |
| 128 * Convert a short metric name to the full format. |
| 129 * |
| 130 * @param {string} name Short metric name. |
| 131 * @return {string} Full metric name. |
| 132 * @override |
| 133 * @private |
| 134 */ |
| 135 metrics.convertName_ = function(name) { |
| 136 return 'VideoPlayer.' + name; |
| 137 }; |
OLD | NEW |