Index: net/url_request/url_request_simple_job.cc |
diff --git a/net/url_request/url_request_simple_job.cc b/net/url_request/url_request_simple_job.cc |
index c12555d4b08c37bd8d910baefee364c78d172cd6..bc1507915fb7919a95f44bb9d83b1f37ca6b44f5 100644 |
--- a/net/url_request/url_request_simple_job.cc |
+++ b/net/url_request/url_request_simple_job.cc |
@@ -65,20 +65,33 @@ bool URLRequestSimpleJob::GetCharset(std::string* charset) { |
URLRequestSimpleJob::~URLRequestSimpleJob() {} |
-int URLRequestSimpleJob::ReadRawData(IOBuffer* buf, int buf_size) { |
- buf_size = std::min(static_cast<int64>(buf_size), |
- byte_range_.last_byte_position() - next_data_offset_ + 1); |
- if (buf_size == 0) |
- return 0; |
+bool URLRequestSimpleJob::ReadRawData(IOBuffer* buf, |
+ int buf_size, |
+ int* bytes_read) { |
+ DCHECK(bytes_read); |
+ buf_size = static_cast<int>( |
+ std::min(static_cast<int64>(buf_size), |
+ byte_range_.last_byte_position() - next_data_offset_ + 1)); |
+ DCHECK_GE(buf_size, 0); |
+ if (buf_size == 0) { |
+ *bytes_read = 0; |
+ return true; |
+ } |
// Do memory copy on a background thread. See crbug.com/422489. |
GetTaskRunner()->PostTaskAndReply( |
FROM_HERE, base::Bind(&CopyData, make_scoped_refptr(buf), buf_size, data_, |
next_data_offset_), |
- base::Bind(&URLRequestSimpleJob::ReadRawDataComplete, |
+ base::Bind(&URLRequestSimpleJob::OnReadCompleted, |
weak_factory_.GetWeakPtr(), buf_size)); |
next_data_offset_ += buf_size; |
- return ERR_IO_PENDING; |
+ SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); |
+ return false; |
+} |
+ |
+void URLRequestSimpleJob::OnReadCompleted(int bytes_read) { |
+ SetStatus(URLRequestStatus()); |
+ NotifyReadComplete(bytes_read); |
} |
base::TaskRunner* URLRequestSimpleJob::GetTaskRunner() const { |
@@ -109,8 +122,8 @@ void URLRequestSimpleJob::StartAsync() { |
return; |
if (ranges().size() > 1) { |
- NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, |
- ERR_REQUEST_RANGE_NOT_SATISFIABLE)); |
+ NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, |
+ ERR_REQUEST_RANGE_NOT_SATISFIABLE)); |
return; |
} |
@@ -130,8 +143,8 @@ void URLRequestSimpleJob::OnGetDataCompleted(int result) { |
if (result == OK) { |
// Notify that the headers are complete |
if (!byte_range_.ComputeBounds(data_->size())) { |
- NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, |
- ERR_REQUEST_RANGE_NOT_SATISFIABLE)); |
+ NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, |
+ ERR_REQUEST_RANGE_NOT_SATISFIABLE)); |
return; |
} |