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

Unified Diff: webkit/blob/blob_url_request_job.cc

Issue 9402014: net: FileStream::Read/Write() to take IOBuffer* instead of char* (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix redirect_to_file_resource_handler.cc Created 8 years, 10 months 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 | « webkit/blob/blob_url_request_job.h ('k') | webkit/fileapi/file_system_url_request_job.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/blob/blob_url_request_job.cc
diff --git a/webkit/blob/blob_url_request_job.cc b/webkit/blob/blob_url_request_job.cc
index d00761e93bfdd811c7bf87dc3906cd7587f79f31..0e4432c576b795f9cca94772c8385826ad0d9f76 100644
--- a/webkit/blob/blob_url_request_job.cc
+++ b/webkit/blob/blob_url_request_job.cc
@@ -59,9 +59,6 @@ BlobURLRequestJob::BlobURLRequestJob(
total_size_(0),
current_item_offset_(0),
remaining_bytes_(0),
- read_buf_offset_(0),
- read_buf_size_(0),
- read_buf_remaining_bytes_(0),
bytes_to_read_(0),
error_(false),
headers_set_(false),
@@ -233,17 +230,14 @@ bool BlobURLRequestJob::ReadRawData(net::IOBuffer* dest,
// Keep track of the buffer.
DCHECK(!read_buf_);
- read_buf_ = dest;
- read_buf_offset_ = 0;
- read_buf_size_ = dest_size;
- read_buf_remaining_bytes_ = dest_size;
+ read_buf_ = new net::DrainableIOBuffer(dest, dest_size);
return ReadLoop(bytes_read);
}
bool BlobURLRequestJob::ReadLoop(int* bytes_read) {
// Read until we encounter an error or could not get the data immediately.
- while (remaining_bytes_ > 0 && read_buf_remaining_bytes_ > 0) {
+ while (remaining_bytes_ > 0 && read_buf_->BytesRemaining() > 0) {
if (!ReadItem())
return false;
}
@@ -255,9 +249,10 @@ bool BlobURLRequestJob::ReadLoop(int* bytes_read) {
int BlobURLRequestJob::ComputeBytesToRead() const {
int64 current_item_remaining_bytes =
item_length_list_[item_index_] - current_item_offset_;
- int bytes_to_read = (read_buf_remaining_bytes_ > current_item_remaining_bytes)
+ int bytes_to_read = (read_buf_->BytesRemaining() >
+ current_item_remaining_bytes)
? static_cast<int>(current_item_remaining_bytes)
- : read_buf_remaining_bytes_;
+ : read_buf_->BytesRemaining();
if (bytes_to_read > remaining_bytes_)
bytes_to_read = static_cast<int>(remaining_bytes_);
return bytes_to_read;
@@ -298,9 +293,9 @@ bool BlobURLRequestJob::ReadItem() {
}
bool BlobURLRequestJob::ReadBytes(const BlobData::Item& item) {
- DCHECK(read_buf_remaining_bytes_ >= bytes_to_read_);
+ DCHECK_GE(read_buf_->BytesRemaining(), bytes_to_read_);
- memcpy(read_buf_->data() + read_buf_offset_,
+ memcpy(read_buf_->data(),
&item.data.at(0) + item.offset + current_item_offset_,
bytes_to_read_);
@@ -348,10 +343,10 @@ void BlobURLRequestJob::DidOpen(base::PlatformFileError rv,
bool BlobURLRequestJob::ReadFile(const BlobData::Item& item) {
DCHECK(stream_.get());
DCHECK(stream_->IsOpen());
- DCHECK(read_buf_remaining_bytes_ >= bytes_to_read_);
+ DCHECK_GE(read_buf_->BytesRemaining(), bytes_to_read_);
// Start the asynchronous reading.
- int rv = stream_->Read(read_buf_->data() + read_buf_offset_,
+ int rv = stream_->Read(read_buf_,
bytes_to_read_,
base::Bind(&BlobURLRequestJob::DidRead,
base::Unretained(this)));
@@ -387,7 +382,7 @@ void BlobURLRequestJob::DidRead(int result) {
AdvanceBytesRead(result);
// If the read buffer is completely filled, we're done.
- if (!read_buf_remaining_bytes_) {
+ if (!read_buf_->BytesRemaining()) {
int bytes_read = ReadCompleted();
NotifyReadComplete(bytes_read);
return;
@@ -421,17 +416,13 @@ void BlobURLRequestJob::AdvanceBytesRead(int result) {
DCHECK_GE(remaining_bytes_, 0);
// Adjust the read buffer.
- read_buf_offset_ += result;
- read_buf_remaining_bytes_ -= result;
- DCHECK_GE(read_buf_remaining_bytes_, 0);
+ read_buf_->DidConsume(result);
+ DCHECK_GE(read_buf_->BytesRemaining(), 0);
}
int BlobURLRequestJob::ReadCompleted() {
- int bytes_read = read_buf_size_ - read_buf_remaining_bytes_;
+ int bytes_read = read_buf_->BytesConsumed();
read_buf_ = NULL;
- read_buf_offset_ = 0;
- read_buf_size_ = 0;
- read_buf_remaining_bytes_ = 0;
return bytes_read;
}
« no previous file with comments | « webkit/blob/blob_url_request_job.h ('k') | webkit/fileapi/file_system_url_request_job.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698