| 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..feb0fa037b8c9ac94da1ae99a985ccd49dec7784 100644
|
| --- a/net/base/upload_data_stream.cc
|
| +++ b/net/base/upload_data_stream.cc
|
| @@ -6,11 +6,38 @@
|
|
|
| #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("net_error", 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);
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| UploadDataStream::UploadDataStream(bool is_chunked, int64_t identifier)
|
| : total_size_(0),
|
| current_position_(0),
|
| @@ -23,18 +50,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 +76,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 +101,21 @@ bool UploadDataStream::IsEOF() const {
|
| }
|
|
|
| void UploadDataStream::Reset() {
|
| + // If there's a pending callback, there's a pending init or read call that is
|
| + // being canceled.
|
| + if (!callback_.is_null()) {
|
| + if (!initialized_successfully_) {
|
| + // If initialization has not yet succeeded, this call is aborting
|
| + // initialization.
|
| + net_log_.EndEventWithNetErrorCode(NetLog::TYPE_UPLOAD_DATA_STREAM_INIT,
|
| + ERR_ABORTED);
|
| + } else {
|
| + // Otherwise, a read is being aborted.
|
| + net_log_.EndEventWithNetErrorCode(NetLog::TYPE_UPLOAD_DATA_STREAM_READ,
|
| + ERR_ABORTED);
|
| + }
|
| + }
|
| +
|
| current_position_ = 0;
|
| initialized_successfully_ = false;
|
| is_eof_ = false;
|
| @@ -104,6 +157,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 +180,9 @@ void UploadDataStream::OnReadCompleted(int result) {
|
| }
|
| }
|
|
|
| + net_log_.EndEventWithNetErrorCode(NetLog::TYPE_UPLOAD_DATA_STREAM_READ,
|
| + result);
|
| +
|
| if (!callback_.is_null())
|
| base::ResetAndReturn(&callback_).Run(result);
|
| }
|
|
|