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 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 18 CapturingNetLog::Entry::~Entry() {} 19 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 26 CapturingNetLog::~CapturingNetLog() {} 27 28 void CapturingNetLog::GetEntries(EntryList* entry_list) const { 29 base::AutoLock lock(lock_); 30 *entry_list = entries_; 31 } 32 33 void CapturingNetLog::Clear() { 34 base::AutoLock lock(lock_); 35 entries_.clear(); 36 } 37 38 void CapturingNetLog::SetLogLevel(NetLog::LogLevel log_level) { 39 base::AutoLock lock(lock_); 40 log_level_ = log_level; 41 } 42 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 54 uint32 CapturingNetLog::NextID() { 55 return base::subtle::NoBarrier_AtomicIncrement(&last_id_, 1); 56 } 57 58 NetLog::LogLevel CapturingNetLog::GetLogLevel() const { 59 base::AutoLock lock(lock_); 60 return log_level_; 61 } 62 63 CapturingBoundNetLog::CapturingBoundNetLog(const NetLog::Source& source, 64 CapturingNetLog* net_log) 65 : source_(source), capturing_net_log_(net_log) { 66 } 67 68 CapturingBoundNetLog::CapturingBoundNetLog(size_t max_num_entries) 69 : capturing_net_log_(new CapturingNetLog(max_num_entries)) {} 70 71 CapturingBoundNetLog::~CapturingBoundNetLog() {} 72 73 void CapturingBoundNetLog::GetEntries( 74 CapturingNetLog::EntryList* entry_list) const { 75 capturing_net_log_->GetEntries(entry_list); 76 } 77 78 void CapturingBoundNetLog::Clear() { 79 capturing_net_log_->Clear(); 80 } 81 82 void CapturingBoundNetLog::SetLogLevel(NetLog::LogLevel log_level) { 83 capturing_net_log_->SetLogLevel(log_level); 84 } 85 86 } // namespace net 87