Index: net/base/net_log.cc |
=================================================================== |
--- net/base/net_log.cc (revision 87467) |
+++ net/base/net_log.cc (working copy) |
@@ -13,6 +13,42 @@ |
namespace net { |
+namespace { |
+ |
+// Parameters for logging data transferred events. Includes bytes transferred |
+// and, if |bytes| is not NULL, the bytes themselves. |
+class NetLogBytesTransferredParameter : public NetLog::EventParameters { |
+ public: |
+ NetLogBytesTransferredParameter(int byte_count, const char* bytes); |
+ |
+ virtual Value* ToValue() const; |
+ |
+ private: |
+ const int byte_count_; |
+ std::string hex_encoded_bytes_; |
+ bool has_bytes_; |
+}; |
+ |
+NetLogBytesTransferredParameter::NetLogBytesTransferredParameter( |
+ int byte_count, const char* transferred_bytes) |
+ : byte_count_(byte_count), |
+ has_bytes_(false) { |
+ if (transferred_bytes) { |
+ hex_encoded_bytes_ = base::HexEncode(transferred_bytes, byte_count); |
+ has_bytes_ = true; |
+ } |
+} |
+ |
+Value* NetLogBytesTransferredParameter::ToValue() const { |
+ DictionaryValue* dict = new DictionaryValue(); |
+ dict->SetInteger("byte_count", byte_count_); |
+ if (has_bytes_ && byte_count_ > 0) |
+ dict->SetString("hex_encoded_bytes", hex_encoded_bytes_); |
+ return dict; |
+} |
+ |
+} // namespace |
+ |
Value* NetLog::Source::ToValue() const { |
DictionaryValue* dict = new DictionaryValue(); |
dict->SetInteger("type", static_cast<int>(type)); |
@@ -157,6 +193,17 @@ |
} |
} |
+void BoundNetLog::AddByteTransferEvent(NetLog::EventType event_type, |
+ int byte_count, char* bytes) const { |
+ scoped_refptr<NetLog::EventParameters> params; |
+ if (IsLoggingBytes()) { |
+ params = new NetLogBytesTransferredParameter(byte_count, bytes); |
+ } else { |
+ params = new NetLogBytesTransferredParameter(byte_count, NULL); |
+ } |
+ AddEvent(event_type, params); |
+} |
+ |
NetLog::LogLevel BoundNetLog::GetLogLevel() const { |
if (net_log_) |
return net_log_->GetLogLevel(); |