Chromium Code Reviews| Index: chrome/browser/resources/gcm_internals.js |
| diff --git a/chrome/browser/resources/gcm_internals.js b/chrome/browser/resources/gcm_internals.js |
| index f309479eb7c29cc9716bc9aca39439c8cbaeaf00..56e6c75e731b20a49fcc285c5f6e627690d599ee 100644 |
| --- a/chrome/browser/resources/gcm_internals.js |
| +++ b/chrome/browser/resources/gcm_internals.js |
| @@ -5,9 +5,11 @@ |
| cr.define('gcmInternals', function() { |
| 'use strict'; |
| + var isRecording = false; |
| + |
| /** |
| * If the info dictionary has property prop, then set the text content of |
| - * element to the value of this property. |
| + * element to the value of this property. Otherwise clear the content. |
| * @param {!Object} info A dictionary of device infos to be displayed. |
| * @param {string} prop Name of the property. |
| * @param {string} element The id of a HTML element. |
| @@ -15,6 +17,8 @@ cr.define('gcmInternals', function() { |
| function setIfExists(info, prop, element) { |
| if (info[prop] !== undefined) { |
| $(element).textContent = info[prop]; |
| + } else { |
| + $(element).textContent = ''; |
| } |
| } |
| @@ -32,10 +36,77 @@ cr.define('gcmInternals', function() { |
| setIfExists(info, 'gcmClientReady', 'gcm-client-ready'); |
| setIfExists(info, 'connectionClientCreated', 'connection-client-created'); |
| setIfExists(info, 'connectionState', 'connection-state'); |
| + setIfExists(info, 'appIdsCached', 'app-ids-cached'); |
| + setIfExists(info, 'sendQueueSize', 'send-queue-size'); |
| + setIfExists(info, 'unackedQueueSize', 'unacked-queue-size'); |
| + } |
| + |
| + /** |
| + * Remove all the child nodes of the element. |
| + * @param {HTMLElement} element A HTML element. |
| + */ |
| + function removeAllChildNodes(element) { |
| + while (element.firstChild) { |
|
arv (Not doing code reviews)
2014/03/24 18:47:05
element.textContent = '';
juyik
2014/03/26 04:06:03
Done.
|
| + element.removeChild(element.firstChild); |
| + } |
| + } |
| + |
| + /** |
| + * For each item in line, add a row to the table. Each item is actually a list |
| + * of sub-items; each of which will have a corresponding cell created in that |
| + * row, and the sub-item will be displayed in the cell. |
| + * @param {HTMLElement} table A HTML tbody element. |
| + * @param {!Object} list A list of list of item. |
| + */ |
| + function addRows(table, list) { |
| + for (var i = 0; i < list.length; ++i) { |
| + var row = document.createElement('tr'); |
| + |
| + // The first element is always a timestamp. |
| + var cell = document.createElement('td'); |
| + var d = new Date(list[i][0]); |
| + cell.textContent = d.toString(); |
| + row.appendChild(cell); |
| + |
| + for (var j = 1; j < list[i].length; ++j) { |
| + var cell = document.createElement('td'); |
| + cell.textContent = list[i][j]; |
| + row.appendChild(cell); |
| + } |
| + if ((i % 2) == 0) |
| + row.className = 'odd-number-row'; |
| + table.appendChild(row); |
| + } |
| + } |
| + |
| + /** |
| + * Refresh all displayed information. |
| + */ |
| + function refreshAll() { |
| + chrome.send('getGcmInternalsInfo', [false]); |
| + } |
| + |
| + /** |
| + * Toggle the isRecording variable and send it to browser. |
| + */ |
| + function setRecording() { |
| + isRecording = !isRecording; |
| + chrome.send('setGcmInternalsRecording', [isRecording]); |
| + } |
| + |
| + /** |
| + * Clear all the activity logs. |
| + */ |
| + function clearLogs() { |
| + chrome.send('getGcmInternalsInfo', [true]); |
| } |
| function initialize() { |
| - chrome.send('getGcmInternalsInfo'); |
| + $('recording').disabled = true; |
| + $('refresh').onclick = refreshAll; |
| + $('recording').onclick = setRecording; |
| + $('clear-logs').onclick = clearLogs; |
| + chrome.send('getGcmInternalsInfo', [false]); |
| } |
| /** |
| @@ -43,9 +114,20 @@ cr.define('gcmInternals', function() { |
| * @param {!Object} infos A dictionary of info items to be displayed. |
| */ |
| function setGcmInternalsInfo(infos) { |
| + isRecording = infos.isRecording; |
| + if (isRecording) |
| + $('recording').textContent = 'Stop Recording'; |
| + else |
| + $('recording').textContent = 'Start Recording'; |
| + $('recording').disabled = false; |
| if (infos.deviceInfo !== undefined) { |
| displayDeviceInfo(infos.deviceInfo); |
| } |
| + |
| + removeAllChildNodes($('send-info')); |
| + if (infos.sendInfo !== undefined) { |
| + addRows($('send-info'), infos.sendInfo); |
| + } |
| } |
| // Return an object with all of the exports. |