Bug 691108 - Make sure that no entry can be bound to the disk cache when nsDiskCacheDevice::ClearDiskCache() is in progress

This commit is contained in:
Michal Novotny 2012-04-12 18:27:38 +02:00
Родитель 1875e76cb4
Коммит d5970a18e4
2 изменённых файлов: 8 добавлений и 0 удалений

7
netwerk/cache/nsDiskCacheDevice.cpp поставляемый
Просмотреть файл

@ -405,6 +405,7 @@ nsDiskCacheDevice::nsDiskCacheDevice()
: mCacheCapacity(0)
, mMaxEntrySize(-1) // -1 means "no limit"
, mInitialized(false)
, mClearingDiskCache(false)
{
}
@ -512,6 +513,7 @@ nsDiskCacheDevice::FindEntry(nsCString * key, bool *collision)
{
Telemetry::AutoTimer<Telemetry::CACHE_DISK_SEARCH> timer;
if (!Initialized()) return nsnull; // NS_ERROR_NOT_INITIALIZED
if (mClearingDiskCache) return nsnull;
nsDiskCacheRecord record;
nsDiskCacheBinding * binding = nsnull;
PLDHashNumber hashNumber = nsDiskCache::Hash(key->get());
@ -640,6 +642,7 @@ nsresult
nsDiskCacheDevice::BindEntry(nsCacheEntry * entry)
{
if (!Initialized()) return NS_ERROR_NOT_INITIALIZED;
if (mClearingDiskCache) return NS_ERROR_NOT_AVAILABLE;
nsresult rv = NS_OK;
nsDiskCacheRecord record, oldRecord;
nsDiskCacheBinding *binding;
@ -1060,10 +1063,14 @@ nsDiskCacheDevice::ClearDiskCache()
if (mBindery.ActiveBindings())
return NS_ERROR_CACHE_IN_USE;
mClearingDiskCache = true;
nsresult rv = Shutdown_Private(false); // false: don't bother flushing
if (NS_FAILED(rv))
return rv;
mClearingDiskCache = false;
// If the disk cache directory is already gone, then it's not an error if
// we fail to delete it ;-)
rv = nsDeleteDir::DeleteDir(mCacheDirectory, true);

1
netwerk/cache/nsDiskCacheDevice.h поставляемый
Просмотреть файл

@ -141,6 +141,7 @@ private:
// XXX need soft/hard limits, currentTotal
nsDiskCacheMap mCacheMap;
bool mInitialized;
bool mClearingDiskCache;
};
#endif // _nsDiskCacheDevice_h_