Bug 980447 - Follow-up fixes in clearStoragesForURI to address follow-up comments (r=janv)

--HG--
extra : rebase_source : 31a02fb699def1957c96aeae09052b7106509c84
This commit is contained in:
Luke Wagner 2014-04-15 21:30:26 -05:00
parent 8e3ce5bc7e
commit df4b523fb5
2 changed files with 30 additions and 16 deletions

View File

@ -57,7 +57,7 @@ PersistenceTypeFromText(const nsACString& aText)
inline nsresult
NullablePersistenceTypeFromText(const nsACString& aText,
Nullable<PersistenceType> *aPersistenceType)
Nullable<PersistenceType>* aPersistenceType)
{
if (aText.IsVoid()) {
*aPersistenceType = Nullable<PersistenceType>();
@ -74,7 +74,7 @@ NullablePersistenceTypeFromText(const nsACString& aText,
return NS_OK;
}
return NS_ERROR_UNEXPECTED;
return NS_ERROR_FAILURE;
}
inline mozilla::dom::StorageType

View File

@ -2290,6 +2290,13 @@ QuotaManager::ClearStoragesForURI(nsIURI* aURI,
NS_ENSURE_ARG_POINTER(aURI);
Nullable<PersistenceType> persistenceType;
nsresult rv =
NullablePersistenceTypeFromText(aPersistenceType, &persistenceType);
if (NS_WARN_IF(NS_FAILED(rv))) {
return NS_ERROR_INVALID_ARG;
}
// This only works from the main process.
NS_ENSURE_TRUE(IsMainProcess(), NS_ERROR_NOT_AVAILABLE);
@ -2299,17 +2306,13 @@ QuotaManager::ClearStoragesForURI(nsIURI* aURI,
// Figure out which origin we're dealing with.
nsCString origin;
nsresult rv = GetInfoFromURI(aURI, aAppId, aInMozBrowserOnly, nullptr, &origin,
nullptr, nullptr);
rv = GetInfoFromURI(aURI, aAppId, aInMozBrowserOnly, nullptr, &origin,
nullptr, nullptr);
NS_ENSURE_SUCCESS(rv, rv);
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, persistenceType)) {
@ -2687,7 +2690,9 @@ QuotaManager::AcquireExclusiveAccess(const nsACString& aPattern,
nsIOfflineStorage*& storage = matches[index];
if (!storage->IsClosed() &&
storage != aStorage &&
storage->Id() == aStorage->Id()) {
storage->Id() == aStorage->Id() &&
(aPersistenceType.IsNull() ||
aPersistenceType.Value() == storage->Type())) {
liveStorages.AppendElement(storage);
}
}
@ -2708,14 +2713,23 @@ QuotaManager::AcquireExclusiveAccess(const nsACString& aPattern,
matches.Find(mLiveStorages, aPattern);
}
if (!matches.IsEmpty()) {
// We want *all* storages, even those that are closed, when we're going to
// clear the origin.
matches.AppendElementsTo(liveStorages);
NS_ASSERTION(op->mStorages.IsEmpty(),
"How do we already have storages here?");
NS_ASSERTION(op->mStorages.IsEmpty(),
"How do we already have storages here?");
matches.SwapElements(op->mStorages);
// We want *all* storages that match the given persistence type, even those
// that are closed, when we're going to clear the origin.
if (!matches.IsEmpty()) {
for (uint32_t i = 0; i < Client::TYPE_MAX; i++) {
nsTArray<nsIOfflineStorage*>& storages = matches.ArrayAt(i);
for (uint32_t j = 0; j < storages.Length(); j++) {
nsIOfflineStorage* storage = storages[j];
if (aPersistenceType.IsNull() ||
aPersistenceType.Value() == storage->Type()) {
liveStorages.AppendElement(storage);
op->mStorages[i].AppendElement(storage);
}
}
}
}
}