Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Unified Diff: ui/file_manager/file_manager/foreground/js/metrics_base.js

Issue 806163003: Adds histograms for casting feature of Video Player Base URL: https://chromium.googlesource.com/chromium/src.git@2214
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/metrics/histograms/histograms.xml ('k') | ui/file_manager/video_player/js/cast/cast_video_element.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/file_manager/file_manager/foreground/js/metrics_base.js
diff --git a/ui/file_manager/file_manager/foreground/js/metrics.js b/ui/file_manager/file_manager/foreground/js/metrics_base.js
similarity index 70%
copy from ui/file_manager/file_manager/foreground/js/metrics.js
copy to ui/file_manager/file_manager/foreground/js/metrics_base.js
index 315b6208cbdb315b8a2e2d03bc934ff91514b780..0aa935552f8261222a2488172ebf2c1eb761ee47 100644
--- a/ui/file_manager/file_manager/foreground/js/metrics.js
+++ b/ui/file_manager/file_manager/foreground/js/metrics_base.js
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// 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.
@@ -8,12 +8,25 @@
* To be included as a first script in main.html
*/
-var metrics = {};
+var metricsBase = {};
/**
* A map from interval name to interval start timestamp.
*/
-metrics.intervals = {};
+metricsBase.intervals = {};
+
+/**
+ * A mapping of enum names to valid values. This object is consulted
+ * any time an enum value is being reported un-accompanied by a list
+ * of valid values.
+ *
+ * <p>Values mut be provided by base classes. Values should correspond exactly
+ * with values from histograms.xml.
+ *
+ * @private {!Object.<string, !Array.<*>|number>}
+ */
+metricsBase.validEnumValues_ = {};
+
/**
* Start the named time interval.
@@ -21,13 +34,10 @@ metrics.intervals = {};
*
* @param {string} name Unique interval name.
*/
-metrics.startInterval = function(name) {
- metrics.intervals[name] = Date.now();
+metricsBase.startInterval = function(name) {
+ metricsBase.intervals[name] = Date.now();
};
-metrics.startInterval('Load.Total');
-metrics.startInterval('Load.Script');
-
/**
* Convert a short metric name to the full format.
*
@@ -35,8 +45,8 @@ metrics.startInterval('Load.Script');
* @return {string} Full metric name.
* @private
*/
-metrics.convertName_ = function(name) {
- return 'FileBrowser.' + name;
+metricsBase.convertName_ = function(name) {
+ throw new Error('metricsBase.convertName_() must be overrideen by subclass.');
};
/**
@@ -45,7 +55,7 @@ metrics.convertName_ = function(name) {
* @param {Array.<Object>} args Arguments.
* @private
*/
-metrics.call_ = function(methodName, args) {
+metricsBase.call_ = function(methodName, args) {
try {
chrome.metricsPrivate[methodName].apply(chrome.metricsPrivate, args);
} catch (e) {
@@ -60,7 +70,7 @@ metrics.call_ = function(methodName, args) {
* @param {string} name Short metric name.
* @param {number} value Value to be recorded.
*/
-metrics.recordMediumCount = function(name, value) {
+metricsBase.recordMediumCount = function(name, value) {
metrics.call_('recordMediumCount', [metrics.convertName_(name), value]);
};
@@ -69,7 +79,7 @@ metrics.recordMediumCount = function(name, value) {
* @param {string} name Short metric name.
* @param {number} value Value to be recorded.
*/
-metrics.recordSmallCount = function(name, value) {
+metricsBase.recordSmallCount = function(name, value) {
metrics.call_('recordSmallCount', [metrics.convertName_(name), value]);
};
@@ -78,7 +88,7 @@ metrics.recordSmallCount = function(name, value) {
* @param {string} name Short metric name.
* @param {number} time Time to be recorded in milliseconds.
*/
-metrics.recordTime = function(name, time) {
+metricsBase.recordTime = function(name, time) {
metrics.call_('recordTime', [metrics.convertName_(name), time]);
};
@@ -86,7 +96,7 @@ metrics.recordTime = function(name, time) {
* Records an action performed by the user.
* @param {string} name Short metric name.
*/
-metrics.recordUserAction = function(name) {
+metricsBase.recordUserAction = function(name) {
metrics.call_('recordUserAction', [metrics.convertName_(name)]);
};
@@ -97,7 +107,7 @@ metrics.recordUserAction = function(name) {
*
* @param {string} name Unique interval name.
*/
-metrics.recordInterval = function(name) {
+metricsBase.recordInterval = function(name) {
if (name in metrics.intervals) {
metrics.recordTime(name, Date.now() - metrics.intervals[name]);
} else {
@@ -110,12 +120,20 @@ metrics.recordInterval = function(name) {
*
* @param {string} name Metric name.
* @param {*} value Enum value.
- * @param {Array.<*>|number} validValues Array of valid values
+ * @param {Array.<*>|number=} opt_validValues Array of valid values
* or a boundary number value.
*/
-metrics.recordEnum = function(name, value, validValues) {
+metricsBase.recordEnum = function(name, value, opt_validValues) {
var boundaryValue;
var index;
+
+ var validValues = opt_validValues;
+ if (metrics.validEnumValues_ && name in metrics.validEnumValues_) {
+ console.assert(validValues === undefined);
+ validValues = metrics.validEnumValues_[name]
+ }
+ console.assert(validValues !== undefined);
+
if (validValues.constructor.name == 'Array') {
index = validValues.indexOf(value);
boundaryValue = validValues.length;
« no previous file with comments | « tools/metrics/histograms/histograms.xml ('k') | ui/file_manager/video_player/js/cast/cast_video_element.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698