Chromium Code Reviews| Index: chrome/browser/resources/sync_internals/notifications.html |
| diff --git a/chrome/browser/resources/sync_internals/notifications.html b/chrome/browser/resources/sync_internals/notifications.html |
| index dccc68c90f61380b22ed43a564069ef704486989..bb430159ab4f5a54587d2af9acfb688a1daa7ced 100644 |
| --- a/chrome/browser/resources/sync_internals/notifications.html |
| +++ b/chrome/browser/resources/sync_internals/notifications.html |
| @@ -1,9 +1,7 @@ |
| <script> |
| (function () { |
| -// Contains all notifications received since the page was loaded as a |
| -// map from each data type to the number of notifications received for |
| -// it. |
| -chrome.sync.notifications = {}; |
| + |
| +// TODO(akalin): Use table.js. |
| function updateNotificationsEnabledInfo(notificationsEnabled) { |
| var notificationsEnabledInfo = |
| @@ -13,13 +11,59 @@ function updateNotificationsEnabledInfo(notificationsEnabled) { |
| notificationsEnabledInfo); |
| } |
| -function updateNotificationInfo(notification) { |
| - var notificationInfo = document.getElementById('notificationInfo'); |
| - jstProcess( |
| - new JsEvalContext({ |
| - 'notificationInfo': JSON.stringify(notification, null, 2) |
| - }), |
| - notificationInfo); |
| +// Contains all notifications received since the page was loaded as a |
| +// map from each data type to the number of notifications received for |
| +// it. |
| +chrome.sync.notifications = {}; |
| + |
| +/** |
| + * Merges d1 and d2 (with d2 taking precedence) and returns the result. |
| + */ |
| +function mergeDictionaries(d1, d2) { |
| + var d = {}; |
| + for (var k in d1) { |
| + d[k] = d1[k]; |
| + } |
| + for (var k in d2) { |
| + d[k] = d2[k]; |
| + } |
| + return d; |
| +} |
| + |
| +/** |
| + * Merge notificationInfo into chrome.sync.notifications. |
| + */ |
| +function updateNotificationsFromNotificationInfo(notificationInfo) { |
| + for (var k in notificationInfo) { |
| + chrome.sync.notifications[k] = |
| + mergeDictionaries(chrome.sync.notifications[k] || {}, |
| + notificationInfo[k]); |
| + chrome.sync.notifications[k].type = k; |
|
Nicolas Zea
2011/05/12 23:38:09
Is this information not in the original notificati
akalin
2011/05/13 00:10:18
It is, but only as the key. I'm stuffing it into
|
| + chrome.sync.notifications[k].sessionCount = |
| + chrome.sync.notifications[k].sessionCount || 0; |
| + } |
| +} |
| + |
| +function incrementSessionNotificationCount(changedType) { |
| + chrome.sync.notifications[changedType].sessionCount = |
|
Nicolas Zea
2011/05/12 23:38:09
Is it possible this data will be overwritten when
akalin
2011/05/13 00:10:18
No, because we don't only the sessionCount in this
|
| + chrome.sync.notifications[changedType].sessionCount || 0; |
| + ++chrome.sync.notifications[changedType].sessionCount; |
| +} |
| + |
| +function updateNotificationInfoTable() { |
| + var notificationInfoTable = |
| + document.getElementById('notificationInfo'); |
| + var infos = []; |
| + for (var k in chrome.sync.notifications) { |
| + infos.push(chrome.sync.notifications[k]); |
| + } |
| + jstProcess(new JsEvalContext({ 'notifications': infos }), |
| + notificationInfoTable); |
| +} |
| + |
| +function updateNotificationInfo(notificationInfo) { |
| + updateNotificationsFromNotificationInfo(notificationInfo); |
| + updateNotificationInfoTable(); |
| } |
| function onLoad() { |
| @@ -31,25 +75,11 @@ function onLoad() { |
| chrome.sync.onIncomingNotification.addListener(function(details) { |
| var changedTypes = details.changedTypes; |
| for (var i = 0; i < changedTypes.length; ++i) { |
| - var changedType = changedTypes[i]; |
| - chrome.sync.notifications[changedType] = |
| - chrome.sync.notifications[changedType] || 0; |
| - ++chrome.sync.notifications[changedType]; |
| + incrementSessionNotificationCount(changedTypes[i]); |
| } |
| + updateNotificationInfoTable(); |
| - var infos = []; |
| - for (var k in chrome.sync.notifications) { |
| - var info = { |
| - 'modelType': k, |
| - 'notificationCount': chrome.sync.notifications[k] |
| - }; |
| - infos.push(info); |
| - } |
| - |
| - var notificationsInfo = |
| - document.getElementById('notificationsInfo'); |
| - jstProcess(new JsEvalContext({ 'notifications': infos }), |
| - notificationsInfo); |
| + // Also update total counts. |
| chrome.sync.getNotificationInfo(updateNotificationInfo); |
| }); |
| } |
| @@ -59,7 +89,7 @@ document.addEventListener("DOMContentLoaded", onLoad, false); |
| </script> |
| <style> |
| -table#notificationsInfo tr:nth-child(odd) { |
| +table#notificationInfo tr:nth-child(odd) { |
| background: #eff3ff; |
| } |
| </style> |
| @@ -67,10 +97,17 @@ table#notificationsInfo tr:nth-child(odd) { |
| <p id='notificationsEnabledInfo'> |
| Enabled: <span jscontent='notificationsEnabled'></span> |
| </p> |
| -<pre id='notificationInfo'><span jscontent='notificationInfo'></span></pre> |
| -<table id='notificationsInfo'> |
| +<table id='notificationInfo'> |
| + <tr> |
| + <th>Type</th> |
| + <th>Total count</th> |
| + <th>Session count</th> |
| + <th>Payload</th> |
| + </tr> |
| <tr jsselect='notifications'> |
| - <td jscontent='modelType'/> |
| - <td jscontent='notificationCount'/> |
| + <td jscontent='type'/> |
| + <td jscontent='totalCount'/> |
| + <td jscontent='sessionCount'/> |
| + <td jscontent='payload'/> |
| </tr> |
| </table> |