OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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. |
10 * It receives events from the browser and when loading a log file, and passes | 10 * It receives events from the browser and when loading a log file, 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 this.observers_ = []; | 16 // Observers that are sent all events as they happen. This allows for easy |
17 // watching for particular events. | |
18 this.logEntryObservers_ = []; | |
19 | |
20 // Observers that only want to receive lists of updated SourceEntries. | |
21 this.sourceEntryObservers_ = []; | |
17 | 22 |
18 // True when cookies and authentication information should be removed from | 23 // True when cookies and authentication information should be removed from |
19 // displayed events. When true, such information should be hidden from | 24 // displayed events. When true, such information should be hidden from |
20 // all pages. | 25 // all pages. |
21 this.enableSecurityStripping_ = true; | 26 this.enableSecurityStripping_ = true; |
22 | 27 |
23 this.clearEntries_(); | 28 this.clearEntries_(); |
24 } | 29 } |
25 | 30 |
26 SourceTracker.prototype = { | 31 SourceTracker.prototype = { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
108 logEntries[i].wasPassivelyCaptured = true; | 113 logEntries[i].wasPassivelyCaptured = true; |
109 | 114 |
110 this.onReceivedLogEntries(logEntries); | 115 this.onReceivedLogEntries(logEntries); |
111 | 116 |
112 // Add back early actively captured events, if any. | 117 // Add back early actively captured events, if any. |
113 if (earlyActivelyCapturedEvents.length) | 118 if (earlyActivelyCapturedEvents.length) |
114 this.onReceivedLogEntries(earlyActivelyCapturedEvents); | 119 this.onReceivedLogEntries(earlyActivelyCapturedEvents); |
115 }, | 120 }, |
116 | 121 |
117 /** | 122 /** |
118 * Sends each entry to all log observers, and updates |capturedEvents_|. | 123 * Sends each entry to all observers and updates |capturedEvents_|. |
119 * Also assigns unique ids to log entries without a source. | 124 * Also assigns unique ids to log entries without a source. |
120 */ | 125 */ |
121 onReceivedLogEntries: function(logEntries) { | 126 onReceivedLogEntries: function(logEntries) { |
122 // List source entries with new log entries. Sorted chronologically, by | 127 // List source entries with new log entries. Sorted chronologically, by |
123 // first new log entry. | 128 // first new log entry. |
124 var updatedSourceEntries = []; | 129 var updatedSourceEntries = []; |
125 | 130 |
126 var updatedSourceEntryIdMap = {}; | 131 var updatedSourceEntryIdMap = {}; |
127 | 132 |
128 for (var e = 0; e < logEntries.length; ++e) { | 133 for (var e = 0; e < logEntries.length; ++e) { |
(...skipping 17 matching lines...) Expand all Loading... | |
146 } | 151 } |
147 | 152 |
148 // Add to updated SourceEntry list, if not already in it. | 153 // Add to updated SourceEntry list, if not already in it. |
149 if (!updatedSourceEntryIdMap[logEntry.source.id]) { | 154 if (!updatedSourceEntryIdMap[logEntry.source.id]) { |
150 updatedSourceEntryIdMap[logEntry.source.id] = sourceEntry; | 155 updatedSourceEntryIdMap[logEntry.source.id] = sourceEntry; |
151 updatedSourceEntries.push(sourceEntry); | 156 updatedSourceEntries.push(sourceEntry); |
152 } | 157 } |
153 } | 158 } |
154 | 159 |
155 this.capturedEvents_ = this.capturedEvents_.concat(logEntries); | 160 this.capturedEvents_ = this.capturedEvents_.concat(logEntries); |
156 for (var i = 0; i < this.observers_.length; ++i) | 161 for (var i = 0; i < this.sourceEntryObservers_.length; ++i) { |
157 this.observers_[i].onSourceEntriesUpdated(updatedSourceEntries); | 162 this.sourceEntryObservers_[i].onSourceEntriesUpdated( |
163 updatedSourceEntries); | |
164 } | |
165 for (var i = 0; i < this.logEntryObservers_.length; ++i) | |
166 this.logEntryObservers_[i].onReceivedLogEntries(logEntries); | |
158 }, | 167 }, |
159 | 168 |
160 /** | 169 /** |
161 * Deletes captured events with source IDs in |sourceEntryIds|. | 170 * Deletes captured events with source IDs in |sourceEntryIds|. |
162 */ | 171 */ |
163 deleteSourceEntries: function(sourceEntryIds) { | 172 deleteSourceEntries: function(sourceEntryIds) { |
164 var sourceIdDict = {}; | 173 var sourceIdDict = {}; |
165 for (var i = 0; i < sourceEntryIds.length; i++) { | 174 for (var i = 0; i < sourceEntryIds.length; i++) { |
166 sourceIdDict[sourceEntryIds[i]] = true; | 175 sourceIdDict[sourceEntryIds[i]] = true; |
167 delete this.sourceEntries_[sourceEntryIds[i]]; | 176 delete this.sourceEntries_[sourceEntryIds[i]]; |
168 } | 177 } |
169 | 178 |
170 var newEventList = []; | 179 var newEventList = []; |
171 for (var i = 0; i < this.capturedEvents_.length; ++i) { | 180 for (var i = 0; i < this.capturedEvents_.length; ++i) { |
172 var id = this.capturedEvents_[i].source.id; | 181 var id = this.capturedEvents_[i].source.id; |
173 if (id in sourceIdDict) { | 182 if (id in sourceIdDict) { |
174 if (this.capturedEvents_[i].wasPassivelyCaptured) | 183 if (this.capturedEvents_[i].wasPassivelyCaptured) |
175 --this.numPassivelyCapturedEvents_; | 184 --this.numPassivelyCapturedEvents_; |
176 continue; | 185 continue; |
177 } | 186 } |
178 newEventList.push(this.capturedEvents_[i]); | 187 newEventList.push(this.capturedEvents_[i]); |
179 } | 188 } |
180 this.capturedEvents_ = newEventList; | 189 this.capturedEvents_ = newEventList; |
181 | 190 |
182 for (var i = 0; i < this.observers_.length; ++i) | 191 for (var i = 0; i < this.sourceEntryObservers_.length; ++i) |
183 this.observers_[i].onSourceEntriesDeleted(sourceEntryIds); | 192 this.sourceEntryObservers_[i].onSourceEntriesDeleted(sourceEntryIds); |
184 }, | 193 }, |
185 | 194 |
186 /** | 195 /** |
187 * Deletes all captured events. | 196 * Deletes all captured events. |
188 */ | 197 */ |
189 deleteAllSourceEntries: function() { | 198 deleteAllSourceEntries: function() { |
190 this.clearEntries_(); | 199 this.clearEntries_(); |
191 for (var i = 0; i < this.observers_.length; ++i) | 200 for (var i = 0; i < this.sourceEntryObservers_.length; ++i) |
192 this.observers_[i].onAllSourceEntriesDeleted(); | 201 this.sourceEntryObservers_[i].onAllSourceEntriesDeleted(); |
202 for (var i = 0; i < this.logEntryObservers_.length; ++i) | |
203 this.logEntryObservers_[i].onAllLogEntriesDeleted(); | |
193 }, | 204 }, |
194 | 205 |
195 /** | 206 /** |
196 * Sets the value of |enableSecurityStripping_| and informs log observers | 207 * Sets the value of |enableSecurityStripping_| and informs log observers |
197 * of the change. | 208 * of the change. |
198 */ | 209 */ |
199 setSecurityStripping: function(enableSecurityStripping) { | 210 setSecurityStripping: function(enableSecurityStripping) { |
200 this.enableSecurityStripping_ = enableSecurityStripping; | 211 this.enableSecurityStripping_ = enableSecurityStripping; |
201 for (var i = 0; i < this.observers_.length; ++i) { | 212 for (var i = 0; i < this.sourceEntryObservers_.length; ++i) { |
202 if (this.observers_[i].onSecurityStrippingChanged) | 213 if (this.sourceEntryObservers_[i].onSecurityStrippingChanged) |
203 this.observers_[i].onSecurityStrippingChanged(); | 214 this.sourceEntryObservers_[i].onSecurityStrippingChanged(); |
204 } | 215 } |
205 }, | 216 }, |
206 | 217 |
207 /** | 218 /** |
208 * Returns whether or not cookies and authentication information should be | 219 * Returns whether or not cookies and authentication information should be |
209 * displayed for events that contain them. | 220 * displayed for events that contain them. |
210 */ | 221 */ |
211 getSecurityStripping: function() { | 222 getSecurityStripping: function() { |
212 return this.enableSecurityStripping_; | 223 return this.enableSecurityStripping_; |
213 }, | 224 }, |
214 | 225 |
215 /** | 226 /** |
227 * Adds a listener of SourceEntries. |observer| will be called back when | |
228 * SourceEntries are added or modified, source entries are deleted, or | |
229 * security stripping changes through: | |
eroman
2011/11/16 04:03:46
nit: "through" seems unnecessary, can probably rem
mmenke
2011/11/16 18:39:35
Done.
| |
230 * | |
231 * observer.onSourceEntriesUpdated(sourceEntries) | |
232 * observer.onSourceEntriesDeleted(sourceEntryIds) | |
233 * ovserver.onAllSourceEntriesDeleted() | |
234 * observer.onSecurityStrippingChanged() | |
235 */ | |
236 addSourceEntryObserver: function(observer) { | |
237 this.sourceEntryObservers_.push(observer); | |
238 }, | |
239 | |
240 /** | |
216 * Adds a listener of log entries. |observer| will be called back when new | 241 * Adds a listener of log entries. |observer| will be called back when new |
217 * log data arrives, source entries are deleted, or security stripping | 242 * log data arrives or all entries are deleted through: |
218 * changes through: | |
219 * | 243 * |
220 * observer.onSourceEntriesUpdated(sourceEntries) | 244 * observer.onReceivedLogEntries(entries) |
221 * observer.deleteSourceEntries(sourceEntryIds) | 245 * ovserver.onAllLogEntriesDeleted() |
222 * ovserver.deleteAllSourceEntries() | |
223 * observer.onSecurityStrippingChanged() | |
224 */ | 246 */ |
225 addObserver: function(observer) { | 247 addLogEntryObserver: function(observer) { |
226 this.observers_.push(observer); | 248 this.logEntryObservers_.push(observer); |
227 } | 249 } |
228 }; | 250 }; |
229 | 251 |
230 return SourceTracker; | 252 return SourceTracker; |
231 })(); | 253 })(); |
OLD | NEW |