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

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

Issue 942633004: IndexedDB: Fixed support for empty blobs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Creating empty cursor to avoid null ptr deref. Created 5 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
Index: storage/browser/fileapi/file_writer_delegate.cc
diff --git a/storage/browser/fileapi/file_writer_delegate.cc b/storage/browser/fileapi/file_writer_delegate.cc
index abc9976e6d5be4ece24ee745ea86ab69464fb74d..73a0f2e075b2084532a001facc00e1e680d11f2d 100644
--- a/storage/browser/fileapi/file_writer_delegate.cc
+++ b/storage/browser/fileapi/file_writer_delegate.cc
@@ -31,6 +31,7 @@ FileWriterDelegate::FileWriterDelegate(
bytes_written_backlog_(0),
bytes_written_(0),
bytes_read_(0),
+ total_bytes_read_(0),
io_buffer_(new net::IOBufferWithSize(kReadBufSize)),
weak_factory_(this) {
}
@@ -135,7 +136,15 @@ void FileWriterDelegate::Read() {
void FileWriterDelegate::OnDataReceived(int bytes_read) {
bytes_read_ = bytes_read;
+ total_bytes_read_ += bytes_read;
if (!bytes_read_) { // We're done.
+ if (total_bytes_read_ == 0) {
+ // Need to call Write (even though no data was received). This is because
+ // the file is created lazily upon first receipt of data, so without it
+ // no empty file would be created.
+ cursor_ = new net::DrainableIOBuffer(io_buffer_.get(), bytes_read_);
jsbell 2015/02/25 00:10:30 Can you refactor to remove these duplicate bodies?
cmumford 2015/02/25 18:09:49 Done.
+ Write();
+ }
OnProgress(0, true);
} else {
// This could easily be optimized to rotate between a pool of buffers, so
@@ -234,9 +243,12 @@ void FileWriterDelegate::MaybeFlushForCompletion(
// DCHECK_EQ on enum classes is not supported.
DCHECK(flush_policy_ == FlushPolicy::FLUSH_ON_COMPLETION);
- int flush_error = file_stream_writer_->Flush(
- base::Bind(&FileWriterDelegate::OnFlushed, weak_factory_.GetWeakPtr(),
- error, bytes_written, progress_status));
+ int flush_error = 0;
+ if (bytes_written) {
+ flush_error = file_stream_writer_->Flush(
+ base::Bind(&FileWriterDelegate::OnFlushed, weak_factory_.GetWeakPtr(),
+ error, bytes_written, progress_status));
+ }
if (flush_error != net::ERR_IO_PENDING)
OnFlushed(error, bytes_written, progress_status, flush_error);
}
« storage/browser/blob/blob_data_builder.cc ('K') | « storage/browser/fileapi/file_writer_delegate.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698