Bug 1014394 - Correctly delete all HTTP cache leftover trashes, r=michal

This commit is contained in:
Honza Bambas 2014-05-29 00:52:21 +02:00
parent b988789c5b
commit 3b4a73d31e
6 changed files with 40 additions and 39 deletions

View File

@ -305,13 +305,6 @@ nsDeleteDir::RemoveOldTrashes(nsIFile *cacheDir)
nsresult rv;
static bool firstRun = true;
if (!firstRun)
return NS_OK;
firstRun = false;
nsCOMPtr<nsIFile> trash;
rv = GetTrashDir(cacheDir, &trash);
if (NS_FAILED(rv))

View File

@ -394,8 +394,6 @@ nsDiskCacheDevice::Init()
if (NS_FAILED(rv))
return rv;
nsDeleteDir::RemoveOldTrashes(mCacheDirectory);
// Open Disk Cache
rv = OpenDiskCache();
if (NS_FAILED(rv)) {

View File

@ -250,21 +250,6 @@ uint32_t const CacheObserver::MemoryCacheCapacity()
return sAutoMemoryCacheCapacity = capacity;
}
void CacheObserver::SchduleAutoDelete()
{
// Auto-delete not set
if (sAutoDeleteCacheVersion == -1)
return;
// Don't autodelete the same version of the cache user has setup
// to use.
int32_t activeVersion = UseNewCache() ? 1 : 0;
if (sAutoDeleteCacheVersion == activeVersion)
return;
CacheStorageService::WipeCacheDirectory(sAutoDeleteCacheVersion);
}
// static
bool const CacheObserver::UseNewCache()
{
@ -444,7 +429,8 @@ CacheObserver::Observe(nsISupports* aSubject,
}
if (!strcmp(aTopic, "sessionstore-windows-restored")) {
SchduleAutoDelete();
uint32_t activeVersion = UseNewCache() ? 1 : 0;
CacheStorageService::CleaupCacheDirectories(sAutoDeleteCacheVersion, activeVersion);
return NS_OK;
}

View File

@ -63,7 +63,6 @@ private:
void StoreDiskCacheCapacity();
void AttachToPreferences();
void SchduleAutoDelete();
static uint32_t sUseNewCache;
static bool sUseMemoryCache;

View File

@ -535,22 +535,46 @@ void CacheStorageService::DropPrivateBrowsingEntries()
}
// static
void CacheStorageService::WipeCacheDirectory(uint32_t aVersion)
void CacheStorageService::CleaupCacheDirectories(uint32_t aVersion, uint32_t aActive)
{
nsCOMPtr<nsIFile> cacheDir;
switch (aVersion) {
case 0:
nsCacheService::GetDiskCacheDirectory(getter_AddRefs(cacheDir));
break;
case 1:
CacheFileIOManager::GetCacheDirectory(getter_AddRefs(cacheDir));
break;
// CleaupCacheDirectories is called regardless what cache version is set up to use.
// To obtain the cache1 directory we must unfortunatelly instantiate the old cache
// service despite it may not be used at all... This also initialize nsDeleteDir.
nsCOMPtr<nsICacheService> service = do_GetService(NS_CACHESERVICE_CONTRACTID);
// Schedule delete of both the cache1 and cache2 remaining trashes.
nsCOMPtr<nsIFile> cache1Dir, cache2Dir;
nsCacheService::GetDiskCacheDirectory(getter_AddRefs(cache1Dir));
CacheFileIOManager::GetCacheDirectory(getter_AddRefs(cache2Dir));
// Make sure we schedule just once in case CleaupCacheDirectories gets called
// multiple times from some reason.
static bool runOnce = (
cache1Dir && NS_SUCCEEDED(nsDeleteDir::RemoveOldTrashes(cache1Dir)),
cache2Dir && NS_SUCCEEDED(nsDeleteDir::RemoveOldTrashes(cache2Dir))
);
if (!runOnce) {
NS_WARNING("Could not start deletion of some of the old cache trashes");
}
if (!cacheDir)
// Delete the non-active version cache data right now
if (aVersion == aActive) {
return;
}
nsDeleteDir::DeleteDir(cacheDir, true, 30000);
switch (aVersion) {
case 0:
if (cache1Dir) {
nsDeleteDir::DeleteDir(cache1Dir, true, 30000);
}
break;
case 1:
if (cache2Dir) {
nsDeleteDir::DeleteDir(cache2Dir, true, 30000);
}
break;
}
}
// Helper methods

View File

@ -77,8 +77,9 @@ public:
void Shutdown();
void DropPrivateBrowsingEntries();
// Wipes out the new or the old cache directory completely.
static void WipeCacheDirectory(uint32_t aVersion);
// Takes care of deleting any pending trashes for both cache1 and cache2
// as well as the cache directory of an inactive cache version when requested.
static void CleaupCacheDirectories(uint32_t aVersion, uint32_t aActive);
static CacheStorageService* Self() { return sSelf; }
static nsISupports* SelfISupports() { return static_cast<nsICacheStorageService*>(Self()); }