Index: net/base/net_log.cc |
=================================================================== |
--- net/base/net_log.cc (revision 40318) |
+++ net/base/net_log.cc (working copy) |
@@ -1,48 +1,154 @@ |
-// Copyright (c) 2009 The Chromium Authors. All rights reserved. |
+// Copyright (c) 2010 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/load_log.h" |
+#include "net/base/net_log.h" |
#include "base/logging.h" |
namespace net { |
-LoadLog::LoadLog(size_t max_num_entries) |
- : num_entries_truncated_(0), max_num_entries_(max_num_entries) { |
- DCHECK_GT(max_num_entries, 0u); |
-} |
- |
// static |
-const char* LoadLog::EventTypeToString(EventType event) { |
+const char* NetLog::EventTypeToString(EventType event) { |
switch (event) { |
#define EVENT_TYPE(label) case TYPE_ ## label: return #label; |
-#include "net/base/load_log_event_type_list.h" |
+#include "net/base/net_log_event_type_list.h" |
#undef EVENT_TYPE |
} |
return NULL; |
} |
-void LoadLog::Add(const Entry& entry) { |
- // Minor optimization. TODO(eroman): use StackVector instead. |
- if (entries_.empty()) |
- entries_.reserve(10); // It is likely we will have at least 10 entries. |
+void BoundNetLog::AddEntry(const NetLog::Entry& entry) const { |
+ if (net_log_) |
+ net_log_->AddEntry(entry); |
+} |
- // Enforce a bound of |max_num_entries_| -- once we reach it, keep overwriting |
- // the final entry in the log. |
+bool BoundNetLog::HasListener() const { |
+ if (net_log_) |
+ return net_log_->HasListener(); |
+ return false; |
+} |
- if (entries_.size() + 1 <= max_num_entries_ || |
- max_num_entries_ == kUnbounded) { |
- entries_.push_back(entry); |
- } else { |
- num_entries_truncated_ += 1; |
- entries_[max_num_entries_ - 1] = entry; |
+void BoundNetLog::AddEvent(NetLog::EventType event_type) const { |
+ if (net_log_) { |
+ NetLog::Entry entry; |
+ entry.source = source_; |
+ entry.type = NetLog::Entry::TYPE_EVENT; |
+ entry.time = base::TimeTicks::Now(); |
+ entry.event = NetLog::Event(event_type, NetLog::PHASE_NONE); |
+ AddEntry(entry); |
} |
} |
-void LoadLog::Append(const LoadLog* log) { |
- for (size_t i = 0; i < log->entries().size(); ++i) |
- Add(log->entries()[i]); |
- num_entries_truncated_ += log->num_entries_truncated(); |
+void BoundNetLog::BeginEvent(NetLog::EventType event_type) const { |
+ if (net_log_) { |
+ NetLog::Entry entry; |
+ entry.source = source_; |
+ entry.type = NetLog::Entry::TYPE_EVENT; |
+ entry.time = base::TimeTicks::Now(); |
+ entry.event = NetLog::Event(event_type, NetLog::PHASE_BEGIN); |
+ AddEntry(entry); |
+ } |
} |
+void BoundNetLog::BeginEventWithString(NetLog::EventType event_type, |
+ const std::string& string) const { |
+ NetLog::Entry entry; |
+ entry.source = source_; |
+ entry.type = NetLog::Entry::TYPE_EVENT; |
+ entry.time = base::TimeTicks::Now(); |
+ entry.event = NetLog::Event(event_type, NetLog::PHASE_BEGIN); |
+ entry.string = string; |
+ AddEntry(entry); |
+} |
+ |
+void BoundNetLog::AddEventWithInteger(NetLog::EventType event_type, |
+ int integer) const { |
+ NetLog::Entry entry; |
+ entry.source = source_; |
+ entry.type = NetLog::Entry::TYPE_EVENT; |
+ entry.time = base::TimeTicks::Now(); |
+ entry.event = NetLog::Event(event_type, NetLog::PHASE_NONE); |
+ entry.error_code = integer; |
+ AddEntry(entry); |
+} |
+ |
+void BoundNetLog::EndEvent(NetLog::EventType event_type) const { |
+ if (net_log_) { |
+ NetLog::Entry entry; |
+ entry.source = source_; |
+ entry.type = NetLog::Entry::TYPE_EVENT; |
+ entry.time = base::TimeTicks::Now(); |
+ entry.event = NetLog::Event(event_type, NetLog::PHASE_END); |
+ AddEntry(entry); |
+ } |
+} |
+ |
+void BoundNetLog::AddStringLiteral(const char* literal) const { |
+ if (net_log_) { |
+ NetLog::Entry entry; |
+ entry.source = source_; |
+ entry.type = NetLog::Entry::TYPE_STRING_LITERAL; |
+ entry.time = base::TimeTicks::Now(); |
+ entry.literal = literal; |
+ AddEntry(entry); |
+ } |
+} |
+ |
+void BoundNetLog::AddString(const std::string& string) const { |
+ if (net_log_) { |
+ NetLog::Entry entry; |
+ entry.source = source_; |
+ entry.type = NetLog::Entry::TYPE_STRING; |
+ entry.time = base::TimeTicks::Now(); |
+ entry.string = string; |
+ AddEntry(entry); |
+ } |
+} |
+ |
+void BoundNetLog::AddErrorCode(int error) const { |
+ if (net_log_) { |
+ NetLog::Entry entry; |
+ entry.source = source_; |
+ entry.type = NetLog::Entry::TYPE_ERROR_CODE; |
+ entry.time = base::TimeTicks::Now(); |
+ entry.error_code = error; |
+ AddEntry(entry); |
+ } |
+} |
+ |
+// static |
+BoundNetLog BoundNetLog::Make(NetLog* net_log, |
+ NetLog::SourceType source_type) { |
+ if (!net_log) |
+ return BoundNetLog(); |
+ |
+ NetLog::Source source(source_type, net_log->NextID()); |
+ return BoundNetLog(source, net_log); |
+} |
+ |
+void CapturingNetLog::AddEntry(const Entry& entry) { |
+ if (entries_.size() + 1 < max_num_entries_) |
+ entries_.push_back(entry); |
+} |
+ |
+int CapturingNetLog::NextID() { |
+ return next_id_++; |
+} |
+ |
+void CapturingNetLog::Clear() { |
+ entries_.clear(); |
+} |
+ |
+void CapturingBoundNetLog::Clear() { |
+ capturing_net_log_->Clear(); |
+} |
+ |
+void CapturingBoundNetLog::AppendTo(const BoundNetLog& net_log) const { |
+ for (size_t i = 0; i < entries().size(); ++i) { |
+ NetLog::Entry entry = entries()[i]; |
+ entry.source = net_log.source(); |
+ net_log.AddEntry(entry); |
+ } |
+} |
+ |
} // namespace net |