Bug 769291 - Move nsOfflineCacheDevice::Discard() to cache IO thread. r=honzab

Discard() is called from destructor of nsApplicationCache.  Instances
of nsApplicationCache is released by last reference, it can be in main
thread.  We move Discard() tasks to cache IO thread to avoid blocking
the main thread.
This commit is contained in:
Thinker K.F. Li 2012-07-11 14:16:00 +08:00
Родитель d5a4600419
Коммит 68ea4f962a
1 изменённых файлов: 32 добавлений и 6 удалений

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

@ -220,6 +220,34 @@ nsOfflineCacheEvictionFunction::Apply()
Reset();
}
class nsOfflineCacheDiscardCache : public nsRunnable
{
public:
nsOfflineCacheDiscardCache(nsOfflineCacheDevice *device,
nsCString &group,
nsCString &clientID)
: mDevice(device)
, mGroup(group)
, mClientID(clientID)
{
}
NS_IMETHOD Run()
{
if (mDevice->IsActiveCache(mGroup, mClientID))
{
mDevice->DeactivateGroup(mGroup);
}
return mDevice->EvictEntries(mClientID.get());
}
private:
nsRefPtr<nsOfflineCacheDevice> mDevice;
nsCString mGroup;
nsCString mClientID;
};
/******************************************************************************
* nsOfflineCacheDeviceInfo
*/
@ -668,12 +696,10 @@ nsApplicationCache::Discard()
mValid = false;
if (mDevice->IsActiveCache(mGroup, mClientID))
{
mDevice->DeactivateGroup(mGroup);
}
return mDevice->EvictEntries(mClientID.get());
nsRefPtr<nsIRunnable> ev =
new nsOfflineCacheDiscardCache(mDevice, mGroup, mClientID);
nsresult rv = nsCacheService::DispatchToCacheIOThread(ev);
return rv;
}
NS_IMETHODIMP