summaryrefslogtreecommitdiffstats
path: root/chrome/browser/resources/sync_file_system_internals/sync_service.js
blob: 9c9d0e8e3cdfa10ee7f7e99a7f656295be97c63f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

/**
 * WebUI to monitor the Sync File System Service.
 */
var SyncService = (function() {
'use strict';

var SyncService = {};

/**
 * Request Sync Service Status.
 */
function getServiceStatus() {
  chrome.send('getServiceStatus');
}

/**
 * Called when service status is initially retrieved or updated via events.
 * @param {string} Service status enum as a string.
 */
SyncService.onGetServiceStatus = function(statusString) {
  $('service-status').textContent = statusString;
}

/**
 * Request Google Drive Notification Source. e.g. XMPP or polling.
 */
function getNotificationSource() {
  chrome.send('getNotificationSource');
}

/**
 * Handles callback from getNotificationSource.
 * @param {string} Notification source as a string.
 */
SyncService.onGetNotificationSource = function(sourceString) {
  $('notification-source').textContent = sourceString;
}

// Keeps track of the last log event seen so it's not reprinted.
var lastLogEventId = -1;

/**
 * Request debug log.
 */
function getLog() {
  chrome.send('getLog', [lastLogEventId]);
}

/**
 * Clear old logs.
 */
function clearLogs() {
  chrome.send('clearLogs');
  $('log-entries').innerHTML = '';
}

/**
 * Handles callback from getUpdateLog.
 * @param {Array} list List of dictionaries containing 'id', 'time', 'logEvent'.
 */
SyncService.onGetLog = function(logEntries) {
  var itemContainer = $('log-entries');
  for (var i = 0; i < logEntries.length; i++) {
    var logEntry = logEntries[i];
    var tr = document.createElement('tr');
    var error = /ERROR/.test(logEntry.logEvent) ? ' error' : '';
    tr.appendChild(createElementFromText('td', logEntry.time,
                                         {class: 'log-time'}));
    tr.appendChild(createElementFromText('td', logEntry.logEvent,
                                         {class: 'log-event' + error}));
    itemContainer.appendChild(tr);

    lastLogEventId = logEntry.id;
  }
}

/**
 * Get initial sync service values and set listeners to get updated values.
 */
function main() {
  cr.ui.decorate('tabbox', cr.ui.TabBox);
  $('clear-log-button').addEventListener('click', clearLogs);
  getServiceStatus();
  getNotificationSource();

  // TODO: Look for a way to push entries to the page when necessary.
  window.setInterval(getLog, 1000);
}

document.addEventListener('DOMContentLoaded', main);
return SyncService;
})();