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