OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_NET_CHROME_NET_LOG_H_ | 5 #ifndef CHROME_BROWSER_NET_CHROME_NET_LOG_H_ |
6 #define CHROME_BROWSER_NET_CHROME_NET_LOG_H_ | 6 #define CHROME_BROWSER_NET_CHROME_NET_LOG_H_ |
7 | 7 |
8 #include "base/atomicops.h" | 8 #include "base/atomicops.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/observer_list.h" | 10 #include "base/observer_list.h" |
11 #include "base/synchronization/lock.h" | 11 #include "base/synchronization/lock.h" |
12 #include "net/base/net_log.h" | 12 #include "net/base/net_log.h" |
13 | 13 |
14 class NetLogLogger; | 14 class NetLogLogger; |
15 class NetLogTempFile; | 15 class NetLogTempFile; |
16 | 16 |
17 // ChromeNetLog is an implementation of NetLog that dispatches network log | 17 // ChromeNetLog is an implementation of NetLog that dispatches network log |
18 // messages to a list of observers. | 18 // messages to a list of observers. |
19 // | 19 // |
20 // All methods are thread safe, with the exception that no NetLog or | 20 // All methods are thread safe, with the exception that no NetLog or |
21 // NetLog::ThreadSafeObserver functions may be called by an observer's | 21 // NetLog::ThreadSafeObserver functions may be called by an observer's |
22 // OnAddEntry() method. Doing so will result in a deadlock. | 22 // OnAddEntry() method. Doing so will result in a deadlock. |
23 class ChromeNetLog : public net::NetLog { | 23 class ChromeNetLog : public net::NetLog { |
24 public: | 24 public: |
25 ChromeNetLog(); | 25 ChromeNetLog(); |
26 virtual ~ChromeNetLog(); | 26 virtual ~ChromeNetLog(); |
27 | 27 |
28 // NetLog implementation: | |
29 virtual uint32 NextID() OVERRIDE; | |
30 virtual LogLevel GetLogLevel() const OVERRIDE; | |
31 virtual void AddThreadSafeObserver(ThreadSafeObserver* observer, | |
32 LogLevel log_level) OVERRIDE; | |
33 virtual void SetObserverLogLevel(ThreadSafeObserver* observer, | |
34 LogLevel log_level) OVERRIDE; | |
35 virtual void RemoveThreadSafeObserver(ThreadSafeObserver* observer) OVERRIDE; | |
36 | |
37 NetLogTempFile* net_log_temp_file() { | 28 NetLogTempFile* net_log_temp_file() { |
38 return net_log_temp_file_.get(); | 29 return net_log_temp_file_.get(); |
39 } | 30 } |
40 | 31 |
41 private: | 32 private: |
42 // NetLog implementation: | |
43 virtual void OnAddEntry(const net::NetLog::Entry& entry) OVERRIDE; | |
44 | |
45 // Called whenever an observer is added or removed, or has its log level | |
46 // changed. Must have acquired |lock_| prior to calling. | |
47 void UpdateLogLevel(); | |
48 | |
49 // |lock_| protects access to |observers_|. | |
50 base::Lock lock_; | |
51 | |
52 // Last assigned source ID. Incremented to get the next one. | |
53 base::subtle::Atomic32 last_id_; | |
54 | |
55 // The lowest allowed log level, regardless of any ChromeNetLogObservers. | |
56 // Normally defaults to LOG_BASIC, but can be changed with command line flags. | |
57 LogLevel base_log_level_; | |
58 | |
59 // The current log level. | |
60 base::subtle::Atomic32 effective_log_level_; | |
61 | |
62 scoped_ptr<NetLogLogger> net_log_logger_; | 33 scoped_ptr<NetLogLogger> net_log_logger_; |
63 scoped_ptr<NetLogTempFile> net_log_temp_file_; | 34 scoped_ptr<NetLogTempFile> net_log_temp_file_; |
64 | 35 |
65 // |lock_| must be acquired whenever reading or writing to this. | |
66 ObserverList<ThreadSafeObserver, true> observers_; | |
67 | |
68 DISALLOW_COPY_AND_ASSIGN(ChromeNetLog); | 36 DISALLOW_COPY_AND_ASSIGN(ChromeNetLog); |
69 }; | 37 }; |
70 | 38 |
71 #endif // CHROME_BROWSER_NET_CHROME_NET_LOG_H_ | 39 #endif // CHROME_BROWSER_NET_CHROME_NET_LOG_H_ |
OLD | NEW |