Chromium Code Reviews| Index: ui/file_manager/video_player/js/video_player_metrics.js |
| diff --git a/ui/file_manager/video_player/js/video_player_metrics.js b/ui/file_manager/video_player/js/video_player_metrics.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..84133f3ca65fedd674ffa9ad225cc1e73d05201d |
| --- /dev/null |
| +++ b/ui/file_manager/video_player/js/video_player_metrics.js |
| @@ -0,0 +1,130 @@ |
| +// Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +/** |
| + * @fileoverview Utility methods for accessing chrome.metricsPrivate API. |
| + * |
| + * To be included as a first script in main.html |
| + */ |
| + |
| +/** |
| + * @extends {metricsBase} |
| + */ |
| +var metrics = metricsBase; |
| + |
| +/** |
| + * Values for "VideoPlayer.CastExtensionStaus" metrics. |
| + * @enum {number} |
| + */ |
| +metrics.CAST_EXTENSION = { |
| + EXTENSION_UNAVAILABLE: 0, |
| + API_INSTALLATION_FAILED: 1, |
| + API_LOAD_FAILED: 2, |
| + API_INSTALLED_AND_LOADED: 3, |
| + API_AVAILABLE_AND_LOADED: 4, |
| + MAX_VALUE: 4, |
| +}; |
| + |
| +/** |
| + * Values for "VideoPlayer.PlayType" metrics. |
| + * @enum {number} |
| + */ |
| +metrics.PLAY_TYPE = { |
| + LOCAL: 0, |
| + CAST: 1, |
| + MAX_VALUE: 1, |
|
Ilya Sherman
2014/12/09 01:57:49
Unless the JS metrics API is different from the C+
yoshiki
2014/12/10 03:20:50
In the base class, the final value is passed with
|
| +}; |
| + |
| +/** |
| + * Utility function to check if the given value is in the given values. |
| + * @param {Object} values |
| + * @param {*} value |
| + * @reutrn {boolean} True if one or more elements of the given values hash have |
| + * the given value as value. False otherwise. |
| + */ |
| +metrics.hasValue_ = function(values, value) { |
| + return Object.keys(values).some(function(key) { |
| + return values[key] === value; |
| + }); |
| +}; |
| + |
| +/** |
| + * Record "VideoPlayer.CastExtensionStatsu" metrics. |
| + * @param {metrics.CAST_EXTENSION} status Status to be recorded. |
| + */ |
| +metrics.recordCastExtensionStatus = function(status) { |
| + if (!metrics.hasValue_(metrics.CAST_EXTENSION, status)) { |
| + console.error('The given value "' + status + '" is invalid.'); |
| + return; |
| + } |
| + |
| + metrics.recordEnum('CastExtensionStatus', |
| + status, |
| + metrics.CAST_EXTENSION.MAX_VALUE); |
| +}; |
| + |
| +/** |
| + * Record "VideoPlayer.NumberOfCastDevices" metrics. |
| + * @param {number} number Value to be recorded. |
| + */ |
| +metrics.recordNumberOfCastDevices = function(number) { |
| + metrics.recordSmallCount('NumberOfCastDevices', number); |
| +}; |
| + |
| +/** |
| + * Record "VideoPlayer.NumberOfOpenedFile" metrics. |
| + * @param {number} number Value to be recorded. |
| + */ |
| +metrics.recordNumberOfOpenedFiles = function(number) { |
| + metrics.recordSmallCount('NumberOfOpenedFiles', number); |
| +}; |
| + |
| +/** |
| + * Record "VideoPlayer.CastedVideoLength" metrics. |
| + * @param {number} seconds Value to be recorded. |
| + */ |
| +metrics.recordCastedVideoLength = function(seconds) { |
| + metrics.recordMediumCount('CastedVideoLength', seconds); |
| +}; |
| + |
| +/** |
| + * Record "VideoPlayer.CastVideoError" metrics. |
| + */ |
| +metrics.recordCastVideoErrorAction = function() { |
| + metrics.recordUserAction('CastVideoError'); |
|
Ilya Sherman
2014/12/09 01:57:49
I don't see this defined in actions.xml
yoshiki
2014/12/10 03:20:50
I accidentally removed. Added.
|
| +}; |
| + |
| +/** |
| + * Record "VideoPlayer.OpenVideoPlayer" action. |
| + */ |
| +metrics.recordOpenVideoPlayerAction = function() { |
| + metrics.recordUserAction('OpenVideoPlayer'); |
| +}; |
| + |
| +/** |
| + * Record "VideoPlayer.PlayType" metrics. |
| + * @param {metrics.PLAY_TYPE} type Value to be recorded. |
| + */ |
| +metrics.recordPlayType = function(type) { |
| + if (!metrics.hasValue_(metrics.PLAY_TYPE, type)) { |
| + console.error('The given value "' + status + '" is invalid.'); |
| + return; |
| + } |
| + |
| + metrics.recordEnum('PlayType', |
| + type, |
| + metrics.PLAY_TYPE.MAX_VALUE); |
| +}; |
| + |
| +/** |
| + * Convert a short metric name to the full format. |
| + * |
| + * @param {string} name Short metric name. |
| + * @return {string} Full metric name. |
| + * @override |
| + * @private |
| + */ |
| +metrics.convertName_ = function(name) { |
| + return 'VideoPlayer.' + name; |
| +}; |