| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 cr.define('chrome.invalidations', function() { | 5 cr.define('chrome.invalidations', function() { |
| 6 /** | 6 /** |
| 7 * Local variable where we maintain a count of the invalidations received | 7 * Local variable where we maintain a count of the invalidations received |
| 8 * and of every ObjectId that has ever been updated (note that this doesn't | 8 * and of every ObjectId that has ever been updated (note that this doesn't |
| 9 * log any invalidations ocurred prior to opening the about:invalidation | 9 * log any invalidations ocurred prior to opening the about:invalidation |
| 10 * page). | 10 * page). |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 function repaintTable() { | 40 function repaintTable() { |
| 41 var keys = []; | 41 var keys = []; |
| 42 for (var key in tableObjects) { | 42 for (var key in tableObjects) { |
| 43 keys.push(key); | 43 keys.push(key); |
| 44 } | 44 } |
| 45 keys.sort(); | 45 keys.sort(); |
| 46 var sortedInvalidations = []; | 46 var sortedInvalidations = []; |
| 47 for (var i = 0; i < keys.length; i++) { | 47 for (var i = 0; i < keys.length; i++) { |
| 48 sortedInvalidations.push(tableObjects[keys[i]]); | 48 sortedInvalidations.push(tableObjects[keys[i]]); |
| 49 } | 49 } |
| 50 var wrapped = { objectsidtable: sortedInvalidations }; | 50 var wrapped = {objectsidtable: sortedInvalidations}; |
| 51 jstProcess(new JsEvalContext(wrapped), $('objectsid-table-div')); | 51 jstProcess(new JsEvalContext(wrapped), $('objectsid-table-div')); |
| 52 } | 52 } |
| 53 | 53 |
| 54 /** | 54 /** |
| 55 * Shows the current state of the InvalidatorService. | 55 * Shows the current state of the InvalidatorService. |
| 56 * @param {string} newState The string to be displayed and logged. | 56 * @param {string} newState The string to be displayed and logged. |
| 57 * @param {number} lastChangedTime The time in epoch when the state was last | 57 * @param {number} lastChangedTime The time in epoch when the state was last |
| 58 * changed. | 58 * changed. |
| 59 */ | 59 */ |
| 60 function updateInvalidatorState(newState, lastChangedTime) { | 60 function updateInvalidatorState(newState, lastChangedTime) { |
| 61 var logMessage = nowTimeString() + | 61 var logMessage = nowTimeString() + |
| 62 'Invalidations service state changed to ' + quote(newState); | 62 'Invalidations service state changed to ' + quote(newState); |
| 63 | 63 |
| 64 appendToLog(logMessage); | 64 appendToLog(logMessage); |
| 65 $('invalidations-state').textContent = newState + ' (since ' + | 65 $('invalidations-state').textContent = |
| 66 new Date(lastChangedTime) + ')'; | 66 newState + ' (since ' + new Date(lastChangedTime) + ')'; |
| 67 } | 67 } |
| 68 | 68 |
| 69 /** | 69 /** |
| 70 * Adds to the log the latest invalidations received | 70 * Adds to the log the latest invalidations received |
| 71 * @param {!Array<!Object>} allInvalidations The array of ObjectId | 71 * @param {!Array<!Object>} allInvalidations The array of ObjectId |
| 72 * that contains the invalidations received by the InvalidatorService. | 72 * that contains the invalidations received by the InvalidatorService. |
| 73 */ | 73 */ |
| 74 function logInvalidations(allInvalidations) { | 74 function logInvalidations(allInvalidations) { |
| 75 for (var i = 0; i < allInvalidations.length; i++) { | 75 for (var i = 0; i < allInvalidations.length; i++) { |
| 76 var inv = allInvalidations[i]; | 76 var inv = allInvalidations[i]; |
| 77 if (inv.hasOwnProperty('objectId')) { | 77 if (inv.hasOwnProperty('objectId')) { |
| 78 var logMessage = nowTimeString() + | 78 var logMessage = nowTimeString() + 'Received Invalidation with type ' + |
| 79 'Received Invalidation with type ' + | 79 quote(inv.objectId.name) + ' version ' + |
| 80 quote(inv.objectId.name) + | 80 quote((inv.isUnknownVersion ? 'Unknown' : inv.version)) + |
| 81 ' version ' + | 81 ' with payload ' + quote(inv.payload); |
| 82 quote((inv.isUnknownVersion ? 'Unknown' : inv.version)) + | |
| 83 ' with payload ' + | |
| 84 quote(inv.payload); | |
| 85 | 82 |
| 86 appendToLog(logMessage); | 83 appendToLog(logMessage); |
| 87 var isInvalidation = true; | 84 var isInvalidation = true; |
| 88 logToTable(inv, isInvalidation); | 85 logToTable(inv, isInvalidation); |
| 89 } | 86 } |
| 90 } | 87 } |
| 91 repaintTable(); | 88 repaintTable(); |
| 92 } | 89 } |
| 93 | 90 |
| 94 /** | 91 /** |
| 95 * Marks a change in the table whether a new invalidation has arrived | 92 * Marks a change in the table whether a new invalidation has arrived |
| 96 * or a new ObjectId is currently being added or updated. | 93 * or a new ObjectId is currently being added or updated. |
| 97 * @param {!Object} oId The ObjectId being added or updated. | 94 * @param {!Object} oId The ObjectId being added or updated. |
| 98 * @param {!boolean} isInvaldation A flag that says that an invalidation | 95 * @param {!boolean} isInvaldation A flag that says that an invalidation |
| 99 * for this ObjectId has arrived or we just need to add it to the table | 96 * for this ObjectId has arrived or we just need to add it to the table |
| 100 * as it was just updated its state. | 97 * as it was just updated its state. |
| 101 */ | 98 */ |
| 102 function logToTable(oId, isInvalidation) { | 99 function logToTable(oId, isInvalidation) { |
| 103 var registrar = oId.registrar; | 100 var registrar = oId.registrar; |
| 104 var name = oId.objectId.name; | 101 var name = oId.objectId.name; |
| 105 var source = oId.objectId.source; | 102 var source = oId.objectId.source; |
| 106 var totalCount = oId.objectId.totalCount || 0; | 103 var totalCount = oId.objectId.totalCount || 0; |
| 107 var key = source + '-' + name; | 104 var key = source + '-' + name; |
| 108 var time = new Date(); | 105 var time = new Date(); |
| 109 var version = oId.isUnknownVersion ? '?' : | 106 var version = oId.isUnknownVersion ? '?' : oId.version; |
| 110 oId.version; | |
| 111 var payload = ''; | 107 var payload = ''; |
| 112 if (oId.hasOwnProperty('payload')) | 108 if (oId.hasOwnProperty('payload')) |
| 113 payload = oId.payload; | 109 payload = oId.payload; |
| 114 if (!(key in tableObjects)) { | 110 if (!(key in tableObjects)) { |
| 115 tableObjects[key] = { | 111 tableObjects[key] = { |
| 116 name: name, | 112 name: name, |
| 117 source: source, | 113 source: source, |
| 118 totalCount: totalCount, | 114 totalCount: totalCount, |
| 119 sessionCount: 0, | 115 sessionCount: 0, |
| 120 registrar: registrar, | 116 registrar: registrar, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 */ | 158 */ |
| 163 function updateIds(registrar, allIds) { | 159 function updateIds(registrar, allIds) { |
| 164 // Grey out every datatype assigned to this registrar | 160 // Grey out every datatype assigned to this registrar |
| 165 // (and reenable them later in case they are still registered). | 161 // (and reenable them later in case they are still registered). |
| 166 for (var key in tableObjects) { | 162 for (var key in tableObjects) { |
| 167 if (tableObjects[key]['registrar'] === registrar) | 163 if (tableObjects[key]['registrar'] === registrar) |
| 168 tableObjects[key].type = 'greyed'; | 164 tableObjects[key].type = 'greyed'; |
| 169 } | 165 } |
| 170 // Reenable those ObjectsIds still registered with this registrar. | 166 // Reenable those ObjectsIds still registered with this registrar. |
| 171 for (var i = 0; i < allIds.length; i++) { | 167 for (var i = 0; i < allIds.length; i++) { |
| 172 var oId = { objectId: allIds[i], registrar: registrar }; | 168 var oId = {objectId: allIds[i], registrar: registrar}; |
| 173 var isInvalidation = false; | 169 var isInvalidation = false; |
| 174 logToTable(oId, isInvalidation); | 170 logToTable(oId, isInvalidation); |
| 175 } | 171 } |
| 176 repaintTable(); | 172 repaintTable(); |
| 177 } | 173 } |
| 178 | 174 |
| 179 /** | 175 /** |
| 180 * Update the internal status display, merging new detailed information. | 176 * Update the internal status display, merging new detailed information. |
| 181 * @param {!Object} newDetails The dictionary containing assorted debugging | 177 * @param {!Object} newDetails The dictionary containing assorted debugging |
| 182 * details (e.g. Network Channel information). | 178 * details (e.g. Network Channel information). |
| (...skipping 21 matching lines...) Expand all Loading... |
| 204 logInvalidations: logInvalidations, | 200 logInvalidations: logInvalidations, |
| 205 onLoadWork: onLoadWork, | 201 onLoadWork: onLoadWork, |
| 206 updateDetailedStatus: updateDetailedStatus, | 202 updateDetailedStatus: updateDetailedStatus, |
| 207 updateHandlers: updateHandlers, | 203 updateHandlers: updateHandlers, |
| 208 updateIds: updateIds, | 204 updateIds: updateIds, |
| 209 updateInvalidatorState: updateInvalidatorState, | 205 updateInvalidatorState: updateInvalidatorState, |
| 210 }; | 206 }; |
| 211 }); | 207 }); |
| 212 | 208 |
| 213 document.addEventListener('DOMContentLoaded', chrome.invalidations.onLoadWork); | 209 document.addEventListener('DOMContentLoaded', chrome.invalidations.onLoadWork); |
| OLD | NEW |