Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: net/base/net_log.cc

Issue 848006: Generalize the net module's LoadLog facility from a passive container, to an event stream (NetLog). (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Split up RequestTracker into ConnectJobTracker+RequestTracker+RequestTrackerBase, address comments Created 10 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/base/net_log.h ('k') | net/base/net_log_event_type_list.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 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/load_log.h" 5 #include "net/base/net_log.h"
6 #include "base/logging.h" 6 #include "base/logging.h"
7 7
8 namespace net { 8 namespace net {
9 9
10 LoadLog::LoadLog(size_t max_num_entries)
11 : num_entries_truncated_(0), max_num_entries_(max_num_entries) {
12 DCHECK_GT(max_num_entries, 0u);
13 }
14
15 // static 10 // static
16 const char* LoadLog::EventTypeToString(EventType event) { 11 const char* NetLog::EventTypeToString(EventType event) {
17 switch (event) { 12 switch (event) {
18 #define EVENT_TYPE(label) case TYPE_ ## label: return #label; 13 #define EVENT_TYPE(label) case TYPE_ ## label: return #label;
19 #include "net/base/load_log_event_type_list.h" 14 #include "net/base/net_log_event_type_list.h"
20 #undef EVENT_TYPE 15 #undef EVENT_TYPE
21 } 16 }
22 return NULL; 17 return NULL;
23 } 18 }
24 19
25 void LoadLog::Add(const Entry& entry) { 20 void BoundNetLog::AddEntry(const NetLog::Entry& entry) const {
26 // Minor optimization. TODO(eroman): use StackVector instead. 21 if (net_log_)
27 if (entries_.empty()) 22 net_log_->AddEntry(entry);
28 entries_.reserve(10); // It is likely we will have at least 10 entries. 23 }
29 24
30 // Enforce a bound of |max_num_entries_| -- once we reach it, keep overwriting 25 bool BoundNetLog::HasListener() const {
31 // the final entry in the log. 26 if (net_log_)
27 return net_log_->HasListener();
28 return false;
29 }
32 30
33 if (entries_.size() + 1 <= max_num_entries_ || 31 void BoundNetLog::AddEvent(NetLog::EventType event_type) const {
34 max_num_entries_ == kUnbounded) { 32 if (net_log_) {
35 entries_.push_back(entry); 33 NetLog::Entry entry;
36 } else { 34 entry.source = source_;
37 num_entries_truncated_ += 1; 35 entry.type = NetLog::Entry::TYPE_EVENT;
38 entries_[max_num_entries_ - 1] = entry; 36 entry.time = base::TimeTicks::Now();
37 entry.event = NetLog::Event(event_type, NetLog::PHASE_NONE);
38 AddEntry(entry);
39 } 39 }
40 } 40 }
41 41
42 void LoadLog::Append(const LoadLog* log) { 42 void BoundNetLog::BeginEvent(NetLog::EventType event_type) const {
43 for (size_t i = 0; i < log->entries().size(); ++i) 43 if (net_log_) {
44 Add(log->entries()[i]); 44 NetLog::Entry entry;
45 num_entries_truncated_ += log->num_entries_truncated(); 45 entry.source = source_;
46 entry.type = NetLog::Entry::TYPE_EVENT;
47 entry.time = base::TimeTicks::Now();
48 entry.event = NetLog::Event(event_type, NetLog::PHASE_BEGIN);
49 AddEntry(entry);
50 }
51 }
52
53 void BoundNetLog::BeginEventWithString(NetLog::EventType event_type,
54 const std::string& string) const {
55 NetLog::Entry entry;
56 entry.source = source_;
57 entry.type = NetLog::Entry::TYPE_EVENT;
58 entry.time = base::TimeTicks::Now();
59 entry.event = NetLog::Event(event_type, NetLog::PHASE_BEGIN);
60 entry.string = string;
61 AddEntry(entry);
62 }
63
64 void BoundNetLog::AddEventWithInteger(NetLog::EventType event_type,
65 int integer) const {
66 NetLog::Entry entry;
67 entry.source = source_;
68 entry.type = NetLog::Entry::TYPE_EVENT;
69 entry.time = base::TimeTicks::Now();
70 entry.event = NetLog::Event(event_type, NetLog::PHASE_NONE);
71 entry.error_code = integer;
72 AddEntry(entry);
73 }
74
75 void BoundNetLog::EndEvent(NetLog::EventType event_type) const {
76 if (net_log_) {
77 NetLog::Entry entry;
78 entry.source = source_;
79 entry.type = NetLog::Entry::TYPE_EVENT;
80 entry.time = base::TimeTicks::Now();
81 entry.event = NetLog::Event(event_type, NetLog::PHASE_END);
82 AddEntry(entry);
83 }
84 }
85
86 void BoundNetLog::AddStringLiteral(const char* literal) const {
87 if (net_log_) {
88 NetLog::Entry entry;
89 entry.source = source_;
90 entry.type = NetLog::Entry::TYPE_STRING_LITERAL;
91 entry.time = base::TimeTicks::Now();
92 entry.literal = literal;
93 AddEntry(entry);
94 }
95 }
96
97 void BoundNetLog::AddString(const std::string& string) const {
98 if (net_log_) {
99 NetLog::Entry entry;
100 entry.source = source_;
101 entry.type = NetLog::Entry::TYPE_STRING;
102 entry.time = base::TimeTicks::Now();
103 entry.string = string;
104 AddEntry(entry);
105 }
106 }
107
108 void BoundNetLog::AddErrorCode(int error) const {
109 if (net_log_) {
110 NetLog::Entry entry;
111 entry.source = source_;
112 entry.type = NetLog::Entry::TYPE_ERROR_CODE;
113 entry.time = base::TimeTicks::Now();
114 entry.error_code = error;
115 AddEntry(entry);
116 }
117 }
118
119 // static
120 BoundNetLog BoundNetLog::Make(NetLog* net_log,
121 NetLog::SourceType source_type) {
122 if (!net_log)
123 return BoundNetLog();
124
125 NetLog::Source source(source_type, net_log->NextID());
126 return BoundNetLog(source, net_log);
127 }
128
129 void CapturingNetLog::AddEntry(const Entry& entry) {
130 if (entries_.size() + 1 < max_num_entries_)
131 entries_.push_back(entry);
132 }
133
134 int CapturingNetLog::NextID() {
135 return next_id_++;
136 }
137
138 void CapturingNetLog::Clear() {
139 entries_.clear();
140 }
141
142 void CapturingBoundNetLog::Clear() {
143 capturing_net_log_->Clear();
144 }
145
146 void CapturingBoundNetLog::AppendTo(const BoundNetLog& net_log) const {
147 for (size_t i = 0; i < entries().size(); ++i) {
148 NetLog::Entry entry = entries()[i];
149 entry.source = net_log.source();
150 net_log.AddEntry(entry);
151 }
46 } 152 }
47 153
48 } // namespace net 154 } // namespace net
OLDNEW
« no previous file with comments | « net/base/net_log.h ('k') | net/base/net_log_event_type_list.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698