Commit d9059b9e authored by Daniel Murphy's avatar Daniel Murphy Committed by Commit Bot

Removing BackingStore dependency from ChainedBlobWriteImpl

R=enne@chromium.org

Bug: 1024966
Change-Id: I88d3d38ff608277ec64c2c134affd3d4704ea9e9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1925225
Auto-Submit: Daniel Murphy <dmurph@chromium.org>
Reviewed-by: default avatarenne <enne@chromium.org>
Commit-Queue: Daniel Murphy <dmurph@chromium.org>
Cr-Commit-Position: refs/heads/master@{#719428}
parent 58c201f2
...@@ -90,6 +90,8 @@ using indexed_db::PutVarInt; ...@@ -90,6 +90,8 @@ using indexed_db::PutVarInt;
using indexed_db::ReportOpenStatus; using indexed_db::ReportOpenStatus;
namespace { namespace {
using WriteBlobFileCallback = base::RepeatingCallback<
bool(/*database_id=*/int64_t, const WriteDescriptor&, ChainedBlobWriter*)>;
FilePath GetBlobDirectoryName(const FilePath& path_base, int64_t database_id) { FilePath GetBlobDirectoryName(const FilePath& path_base, int64_t database_id) {
return path_base.AppendASCII(base::StringPrintf("%" PRIx64, database_id)); return path_base.AppendASCII(base::StringPrintf("%" PRIx64, database_id));
...@@ -1379,18 +1381,19 @@ Status IndexedDBBackingStore::KeyExistsInObjectStore( ...@@ -1379,18 +1381,19 @@ Status IndexedDBBackingStore::KeyExistsInObjectStore(
class IndexedDBBackingStore::Transaction::ChainedBlobWriterImpl class IndexedDBBackingStore::Transaction::ChainedBlobWriterImpl
: public ChainedBlobWriter { : public ChainedBlobWriter {
public: public:
// Must be called on the IDB task runner.
static scoped_refptr<ChainedBlobWriterImpl> Create( static scoped_refptr<ChainedBlobWriterImpl> Create(
int64_t database_id, int64_t database_id,
base::WeakPtr<IndexedDBBackingStore> backing_store,
WriteDescriptorVec* blobs, WriteDescriptorVec* blobs,
blink::mojom::IDBTransactionDurability durability, blink::mojom::IDBTransactionDurability durability,
WriteBlobFileCallback write_file_callback,
BlobWriteCallback callback) { BlobWriteCallback callback) {
DCHECK(backing_store->task_runner()->RunsTasksInCurrentSequence());
auto writer = base::WrapRefCounted(new ChainedBlobWriterImpl( auto writer = base::WrapRefCounted(new ChainedBlobWriterImpl(
database_id, backing_store, durability, std::move(callback))); database_id, durability, std::move(write_file_callback),
std::move(callback)));
writer->blobs_.swap(*blobs); writer->blobs_.swap(*blobs);
writer->iter_ = writer->blobs_.begin(); writer->iter_ = writer->blobs_.begin();
backing_store->task_runner()->PostTask( base::SequencedTaskRunnerHandle::Get()->PostTask(
FROM_HERE, FROM_HERE,
base::BindOnce(&ChainedBlobWriterImpl::WriteNextFile, writer)); base::BindOnce(&ChainedBlobWriterImpl::WriteNextFile, writer));
return writer; return writer;
...@@ -1439,20 +1442,20 @@ class IndexedDBBackingStore::Transaction::ChainedBlobWriterImpl ...@@ -1439,20 +1442,20 @@ class IndexedDBBackingStore::Transaction::ChainedBlobWriterImpl
} }
private: private:
// Must be called on the IDB task runner.
ChainedBlobWriterImpl(int64_t database_id, ChainedBlobWriterImpl(int64_t database_id,
base::WeakPtr<IndexedDBBackingStore> backing_store,
blink::mojom::IDBTransactionDurability durability, blink::mojom::IDBTransactionDurability durability,
WriteBlobFileCallback write_file_callback,
BlobWriteCallback callback) BlobWriteCallback callback)
: waiting_for_callback_(false), : waiting_for_callback_(false),
durability_(durability), durability_(durability),
database_id_(database_id), database_id_(database_id),
backing_store_(backing_store), write_file_callback_(std::move(write_file_callback)),
callback_(std::move(callback)), callback_(std::move(callback)),
aborted_(false) { aborted_(false) {}
DCHECK(!backing_store_ || ~ChainedBlobWriterImpl() override {
backing_store_->task_runner()->RunsTasksInCurrentSequence()); DCHECK_CALLED_ON_VALID_SEQUENCE(idb_sequence_checker_);
} }
~ChainedBlobWriterImpl() override {}
void WriteNextFile() { void WriteNextFile() {
DCHECK_CALLED_ON_VALID_SEQUENCE(idb_sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(idb_sequence_checker_);
...@@ -1466,8 +1469,7 @@ class IndexedDBBackingStore::Transaction::ChainedBlobWriterImpl ...@@ -1466,8 +1469,7 @@ class IndexedDBBackingStore::Transaction::ChainedBlobWriterImpl
std::move(callback_).Run(BlobWriteResult::kRunPhaseTwoAsync); std::move(callback_).Run(BlobWriteResult::kRunPhaseTwoAsync);
return; return;
} else { } else {
if (!backing_store_ || if (!write_file_callback_.Run(database_id_, *iter_, this)) {
!backing_store_->WriteBlobFile(database_id_, *iter_, this)) {
std::move(callback_).Run(BlobWriteResult::kFailure); std::move(callback_).Run(BlobWriteResult::kFailure);
return; return;
} }
...@@ -1481,7 +1483,7 @@ class IndexedDBBackingStore::Transaction::ChainedBlobWriterImpl ...@@ -1481,7 +1483,7 @@ class IndexedDBBackingStore::Transaction::ChainedBlobWriterImpl
WriteDescriptorVec blobs_; WriteDescriptorVec blobs_;
WriteDescriptorVec::const_iterator iter_; WriteDescriptorVec::const_iterator iter_;
int64_t database_id_; int64_t database_id_;
base::WeakPtr<IndexedDBBackingStore> backing_store_; WriteBlobFileCallback write_file_callback_;
// Callback result is useless as call stack is no longer transaction's // Callback result is useless as call stack is no longer transaction's
// operations queue. Errors are instead handled in // operations queue. Errors are instead handled in
// IndexedDBTransaction::BlobWriteComplete. // IndexedDBTransaction::BlobWriteComplete.
...@@ -3264,8 +3266,17 @@ leveldb::Status IndexedDBBackingStore::Transaction::WriteNewBlobs( ...@@ -3264,8 +3266,17 @@ leveldb::Status IndexedDBBackingStore::Transaction::WriteNewBlobs(
// Creating the writer will start it going asynchronously. The transaction // Creating the writer will start it going asynchronously. The transaction
// can be destructed before the callback is triggered. // can be destructed before the callback is triggered.
chained_blob_writer_ = ChainedBlobWriterImpl::Create( chained_blob_writer_ = ChainedBlobWriterImpl::Create(
database_id_, backing_store_->AsWeakPtr(), new_files_to_write, database_id_, new_files_to_write, durability_,
durability_, base::BindRepeating(
[](base::WeakPtr<IndexedDBBackingStore> backing_store,
int64_t database_id, const WriteDescriptor& descriptor,
ChainedBlobWriter* chained_blob_writer) {
if (!backing_store)
return false;
return backing_store->WriteBlobFile(database_id, descriptor,
chained_blob_writer);
},
backing_store_->AsWeakPtr()),
base::BindOnce( base::BindOnce(
[](base::WeakPtr<IndexedDBBackingStore::Transaction> transaction, [](base::WeakPtr<IndexedDBBackingStore::Transaction> transaction,
void* tracing_end_ptr, BlobWriteCallback final_callback, void* tracing_end_ptr, BlobWriteCallback final_callback,
......
...@@ -118,14 +118,18 @@ typedef std::vector<WriteDescriptor> WriteDescriptorVec; ...@@ -118,14 +118,18 @@ typedef std::vector<WriteDescriptor> WriteDescriptorVec;
// This class facilitates writing multiple blobs to files. // This class facilitates writing multiple blobs to files.
class ChainedBlobWriter : public base::RefCountedThreadSafe<ChainedBlobWriter> { class ChainedBlobWriter : public base::RefCountedThreadSafe<ChainedBlobWriter> {
public: public:
// Called on the IO thread.
virtual void set_delegate( virtual void set_delegate(
std::unique_ptr<storage::FileWriterDelegate> delegate) = 0; std::unique_ptr<storage::FileWriterDelegate> delegate) = 0;
// Called on the IDB task runner.
virtual void ReportWriteCompletion(bool succeeded, int64_t bytes_written) = 0; virtual void ReportWriteCompletion(bool succeeded, int64_t bytes_written) = 0;
// Called on the IDB task runner.
virtual void Abort() = 0; virtual void Abort() = 0;
// Whether to flush to the file system when writing or not. // Whether to flush to the file system when writing or not.
// Called on the IO thread.
virtual storage::FlushPolicy GetFlushPolicy() const = 0; virtual storage::FlushPolicy GetFlushPolicy() const = 0;
protected: protected:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment