Bug 1170021 - Part 2: Move DirectoryLock out of QuotaManager class; r=bent

This commit is contained in:
Jan Varga 2015-06-30 14:59:53 +02:00
parent b42f7e1c86
commit 138aed340f
7 changed files with 63 additions and 84 deletions

View File

@ -484,7 +484,7 @@ class MainProcessRunnable
: public virtual FileDescriptorHolder
, public quota::OpenDirectoryListener
{
typedef mozilla::dom::quota::QuotaManager::DirectoryLock DirectoryLock;
typedef mozilla::dom::quota::DirectoryLock DirectoryLock;
public:
NS_DECL_NSIRUNNABLE

View File

@ -12,6 +12,7 @@
#include "mozilla/dom/cache/FileUtils.h"
#include "mozilla/dom/cache/Manager.h"
#include "mozilla/dom/cache/ManagerId.h"
#include "mozilla/dom/quota/QuotaManager.h"
#include "mozIStorageConnection.h"
#include "nsIFile.h"
#include "nsIPrincipal.h"

10
dom/cache/Context.h vendored
View File

@ -8,7 +8,6 @@
#define mozilla_dom_cache_Context_h
#include "mozilla/dom/cache/Types.h"
#include "mozilla/dom/quota/QuotaManager.h"
#include "nsAutoPtr.h"
#include "nsCOMPtr.h"
#include "nsISupportsImpl.h"
@ -22,6 +21,13 @@ class nsIThread;
namespace mozilla {
namespace dom {
namespace quota {
class DirectoryLock;
} // namespace quota
namespace cache {
class Action;
@ -59,7 +65,7 @@ class Manager;
// via the code in ShutdownObserver.cpp.
class Context final
{
typedef mozilla::dom::quota::QuotaManager::DirectoryLock DirectoryLock;
typedef mozilla::dom::quota::DirectoryLock DirectoryLock;
public:
// Define a class allowing other threads to hold the Context alive. This also

View File

@ -5590,8 +5590,6 @@ private:
NS_DECL_NSIRUNNABLE
};
using DirectoryLock = mozilla::dom::quota::QuotaManager::DirectoryLock;
class UnlockDirectoryRunnable final
: public nsRunnable
{

View File

@ -146,7 +146,7 @@ class DeleteFilesRunnable final
: public nsIRunnable
, public OpenDirectoryListener
{
typedef mozilla::dom::quota::QuotaManager::DirectoryLock DirectoryLock;
typedef mozilla::dom::quota::DirectoryLock DirectoryLock;
enum State
{

View File

@ -91,8 +91,6 @@ namespace mozilla {
namespace dom {
namespace quota {
using DirectoryLock = QuotaManager::DirectoryLock;
namespace {
/*******************************************************************************
@ -136,7 +134,7 @@ enum AppId {
} // anonymous namespace
class QuotaManager::DirectoryLockImpl final
class DirectoryLockImpl final
: public DirectoryLock
{
nsRefPtr<QuotaManager> mQuotaManager;
@ -468,7 +466,9 @@ private:
nsRefPtr<GroupInfo> mDefaultStorageGroupInfo;
};
class QuotaManager::CollectOriginsHelper final
namespace {
class CollectOriginsHelper final
: public nsRunnable
{
uint64_t mMinSizeToBeFreed;
@ -477,7 +477,7 @@ class QuotaManager::CollectOriginsHelper final
CondVar mCondVar;
// The members below are protected by mMutex.
nsTArray<nsRefPtr<QuotaManager::DirectoryLockImpl>> mLocks;
nsTArray<nsRefPtr<DirectoryLockImpl>> mLocks;
uint64_t mSizeToBeFreed;
bool mWaiting;
@ -499,8 +499,6 @@ private:
Run();
};
namespace {
class OriginOperationBase
: public nsRunnable
{
@ -763,9 +761,7 @@ private:
{ }
};
} // anonymous namespace
class QuotaManager::FinalizeOriginEvictionOp
class FinalizeOriginEvictionOp
: public OriginOperationBase
{
nsTArray<nsRefPtr<DirectoryLockImpl>> mLocks;
@ -799,8 +795,6 @@ private:
UnblockOpen() override;
};
namespace {
/*******************************************************************************
* Helper Functions
******************************************************************************/
@ -1620,7 +1614,6 @@ GetTemporaryStorageLimit(nsIFile* aDirectory, uint64_t aCurrentUsage,
* Directory lock
******************************************************************************/
QuotaManager::
DirectoryLockImpl::DirectoryLockImpl(QuotaManager* aQuotaManager,
Nullable<PersistenceType> aPersistenceType,
const nsACString& aGroup,
@ -1656,7 +1649,6 @@ DirectoryLockImpl::DirectoryLockImpl(QuotaManager* aQuotaManager,
MOZ_ASSERT_IF(!aInternal, aOpenListener);
}
QuotaManager::
DirectoryLockImpl::~DirectoryLockImpl()
{
MOZ_ASSERT(NS_IsMainThread());
@ -1673,7 +1665,6 @@ DirectoryLockImpl::~DirectoryLockImpl()
// static
bool
QuotaManager::
DirectoryLockImpl::MatchOriginScopes(const OriginScope& aOriginScope1,
const OriginScope& aOriginScope2)
{
@ -1700,7 +1691,6 @@ DirectoryLockImpl::MatchOriginScopes(const OriginScope& aOriginScope1,
}
bool
QuotaManager::
DirectoryLockImpl::MustWaitFor(const DirectoryLockImpl& aExistingLock)
{
MOZ_ASSERT(NS_IsMainThread());
@ -1734,7 +1724,6 @@ DirectoryLockImpl::MustWaitFor(const DirectoryLockImpl& aExistingLock)
}
void
QuotaManager::
DirectoryLockImpl::NotifyOpenListener()
{
MOZ_ASSERT(NS_IsMainThread());
@ -1752,7 +1741,7 @@ DirectoryLockImpl::NotifyOpenListener()
mQuotaManager->RemovePendingDirectoryLock(this);
}
NS_IMPL_ISUPPORTS0(QuotaManager::DirectoryLockImpl);
NS_IMPL_ISUPPORTS0(DirectoryLockImpl);
/*******************************************************************************
* Quota object
@ -1883,7 +1872,7 @@ QuotaObject::MaybeUpdateSize(int64_t aSize, bool aTruncate)
if (newTemporaryStorageUsage > quotaManager->mTemporaryStorageLimit) {
// This will block the thread without holding the lock while waitting.
nsAutoTArray<nsRefPtr<QuotaManager::DirectoryLockImpl>, 10> locks;
nsAutoTArray<nsRefPtr<DirectoryLockImpl>, 10> locks;
uint64_t sizeToBeFreed =
quotaManager->LockedCollectOriginsForEviction(delta, locks);
@ -1897,7 +1886,7 @@ QuotaObject::MaybeUpdateSize(int64_t aSize, bool aTruncate)
{
MutexAutoUnlock autoUnlock(quotaManager->mQuotaMutex);
for (nsRefPtr<QuotaManager::DirectoryLockImpl>& lock : locks) {
for (nsRefPtr<DirectoryLockImpl>& lock : locks) {
MOZ_ASSERT(!lock->GetPersistenceType().IsNull());
MOZ_ASSERT(lock->GetOriginScope().IsOrigin());
MOZ_ASSERT(!lock->GetOriginScope().IsEmpty());
@ -1911,7 +1900,7 @@ QuotaObject::MaybeUpdateSize(int64_t aSize, bool aTruncate)
NS_ASSERTION(mOriginInfo, "How come?!");
for (QuotaManager::DirectoryLockImpl* lock : locks) {
for (DirectoryLockImpl* lock : locks) {
MOZ_ASSERT(!lock->GetPersistenceType().IsNull());
MOZ_ASSERT(!lock->GetGroup().IsEmpty());
MOZ_ASSERT(lock->GetOriginScope().IsOrigin());
@ -4395,7 +4384,6 @@ GroupInfoPair::GetGroupInfoForPersistenceType(PersistenceType aPersistenceType)
}
}
QuotaManager::
CollectOriginsHelper::CollectOriginsHelper(mozilla::Mutex& aMutex,
uint64_t aMinSizeToBeFreed)
: mMinSizeToBeFreed(aMinSizeToBeFreed),
@ -4409,7 +4397,6 @@ CollectOriginsHelper::CollectOriginsHelper(mozilla::Mutex& aMutex,
}
int64_t
QuotaManager::
CollectOriginsHelper::BlockAndReturnOriginsForEviction(
nsTArray<nsRefPtr<DirectoryLockImpl>>& aLocks)
{
@ -4425,7 +4412,6 @@ CollectOriginsHelper::BlockAndReturnOriginsForEviction(
}
NS_IMETHODIMP
QuotaManager::
CollectOriginsHelper::Run()
{
MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
@ -4996,7 +4982,6 @@ OriginClearOp::DoDirectoryWork(QuotaManager* aQuotaManager)
}
void
QuotaManager::
FinalizeOriginEvictionOp::Dispatch()
{
MOZ_ASSERT(!NS_IsMainThread());
@ -5008,7 +4993,6 @@ FinalizeOriginEvictionOp::Dispatch()
}
void
QuotaManager::
FinalizeOriginEvictionOp::RunOnIOThreadImmediately()
{
AssertIsOnIOThread();
@ -5020,14 +5004,12 @@ FinalizeOriginEvictionOp::RunOnIOThreadImmediately()
}
nsresult
QuotaManager::
FinalizeOriginEvictionOp::Open()
{
MOZ_CRASH("Shouldn't get here!");
}
nsresult
QuotaManager::
FinalizeOriginEvictionOp::DoDirectoryWork(QuotaManager* aQuotaManager)
{
AssertIsOnIOThread();
@ -5045,7 +5027,6 @@ FinalizeOriginEvictionOp::DoDirectoryWork(QuotaManager* aQuotaManager)
}
void
QuotaManager::
FinalizeOriginEvictionOp::UnblockOpen()
{
MOZ_ASSERT(NS_IsMainThread());

View File

@ -39,13 +39,53 @@ class OptionalContentId;
BEGIN_QUOTA_NAMESPACE
class DirectoryLockImpl;
class GroupInfo;
class GroupInfoPair;
class OpenDirectoryListener;
class OriginInfo;
class OriginScope;
class QuotaObject;
class NS_NO_VTABLE RefCountedObject
{
public:
NS_IMETHOD_(MozExternalRefCountType)
AddRef() = 0;
NS_IMETHOD_(MozExternalRefCountType)
Release() = 0;
};
// nsISupports is needed for nsMainThreadPtrHandle<DirectoryLock>
// XXX RemoveMe once bug 1164581 gets fixed.
class DirectoryLock
: public nsISupports
{
friend class DirectoryLockImpl;
private:
DirectoryLock()
{ }
~DirectoryLock()
{ }
};
class NS_NO_VTABLE OpenDirectoryListener
: public RefCountedObject
{
public:
virtual void
DirectoryLockAcquired(DirectoryLock* aLock) = 0;
virtual void
DirectoryLockFailed() = 0;
protected:
virtual ~OpenDirectoryListener()
{ }
};
struct OriginParams
{
OriginParams(PersistenceType aPersistenceType,
@ -64,10 +104,7 @@ struct OriginParams
class QuotaManager final : public nsIQuotaManager,
public nsIObserver
{
public:
class DirectoryLock;
private:
friend class DirectoryLockImpl;
friend class GroupInfo;
friend class OriginInfo;
friend class QuotaObject;
@ -79,10 +116,6 @@ private:
IgnoreMozBrowser
};
class CollectOriginsHelper;
class DirectoryLockImpl;
class FinalizeOriginEvictionOp;
typedef nsClassHashtable<nsCStringHashKey,
nsTArray<DirectoryLockImpl*>> DirectoryLockTable;
@ -488,46 +521,6 @@ private:
bool mStorageAreaInitialized;
};
class NS_NO_VTABLE RefCountedObject
{
public:
NS_IMETHOD_(MozExternalRefCountType)
AddRef() = 0;
NS_IMETHOD_(MozExternalRefCountType)
Release() = 0;
};
// nsISupports is needed for nsMainThreadPtrHandle<DirectoryLock>
// XXX RemoveMe once bug 1164581 gets fixed.
class QuotaManager::DirectoryLock
: public nsISupports
{
friend class DirectoryLockImpl;
private:
DirectoryLock()
{ }
~DirectoryLock()
{ }
};
class NS_NO_VTABLE OpenDirectoryListener
: public RefCountedObject
{
public:
virtual void
DirectoryLockAcquired(QuotaManager::DirectoryLock* aLock) = 0;
virtual void
DirectoryLockFailed() = 0;
protected:
virtual ~OpenDirectoryListener()
{ }
};
END_QUOTA_NAMESPACE
#endif /* mozilla_dom_quota_quotamanager_h__ */