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/log/capturing_net_log_observer.h"
7 #include "base/values.h"
11 CapturingNetLogObserver::CapturingNetLogObserver() {
14 CapturingNetLogObserver::~CapturingNetLogObserver() {
17 void CapturingNetLogObserver::GetEntries(
18 CapturedNetLogEntry::List
* entry_list
) const {
19 base::AutoLock
lock(lock_
);
20 *entry_list
= captured_entries_
;
23 void CapturingNetLogObserver::GetEntriesForSource(
24 NetLog::Source source
,
25 CapturedNetLogEntry::List
* entry_list
) const {
26 base::AutoLock
lock(lock_
);
28 for (CapturedNetLogEntry::List::const_iterator entry
=
29 captured_entries_
.begin();
30 entry
!= captured_entries_
.end(); ++entry
) {
31 if (entry
->source
.id
== source
.id
)
32 entry_list
->push_back(*entry
);
36 size_t CapturingNetLogObserver::GetSize() const {
37 base::AutoLock
lock(lock_
);
38 return captured_entries_
.size();
41 void CapturingNetLogObserver::Clear() {
42 base::AutoLock
lock(lock_
);
43 captured_entries_
.clear();
46 void CapturingNetLogObserver::OnAddEntry(const net::NetLog::Entry
& entry
) {
47 // Using Dictionaries instead of Values makes checking values a little
49 base::DictionaryValue
* param_dict
= nullptr;
50 base::Value
* param_value
= entry
.ParametersToValue();
51 if (param_value
&& !param_value
->GetAsDictionary(¶m_dict
))
54 // Only need to acquire the lock when accessing class variables.
55 base::AutoLock
lock(lock_
);
56 captured_entries_
.push_back(CapturedNetLogEntry(
57 entry
.type(), base::TimeTicks::Now(), entry
.source(), entry
.phase(),
58 scoped_ptr
<base::DictionaryValue
>(param_dict
)));