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/net_log.h" | 5 #include "net/base/capturing_net_log.h" |
6 #include "base/logging.h" | |
7 #include "base/string_util.h" | |
8 | 6 |
9 namespace net { | 7 namespace net { |
10 | 8 |
11 // static | 9 CapturingNetLog::CapturingNetLog(size_t max_num_entries) |
12 const char* NetLog::EventTypeToString(EventType event) { | 10 : next_id_(0), max_num_entries_(max_num_entries) { |
13 switch (event) { | |
14 #define EVENT_TYPE(label) case TYPE_ ## label: return #label; | |
15 #include "net/base/net_log_event_type_list.h" | |
16 #undef EVENT_TYPE | |
17 } | |
18 return NULL; | |
19 } | |
20 | |
21 // static | |
22 std::vector<NetLog::EventType> NetLog::GetAllEventTypes() { | |
23 std::vector<NetLog::EventType> types; | |
24 #define EVENT_TYPE(label) types.push_back(TYPE_ ## label); | |
25 #include "net/base/net_log_event_type_list.h" | |
26 #undef EVENT_TYPE | |
27 return types; | |
28 } | |
29 | |
30 void BoundNetLog::AddEntry(NetLog::EventType type, | |
31 NetLog::EventPhase phase, | |
32 NetLog::EventParameters* extra_parameters) const { | |
33 if (net_log_) { | |
34 net_log_->AddEntry(type, base::TimeTicks::Now(), source_, phase, | |
35 extra_parameters); | |
36 } | |
37 } | |
38 | |
39 void BoundNetLog::AddEntryWithTime( | |
40 NetLog::EventType type, | |
41 const base::TimeTicks& time, | |
42 NetLog::EventPhase phase, | |
43 NetLog::EventParameters* extra_parameters) const { | |
44 if (net_log_) { | |
45 net_log_->AddEntry(type, time, source_, phase, extra_parameters); | |
46 } | |
47 } | |
48 | |
49 bool BoundNetLog::HasListener() const { | |
50 if (net_log_) | |
51 return net_log_->HasListener(); | |
52 return false; | |
53 } | |
54 | |
55 void BoundNetLog::AddEvent(NetLog::EventType event_type) const { | |
56 AddEventWithParameters(event_type, NULL); | |
57 } | |
58 | |
59 void BoundNetLog::AddEventWithParameters( | |
60 NetLog::EventType event_type, | |
61 NetLog::EventParameters* params) const { | |
62 AddEntry(event_type, NetLog::PHASE_NONE, params); | |
63 } | |
64 | |
65 void BoundNetLog::AddEventWithInteger(NetLog::EventType event_type, | |
66 int integer) const { | |
67 scoped_refptr<NetLog::EventParameters> params = | |
68 new NetLogIntegerParameter(integer); | |
69 AddEventWithParameters(event_type, params); | |
70 } | |
71 | |
72 void BoundNetLog::BeginEvent(NetLog::EventType event_type) const { | |
73 BeginEventWithParameters(event_type, NULL); | |
74 } | |
75 | |
76 void BoundNetLog::BeginEventWithParameters( | |
77 NetLog::EventType event_type, | |
78 NetLog::EventParameters* params) const { | |
79 AddEntry(event_type, NetLog::PHASE_BEGIN, params); | |
80 } | |
81 | |
82 void BoundNetLog::BeginEventWithString(NetLog::EventType event_type, | |
83 const std::string& string) const { | |
84 scoped_refptr<NetLog::EventParameters> params = | |
85 new NetLogStringParameter(string); | |
86 BeginEventWithParameters(event_type, params); | |
87 } | |
88 | |
89 void BoundNetLog::BeginEventWithInteger(NetLog::EventType event_type, | |
90 int integer) const { | |
91 scoped_refptr<NetLog::EventParameters> params = | |
92 new NetLogIntegerParameter(integer); | |
93 BeginEventWithParameters(event_type, params); | |
94 } | |
95 | |
96 void BoundNetLog::EndEvent(NetLog::EventType event_type) const { | |
97 EndEventWithParameters(event_type, NULL); | |
98 } | |
99 | |
100 void BoundNetLog::EndEventWithParameters( | |
101 NetLog::EventType event_type, | |
102 NetLog::EventParameters* params) const { | |
103 AddEntry(event_type, NetLog::PHASE_END, params); | |
104 } | |
105 | |
106 void BoundNetLog::EndEventWithInteger(NetLog::EventType event_type, | |
107 int integer) const { | |
108 scoped_refptr<NetLog::EventParameters> params = | |
109 new NetLogIntegerParameter(integer); | |
110 EndEventWithParameters(event_type, params); | |
111 } | |
112 | |
113 void BoundNetLog::AddString(const std::string& string) const { | |
114 // We pass TYPE_TODO_STRING since we have no event type to associate this | |
115 // with. (AddString() is deprecated, and should be replaced with | |
116 // AddEventWithParameters()). | |
117 scoped_refptr<NetLog::EventParameters> params = | |
118 new NetLogStringParameter(string); | |
119 AddEventWithParameters(NetLog::TYPE_TODO_STRING, params); | |
120 } | |
121 | |
122 void BoundNetLog::AddStringLiteral(const char* literal) const { | |
123 // We pass TYPE_TODO_STRING_LITERAL since we have no event type to associate | |
124 // this with. (AddString() is deprecated, and should be replaced with | |
125 // AddEventWithParameters()). | |
126 scoped_refptr<NetLog::EventParameters> params = | |
127 new NetLogStringLiteralParameter(literal); | |
128 AddEventWithParameters(NetLog::TYPE_TODO_STRING_LITERAL, params); | |
129 } | |
130 | |
131 // static | |
132 BoundNetLog BoundNetLog::Make(NetLog* net_log, | |
133 NetLog::SourceType source_type) { | |
134 if (!net_log) | |
135 return BoundNetLog(); | |
136 | |
137 NetLog::Source source(source_type, net_log->NextID()); | |
138 return BoundNetLog(source, net_log); | |
139 } | |
140 | |
141 NetLogStringParameter::NetLogStringParameter(const std::string& value) | |
142 : value_(value) { | |
143 } | |
144 | |
145 std::string NetLogIntegerParameter::ToString() const { | |
146 return IntToString(value_); | |
147 } | |
148 | |
149 std::string NetLogStringLiteralParameter::ToString() const { | |
150 return std::string(value_); | |
151 } | 11 } |
152 | 12 |
153 void CapturingNetLog::AddEntry(EventType type, | 13 void CapturingNetLog::AddEntry(EventType type, |
154 const base::TimeTicks& time, | 14 const base::TimeTicks& time, |
155 const Source& source, | 15 const Source& source, |
156 EventPhase phase, | 16 EventPhase phase, |
157 EventParameters* extra_parameters) { | 17 EventParameters* extra_parameters) { |
158 Entry entry(type, time, source, phase, extra_parameters); | 18 Entry entry(type, time, source, phase, extra_parameters); |
159 if (entries_.size() + 1 < max_num_entries_) | 19 if (entries_.size() + 1 < max_num_entries_) |
160 entries_.push_back(entry); | 20 entries_.push_back(entry); |
(...skipping 13 matching lines...) Expand all Loading... |
174 | 34 |
175 void CapturingBoundNetLog::AppendTo(const BoundNetLog& net_log) const { | 35 void CapturingBoundNetLog::AppendTo(const BoundNetLog& net_log) const { |
176 for (size_t i = 0; i < entries().size(); ++i) { | 36 for (size_t i = 0; i < entries().size(); ++i) { |
177 const CapturingNetLog::Entry& entry = entries()[i]; | 37 const CapturingNetLog::Entry& entry = entries()[i]; |
178 net_log.AddEntryWithTime(entry.type, entry.time, entry.phase, | 38 net_log.AddEntryWithTime(entry.type, entry.time, entry.phase, |
179 entry.extra_parameters); | 39 entry.extra_parameters); |
180 } | 40 } |
181 } | 41 } |
182 | 42 |
183 } // namespace net | 43 } // namespace net |
OLD | NEW |