From df4b523fb5848ca6f352f20e335faaae8f0d758c Mon Sep 17 00:00:00 2001 From: Luke Wagner Date: Tue, 15 Apr 2014 21:30:26 -0500 Subject: [PATCH] Bug 980447 - Follow-up fixes in clearStoragesForURI to address follow-up comments (r=janv) --HG-- extra : rebase_source : 31a02fb699def1957c96aeae09052b7106509c84 --- dom/quota/PersistenceType.h | 4 ++-- dom/quota/QuotaManager.cpp | 42 ++++++++++++++++++++++++------------- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/dom/quota/PersistenceType.h b/dom/quota/PersistenceType.h index 171f061c4c3..736747312a4 100644 --- a/dom/quota/PersistenceType.h +++ b/dom/quota/PersistenceType.h @@ -57,7 +57,7 @@ PersistenceTypeFromText(const nsACString& aText) inline nsresult NullablePersistenceTypeFromText(const nsACString& aText, - Nullable *aPersistenceType) + Nullable* aPersistenceType) { if (aText.IsVoid()) { *aPersistenceType = Nullable(); @@ -74,7 +74,7 @@ NullablePersistenceTypeFromText(const nsACString& aText, return NS_OK; } - return NS_ERROR_UNEXPECTED; + return NS_ERROR_FAILURE; } inline mozilla::dom::StorageType diff --git a/dom/quota/QuotaManager.cpp b/dom/quota/QuotaManager.cpp index 73e7cca260d..521e5f3d8d1 100644 --- a/dom/quota/QuotaManager.cpp +++ b/dom/quota/QuotaManager.cpp @@ -2290,6 +2290,13 @@ QuotaManager::ClearStoragesForURI(nsIURI* aURI, NS_ENSURE_ARG_POINTER(aURI); + Nullable 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; - 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& 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); + } + } + } } }