Commit 552f07b4 authored by Daniel Murphy's avatar Daniel Murphy Committed by Commit Bot

[IndexedDB] Moving blob storage related classes out of IndexedDBBackingStore

This change is the first one in a series to start removing blob-specific
code from the IndexedDBBackingStore class into its own file. This will
eventually hold the blob storage integration separately with its own
tests, etc.

Work planning doc:
https://docs.google.com/document/d/18suNOOzuEJbqgRJF0MB2VqdTyYqS4cvI2PGaCpyPXSw/edit?pli=1#heading=h.ilyrswbua4hv

Bug: 1024966
Change-Id: I3a468f79720344437973b175b098ad60389079fc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1918199Reviewed-by: default avatarenne <enne@chromium.org>
Commit-Queue: Daniel Murphy <dmurph@chromium.org>
Auto-Submit: Daniel Murphy <dmurph@chromium.org>
Cr-Commit-Position: refs/heads/master@{#719423}
parent f8315ef2
...@@ -977,6 +977,8 @@ jumbo_source_set("browser") { ...@@ -977,6 +977,8 @@ jumbo_source_set("browser") {
"indexed_db/indexed_db_backing_store.h", "indexed_db/indexed_db_backing_store.h",
"indexed_db/indexed_db_blob_info.cc", "indexed_db/indexed_db_blob_info.cc",
"indexed_db/indexed_db_blob_info.h", "indexed_db/indexed_db_blob_info.h",
"indexed_db/indexed_db_blob_storage.cc",
"indexed_db/indexed_db_blob_storage.h",
"indexed_db/indexed_db_callback_helpers.h", "indexed_db/indexed_db_callback_helpers.h",
"indexed_db/indexed_db_callbacks.cc", "indexed_db/indexed_db_callbacks.cc",
"indexed_db/indexed_db_callbacks.h", "indexed_db/indexed_db_callbacks.h",
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "components/services/storage/indexed_db/scopes/scope_lock.h" #include "components/services/storage/indexed_db/scopes/scope_lock.h"
#include "content/browser/indexed_db/indexed_db.h" #include "content/browser/indexed_db/indexed_db.h"
#include "content/browser/indexed_db/indexed_db_blob_info.h" #include "content/browser/indexed_db/indexed_db_blob_info.h"
#include "content/browser/indexed_db/indexed_db_blob_storage.h"
#include "content/browser/indexed_db/indexed_db_leveldb_coding.h" #include "content/browser/indexed_db/indexed_db_leveldb_coding.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "storage/browser/blob/blob_data_handle.h" #include "storage/browser/blob/blob_data_handle.h"
...@@ -46,10 +47,6 @@ class IndexedDBKeyRange; ...@@ -46,10 +47,6 @@ class IndexedDBKeyRange;
struct IndexedDBDatabaseMetadata; struct IndexedDBDatabaseMetadata;
} // namespace blink } // namespace blink
namespace storage {
class FileWriterDelegate;
}
namespace content { namespace content {
class IndexedDBActiveBlobRegistry; class IndexedDBActiveBlobRegistry;
class TransactionalLevelDBDatabase; class TransactionalLevelDBDatabase;
...@@ -94,43 +91,6 @@ class CONTENT_EXPORT IndexedDBBackingStore { ...@@ -94,43 +91,6 @@ class CONTENT_EXPORT IndexedDBBackingStore {
DISALLOW_COPY_AND_ASSIGN(RecordIdentifier); DISALLOW_COPY_AND_ASSIGN(RecordIdentifier);
}; };
enum class BlobWriteResult {
// There was an error writing the blobs.
kFailure,
// The blobs were written, and phase two should be scheduled asynchronously.
// The returned status will be ignored.
kRunPhaseTwoAsync,
// The blobs were written, and phase two should be run now. The returned
// status will be correctly propagated.
kRunPhaseTwoAndReturnResult,
};
// The returned status is only used when the result is
// |kRunPhaseTwoAndReturnResult|.
using BlobWriteCallback = base::OnceCallback<leveldb::Status(
IndexedDBBackingStore::BlobWriteResult)>;
class BlobChangeRecord {
public:
BlobChangeRecord(const std::string& key, int64_t object_store_id);
~BlobChangeRecord();
const std::string& key() const { return key_; }
int64_t object_store_id() const { return object_store_id_; }
void SetBlobInfo(std::vector<IndexedDBBlobInfo>* blob_info);
std::vector<IndexedDBBlobInfo>& mutable_blob_info() { return blob_info_; }
const std::vector<IndexedDBBlobInfo>& blob_info() const {
return blob_info_;
}
std::unique_ptr<BlobChangeRecord> Clone() const;
private:
std::string key_;
int64_t object_store_id_;
std::vector<IndexedDBBlobInfo> blob_info_;
DISALLOW_COPY_AND_ASSIGN(BlobChangeRecord);
};
class CONTENT_EXPORT Transaction { class CONTENT_EXPORT Transaction {
public: public:
explicit Transaction(base::WeakPtr<IndexedDBBackingStore> backing_store, explicit Transaction(base::WeakPtr<IndexedDBBackingStore> backing_store,
...@@ -160,11 +120,9 @@ class CONTENT_EXPORT IndexedDBBackingStore { ...@@ -160,11 +120,9 @@ class CONTENT_EXPORT IndexedDBBackingStore {
void Reset(); void Reset();
leveldb::Status PutBlobInfoIfNeeded( leveldb::Status PutBlobInfoIfNeeded(
int64_t database_id, int64_t database_id,
int64_t object_store_id,
const std::string& object_store_data_key, const std::string& object_store_data_key,
std::vector<IndexedDBBlobInfo>*); std::vector<IndexedDBBlobInfo>*);
void PutBlobInfo(int64_t database_id, void PutBlobInfo(int64_t database_id,
int64_t object_store_id,
const std::string& object_store_data_key, const std::string& object_store_data_key,
std::vector<IndexedDBBlobInfo>*); std::vector<IndexedDBBlobInfo>*);
...@@ -181,74 +139,11 @@ class CONTENT_EXPORT IndexedDBBackingStore { ...@@ -181,74 +139,11 @@ class CONTENT_EXPORT IndexedDBBackingStore {
base::WeakPtr<Transaction> AsWeakPtr(); base::WeakPtr<Transaction> AsWeakPtr();
// This holds a BlobEntryKey and the encoded IndexedDBBlobInfo vector stored
// under that key.
typedef std::vector<std::pair<BlobEntryKey, std::string>>
BlobEntryKeyValuePairVec;
class CONTENT_EXPORT WriteDescriptor {
public:
WriteDescriptor(const storage::BlobDataHandle* blob,
int64_t key,
int64_t size,
base::Time last_modified);
WriteDescriptor(const base::FilePath& path,
int64_t key,
int64_t size,
base::Time last_modified);
WriteDescriptor(const WriteDescriptor& other);
~WriteDescriptor();
WriteDescriptor& operator=(const WriteDescriptor& other);
bool is_file() const { return is_file_; }
const storage::BlobDataHandle* blob() const {
DCHECK(!is_file_);
return &blob_.value();
}
const base::FilePath& file_path() const {
DCHECK(is_file_);
return file_path_;
}
int64_t key() const { return key_; }
int64_t size() const { return size_; }
base::Time last_modified() const { return last_modified_; }
private:
bool is_file_;
base::Optional<storage::BlobDataHandle> blob_;
base::FilePath file_path_;
int64_t key_;
int64_t size_;
base::Time last_modified_;
};
class ChainedBlobWriter
: public base::RefCountedThreadSafe<ChainedBlobWriter> {
public:
virtual void set_delegate(
std::unique_ptr<storage::FileWriterDelegate> delegate) = 0;
// TODO(ericu): Add a reason in the event of failure.
virtual void ReportWriteCompletion(bool succeeded,
int64_t bytes_written) = 0;
virtual void Abort() = 0;
// Whether to flush to the file system when writing or not.
virtual storage::FlushPolicy GetFlushPolicy() const = 0;
protected:
friend class base::RefCountedThreadSafe<ChainedBlobWriter>;
virtual ~ChainedBlobWriter() {}
};
class ChainedBlobWriterImpl; class ChainedBlobWriterImpl;
typedef std::vector<WriteDescriptor> WriteDescriptorVec;
private: private:
// Called by CommitPhaseOne: Identifies the blob entries to write and adds // Called by CommitPhaseOne: Identifies the blob entries to write and adds
// them to the primary blob journal directly (i.e. not as part of the // them to the recovery blob journal directly (i.e. not as part of the
// transaction). Populates blobs_to_write_. // transaction). Populates blobs_to_write_.
leveldb::Status HandleBlobPreTransaction( leveldb::Status HandleBlobPreTransaction(
BlobEntryKeyValuePairVec* new_blob_entries, BlobEntryKeyValuePairVec* new_blob_entries,
...@@ -287,12 +182,12 @@ class CONTENT_EXPORT IndexedDBBackingStore { ...@@ -287,12 +182,12 @@ class CONTENT_EXPORT IndexedDBBackingStore {
int64_t database_id_; int64_t database_id_;
// List of blob files being newly written as part of this transaction. // List of blob files being newly written as part of this transaction.
// These will be added to the primary blob journal prior to commit, then // These will be added to the recovery blob journal prior to commit, then
// removed after a successful commit. // removed after a successful commit.
BlobJournalType blobs_to_write_; BlobJournalType blobs_to_write_;
// List of blob files being deleted as part of this transaction. These will // List of blob files being deleted as part of this transaction. These will
// be added to either the primary or live blob journal as appropriate // be added to either the recovery or live blob journal as appropriate
// following a successful commit. // following a successful commit.
BlobJournalType blobs_to_remove_; BlobJournalType blobs_to_remove_;
scoped_refptr<ChainedBlobWriter> chained_blob_writer_; scoped_refptr<ChainedBlobWriter> chained_blob_writer_;
...@@ -610,10 +505,9 @@ class CONTENT_EXPORT IndexedDBBackingStore { ...@@ -610,10 +505,9 @@ class CONTENT_EXPORT IndexedDBBackingStore {
leveldb::Status GetCompleteMetadata( leveldb::Status GetCompleteMetadata(
std::vector<blink::IndexedDBDatabaseMetadata>* output); std::vector<blink::IndexedDBDatabaseMetadata>* output);
virtual bool WriteBlobFile( virtual bool WriteBlobFile(int64_t database_id,
int64_t database_id, const WriteDescriptor& descriptor,
const Transaction::WriteDescriptor& descriptor, ChainedBlobWriter* chained_blob_writer);
Transaction::ChainedBlobWriter* chained_blob_writer);
// Remove the referenced file on disk. // Remove the referenced file on disk.
virtual bool RemoveBlobFile(int64_t database_id, int64_t key) const; virtual bool RemoveBlobFile(int64_t database_id, int64_t key) const;
......
...@@ -86,10 +86,7 @@ class TestableIndexedDBBackingStore : public IndexedDBBackingStore { ...@@ -86,10 +86,7 @@ class TestableIndexedDBBackingStore : public IndexedDBBackingStore {
database_id_(0) {} database_id_(0) {}
~TestableIndexedDBBackingStore() override = default; ~TestableIndexedDBBackingStore() override = default;
const std::vector<IndexedDBBackingStore::Transaction::WriteDescriptor>& const std::vector<WriteDescriptor>& writes() const { return writes_; }
writes() const {
return writes_;
}
void ClearWrites() { writes_.clear(); } void ClearWrites() { writes_.clear(); }
const std::vector<int64_t>& removals() const { return removals_; } const std::vector<int64_t>& removals() const { return removals_; }
void ClearRemovals() { removals_.clear(); } void ClearRemovals() { removals_.clear(); }
...@@ -99,10 +96,9 @@ class TestableIndexedDBBackingStore : public IndexedDBBackingStore { ...@@ -99,10 +96,9 @@ class TestableIndexedDBBackingStore : public IndexedDBBackingStore {
} }
protected: protected:
bool WriteBlobFile( bool WriteBlobFile(int64_t database_id,
int64_t database_id, const WriteDescriptor& descriptor,
const Transaction::WriteDescriptor& descriptor, ChainedBlobWriter* chained_blob_writer) override {
Transaction::ChainedBlobWriter* chained_blob_writer) override {
if (KeyPrefix::IsValidDatabaseId(database_id_)) { if (KeyPrefix::IsValidDatabaseId(database_id_)) {
if (database_id_ != database_id) { if (database_id_ != database_id) {
return false; return false;
...@@ -112,9 +108,8 @@ class TestableIndexedDBBackingStore : public IndexedDBBackingStore { ...@@ -112,9 +108,8 @@ class TestableIndexedDBBackingStore : public IndexedDBBackingStore {
} }
writes_.push_back(descriptor); writes_.push_back(descriptor);
task_runner()->PostTask( task_runner()->PostTask(
FROM_HERE, FROM_HERE, base::BindOnce(&ChainedBlobWriter::ReportWriteCompletion,
base::BindOnce(&Transaction::ChainedBlobWriter::ReportWriteCompletion, chained_blob_writer, true, 1));
chained_blob_writer, true, 1));
return true; return true;
} }
...@@ -129,7 +124,7 @@ class TestableIndexedDBBackingStore : public IndexedDBBackingStore { ...@@ -129,7 +124,7 @@ class TestableIndexedDBBackingStore : public IndexedDBBackingStore {
private: private:
int64_t database_id_; int64_t database_id_;
std::vector<Transaction::WriteDescriptor> writes_; std::vector<WriteDescriptor> writes_;
// This is modified in an overridden virtual function that is properly const // This is modified in an overridden virtual function that is properly const
// in the real implementation, therefore must be mutable here. // in the real implementation, therefore must be mutable here.
...@@ -390,8 +385,7 @@ class IndexedDBBackingStoreTestWithBlobs : public IndexedDBBackingStoreTest { ...@@ -390,8 +385,7 @@ class IndexedDBBackingStoreTestWithBlobs : public IndexedDBBackingStoreTest {
if (backing_store_->writes().size() != blob_info_.size()) if (backing_store_->writes().size() != blob_info_.size())
return false; return false;
for (size_t i = 0; i < backing_store_->writes().size(); ++i) { for (size_t i = 0; i < backing_store_->writes().size(); ++i) {
const IndexedDBBackingStore::Transaction::WriteDescriptor& desc = const WriteDescriptor& desc = backing_store_->writes()[i];
backing_store_->writes()[i];
const IndexedDBBlobInfo& info = blob_info_[i]; const IndexedDBBlobInfo& info = blob_info_[i];
if (desc.is_file() != info.is_file()) { if (desc.is_file() != info.is_file()) {
if (!info.is_file() || !info.file_path().empty()) if (!info.is_file() || !info.file_path().empty())
...@@ -439,23 +433,21 @@ class TestCallback { ...@@ -439,23 +433,21 @@ class TestCallback {
TestCallback() = default; TestCallback() = default;
~TestCallback() = default; ~TestCallback() = default;
IndexedDBBackingStore::BlobWriteCallback CreateCallback() { BlobWriteCallback CreateCallback() {
return base::BindLambdaForTesting( return base::BindLambdaForTesting([this](BlobWriteResult result) {
[this](IndexedDBBackingStore::BlobWriteResult result) { this->called = true;
this->called = true; switch (result) {
switch (result) { case BlobWriteResult::kFailure:
case IndexedDBBackingStore::BlobWriteResult::kFailure: // Not tested.
// Not tested. this->succeeded = false;
this->succeeded = false; break;
break; case BlobWriteResult::kRunPhaseTwoAsync:
case IndexedDBBackingStore::BlobWriteResult::kRunPhaseTwoAsync: case BlobWriteResult::kRunPhaseTwoAndReturnResult:
case IndexedDBBackingStore::BlobWriteResult:: this->succeeded = true;
kRunPhaseTwoAndReturnResult: break;
this->succeeded = true; }
break; return leveldb::Status::OK();
} });
return leveldb::Status::OK();
});
} }
bool called = false; bool called = false;
bool succeeded = false; bool succeeded = false;
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/browser/indexed_db/indexed_db_blob_storage.h"
#include "base/callback.h"
namespace content {
BlobChangeRecord::BlobChangeRecord(const std::string& object_store_data_key)
: object_store_data_key_(object_store_data_key) {}
BlobChangeRecord::~BlobChangeRecord() = default;
void BlobChangeRecord::SetBlobInfo(std::vector<IndexedDBBlobInfo>* blob_info) {
blob_info_.clear();
if (blob_info)
blob_info_.swap(*blob_info);
}
std::unique_ptr<BlobChangeRecord> BlobChangeRecord::Clone() const {
std::unique_ptr<BlobChangeRecord> record(
new BlobChangeRecord(object_store_data_key_));
record->blob_info_ = blob_info_;
return record;
}
WriteDescriptor::WriteDescriptor(const storage::BlobDataHandle* blob,
int64_t key,
int64_t size,
base::Time last_modified)
: is_file_(false),
blob_(*blob),
key_(key),
size_(size),
last_modified_(last_modified) {}
WriteDescriptor::WriteDescriptor(const base::FilePath& file_path,
int64_t key,
int64_t size,
base::Time last_modified)
: is_file_(true),
file_path_(file_path),
key_(key),
size_(size),
last_modified_(last_modified) {}
WriteDescriptor::WriteDescriptor(const WriteDescriptor& other) = default;
WriteDescriptor::~WriteDescriptor() = default;
WriteDescriptor& WriteDescriptor::operator=(const WriteDescriptor& other) =
default;
} // namespace content
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_BLOB_STORAGE_H_
#define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_BLOB_STORAGE_H_
#include <stdint.h>
#include <map>
#include <string>
#include <vector>
#include "base/callback_forward.h"
#include "base/files/file_path.h"
#include "base/memory/ref_counted.h"
#include "base/optional.h"
#include "base/time/time.h"
#include "content/browser/indexed_db/indexed_db_blob_info.h"
#include "content/browser/indexed_db/indexed_db_leveldb_coding.h"
#include "storage/common/file_system/file_system_mount_option.h"
#include "third_party/leveldatabase/src/include/leveldb/status.h"
namespace storage {
class FileWriterDelegate;
} // namespace storage
namespace content {
// This file contains all of the classes & types used to store blobs in
// IndexedDB. Currently it is messy because this is mid-refactor, but it will be
// cleaned up over time.
enum class BlobWriteResult {
// There was an error writing the blobs.
kFailure,
// The blobs were written, and phase two should be scheduled asynchronously.
// The returned status will be ignored.
kRunPhaseTwoAsync,
// The blobs were written, and phase two should be run now. The returned
// status will be correctly propagated.
kRunPhaseTwoAndReturnResult,
};
// This callback is used to signify that writing blobs is complete. The
// BlobWriteResult signifies if the operation succeeded or not, and the returned
// status is used to handle errors in the next part of the transcation commit
// lifecycle. Note: The returned status can only be used when the result is
// |kRunPhaseTwoAndReturnResult|.
using BlobWriteCallback = base::OnceCallback<leveldb::Status(BlobWriteResult)>;
// This object represents a change in the database involving adding or removing
// blobs. if blob_info() is empty, then blobs are to be deleted, and if
// blob_info() is populated, then blobs are two be written (and also possibly
// deleted if there were already blobs).
class BlobChangeRecord {
public:
BlobChangeRecord(const std::string& object_store_data_key);
~BlobChangeRecord();
const std::string& object_store_data_key() const {
return object_store_data_key_;
}
void SetBlobInfo(std::vector<IndexedDBBlobInfo>* blob_info);
std::vector<IndexedDBBlobInfo>& mutable_blob_info() { return blob_info_; }
const std::vector<IndexedDBBlobInfo>& blob_info() const { return blob_info_; }
std::unique_ptr<BlobChangeRecord> Clone() const;
private:
std::string object_store_data_key_;
std::vector<IndexedDBBlobInfo> blob_info_;
DISALLOW_COPY_AND_ASSIGN(BlobChangeRecord);
};
// This holds a BlobEntryKey and the encoded IndexedDBBlobInfo vector stored
// under that key.
typedef std::vector<std::pair<BlobEntryKey, std::string>>
BlobEntryKeyValuePairVec;
// This is a blob that is going to to be written to a file.
class CONTENT_EXPORT WriteDescriptor {
public:
WriteDescriptor(const storage::BlobDataHandle* blob,
int64_t key,
int64_t size,
base::Time last_modified);
WriteDescriptor(const base::FilePath& path,
int64_t key,
int64_t size,
base::Time last_modified);
WriteDescriptor(const WriteDescriptor& other);
~WriteDescriptor();
WriteDescriptor& operator=(const WriteDescriptor& other);
bool is_file() const { return is_file_; }
const storage::BlobDataHandle* blob() const {
DCHECK(!is_file_);
return &blob_.value();
}
const base::FilePath& file_path() const {
DCHECK(is_file_);
return file_path_;
}
int64_t key() const { return key_; }
int64_t size() const { return size_; }
base::Time last_modified() const { return last_modified_; }
private:
bool is_file_;
base::Optional<storage::BlobDataHandle> blob_;
base::FilePath file_path_;
int64_t key_;
int64_t size_;
base::Time last_modified_;
};
typedef std::vector<WriteDescriptor> WriteDescriptorVec;
// This class facilitates writing multiple blobs to files.
class ChainedBlobWriter : public base::RefCountedThreadSafe<ChainedBlobWriter> {
public:
virtual void set_delegate(
std::unique_ptr<storage::FileWriterDelegate> delegate) = 0;
virtual void ReportWriteCompletion(bool succeeded, int64_t bytes_written) = 0;
virtual void Abort() = 0;
// Whether to flush to the file system when writing or not.
virtual storage::FlushPolicy GetFlushPolicy() const = 0;
protected:
friend class base::RefCountedThreadSafe<ChainedBlobWriter>;
virtual ~ChainedBlobWriter() {}
};
// This holds a BlobEntryKey and the encoded IndexedDBBlobInfo vector stored
// under that key.
typedef std::vector<std::pair<BlobEntryKey, std::string>>
BlobEntryKeyValuePairVec;
// Reports that the recovery and/or active journals have been processed, and
// blob files have been deleted.
using BlobFilesCleanedCallback = base::RepeatingClosure;
// Reports that there are (or are not) active blobs.
using ReportOutstandingBlobsCallback =
base::RepeatingCallback<void(/*outstanding_blobs=*/bool)>;
} // namespace content
#endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_BLOB_STORAGE_H_
...@@ -176,8 +176,7 @@ void IndexedDBFakeBackingStore::FakeTransaction::Begin( ...@@ -176,8 +176,7 @@ void IndexedDBFakeBackingStore::FakeTransaction::Begin(
std::vector<ScopeLock> locks) {} std::vector<ScopeLock> locks) {}
leveldb::Status IndexedDBFakeBackingStore::FakeTransaction::CommitPhaseOne( leveldb::Status IndexedDBFakeBackingStore::FakeTransaction::CommitPhaseOne(
BlobWriteCallback callback) { BlobWriteCallback callback) {
return std::move(callback).Run( return std::move(callback).Run(BlobWriteResult::kRunPhaseTwoAndReturnResult);
IndexedDBBackingStore::BlobWriteResult::kRunPhaseTwoAndReturnResult);
} }
leveldb::Status IndexedDBFakeBackingStore::FakeTransaction::CommitPhaseTwo() { leveldb::Status IndexedDBFakeBackingStore::FakeTransaction::CommitPhaseTwo() {
return result_; return result_;
......
...@@ -259,14 +259,14 @@ void IndexedDBTransaction::EnsureBackingStoreTransactionBegun() { ...@@ -259,14 +259,14 @@ void IndexedDBTransaction::EnsureBackingStoreTransactionBegun() {
} }
leveldb::Status IndexedDBTransaction::BlobWriteComplete( leveldb::Status IndexedDBTransaction::BlobWriteComplete(
IndexedDBBackingStore::BlobWriteResult result) { BlobWriteResult result) {
IDB_TRACE("IndexedDBTransaction::BlobWriteComplete"); IDB_TRACE("IndexedDBTransaction::BlobWriteComplete");
if (state_ == FINISHED) // aborted if (state_ == FINISHED) // aborted
return leveldb::Status::OK(); return leveldb::Status::OK();
DCHECK_EQ(state_, COMMITTING); DCHECK_EQ(state_, COMMITTING);
switch (result) { switch (result) {
case IndexedDBBackingStore::BlobWriteResult::kFailure: { case BlobWriteResult::kFailure: {
leveldb::Status status = Abort(IndexedDBDatabaseError( leveldb::Status status = Abort(IndexedDBDatabaseError(
blink::mojom::IDBException::kDataError, "Failed to write blobs.")); blink::mojom::IDBException::kDataError, "Failed to write blobs."));
if (!status.ok()) if (!status.ok())
...@@ -274,11 +274,11 @@ leveldb::Status IndexedDBTransaction::BlobWriteComplete( ...@@ -274,11 +274,11 @@ leveldb::Status IndexedDBTransaction::BlobWriteComplete(
// The result is ignored. // The result is ignored.
return leveldb::Status::OK(); return leveldb::Status::OK();
} }
case IndexedDBBackingStore::BlobWriteResult::kRunPhaseTwoAsync: case BlobWriteResult::kRunPhaseTwoAsync:
ScheduleTask(base::BindOnce(&CommitPhaseTwoProxy)); ScheduleTask(base::BindOnce(&CommitPhaseTwoProxy));
run_tasks_callback_.Run(); run_tasks_callback_.Run();
return leveldb::Status::OK(); return leveldb::Status::OK();
case IndexedDBBackingStore::BlobWriteResult::kRunPhaseTwoAndReturnResult: { case BlobWriteResult::kRunPhaseTwoAndReturnResult: {
return CommitPhaseTwo(); return CommitPhaseTwo();
} }
} }
...@@ -331,7 +331,7 @@ leveldb::Status IndexedDBTransaction::Commit() { ...@@ -331,7 +331,7 @@ leveldb::Status IndexedDBTransaction::Commit() {
// to write. // to write.
s = transaction_->CommitPhaseOne(base::BindOnce( s = transaction_->CommitPhaseOne(base::BindOnce(
[](base::WeakPtr<IndexedDBTransaction> transaction, [](base::WeakPtr<IndexedDBTransaction> transaction,
IndexedDBBackingStore::BlobWriteResult result) { BlobWriteResult result) {
if (!transaction) if (!transaction)
return leveldb::Status::OK(); return leveldb::Status::OK();
return transaction->BlobWriteComplete(result); return transaction->BlobWriteComplete(result);
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "base/timer/timer.h" #include "base/timer/timer.h"
#include "components/services/storage/indexed_db/scopes/scope_lock.h" #include "components/services/storage/indexed_db/scopes/scope_lock.h"
#include "content/browser/indexed_db/indexed_db_backing_store.h" #include "content/browser/indexed_db/indexed_db_backing_store.h"
#include "content/browser/indexed_db/indexed_db_blob_storage.h"
#include "content/browser/indexed_db/indexed_db_connection.h" #include "content/browser/indexed_db/indexed_db_connection.h"
#include "content/browser/indexed_db/indexed_db_database_error.h" #include "content/browser/indexed_db/indexed_db_database_error.h"
#include "content/browser/indexed_db/indexed_db_observer.h" #include "content/browser/indexed_db/indexed_db_observer.h"
...@@ -202,8 +203,7 @@ class CONTENT_EXPORT IndexedDBTransaction { ...@@ -202,8 +203,7 @@ class CONTENT_EXPORT IndexedDBTransaction {
bool IsTaskQueueEmpty() const; bool IsTaskQueueEmpty() const;
bool HasPendingTasks() const; bool HasPendingTasks() const;
leveldb::Status BlobWriteComplete( leveldb::Status BlobWriteComplete(BlobWriteResult result);
IndexedDBBackingStore::BlobWriteResult result);
void CloseOpenCursorBindings(); void CloseOpenCursorBindings();
void CloseOpenCursors(); void CloseOpenCursors();
leveldb::Status CommitPhaseTwo(); leveldb::Status CommitPhaseTwo();
......
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