Elim cr-checkbox
[chromium-blink-merge.git] / chrome / browser / resources / sync_file_system_internals / sync_service.js
blobb5a2578ee3dcb0ab82f231285113efcca9d8bd02
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.
5 /**
6 * WebUI to monitor the Sync File System Service.
7 */
8 var SyncService = (function() {
9 'use strict';
11 var SyncService = {};
13 /**
14 * Request Sync Service Status.
16 function getServiceStatus() {
17 chrome.send('getServiceStatus');
20 /**
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;
28 /**
29 * Request Google Drive Notification Source. e.g. XMPP or polling.
31 function getNotificationSource() {
32 chrome.send('getNotificationSource');
35 /**
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;
46 /**
47 * Request debug log.
49 function getLog() {
50 chrome.send('getLog', [lastLogEventId]);
53 /**
54 * Clear old logs.
56 function clearLogs() {
57 chrome.send('clearLogs');
58 $('log-entries').innerHTML = '';
61 /**
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;
81 /**
82 * Get initial sync service values and set listeners to get updated values.
84 function main() {
85 cr.ui.decorate('tabbox', cr.ui.TabBox);
86 $('clear-log-button').addEventListener('click', clearLogs);
87 getServiceStatus();
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);
95 return SyncService;
96 })();