| 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" | 6 #include "base/logging.h" |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "base/values.h" |
| 8 | 9 |
| 9 namespace net { | 10 namespace net { |
| 10 | 11 |
| 11 // static | 12 // static |
| 12 const char* NetLog::EventTypeToString(EventType event) { | 13 const char* NetLog::EventTypeToString(EventType event) { |
| 13 switch (event) { | 14 switch (event) { |
| 14 #define EVENT_TYPE(label) case TYPE_ ## label: return #label; | 15 #define EVENT_TYPE(label) case TYPE_ ## label: return #label; |
| 15 #include "net/base/net_log_event_type_list.h" | 16 #include "net/base/net_log_event_type_list.h" |
| 16 #undef EVENT_TYPE | 17 #undef EVENT_TYPE |
| 17 } | 18 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 AddEventWithParameters(event_type, NULL); | 57 AddEventWithParameters(event_type, NULL); |
| 57 } | 58 } |
| 58 | 59 |
| 59 void BoundNetLog::AddEventWithParameters( | 60 void BoundNetLog::AddEventWithParameters( |
| 60 NetLog::EventType event_type, | 61 NetLog::EventType event_type, |
| 61 NetLog::EventParameters* params) const { | 62 NetLog::EventParameters* params) const { |
| 62 AddEntry(event_type, NetLog::PHASE_NONE, params); | 63 AddEntry(event_type, NetLog::PHASE_NONE, params); |
| 63 } | 64 } |
| 64 | 65 |
| 65 void BoundNetLog::AddEventWithInteger(NetLog::EventType event_type, | 66 void BoundNetLog::AddEventWithInteger(NetLog::EventType event_type, |
| 66 int integer) const { | 67 const char* name, |
| 68 int value) const { |
| 67 scoped_refptr<NetLog::EventParameters> params = | 69 scoped_refptr<NetLog::EventParameters> params = |
| 68 new NetLogIntegerParameter(integer); | 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); |
| 69 AddEventWithParameters(event_type, params); | 79 AddEventWithParameters(event_type, params); |
| 70 } | 80 } |
| 71 | 81 |
| 72 void BoundNetLog::BeginEvent(NetLog::EventType event_type) const { | 82 void BoundNetLog::BeginEvent(NetLog::EventType event_type) const { |
| 73 BeginEventWithParameters(event_type, NULL); | 83 BeginEventWithParameters(event_type, NULL); |
| 74 } | 84 } |
| 75 | 85 |
| 76 void BoundNetLog::BeginEventWithParameters( | 86 void BoundNetLog::BeginEventWithParameters( |
| 77 NetLog::EventType event_type, | 87 NetLog::EventType event_type, |
| 78 NetLog::EventParameters* params) const { | 88 NetLog::EventParameters* params) const { |
| 79 AddEntry(event_type, NetLog::PHASE_BEGIN, params); | 89 AddEntry(event_type, NetLog::PHASE_BEGIN, params); |
| 80 } | 90 } |
| 81 | 91 |
| 82 void BoundNetLog::BeginEventWithString(NetLog::EventType event_type, | 92 void BoundNetLog::BeginEventWithString(NetLog::EventType event_type, |
| 83 const std::string& string) const { | 93 const char* name, |
| 94 const std::string& value) const { |
| 84 scoped_refptr<NetLog::EventParameters> params = | 95 scoped_refptr<NetLog::EventParameters> params = |
| 85 new NetLogStringParameter(string); | 96 new NetLogStringParameter(name, value); |
| 86 BeginEventWithParameters(event_type, params); | 97 BeginEventWithParameters(event_type, params); |
| 87 } | 98 } |
| 88 | 99 |
| 89 void BoundNetLog::BeginEventWithInteger(NetLog::EventType event_type, | 100 void BoundNetLog::BeginEventWithInteger(NetLog::EventType event_type, |
| 90 int integer) const { | 101 const char* name, |
| 102 int value) const { |
| 91 scoped_refptr<NetLog::EventParameters> params = | 103 scoped_refptr<NetLog::EventParameters> params = |
| 92 new NetLogIntegerParameter(integer); | 104 new NetLogIntegerParameter(name, value); |
| 93 BeginEventWithParameters(event_type, params); | 105 BeginEventWithParameters(event_type, params); |
| 94 } | 106 } |
| 95 | 107 |
| 96 void BoundNetLog::EndEvent(NetLog::EventType event_type) const { | 108 void BoundNetLog::EndEvent(NetLog::EventType event_type) const { |
| 97 EndEventWithParameters(event_type, NULL); | 109 EndEventWithParameters(event_type, NULL); |
| 98 } | 110 } |
| 99 | 111 |
| 100 void BoundNetLog::EndEventWithParameters( | 112 void BoundNetLog::EndEventWithParameters( |
| 101 NetLog::EventType event_type, | 113 NetLog::EventType event_type, |
| 102 NetLog::EventParameters* params) const { | 114 NetLog::EventParameters* params) const { |
| 103 AddEntry(event_type, NetLog::PHASE_END, params); | 115 AddEntry(event_type, NetLog::PHASE_END, params); |
| 104 } | 116 } |
| 105 | 117 |
| 106 void BoundNetLog::EndEventWithInteger(NetLog::EventType event_type, | 118 void BoundNetLog::EndEventWithInteger(NetLog::EventType event_type, |
| 107 int integer) const { | 119 const char* name, |
| 120 int value) const { |
| 108 scoped_refptr<NetLog::EventParameters> params = | 121 scoped_refptr<NetLog::EventParameters> params = |
| 109 new NetLogIntegerParameter(integer); | 122 new NetLogIntegerParameter(name, value); |
| 110 EndEventWithParameters(event_type, params); | 123 EndEventWithParameters(event_type, params); |
| 111 } | 124 } |
| 112 | 125 |
| 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 | 126 // static |
| 132 BoundNetLog BoundNetLog::Make(NetLog* net_log, | 127 BoundNetLog BoundNetLog::Make(NetLog* net_log, |
| 133 NetLog::SourceType source_type) { | 128 NetLog::SourceType source_type) { |
| 134 if (!net_log) | 129 if (!net_log) |
| 135 return BoundNetLog(); | 130 return BoundNetLog(); |
| 136 | 131 |
| 137 NetLog::Source source(source_type, net_log->NextID()); | 132 NetLog::Source source(source_type, net_log->NextID()); |
| 138 return BoundNetLog(source, net_log); | 133 return BoundNetLog(source, net_log); |
| 139 } | 134 } |
| 140 | 135 |
| 141 NetLogStringParameter::NetLogStringParameter(const std::string& value) | 136 NetLogStringParameter::NetLogStringParameter(const char* name, |
| 142 : value_(value) { | 137 const std::string& value) |
| 138 : name_(name), value_(value) { |
| 143 } | 139 } |
| 144 | 140 |
| 145 std::string NetLogIntegerParameter::ToString() const { | 141 Value* NetLogIntegerParameter::ToValue() const { |
| 146 return IntToString(value_); | 142 DictionaryValue* dict = new DictionaryValue(); |
| 143 dict->SetInteger(ASCIIToWide(name_), value_); |
| 144 return dict; |
| 147 } | 145 } |
| 148 | 146 |
| 149 std::string NetLogStringLiteralParameter::ToString() const { | 147 Value* NetLogStringParameter::ToValue() const { |
| 150 return std::string(value_); | 148 DictionaryValue* dict = new DictionaryValue(); |
| 149 dict->SetString(ASCIIToWide(name_), value_); |
| 150 return dict; |
| 151 } | 151 } |
| 152 | 152 |
| 153 void CapturingNetLog::AddEntry(EventType type, | 153 void CapturingNetLog::AddEntry(EventType type, |
| 154 const base::TimeTicks& time, | 154 const base::TimeTicks& time, |
| 155 const Source& source, | 155 const Source& source, |
| 156 EventPhase phase, | 156 EventPhase phase, |
| 157 EventParameters* extra_parameters) { | 157 EventParameters* extra_parameters) { |
| 158 Entry entry(type, time, source, phase, extra_parameters); | 158 Entry entry(type, time, source, phase, extra_parameters); |
| 159 if (entries_.size() + 1 < max_num_entries_) | 159 if (entries_.size() + 1 < max_num_entries_) |
| 160 entries_.push_back(entry); | 160 entries_.push_back(entry); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 174 | 174 |
| 175 void CapturingBoundNetLog::AppendTo(const BoundNetLog& net_log) const { | 175 void CapturingBoundNetLog::AppendTo(const BoundNetLog& net_log) const { |
| 176 for (size_t i = 0; i < entries().size(); ++i) { | 176 for (size_t i = 0; i < entries().size(); ++i) { |
| 177 const CapturingNetLog::Entry& entry = entries()[i]; | 177 const CapturingNetLog::Entry& entry = entries()[i]; |
| 178 net_log.AddEntryWithTime(entry.type, entry.time, entry.phase, | 178 net_log.AddEntryWithTime(entry.type, entry.time, entry.phase, |
| 179 entry.extra_parameters); | 179 entry.extra_parameters); |
| 180 } | 180 } |
| 181 } | 181 } |
| 182 | 182 |
| 183 } // namespace net | 183 } // namespace net |
| OLD | NEW |