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