Bug 922081 - respect browser.cache.disk.parent_directory preference in the new cache, r=michal

This commit is contained in:
Honza Bambas 2014-02-27 00:11:38 +01:00
Родитель 811f3e58f6
Коммит 7d882ef618
3 изменённых файлов: 36 добавлений и 4 удалений

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

@ -1208,9 +1208,11 @@ CacheFileIOManager::OnProfile()
nsCOMPtr<nsIFile> directory;
CacheObserver::ParentDirOverride(getter_AddRefs(directory));
#if defined(MOZ_WIDGET_ANDROID)
char* cachePath = getenv("CACHE_DIRECTORY");
if (cachePath && *cachePath) {
if (!directory && cachePath && *cachePath) {
rv = NS_NewNativeLocalFile(nsDependentCString(cachePath),
true, getter_AddRefs(directory));
}
@ -1229,11 +1231,13 @@ CacheFileIOManager::OnProfile()
if (directory) {
rv = directory->Append(NS_LITERAL_STRING("cache2"));
NS_ENSURE_SUCCESS(rv, rv);
}
rv = directory->Clone(getter_AddRefs(ioMan->mCacheDirectory));
NS_ENSURE_SUCCESS(rv, rv);
// All functions return a clone.
ioMan->mCacheDirectory.swap(directory);
CacheIndex::Init(directory);
if (ioMan->mCacheDirectory) {
CacheIndex::Init(ioMan->mCacheDirectory);
}
return NS_OK;

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

@ -59,6 +59,7 @@ NS_IMPL_ISUPPORTS2(CacheObserver,
nsIObserver,
nsISupportsWeakReference)
// static
nsresult
CacheObserver::Init()
{
@ -86,6 +87,7 @@ CacheObserver::Init()
return NS_OK;
}
// static
nsresult
CacheObserver::Shutdown()
{
@ -128,6 +130,10 @@ CacheObserver::AttachToPreferences()
mozilla::Preferences::AddUintVarCache(
&sCompressionLevel, "browser.cache.compression_level", kDefaultCompressionLevel);
mozilla::Preferences::GetComplex(
"browser.cache.disk.parent_directory", NS_GET_IID(nsIFile),
getter_AddRefs(mCacheParentDirectoryOverride));
sHalfLifeExperiment = mozilla::Preferences::GetInt(
"browser.cache.frecency_experiment", kDefaultHalfLifeExperiment);
@ -198,6 +204,22 @@ bool const CacheObserver::UseNewCache()
return true;
}
// static
void CacheObserver::ParentDirOverride(nsIFile** aDir)
{
if (NS_WARN_IF(!aDir))
return;
*aDir = nullptr;
if (!sSelf)
return;
if (!sSelf->mCacheParentDirectoryOverride)
return;
sSelf->mCacheParentDirectoryOverride->Clone(aDir);
}
namespace { // anon
class CacheStorageEvictHelper

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

@ -6,6 +6,8 @@
#define CacheObserver__h__
#include "nsIObserver.h"
#include "nsIFile.h"
#include "nsCOMPtr.h"
#include "nsWeakReference.h"
#include <algorithm>
@ -44,6 +46,7 @@ class CacheObserver : public nsIObserver
{ return sHalfLifeHours * 60 * 60; }
static int32_t const HalfLifeExperiment()
{ return sHalfLifeExperiment; }
static void ParentDirOverride(nsIFile ** aDir);
static bool const EntryIsTooBig(int64_t aSize, bool aUsingDisk);
@ -63,6 +66,9 @@ private:
static uint32_t sCompressionLevel;
static uint32_t sHalfLifeHours;
static int32_t sHalfLifeExperiment;
// Non static properties, accessible via sSelf
nsCOMPtr<nsIFile> mCacheParentDirectoryOverride;
};
} // net