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