1 // Copyright (c) 2012 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.
7 // TODO(akalin): Use table.js.
9 function updateNotificationStateInfo(notificationState) {
10 var notificationStateInfo = $('notificationStateInfo');
12 new JsEvalContext({ 'notificationState': notificationState }),
13 notificationStateInfo);
16 // Contains all notification data. The keys are sync types (as strings) and
17 // the value is a dictionary with:
19 // type: the sync type again (for convenience when using JsTemplate)
20 // totalCount: Number of notifications received since browser start.
21 // sessionCount: Number of notifications received this
22 // chrome://sync-internals session.
23 // payload: The last received payload.
25 chrome.sync.notifications = {};
28 * Merges d1 and d2 (with d2 taking precedence) and returns the result.
30 function mergeDictionaries(d1, d2) {
42 * Merge notificationInfo into chrome.sync.notifications.
44 function updateNotificationsFromNotificationInfo(notificationInfo) {
45 for (var k in notificationInfo) {
46 chrome.sync.notifications[k] =
47 mergeDictionaries(chrome.sync.notifications[k] || {},
49 // notificationInfo[k] has values for the totalCount and payload keys,
50 // so fill in the rest (if necessary).
51 chrome.sync.notifications[k].type = k;
52 chrome.sync.notifications[k].sessionCount =
53 chrome.sync.notifications[k].sessionCount || 0;
57 function incrementSessionNotificationCount(changedType) {
58 chrome.sync.notifications[changedType].sessionCount =
59 chrome.sync.notifications[changedType].sessionCount || 0;
60 ++chrome.sync.notifications[changedType].sessionCount;
63 function updateNotificationInfoTable() {
64 var notificationInfoTable = $('notificationInfo');
66 for (var k in chrome.sync.notifications) {
67 infos.push(chrome.sync.notifications[k]);
69 jstProcess(new JsEvalContext({ 'notifications': infos }),
70 notificationInfoTable);
73 function updateNotificationInfo(notificationInfo) {
74 updateNotificationsFromNotificationInfo(notificationInfo);
75 updateNotificationInfoTable();
79 chrome.sync.getNotificationState(updateNotificationStateInfo);
80 chrome.sync.getNotificationInfo(updateNotificationInfo);
81 chrome.sync.onNotificationStateChange.addListener(
82 function(details) { updateNotificationStateInfo(details.state); });
84 chrome.sync.onIncomingNotification.addListener(function(details) {
85 var changedTypes = details.changedTypes;
86 for (var i = 0; i < changedTypes.length; ++i) {
87 incrementSessionNotificationCount(changedTypes[i]);
89 updateNotificationInfoTable();
91 // Also update total counts.
92 chrome.sync.getNotificationInfo(updateNotificationInfo);
96 document.addEventListener('DOMContentLoaded', onLoad, false);