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 #include "net/base/capturing_net_log_observer.h"
7 #include "base/values.h"
11 CapturingNetLogObserver::CapturingNetLogObserver() {}
13 CapturingNetLogObserver::~CapturingNetLogObserver() {}
15 void CapturingNetLogObserver::GetEntries(
16 CapturedNetLogEntry::List
* entry_list
) const {
17 base::AutoLock
lock(lock_
);
18 *entry_list
= captured_entries_
;
21 void CapturingNetLogObserver::GetEntriesForSource(
22 NetLog::Source source
,
23 CapturedNetLogEntry::List
* entry_list
) const {
24 base::AutoLock
lock(lock_
);
26 for (CapturedNetLogEntry::List::const_iterator entry
=
27 captured_entries_
.begin();
28 entry
!= captured_entries_
.end(); ++entry
) {
29 if (entry
->source
.id
== source
.id
)
30 entry_list
->push_back(*entry
);
34 size_t CapturingNetLogObserver::GetSize() const {
35 base::AutoLock
lock(lock_
);
36 return captured_entries_
.size();
39 void CapturingNetLogObserver::Clear() {
40 base::AutoLock
lock(lock_
);
41 captured_entries_
.clear();
44 void CapturingNetLogObserver::OnAddEntry(const net::NetLog::Entry
& entry
) {
45 // Using Dictionaries instead of Values makes checking values a little
47 base::DictionaryValue
* param_dict
= nullptr;
48 base::Value
* param_value
= entry
.ParametersToValue();
49 if (param_value
&& !param_value
->GetAsDictionary(¶m_dict
))
52 // Only need to acquire the lock when accessing class variables.
53 base::AutoLock
lock(lock_
);
54 captured_entries_
.push_back(
55 CapturedNetLogEntry(entry
.type(),
56 base::TimeTicks::Now(),
59 scoped_ptr
<base::DictionaryValue
>(param_dict
)));