• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2010 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.h"
6 
7 namespace net {
8 
Entry(EventType type,const base::TimeTicks & time,Source source,EventPhase phase,EventParameters * extra_parameters)9 CapturingNetLog::Entry::Entry(EventType type,
10                               const base::TimeTicks& time,
11                               Source source,
12                               EventPhase phase,
13                               EventParameters* extra_parameters)
14     : type(type), time(time), source(source), phase(phase),
15       extra_parameters(extra_parameters) {
16 }
17 
~Entry()18 CapturingNetLog::Entry::~Entry() {}
19 
CapturingNetLog(size_t max_num_entries)20 CapturingNetLog::CapturingNetLog(size_t max_num_entries)
21     : last_id_(-1),
22       max_num_entries_(max_num_entries),
23       log_level_(LOG_ALL_BUT_BYTES) {
24 }
25 
~CapturingNetLog()26 CapturingNetLog::~CapturingNetLog() {}
27 
GetEntries(EntryList * entry_list) const28 void CapturingNetLog::GetEntries(EntryList* entry_list) const {
29   base::AutoLock lock(lock_);
30   *entry_list = entries_;
31 }
32 
Clear()33 void CapturingNetLog::Clear() {
34   base::AutoLock lock(lock_);
35   entries_.clear();
36 }
37 
SetLogLevel(NetLog::LogLevel log_level)38 void CapturingNetLog::SetLogLevel(NetLog::LogLevel log_level) {
39   base::AutoLock lock(lock_);
40   log_level_ = log_level;
41 }
42 
AddEntry(EventType type,const base::TimeTicks & time,const Source & source,EventPhase phase,EventParameters * extra_parameters)43 void CapturingNetLog::AddEntry(EventType type,
44                                const base::TimeTicks& time,
45                                const Source& source,
46                                EventPhase phase,
47                                EventParameters* extra_parameters) {
48   base::AutoLock lock(lock_);
49   Entry entry(type, time, source, phase, extra_parameters);
50   if (entries_.size() + 1 < max_num_entries_)
51     entries_.push_back(entry);
52 }
53 
NextID()54 uint32 CapturingNetLog::NextID() {
55   return base::subtle::NoBarrier_AtomicIncrement(&last_id_, 1);
56 }
57 
GetLogLevel() const58 NetLog::LogLevel CapturingNetLog::GetLogLevel() const {
59   base::AutoLock lock(lock_);
60   return log_level_;
61 }
62 
CapturingBoundNetLog(const NetLog::Source & source,CapturingNetLog * net_log)63 CapturingBoundNetLog::CapturingBoundNetLog(const NetLog::Source& source,
64                                            CapturingNetLog* net_log)
65     : source_(source), capturing_net_log_(net_log) {
66 }
67 
CapturingBoundNetLog(size_t max_num_entries)68 CapturingBoundNetLog::CapturingBoundNetLog(size_t max_num_entries)
69     : capturing_net_log_(new CapturingNetLog(max_num_entries)) {}
70 
~CapturingBoundNetLog()71 CapturingBoundNetLog::~CapturingBoundNetLog() {}
72 
GetEntries(CapturingNetLog::EntryList * entry_list) const73 void CapturingBoundNetLog::GetEntries(
74     CapturingNetLog::EntryList* entry_list) const {
75   capturing_net_log_->GetEntries(entry_list);
76 }
77 
Clear()78 void CapturingBoundNetLog::Clear() {
79   capturing_net_log_->Clear();
80 }
81 
SetLogLevel(NetLog::LogLevel log_level)82 void CapturingBoundNetLog::SetLogLevel(NetLog::LogLevel log_level) {
83   capturing_net_log_->SetLogLevel(log_level);
84 }
85 
86 }  // namespace net
87