| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 * WebUI to monitor the Sync File System Service. | 6 * WebUI to monitor the Sync File System Service. |
| 7 */ | 7 */ |
| 8 var SyncService = (function() { | 8 var SyncService = (function() { |
| 9 'use strict'; | 9 'use strict'; |
| 10 | 10 |
| 11 var SyncService = {}; | 11 var SyncService = {}; |
| 12 | 12 |
| 13 /** | 13 /** |
| 14 * Request Sync Service Status. | 14 * Request Sync Service Status. |
| 15 */ | 15 */ |
| 16 function getServiceStatus() { | 16 function getServiceStatus() { |
| 17 chrome.send('getServiceStatus'); | 17 chrome.send('getServiceStatus'); |
| 18 } | 18 } |
| 19 | 19 |
| 20 /** | 20 /** |
| 21 * Called when service status is initially retrieved or updated via events. | 21 * Called when service status is initially retrieved or updated via events. |
| 22 * @param {string} Service status enum as a string. | 22 * @param {string} Service status enum as a string. |
| 23 */ | 23 */ |
| 24 SyncService.onGetServiceStatus = function(statusString) { | 24 SyncService.onGetServiceStatus = |
| 25 $('service-status').textContent = statusString; | 25 function(statusString) { |
| 26 } | 26 $('service-status').textContent = statusString; |
| 27 } |
| 27 | 28 |
| 28 /** | 29 /** |
| 29 * Request Google Drive Notification Source. e.g. XMPP or polling. | 30 * Request Google Drive Notification Source. e.g. XMPP or polling. |
| 30 */ | 31 */ |
| 31 function getNotificationSource() { | 32 function |
| 32 chrome.send('getNotificationSource'); | 33 getNotificationSource() { |
| 33 } | 34 chrome.send('getNotificationSource'); |
| 35 } |
| 34 | 36 |
| 35 /** | 37 /** |
| 36 * Handles callback from getNotificationSource. | 38 * Handles callback from getNotificationSource. |
| 37 * @param {string} Notification source as a string. | 39 * @param {string} Notification source as a string. |
| 38 */ | 40 */ |
| 39 SyncService.onGetNotificationSource = function(sourceString) { | 41 SyncService.onGetNotificationSource = |
| 40 $('notification-source').textContent = sourceString; | 42 function(sourceString) { |
| 41 } | 43 $('notification-source').textContent = sourceString; |
| 44 } |
| 42 | 45 |
| 43 // Keeps track of the last log event seen so it's not reprinted. | 46 // Keeps track of the last log event seen so it's not reprinted. |
| 44 var lastLogEventId = -1; | 47 var lastLogEventId = -1; |
| 45 | 48 |
| 46 /** | 49 /** |
| 47 * Request debug log. | 50 * Request debug log. |
| 48 */ | 51 */ |
| 49 function getLog() { | 52 function getLog() { |
| 50 chrome.send('getLog', [lastLogEventId]); | 53 chrome.send('getLog', [lastLogEventId]); |
| 51 } | 54 } |
| 52 | 55 |
| 53 /** | 56 /** |
| 54 * Clear old logs. | 57 * Clear old logs. |
| 55 */ | 58 */ |
| 56 function clearLogs() { | 59 function clearLogs() { |
| 57 chrome.send('clearLogs'); | 60 chrome.send('clearLogs'); |
| 58 $('log-entries').innerHTML = ''; | 61 $('log-entries').innerHTML = ''; |
| 59 } | 62 } |
| 60 | 63 |
| 61 /** | 64 /** |
| 62 * Handles callback from getUpdateLog. | 65 * Handles callback from getUpdateLog. |
| 63 * @param {Array} list List of dictionaries containing 'id', 'time', 'logEvent'. | 66 * @param {Array} list List of dictionaries containing 'id', 'time', |
| 64 */ | 67 * 'logEvent'. |
| 65 SyncService.onGetLog = function(logEntries) { | 68 */ |
| 66 var itemContainer = $('log-entries'); | 69 SyncService.onGetLog = |
| 67 for (var i = 0; i < logEntries.length; i++) { | 70 function(logEntries) { |
| 68 var logEntry = logEntries[i]; | 71 var itemContainer = $('log-entries'); |
| 69 var tr = document.createElement('tr'); | 72 for (var i = 0; i < logEntries.length; i++) { |
| 70 var error = /ERROR/.test(logEntry.logEvent) ? ' error' : ''; | 73 var logEntry = logEntries[i]; |
| 71 tr.appendChild(createElementFromText('td', logEntry.time, | 74 var tr = document.createElement('tr'); |
| 72 {'class': 'log-time'})); | 75 var error = /ERROR/.test(logEntry.logEvent) ? ' error' : ''; |
| 73 tr.appendChild(createElementFromText('td', logEntry.logEvent, | 76 tr.appendChild( |
| 74 {'class': 'log-event' + error})); | 77 createElementFromText('td', logEntry.time, {'class': 'log-time'})); |
| 75 itemContainer.appendChild(tr); | 78 tr.appendChild(createElementFromText( |
| 79 'td', logEntry.logEvent, {'class': 'log-event' + error})); |
| 80 itemContainer.appendChild(tr); |
| 76 | 81 |
| 77 lastLogEventId = logEntry.id; | 82 lastLogEventId = logEntry.id; |
| 83 } |
| 78 } | 84 } |
| 79 } | |
| 80 | 85 |
| 81 /** | 86 /** |
| 82 * Get initial sync service values and set listeners to get updated values. | 87 * Get initial sync service values and set listeners to get updated |
| 83 */ | 88 * values. |
| 84 function main() { | 89 */ |
| 85 cr.ui.decorate('tabbox', cr.ui.TabBox); | 90 function |
| 86 $('clear-log-button').addEventListener('click', clearLogs); | 91 main() { |
| 87 getServiceStatus(); | 92 cr.ui.decorate('tabbox', cr.ui.TabBox); |
| 88 getNotificationSource(); | 93 $('clear-log-button').addEventListener('click', clearLogs); |
| 94 getServiceStatus(); |
| 95 getNotificationSource(); |
| 89 | 96 |
| 90 // TODO: Look for a way to push entries to the page when necessary. | 97 // TODO: Look for a way to push entries to the page when necessary. |
| 91 window.setInterval(getLog, 1000); | 98 window.setInterval(getLog, 1000); |
| 92 } | 99 } |
| 93 | 100 |
| 94 document.addEventListener('DOMContentLoaded', main); | 101 document.addEventListener('DOMContentLoaded', main); |
| 95 return SyncService; | 102 return SyncService; |
| 96 })(); | 103 })(); |
| OLD | NEW |