OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef NET_LOG_CAPTURING_NET_LOG_H_ | |
6 #define NET_LOG_CAPTURING_NET_LOG_H_ | |
7 | |
8 #include <string> | |
9 #include <vector> | |
10 | |
11 #include "base/basictypes.h" | |
12 #include "base/compiler_specific.h" | |
13 #include "net/log/captured_net_log_entry.h" | |
14 #include "net/log/capturing_net_log_observer.h" | |
15 #include "net/log/net_log.h" | |
16 | |
17 namespace net { | |
18 | |
19 // CapturingNetLog is convenience class which combines a NetLog and a | |
20 // CapturingNetLogObserver. It is intended for testing only, and is part of the | |
21 // net_test_support project. | |
22 class CapturingNetLog : public NetLog { | |
23 public: | |
24 // TODO(mmenke): Get rid of these. | |
25 typedef CapturedNetLogEntry CapturedEntry; | |
26 typedef CapturedNetLogEntry::List CapturedEntryList; | |
27 | |
28 CapturingNetLog(); | |
29 ~CapturingNetLog() override; | |
30 | |
31 void SetLogLevel(LogLevel log_level); | |
32 | |
33 // Below methods are forwarded to capturing_net_log_observer_. | |
34 void GetEntries(CapturedEntryList* entry_list) const; | |
35 void GetEntriesForSource(Source source, CapturedEntryList* entry_list) const; | |
36 size_t GetSize() const; | |
37 void Clear(); | |
38 | |
39 private: | |
40 CapturingNetLogObserver capturing_net_log_observer_; | |
41 | |
42 DISALLOW_COPY_AND_ASSIGN(CapturingNetLog); | |
43 }; | |
44 | |
45 // Helper class that exposes a similar API as BoundNetLog, but uses a | |
46 // CapturingNetLog rather than the more generic NetLog. | |
47 // | |
48 // A CapturingBoundNetLog can easily be converted to a BoundNetLog using the | |
49 // bound() method. | |
50 class CapturingBoundNetLog { | |
51 public: | |
52 CapturingBoundNetLog(); | |
53 ~CapturingBoundNetLog(); | |
54 | |
55 // The returned BoundNetLog is only valid while |this| is alive. | |
56 BoundNetLog bound() const { return net_log_; } | |
57 | |
58 // Fills |entry_list| with all entries in the log. | |
59 void GetEntries(CapturingNetLog::CapturedEntryList* entry_list) const; | |
60 | |
61 // Fills |entry_list| with all entries in the log from the specified Source. | |
62 void GetEntriesForSource( | |
63 NetLog::Source source, | |
64 CapturingNetLog::CapturedEntryList* entry_list) const; | |
65 | |
66 // Returns number of entries in the log. | |
67 size_t GetSize() const; | |
68 | |
69 void Clear(); | |
70 | |
71 // Sets the log level of the underlying CapturingNetLog. | |
72 void SetLogLevel(NetLog::LogLevel log_level); | |
73 | |
74 private: | |
75 CapturingNetLog capturing_net_log_; | |
76 const BoundNetLog net_log_; | |
77 | |
78 DISALLOW_COPY_AND_ASSIGN(CapturingBoundNetLog); | |
79 }; | |
80 | |
81 } // namespace net | |
82 | |
83 #endif // NET_LOG_CAPTURING_NET_LOG_H_ | |
OLD | NEW |