1 // Copyright 2014 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_OBSERVER_H_
6 #define NET_LOG_CAPTURING_NET_LOG_OBSERVER_H_
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "base/synchronization/lock.h"
14 #include "net/log/captured_net_log_entry.h"
15 #include "net/log/net_log.h"
18 class DictionaryValue
;
24 // CapturingNetLogObserver is an implementation of NetLog::ThreadSafeObserver
25 // that saves messages to a bounded buffer. It is intended for testing only,
26 // and is part of the net_test_support project.
27 class CapturingNetLogObserver
: public NetLog::ThreadSafeObserver
{
29 CapturingNetLogObserver();
30 ~CapturingNetLogObserver() override
;
32 // Returns the list of all entries in the log.
33 void GetEntries(CapturedNetLogEntry::List
* entry_list
) const;
35 // Fills |entry_list| with all entries in the log from the specified Source.
36 void GetEntriesForSource(NetLog::Source source
,
37 CapturedNetLogEntry::List
* entry_list
) const;
39 // Returns number of entries in the log.
40 size_t GetSize() const;
45 // ThreadSafeObserver implementation:
46 void OnAddEntry(const NetLog::Entry
& entry
) override
;
48 // Needs to be "mutable" so can use it in GetEntries().
49 mutable base::Lock lock_
;
51 CapturedNetLogEntry::List captured_entries_
;
53 DISALLOW_COPY_AND_ASSIGN(CapturingNetLogObserver
);
58 #endif // NET_LOG_CAPTURING_NET_LOG_OBSERVER_H_