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.
6 * @fileoverview Utility methods for accessing chrome.metricsPrivate API.
8 * To be included as a first script in main.html
12 * @extends {metricsBase}
14 var metrics
= metricsBase
;
17 * Values for "VideoPlayer.CastAPIExtensionStaus" metrics.
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.
24 // Installation of Cast API extension is failed.
25 INSTALLATION_FAILED
: 1,
26 // Load of Cast API extension is failed.
28 // Cast API extension is newly installed and loaded.
29 INSTALLED_AND_LOADED
: 3,
30 // Cast API extension is loaded.
37 * Values for "VideoPlayer.PlayType" metrics.
47 * Utility function to check if the given value is in the given values.
48 * @param {!Object} values
50 * @return {boolean} True if one or more elements of the given values hash have
51 * the given value as value. False otherwise.
53 metrics
.hasValue_ = function(values
, value
) {
54 return Object
.keys(values
).some(function(key
) {
55 return values
[key
] === value
;
60 * Record "VideoPlayer.CastAPIExtensionStatsu" metrics.
61 * @param {metrics.CAST_API_EXTENSION_STATUS} status Status to be recorded.
63 metrics
.recordCastAPIExtensionStatus = function(status
) {
64 if (!metrics
.hasValue_(metrics
.CAST_API_EXTENSION_STATUS
, status
)) {
65 console
.error('The given value "' + status
+ '" is invalid.');
69 metrics
.recordEnum('CastAPIExtensionStatus',
71 metrics
.CAST_API_EXTENSION_STATUS
.MAX_VALUE
);
75 * Record "VideoPlayer.NumberOfCastDevices" metrics.
76 * @param {number} number Value to be recorded.
78 metrics
.recordNumberOfCastDevices = function(number
) {
79 metrics
.recordSmallCount('NumberOfCastDevices', number
);
83 * Record "VideoPlayer.NumberOfOpenedFile" metrics.
84 * @param {number} number Value to be recorded.
86 metrics
.recordNumberOfOpenedFiles = function(number
) {
87 metrics
.recordSmallCount('NumberOfOpenedFiles', number
);
91 * Record "VideoPlayer.CastedVideoLength" metrics.
92 * @param {number} seconds Value to be recorded.
94 metrics
.recordCastedVideoLength = function(seconds
) {
95 metrics
.recordMediumCount('CastedVideoLength', seconds
);
99 * Record "VideoPlayer.CastVideoError" metrics.
101 metrics
.recordCastVideoErrorAction = function() {
102 metrics
.recordUserAction('CastVideoError');
106 * Record "VideoPlayer.OpenVideoPlayer" action.
108 metrics
.recordOpenVideoPlayerAction = function() {
109 metrics
.recordUserAction('OpenVideoPlayer');
113 * Record "VideoPlayer.PlayType" metrics.
114 * @param {metrics.PLAY_TYPE} type Value to be recorded.
116 metrics
.recordPlayType = function(type
) {
117 if (!metrics
.hasValue_(metrics
.PLAY_TYPE
, type
)) {
118 console
.error('The given value "' + type
+ '" is invalid.');
122 metrics
.recordEnum('PlayType',
124 metrics
.PLAY_TYPE
.MAX_VALUE
);
128 * Convert a short metric name to the full format.
130 * @param {string} name Short metric name.
131 * @return {string} Full metric name.
135 metrics
.convertName_ = function(name
) {
136 return 'VideoPlayer.' + name
;