Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(376)

Side by Side Diff: chrome/browser/resources/net_internals/source_tracker.js

Issue 8474001: Add a timeline view to about:net-internals. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Comment fix Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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:
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:
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 })();
OLDNEW
« no previous file with comments | « chrome/browser/resources/net_internals/source_entry.js ('k') | chrome/browser/resources/net_internals/test_view.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698