Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(837)

Unified Diff: net/url_request/url_request_simple_job.cc

Issue 1459333002: Revert "Reland: URLRequestJob: change ReadRawData contract" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/url_request/url_request_simple_job.h ('k') | net/url_request/url_request_status.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
}
« no previous file with comments | « net/url_request/url_request_simple_job.h ('k') | net/url_request/url_request_status.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698