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

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

Issue 673933003: Fix some type check errors in file_manager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move logging for metrics to common part. Created 6 years, 2 months 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
Index: ui/file_manager/file_manager/foreground/js/metrics.js
diff --git a/ui/file_manager/file_manager/foreground/js/metrics.js b/ui/file_manager/file_manager/foreground/js/metrics.js
index a59491d7b489192dd1661efd77c3f6a03f933091..315b6208cbdb315b8a2e2d03bc934ff91514b780 100644
--- a/ui/file_manager/file_manager/foreground/js/metrics.js
+++ b/ui/file_manager/file_manager/foreground/js/metrics.js
@@ -41,39 +41,54 @@ metrics.convertName_ = function(name) {
/**
* Wrapper method for calling chrome.fileManagerPrivate safely.
- * @param {string} name Method name.
+ * @param {string} methodName Method name.
* @param {Array.<Object>} args Arguments.
* @private
*/
-metrics.call_ = function(name, args) {
+metrics.call_ = function(methodName, args) {
try {
- chrome.metricsPrivate[name].apply(chrome.metricsPrivate, args);
+ chrome.metricsPrivate[methodName].apply(chrome.metricsPrivate, args);
} catch (e) {
console.error(e.stack);
}
+ if (metrics.log)
+ console.log('chrome.metricsPrivate.' + methodName, args);
};
/**
- * Create a decorator function that calls a chrome.metricsPrivate function
- * with the same name and correct parameters.
- *
- * @param {string} name Method name.
+ * Records a value than can range from 1 to 10,000.
+ * @param {string} name Short metric name.
+ * @param {number} value Value to be recorded.
*/
-metrics.decorate = function(name) {
- metrics[name] = function() {
- var args = Array.apply(null, arguments);
- args[0] = metrics.convertName_(args[0]);
- metrics.call_(name, args);
- if (metrics.log) {
- console.log('chrome.metricsPrivate.' + name, args);
- }
- };
+metrics.recordMediumCount = function(name, value) {
+ metrics.call_('recordMediumCount', [metrics.convertName_(name), value]);
+};
+
+/**
+ * Records a value than can range from 1 to 100.
+ * @param {string} name Short metric name.
+ * @param {number} value Value to be recorded.
+ */
+metrics.recordSmallCount = function(name, value) {
+ metrics.call_('recordSmallCount', [metrics.convertName_(name), value]);
+};
+
+/**
+ * Records an elapsed time of no more than 10 seconds.
+ * @param {string} name Short metric name.
+ * @param {number} time Time to be recorded in milliseconds.
+ */
+metrics.recordTime = function(name, time) {
+ metrics.call_('recordTime', [metrics.convertName_(name), time]);
};
-metrics.decorate('recordMediumCount');
-metrics.decorate('recordSmallCount');
-metrics.decorate('recordTime');
-metrics.decorate('recordUserAction');
+/**
+ * Records an action performed by the user.
+ * @param {string} name Short metric name.
+ */
+metrics.recordUserAction = function(name) {
+ metrics.call_('recordUserAction', [metrics.convertName_(name)]);
+};
/**
* Complete the time interval recording.
@@ -124,8 +139,4 @@ metrics.recordEnum = function(name, value, validValues) {
'buckets': boundaryValue + 1
};
metrics.call_('recordValue', [metricDescr, index]);
- if (metrics.log) {
- console.log('chrome.metricsPrivate.recordValue',
- [metricDescr.metricName, index, value]);
- }
};

Powered by Google App Engine
This is Rietveld 408576698