Commit ce25071d authored by Wez's avatar Wez Committed by Commit Bot

Add thread checks to IndexedDBBackingStore classes and fix tests.

Bug: 838386
Change-Id: I614e823499c927704ed95d76103bf1e1c2c216f0
Reviewed-on: https://chromium-review.googlesource.com/1036445
Commit-Queue: Wez <wez@chromium.org>
Reviewed-by: default avatarDaniel Murphy <dmurph@chromium.org>
Cr-Commit-Position: refs/heads/master@{#558144}
parent 36589a21
...@@ -585,9 +585,14 @@ IndexedDBBackingStore::IndexedDBBackingStore( ...@@ -585,9 +585,14 @@ IndexedDBBackingStore::IndexedDBBackingStore(
db_(std::move(db)), db_(std::move(db)),
comparator_(std::move(comparator)), comparator_(std::move(comparator)),
active_blob_registry_(this), active_blob_registry_(this),
committing_transaction_count_(0) {} committing_transaction_count_(0) {
// TODO(838386): Make IndexedDBBackingStore an interface, so that we can
// check that |task_runner| is non-null here without breaking tests.
DCHECK(!task_runner_ || task_runner_->RunsTasksInCurrentSequence());
}
IndexedDBBackingStore::~IndexedDBBackingStore() { IndexedDBBackingStore::~IndexedDBBackingStore() {
DCHECK(!task_runner_ || task_runner_->RunsTasksInCurrentSequence());
if (!blob_path_.empty() && !child_process_ids_granted_.empty()) { if (!blob_path_.empty() && !child_process_ids_granted_.empty()) {
ChildProcessSecurityPolicyImpl* policy = ChildProcessSecurityPolicyImpl* policy =
ChildProcessSecurityPolicyImpl::GetInstance(); ChildProcessSecurityPolicyImpl::GetInstance();
...@@ -643,6 +648,8 @@ Status IndexedDBBackingStore::DestroyBackingStore(const FilePath& path_base, ...@@ -643,6 +648,8 @@ Status IndexedDBBackingStore::DestroyBackingStore(const FilePath& path_base,
Status IndexedDBBackingStore::AnyDatabaseContainsBlobs( Status IndexedDBBackingStore::AnyDatabaseContainsBlobs(
LevelDBTransaction* transaction, LevelDBTransaction* transaction,
bool* blobs_exist) { bool* blobs_exist) {
DCHECK(task_runner_->RunsTasksInCurrentSequence());
Status status = leveldb::Status::OK(); Status status = leveldb::Status::OK();
std::vector<base::string16> names; std::vector<base::string16> names;
IndexedDBMetadataCoding metadata_coding; IndexedDBMetadataCoding metadata_coding;
...@@ -688,6 +695,8 @@ Status IndexedDBBackingStore::AnyDatabaseContainsBlobs( ...@@ -688,6 +695,8 @@ Status IndexedDBBackingStore::AnyDatabaseContainsBlobs(
} }
WARN_UNUSED_RESULT Status IndexedDBBackingStore::SetUpMetadata() { WARN_UNUSED_RESULT Status IndexedDBBackingStore::SetUpMetadata() {
DCHECK(task_runner_->RunsTasksInCurrentSequence());
const IndexedDBDataFormatVersion latest_known_data_version = const IndexedDBDataFormatVersion latest_known_data_version =
IndexedDBDataFormatVersion::GetCurrent(); IndexedDBDataFormatVersion::GetCurrent();
const std::string schema_version_key = SchemaVersionKey::Encode(); const std::string schema_version_key = SchemaVersionKey::Encode();
...@@ -830,6 +839,8 @@ WARN_UNUSED_RESULT Status IndexedDBBackingStore::SetUpMetadata() { ...@@ -830,6 +839,8 @@ WARN_UNUSED_RESULT Status IndexedDBBackingStore::SetUpMetadata() {
leveldb::Status IndexedDBBackingStore::GetCompleteMetadata( leveldb::Status IndexedDBBackingStore::GetCompleteMetadata(
std::vector<IndexedDBDatabaseMetadata>* output) { std::vector<IndexedDBDatabaseMetadata>* output) {
DCHECK(task_runner_->RunsTasksInCurrentSequence());
IndexedDBMetadataCoding metadata_coding; IndexedDBMetadataCoding metadata_coding;
leveldb::Status status = leveldb::Status::OK(); leveldb::Status status = leveldb::Status::OK();
std::vector<base::string16> names; std::vector<base::string16> names;
...@@ -855,6 +866,7 @@ leveldb::Status IndexedDBBackingStore::GetCompleteMetadata( ...@@ -855,6 +866,7 @@ leveldb::Status IndexedDBBackingStore::GetCompleteMetadata(
return status; return status;
} }
// static
bool IndexedDBBackingStore::ReadCorruptionInfo(const FilePath& path_base, bool IndexedDBBackingStore::ReadCorruptionInfo(const FilePath& path_base,
const Origin& origin, const Origin& origin,
std::string* message) { std::string* message) {
...@@ -893,6 +905,7 @@ bool IndexedDBBackingStore::ReadCorruptionInfo(const FilePath& path_base, ...@@ -893,6 +905,7 @@ bool IndexedDBBackingStore::ReadCorruptionInfo(const FilePath& path_base,
return success; return success;
} }
// static
bool IndexedDBBackingStore::RecordCorruptionInfo(const FilePath& path_base, bool IndexedDBBackingStore::RecordCorruptionInfo(const FilePath& path_base,
const Origin& origin, const Origin& origin,
const std::string& message) { const std::string& message) {
...@@ -1132,6 +1145,8 @@ scoped_refptr<IndexedDBBackingStore> IndexedDBBackingStore::Create( ...@@ -1132,6 +1145,8 @@ scoped_refptr<IndexedDBBackingStore> IndexedDBBackingStore::Create(
} }
void IndexedDBBackingStore::GrantChildProcessPermissions(int child_process_id) { void IndexedDBBackingStore::GrantChildProcessPermissions(int child_process_id) {
DCHECK(task_runner_->RunsTasksInCurrentSequence());
if (!child_process_ids_granted_.count(child_process_id)) { if (!child_process_ids_granted_.count(child_process_id)) {
child_process_ids_granted_.insert(child_process_id); child_process_ids_granted_.insert(child_process_id);
ChildProcessSecurityPolicyImpl::GetInstance()->GrantReadFile( ChildProcessSecurityPolicyImpl::GetInstance()->GrantReadFile(
...@@ -1140,6 +1155,8 @@ void IndexedDBBackingStore::GrantChildProcessPermissions(int child_process_id) { ...@@ -1140,6 +1155,8 @@ void IndexedDBBackingStore::GrantChildProcessPermissions(int child_process_id) {
} }
Status IndexedDBBackingStore::DeleteDatabase(const base::string16& name) { Status IndexedDBBackingStore::DeleteDatabase(const base::string16& name) {
DCHECK(task_runner_->RunsTasksInCurrentSequence());
IDB_TRACE("IndexedDBBackingStore::DeleteDatabase"); IDB_TRACE("IndexedDBBackingStore::DeleteDatabase");
std::unique_ptr<LevelDBDirectTransaction> transaction = std::unique_ptr<LevelDBDirectTransaction> transaction =
LevelDBDirectTransaction::Create(db_.get()); LevelDBDirectTransaction::Create(db_.get());
...@@ -1205,7 +1222,10 @@ Status IndexedDBBackingStore::DeleteDatabase(const base::string16& name) { ...@@ -1205,7 +1222,10 @@ Status IndexedDBBackingStore::DeleteDatabase(const base::string16& name) {
return s; return s;
} }
void IndexedDBBackingStore::Compact() { db_->CompactAll(); } void IndexedDBBackingStore::Compact() {
DCHECK(task_runner_->RunsTasksInCurrentSequence());
db_->CompactAll();
}
Status IndexedDBBackingStore::GetRecord( Status IndexedDBBackingStore::GetRecord(
IndexedDBBackingStore::Transaction* transaction, IndexedDBBackingStore::Transaction* transaction,
...@@ -1213,6 +1233,8 @@ Status IndexedDBBackingStore::GetRecord( ...@@ -1213,6 +1233,8 @@ Status IndexedDBBackingStore::GetRecord(
int64_t object_store_id, int64_t object_store_id,
const IndexedDBKey& key, const IndexedDBKey& key,
IndexedDBValue* record) { IndexedDBValue* record) {
DCHECK(task_runner_->RunsTasksInCurrentSequence());
IDB_TRACE("IndexedDBBackingStore::GetRecord"); IDB_TRACE("IndexedDBBackingStore::GetRecord");
if (!KeyPrefix::ValidIds(database_id, object_store_id)) if (!KeyPrefix::ValidIds(database_id, object_store_id))
return InvalidDBKeyStatus(); return InvalidDBKeyStatus();
...@@ -1249,6 +1271,8 @@ Status IndexedDBBackingStore::GetRecord( ...@@ -1249,6 +1271,8 @@ Status IndexedDBBackingStore::GetRecord(
} }
int64_t IndexedDBBackingStore::GetInMemoryBlobSize() const { int64_t IndexedDBBackingStore::GetInMemoryBlobSize() const {
DCHECK(task_runner_->RunsTasksInCurrentSequence());
int64_t total_size = 0; int64_t total_size = 0;
for (const auto& kvp : incognito_blob_map_) { for (const auto& kvp : incognito_blob_map_) {
for (const IndexedDBBlobInfo& blob_info : kvp.second->blob_info()) { for (const IndexedDBBlobInfo& blob_info : kvp.second->blob_info()) {
...@@ -1268,6 +1292,8 @@ Status IndexedDBBackingStore::PutRecord( ...@@ -1268,6 +1292,8 @@ Status IndexedDBBackingStore::PutRecord(
IndexedDBValue* value, IndexedDBValue* value,
std::vector<std::unique_ptr<storage::BlobDataHandle>>* handles, std::vector<std::unique_ptr<storage::BlobDataHandle>>* handles,
RecordIdentifier* record_identifier) { RecordIdentifier* record_identifier) {
DCHECK(task_runner_->RunsTasksInCurrentSequence());
IDB_TRACE("IndexedDBBackingStore::PutRecord"); IDB_TRACE("IndexedDBBackingStore::PutRecord");
if (!KeyPrefix::ValidIds(database_id, object_store_id)) if (!KeyPrefix::ValidIds(database_id, object_store_id))
return InvalidDBKeyStatus(); return InvalidDBKeyStatus();
...@@ -1313,6 +1339,8 @@ Status IndexedDBBackingStore::ClearObjectStore( ...@@ -1313,6 +1339,8 @@ Status IndexedDBBackingStore::ClearObjectStore(
IndexedDBBackingStore::Transaction* transaction, IndexedDBBackingStore::Transaction* transaction,
int64_t database_id, int64_t database_id,
int64_t object_store_id) { int64_t object_store_id) {
DCHECK(task_runner_->RunsTasksInCurrentSequence());
IDB_TRACE("IndexedDBBackingStore::ClearObjectStore"); IDB_TRACE("IndexedDBBackingStore::ClearObjectStore");
if (!KeyPrefix::ValidIds(database_id, object_store_id)) if (!KeyPrefix::ValidIds(database_id, object_store_id))
return InvalidDBKeyStatus(); return InvalidDBKeyStatus();
...@@ -1333,6 +1361,8 @@ Status IndexedDBBackingStore::DeleteRecord( ...@@ -1333,6 +1361,8 @@ Status IndexedDBBackingStore::DeleteRecord(
int64_t database_id, int64_t database_id,
int64_t object_store_id, int64_t object_store_id,
const RecordIdentifier& record_identifier) { const RecordIdentifier& record_identifier) {
DCHECK(task_runner_->RunsTasksInCurrentSequence());
IDB_TRACE("IndexedDBBackingStore::DeleteRecord"); IDB_TRACE("IndexedDBBackingStore::DeleteRecord");
if (!KeyPrefix::ValidIds(database_id, object_store_id)) if (!KeyPrefix::ValidIds(database_id, object_store_id))
return InvalidDBKeyStatus(); return InvalidDBKeyStatus();
...@@ -1357,6 +1387,8 @@ Status IndexedDBBackingStore::DeleteRange( ...@@ -1357,6 +1387,8 @@ Status IndexedDBBackingStore::DeleteRange(
int64_t database_id, int64_t database_id,
int64_t object_store_id, int64_t object_store_id,
const IndexedDBKeyRange& key_range) { const IndexedDBKeyRange& key_range) {
DCHECK(task_runner_->RunsTasksInCurrentSequence());
Status s; Status s;
std::unique_ptr<IndexedDBBackingStore::Cursor> start_cursor = std::unique_ptr<IndexedDBBackingStore::Cursor> start_cursor =
OpenObjectStoreCursor(transaction, database_id, object_store_id, OpenObjectStoreCursor(transaction, database_id, object_store_id,
......
...@@ -591,6 +591,9 @@ TEST_F(IndexedDBBackingStoreTestWithBlobs, PutGetConsistencyWithBlobs) { ...@@ -591,6 +591,9 @@ TEST_F(IndexedDBBackingStoreTestWithBlobs, PutGetConsistencyWithBlobs) {
// Finish up transaction 3, verifying blob deletes. // Finish up transaction 3, verifying blob deletes.
EXPECT_TRUE(state->transaction3->CommitPhaseTwo().ok()); EXPECT_TRUE(state->transaction3->CommitPhaseTwo().ok());
EXPECT_TRUE(test->CheckBlobRemovals()); EXPECT_TRUE(test->CheckBlobRemovals());
// Clean up Transactions, etc on the IDB thread.
*state = TestState();
}, },
base::Unretained(this), base::Unretained(&state))); base::Unretained(this), base::Unretained(&state)));
RunAllTasksUntilIdle(); RunAllTasksUntilIdle();
...@@ -716,6 +719,9 @@ TEST_F(IndexedDBBackingStoreTest, DeleteRange) { ...@@ -716,6 +719,9 @@ TEST_F(IndexedDBBackingStoreTest, DeleteRange) {
backing_store->removals()[0]); backing_store->removals()[0]);
EXPECT_EQ(backing_store->writes()[2].key(), EXPECT_EQ(backing_store->writes()[2].key(),
backing_store->removals()[1]); backing_store->removals()[1]);
// Clean up Transactions, etc on the IDB thread.
*state = TestState();
}, },
base::Unretained(backing_store()), base::Unretained(&state))); base::Unretained(backing_store()), base::Unretained(&state)));
RunAllTasksUntilIdle(); RunAllTasksUntilIdle();
...@@ -837,6 +843,9 @@ TEST_F(IndexedDBBackingStoreTest, DeleteRangeEmptyRange) { ...@@ -837,6 +843,9 @@ TEST_F(IndexedDBBackingStoreTest, DeleteRangeEmptyRange) {
// Verify blob removals. // Verify blob removals.
EXPECT_EQ(0UL, backing_store->removals().size()); EXPECT_EQ(0UL, backing_store->removals().size());
// Clean up Transactions, etc on the IDB thread.
*state = TestState();
}, },
base::Unretained(backing_store()), base::Unretained(&state))); base::Unretained(backing_store()), base::Unretained(&state)));
RunAllTasksUntilIdle(); RunAllTasksUntilIdle();
...@@ -919,6 +928,9 @@ TEST_F(IndexedDBBackingStoreTestWithBlobs, BlobJournalInterleavedTransactions) { ...@@ -919,6 +928,9 @@ TEST_F(IndexedDBBackingStoreTestWithBlobs, BlobJournalInterleavedTransactions) {
EXPECT_TRUE(state->transaction2->CommitPhaseTwo().ok()); EXPECT_TRUE(state->transaction2->CommitPhaseTwo().ok());
EXPECT_EQ(0U, test->backing_store()->removals().size()); EXPECT_EQ(0U, test->backing_store()->removals().size());
// Clean up Transactions, etc on the IDB thread.
*state = TestState();
}, },
base::Unretained(this), base::Unretained(&state))); base::Unretained(this), base::Unretained(&state)));
RunAllTasksUntilIdle(); RunAllTasksUntilIdle();
...@@ -1022,7 +1034,7 @@ TEST_F(IndexedDBBackingStoreTestWithBlobs, LiveBlobJournal) { ...@@ -1022,7 +1034,7 @@ TEST_F(IndexedDBBackingStoreTestWithBlobs, LiveBlobJournal) {
idb_context_->TaskRunner()->PostTask( idb_context_->TaskRunner()->PostTask(
FROM_HERE, FROM_HERE,
base::BindOnce( base::BindOnce(
[](IndexedDBBackingStoreTestWithBlobs* test) { [](IndexedDBBackingStoreTestWithBlobs* test, TestState* state) {
EXPECT_TRUE(test->backing_store()->IsBlobCleanupPending()); EXPECT_TRUE(test->backing_store()->IsBlobCleanupPending());
#if DCHECK_IS_ON() #if DCHECK_IS_ON()
EXPECT_EQ(3, EXPECT_EQ(3,
...@@ -1040,8 +1052,11 @@ TEST_F(IndexedDBBackingStoreTestWithBlobs, LiveBlobJournal) { ...@@ -1040,8 +1052,11 @@ TEST_F(IndexedDBBackingStoreTestWithBlobs, LiveBlobJournal) {
test->backing_store()->NumBlobFilesDeletedForTesting()); test->backing_store()->NumBlobFilesDeletedForTesting());
#endif #endif
EXPECT_FALSE(test->backing_store()->IsBlobCleanupPending()); EXPECT_FALSE(test->backing_store()->IsBlobCleanupPending());
// Clean up Transactions, etc on the IDB thread.
*state = TestState();
}, },
base::Unretained(this))); base::Unretained(this), base::Unretained(&state)));
RunAllTasksUntilIdle(); RunAllTasksUntilIdle();
} }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "content/browser/indexed_db/indexed_db_fake_backing_store.h" #include "content/browser/indexed_db/indexed_db_fake_backing_store.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/threading/sequenced_task_runner_handle.h"
#include "net/url_request/url_request_context_getter.h" #include "net/url_request/url_request_context_getter.h"
namespace content { namespace content {
...@@ -16,7 +17,7 @@ IndexedDBFakeBackingStore::IndexedDBFakeBackingStore() ...@@ -16,7 +17,7 @@ IndexedDBFakeBackingStore::IndexedDBFakeBackingStore()
scoped_refptr<net::URLRequestContextGetter>(), scoped_refptr<net::URLRequestContextGetter>(),
std::unique_ptr<LevelDBDatabase>(), std::unique_ptr<LevelDBDatabase>(),
std::unique_ptr<LevelDBComparator>(), std::unique_ptr<LevelDBComparator>(),
nullptr /* task_runner */) {} base::SequencedTaskRunnerHandle::Get().get()) {}
IndexedDBFakeBackingStore::IndexedDBFakeBackingStore( IndexedDBFakeBackingStore::IndexedDBFakeBackingStore(
IndexedDBFactory* factory, IndexedDBFactory* factory,
base::SequencedTaskRunner* task_runner) base::SequencedTaskRunner* task_runner)
......
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