Index: net/base/net_log.h |
diff --git a/net/base/net_log.h b/net/base/net_log.h |
index 8ae33e94b745e050eae956b3a1c0a5aac452b133..66a3e505f48a180392427c8c12f63edeb7a98b3f 100644 |
--- a/net/base/net_log.h |
+++ b/net/base/net_log.h |
@@ -7,10 +7,13 @@ |
#include <string> |
+#include "base/atomicops.h" |
#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/synchronization/lock.h" |
#include "base/time.h" |
#include "net/base/net_export.h" |
@@ -198,8 +201,8 @@ class NET_EXPORT NetLog { |
DISALLOW_COPY_AND_ASSIGN(ThreadSafeObserver); |
}; |
- NetLog() {} |
- virtual ~NetLog() {} |
+ NetLog(); |
+ virtual ~NetLog(); |
// Emits a global event to the log stream, with its own unique source ID. |
void AddGlobalEntry(EventType type); |
@@ -208,11 +211,14 @@ 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(); |
+ |
+ // Set the lowest allowed log level, regardless of any Observers. |
+ void SetBaseLogLevel(LogLevel log_level); |
mmenke
2013/06/03 14:27:09
Suggest making this protected, to discourage exter
kouhei (in TOK)
2013/06/04 15:41:44
Done.
|
// 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 +230,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. |
@@ -293,10 +297,6 @@ class NET_EXPORT NetLog { |
const base::string16* value); |
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; |
- |
// Subclasses must call these in the corresponding functions to set an |
// observer's |net_log_| and |log_level_| values. |
mmenke
2013/06/03 14:27:09
This comment is no longer accurate, though I think
kouhei (in TOK)
2013/06/04 15:41:44
Done.
|
void OnAddObserver(ThreadSafeObserver* observer, LogLevel log_level); |
@@ -312,6 +312,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_; |
+ |
+ // Last assigned source ID. Incremented to get the next one. |
+ base::subtle::Atomic32 last_id_; |
+ |
+ // The lowest allowed log level, regardless of any Observers. |
+ // Normally defaults to LOG_NONE, but can be changed with command line flags |
mmenke
2013/06/03 14:27:09
Fix comment: "but can be changed with SetLogLevel
kouhei (in TOK)
2013/06/04 15:41:44
Done.
|
+ 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); |
}; |