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 NET_BASE_CAPTURING_NET_LOG_H_ | 5 #ifndef NET_BASE_CAPTURING_NET_LOG_H_ |
6 #define NET_BASE_CAPTURING_NET_LOG_H_ | 6 #define NET_BASE_CAPTURING_NET_LOG_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/atomicops.h" | 11 #include "base/atomicops.h" |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/memory/scoped_ptr.h" | |
16 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" |
17 #include "base/time.h" | 16 #include "base/time.h" |
18 #include "net/base/net_export.h" | 17 #include "net/base/net_export.h" |
19 #include "net/base/net_log.h" | 18 #include "net/base/net_log.h" |
20 | 19 |
21 namespace net { | 20 namespace net { |
22 | 21 |
23 // CapturingNetLog is an implementation of NetLog that saves messages to a | 22 // CapturingNetLog is an implementation of NetLog that saves messages to a |
24 // bounded buffer. | 23 // bounded buffer. |
25 class NET_EXPORT CapturingNetLog : public NetLog { | 24 class NET_EXPORT CapturingNetLog : public NetLog { |
(...skipping 24 matching lines...) Expand all Loading... |
50 virtual ~CapturingNetLog(); | 49 virtual ~CapturingNetLog(); |
51 | 50 |
52 // Returns the list of all entries in the log. | 51 // Returns the list of all entries in the log. |
53 void GetEntries(EntryList* entry_list) const; | 52 void GetEntries(EntryList* entry_list) const; |
54 | 53 |
55 void Clear(); | 54 void Clear(); |
56 | 55 |
57 void SetLogLevel(NetLog::LogLevel log_level); | 56 void SetLogLevel(NetLog::LogLevel log_level); |
58 | 57 |
59 // NetLog implementation: | 58 // NetLog implementation: |
60 virtual void AddEntry(EventType type, | 59 virtual void AddEntry( |
61 const base::TimeTicks& time, | 60 EventType type, |
62 const Source& source, | 61 const Source& source, |
63 EventPhase phase, | 62 EventPhase phase, |
64 EventParameters* extra_parameters) OVERRIDE; | 63 const scoped_refptr<EventParameters>& extra_parameters) OVERRIDE; |
65 virtual uint32 NextID() OVERRIDE; | 64 virtual uint32 NextID() OVERRIDE; |
66 virtual LogLevel GetLogLevel() const OVERRIDE; | 65 virtual LogLevel GetLogLevel() const OVERRIDE; |
67 virtual void AddThreadSafeObserver(ThreadSafeObserver* observer, | 66 virtual void AddThreadSafeObserver(ThreadSafeObserver* observer, |
68 LogLevel log_level) OVERRIDE; | 67 LogLevel log_level) OVERRIDE; |
69 virtual void SetObserverLogLevel(ThreadSafeObserver* observer, | 68 virtual void SetObserverLogLevel(ThreadSafeObserver* observer, |
70 LogLevel log_level) OVERRIDE; | 69 LogLevel log_level) OVERRIDE; |
71 virtual void RemoveThreadSafeObserver(ThreadSafeObserver* observer) OVERRIDE; | 70 virtual void RemoveThreadSafeObserver(ThreadSafeObserver* observer) OVERRIDE; |
72 | 71 |
73 private: | 72 private: |
74 // Needs to be "mutable" so can use it in GetEntries(). | 73 // Needs to be "mutable" so can use it in GetEntries(). |
(...skipping 10 matching lines...) Expand all Loading... |
85 DISALLOW_COPY_AND_ASSIGN(CapturingNetLog); | 84 DISALLOW_COPY_AND_ASSIGN(CapturingNetLog); |
86 }; | 85 }; |
87 | 86 |
88 // Helper class that exposes a similar API as BoundNetLog, but uses a | 87 // Helper class that exposes a similar API as BoundNetLog, but uses a |
89 // CapturingNetLog rather than the more generic NetLog. | 88 // CapturingNetLog rather than the more generic NetLog. |
90 // | 89 // |
91 // CapturingBoundNetLog can easily be converted to a BoundNetLog using the | 90 // CapturingBoundNetLog can easily be converted to a BoundNetLog using the |
92 // bound() method. | 91 // bound() method. |
93 class NET_EXPORT_PRIVATE CapturingBoundNetLog { | 92 class NET_EXPORT_PRIVATE CapturingBoundNetLog { |
94 public: | 93 public: |
95 CapturingBoundNetLog(const NetLog::Source& source, CapturingNetLog* net_log); | |
96 | |
97 explicit CapturingBoundNetLog(size_t max_num_entries); | 94 explicit CapturingBoundNetLog(size_t max_num_entries); |
98 | 95 |
99 ~CapturingBoundNetLog(); | 96 ~CapturingBoundNetLog(); |
100 | 97 |
101 // The returned BoundNetLog is only valid while |this| is alive. | 98 // The returned BoundNetLog is only valid while |this| is alive. |
102 BoundNetLog bound() const { | 99 BoundNetLog bound() const { return net_log_; } |
103 return BoundNetLog(source_, capturing_net_log_.get()); | |
104 } | |
105 | 100 |
106 // Fills |entry_list| with all entries in the log. | 101 // Fills |entry_list| with all entries in the log. |
107 void GetEntries(CapturingNetLog::EntryList* entry_list) const; | 102 void GetEntries(CapturingNetLog::EntryList* entry_list) const; |
108 | 103 |
109 void Clear(); | 104 void Clear(); |
110 | 105 |
111 // Sets the log level of the underlying CapturingNetLog. | 106 // Sets the log level of the underlying CapturingNetLog. |
112 void SetLogLevel(NetLog::LogLevel log_level); | 107 void SetLogLevel(NetLog::LogLevel log_level); |
113 | 108 |
114 private: | 109 private: |
115 NetLog::Source source_; | 110 CapturingNetLog capturing_net_log_; |
116 scoped_ptr<CapturingNetLog> capturing_net_log_; | 111 const BoundNetLog net_log_; |
117 | 112 |
118 DISALLOW_COPY_AND_ASSIGN(CapturingBoundNetLog); | 113 DISALLOW_COPY_AND_ASSIGN(CapturingBoundNetLog); |
119 }; | 114 }; |
120 | 115 |
121 } // namespace net | 116 } // namespace net |
122 | 117 |
123 #endif // NET_BASE_CAPTURING_NET_LOG_H_ | 118 #endif // NET_BASE_CAPTURING_NET_LOG_H_ |
OLD | NEW |