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 <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/atomicops.h" | 12 #include "base/atomicops.h" |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
17 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
18 #include "base/time.h" | 18 #include "base/time.h" |
19 #include "net/base/net_export.h" | |
20 #include "net/base/net_log.h" | 19 #include "net/base/net_log.h" |
21 | 20 |
22 namespace base { | 21 namespace base { |
23 class DictionaryValue; | 22 class DictionaryValue; |
24 } | 23 } |
25 | 24 |
26 namespace net { | 25 namespace net { |
27 | 26 |
28 // CapturingNetLog is an implementation of NetLog that saves messages to a | 27 // CapturingNetLog is an implementation of NetLog that saves messages to a |
29 // bounded buffer. CapturingNetLogs should only be used in unit tests, never | 28 // bounded buffer. CapturingNetLogs should only be used in unit tests, never |
eroman
2012/06/08 18:18:23
Perhaps this comment is less necessary now since i
mmenke
2012/06/08 18:27:07
Copied the updated comment from the other CL.
| |
30 // in production code. | 29 // in production code. |
31 // TODO(mmenke): Move CapturingNetLog to net_unittests project, once the CL | 30 // TODO(mmenke): Move CapturingNetLog to net_unittests project, once the CL |
eroman
2012/06/08 18:18:23
Remove this comment
mmenke
2012/06/08 18:27:07
Done.
| |
32 // to remove the use of it in the Jingle unit tests has landed. | 31 // to remove the use of it in the Jingle unit tests has landed. |
33 class NET_EXPORT CapturingNetLog : public NetLog { | 32 class CapturingNetLog : public NetLog { |
34 public: | 33 public: |
35 struct NET_EXPORT_PRIVATE CapturedEntry { | 34 struct CapturedEntry { |
36 CapturedEntry(EventType type, | 35 CapturedEntry(EventType type, |
37 const base::TimeTicks& time, | 36 const base::TimeTicks& time, |
38 Source source, | 37 Source source, |
39 EventPhase phase, | 38 EventPhase phase, |
40 scoped_ptr<base::DictionaryValue> params); | 39 scoped_ptr<base::DictionaryValue> params); |
41 // Copy constructor needed to store in a std::vector because of the | 40 // Copy constructor needed to store in a std::vector because of the |
42 // scoped_ptr. | 41 // scoped_ptr. |
43 CapturedEntry(const CapturedEntry& entry); | 42 CapturedEntry(const CapturedEntry& entry); |
44 | 43 |
45 ~CapturedEntry(); | 44 ~CapturedEntry(); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
109 NetLog::LogLevel log_level_; | 108 NetLog::LogLevel log_level_; |
110 | 109 |
111 DISALLOW_COPY_AND_ASSIGN(CapturingNetLog); | 110 DISALLOW_COPY_AND_ASSIGN(CapturingNetLog); |
112 }; | 111 }; |
113 | 112 |
114 // Helper class that exposes a similar API as BoundNetLog, but uses a | 113 // Helper class that exposes a similar API as BoundNetLog, but uses a |
115 // CapturingNetLog rather than the more generic NetLog. | 114 // CapturingNetLog rather than the more generic NetLog. |
116 // | 115 // |
117 // CapturingBoundNetLog can easily be converted to a BoundNetLog using the | 116 // CapturingBoundNetLog can easily be converted to a BoundNetLog using the |
118 // bound() method. | 117 // bound() method. |
119 class NET_EXPORT_PRIVATE CapturingBoundNetLog { | 118 class CapturingBoundNetLog { |
120 public: | 119 public: |
121 explicit CapturingBoundNetLog(size_t max_num_entries); | 120 explicit CapturingBoundNetLog(size_t max_num_entries); |
122 | 121 |
123 ~CapturingBoundNetLog(); | 122 ~CapturingBoundNetLog(); |
124 | 123 |
125 // The returned BoundNetLog is only valid while |this| is alive. | 124 // The returned BoundNetLog is only valid while |this| is alive. |
126 BoundNetLog bound() const { return net_log_; } | 125 BoundNetLog bound() const { return net_log_; } |
127 | 126 |
128 // Fills |entry_list| with all entries in the log. | 127 // Fills |entry_list| with all entries in the log. |
129 void GetEntries(CapturingNetLog::CapturedEntryList* entry_list) const; | 128 void GetEntries(CapturingNetLog::CapturedEntryList* entry_list) const; |
130 | 129 |
131 void Clear(); | 130 void Clear(); |
132 | 131 |
133 // Sets the log level of the underlying CapturingNetLog. | 132 // Sets the log level of the underlying CapturingNetLog. |
134 void SetLogLevel(NetLog::LogLevel log_level); | 133 void SetLogLevel(NetLog::LogLevel log_level); |
135 | 134 |
136 private: | 135 private: |
137 CapturingNetLog capturing_net_log_; | 136 CapturingNetLog capturing_net_log_; |
138 const BoundNetLog net_log_; | 137 const BoundNetLog net_log_; |
139 | 138 |
140 DISALLOW_COPY_AND_ASSIGN(CapturingBoundNetLog); | 139 DISALLOW_COPY_AND_ASSIGN(CapturingBoundNetLog); |
141 }; | 140 }; |
142 | 141 |
143 } // namespace net | 142 } // namespace net |
144 | 143 |
145 #endif // NET_BASE_CAPTURING_NET_LOG_H_ | 144 #endif // NET_BASE_CAPTURING_NET_LOG_H_ |
OLD | NEW |