diff --git a/dom/src/storage/nsDOMStoragePersistentDB.cpp b/dom/src/storage/nsDOMStoragePersistentDB.cpp index ed00c6a1fe0..fe491706030 100644 --- a/dom/src/storage/nsDOMStoragePersistentDB.cpp +++ b/dom/src/storage/nsDOMStoragePersistentDB.cpp @@ -744,7 +744,7 @@ nsDOMStoragePersistentDB::SetKey(DOMStorageImpl* aStorage, NS_ENSURE_SUCCESS(rv, rv); if (!aStorage->GetQuotaDomainDBKey(!aExcludeOfflineFromUsage).IsEmpty()) { - mCachedOwner = aStorage->GetQuotaDomainDBKey(!aExcludeOfflineFromUsage); + // No need to set mCachedOwner since it was set by GetUsage() mCachedUsage = usage; } @@ -807,8 +807,10 @@ nsDOMStoragePersistentDB::RemoveKey(DOMStorageImpl* aStorage, mozStorageStatementScoper scope(mRemoveKeyStatement); - if (aStorage->GetQuotaDomainDBKey(!aExcludeOfflineFromUsage) == mCachedOwner) { - mCachedUsage -= aKeyUsage; + if (DomainMaybeCached( + aStorage->GetQuotaDomainDBKey(!aExcludeOfflineFromUsage))) { + mCachedUsage = 0; + mCachedOwner.Truncate(); } Binder binder(mRemoveKeyStatement, &rv); @@ -877,15 +879,15 @@ nsDOMStoragePersistentDB::RemoveOwner(const nsACString& aOwner, nsCAutoString subdomainsDBKey; nsDOMStorageDBWrapper::CreateDomainScopeDBKey(aOwner, subdomainsDBKey); - if (!aIncludeSubDomains) - subdomainsDBKey.AppendLiteral(":"); - subdomainsDBKey.AppendLiteral("*"); - - if (subdomainsDBKey == mCachedOwner) { + if (DomainMaybeCached(subdomainsDBKey)) { mCachedUsage = 0; mCachedOwner.Truncate(); } + if (!aIncludeSubDomains) + subdomainsDBKey.AppendLiteral(":"); + subdomainsDBKey.AppendLiteral("*"); + Binder binder(mRemoveOwnerStatement, &rv); NS_ENSURE_SUCCESS(rv, rv); @@ -960,6 +962,11 @@ nsDOMStoragePersistentDB::RemoveOwners(const nsTArray &aOwners, rv = nsDOMStorageDBWrapper::CreateDomainScopeDBKey( NS_ConvertUTF16toUTF8(aOwners[i]), quotaKey); + if (DomainMaybeCached(quotaKey)) { + mCachedUsage = 0; + mCachedOwner.Truncate(); + } + if (!aIncludeSubDomains) quotaKey.AppendLiteral(":"); quotaKey.AppendLiteral("*"); @@ -1120,3 +1127,17 @@ nsDOMStoragePersistentDB::MaybeCommitInsertTransaction() return NS_OK; } + +bool +nsDOMStoragePersistentDB::DomainMaybeCached(const nsACString& aDomain) +{ + if (mCachedOwner.IsEmpty()) + return false; + + // if cached owner contains colon we must ignore it + if (mCachedOwner[mCachedOwner.Length() - 1] == ':') + return StringBeginsWith(aDomain, Substring(mCachedOwner, 0, + mCachedOwner.Length() - 1)); + else + return StringBeginsWith(aDomain, mCachedOwner); +} diff --git a/dom/src/storage/nsDOMStoragePersistentDB.h b/dom/src/storage/nsDOMStoragePersistentDB.h index ad9cd531e03..068e71c6ee0 100644 --- a/dom/src/storage/nsDOMStoragePersistentDB.h +++ b/dom/src/storage/nsDOMStoragePersistentDB.h @@ -219,6 +219,11 @@ protected: friend class nsDOMStorageMemoryDB; nsresult GetUsageInternal(const nsACString& aQuotaDomainDBKey, bool aExcludeOfflineFromUsage, PRInt32 *aUsage); + + // Compares aDomain with the mCachedOwner and returns false if changes + // in aDomain don't affect mCachedUsage. + bool DomainMaybeCached(const nsACString& aDomain); + }; #endif /* nsDOMStorageDB_h___ */