| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 log_util = (function() { | 5 log_util = (function() { |
| 6 'use strict'; | 6 'use strict'; |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * Creates a new log dump. |events| is a list of all events, |polledData| is | 9 * Creates a new log dump. |events| is a list of all events, |polledData| is |
| 10 * an object containing the results of each poll, |tabData| is an object | 10 * an object containing the results of each poll, |tabData| is an object |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 * Returns a new log dump created using the polled data and date from the | 56 * Returns a new log dump created using the polled data and date from the |
| 57 * |oldLogDump|. The other parts of the log dump come from current | 57 * |oldLogDump|. The other parts of the log dump come from current |
| 58 * net-internals state. | 58 * net-internals state. |
| 59 */ | 59 */ |
| 60 function createUpdatedLogDump(userComments, oldLogDump, securityStripping) { | 60 function createUpdatedLogDump(userComments, oldLogDump, securityStripping) { |
| 61 var numericDate = null; | 61 var numericDate = null; |
| 62 if (oldLogDump.constants.clientInfo && | 62 if (oldLogDump.constants.clientInfo && |
| 63 oldLogDump.constants.clientInfo.numericDate) { | 63 oldLogDump.constants.clientInfo.numericDate) { |
| 64 numericDate = oldLogDump.constants.clientInfo.numericDate; | 64 numericDate = oldLogDump.constants.clientInfo.numericDate; |
| 65 } | 65 } |
| 66 var logDump = createLogDump(userComments, | 66 var logDump = createLogDump( |
| 67 Constants, | 67 userComments, |
| 68 g_browser.sourceTracker.getAllCapturedEvents(), | 68 Constants, |
| 69 oldLogDump.polledData, | 69 EventsTracker.getInstance().getAllCapturedEvents(), |
| 70 getTabData_(), | 70 oldLogDump.polledData, |
| 71 numericDate, | 71 getTabData_(), |
| 72 securityStripping); | 72 numericDate, |
| 73 securityStripping); |
| 73 return JSON.stringify(logDump, null, ' '); | 74 return JSON.stringify(logDump, null, ' '); |
| 74 } | 75 } |
| 75 | 76 |
| 76 /** | 77 /** |
| 77 * Creates a full log dump using |polledData| and the return value of each | 78 * Creates a full log dump using |polledData| and the return value of each |
| 78 * tab's saveState function and passes it to |callback|. | 79 * tab's saveState function and passes it to |callback|. |
| 79 */ | 80 */ |
| 80 function onUpdateAllCompleted(userComments, callback, securityStripping, | 81 function onUpdateAllCompleted(userComments, callback, securityStripping, |
| 81 polledData) { | 82 polledData) { |
| 82 var logDump = createLogDump(userComments, | 83 var logDump = createLogDump( |
| 83 Constants, | 84 userComments, |
| 84 g_browser.sourceTracker.getAllCapturedEvents(), | 85 Constants, |
| 85 polledData, | 86 EventsTracker.getInstance().getAllCapturedEvents(), |
| 86 getTabData_(), | 87 polledData, |
| 87 timeutil.getCurrentTime(), | 88 getTabData_(), |
| 88 securityStripping); | 89 timeutil.getCurrentTime(), |
| 90 securityStripping); |
| 89 callback(JSON.stringify(logDump, null, ' ')); | 91 callback(JSON.stringify(logDump, null, ' ')); |
| 90 } | 92 } |
| 91 | 93 |
| 92 /** | 94 /** |
| 93 * Called to create a new log dump. Must not be called once a dump has been | 95 * Called to create a new log dump. Must not be called once a dump has been |
| 94 * loaded. Once a log dump has been created, |callback| is passed the dumped | 96 * loaded. Once a log dump has been created, |callback| is passed the dumped |
| 95 * text as a string. | 97 * text as a string. |
| 96 */ | 98 */ |
| 97 function createLogDumpAsync(userComments, callback, securityStripping) { | 99 function createLogDumpAsync(userComments, callback, securityStripping) { |
| 98 g_browser.updateAllInfo( | 100 g_browser.updateAllInfo( |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 ClientInfo.numericDate = 0; | 209 ClientInfo.numericDate = 0; |
| 208 } | 210 } |
| 209 } | 211 } |
| 210 | 212 |
| 211 // Prevent communication with the browser. Once the constants have been | 213 // Prevent communication with the browser. Once the constants have been |
| 212 // loaded, it's safer to continue trying to load the log, even in the case | 214 // loaded, it's safer to continue trying to load the log, even in the case |
| 213 // of bad data. | 215 // of bad data. |
| 214 MainView.getInstance().onLoadLog(opt_fileName); | 216 MainView.getInstance().onLoadLog(opt_fileName); |
| 215 | 217 |
| 216 // Delete all events. This will also update all logObservers. | 218 // Delete all events. This will also update all logObservers. |
| 217 g_browser.sourceTracker.deleteAllSourceEntries(); | 219 EventsTracker.getInstance().deleteAllLogEntries(); |
| 218 | 220 |
| 219 // Inform all the views that a log file is being loaded, and pass in | 221 // Inform all the views that a log file is being loaded, and pass in |
| 220 // view-specific saved state, if any. | 222 // view-specific saved state, if any. |
| 221 var categoryTabSwitcher = MainView.getInstance().categoryTabSwitcher(); | 223 var categoryTabSwitcher = MainView.getInstance().categoryTabSwitcher(); |
| 222 var tabIds = categoryTabSwitcher.getAllTabIds(); | 224 var tabIds = categoryTabSwitcher.getAllTabIds(); |
| 223 for (var i = 0; i < tabIds.length; ++i) { | 225 for (var i = 0; i < tabIds.length; ++i) { |
| 224 var view = categoryTabSwitcher.findTabById(tabIds[i]).contentView; | 226 var view = categoryTabSwitcher.findTabById(tabIds[i]).contentView; |
| 225 view.onLoadLogStart(logDump.polledData, logDump.tabData[tabIds[i]]); | 227 view.onLoadLogStart(logDump.polledData, logDump.tabData[tabIds[i]]); |
| 226 } | 228 } |
| 227 g_browser.sourceTracker.onReceivedLogEntries(validEvents); | 229 EventsTracker.getInstance().addLogEntries(validEvents); |
| 228 | 230 |
| 229 var numInvalidEvents = logDump.events.length - | 231 var numInvalidEvents = logDump.events.length - |
| 230 (validEvents.length + numDeprecatedPassiveEvents); | 232 (validEvents.length + numDeprecatedPassiveEvents); |
| 231 if (numInvalidEvents > 0) { | 233 if (numInvalidEvents > 0) { |
| 232 errorString += 'Unable to load ' + numInvalidEvents + | 234 errorString += 'Unable to load ' + numInvalidEvents + |
| 233 ' events, due to invalid data.\n\n'; | 235 ' events, due to invalid data.\n\n'; |
| 234 } | 236 } |
| 235 | 237 |
| 236 if (numDeprecatedPassiveEvents > 0) { | 238 if (numDeprecatedPassiveEvents > 0) { |
| 237 errorString += 'Discarded ' + numDeprecatedPassiveEvents + | 239 errorString += 'Discarded ' + numDeprecatedPassiveEvents + |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 return loadLogDump(parsedDump, fileName); | 292 return loadLogDump(parsedDump, fileName); |
| 291 } | 293 } |
| 292 | 294 |
| 293 // Exports. | 295 // Exports. |
| 294 return { | 296 return { |
| 295 createUpdatedLogDump: createUpdatedLogDump, | 297 createUpdatedLogDump: createUpdatedLogDump, |
| 296 createLogDumpAsync: createLogDumpAsync, | 298 createLogDumpAsync: createLogDumpAsync, |
| 297 loadLogFile: loadLogFile | 299 loadLogFile: loadLogFile |
| 298 }; | 300 }; |
| 299 })(); | 301 })(); |
| OLD | NEW |