summaryrefslogtreecommitdiffstats
path: root/chrome/browser/resources/net_internals
diff options
context:
space:
mode:
authoreroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-03 08:51:56 +0000
committereroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-03 08:51:56 +0000
commit1420d5e4d6775181247fec766e8e5ff01106f884 (patch)
treec1d3f8f7553b977eb8d4e1ccc493dfbfb6f18b05 /chrome/browser/resources/net_internals
parent32c800ebcabf081547a6bfac816cd458b4e6acdb (diff)
downloadchromium_src-1420d5e4d6775181247fec766e8e5ff01106f884.zip
chromium_src-1420d5e4d6775181247fec766e8e5ff01106f884.tar.gz
chromium_src-1420d5e4d6775181247fec766e8e5ff01106f884.tar.bz2
[refactor] Split up SourceTracker into SourceTracker + EventsTracker.
This is in preparation for adding some extra functionality at the EventsTracker layer (max events throttling). Review URL: http://codereview.chromium.org/9581021 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@124847 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/resources/net_internals')
-rw-r--r--chrome/browser/resources/net_internals/browser_bridge.js6
-rw-r--r--chrome/browser/resources/net_internals/capture_status_view.js14
-rw-r--r--chrome/browser/resources/net_internals/events_tracker.js71
-rw-r--r--chrome/browser/resources/net_internals/events_view.js2
-rw-r--r--chrome/browser/resources/net_internals/export_view.js5
-rw-r--r--chrome/browser/resources/net_internals/index.js1
-rw-r--r--chrome/browser/resources/net_internals/log_util.js34
-rw-r--r--chrome/browser/resources/net_internals/log_view_painter.js2
-rw-r--r--chrome/browser/resources/net_internals/main.js2
-rw-r--r--chrome/browser/resources/net_internals/source_entry.js4
-rw-r--r--chrome/browser/resources/net_internals/source_tracker.js46
-rw-r--r--chrome/browser/resources/net_internals/timeline_view.js7
12 files changed, 118 insertions, 76 deletions
diff --git a/chrome/browser/resources/net_internals/browser_bridge.js b/chrome/browser/resources/net_internals/browser_bridge.js
index c6822da..7353b45 100644
--- a/chrome/browser/resources/net_internals/browser_bridge.js
+++ b/chrome/browser/resources/net_internals/browser_bridge.js
@@ -65,10 +65,6 @@ var BrowserBridge = (function() {
new PollableDataHelper('onHttpPipeliningStatusChanged',
this.sendGetHttpPipeliningStatus.bind(this));
- // NetLog entries are all sent to the |SourceTracker|, which both tracks
- // them and manages its own observer list.
- this.sourceTracker = new SourceTracker();
-
// Setting this to true will cause messages from the browser to be ignored,
// and no messages will be sent to the browser, either. Intended for use
// when viewing log files.
@@ -258,7 +254,7 @@ var BrowserBridge = (function() {
},
receivedLogEntries: function(logEntries) {
- this.sourceTracker.onReceivedLogEntries(logEntries);
+ EventsTracker.getInstance().addLogEntries(logEntries);
},
receivedProxySettings: function(proxySettings) {
diff --git a/chrome/browser/resources/net_internals/capture_status_view.js b/chrome/browser/resources/net_internals/capture_status_view.js
index 29f3443..b4789a2 100644
--- a/chrome/browser/resources/net_internals/capture_status_view.js
+++ b/chrome/browser/resources/net_internals/capture_status_view.js
@@ -17,8 +17,8 @@ var CaptureStatusView = (function() {
$(CaptureStatusView.STOP_BUTTON_ID).onclick = switchToViewOnlyMode_;
$(CaptureStatusView.RESET_BUTTON_ID).onclick =
- g_browser.sourceTracker.deleteAllSourceEntries.bind(
- g_browser.sourceTracker);
+ EventsTracker.getInstance().deleteAllLogEntries.bind(
+ EventsTracker.getInstance());
$(CaptureStatusView.CLEAR_CACHE_BUTTON_ID).onclick =
g_browser.sendClearAllCache.bind(g_browser);
$(CaptureStatusView.FLUSH_SOCKETS_BUTTON_ID).onclick =
@@ -31,7 +31,7 @@ var CaptureStatusView = (function() {
$(CaptureStatusView.CAPTURED_EVENTS_COUNT_ID);
this.updateEventCounts_();
- g_browser.sourceTracker.addSourceEntryObserver(this);
+ EventsTracker.getInstance().addLogEntryObserver(this);
}
// IDs for special HTML elements in status_view.html
@@ -51,16 +51,16 @@ var CaptureStatusView = (function() {
__proto__: superClass.prototype,
/**
- * Called whenever a new event is received.
+ * Called whenever new log entries have been received.
*/
- onSourceEntriesUpdated: function(sourceEntries) {
+ onReceivedLogEntries: function(logEntries) {
this.updateEventCounts_();
},
/**
* Called whenever all log events are deleted.
*/
- onAllSourceEntriesDeleted: function() {
+ onAllLogEntriesDeleted: function() {
this.updateEventCounts_();
},
@@ -69,7 +69,7 @@ var CaptureStatusView = (function() {
*/
updateEventCounts_: function() {
this.capturedEventsCountBox_.textContent =
- g_browser.sourceTracker.getNumCapturedEvents();
+ EventsTracker.getInstance().getNumCapturedEvents();
},
/**
diff --git a/chrome/browser/resources/net_internals/events_tracker.js b/chrome/browser/resources/net_internals/events_tracker.js
new file mode 100644
index 0000000..34ed91e
--- /dev/null
+++ b/chrome/browser/resources/net_internals/events_tracker.js
@@ -0,0 +1,71 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+var EventsTracker = (function() {
+ 'use strict';
+
+ /**
+ * This class keeps track of all NetLog events.
+ * It receives events from the browser and when loading a log file, and passes
+ * them on to all its observers.
+ *
+ * @constructor
+ */
+ function EventsTracker() {
+ assertFirstConstructorCall(EventsTracker);
+
+ this.capturedEvents_ = [];
+ this.observers_ = [];
+ }
+
+ cr.addSingletonGetter(EventsTracker);
+
+ EventsTracker.prototype = {
+ /**
+ * Returns a list of all captured events.
+ */
+ getAllCapturedEvents: function() {
+ return this.capturedEvents_;
+ },
+
+ /**
+ * Returns the number of events that were captured.
+ */
+ getNumCapturedEvents: function() {
+ return this.capturedEvents_.length;
+ },
+
+ /**
+ * Deletes all the tracked events, and notifies any observers.
+ */
+ deleteAllLogEntries: function() {
+ this.capturedEvents_ = [];
+ for (var i = 0; i < this.observers_.length; ++i)
+ this.observers_[i].onAllLogEntriesDeleted();
+ },
+
+ /**
+ * Adds captured events, and broadcasts them to any observers.
+ */
+ addLogEntries: function(logEntries) {
+ this.capturedEvents_ = this.capturedEvents_.concat(logEntries);
+ for (var i = 0; i < this.observers_.length; ++i) {
+ this.observers_[i].onReceivedLogEntries(logEntries);
+ }
+ },
+
+ /**
+ * Adds a listener of log entries. |observer| will be called back when new
+ * log data arrives or all entries are deleted:
+ *
+ * observer.onReceivedLogEntries(entries)
+ * observer.onAllLogEntriesDeleted()
+ */
+ addLogEntryObserver: function(observer) {
+ this.observers_.push(observer);
+ }
+ };
+
+ return EventsTracker;
+})();
diff --git a/chrome/browser/resources/net_internals/events_view.js b/chrome/browser/resources/net_internals/events_view.js
index d2f2315..378b4e0 100644
--- a/chrome/browser/resources/net_internals/events_view.js
+++ b/chrome/browser/resources/net_internals/events_view.js
@@ -50,7 +50,7 @@ var EventsView = (function() {
this.splitterView_ = new ResizableVerticalSplitView(
leftPane, this.detailsView_, new DivView(EventsView.SIZER_ID));
- g_browser.sourceTracker.addSourceEntryObserver(this);
+ SourceTracker.getInstance().addSourceEntryObserver(this);
this.tableBody_ = $(EventsView.TBODY_ID);
diff --git a/chrome/browser/resources/net_internals/export_view.js b/chrome/browser/resources/net_internals/export_view.js
index cb2c3e0..fd1563c 100644
--- a/chrome/browser/resources/net_internals/export_view.js
+++ b/chrome/browser/resources/net_internals/export_view.js
@@ -65,7 +65,7 @@ var ExportView = (function() {
* cookies and passwords from log dumps and displayed events.
*/
onSetSecurityStripping_: function(securityStrippingCheckbox) {
- g_browser.sourceTracker.setSecurityStripping(
+ SourceTracker.getInstance().setSecurityStripping(
securityStrippingCheckbox.checked);
},
@@ -130,7 +130,8 @@ var ExportView = (function() {
this.setSaveFileStatus('Preparing data...', true);
- var securityStripping = g_browser.sourceTracker.getSecurityStripping();
+ var securityStripping =
+ SourceTracker.getInstance().getSecurityStripping();
// If we have a cached log dump, update it synchronously.
if (this.loadedLogDump_) {
diff --git a/chrome/browser/resources/net_internals/index.js b/chrome/browser/resources/net_internals/index.js
index a14d287..ffc2763 100644
--- a/chrome/browser/resources/net_internals/index.js
+++ b/chrome/browser/resources/net_internals/index.js
@@ -13,6 +13,7 @@
<include src="test_view.js"/>
<include src="hsts_view.js"/>
<include src="browser_bridge.js"/>
+<include src="events_tracker.js"/>
<include src="source_tracker.js"/>
<include src="resizable_vertical_split_view.js"/>
<include src="main.js"/>
diff --git a/chrome/browser/resources/net_internals/log_util.js b/chrome/browser/resources/net_internals/log_util.js
index 7d2cdfd..78c7e34 100644
--- a/chrome/browser/resources/net_internals/log_util.js
+++ b/chrome/browser/resources/net_internals/log_util.js
@@ -63,13 +63,14 @@ log_util = (function() {
oldLogDump.constants.clientInfo.numericDate) {
numericDate = oldLogDump.constants.clientInfo.numericDate;
}
- var logDump = createLogDump(userComments,
- Constants,
- g_browser.sourceTracker.getAllCapturedEvents(),
- oldLogDump.polledData,
- getTabData_(),
- numericDate,
- securityStripping);
+ var logDump = createLogDump(
+ userComments,
+ Constants,
+ EventsTracker.getInstance().getAllCapturedEvents(),
+ oldLogDump.polledData,
+ getTabData_(),
+ numericDate,
+ securityStripping);
return JSON.stringify(logDump, null, ' ');
}
@@ -79,13 +80,14 @@ log_util = (function() {
*/
function onUpdateAllCompleted(userComments, callback, securityStripping,
polledData) {
- var logDump = createLogDump(userComments,
- Constants,
- g_browser.sourceTracker.getAllCapturedEvents(),
- polledData,
- getTabData_(),
- timeutil.getCurrentTime(),
- securityStripping);
+ var logDump = createLogDump(
+ userComments,
+ Constants,
+ EventsTracker.getInstance().getAllCapturedEvents(),
+ polledData,
+ getTabData_(),
+ timeutil.getCurrentTime(),
+ securityStripping);
callback(JSON.stringify(logDump, null, ' '));
}
@@ -214,7 +216,7 @@ log_util = (function() {
MainView.getInstance().onLoadLog(opt_fileName);
// Delete all events. This will also update all logObservers.
- g_browser.sourceTracker.deleteAllSourceEntries();
+ EventsTracker.getInstance().deleteAllLogEntries();
// Inform all the views that a log file is being loaded, and pass in
// view-specific saved state, if any.
@@ -224,7 +226,7 @@ log_util = (function() {
var view = categoryTabSwitcher.findTabById(tabIds[i]).contentView;
view.onLoadLogStart(logDump.polledData, logDump.tabData[tabIds[i]]);
}
- g_browser.sourceTracker.onReceivedLogEntries(validEvents);
+ EventsTracker.getInstance().addLogEntries(validEvents);
var numInvalidEvents = logDump.events.length -
(validEvents.length + numDeprecatedPassiveEvents);
diff --git a/chrome/browser/resources/net_internals/log_view_painter.js b/chrome/browser/resources/net_internals/log_view_painter.js
index ff1ac2e..7b5001f 100644
--- a/chrome/browser/resources/net_internals/log_view_painter.js
+++ b/chrome/browser/resources/net_internals/log_view_painter.js
@@ -79,7 +79,7 @@ printLogEntriesAsText = function(logEntries, parent) {
tablePrinter.setNewRowCellIndent(5 + entry.getDepth());
addRowsForExtraParams(tablePrinter,
entry.orig,
- g_browser.sourceTracker.getSecurityStripping());
+ SourceTracker.getInstance().getSecurityStripping());
tablePrinter.setNewRowCellIndent(0);
}
}
diff --git a/chrome/browser/resources/net_internals/main.js b/chrome/browser/resources/net_internals/main.js
index 18215cf..671dd95 100644
--- a/chrome/browser/resources/net_internals/main.js
+++ b/chrome/browser/resources/net_internals/main.js
@@ -168,7 +168,7 @@ var MainView = (function() {
onLoadLog: function(opt_fileName) {
isViewingLoadedLog = true;
- g_browser.sourceTracker.setSecurityStripping(false);
+ SourceTracker.getInstance().setSecurityStripping(false);
this.stopCapturing();
if (opt_fileName != undefined) {
// If there's a file name, a log file was loaded, so swap out the status
diff --git a/chrome/browser/resources/net_internals/source_entry.js b/chrome/browser/resources/net_internals/source_entry.js
index f4d3ce0..4b1c7d8 100644
--- a/chrome/browser/resources/net_internals/source_entry.js
+++ b/chrome/browser/resources/net_internals/source_entry.js
@@ -108,7 +108,7 @@ var SourceEntry = (function() {
if (e.params.source_dependency != undefined) {
var parentId = e.params.source_dependency.id;
this.description_ =
- g_browser.sourceTracker.getDescription(parentId);
+ SourceTracker.getInstance().getDescription(parentId);
}
break;
case LogSourceType.UDP_SOCKET:
@@ -119,7 +119,7 @@ var SourceEntry = (function() {
if (this.entries_[0].type == LogEventType.SOCKET_ALIVE &&
this.entries_[0].params.source_dependency != undefined) {
var parentId = this.entries_[0].params.source_dependency.id;
- var parent = g_browser.sourceTracker.getSourceEntry(parentId);
+ var parent = SourceTracker.getInstance().getSourceEntry(parentId);
if (parent &&
parent.getSourceType() ==
LogSourceType.HOST_RESOLVER_IMPL_JOB &&
diff --git a/chrome/browser/resources/net_internals/source_tracker.js b/chrome/browser/resources/net_internals/source_tracker.js
index 92d576d..7220a3f 100644
--- a/chrome/browser/resources/net_internals/source_tracker.js
+++ b/chrome/browser/resources/net_internals/source_tracker.js
@@ -6,16 +6,14 @@ var SourceTracker = (function() {
'use strict';
/**
- * This class keeps track of all NetLog events.
- * It receives events from the browser and when loading a log file, and passes
+ * This class keeps track of all NetLog events, grouped into per-source
+ * streams. It receives events from EventsTracker, and passes
* them on to all its observers.
*
* @constructor
*/
function SourceTracker() {
- // Observers that are sent all events as they happen. This allows for easy
- // watching for particular events.
- this.logEntryObservers_ = [];
+ assertFirstConstructorCall(SourceTracker);
// Observers that only want to receive lists of updated SourceEntries.
this.sourceEntryObservers_ = [];
@@ -26,8 +24,12 @@ var SourceTracker = (function() {
this.enableSecurityStripping_ = true;
this.clearEntries_();
+
+ EventsTracker.getInstance().addLogEntryObserver(this);
}
+ cr.addSingletonGetter(SourceTracker);
+
SourceTracker.prototype = {
/**
* Clears all log entries and SourceEntries and related state.
@@ -48,13 +50,6 @@ var SourceTracker = (function() {
},
/**
- * Returns a list of all captured events.
- */
- getAllCapturedEvents: function() {
- return this.capturedEvents_;
- },
-
- /**
* Returns a list of all SourceEntries.
*/
getAllSourceEntries: function() {
@@ -62,14 +57,6 @@ var SourceTracker = (function() {
},
/**
- * Returns the number of events that were captured while we were
- * listening for events.
- */
- getNumCapturedEvents: function() {
- return this.capturedEvents_.length;
- },
-
- /**
* Returns the description of the specified SourceEntry, or an empty string
* if it doesn't exist.
*/
@@ -130,19 +117,15 @@ var SourceTracker = (function() {
this.sourceEntryObservers_[i].onSourceEntriesUpdated(
updatedSourceEntries);
}
- for (var i = 0; i < this.logEntryObservers_.length; ++i)
- this.logEntryObservers_[i].onReceivedLogEntries(logEntries);
},
/**
- * Deletes all captured events.
+ * Called when all log events have been deleted.
*/
- deleteAllSourceEntries: function() {
+ onAllLogEntriesDeleted: function() {
this.clearEntries_();
for (var i = 0; i < this.sourceEntryObservers_.length; ++i)
this.sourceEntryObservers_[i].onAllSourceEntriesDeleted();
- for (var i = 0; i < this.logEntryObservers_.length; ++i)
- this.logEntryObservers_[i].onAllLogEntriesDeleted();
},
/**
@@ -176,17 +159,6 @@ var SourceTracker = (function() {
*/
addSourceEntryObserver: function(observer) {
this.sourceEntryObservers_.push(observer);
- },
-
- /**
- * Adds a listener of log entries. |observer| will be called back when new
- * log data arrives or all entries are deleted:
- *
- * observer.onReceivedLogEntries(entries)
- * ovserver.onAllLogEntriesDeleted()
- */
- addLogEntryObserver: function(observer) {
- this.logEntryObservers_.push(observer);
}
};
diff --git a/chrome/browser/resources/net_internals/timeline_view.js b/chrome/browser/resources/net_internals/timeline_view.js
index fc6454c..04e5422 100644
--- a/chrome/browser/resources/net_internals/timeline_view.js
+++ b/chrome/browser/resources/net_internals/timeline_view.js
@@ -51,7 +51,7 @@ var TimelineView = (function() {
// them on to each DataSource. We initialize the graph range to initially
// include all events, but after that, we only update it to be the current
// time on a timer.
- g_browser.sourceTracker.addLogEntryObserver(this);
+ EventsTracker.getInstance().addLogEntryObserver(this);
this.graphRangeInitialized_ = false;
}
@@ -233,8 +233,7 @@ var TimelineView = (function() {
},
/**
- * When log entries are deleted, simpler to recreate the DataSeries, rather
- * than clearing them.
+ * When all log entries are deleted, recreate the DataSeries.
*/
onAllLogEntriesDeleted: function() {
this.graphRangeInitialized_ = false;
@@ -243,7 +242,7 @@ var TimelineView = (function() {
onReceivedLogEntries: function(entries) {
// Pass each entry to every DataSeries, one at a time. Not having each
- // data series get data directly from the SourceTracker saves us from
+ // data series get data directly from the EventsTracker saves us from
// having very un-Javascript-like destructors for when we load new,
// constants and slightly simplifies DataSeries objects.
for (var entry = 0; entry < entries.length; ++entry) {