Bug 961024 - Move HTTP cache on Android to application's cache/profile leaf name, r=michal

This commit is contained in:
Honza Bambas 2014-06-03 14:35:17 +02:00
Родитель 4b14ce2ad7
Коммит 8f57c8e341
3 изменённых файлов: 72 добавлений и 2 удалений

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

@ -1342,10 +1342,33 @@ CacheFileIOManager::OnProfile()
CacheObserver::ParentDirOverride(getter_AddRefs(directory));
#if defined(MOZ_WIDGET_ANDROID)
nsCOMPtr<nsIFile> profilelessDirectory;
char* cachePath = getenv("CACHE_DIRECTORY");
if (!directory && cachePath && *cachePath) {
rv = NS_NewNativeLocalFile(nsDependentCString(cachePath),
true, getter_AddRefs(directory));
if (NS_SUCCEEDED(rv)) {
// Save this directory as the profileless path.
rv = directory->Clone(getter_AddRefs(profilelessDirectory));
NS_ENSURE_SUCCESS(rv, rv);
// Add profile leaf name to the directory name to distinguish
// multiple profiles Fennec supports.
nsCOMPtr<nsIFile> profD;
rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR,
getter_AddRefs(profD));
nsAutoCString leafName;
if (NS_SUCCEEDED(rv)) {
rv = profD->GetNativeLeafName(leafName);
}
if (NS_SUCCEEDED(rv)) {
rv = directory->AppendNative(leafName);
}
if (NS_FAILED(rv)) {
directory = nullptr;
}
}
}
#endif
@ -1367,6 +1390,15 @@ CacheFileIOManager::OnProfile()
// All functions return a clone.
ioMan->mCacheDirectory.swap(directory);
#if defined(MOZ_WIDGET_ANDROID)
if (profilelessDirectory) {
rv = profilelessDirectory->Append(NS_LITERAL_STRING("cache2"));
NS_ENSURE_SUCCESS(rv, rv);
}
ioMan->mCacheProfilelessDirectory.swap(profilelessDirectory);
#endif
if (ioMan->mCacheDirectory) {
CacheIndex::Init(ioMan->mCacheDirectory);
}
@ -2221,10 +2253,26 @@ void CacheFileIOManager::GetCacheDirectory(nsIFile** result)
return;
}
nsCOMPtr<nsIFile> file = ioMan->mCacheDirectory;
file.forget(result);
ioMan->mCacheDirectory->Clone(result);
}
#if defined(MOZ_WIDGET_ANDROID)
// static
void CacheFileIOManager::GetProfilelessCacheDirectory(nsIFile** result)
{
*result = nullptr;
nsRefPtr<CacheFileIOManager> ioMan = gInstance;
if (!ioMan) {
return;
}
ioMan->mCacheProfilelessDirectory->Clone(result);
}
#endif
// static
nsresult
CacheFileIOManager::GetEntryInfo(const SHA1Sum::Hash *aHash,

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

@ -280,6 +280,9 @@ public:
};
static void GetCacheDirectory(nsIFile** result);
#if defined(MOZ_WIDGET_ANDROID)
static void GetProfilelessCacheDirectory(nsIFile** result);
#endif
// Calls synchronously OnEntryInfo for an entry with the given hash.
// Tries to find an existing entry in the service hashtables first, if not
@ -383,6 +386,13 @@ private:
bool mShuttingDown;
nsRefPtr<CacheIOThread> mIOThread;
nsCOMPtr<nsIFile> mCacheDirectory;
#if defined(MOZ_WIDGET_ANDROID)
// On Android we add the active profile directory name between the path
// and the 'cache2' leaf name. However, to delete any leftover data from
// times before we were doing it, we still need to access the directory
// w/o the profile name in the path. Here it is stored.
nsCOMPtr<nsIFile> mCacheProfilelessDirectory;
#endif
bool mTreeCreated;
CacheFileHandles mHandles;
nsTArray<CacheFileHandle *> mHandlesByLastUsed;

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

@ -548,11 +548,17 @@ private:
{
nsCacheService::GetDiskCacheDirectory(getter_AddRefs(mCache1Dir));
CacheFileIOManager::GetCacheDirectory(getter_AddRefs(mCache2Dir));
#if defined(MOZ_WIDGET_ANDROID)
CacheFileIOManager::GetProfilelessCacheDirectory(getter_AddRefs(mCache2Profileless));
#endif
}
virtual ~CleaupCacheDirectoriesRunnable() {}
uint32_t mVersion, mActive;
nsCOMPtr<nsIFile> mCache1Dir, mCache2Dir;
#if defined(MOZ_WIDGET_ANDROID)
nsCOMPtr<nsIFile> mCache2Profileless;
#endif
};
// static
@ -586,6 +592,12 @@ NS_IMETHODIMP CleaupCacheDirectoriesRunnable::Run()
if (mCache2Dir) {
nsDeleteDir::RemoveOldTrashes(mCache2Dir);
}
#if defined(MOZ_WIDGET_ANDROID)
if (mCache2Profileless) {
// Always delete the profileless cache on Android
nsDeleteDir::DeleteDir(mCache2Profileless, true, 30000);
}
#endif
// Delete the non-active version cache data right now
if (mVersion == mActive) {