| 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 var SourceTracker = (function() { | 5 var SourceTracker = (function() { |
| 6 'use strict'; | 6 'use strict'; |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * This class keeps track of all NetLog events. | 9 * This class keeps track of all NetLog events, grouped into per-source |
| 10 * It receives events from the browser and when loading a log file, and passes | 10 * streams. It receives events from EventsTracker, and passes |
| 11 * them on to all its observers. | 11 * them on to all its observers. |
| 12 * | 12 * |
| 13 * @constructor | 13 * @constructor |
| 14 */ | 14 */ |
| 15 function SourceTracker() { | 15 function SourceTracker() { |
| 16 // Observers that are sent all events as they happen. This allows for easy | 16 assertFirstConstructorCall(SourceTracker); |
| 17 // watching for particular events. | |
| 18 this.logEntryObservers_ = []; | |
| 19 | 17 |
| 20 // Observers that only want to receive lists of updated SourceEntries. | 18 // Observers that only want to receive lists of updated SourceEntries. |
| 21 this.sourceEntryObservers_ = []; | 19 this.sourceEntryObservers_ = []; |
| 22 | 20 |
| 23 // True when cookies and authentication information should be removed from | 21 // True when cookies and authentication information should be removed from |
| 24 // displayed events. When true, such information should be hidden from | 22 // displayed events. When true, such information should be hidden from |
| 25 // all pages. | 23 // all pages. |
| 26 this.enableSecurityStripping_ = true; | 24 this.enableSecurityStripping_ = true; |
| 27 | 25 |
| 28 this.clearEntries_(); | 26 this.clearEntries_(); |
| 27 |
| 28 EventsTracker.getInstance().addLogEntryObserver(this); |
| 29 } | 29 } |
| 30 | 30 |
| 31 cr.addSingletonGetter(SourceTracker); |
| 32 |
| 31 SourceTracker.prototype = { | 33 SourceTracker.prototype = { |
| 32 /** | 34 /** |
| 33 * Clears all log entries and SourceEntries and related state. | 35 * Clears all log entries and SourceEntries and related state. |
| 34 */ | 36 */ |
| 35 clearEntries_: function() { | 37 clearEntries_: function() { |
| 36 // Used for sorting entries with automatically assigned IDs. | 38 // Used for sorting entries with automatically assigned IDs. |
| 37 this.maxReceivedSourceId_ = 0; | 39 this.maxReceivedSourceId_ = 0; |
| 38 | 40 |
| 39 // Next unique id to be assigned to a log entry without a source. | 41 // Next unique id to be assigned to a log entry without a source. |
| 40 // Needed to identify associated GUI elements, etc. | 42 // Needed to identify associated GUI elements, etc. |
| 41 this.nextSourcelessEventId_ = -1; | 43 this.nextSourcelessEventId_ = -1; |
| 42 | 44 |
| 43 // Ordered list of log entries. Needed to maintain original order when | 45 // Ordered list of log entries. Needed to maintain original order when |
| 44 // generating log dumps | 46 // generating log dumps |
| 45 this.capturedEvents_ = []; | 47 this.capturedEvents_ = []; |
| 46 | 48 |
| 47 this.sourceEntries_ = {}; | 49 this.sourceEntries_ = {}; |
| 48 }, | 50 }, |
| 49 | 51 |
| 50 /** | 52 /** |
| 51 * Returns a list of all captured events. | |
| 52 */ | |
| 53 getAllCapturedEvents: function() { | |
| 54 return this.capturedEvents_; | |
| 55 }, | |
| 56 | |
| 57 /** | |
| 58 * Returns a list of all SourceEntries. | 53 * Returns a list of all SourceEntries. |
| 59 */ | 54 */ |
| 60 getAllSourceEntries: function() { | 55 getAllSourceEntries: function() { |
| 61 return this.sourceEntries_; | 56 return this.sourceEntries_; |
| 62 }, | 57 }, |
| 63 | 58 |
| 64 /** | 59 /** |
| 65 * Returns the number of events that were captured while we were | |
| 66 * listening for events. | |
| 67 */ | |
| 68 getNumCapturedEvents: function() { | |
| 69 return this.capturedEvents_.length; | |
| 70 }, | |
| 71 | |
| 72 /** | |
| 73 * Returns the description of the specified SourceEntry, or an empty string | 60 * Returns the description of the specified SourceEntry, or an empty string |
| 74 * if it doesn't exist. | 61 * if it doesn't exist. |
| 75 */ | 62 */ |
| 76 getDescription: function(id) { | 63 getDescription: function(id) { |
| 77 var entry = this.getSourceEntry(id); | 64 var entry = this.getSourceEntry(id); |
| 78 if (entry) | 65 if (entry) |
| 79 return entry.getDescription(); | 66 return entry.getDescription(); |
| 80 return ''; | 67 return ''; |
| 81 }, | 68 }, |
| 82 | 69 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 updatedSourceEntryIdMap[logEntry.source.id] = sourceEntry; | 110 updatedSourceEntryIdMap[logEntry.source.id] = sourceEntry; |
| 124 updatedSourceEntries.push(sourceEntry); | 111 updatedSourceEntries.push(sourceEntry); |
| 125 } | 112 } |
| 126 } | 113 } |
| 127 | 114 |
| 128 this.capturedEvents_ = this.capturedEvents_.concat(logEntries); | 115 this.capturedEvents_ = this.capturedEvents_.concat(logEntries); |
| 129 for (var i = 0; i < this.sourceEntryObservers_.length; ++i) { | 116 for (var i = 0; i < this.sourceEntryObservers_.length; ++i) { |
| 130 this.sourceEntryObservers_[i].onSourceEntriesUpdated( | 117 this.sourceEntryObservers_[i].onSourceEntriesUpdated( |
| 131 updatedSourceEntries); | 118 updatedSourceEntries); |
| 132 } | 119 } |
| 133 for (var i = 0; i < this.logEntryObservers_.length; ++i) | |
| 134 this.logEntryObservers_[i].onReceivedLogEntries(logEntries); | |
| 135 }, | 120 }, |
| 136 | 121 |
| 137 /** | 122 /** |
| 138 * Deletes all captured events. | 123 * Called when all log events have been deleted. |
| 139 */ | 124 */ |
| 140 deleteAllSourceEntries: function() { | 125 onAllLogEntriesDeleted: function() { |
| 141 this.clearEntries_(); | 126 this.clearEntries_(); |
| 142 for (var i = 0; i < this.sourceEntryObservers_.length; ++i) | 127 for (var i = 0; i < this.sourceEntryObservers_.length; ++i) |
| 143 this.sourceEntryObservers_[i].onAllSourceEntriesDeleted(); | 128 this.sourceEntryObservers_[i].onAllSourceEntriesDeleted(); |
| 144 for (var i = 0; i < this.logEntryObservers_.length; ++i) | |
| 145 this.logEntryObservers_[i].onAllLogEntriesDeleted(); | |
| 146 }, | 129 }, |
| 147 | 130 |
| 148 /** | 131 /** |
| 149 * Sets the value of |enableSecurityStripping_| and informs log observers | 132 * Sets the value of |enableSecurityStripping_| and informs log observers |
| 150 * of the change. | 133 * of the change. |
| 151 */ | 134 */ |
| 152 setSecurityStripping: function(enableSecurityStripping) { | 135 setSecurityStripping: function(enableSecurityStripping) { |
| 153 this.enableSecurityStripping_ = enableSecurityStripping; | 136 this.enableSecurityStripping_ = enableSecurityStripping; |
| 154 for (var i = 0; i < this.sourceEntryObservers_.length; ++i) { | 137 for (var i = 0; i < this.sourceEntryObservers_.length; ++i) { |
| 155 if (this.sourceEntryObservers_[i].onSecurityStrippingChanged) | 138 if (this.sourceEntryObservers_[i].onSecurityStrippingChanged) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 169 * Adds a listener of SourceEntries. |observer| will be called back when | 152 * Adds a listener of SourceEntries. |observer| will be called back when |
| 170 * SourceEntries are added or modified, source entries are deleted, or | 153 * SourceEntries are added or modified, source entries are deleted, or |
| 171 * security stripping changes: | 154 * security stripping changes: |
| 172 * | 155 * |
| 173 * observer.onSourceEntriesUpdated(sourceEntries) | 156 * observer.onSourceEntriesUpdated(sourceEntries) |
| 174 * ovserver.onAllSourceEntriesDeleted() | 157 * ovserver.onAllSourceEntriesDeleted() |
| 175 * observer.onSecurityStrippingChanged() | 158 * observer.onSecurityStrippingChanged() |
| 176 */ | 159 */ |
| 177 addSourceEntryObserver: function(observer) { | 160 addSourceEntryObserver: function(observer) { |
| 178 this.sourceEntryObservers_.push(observer); | 161 this.sourceEntryObservers_.push(observer); |
| 179 }, | |
| 180 | |
| 181 /** | |
| 182 * Adds a listener of log entries. |observer| will be called back when new | |
| 183 * log data arrives or all entries are deleted: | |
| 184 * | |
| 185 * observer.onReceivedLogEntries(entries) | |
| 186 * ovserver.onAllLogEntriesDeleted() | |
| 187 */ | |
| 188 addLogEntryObserver: function(observer) { | |
| 189 this.logEntryObservers_.push(observer); | |
| 190 } | 162 } |
| 191 }; | 163 }; |
| 192 | 164 |
| 193 return SourceTracker; | 165 return SourceTracker; |
| 194 })(); | 166 })(); |
| OLD | NEW |