Chromium Code Reviews| Index: chrome/browser/resources/net_internals/events_tracker.js |
| diff --git a/chrome/browser/resources/net_internals/events_tracker.js b/chrome/browser/resources/net_internals/events_tracker.js |
| index 34ed91eb170fac3f310d0df5beba5b0b209e55b5..a0e824dc16a31c653d00794bab48685b05258d91 100644 |
| --- a/chrome/browser/resources/net_internals/events_tracker.js |
| +++ b/chrome/browser/resources/net_internals/events_tracker.js |
| @@ -17,6 +17,10 @@ var EventsTracker = (function() { |
| this.capturedEvents_ = []; |
| this.observers_ = []; |
| + |
| + // Controls how large |capturedEvents_| can grow. |
| + this.softLimit_ = Infinity; |
| + this.hardLimit_ = Infinity; |
| } |
| cr.addSingletonGetter(EventsTracker); |
| @@ -53,6 +57,15 @@ var EventsTracker = (function() { |
| for (var i = 0; i < this.observers_.length; ++i) { |
| this.observers_[i].onReceivedLogEntries(logEntries); |
| } |
| + |
| + // Check that we haven't grown too big. If so, toss out older events. |
| + if (this.getNumCapturedEvents() > this.hardLimit_) { |
|
mmenke
2012/03/06 15:21:18
nit: Remove extra space.
eroman
2012/03/06 17:14:14
Done.
|
| + var originalEvents = this.capturedEvents_; |
| + this.deleteAllLogEntries(); |
| + // Delete the oldest events until we reach the soft limit. |
| + originalEvents.splice(0, originalEvents.length - this.softLimit_); |
| + this.addLogEntries(originalEvents); |
| + } |
| }, |
| /** |
| @@ -64,6 +77,29 @@ var EventsTracker = (function() { |
| */ |
| addLogEntryObserver: function(observer) { |
| this.observers_.push(observer); |
| + }, |
| + |
| + /** |
| + * Set bounds on the maximum number of events that will be tracked. This |
| + * helps to bound the total amount of memory usage, since otherwise |
| + * long-running capture sessions can exhaust the renderer's memory and |
| + * crash. |
| + * |
| + * Once |hardLimit| number of events have been captured we do a garbage |
| + * collection and toss out old events, bringing our count down to |
| + * |softLimit|. |
| + * |
| + * To log observers this will look like all the events got deleted, and |
| + * then subsequently a bunch of new events were received. In other words, it |
| + * behaves the same as if the user had simply started logging a bit later |
| + * in time! |
| + */ |
| + setLimits: function(softLimit, hardLimit) { |
| + if (hardLimit != Infinity && softLimit >= hardLimit) |
| + throw 'hardLimit must be greater than softLimit'; |
| + |
| + this.softLimit_ = softLimit; |
| + this.hardLimit_ = hardLimit; |
| } |
| }; |