Bug 980447 - Add persistenceType argument to nsIQuotaManager.clearStoragesForURI (r=janv)

--HG--
extra : rebase_source : 4d034bd92b099bd1385fc9e8a95fa959fc8e51e0
This commit is contained in:
Luke Wagner 2014-04-14 15:48:49 -05:00
parent 1553a0f695
commit b9c343c46a
7 changed files with 87 additions and 45 deletions

View File

@ -608,7 +608,9 @@ IndexedDatabaseManager::AsyncDeleteFile(FileManager* aFileManager,
// See if we're currently clearing the storages for this origin. If so then
// we pretend that we've already deleted everything.
if (quotaManager->IsClearOriginPending(aFileManager->Origin())) {
if (quotaManager->IsClearOriginPending(
aFileManager->Origin(),
Nullable<PersistenceType>(aFileManager->Type()))) {
return NS_OK;
}

View File

@ -2146,7 +2146,8 @@ OpenDatabaseHelper::StartSetVersion()
NS_ASSERTION(quotaManager, "This should never be null!");
rv = quotaManager->AcquireExclusiveAccess(
mDatabase, mDatabase->Origin(), helper,
mDatabase, mDatabase->Origin(),
Nullable<PersistenceType>(mDatabase->Type()), helper,
&VersionChangeEventsRunnable::QueueVersionChange<SetVersionHelper>,
helper);
IDB_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
@ -2176,7 +2177,8 @@ OpenDatabaseHelper::StartDelete()
NS_ASSERTION(quotaManager, "This should never be null!");
rv = quotaManager->AcquireExclusiveAccess(
mDatabase, mDatabase->Origin(), helper,
mDatabase, mDatabase->Origin(),
Nullable<PersistenceType>(mDatabase->Type()), helper,
&VersionChangeEventsRunnable::QueueVersionChange<DeleteDatabaseHelper>,
helper);
IDB_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);

View File

@ -55,6 +55,28 @@ PersistenceTypeFromText(const nsACString& aText)
MOZ_ASSUME_UNREACHABLE("Should never get here!");
}
inline nsresult
NullablePersistenceTypeFromText(const nsACString& aText,
Nullable<PersistenceType> *aPersistenceType)
{
if (aText.IsVoid()) {
*aPersistenceType = Nullable<PersistenceType>();
return NS_OK;
}
if (aText.EqualsLiteral("persistent")) {
*aPersistenceType = Nullable<PersistenceType>(PERSISTENCE_TYPE_PERSISTENT);
return NS_OK;
}
if (aText.EqualsLiteral("temporary")) {
*aPersistenceType = Nullable<PersistenceType>(PERSISTENCE_TYPE_TEMPORARY);
return NS_OK;
}
return NS_ERROR_UNEXPECTED;
}
inline mozilla::dom::StorageType
PersistenceTypeToStorage(PersistenceType aPersistenceType)
{

View File

@ -188,8 +188,10 @@ class OriginClearRunnable MOZ_FINAL : public nsRunnable,
public:
NS_DECL_ISUPPORTS_INHERITED
OriginClearRunnable(const OriginOrPatternString& aOriginOrPattern)
OriginClearRunnable(const OriginOrPatternString& aOriginOrPattern,
Nullable<PersistenceType> aPersistenceType)
: mOriginOrPattern(aOriginOrPattern),
mPersistenceType(aPersistenceType),
mCallbackState(Pending)
{ }
@ -228,6 +230,7 @@ public:
private:
OriginOrPatternString mOriginOrPattern;
Nullable<PersistenceType> mPersistenceType;
CallbackState mCallbackState;
};
@ -2280,6 +2283,7 @@ NS_IMETHODIMP
QuotaManager::ClearStoragesForURI(nsIURI* aURI,
uint32_t aAppId,
bool aInMozBrowserOnly,
const nsACString& aPersistenceType,
uint8_t aOptionalArgCount)
{
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
@ -2302,19 +2306,23 @@ QuotaManager::ClearStoragesForURI(nsIURI* aURI,
nsAutoCString pattern;
GetOriginPatternString(aAppId, aInMozBrowserOnly, origin, pattern);
Nullable<PersistenceType> persistenceType;
rv = NullablePersistenceTypeFromText(aPersistenceType, &persistenceType);
NS_ENSURE_SUCCESS(rv, rv);
// If there is a pending or running clear operation for this origin, return
// immediately.
if (IsClearOriginPending(pattern)) {
if (IsClearOriginPending(pattern, persistenceType)) {
return NS_OK;
}
OriginOrPatternString oops = OriginOrPatternString::FromPattern(pattern);
// Queue up the origin clear runnable.
nsRefPtr<OriginClearRunnable> runnable = new OriginClearRunnable(oops);
nsRefPtr<OriginClearRunnable> runnable =
new OriginClearRunnable(oops, persistenceType);
rv = WaitForOpenAllowed(oops, Nullable<PersistenceType>(), EmptyCString(),
runnable);
rv = WaitForOpenAllowed(oops, persistenceType, EmptyCString(), runnable);
NS_ENSURE_SUCCESS(rv, rv);
runnable->AdvanceState();
@ -2324,11 +2332,14 @@ QuotaManager::ClearStoragesForURI(nsIURI* aURI,
matches.Find(mLiveStorages, pattern);
for (uint32_t index = 0; index < matches.Length(); index++) {
if (persistenceType.IsNull() ||
matches[index]->Type() == persistenceType.Value()) {
// We need to grab references to any live storages here to prevent them
// from dying while we invalidate them.
nsCOMPtr<nsIOfflineStorage> storage = matches[index];
storage->Invalidate();
}
}
// After everything has been invalidated the helper should be dispatched to
// the end of the event queue.
@ -2640,6 +2651,7 @@ QuotaManager::LockedRemoveQuotaForOrigin(PersistenceType aPersistenceType,
nsresult
QuotaManager::AcquireExclusiveAccess(const nsACString& aPattern,
Nullable<PersistenceType> aPersistenceType,
nsIOfflineStorage* aStorage,
AcquireListener* aListener,
WaitingOnStoragesCallback aCallback,
@ -2649,16 +2661,9 @@ QuotaManager::AcquireExclusiveAccess(const nsACString& aPattern,
NS_ASSERTION(aListener, "Need a listener!");
// Find the right SynchronizedOp.
SynchronizedOp* op;
if (aStorage) {
op = FindSynchronizedOp(aPattern,
Nullable<PersistenceType>(aStorage->Type()),
aStorage->Id());
}
else {
op = FindSynchronizedOp(aPattern, Nullable<PersistenceType>(),
EmptyCString());
}
SynchronizedOp* op =
FindSynchronizedOp(aPattern, aPersistenceType,
aStorage ? aStorage->Id() : EmptyCString());
NS_ASSERTION(op, "We didn't find a SynchronizedOp?");
NS_ASSERTION(!op->mListener, "SynchronizedOp already has a listener?!?");
@ -2840,20 +2845,23 @@ QuotaManager::ClearStoragesForApp(uint32_t aAppId, bool aBrowserOnly)
nsAutoCString pattern;
GetOriginPatternStringMaybeIgnoreBrowser(aAppId, aBrowserOnly, pattern);
// Clear both temporary and persistent storages.
Nullable<PersistenceType> persistenceType;
// If there is a pending or running clear operation for this app, return
// immediately.
if (IsClearOriginPending(pattern)) {
if (IsClearOriginPending(pattern, persistenceType)) {
return NS_OK;
}
OriginOrPatternString oops = OriginOrPatternString::FromPattern(pattern);
// Queue up the origin clear runnable.
nsRefPtr<OriginClearRunnable> runnable = new OriginClearRunnable(oops);
nsRefPtr<OriginClearRunnable> runnable =
new OriginClearRunnable(oops, persistenceType);
nsresult rv =
WaitForOpenAllowed(oops, Nullable<PersistenceType>(), EmptyCString(),
runnable);
WaitForOpenAllowed(oops, persistenceType, EmptyCString(), runnable);
NS_ENSURE_SUCCESS(rv, rv);
runnable->AdvanceState();
@ -3507,8 +3515,9 @@ OriginClearRunnable::Run()
// Now we have to wait until the thread pool is done with all of the
// storages we care about.
nsresult rv =
quotaManager->AcquireExclusiveAccess(mOriginOrPattern, this,
InvalidateOpenedStorages, nullptr);
quotaManager->AcquireExclusiveAccess(mOriginOrPattern, mPersistenceType,
this, InvalidateOpenedStorages,
nullptr);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
@ -3519,9 +3528,12 @@ OriginClearRunnable::Run()
AdvanceState();
if (mPersistenceType.IsNull()) {
DeleteFiles(quotaManager, PERSISTENCE_TYPE_PERSISTENT);
DeleteFiles(quotaManager, PERSISTENCE_TYPE_TEMPORARY);
} else {
DeleteFiles(quotaManager, mPersistenceType.Value());
}
// Now dispatch back to the main thread.
if (NS_FAILED(NS_DispatchToMainThread(this, NS_DISPATCH_NORMAL))) {
@ -3536,8 +3548,7 @@ OriginClearRunnable::Run()
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
// Tell the QuotaManager that we're done.
quotaManager->AllowNextSynchronizedOp(mOriginOrPattern,
Nullable<PersistenceType>(),
quotaManager->AllowNextSynchronizedOp(mOriginOrPattern, mPersistenceType,
EmptyCString());
return NS_OK;
@ -3863,7 +3874,8 @@ ResetOrClearRunnable::Run()
// Now we have to wait until the thread pool is done with all of the
// storages we care about.
nsresult rv =
quotaManager->AcquireExclusiveAccess(NullCString(), this,
quotaManager->AcquireExclusiveAccess(NullCString(),
Nullable<PersistenceType>(), this,
InvalidateOpenedStorages, nullptr);
NS_ENSURE_SUCCESS(rv, rv);

View File

@ -198,23 +198,25 @@ public:
nsresult
AcquireExclusiveAccess(nsIOfflineStorage* aStorage,
const nsACString& aOrigin,
Nullable<PersistenceType> aPersistenceType,
AcquireListener* aListener,
WaitingOnStoragesCallback aCallback,
void* aClosure)
{
NS_ASSERTION(aStorage, "Need a storage here!");
return AcquireExclusiveAccess(aOrigin, aStorage, aListener, aCallback,
aClosure);
return AcquireExclusiveAccess(aOrigin, aPersistenceType, aStorage,
aListener, aCallback, aClosure);
}
nsresult
AcquireExclusiveAccess(const nsACString& aOrigin,
Nullable<PersistenceType> aPersistenceType,
AcquireListener* aListener,
WaitingOnStoragesCallback aCallback,
void* aClosure)
{
return AcquireExclusiveAccess(aOrigin, nullptr, aListener, aCallback,
aClosure);
return AcquireExclusiveAccess(aOrigin, aPersistenceType, nullptr,
aListener, aCallback, aClosure);
}
void
@ -223,10 +225,10 @@ public:
const nsACString& aId);
bool
IsClearOriginPending(const nsACString& aPattern)
IsClearOriginPending(const nsACString& aPattern,
Nullable<PersistenceType> aPersistenceType)
{
return !!FindSynchronizedOp(aPattern, Nullable<PersistenceType>(),
EmptyCString());
return !!FindSynchronizedOp(aPattern, aPersistenceType, EmptyCString());
}
nsresult
@ -369,6 +371,7 @@ private:
nsresult
AcquireExclusiveAccess(const nsACString& aOrigin,
Nullable<PersistenceType> aPersistenceType,
nsIOfflineStorage* aStorage,
AcquireListener* aListener,
WaitingOnStoragesCallback aCallback,

View File

@ -10,7 +10,7 @@ interface nsIQuotaRequest;
interface nsIURI;
interface nsIUsageCallback;
[scriptable, builtinclass, uuid(f19a03ae-e97d-41e9-95dd-681b910c4093)]
[scriptable, builtinclass, uuid(2968fcd5-1872-4ddc-8c16-62b27e357f31)]
interface nsIQuotaManager : nsISupports
{
/**
@ -51,7 +51,8 @@ interface nsIQuotaManager : nsISupports
void
clearStoragesForURI(in nsIURI aURI,
[optional] in unsigned long aAppId,
[optional] in boolean aInMozBrowserOnly);
[optional] in boolean aInMozBrowserOnly,
[optional] in ACString aPersistenceType);
/**
* Resets quota and storage management. This can be used to force

View File

@ -312,8 +312,8 @@ class xpc_qsACString : public xpc_qsBasicString<nsACString, nsCString>
public:
xpc_qsACString(JSContext *cx, JS::HandleValue v,
JS::MutableHandleValue pval, bool notpassed,
StringificationBehavior nullBehavior,
StringificationBehavior undefinedBehavior);
StringificationBehavior nullBehavior = eNull,
StringificationBehavior undefinedBehavior = eNull);
};
/**