diff --git a/dom/quota/ActorsParent.cpp b/dom/quota/ActorsParent.cpp index e63c713dfb00..d73b9fe9ec06 100644 --- a/dom/quota/ActorsParent.cpp +++ b/dom/quota/ActorsParent.cpp @@ -2899,7 +2899,7 @@ DirectoryLockImpl::~DirectoryLockImpl() { mBlocking.Clear(); if (mRegistered) { - mQuotaManager->UnregisterDirectoryLock(this); + mQuotaManager->UnregisterDirectoryLock(*this); } MOZ_ASSERT(!mRegistered); @@ -2962,7 +2962,7 @@ void DirectoryLockImpl::NotifyOpenListener() { mOpenListener.destroy(); - mQuotaManager->RemovePendingDirectoryLock(this); + mQuotaManager->RemovePendingDirectoryLock(*this); } already_AddRefed DirectoryLockImpl::Specialize( @@ -3007,7 +3007,7 @@ already_AddRefed DirectoryLockImpl::Specialize( } } - mQuotaManager->RegisterDirectoryLock(lock); + mQuotaManager->RegisterDirectoryLock(*lock); if (mInvalidated) { lock->Invalidate(); @@ -3686,8 +3686,9 @@ bool QuotaManager::IsDotFile(const nsAString& aFileName) { auto QuotaManager::CreateDirectoryLock( const Nullable& aPersistenceType, const nsACString& aGroup, const OriginScope& aOriginScope, const Nullable& aClientType, - bool aExclusive, bool aInternal, OpenDirectoryListener* aOpenListener, - bool& aBlockedOut) -> already_AddRefed { + bool aExclusive, bool aInternal, + RefPtr aOpenListener, bool& aBlockedOut) + -> already_AddRefed { AssertIsOnOwningThread(); MOZ_ASSERT_IF(aOriginScope.IsOrigin(), !aOriginScope.GetOrigin().IsEmpty()); MOZ_ASSERT_IF(!aInternal, !aPersistenceType.IsNull()); @@ -3701,7 +3702,8 @@ auto QuotaManager::CreateDirectoryLock( RefPtr lock = new DirectoryLockImpl( WrapNotNullUnchecked(this), GenerateDirectoryLockId(), aPersistenceType, - aGroup, aOriginScope, aClientType, aExclusive, aInternal, aOpenListener); + aGroup, aOriginScope, aClientType, aExclusive, aInternal, + std::move(aOpenListener)); mPendingDirectoryLocks.AppendElement(lock); @@ -3716,7 +3718,7 @@ auto QuotaManager::CreateDirectoryLock( } } - RegisterDirectoryLock(lock); + RegisterDirectoryLock(*lock); // Otherwise, notify the open listener immediately. if (!blocked) { @@ -3748,83 +3750,80 @@ auto QuotaManager::CreateDirectoryLockForEviction( } #endif - RegisterDirectoryLock(lock); + RegisterDirectoryLock(*lock); return lock.forget(); } -void QuotaManager::RegisterDirectoryLock(DirectoryLockImpl* aLock) { +void QuotaManager::RegisterDirectoryLock(DirectoryLockImpl& aLock) { AssertIsOnOwningThread(); - MOZ_ASSERT(aLock); - mDirectoryLocks.AppendElement(aLock); + mDirectoryLocks.AppendElement(&aLock); - if (aLock->ShouldUpdateLockIdTable()) { + if (aLock.ShouldUpdateLockIdTable()) { MutexAutoLock lock(mQuotaMutex); - MOZ_DIAGNOSTIC_ASSERT(!mDirectoryLockIdTable.Get(aLock->Id())); - mDirectoryLockIdTable.Put(aLock->Id(), aLock); + MOZ_DIAGNOSTIC_ASSERT(!mDirectoryLockIdTable.Get(aLock.Id())); + mDirectoryLockIdTable.Put(aLock.Id(), &aLock); } - if (aLock->ShouldUpdateLockTable()) { + if (aLock.ShouldUpdateLockTable()) { DirectoryLockTable& directoryLockTable = - GetDirectoryLockTable(aLock->GetPersistenceType()); + GetDirectoryLockTable(aLock.GetPersistenceType()); nsTArray* array; - if (!directoryLockTable.Get(aLock->Origin(), &array)) { + if (!directoryLockTable.Get(aLock.Origin(), &array)) { array = new nsTArray(); - directoryLockTable.Put(aLock->Origin(), array); + directoryLockTable.Put(aLock.Origin(), array); if (!IsShuttingDown()) { - UpdateOriginAccessTime(aLock->GetPersistenceType(), aLock->Group(), - aLock->Origin()); + UpdateOriginAccessTime(aLock.GetPersistenceType(), aLock.Group(), + aLock.Origin()); } } - array->AppendElement(aLock); + array->AppendElement(&aLock); } - aLock->SetRegistered(true); + aLock.SetRegistered(true); } -void QuotaManager::UnregisterDirectoryLock(DirectoryLockImpl* aLock) { +void QuotaManager::UnregisterDirectoryLock(DirectoryLockImpl& aLock) { AssertIsOnOwningThread(); - MOZ_ASSERT(aLock); - MOZ_ALWAYS_TRUE(mDirectoryLocks.RemoveElement(aLock)); + MOZ_ALWAYS_TRUE(mDirectoryLocks.RemoveElement(&aLock)); - if (aLock->ShouldUpdateLockIdTable()) { + if (aLock.ShouldUpdateLockIdTable()) { MutexAutoLock lock(mQuotaMutex); - MOZ_DIAGNOSTIC_ASSERT(mDirectoryLockIdTable.Get(aLock->Id())); - mDirectoryLockIdTable.Remove(aLock->Id()); + MOZ_DIAGNOSTIC_ASSERT(mDirectoryLockIdTable.Get(aLock.Id())); + mDirectoryLockIdTable.Remove(aLock.Id()); } - if (aLock->ShouldUpdateLockTable()) { + if (aLock.ShouldUpdateLockTable()) { DirectoryLockTable& directoryLockTable = - GetDirectoryLockTable(aLock->GetPersistenceType()); + GetDirectoryLockTable(aLock.GetPersistenceType()); nsTArray* array; - MOZ_ALWAYS_TRUE(directoryLockTable.Get(aLock->Origin(), &array)); + MOZ_ALWAYS_TRUE(directoryLockTable.Get(aLock.Origin(), &array)); - MOZ_ALWAYS_TRUE(array->RemoveElement(aLock)); + MOZ_ALWAYS_TRUE(array->RemoveElement(&aLock)); if (array->IsEmpty()) { - directoryLockTable.Remove(aLock->Origin()); + directoryLockTable.Remove(aLock.Origin()); if (!IsShuttingDown()) { - UpdateOriginAccessTime(aLock->GetPersistenceType(), aLock->Group(), - aLock->Origin()); + UpdateOriginAccessTime(aLock.GetPersistenceType(), aLock.Group(), + aLock.Origin()); } } } - aLock->SetRegistered(false); + aLock.SetRegistered(false); } -void QuotaManager::RemovePendingDirectoryLock(DirectoryLockImpl* aLock) { +void QuotaManager::RemovePendingDirectoryLock(DirectoryLockImpl& aLock) { AssertIsOnOwningThread(); - MOZ_ASSERT(aLock); - MOZ_ALWAYS_TRUE(mPendingDirectoryLocks.RemoveElement(aLock)); + MOZ_ALWAYS_TRUE(mPendingDirectoryLocks.RemoveElement(&aLock)); } uint64_t QuotaManager::CollectOriginsForEviction( @@ -6769,7 +6768,7 @@ nsresult QuotaManager::EnsureStorageIsInitialized() { already_AddRefed QuotaManager::OpenDirectory( PersistenceType aPersistenceType, const nsACString& aGroup, const nsACString& aOrigin, Client::Type aClientType, bool aExclusive, - OpenDirectoryListener* aOpenListener) { + RefPtr aOpenListener) { AssertIsOnOwningThread(); bool blocked; diff --git a/dom/quota/QuotaManager.h b/dom/quota/QuotaManager.h index d0c4c2416e62..c9ebdae27d1a 100644 --- a/dom/quota/QuotaManager.h +++ b/dom/quota/QuotaManager.h @@ -297,7 +297,7 @@ class QuotaManager final : public BackgroundThreadObject { already_AddRefed OpenDirectory( PersistenceType aPersistenceType, const nsACString& aGroup, const nsACString& aOrigin, Client::Type aClientType, bool aExclusive, - OpenDirectoryListener* aOpenListener); + RefPtr aOpenListener); // XXX RemoveMe once bug 1170279 gets fixed. already_AddRefed OpenDirectoryInternal( @@ -481,17 +481,18 @@ class QuotaManager final : public BackgroundThreadObject { const Nullable& aPersistenceType, const nsACString& aGroup, const OriginScope& aOriginScope, const Nullable& aClientType, bool aExclusive, - bool aInternal, OpenDirectoryListener* aOpenListener, bool& aBlockedOut); + bool aInternal, RefPtr aOpenListener, + bool& aBlockedOut); already_AddRefed CreateDirectoryLockForEviction( PersistenceType aPersistenceType, const nsACString& aGroup, const nsACString& aOrigin); - void RegisterDirectoryLock(DirectoryLockImpl* aLock); + void RegisterDirectoryLock(DirectoryLockImpl& aLock); - void UnregisterDirectoryLock(DirectoryLockImpl* aLock); + void UnregisterDirectoryLock(DirectoryLockImpl& aLock); - void RemovePendingDirectoryLock(DirectoryLockImpl* aLock); + void RemovePendingDirectoryLock(DirectoryLockImpl& aLock); uint64_t LockedCollectOriginsForEviction( uint64_t aMinSizeToBeFreed, nsTArray>& aLocks);