summaryrefslogtreecommitdiffstats
path: root/chrome/browser/net/chrome_net_log.h
diff options
context:
space:
mode:
authordpranke@chromium.org <dpranke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-26 23:09:27 +0000
committerdpranke@chromium.org <dpranke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-26 23:09:27 +0000
commite07dc0e46f2904120798341acc3225cf396f2ec4 (patch)
tree914702949651664c1df1b0ef958e5fad3dd3aebc /chrome/browser/net/chrome_net_log.h
parentcaf41afeb2542ce803f3faa61287f3681b78837a (diff)
downloadchromium_src-e07dc0e46f2904120798341acc3225cf396f2ec4.zip
chromium_src-e07dc0e46f2904120798341acc3225cf396f2ec4.tar.gz
chromium_src-e07dc0e46f2904120798341acc3225cf396f2ec4.tar.bz2
Remove ChromeNetLog dependency from content/browser/debugger.
Add Observer concept to net::NetLog. Use net::NetLog::Observer in ChromeNetLog. Remove ChromeNetLog dependency in content/browser/debugger. Forked from http://codereview.chromium.org/7310029/ to finish Jói's patch. BUG=84078 TEST=existing Review URL: http://codereview.chromium.org/7468019 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@94196 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/net/chrome_net_log.h')
-rw-r--r--chrome/browser/net/chrome_net_log.h114
1 files changed, 68 insertions, 46 deletions
diff --git a/chrome/browser/net/chrome_net_log.h b/chrome/browser/net/chrome_net_log.h
index 909ca0a..a032c33 100644
--- a/chrome/browser/net/chrome_net_log.h
+++ b/chrome/browser/net/chrome_net_log.h
@@ -23,7 +23,7 @@ class PassiveLogCollector;
// messages to a list of observers.
//
// All methods are thread safe, with the exception that no ChromeNetLog or
-// ChromeNetLog::ThreadSafeObserver functions may be called by an observer's
+// ChromeNetLog::ThreadSafeObserverImpl functions may be called by an observer's
// OnAddEntry() method. Doing so will result in a deadlock.
//
// By default, ChromeNetLog will attach the observer PassiveLogCollector which
@@ -54,53 +54,73 @@ class ChromeNetLog : public net::NetLog {
typedef std::vector<Entry> EntryList;
- // Interface for observing the events logged by the network stack.
- class ThreadSafeObserver {
+ // Base class for observing the events logged by the network
+ // stack. This has some nice-to-have functionality for use by code
+ // within chrome/, but any net::NetLog::ThreadSafeObserver may be
+ // registered to observe the NetLog.
+ //
+ // This class uses composition rather than inheritance so that
+ // certain invariants can be maintained when subclasses of it are
+ // added as observers (through the AddAsObserver and
+ // RemoveAsObserver methods on this class).
+ class ThreadSafeObserverImpl {
public:
- // Constructs an observer that wants to see network events, with
- // the specified minimum event granularity. A ThreadSafeObserver can only
- // observe a single ChromeNetLog at a time.
- //
- // Typical observers should specify LOG_BASIC.
- //
// Observers that need to see the full granularity of events can
// specify LOG_ALL. However doing so will have performance consequences,
// and may cause PassiveLogCollector to use more memory than anticipated.
- //
- // Observers will be called on the same thread an entry is added on,
- // and are responsible for ensuring their own thread safety.
- explicit ThreadSafeObserver(LogLevel log_level);
-
- virtual ~ThreadSafeObserver();
-
- // This method will be called on the thread that the event occurs on. It
- // is the responsibility of the observer to handle it in a thread safe
- // manner.
- //
- // It is illegal for an Observer to call any ChromeNetLog or
- // ChromeNetLog::ThreadSafeObserver functions in response to a call to
- // OnAddEntry.
+ explicit ThreadSafeObserverImpl(LogLevel log_level);
+ virtual ~ThreadSafeObserverImpl();
+
virtual void OnAddEntry(EventType type,
const base::TimeTicks& time,
const Source& source,
EventPhase phase,
EventParameters* params) = 0;
- LogLevel log_level() const;
- protected:
- void AssertNetLogLockAcquired() const;
+ // These must be used instead of
+ // ChromeNetLog::Add/RemoveThreadSafeObserver to manage the
+ // association in this class with a given ChromeNetLog instance.
+ void AddAsObserver(ChromeNetLog* net_log);
+ void RemoveAsObserver();
- // Can only be called when actively observing a ChromeNetLog.
void SetLogLevel(LogLevel log_level);
- // ChromeNetLog currently being observed, if any. Set by ChromeNetLog's
- // AddObserver and RemoveObserver methods.
- ChromeNetLog* net_log_;
+ void AddAsObserverAndGetAllPassivelyCapturedEvents(
+ ChromeNetLog *net_log,
+ EntryList* passive_entries);
+
+ protected:
+ void AssertNetLogLockAcquired() const;
private:
- friend class ChromeNetLog;
- LogLevel log_level_;
- DISALLOW_COPY_AND_ASSIGN(ThreadSafeObserver);
+ class PassThroughObserver : public ThreadSafeObserver {
+ public:
+ PassThroughObserver(ThreadSafeObserverImpl* owner, LogLevel log_level);
+ virtual ~PassThroughObserver() {}
+ virtual void OnAddEntry(EventType type,
+ const base::TimeTicks& time,
+ const Source& source,
+ EventPhase phase,
+ EventParameters* params) OVERRIDE;
+
+ // Can only be called when actively observing a ChromeNetLog.
+ void SetLogLevel(LogLevel log_level);
+
+ private:
+ ThreadSafeObserverImpl* owner_;
+ };
+
+ friend class PassThroughObserver;
+
+ // ChromeNetLog currently being observed. Set by
+ // AddAsObserver/RemoveAsObserver.
+ ChromeNetLog* net_log_;
+
+ // The observer we register in AddAsObserver, that passes stuff
+ // through to us.
+ PassThroughObserver internal_observer_;
+
+ DISALLOW_COPY_AND_ASSIGN(ThreadSafeObserverImpl);
};
ChromeNetLog();
@@ -111,19 +131,9 @@ class ChromeNetLog : public net::NetLog {
const base::TimeTicks& time,
const Source& source,
EventPhase phase,
- EventParameters* params);
- virtual uint32 NextID();
- virtual LogLevel GetLogLevel() const;
-
- void AddObserver(ThreadSafeObserver* observer);
- void RemoveObserver(ThreadSafeObserver* observer);
-
- // Adds |observer| and writes all passively captured events to
- // |passive_entries|. Guarantees that no events in |passive_entries| will be
- // sent to |observer| and all future events that have yet been sent to the
- // PassiveLogCollector will be sent to |observer|.
- void AddObserverAndGetAllPassivelyCapturedEvents(ThreadSafeObserver* observer,
- EntryList* passive_entries);
+ EventParameters* params) OVERRIDE;
+ virtual uint32 NextID() OVERRIDE;
+ virtual LogLevel GetLogLevel() const OVERRIDE;
void GetAllPassivelyCapturedEvents(EntryList* passive_entries);
@@ -136,6 +146,18 @@ class ChromeNetLog : public net::NetLog {
private:
void AddObserverWhileLockHeld(ThreadSafeObserver* observer);
+ // NetLog implementation
+ virtual void AddThreadSafeObserver(ThreadSafeObserver* observer) OVERRIDE;
+ virtual void RemoveThreadSafeObserver(ThreadSafeObserver* observer) OVERRIDE;
+
+ // Adds |observer| and writes all passively captured events to
+ // |passive_entries|. Guarantees that no events in |passive_entries| will be
+ // sent to |observer| and all future events that have yet been sent to the
+ // PassiveLogCollector will be sent to |observer|.
+ void AddObserverAndGetAllPassivelyCapturedEvents(ThreadSafeObserver* observer,
+ EntryList* passive_entries);
+
+
// Called whenever an observer is added or removed, or changes its log level.
// Must have acquired |lock_| prior to calling.
void UpdateLogLevel();