OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "net/base/capturing_net_log_observer.h" | |
6 | |
7 #include "base/values.h" | |
8 | |
9 namespace net { | |
10 | |
11 CapturingNetLogObserver::CapturingNetLogObserver() {} | |
12 | |
13 CapturingNetLogObserver::~CapturingNetLogObserver() {} | |
14 | |
15 void CapturingNetLogObserver::GetEntries( | |
16 CapturedNetLogEntry::List* entry_list) const { | |
17 base::AutoLock lock(lock_); | |
18 *entry_list = captured_entries_; | |
19 } | |
20 | |
21 void CapturingNetLogObserver::GetEntriesForSource( | |
22 NetLog::Source source, | |
23 CapturedNetLogEntry::List* entry_list) const { | |
24 base::AutoLock lock(lock_); | |
25 entry_list->clear(); | |
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); | |
31 } | |
32 } | |
33 | |
34 size_t CapturingNetLogObserver::GetSize() const { | |
35 base::AutoLock lock(lock_); | |
36 return captured_entries_.size(); | |
37 } | |
38 | |
39 void CapturingNetLogObserver::Clear() { | |
40 base::AutoLock lock(lock_); | |
41 captured_entries_.clear(); | |
42 } | |
43 | |
44 void CapturingNetLogObserver::OnAddEntry(const net::NetLog::Entry& entry) { | |
45 // Using Dictionaries instead of Values makes checking values a little | |
46 // simpler. | |
47 base::DictionaryValue* param_dict = nullptr; | |
48 base::Value* param_value = entry.ParametersToValue(); | |
49 if (param_value && !param_value->GetAsDictionary(¶m_dict)) | |
50 delete param_value; | |
51 | |
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(), | |
57 entry.source(), | |
58 entry.phase(), | |
59 scoped_ptr<base::DictionaryValue>(param_dict))); | |
60 } | |
61 | |
62 } // namespace net | |
OLD | NEW |