summaryrefslogtreecommitdiffstats
path: root/net/base/net_log.h
diff options
context:
space:
mode:
authormmenke@chromium.org <mmenke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-29 12:43:23 +0000
committermmenke@chromium.org <mmenke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-29 12:43:23 +0000
commitd5cbd92ad951a1c2c24cafebab8bbf3d084b1378 (patch)
tree2c48c137de27922fe1da18620568c4d442ddbe2c /net/base/net_log.h
parent679a319c1fbb027fff52dee50a381ea054092b00 (diff)
downloadchromium_src-d5cbd92ad951a1c2c24cafebab8bbf3d084b1378.zip
chromium_src-d5cbd92ad951a1c2c24cafebab8bbf3d084b1378.tar.gz
chromium_src-d5cbd92ad951a1c2c24cafebab8bbf3d084b1378.tar.bz2
Remove the ChromeNetLog observer classes, using NetLog::ThreadSafeObserver
instead, slightly modifying the NetLog interface to do so. R=eroman@chromium.org BUG=114611 Review URL: http://codereview.chromium.org/9415013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@124176 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/net_log.h')
-rw-r--r--net/base/net_log.h64
1 files changed, 46 insertions, 18 deletions
diff --git a/net/base/net_log.h b/net/base/net_log.h
index f2b4e76..cfb8081 100644
--- a/net/base/net_log.h
+++ b/net/base/net_log.h
@@ -111,20 +111,22 @@ class NET_EXPORT NetLog {
// the specified minimum event granularity. A ThreadSafeObserver can only
// observe a single NetLog 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.
- //
// 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);
+ //
+ // Observers must stop watching a NetLog before either the Observer or the
+ // NetLog is destroyed.
+ ThreadSafeObserver();
virtual ~ThreadSafeObserver();
// Returns the minimum log level for events this observer wants to
- // receive.
+ // receive. Must not be called when not watching a NetLog.
LogLevel log_level() const;
+ // Returns the NetLog we are currently watching, if any. Returns NULL
+ // otherwise.
+ NetLog* net_log() const;
+
// 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.
@@ -137,13 +139,13 @@ class NET_EXPORT NetLog {
EventPhase phase,
EventParameters* params) = 0;
- protected:
- // Subclasses should only ever modify this if they somehow
- // collaborate with concrete implementations of NetLog to enable
- // modification.
+ private:
+ friend class NetLog;
+
+ // Both of these values are only modified by the NetLog.
LogLevel log_level_;
+ NetLog* net_log_;
- private:
DISALLOW_COPY_AND_ASSIGN(ThreadSafeObserver);
};
@@ -173,12 +175,30 @@ class NET_EXPORT NetLog {
// and saving expensive log entries.
virtual LogLevel GetLogLevel() const = 0;
- // Adds an observer. Each observer may be added only once and must
- // be removed via |RemoveObserver()| before this object goes out of
- // scope.
- virtual void AddThreadSafeObserver(ThreadSafeObserver* observer) = 0;
-
- // Removes an observer.
+ // Adds an observer and sets its log level. The observer must not be
+ // watching any NetLog, including this one, when this is called.
+ //
+ // Typical observers should specify LOG_BASIC.
+ //
+ // Observers that need to see the full granularity of events can specify
+ // LOG_ALL_BUT_BYTES. However, doing so will have performance consequences.
+ //
+ // NetLog implementations must call NetLog::OnAddObserver to update the
+ // observer's internal state.
+ virtual void AddThreadSafeObserver(ThreadSafeObserver* observer,
+ LogLevel log_level) = 0;
+
+ // Sets the log level of |observer| to |log_level|. |observer| must be
+ // watching |this|. NetLog implementations must call
+ // NetLog::OnSetObserverLogLevel to update the observer's internal state.
+ virtual void SetObserverLogLevel(ThreadSafeObserver* observer,
+ LogLevel log_level) = 0;
+
+ // Removes an observer. NetLog implementations must call
+ // NetLog::OnAddObserver to update the observer's internal state.
+ //
+ // For thread safety reasons, it is recommended that this not be called in
+ // an object's destructor.
virtual void RemoveThreadSafeObserver(ThreadSafeObserver* observer) = 0;
// Converts a time to the string format that the NetLog uses to represent
@@ -211,6 +231,14 @@ class NET_EXPORT NetLog {
NetLog::EventParameters* params,
bool use_strings);
+ protected:
+ // Subclasses must call these in the corresponding functions to set an
+ // observer's |net_log_| and |log_level_| values.
+ void OnAddObserver(ThreadSafeObserver* observer, LogLevel log_level);
+ void OnSetObserverLogLevel(ThreadSafeObserver* observer,
+ LogLevel log_level);
+ void OnRemoveObserver(ThreadSafeObserver* observer);
+
private:
DISALLOW_COPY_AND_ASSIGN(NetLog);
};