forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcapturing_net_log_observer.cc
62 lines (50 loc) · 1.87 KB
/
capturing_net_log_observer.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "net/base/capturing_net_log_observer.h"
#include "base/values.h"
namespace net {
CapturingNetLogObserver::CapturingNetLogObserver() {}
CapturingNetLogObserver::~CapturingNetLogObserver() {}
void CapturingNetLogObserver::GetEntries(
CapturedNetLogEntry::List* entry_list) const {
base::AutoLock lock(lock_);
*entry_list = captured_entries_;
}
void CapturingNetLogObserver::GetEntriesForSource(
NetLog::Source source,
CapturedNetLogEntry::List* entry_list) const {
base::AutoLock lock(lock_);
entry_list->clear();
for (CapturedNetLogEntry::List::const_iterator entry =
captured_entries_.begin();
entry != captured_entries_.end(); ++entry) {
if (entry->source.id == source.id)
entry_list->push_back(*entry);
}
}
size_t CapturingNetLogObserver::GetSize() const {
base::AutoLock lock(lock_);
return captured_entries_.size();
}
void CapturingNetLogObserver::Clear() {
base::AutoLock lock(lock_);
captured_entries_.clear();
}
void CapturingNetLogObserver::OnAddEntry(const net::NetLog::Entry& entry) {
// Using Dictionaries instead of Values makes checking values a little
// simpler.
base::DictionaryValue* param_dict = nullptr;
base::Value* param_value = entry.ParametersToValue();
if (param_value && !param_value->GetAsDictionary(¶m_dict))
delete param_value;
// Only need to acquire the lock when accessing class variables.
base::AutoLock lock(lock_);
captured_entries_.push_back(
CapturedNetLogEntry(entry.type(),
base::TimeTicks::Now(),
entry.source(),
entry.phase(),
scoped_ptr<base::DictionaryValue>(param_dict)));
}
} // namespace net