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

Unified Diff: ios/web/webui/url_data_manager_ios_backend.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 | « content/test/net/url_request_abort_on_end_job.cc ('k') | mojo/services/network/url_loader_impl_apptest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/web/webui/url_data_manager_ios_backend.cc
diff --git a/ios/web/webui/url_data_manager_ios_backend.cc b/ios/web/webui/url_data_manager_ios_backend.cc
index d5117c27f13c2f907c272aa2f06a31efa2c1ffe6..cc3e3e9af8886bfdab7f8a0ee3822425feeab4a3 100644
--- a/ios/web/webui/url_data_manager_ios_backend.cc
+++ b/ios/web/webui/url_data_manager_ios_backend.cc
@@ -96,7 +96,7 @@ class URLRequestChromeJob : public net::URLRequestJob {
// net::URLRequestJob implementation.
void Start() override;
void Kill() override;
- int ReadRawData(net::IOBuffer* buf, int buf_size) override;
+ bool ReadRawData(net::IOBuffer* buf, int buf_size, int* bytes_read) override;
bool GetMimeType(std::string* mime_type) const override;
int GetResponseCode() const override;
void GetResponseInfo(net::HttpResponseInfo* info) override;
@@ -142,7 +142,7 @@ class URLRequestChromeJob : public net::URLRequestJob {
// Do the actual copy from data_ (the data we're serving) into |buf|.
// Separate from ReadRawData so we can handle async I/O.
- int CompleteRead(net::IOBuffer* buf, int buf_size);
+ void CompleteRead(net::IOBuffer* buf, int buf_size, int* bytes_read);
// The actual data we're serving. NULL until it's been fetched.
scoped_refptr<base::RefCountedMemory> data_;
@@ -291,46 +291,58 @@ void URLRequestChromeJob::MimeTypeAvailable(const std::string& mime_type) {
void URLRequestChromeJob::DataAvailable(base::RefCountedMemory* bytes) {
TRACE_EVENT_ASYNC_END0("browser", "DataManager:Request", this);
if (bytes) {
+ // The request completed, and we have all the data.
+ // Clear any IO pending status.
+ SetStatus(net::URLRequestStatus());
+
data_ = bytes;
+ int bytes_read;
if (pending_buf_.get()) {
CHECK(pending_buf_->data());
- int rv = CompleteRead(pending_buf_.get(), pending_buf_size_);
+ CompleteRead(pending_buf_.get(), pending_buf_size_, &bytes_read);
pending_buf_ = NULL;
- ReadRawDataComplete(rv);
+ NotifyReadComplete(bytes_read);
}
} else {
- ReadRawDataComplete(net::ERR_FAILED);
+ // The request failed.
+ NotifyDone(
+ net::URLRequestStatus(net::URLRequestStatus::FAILED, net::ERR_FAILED));
}
}
-int URLRequestChromeJob::ReadRawData(net::IOBuffer* buf, int buf_size) {
+bool URLRequestChromeJob::ReadRawData(net::IOBuffer* buf,
+ int buf_size,
+ int* bytes_read) {
if (!data_.get()) {
+ SetStatus(net::URLRequestStatus(net::URLRequestStatus::IO_PENDING, 0));
DCHECK(!pending_buf_.get());
CHECK(buf->data());
pending_buf_ = buf;
pending_buf_size_ = buf_size;
- return net::ERR_IO_PENDING; // Tell the caller we're still waiting for
- // data.
+ return false; // Tell the caller we're still waiting for data.
}
// Otherwise, the data is available.
- return CompleteRead(buf, buf_size);
+ CompleteRead(buf, buf_size, bytes_read);
+ return true;
}
-int URLRequestChromeJob::CompleteRead(net::IOBuffer* buf, int buf_size) {
+void URLRequestChromeJob::CompleteRead(net::IOBuffer* buf,
+ int buf_size,
+ int* bytes_read) {
// http://crbug.com/373841
char url_buf[128];
base::strlcpy(url_buf, request_->url().spec().c_str(), arraysize(url_buf));
base::debug::Alias(url_buf);
- int remaining = data_->size() - data_offset_;
+ int remaining = static_cast<int>(data_->size()) - data_offset_;
if (buf_size > remaining)
buf_size = remaining;
if (buf_size > 0) {
memcpy(buf->data(), data_->front() + data_offset_, buf_size);
data_offset_ += buf_size;
}
- return buf_size;
+ *bytes_read = buf_size;
}
namespace {
« no previous file with comments | « content/test/net/url_request_abort_on_end_job.cc ('k') | mojo/services/network/url_loader_impl_apptest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698