Index: net/base/net_log.h |
diff --git a/net/base/net_log.h b/net/base/net_log.h |
index 8ae33e94b745e050eae956b3a1c0a5aac452b133..863080f814faa0b54d4ed2b5e20aee2729eeacc4 100644 |
--- a/net/base/net_log.h |
+++ b/net/base/net_log.h |
@@ -10,6 +10,7 @@ |
#include "base/basictypes.h" |
#include "base/callback_forward.h" |
#include "base/compiler_specific.h" |
+#include "base/observer_list.h" |
#include "base/string16.h" |
#include "base/time.h" |
#include "net/base/net_export.h" |
@@ -198,8 +199,8 @@ class NET_EXPORT NetLog { |
DISALLOW_COPY_AND_ASSIGN(ThreadSafeObserver); |
}; |
- NetLog() {} |
- virtual ~NetLog() {} |
+ explicit NetLog(LogLevel base_log_level = LOG_NONE); |
mmenke
2013/05/30 18:18:59
The Google style guide comes out pretty strongly a
kouhei (in TOK)
2013/05/31 06:30:03
Done.
|
+ virtual ~NetLog(); |
// Emits a global event to the log stream, with its own unique source ID. |
void AddGlobalEntry(EventType type); |
@@ -208,11 +209,11 @@ class NET_EXPORT NetLog { |
// Returns a unique ID which can be used as a source ID. All returned IDs |
// will be unique and greater than 0. |
- virtual uint32 NextID() = 0; |
+ uint32 NextID(); |
// Returns the logging level for this NetLog. This is used to avoid computing |
// and saving expensive log entries. |
- virtual LogLevel GetLogLevel() const = 0; |
+ LogLevel GetLogLevel() const; |
// Adds an observer and sets its log level. The observer must not be |
// watching any NetLog, including this one, when this is called. |
@@ -224,21 +225,19 @@ class NET_EXPORT NetLog { |
// |
// NetLog implementations must call NetLog::OnAddObserver to update the |
// observer's internal state. |
- virtual void AddThreadSafeObserver(ThreadSafeObserver* observer, |
- LogLevel log_level) = 0; |
+ void AddThreadSafeObserver(ThreadSafeObserver* observer, LogLevel log_level); |
// 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; |
+ void SetObserverLogLevel(ThreadSafeObserver* observer, LogLevel log_level); |
// 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; |
+ void RemoveThreadSafeObserver(ThreadSafeObserver* observer); |
// Converts a time to the string format that the NetLog uses to represent |
// times. Strings are used since integers may overflow. |
@@ -295,7 +294,7 @@ class NET_EXPORT NetLog { |
protected: |
// Child classes should respond to the new entry here. This includes |
// creating the Entry object and alerting their observers. |
- virtual void OnAddEntry(const Entry& entry) = 0; |
+ void OnAddEntry(const Entry& entry); |
// Subclasses must call these in the corresponding functions to set an |
// observer's |net_log_| and |log_level_| values. |
@@ -312,6 +311,26 @@ class NET_EXPORT NetLog { |
EventPhase phase, |
const NetLog::ParametersCallback* parameters_callback); |
+ // Called whenever an observer is added or removed, or has its log level |
+ // changed. Must have acquired |lock_| prior to calling. |
+ void UpdateLogLevel(); |
+ |
+ // |lock_| protects access to |observers_|. |
+ base::Lock lock_; |
mmenke
2013/05/30 18:18:59
Need a header for this.
kouhei (in TOK)
2013/05/31 06:30:03
Done.
|
+ |
+ // Last assigned source ID. Incremented to get the next one. |
+ base::subtle::Atomic32 last_id_; |
mmenke
2013/05/30 18:18:59
Need a header for this.
kouhei (in TOK)
2013/05/31 06:30:03
Done.
|
+ |
+ // The lowest allowed log level, regardless of any Observers. |
+ // Normally defaults to LOG_NONE, but can be changed with command line flags. |
+ const LogLevel base_log_level_; |
+ |
+ // The current log level. |
+ base::subtle::Atomic32 effective_log_level_; |
+ |
+ // |lock_| must be acquired whenever reading or writing to this. |
+ ObserverList<ThreadSafeObserver, true> observers_; |
+ |
DISALLOW_COPY_AND_ASSIGN(NetLog); |
}; |