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

Unified Diff: storage/browser/fileapi/file_system_url_request_job.cc

Issue 1467603002: URLRequestJob: change ReadRawData contract (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add done_reading_called_ to MockNetworkTransaction 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 | « storage/browser/fileapi/file_system_url_request_job.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: storage/browser/fileapi/file_system_url_request_job.cc
diff --git a/storage/browser/fileapi/file_system_url_request_job.cc b/storage/browser/fileapi/file_system_url_request_job.cc
index 8d58f6498c14bf7db96749789b768c11f12a14f4..8edcb3d001f59047823207cf7d5fb9bcf73adb94 100644
--- a/storage/browser/fileapi/file_system_url_request_job.cc
+++ b/storage/browser/fileapi/file_system_url_request_job.cc
@@ -62,6 +62,7 @@ FileSystemURLRequestJob::FileSystemURLRequestJob(
file_system_context_(file_system_context),
is_directory_(false),
remaining_bytes_(0),
+ range_parse_result_(net::OK),
weak_factory_(this) {}
FileSystemURLRequestJob::~FileSystemURLRequestJob() {}
@@ -79,39 +80,28 @@ void FileSystemURLRequestJob::Kill() {
weak_factory_.InvalidateWeakPtrs();
}
-bool FileSystemURLRequestJob::ReadRawData(net::IOBuffer* dest,
- int dest_size,
- int* bytes_read) {
+int FileSystemURLRequestJob::ReadRawData(net::IOBuffer* dest, int dest_size) {
DCHECK_NE(dest_size, 0);
- DCHECK(bytes_read);
DCHECK_GE(remaining_bytes_, 0);
if (reader_.get() == NULL)
- return false;
+ return net::ERR_FAILED;
if (remaining_bytes_ < dest_size)
- dest_size = static_cast<int>(remaining_bytes_);
+ dest_size = remaining_bytes_;
- if (!dest_size) {
- *bytes_read = 0;
- return true;
- }
+ if (!dest_size)
+ return 0;
const int rv = reader_->Read(dest, dest_size,
base::Bind(&FileSystemURLRequestJob::DidRead,
weak_factory_.GetWeakPtr()));
if (rv >= 0) {
- // Data is immediately available.
- *bytes_read = rv;
remaining_bytes_ -= rv;
DCHECK_GE(remaining_bytes_, 0);
- return true;
}
- if (rv == net::ERR_IO_PENDING)
- SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0));
- else
- NotifyFailed(rv);
- return false;
+
+ return rv;
}
bool FileSystemURLRequestJob::GetMimeType(std::string* mime_type) const {
@@ -126,8 +116,12 @@ bool FileSystemURLRequestJob::GetMimeType(std::string* mime_type) const {
void FileSystemURLRequestJob::SetExtraRequestHeaders(
const net::HttpRequestHeaders& headers) {
std::string range_header;
+ // Currently this job only cares about the Range header. Note that validation
+ // is deferred to DidGetMetaData(), because NotifyStartError is not legal to
+ // call since the job has not started.
if (headers.GetHeader(net::HttpRequestHeaders::kRange, &range_header)) {
std::vector<net::HttpByteRange> ranges;
+
if (net::HttpUtil::ParseRangeHeader(range_header, &ranges)) {
if (ranges.size() == 1) {
byte_range_ = ranges[0];
@@ -135,7 +129,7 @@ void FileSystemURLRequestJob::SetExtraRequestHeaders(
// We don't support multiple range requests in one single URL request.
// TODO(adamk): decide whether we want to support multiple range
// requests.
- NotifyFailed(net::ERR_REQUEST_RANGE_NOT_SATISFIABLE);
+ range_parse_result_ = net::ERR_REQUEST_RANGE_NOT_SATISFIABLE;
}
}
}
@@ -167,7 +161,7 @@ void FileSystemURLRequestJob::StartAsync() {
}
if (!file_system_context_->CanServeURLRequest(url_)) {
// In incognito mode the API is not usable and there should be no data.
- NotifyFailed(net::ERR_FILE_NOT_FOUND);
+ NotifyStartError(URLRequestStatus::FromError(net::ERR_FILE_NOT_FOUND));
return;
}
file_system_context_->operation_runner()->GetMetadata(
@@ -182,7 +176,7 @@ void FileSystemURLRequestJob::DidAttemptAutoMount(base::File::Error result) {
file_system_context_->CrackURL(request_->url()).is_valid()) {
StartAsync();
} else {
- NotifyFailed(net::ERR_FILE_NOT_FOUND);
+ NotifyStartError(URLRequestStatus::FromError(net::ERR_FILE_NOT_FOUND));
}
}
@@ -190,9 +184,10 @@ void FileSystemURLRequestJob::DidGetMetadata(
base::File::Error error_code,
const base::File::Info& file_info) {
if (error_code != base::File::FILE_OK) {
- NotifyFailed(error_code == base::File::FILE_ERROR_INVALID_URL
- ? net::ERR_INVALID_URL
- : net::ERR_FILE_NOT_FOUND);
+ NotifyStartError(URLRequestStatus::FromError(
+ error_code == base::File::FILE_ERROR_INVALID_URL
+ ? net::ERR_INVALID_URL
+ : net::ERR_FILE_NOT_FOUND));
return;
}
@@ -202,8 +197,14 @@ void FileSystemURLRequestJob::DidGetMetadata(
is_directory_ = file_info.is_directory;
+ if (range_parse_result_ != net::OK) {
+ NotifyStartError(URLRequestStatus::FromError(range_parse_result_));
+ return;
+ }
+
if (!byte_range_.ComputeBounds(file_info.size)) {
- NotifyFailed(net::ERR_REQUEST_RANGE_NOT_SATISFIABLE);
+ NotifyStartError(
+ URLRequestStatus::FromError(net::ERR_REQUEST_RANGE_NOT_SATISFIABLE));
return;
}
@@ -227,17 +228,12 @@ void FileSystemURLRequestJob::DidGetMetadata(
}
void FileSystemURLRequestJob::DidRead(int result) {
- if (result > 0)
- SetStatus(URLRequestStatus()); // Clear the IO_PENDING status
- else if (result == 0)
- NotifyDone(URLRequestStatus());
- else
- NotifyFailed(result);
-
- remaining_bytes_ -= result;
- DCHECK_GE(remaining_bytes_, 0);
+ if (result >= 0) {
+ remaining_bytes_ -= result;
+ DCHECK_GE(remaining_bytes_, 0);
+ }
- NotifyReadComplete(result);
+ ReadRawDataComplete(result);
}
bool FileSystemURLRequestJob::IsRedirectResponse(GURL* location,
@@ -257,8 +253,4 @@ bool FileSystemURLRequestJob::IsRedirectResponse(GURL* location,
return false;
}
-void FileSystemURLRequestJob::NotifyFailed(int rv) {
- NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv));
-}
-
} // namespace storage
« no previous file with comments | « storage/browser/fileapi/file_system_url_request_job.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698