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 8edcb3d001f59047823207cf7d5fb9bcf73adb94..8d58f6498c14bf7db96749789b768c11f12a14f4 100644 |
--- a/storage/browser/fileapi/file_system_url_request_job.cc |
+++ b/storage/browser/fileapi/file_system_url_request_job.cc |
@@ -62,7 +62,6 @@ FileSystemURLRequestJob::FileSystemURLRequestJob( |
file_system_context_(file_system_context), |
is_directory_(false), |
remaining_bytes_(0), |
- range_parse_result_(net::OK), |
weak_factory_(this) {} |
FileSystemURLRequestJob::~FileSystemURLRequestJob() {} |
@@ -80,28 +79,39 @@ void FileSystemURLRequestJob::Kill() { |
weak_factory_.InvalidateWeakPtrs(); |
} |
-int FileSystemURLRequestJob::ReadRawData(net::IOBuffer* dest, int dest_size) { |
+bool FileSystemURLRequestJob::ReadRawData(net::IOBuffer* dest, |
+ int dest_size, |
+ int* bytes_read) { |
DCHECK_NE(dest_size, 0); |
+ DCHECK(bytes_read); |
DCHECK_GE(remaining_bytes_, 0); |
if (reader_.get() == NULL) |
- return net::ERR_FAILED; |
+ return false; |
if (remaining_bytes_ < dest_size) |
- dest_size = remaining_bytes_; |
+ dest_size = static_cast<int>(remaining_bytes_); |
- if (!dest_size) |
- return 0; |
+ if (!dest_size) { |
+ *bytes_read = 0; |
+ return true; |
+ } |
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; |
} |
- |
- return rv; |
+ if (rv == net::ERR_IO_PENDING) |
+ SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); |
+ else |
+ NotifyFailed(rv); |
+ return false; |
} |
bool FileSystemURLRequestJob::GetMimeType(std::string* mime_type) const { |
@@ -116,12 +126,8 @@ 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]; |
@@ -129,7 +135,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. |
- range_parse_result_ = net::ERR_REQUEST_RANGE_NOT_SATISFIABLE; |
+ NotifyFailed(net::ERR_REQUEST_RANGE_NOT_SATISFIABLE); |
} |
} |
} |
@@ -161,7 +167,7 @@ void FileSystemURLRequestJob::StartAsync() { |
} |
if (!file_system_context_->CanServeURLRequest(url_)) { |
// In incognito mode the API is not usable and there should be no data. |
- NotifyStartError(URLRequestStatus::FromError(net::ERR_FILE_NOT_FOUND)); |
+ NotifyFailed(net::ERR_FILE_NOT_FOUND); |
return; |
} |
file_system_context_->operation_runner()->GetMetadata( |
@@ -176,7 +182,7 @@ void FileSystemURLRequestJob::DidAttemptAutoMount(base::File::Error result) { |
file_system_context_->CrackURL(request_->url()).is_valid()) { |
StartAsync(); |
} else { |
- NotifyStartError(URLRequestStatus::FromError(net::ERR_FILE_NOT_FOUND)); |
+ NotifyFailed(net::ERR_FILE_NOT_FOUND); |
} |
} |
@@ -184,10 +190,9 @@ void FileSystemURLRequestJob::DidGetMetadata( |
base::File::Error error_code, |
const base::File::Info& file_info) { |
if (error_code != base::File::FILE_OK) { |
- NotifyStartError(URLRequestStatus::FromError( |
- error_code == base::File::FILE_ERROR_INVALID_URL |
- ? net::ERR_INVALID_URL |
- : net::ERR_FILE_NOT_FOUND)); |
+ NotifyFailed(error_code == base::File::FILE_ERROR_INVALID_URL |
+ ? net::ERR_INVALID_URL |
+ : net::ERR_FILE_NOT_FOUND); |
return; |
} |
@@ -197,14 +202,8 @@ 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)) { |
- NotifyStartError( |
- URLRequestStatus::FromError(net::ERR_REQUEST_RANGE_NOT_SATISFIABLE)); |
+ NotifyFailed(net::ERR_REQUEST_RANGE_NOT_SATISFIABLE); |
return; |
} |
@@ -228,12 +227,17 @@ void FileSystemURLRequestJob::DidGetMetadata( |
} |
void FileSystemURLRequestJob::DidRead(int result) { |
- if (result >= 0) { |
- remaining_bytes_ -= result; |
- DCHECK_GE(remaining_bytes_, 0); |
- } |
+ 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); |
- ReadRawDataComplete(result); |
+ NotifyReadComplete(result); |
} |
bool FileSystemURLRequestJob::IsRedirectResponse(GURL* location, |
@@ -253,4 +257,8 @@ bool FileSystemURLRequestJob::IsRedirectResponse(GURL* location, |
return false; |
} |
+void FileSystemURLRequestJob::NotifyFailed(int rv) { |
+ NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); |
+} |
+ |
} // namespace storage |