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
3 // found in the LICENSE file.
6 * WebUI to monitor the Sync File System Service.
8 var SyncService = (function() {
14 * Request Sync Service Status.
16 function getServiceStatus() {
17 chrome.send('getServiceStatus');
21 * Called when service status is initially retrieved or updated via events.
22 * @param {string} Service status enum as a string.
24 SyncService.onGetServiceStatus = function(statusString) {
25 $('service-status').textContent = statusString;
29 * Request Google Drive Notification Source. e.g. XMPP or polling.
31 function getNotificationSource() {
32 chrome.send('getNotificationSource');
36 * Handles callback from getNotificationSource.
37 * @param {string} Notification source as a string.
39 SyncService.onGetNotificationSource = function(sourceString) {
40 $('notification-source').textContent = sourceString;
43 // Keeps track of the last log event seen so it's not reprinted.
44 var lastLogEventId = -1;
50 chrome.send('getLog', [lastLogEventId]);
56 function clearLogs() {
57 chrome.send('clearLogs');
58 $('log-entries').innerHTML = '';
62 * Handles callback from getUpdateLog.
63 * @param {Array} list List of dictionaries containing 'id', 'time', 'logEvent'.
65 SyncService.onGetLog = function(logEntries) {
66 var itemContainer = $('log-entries');
67 for (var i = 0; i < logEntries.length; i++) {
68 var logEntry = logEntries[i];
69 var tr = document.createElement('tr');
70 var error = /ERROR/.test(logEntry.logEvent) ? ' error' : '';
71 tr.appendChild(createElementFromText('td', logEntry.time,
72 {class: 'log-time'}));
73 tr.appendChild(createElementFromText('td', logEntry.logEvent,
74 {class: 'log-event' + error}));
75 itemContainer.appendChild(tr);
77 lastLogEventId = logEntry.id;
82 * Get initial sync service values and set listeners to get updated values.
85 cr.ui.decorate('tabbox', cr.ui.TabBox);
86 $('clear-log-button').addEventListener('click', clearLogs);
88 getNotificationSource();
90 // TODO: Look for a way to push entries to the page when necessary.
91 window.setInterval(getLog, 1000);
94 document.addEventListener('DOMContentLoaded', main);