Bug 707915 - Broken invalidation of mCachedUsage in nsDOMStoragePersistentDB

This commit is contained in:
Michal Novotny 2011-12-16 21:33:51 +01:00
Родитель ebec881be7
Коммит 0643e829e6
2 изменённых файлов: 34 добавлений и 8 удалений

Просмотреть файл

@ -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<nsString> &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);
}

Просмотреть файл

@ -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___ */