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

Side by Side Diff: content/browser/indexed_db/indexed_db_backing_store.cc

Issue 942633004: IndexedDB: Fixed support for empty blobs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Backing store now creating empty file + test. Created 5 years, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/indexed_db/indexed_db_backing_store.h" 5 #include "content/browser/indexed_db/indexed_db_backing_store.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 2321 matching lines...) Expand 10 before | Expand all | Expand 10 after
2332 if (write_status == FileWriterDelegate::SUCCESS_IO_PENDING) 2332 if (write_status == FileWriterDelegate::SUCCESS_IO_PENDING)
2333 return; // We don't care about progress events. 2333 return; // We don't care about progress events.
2334 if (rv == base::File::FILE_OK) { 2334 if (rv == base::File::FILE_OK) {
2335 DCHECK_EQ(write_status, FileWriterDelegate::SUCCESS_COMPLETED); 2335 DCHECK_EQ(write_status, FileWriterDelegate::SUCCESS_COMPLETED);
2336 } else { 2336 } else {
2337 DCHECK(write_status == FileWriterDelegate::ERROR_WRITE_STARTED || 2337 DCHECK(write_status == FileWriterDelegate::ERROR_WRITE_STARTED ||
2338 write_status == FileWriterDelegate::ERROR_WRITE_NOT_STARTED); 2338 write_status == FileWriterDelegate::ERROR_WRITE_NOT_STARTED);
2339 } 2339 }
2340 2340
2341 bool success = write_status == FileWriterDelegate::SUCCESS_COMPLETED; 2341 bool success = write_status == FileWriterDelegate::SUCCESS_COMPLETED;
2342 2342 if (success && !bytes_written_) {
2343 if (success && !last_modified_.is_null()) { 2343 // LocalFileStreamWriter only creates a file if data is actually written.
2344 // If none was then create one now.
michaeln 2015/03/06 22:31:38 nit: the first line of this comment is enough
2345 task_runner_->PostTask(
2346 FROM_HERE, base::Bind(&LocalWriteClosure::CreateEmptyFile, this));
2347 } else if (success && !last_modified_.is_null()) {
2344 task_runner_->PostTask( 2348 task_runner_->PostTask(
2345 FROM_HERE, base::Bind(&LocalWriteClosure::UpdateTimeStamp, this)); 2349 FROM_HERE, base::Bind(&LocalWriteClosure::UpdateTimeStamp, this));
2346 } else { 2350 } else {
2347 task_runner_->PostTask( 2351 task_runner_->PostTask(
2348 FROM_HERE, 2352 FROM_HERE,
2349 base::Bind(&IndexedDBBackingStore::Transaction::ChainedBlobWriter:: 2353 base::Bind(&IndexedDBBackingStore::Transaction::ChainedBlobWriter::
2350 ReportWriteCompletion, 2354 ReportWriteCompletion,
2351 chained_blob_writer_, 2355 chained_blob_writer_,
2352 success, 2356 success,
2353 bytes_written_)); 2357 bytes_written_));
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
2396 // If necessary, update the timestamps on the file as a final 2400 // If necessary, update the timestamps on the file as a final
2397 // step before reporting success. 2401 // step before reporting success.
2398 void UpdateTimeStamp() { 2402 void UpdateTimeStamp() {
2399 DCHECK(task_runner_->RunsTasksOnCurrentThread()); 2403 DCHECK(task_runner_->RunsTasksOnCurrentThread());
2400 if (!base::TouchFile(file_path_, last_modified_, last_modified_)) { 2404 if (!base::TouchFile(file_path_, last_modified_, last_modified_)) {
2401 // TODO(ericu): Complain quietly; timestamp's probably not vital. 2405 // TODO(ericu): Complain quietly; timestamp's probably not vital.
2402 } 2406 }
2403 chained_blob_writer_->ReportWriteCompletion(true, bytes_written_); 2407 chained_blob_writer_->ReportWriteCompletion(true, bytes_written_);
2404 } 2408 }
2405 2409
2410 // Create an empty file.
michaeln 2015/03/06 22:31:38 this comment probably isn't needed
2411 void CreateEmptyFile() {
2412 DCHECK(task_runner_->RunsTasksOnCurrentThread());
2413 base::File file(file_path_,
2414 base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE);
2415 bool success = file.created();
2416 file.Close();
2417 if (success && !last_modified_.is_null())
2418 UpdateTimeStamp();
2419 else
2420 chained_blob_writer_->ReportWriteCompletion(success, bytes_written_);
2421 }
2422
2406 scoped_refptr<IndexedDBBackingStore::Transaction::ChainedBlobWriter> 2423 scoped_refptr<IndexedDBBackingStore::Transaction::ChainedBlobWriter>
2407 chained_blob_writer_; 2424 chained_blob_writer_;
2408 scoped_refptr<base::SequencedTaskRunner> task_runner_; 2425 scoped_refptr<base::SequencedTaskRunner> task_runner_;
2409 int64 bytes_written_; 2426 int64 bytes_written_;
2410 2427
2411 base::FilePath file_path_; 2428 base::FilePath file_path_;
2412 base::Time last_modified_; 2429 base::Time last_modified_;
2413 2430
2414 DISALLOW_COPY_AND_ASSIGN(LocalWriteClosure); 2431 DISALLOW_COPY_AND_ASSIGN(LocalWriteClosure);
2415 }; 2432 };
(...skipping 1988 matching lines...) Expand 10 before | Expand all | Expand 10 after
4404 4421
4405 IndexedDBBackingStore::Transaction::WriteDescriptor::WriteDescriptor( 4422 IndexedDBBackingStore::Transaction::WriteDescriptor::WriteDescriptor(
4406 const WriteDescriptor& other) = default; 4423 const WriteDescriptor& other) = default;
4407 IndexedDBBackingStore::Transaction::WriteDescriptor::~WriteDescriptor() = 4424 IndexedDBBackingStore::Transaction::WriteDescriptor::~WriteDescriptor() =
4408 default; 4425 default;
4409 IndexedDBBackingStore::Transaction::WriteDescriptor& 4426 IndexedDBBackingStore::Transaction::WriteDescriptor&
4410 IndexedDBBackingStore::Transaction::WriteDescriptor:: 4427 IndexedDBBackingStore::Transaction::WriteDescriptor::
4411 operator=(const WriteDescriptor& other) = default; 4428 operator=(const WriteDescriptor& other) = default;
4412 4429
4413 } // namespace content 4430 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698