| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/base/capturing_net_log.h" | 5 #include "net/base/capturing_net_log.h" |
| 6 | 6 |
| 7 namespace net { | 7 namespace net { |
| 8 | 8 |
| 9 CapturingNetLog::Entry::Entry(EventType type, | 9 CapturingNetLog::Entry::Entry(EventType type, |
| 10 const base::TimeTicks& time, | 10 const base::TimeTicks& time, |
| 11 Source source, | 11 Source source, |
| 12 EventPhase phase, | 12 EventPhase phase, |
| 13 EventParameters* extra_parameters) | 13 EventParameters* extra_parameters) |
| 14 : type(type), time(time), source(source), phase(phase), | 14 : type(type), time(time), source(source), phase(phase), |
| 15 extra_parameters(extra_parameters) { | 15 extra_parameters(extra_parameters) { |
| 16 } | 16 } |
| 17 | 17 |
| 18 CapturingNetLog::Entry::~Entry() {} | 18 CapturingNetLog::Entry::~Entry() {} |
| 19 | 19 |
| 20 CapturingNetLog::CapturingNetLog(size_t max_num_entries) | 20 CapturingNetLog::CapturingNetLog(size_t max_num_entries) |
| 21 : next_id_(0), max_num_entries_(max_num_entries) { | 21 : last_id_(-1), max_num_entries_(max_num_entries) { |
| 22 } | 22 } |
| 23 | 23 |
| 24 CapturingNetLog::~CapturingNetLog() {} | 24 CapturingNetLog::~CapturingNetLog() {} |
| 25 | 25 |
| 26 void CapturingNetLog::AddEntry(EventType type, | 26 void CapturingNetLog::AddEntry(EventType type, |
| 27 const base::TimeTicks& time, | 27 const base::TimeTicks& time, |
| 28 const Source& source, | 28 const Source& source, |
| 29 EventPhase phase, | 29 EventPhase phase, |
| 30 EventParameters* extra_parameters) { | 30 EventParameters* extra_parameters) { |
| 31 AutoLock lock(lock_); |
| 31 Entry entry(type, time, source, phase, extra_parameters); | 32 Entry entry(type, time, source, phase, extra_parameters); |
| 32 if (entries_.size() + 1 < max_num_entries_) | 33 if (entries_.size() + 1 < max_num_entries_) |
| 33 entries_.push_back(entry); | 34 entries_.push_back(entry); |
| 34 } | 35 } |
| 35 | 36 |
| 36 uint32 CapturingNetLog::NextID() { | 37 uint32 CapturingNetLog::NextID() { |
| 37 return next_id_++; | 38 return base::subtle::NoBarrier_AtomicIncrement(&last_id_, 1); |
| 39 } |
| 40 |
| 41 void CapturingNetLog::GetEntries(EntryList* entry_list) const { |
| 42 AutoLock lock(lock_); |
| 43 *entry_list = entries_; |
| 38 } | 44 } |
| 39 | 45 |
| 40 void CapturingNetLog::Clear() { | 46 void CapturingNetLog::Clear() { |
| 47 AutoLock lock(lock_); |
| 41 entries_.clear(); | 48 entries_.clear(); |
| 42 } | 49 } |
| 43 | 50 |
| 44 CapturingBoundNetLog::CapturingBoundNetLog(const NetLog::Source& source, | 51 CapturingBoundNetLog::CapturingBoundNetLog(const NetLog::Source& source, |
| 45 CapturingNetLog* net_log) | 52 CapturingNetLog* net_log) |
| 46 : source_(source), capturing_net_log_(net_log) { | 53 : source_(source), capturing_net_log_(net_log) { |
| 47 } | 54 } |
| 48 | 55 |
| 49 CapturingBoundNetLog::CapturingBoundNetLog(size_t max_num_entries) | 56 CapturingBoundNetLog::CapturingBoundNetLog(size_t max_num_entries) |
| 50 : capturing_net_log_(new CapturingNetLog(max_num_entries)) {} | 57 : capturing_net_log_(new CapturingNetLog(max_num_entries)) {} |
| 51 | 58 |
| 52 CapturingBoundNetLog::~CapturingBoundNetLog() {} | 59 CapturingBoundNetLog::~CapturingBoundNetLog() {} |
| 53 | 60 |
| 61 void CapturingBoundNetLog::GetEntries( |
| 62 CapturingNetLog::EntryList* entry_list) const { |
| 63 capturing_net_log_->GetEntries(entry_list); |
| 64 } |
| 65 |
| 54 void CapturingBoundNetLog::Clear() { | 66 void CapturingBoundNetLog::Clear() { |
| 55 capturing_net_log_->Clear(); | 67 capturing_net_log_->Clear(); |
| 56 } | 68 } |
| 57 | 69 |
| 58 void CapturingBoundNetLog::AppendTo(const BoundNetLog& net_log) const { | |
| 59 for (size_t i = 0; i < entries().size(); ++i) { | |
| 60 const CapturingNetLog::Entry& entry = entries()[i]; | |
| 61 net_log.AddEntryWithTime(entry.type, entry.time, entry.phase, | |
| 62 entry.extra_parameters); | |
| 63 } | |
| 64 } | |
| 65 | |
| 66 } // namespace net | 70 } // namespace net |
| OLD | NEW |