Chromium Code Reviews| 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..b187044b65cc2026c2fd8e17faff926405ca9e9b 100644 |
| --- a/net/base/upload_data_stream.cc |
| +++ b/net/base/upload_data_stream.cc |
| @@ -6,11 +6,47 @@ |
| #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); |
|
mmenke
2016/08/16 19:40:09
Per below comment, call this net_error to get it f
maksims (do not use this acc)
2016/08/17 05:11:57
Done.
|
| + 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( |
|
mmenke
2016/08/16 18:54:13
Can actually get rid of this, and use "EndEventWit
maksims (do not use this acc)
2016/08/16 19:21:37
but wouldn't it mean that there will be no "result
mmenke
2016/08/16 19:40:09
EndEventWithNetErrorCode takes a network error cod
maksims (do not use this acc)
2016/08/17 05:11:57
Done.
|
| + int result, |
| + NetLogCaptureMode /* capture_mode */) { |
| + std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| + |
| + dict->SetInteger("result", result); |
| + return std::move(dict); |
| +} |
| + |
| +} // namespace |
| + |
| UploadDataStream::UploadDataStream(bool is_chunked, int64_t identifier) |
| : total_size_(0), |
| current_position_(0), |
| @@ -23,18 +59,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_INIT); |
| + |
| + int result = InitInternal(net_log_); |
| if (result == ERR_IO_PENDING) { |
| DCHECK(!IsInMemory()); |
| callback_ = callback; |
| } else { |
| OnInitCompleted(result); |
| } |
| + |
| return result; |
| } |
| @@ -44,15 +85,21 @@ 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); |
| + |
| + net_log_.BeginEvent(NetLog::TYPE_UPLOAD_DATA_STREAM_READ, |
| + base::Bind(&NetLogReadInfoCallback, 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 +110,11 @@ bool UploadDataStream::IsEOF() const { |
| } |
| void UploadDataStream::Reset() { |
| + if (initialized_successfully_) { |
| + net_log.EndEvent(NetLog::TYPE_UPLOAD_DATA_STREAM_READ, |
| + base::Bind(&NetLogReadEndInfoCallback, ERR_ABORTED)); |
|
mmenke
2016/08/16 18:54:13
Sorry, should have been clearer. My suggestion wa
maksims (do not use this acc)
2016/08/17 05:11:57
Oh, silly me. I've left your comments to make this
|
| + } |
| + |
| current_position_ = 0; |
| initialized_successfully_ = false; |
| is_eof_ = false; |
| @@ -104,6 +156,11 @@ void UploadDataStream::OnInitCompleted(int result) { |
| if (!is_chunked_ && total_size_ == 0) |
| is_eof_ = true; |
| } |
| + |
| + net_log_.EndEvent( |
| + NetLog::TYPE_UPLOAD_DATA_STREAM_INIT, |
| + base::Bind(&NetLogInitEndInfoCallback, result, total_size_, is_chunked_)); |
| + |
| if (!callback_.is_null()) |
| base::ResetAndReturn(&callback_).Run(result); |
| } |
| @@ -122,6 +179,9 @@ void UploadDataStream::OnReadCompleted(int result) { |
| } |
| } |
| + net_log_.EndEvent(NetLog::TYPE_UPLOAD_DATA_STREAM_READ, |
| + base::Bind(&NetLogReadEndInfoCallback, result)); |
| + |
| if (!callback_.is_null()) |
| base::ResetAndReturn(&callback_).Run(result); |
| } |