Index: net/base/upload_data_stream.cc |
diff --git a/net/base/upload_data_stream.cc b/net/base/upload_data_stream.cc |
index 37e19aed313d210d622ab495643191020a0a63eb..67c370a5cddefe530e829b97407b069c9c6fe6b9 100644 |
--- a/net/base/upload_data_stream.cc |
+++ b/net/base/upload_data_stream.cc |
@@ -6,11 +6,76 @@ |
#include "base/callback_helpers.h" |
#include "base/logging.h" |
+#include "base/values.h" |
#include "net/base/io_buffer.h" |
#include "net/base/net_errors.h" |
namespace net { |
+namespace { |
+ |
+std::unique_ptr<base::Value> NetLogInitEndInfoCallback( |
+ int result, |
+ int total_size, |
+ bool is_chunked, |
+ NetLogCaptureMode /* capture_mode */) { |
+ std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
+ |
+ dict->SetInteger("result", result); |
+ dict->SetInteger("total_size", total_size); |
+ dict->SetBoolean("is_chunked", is_chunked); |
+ return std::move(dict); |
+} |
+ |
+std::unique_ptr<base::Value> NetLogReadInfoCallback( |
+ int current_position, |
+ NetLogCaptureMode /* capture_mode */) { |
+ std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
+ |
+ dict->SetInteger("current_position", current_position); |
+ return std::move(dict); |
+} |
+ |
+std::unique_ptr<base::Value> NetLogReadEndInfoCallback( |
+ int result, |
+ NetLogCaptureMode /* capture_mode */) { |
+ std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
+ |
+ dict->SetInteger("result", result); |
+ return std::move(dict); |
+} |
+ |
+// Logs when an initialization has been completed. |
+void LogInitEnd(const BoundNetLog& net_log, |
mmenke
2016/08/16 15:40:06
I don't think these methods really get us anything
maksims (do not use this acc)
2016/08/16 18:45:37
Done.
|
+ int result, |
+ int total_size_, |
+ bool is_chunked) { |
+ net_log.EndEvent( |
+ NetLog::TYPE_UPLOAD_DATA_STREAM_INIT, |
+ base::Bind(&NetLogInitEndInfoCallback, result, total_size_, is_chunked)); |
+} |
+ |
+// Logs when read has been started. |
+void LogRead(const BoundNetLog& net_log, int current_position) { |
+ net_log.BeginEvent(NetLog::TYPE_UPLOAD_DATA_STREAM_READ, |
+ base::Bind(&NetLogReadInfoCallback, current_position)); |
+} |
+ |
+// Logs when read has been completed (before its callback is run). |
+void LogReadEnd(const BoundNetLog& net_log, int result) { |
+ net_log.EndEvent(NetLog::TYPE_UPLOAD_DATA_STREAM_READ, |
+ base::Bind(&NetLogReadEndInfoCallback, result)); |
+} |
+ |
+// Logs when a read request has been cancelled. |
+void LogCancelRead(const BoundNetLog& net_log) { |
+ net_log.AddEventWithNetErrorCode(NetLog::TYPE_UPLOAD_DATA_STREAM_READ, |
+ NetLog::TYPE_CANCELLED); |
mmenke
2016/08/16 15:40:06
TYPE_CANCELLED isn't a network error code, it's a
maksims (do not use this acc)
2016/08/16 18:45:37
Done.
|
+ net_log.EndEvent(NetLog::TYPE_UPLOAD_DATA_STREAM_READ); |
+} |
+ |
+} // namespace |
+ |
UploadDataStream::UploadDataStream(bool is_chunked, int64_t identifier) |
: total_size_(0), |
current_position_(0), |
@@ -23,18 +88,23 @@ UploadDataStream::UploadDataStream(bool is_chunked, int64_t identifier) |
UploadDataStream::~UploadDataStream() { |
} |
-int UploadDataStream::Init(const CompletionCallback& callback) { |
+int UploadDataStream::Init(const CompletionCallback& callback, |
+ const BoundNetLog& net_log) { |
Reset(); |
DCHECK(!initialized_successfully_); |
DCHECK(callback_.is_null()); |
DCHECK(!callback.is_null() || IsInMemory()); |
- int result = InitInternal(); |
+ net_log_ = net_log; |
+ net_log_.BeginEvent(NetLog::TYPE_UPLOAD_DATA_STREAM_READ); |
mmenke
2016/08/16 15:40:06
TYPE_UPLOAD_DATA_STREAM_INIT
maksims (do not use this acc)
2016/08/16 18:45:37
oops.
|
+ |
+ int result = InitInternal(net_log_); |
if (result == ERR_IO_PENDING) { |
DCHECK(!IsInMemory()); |
callback_ = callback; |
} else { |
OnInitCompleted(result); |
} |
+ |
return result; |
} |
@@ -44,15 +114,20 @@ int UploadDataStream::Read(IOBuffer* buf, |
DCHECK(!callback.is_null() || IsInMemory()); |
DCHECK(initialized_successfully_); |
DCHECK_GT(buf_len, 0); |
- if (is_eof_) |
- return 0; |
- int result = ReadInternal(buf, buf_len); |
+ |
+ LogRead(net_log_, current_position_); |
+ |
+ int result = 0; |
+ if (!is_eof_) |
+ result = ReadInternal(buf, buf_len); |
+ |
if (result == ERR_IO_PENDING) { |
DCHECK(!IsInMemory()); |
callback_ = callback; |
} else { |
OnReadCompleted(result); |
} |
+ |
return result; |
} |
@@ -63,6 +138,9 @@ bool UploadDataStream::IsEOF() const { |
} |
void UploadDataStream::Reset() { |
+ if (!callback_.is_null()) |
+ LogCancelRead(net_log_); |
mmenke
2016/08/16 15:40:06
We may actually be completing initialization. Can
maksims (do not use this acc)
2016/08/16 18:45:37
I though a bit different way. If callback is set,
|
+ |
current_position_ = 0; |
initialized_successfully_ = false; |
is_eof_ = false; |
@@ -104,6 +182,9 @@ void UploadDataStream::OnInitCompleted(int result) { |
if (!is_chunked_ && total_size_ == 0) |
is_eof_ = true; |
} |
+ |
+ LogInitEnd(net_log_, result, total_size_, is_chunked_); |
+ |
if (!callback_.is_null()) |
base::ResetAndReturn(&callback_).Run(result); |
} |
@@ -122,6 +203,8 @@ void UploadDataStream::OnReadCompleted(int result) { |
} |
} |
+ LogReadEnd(net_log_, result); |
+ |
if (!callback_.is_null()) |
base::ResetAndReturn(&callback_).Run(result); |
} |