OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 var EventsTracker = (function() { |
| 6 'use strict'; |
| 7 |
| 8 /** |
| 9 * This class keeps track of all NetLog events. |
| 10 * It receives events from the browser and when loading a log file, and passes |
| 11 * them on to all its observers. |
| 12 * |
| 13 * @constructor |
| 14 */ |
| 15 function EventsTracker() { |
| 16 assertFirstConstructorCall(EventsTracker); |
| 17 |
| 18 this.capturedEvents_ = []; |
| 19 this.observers_ = []; |
| 20 } |
| 21 |
| 22 cr.addSingletonGetter(EventsTracker); |
| 23 |
| 24 EventsTracker.prototype = { |
| 25 /** |
| 26 * Returns a list of all captured events. |
| 27 */ |
| 28 getAllCapturedEvents: function() { |
| 29 return this.capturedEvents_; |
| 30 }, |
| 31 |
| 32 /** |
| 33 * Returns the number of events that were captured. |
| 34 */ |
| 35 getNumCapturedEvents: function() { |
| 36 return this.capturedEvents_.length; |
| 37 }, |
| 38 |
| 39 /** |
| 40 * Deletes all the tracked events, and notifies any observers. |
| 41 */ |
| 42 deleteAllLogEntries: function() { |
| 43 this.capturedEvents_ = []; |
| 44 for (var i = 0; i < this.observers_.length; ++i) |
| 45 this.observers_[i].onAllLogEntriesDeleted(); |
| 46 }, |
| 47 |
| 48 /** |
| 49 * Adds captured events, and broadcasts them to any observers. |
| 50 */ |
| 51 addLogEntries: function(logEntries) { |
| 52 this.capturedEvents_ = this.capturedEvents_.concat(logEntries); |
| 53 for (var i = 0; i < this.observers_.length; ++i) { |
| 54 this.observers_[i].onReceivedLogEntries(logEntries); |
| 55 } |
| 56 }, |
| 57 |
| 58 /** |
| 59 * Adds a listener of log entries. |observer| will be called back when new |
| 60 * log data arrives or all entries are deleted: |
| 61 * |
| 62 * observer.onReceivedLogEntries(entries) |
| 63 * observer.onAllLogEntriesDeleted() |
| 64 */ |
| 65 addLogEntryObserver: function(observer) { |
| 66 this.observers_.push(observer); |
| 67 } |
| 68 }; |
| 69 |
| 70 return EventsTracker; |
| 71 })(); |
OLD | NEW |