| 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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 // NOTE: Up until Chrome 18, log dumps included "passively captured" | 159 // NOTE: Up until Chrome 18, log dumps included "passively captured" |
| 160 // events. These are no longer supported, so skip past them | 160 // events. These are no longer supported, so skip past them |
| 161 // to avoid confusing the rest of the code. | 161 // to avoid confusing the rest of the code. |
| 162 numDeprecatedPassiveEvents++; | 162 numDeprecatedPassiveEvents++; |
| 163 continue; | 163 continue; |
| 164 } | 164 } |
| 165 validEvents.push(event); | 165 validEvents.push(event); |
| 166 } | 166 } |
| 167 } | 167 } |
| 168 | 168 |
| 169 // Make sure the loaded log contained an export date. If not we will | 169 // Determine the export date for the loaded log. |
| 170 // synthesize one. This can legitimately happen for dump files created | 170 // |
| 171 // via command line flag, or for older dump formats (before Chrome 17). | 171 // Dumps created from chrome://net-internals (Chrome 17 - Chrome 59) will |
| 172 // have this set in constants.clientInfo.numericDate. |
| 173 // |
| 174 // However more recent dumping mechanisms (chrome://net-export/ and |
| 175 // --log-net-log) write the constants object directly to a file when the |
| 176 // dump is *started* so lack this ability. |
| 177 // |
| 178 // In this case, we will synthesize this field by looking at the timestamp |
| 179 // of the last event logged. In practice this works fine since there tend |
| 180 // to be lots of events logged. |
| 181 // |
| 182 // TODO(eroman): Fix the log format / writers to avoid this problem. Dumps |
| 183 // *should* contain the time when capturing started, and when capturing |
| 184 // ended. |
| 172 if (typeof logDump.constants.clientInfo.numericDate != 'number') { | 185 if (typeof logDump.constants.clientInfo.numericDate != 'number') { |
| 173 errorString += 'The log file is missing clientInfo.numericDate.\n'; | |
| 174 | |
| 175 if (validEvents.length > 0) { | 186 if (validEvents.length > 0) { |
| 176 errorString += | |
| 177 'Synthesizing export date as time of last event captured.\n'; | |
| 178 var lastEvent = validEvents[validEvents.length - 1]; | 187 var lastEvent = validEvents[validEvents.length - 1]; |
| 179 ClientInfo.numericDate = | 188 ClientInfo.numericDate = |
| 180 timeutil.convertTimeTicksToDate(lastEvent.time).getTime(); | 189 timeutil.convertTimeTicksToDate(lastEvent.time).getTime(); |
| 181 } else { | 190 } else { |
| 182 errorString += 'Can\'t guess export date!\n'; | 191 errorString += 'Can\'t guess export date as there are no events.\n'; |
| 183 ClientInfo.numericDate = 0; | 192 ClientInfo.numericDate = 0; |
| 184 } | 193 } |
| 185 } | 194 } |
| 186 | 195 |
| 187 // Prevent communication with the browser. Once the constants have been | 196 // Prevent communication with the browser. Once the constants have been |
| 188 // loaded, it's safer to continue trying to load the log, even in the case | 197 // loaded, it's safer to continue trying to load the log, even in the case |
| 189 // of bad data. | 198 // of bad data. |
| 190 MainView.getInstance().onLoadLog(opt_fileName); | 199 MainView.getInstance().onLoadLog(opt_fileName); |
| 191 | 200 |
| 192 // Delete all events. This will also update all logObservers. | 201 // Delete all events. This will also update all logObservers. |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 } | 275 } |
| 267 | 276 |
| 268 if (!parsedDump) | 277 if (!parsedDump) |
| 269 return 'Unable to parse log dump as JSON file.'; | 278 return 'Unable to parse log dump as JSON file.'; |
| 270 return errorString + loadLogDump(parsedDump, fileName); | 279 return errorString + loadLogDump(parsedDump, fileName); |
| 271 } | 280 } |
| 272 | 281 |
| 273 // Exports. | 282 // Exports. |
| 274 return {createLogDumpAsync: createLogDumpAsync, loadLogFile: loadLogFile}; | 283 return {createLogDumpAsync: createLogDumpAsync, loadLogFile: loadLogFile}; |
| 275 })(); | 284 })(); |
| OLD | NEW |