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.
5 #ifndef NET_LOG_CAPTURING_NET_LOG_H_
6 #define NET_LOG_CAPTURING_NET_LOG_H_
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"
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
{
24 // TODO(mmenke): Get rid of these.
25 typedef CapturedNetLogEntry CapturedEntry
;
26 typedef CapturedNetLogEntry::List CapturedEntryList
;
29 ~CapturingNetLog() override
;
31 void SetLogLevel(LogLevel log_level
);
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;
40 CapturingNetLogObserver capturing_net_log_observer_
;
42 DISALLOW_COPY_AND_ASSIGN(CapturingNetLog
);
45 // Helper class that exposes a similar API as BoundNetLog, but uses a
46 // CapturingNetLog rather than the more generic NetLog.
48 // A CapturingBoundNetLog can easily be converted to a BoundNetLog using the
50 class CapturingBoundNetLog
{
52 CapturingBoundNetLog();
53 ~CapturingBoundNetLog();
55 // The returned BoundNetLog is only valid while |this| is alive.
56 BoundNetLog
bound() const { return net_log_
; }
58 // Fills |entry_list| with all entries in the log.
59 void GetEntries(CapturingNetLog::CapturedEntryList
* entry_list
) const;
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;
66 // Returns number of entries in the log.
67 size_t GetSize() const;
71 // Sets the log level of the underlying CapturingNetLog.
72 void SetLogLevel(NetLog::LogLevel log_level
);
75 CapturingNetLog capturing_net_log_
;
76 const BoundNetLog net_log_
;
78 DISALLOW_COPY_AND_ASSIGN(CapturingBoundNetLog
);
83 #endif // NET_LOG_CAPTURING_NET_LOG_H_