зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1617170 - Remove some local helper classes. r=dom-workers-and-storage-reviewers,janv
Differential Revision: https://phabricator.services.mozilla.com/D64343 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
f28bafa279
Коммит
d8537d4388
|
@ -695,85 +695,72 @@ void IDBDatabase::UnregisterTransaction(IDBTransaction* aTransaction) {
|
||||||
void IDBDatabase::AbortTransactions(bool aShouldWarn) {
|
void IDBDatabase::AbortTransactions(bool aShouldWarn) {
|
||||||
AssertIsOnOwningThread();
|
AssertIsOnOwningThread();
|
||||||
|
|
||||||
class MOZ_STACK_CLASS Helper final {
|
constexpr size_t StackExceptionLimit = 20;
|
||||||
typedef AutoTArray<RefPtr<IDBTransaction>, 20> StrongTransactionArray;
|
using StrongTransactionArray =
|
||||||
typedef AutoTArray<IDBTransaction*, 20> WeakTransactionArray;
|
AutoTArray<RefPtr<IDBTransaction>, StackExceptionLimit>;
|
||||||
|
using WeakTransactionArray = AutoTArray<IDBTransaction*, StackExceptionLimit>;
|
||||||
|
|
||||||
public:
|
if (!mTransactions.Count()) {
|
||||||
static void AbortTransactions(IDBDatabase* aDatabase,
|
// Return early as an optimization, the remainder is a no-op in this
|
||||||
const bool aShouldWarn) {
|
// case.
|
||||||
MOZ_ASSERT(aDatabase);
|
return;
|
||||||
aDatabase->AssertIsOnOwningThread();
|
}
|
||||||
|
|
||||||
nsTHashtable<nsPtrHashKey<IDBTransaction>>& transactionTable =
|
StrongTransactionArray transactionsToAbort;
|
||||||
aDatabase->mTransactions;
|
transactionsToAbort.SetCapacity(mTransactions.Count());
|
||||||
|
|
||||||
if (!transactionTable.Count()) {
|
for (auto iter = mTransactions.ConstIter(); !iter.Done(); iter.Next()) {
|
||||||
// Return early as an optimization, the remainder is a no-op in this
|
IDBTransaction* transaction = iter.Get()->GetKey();
|
||||||
// case.
|
MOZ_ASSERT(transaction);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
StrongTransactionArray transactionsToAbort;
|
transaction->AssertIsOnOwningThread();
|
||||||
transactionsToAbort.SetCapacity(transactionTable.Count());
|
|
||||||
|
|
||||||
for (auto iter = transactionTable.Iter(); !iter.Done(); iter.Next()) {
|
// Transactions that are already done can simply be ignored. Otherwise
|
||||||
IDBTransaction* transaction = iter.Get()->GetKey();
|
// there is a race here and it's possible that the transaction has not
|
||||||
MOZ_ASSERT(transaction);
|
// been successfully committed yet so we will warn the user.
|
||||||
|
if (!transaction->IsFinished()) {
|
||||||
transaction->AssertIsOnOwningThread();
|
transactionsToAbort.AppendElement(transaction);
|
||||||
|
|
||||||
// Transactions that are already done can simply be ignored. Otherwise
|
|
||||||
// there is a race here and it's possible that the transaction has not
|
|
||||||
// been successfully committed yet so we will warn the user.
|
|
||||||
if (!transaction->IsFinished()) {
|
|
||||||
transactionsToAbort.AppendElement(transaction);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
MOZ_ASSERT(transactionsToAbort.Length() <= transactionTable.Count());
|
|
||||||
|
|
||||||
if (transactionsToAbort.IsEmpty()) {
|
|
||||||
// Return early as an optimization, the remainder is a no-op in this
|
|
||||||
// case.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// We want to abort transactions as soon as possible so we iterate the
|
|
||||||
// transactions once and abort them all first, collecting the transactions
|
|
||||||
// that need to have a warning issued along the way. Those that need a
|
|
||||||
// warning will be a subset of those that are aborted, so we don't need
|
|
||||||
// additional strong references here.
|
|
||||||
WeakTransactionArray transactionsThatNeedWarning;
|
|
||||||
|
|
||||||
for (const auto& transaction : transactionsToAbort) {
|
|
||||||
MOZ_ASSERT(transaction);
|
|
||||||
MOZ_ASSERT(!transaction->IsFinished());
|
|
||||||
|
|
||||||
// We warn for any transactions that could have written data, but
|
|
||||||
// ignore read-only transactions.
|
|
||||||
if (aShouldWarn && transaction->IsWriteAllowed()) {
|
|
||||||
transactionsThatNeedWarning.AppendElement(transaction);
|
|
||||||
}
|
|
||||||
|
|
||||||
transaction->Abort(NS_ERROR_DOM_INDEXEDDB_ABORT_ERR);
|
|
||||||
}
|
|
||||||
|
|
||||||
static const char kWarningMessage[] =
|
|
||||||
"IndexedDBTransactionAbortNavigation";
|
|
||||||
|
|
||||||
for (IDBTransaction* transaction : transactionsThatNeedWarning) {
|
|
||||||
MOZ_ASSERT(transaction);
|
|
||||||
|
|
||||||
nsString filename;
|
|
||||||
uint32_t lineNo, column;
|
|
||||||
transaction->GetCallerLocation(filename, &lineNo, &column);
|
|
||||||
|
|
||||||
aDatabase->LogWarning(kWarningMessage, filename, lineNo, column);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
MOZ_ASSERT(transactionsToAbort.Length() <= mTransactions.Count());
|
||||||
|
|
||||||
Helper::AbortTransactions(this, aShouldWarn);
|
if (transactionsToAbort.IsEmpty()) {
|
||||||
|
// Return early as an optimization, the remainder is a no-op in this
|
||||||
|
// case.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// We want to abort transactions as soon as possible so we iterate the
|
||||||
|
// transactions once and abort them all first, collecting the transactions
|
||||||
|
// that need to have a warning issued along the way. Those that need a
|
||||||
|
// warning will be a subset of those that are aborted, so we don't need
|
||||||
|
// additional strong references here.
|
||||||
|
WeakTransactionArray transactionsThatNeedWarning;
|
||||||
|
|
||||||
|
for (const auto& transaction : transactionsToAbort) {
|
||||||
|
MOZ_ASSERT(transaction);
|
||||||
|
MOZ_ASSERT(!transaction->IsFinished());
|
||||||
|
|
||||||
|
// We warn for any transactions that could have written data, but
|
||||||
|
// ignore read-only transactions.
|
||||||
|
if (aShouldWarn && transaction->IsWriteAllowed()) {
|
||||||
|
transactionsThatNeedWarning.AppendElement(transaction);
|
||||||
|
}
|
||||||
|
|
||||||
|
transaction->Abort(NS_ERROR_DOM_INDEXEDDB_ABORT_ERR);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char kWarningMessage[] = "IndexedDBTransactionAbortNavigation";
|
||||||
|
|
||||||
|
for (IDBTransaction* transaction : transactionsThatNeedWarning) {
|
||||||
|
MOZ_ASSERT(transaction);
|
||||||
|
|
||||||
|
nsString filename;
|
||||||
|
uint32_t lineNo, column;
|
||||||
|
transaction->GetCallerLocation(filename, &lineNo, &column);
|
||||||
|
|
||||||
|
LogWarning(kWarningMessage, filename, lineNo, column);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PBackgroundIDBDatabaseFileChild* IDBDatabase::GetOrCreateFileActorForBlob(
|
PBackgroundIDBDatabaseFileChild* IDBDatabase::GetOrCreateFileActorForBlob(
|
||||||
|
|
|
@ -112,42 +112,34 @@ void IDBMutableFile::UnregisterFileHandle(IDBFileHandle* aFileHandle) {
|
||||||
void IDBMutableFile::AbortFileHandles() {
|
void IDBMutableFile::AbortFileHandles() {
|
||||||
AssertIsOnOwningThread();
|
AssertIsOnOwningThread();
|
||||||
|
|
||||||
class MOZ_STACK_CLASS Helper final {
|
if (!mFileHandles.Count()) {
|
||||||
public:
|
return;
|
||||||
static void AbortFileHandles(
|
}
|
||||||
const nsTHashtable<nsPtrHashKey<IDBFileHandle>>& aTable) {
|
|
||||||
if (!aTable.Count()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsTArray<RefPtr<IDBFileHandle>> fileHandlesToAbort;
|
nsTArray<RefPtr<IDBFileHandle>> fileHandlesToAbort;
|
||||||
fileHandlesToAbort.SetCapacity(aTable.Count());
|
fileHandlesToAbort.SetCapacity(mFileHandles.Count());
|
||||||
|
|
||||||
for (auto iter = aTable.ConstIter(); !iter.Done(); iter.Next()) {
|
for (auto iter = mFileHandles.ConstIter(); !iter.Done(); iter.Next()) {
|
||||||
IDBFileHandle* const fileHandle = iter.Get()->GetKey();
|
IDBFileHandle* const fileHandle = iter.Get()->GetKey();
|
||||||
MOZ_ASSERT(fileHandle);
|
MOZ_ASSERT(fileHandle);
|
||||||
|
|
||||||
fileHandle->AssertIsOnOwningThread();
|
fileHandle->AssertIsOnOwningThread();
|
||||||
|
|
||||||
if (!fileHandle->IsDone()) {
|
if (!fileHandle->IsDone()) {
|
||||||
fileHandlesToAbort.AppendElement(iter.Get()->GetKey());
|
fileHandlesToAbort.AppendElement(iter.Get()->GetKey());
|
||||||
}
|
|
||||||
}
|
|
||||||
MOZ_ASSERT(fileHandlesToAbort.Length() <= aTable.Count());
|
|
||||||
|
|
||||||
if (fileHandlesToAbort.IsEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const auto& fileHandle : fileHandlesToAbort) {
|
|
||||||
MOZ_ASSERT(fileHandle);
|
|
||||||
|
|
||||||
fileHandle->Abort();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
MOZ_ASSERT(fileHandlesToAbort.Length() <= mFileHandles.Count());
|
||||||
|
|
||||||
Helper::AbortFileHandles(mFileHandles);
|
if (fileHandlesToAbort.IsEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const auto& fileHandle : fileHandlesToAbort) {
|
||||||
|
MOZ_ASSERT(fileHandle);
|
||||||
|
|
||||||
|
fileHandle->Abort();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IDBDatabase* IDBMutableFile::Database() const {
|
IDBDatabase* IDBMutableFile::Database() const {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче