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

Side by Side 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, 1 month 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @fileoverview Utility methods for accessing chrome.metricsPrivate API. 6 * @fileoverview Utility methods for accessing chrome.metricsPrivate API.
7 * 7 *
8 * To be included as a first script in main.html 8 * To be included as a first script in main.html
9 */ 9 */
10 10
(...skipping 23 matching lines...) Expand all
34 * @param {string} name Short metric name. 34 * @param {string} name Short metric name.
35 * @return {string} Full metric name. 35 * @return {string} Full metric name.
36 * @private 36 * @private
37 */ 37 */
38 metrics.convertName_ = function(name) { 38 metrics.convertName_ = function(name) {
39 return 'FileBrowser.' + name; 39 return 'FileBrowser.' + name;
40 }; 40 };
41 41
42 /** 42 /**
43 * Wrapper method for calling chrome.fileManagerPrivate safely. 43 * Wrapper method for calling chrome.fileManagerPrivate safely.
44 * @param {string} name Method name. 44 * @param {string} methodName Method name.
45 * @param {Array.<Object>} args Arguments. 45 * @param {Array.<Object>} args Arguments.
46 * @private 46 * @private
47 */ 47 */
48 metrics.call_ = function(name, args) { 48 metrics.call_ = function(methodName, args) {
49 try { 49 try {
50 chrome.metricsPrivate[name].apply(chrome.metricsPrivate, args); 50 chrome.metricsPrivate[methodName].apply(chrome.metricsPrivate, args);
51 } catch (e) { 51 } catch (e) {
52 console.error(e.stack); 52 console.error(e.stack);
53 } 53 }
54 if (metrics.log)
55 console.log('chrome.metricsPrivate.' + methodName, args);
54 }; 56 };
55 57
56 /** 58 /**
57 * Create a decorator function that calls a chrome.metricsPrivate function 59 * Records a value than can range from 1 to 10,000.
58 * with the same name and correct parameters. 60 * @param {string} name Short metric name.
59 * 61 * @param {number} value Value to be recorded.
60 * @param {string} name Method name.
61 */ 62 */
62 metrics.decorate = function(name) { 63 metrics.recordMediumCount = function(name, value) {
63 metrics[name] = function() { 64 metrics.call_('recordMediumCount', [metrics.convertName_(name), value]);
64 var args = Array.apply(null, arguments);
65 args[0] = metrics.convertName_(args[0]);
66 metrics.call_(name, args);
67 if (metrics.log) {
68 console.log('chrome.metricsPrivate.' + name, args);
69 }
70 };
71 }; 65 };
72 66
73 metrics.decorate('recordMediumCount'); 67 /**
74 metrics.decorate('recordSmallCount'); 68 * Records a value than can range from 1 to 100.
75 metrics.decorate('recordTime'); 69 * @param {string} name Short metric name.
76 metrics.decorate('recordUserAction'); 70 * @param {number} value Value to be recorded.
71 */
72 metrics.recordSmallCount = function(name, value) {
73 metrics.call_('recordSmallCount', [metrics.convertName_(name), value]);
74 };
75
76 /**
77 * Records an elapsed time of no more than 10 seconds.
78 * @param {string} name Short metric name.
79 * @param {number} time Time to be recorded in milliseconds.
80 */
81 metrics.recordTime = function(name, time) {
82 metrics.call_('recordTime', [metrics.convertName_(name), time]);
83 };
84
85 /**
86 * Records an action performed by the user.
87 * @param {string} name Short metric name.
88 */
89 metrics.recordUserAction = function(name) {
90 metrics.call_('recordUserAction', [metrics.convertName_(name)]);
91 };
77 92
78 /** 93 /**
79 * Complete the time interval recording. 94 * Complete the time interval recording.
80 * 95 *
81 * Should be preceded by a call to startInterval with the same name. * 96 * Should be preceded by a call to startInterval with the same name. *
82 * 97 *
83 * @param {string} name Unique interval name. 98 * @param {string} name Unique interval name.
84 */ 99 */
85 metrics.recordInterval = function(name) { 100 metrics.recordInterval = function(name) {
86 if (name in metrics.intervals) { 101 if (name in metrics.intervals) {
(...skipping 30 matching lines...) Expand all
117 // bucket AND the underflow bucket. 132 // bucket AND the underflow bucket.
118 // (Source: UMA_HISTOGRAM_ENUMERATION definition in base/metrics/histogram.h) 133 // (Source: UMA_HISTOGRAM_ENUMERATION definition in base/metrics/histogram.h)
119 var metricDescr = { 134 var metricDescr = {
120 'metricName': metrics.convertName_(name), 135 'metricName': metrics.convertName_(name),
121 'type': 'histogram-linear', 136 'type': 'histogram-linear',
122 'min': 1, 137 'min': 1,
123 'max': boundaryValue, 138 'max': boundaryValue,
124 'buckets': boundaryValue + 1 139 'buckets': boundaryValue + 1
125 }; 140 };
126 metrics.call_('recordValue', [metricDescr, index]); 141 metrics.call_('recordValue', [metricDescr, index]);
127 if (metrics.log) {
128 console.log('chrome.metricsPrivate.recordValue',
129 [metricDescr.metricName, index, value]);
130 }
131 }; 142 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698