зеркало из https://github.com/mozilla/pjs.git
[not part of build] stub implementation of Visit().
This commit is contained in:
Родитель
80bc39fade
Коммит
047c50bec3
|
@ -31,7 +31,7 @@
|
|||
|
||||
|
||||
class nsCacheEntry;
|
||||
|
||||
class nsICacheVisitor;
|
||||
|
||||
class nsCacheDevice {
|
||||
public:
|
||||
|
@ -53,6 +53,8 @@ public:
|
|||
virtual nsresult OnDataSizeChange( nsCacheEntry * entry, PRInt32 deltaSize ) = 0;
|
||||
|
||||
// XXX need to define methods for enumerating entries
|
||||
|
||||
virtual nsresult Visit(nsICacheVisitor * visitor) = 0;
|
||||
};
|
||||
|
||||
#endif // _nsCacheDevice_h_
|
||||
|
|
|
@ -45,6 +45,8 @@ static const char CACHE_DIR_PREF[] = { "browser.newcache.directory" };
|
|||
static const char CACHE_DIR_PREF[] = { "browser.cache.directory" };
|
||||
#endif
|
||||
|
||||
static const char CACHE_DISK_CAPACITY[] = { "browser.cache.disk_cache_size" };
|
||||
|
||||
static int PR_CALLBACK cacheDirectoryChanged(const char *pref, void *closure)
|
||||
{
|
||||
nsresult rv;
|
||||
|
@ -63,13 +65,50 @@ static int PR_CALLBACK cacheDirectoryChanged(const char *pref, void *closure)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
static int PR_CALLBACK cacheCapacityChanged(const char *pref, void *closure)
|
||||
{
|
||||
nsresult rv;
|
||||
NS_WITH_SERVICE(nsIPref, prefs, NS_PREF_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
PRInt32 cacheCapacity;
|
||||
rv = prefs->GetIntPref(CACHE_DISK_CAPACITY, &cacheCapacity);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsDiskCacheDevice* device = NS_STATIC_CAST(nsDiskCacheDevice*, closure);
|
||||
device->setCacheCapacity(cacheCapacity);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static nsresult installPrefListeners(nsDiskCacheDevice* device)
|
||||
{
|
||||
nsresult rv;
|
||||
NS_WITH_SERVICE(nsIPref, prefs, NS_PREF_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
rv = prefs->RegisterCallback(CACHE_DIR_PREF, cacheDirectoryChanged, device);
|
||||
|
||||
|
||||
rv = prefs->RegisterCallback(CACHE_DISK_CAPACITY, cacheCapacityChanged, device);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
PRInt32 cacheCapacity;
|
||||
rv = prefs->GetIntPref(CACHE_DISK_CAPACITY, &cacheCapacity);
|
||||
if (NS_FAILED(rv)) {
|
||||
#if DEBUG
|
||||
const kTenMegabytes = 10 * 1024 * 1024;
|
||||
rv = prefs->SetIntPref(CACHE_DISK_CAPACITY, kTenMegabytes);
|
||||
#else
|
||||
return rv;
|
||||
#endif
|
||||
} else {
|
||||
device->setCacheCapacity(cacheCapacity);
|
||||
}
|
||||
|
||||
rv = prefs->RegisterCallback(CACHE_DIR_PREF, cacheDirectoryChanged, device);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
|
@ -91,6 +130,12 @@ static nsresult installPrefListeners(nsDiskCacheDevice* device)
|
|||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
// make sure the Cache directory exists.
|
||||
PRBool exists;
|
||||
rv = cacheDirectory->Exists(&exists);
|
||||
if (NS_SUCCEEDED(rv) && !exists)
|
||||
cacheDirectory->Create(nsIFile::DIRECTORY_TYPE, 0777);
|
||||
|
||||
rv = prefs->SetFileXPref(CACHE_DIR_PREF, cacheDirectory);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
@ -185,7 +230,7 @@ ensureDiskCacheEntry(nsCacheEntry * entry)
|
|||
// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
|
||||
|
||||
nsDiskCacheDevice::nsDiskCacheDevice()
|
||||
: mScannedEntries(PR_FALSE), mTotalCachedDataSize(LL_ZERO)
|
||||
: mScannedEntries(PR_FALSE), mCacheCapacity(0), mCacheSize(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -347,21 +392,25 @@ nsDiskCacheDevice::GetTransportForEntry(nsCacheEntry * entry,
|
|||
nsresult
|
||||
nsDiskCacheDevice::OnDataSizeChange(nsCacheEntry * entry, PRInt32 deltaSize)
|
||||
{
|
||||
PRInt64 deltaSize64;
|
||||
LL_I2L(deltaSize64, deltaSize);
|
||||
LL_ADD(mTotalCachedDataSize, mTotalCachedDataSize, deltaSize64);
|
||||
mCacheSize += deltaSize;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsDiskCacheDevice::Visit(nsICacheVisitor * visitor)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void nsDiskCacheDevice::setCacheDirectory(nsILocalFile* cacheDirectory)
|
||||
{
|
||||
mCacheDirectory = cacheDirectory;
|
||||
}
|
||||
|
||||
// make sure the Cache directory exists.
|
||||
PRBool exists;
|
||||
nsresult rv = cacheDirectory->Exists(&exists);
|
||||
if (NS_SUCCEEDED(rv) && !exists)
|
||||
cacheDirectory->Create(nsIFile::DIRECTORY_TYPE, 0777);
|
||||
void nsDiskCacheDevice::setCacheCapacity(PRUint32 capacity)
|
||||
{
|
||||
// XXX start evicting entries if the new size is smaller!
|
||||
mCacheCapacity = capacity;
|
||||
}
|
||||
|
||||
nsresult nsDiskCacheDevice::getFileForKey(const char* key, PRBool meta, nsIFile ** result)
|
||||
|
|
|
@ -49,9 +49,12 @@ public:
|
|||
nsITransport ** result);
|
||||
|
||||
virtual nsresult OnDataSizeChange(nsCacheEntry * entry, PRInt32 deltaSize);
|
||||
|
||||
virtual nsresult Visit(nsICacheVisitor * visitor);
|
||||
|
||||
/* private: */
|
||||
void setCacheDirectory(nsILocalFile* directory);
|
||||
void setCacheCapacity(PRUint32 capacity);
|
||||
|
||||
private:
|
||||
nsresult getFileForKey(const char* key, PRBool meta, nsIFile**);
|
||||
|
@ -63,10 +66,11 @@ private:
|
|||
nsresult deleteDiskCacheEntry(nsCacheEntry* entry);
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsILocalFile> mCacheDirectory;
|
||||
nsCacheEntryHashTable mBoundEntries;
|
||||
PRBool mScannedEntries;
|
||||
PRUint64 mTotalCachedDataSize;
|
||||
nsCOMPtr<nsILocalFile> mCacheDirectory;
|
||||
nsCacheEntryHashTable mBoundEntries;
|
||||
PRBool mScannedEntries;
|
||||
PRUint32 mCacheCapacity;
|
||||
PRUint32 mCacheSize;
|
||||
};
|
||||
|
||||
#endif // _nsDiskCacheDevice_h_
|
||||
|
|
|
@ -214,6 +214,13 @@ nsMemoryCacheDevice::OnDataSizeChange( nsCacheEntry * entry, PRInt32 deltaSize)
|
|||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsMemoryCacheDevice::Visit(nsICacheVisitor * visitor)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsMemoryCacheDevice::AdjustMemoryLimits(PRUint32 softLimit, PRUint32 hardLimit)
|
||||
{
|
||||
|
|
|
@ -50,6 +50,8 @@ public:
|
|||
|
||||
virtual nsresult OnDataSizeChange( nsCacheEntry * entry, PRInt32 deltaSize );
|
||||
|
||||
virtual nsresult Visit( nsICacheVisitor * visitor );
|
||||
|
||||
static int PR_CALLBACK MemoryCacheSizeChanged(const char * pref, void * closure);
|
||||
|
||||
private:
|
||||
|
|
Загрузка…
Ссылка в новой задаче