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

Side by Side Diff: chrome/browser/resources/task_scheduler_internals/index.js

Issue 2484043004: Apply Delayed Code Review Comments to Task Scheduler Internals (Closed)
Patch Set: Created 4 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
« no previous file with comments | « no previous file | chrome/browser/ui/webui/task_scheduler_internals/task_scheduler_internals_ui.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 var TaskSchedulerInternals = {}; 5 /** @typedef {{min: number, max: number, count: number}} */
6 var Bucket;
6 7
7 /** 8 /** @typedef {{name: string, buckets: !Array<Bucket>}} */
8 * Updates the histograms on the page. 9 var Histogram;
9 * @param {Array<Object>} histograms Array of histogram objects. 10
10 */ 11 var TaskSchedulerInternals = {
11 TaskSchedulerInternals.updateHistograms = function(histograms) { 12 /**
12 var histogramContainer = $('histogram-container'); 13 * Updates the histograms on the page.
13 for (var i in histograms) { 14 * @param {!Array<!Histogram>} histograms Array of histogram objects.
14 var histogram = histograms[i]; 15 */
15 var title = document.createElement('div'); 16 updateHistograms: function(histograms) {
16 title.textContent = histogram.name; 17 var histogramContainer = $('histogram-container');
17 histogramContainer.appendChild(title); 18 for (var i in histograms) {
18 if (histogram.buckets.length > 0) { 19 var histogram = histograms[i];
19 histogramContainer.appendChild( 20 var title = document.createElement('div');
20 TaskSchedulerInternals.createHistogramTable(histogram.buckets)); 21 title.textContent = histogram.name;
21 } else { 22 histogramContainer.appendChild(title);
22 var unavailable = document.createElement('div'); 23 if (histogram.buckets.length > 0) {
23 unavailable.textContent = 'No Data Recorded'; 24 histogramContainer.appendChild(
24 histogramContainer.appendChild(unavailable); 25 TaskSchedulerInternals.createHistogramTable(histogram.buckets));
26 } else {
27 var unavailable = document.createElement('div');
28 unavailable.textContent = 'No Data Recorded';
29 histogramContainer.appendChild(unavailable);
30 }
25 } 31 }
32 },
33
34 /**
35 * Returns a table representation of the histogram buckets.
36 * @param {Object} buckets The histogram buckets.
37 * @return {Object} A table element representation of the histogram buckets.
38 */
39 createHistogramTable: function(buckets) {
40 var table = document.createElement('table');
41 var headerRow = document.createElement('tr');
42 var dataRow = document.createElement('tr');
43 for (var i in buckets) {
44 var bucket = buckets[i];
45 var header = document.createElement('th');
46 header.textContent = `${bucket.min}-${bucket.max}`;
47 headerRow.appendChild(header);
48 var data = document.createElement('td');
49 data.textContent = bucket.count;
50 dataRow.appendChild(data);
51 }
52 table.appendChild(headerRow);
53 table.appendChild(dataRow);
54 return table;
55 },
56
57 /**
58 * Handles callback from onGetTaskSchedulerData.
59 * @param {Object} data Dictionary containing all task scheduler metrics.
60 */
61 onGetTaskSchedulerData: function(data) {
62 $('status').textContent =
63 data.instantiated ? 'Instantiated' : 'Not Instantiated';
64 $('details').hidden = !data.instantiated;
65 if (!data.instantiated)
66 return;
67
68 TaskSchedulerInternals.updateHistograms(data.histograms);
26 } 69 }
27 }; 70 };
28 71
29 /**
30 * Returns a table representation of the histogram buckets.
31 * @param {Object} buckets The histogram buckets.
32 * @return {Object} A table element representation of the histogram buckets.
33 */
34 TaskSchedulerInternals.createHistogramTable = function(buckets) {
35 var table = document.createElement('table');
36 var headerRow = document.createElement('tr');
37 var dataRow = document.createElement('tr');
38 for (var i in buckets) {
39 var bucket = buckets[i];
40 var header = document.createElement('th');
41 header.textContent = bucket.min + '-' + bucket.max;
42 headerRow.appendChild(header);
43 var data = document.createElement('td');
44 data.textContent = bucket.count;
45 dataRow.appendChild(data);
46 }
47 table.appendChild(headerRow);
48 table.appendChild(dataRow);
49 return table;
50 };
51
52 /**
53 * Handles callback from onGetTaskSchedulerData.
54 * @param {Object} data Dictionary containing all task scheduler metrics.
55 */
56 TaskSchedulerInternals.onGetTaskSchedulerData = function(data) {
57 $('status').textContent =
58 data.instantiated ? 'Instantiated' : 'Not Instantiated';
59 $('details').hidden = !data.instantiated;
60 if (!data.instantiated)
61 return;
62
63 TaskSchedulerInternals.updateHistograms(data.histograms);
64 };
65
66 document.addEventListener('DOMContentLoaded', function() { 72 document.addEventListener('DOMContentLoaded', function() {
67 chrome.send('getTaskSchedulerData'); 73 chrome.send('getTaskSchedulerData');
68 }); 74 });
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/webui/task_scheduler_internals/task_scheduler_internals_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698