[not part of build] stub implementation of Visit().

This commit is contained in:
beard%netscape.com 2001-03-08 21:00:02 +00:00
Родитель 80bc39fade
Коммит 047c50bec3
5 изменённых файлов: 79 добавлений и 15 удалений

4
netwerk/cache/src/nsCacheDevice.h поставляемый
Просмотреть файл

@ -31,7 +31,7 @@
class nsCacheEntry; class nsCacheEntry;
class nsICacheVisitor;
class nsCacheDevice { class nsCacheDevice {
public: public:
@ -53,6 +53,8 @@ public:
virtual nsresult OnDataSizeChange( nsCacheEntry * entry, PRInt32 deltaSize ) = 0; virtual nsresult OnDataSizeChange( nsCacheEntry * entry, PRInt32 deltaSize ) = 0;
// XXX need to define methods for enumerating entries // XXX need to define methods for enumerating entries
virtual nsresult Visit(nsICacheVisitor * visitor) = 0;
}; };
#endif // _nsCacheDevice_h_ #endif // _nsCacheDevice_h_

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

@ -45,6 +45,8 @@ static const char CACHE_DIR_PREF[] = { "browser.newcache.directory" };
static const char CACHE_DIR_PREF[] = { "browser.cache.directory" }; static const char CACHE_DIR_PREF[] = { "browser.cache.directory" };
#endif #endif
static const char CACHE_DISK_CAPACITY[] = { "browser.cache.disk_cache_size" };
static int PR_CALLBACK cacheDirectoryChanged(const char *pref, void *closure) static int PR_CALLBACK cacheDirectoryChanged(const char *pref, void *closure)
{ {
nsresult rv; nsresult rv;
@ -63,13 +65,50 @@ static int PR_CALLBACK cacheDirectoryChanged(const char *pref, void *closure)
return NS_OK; 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) static nsresult installPrefListeners(nsDiskCacheDevice* device)
{ {
nsresult rv; nsresult rv;
NS_WITH_SERVICE(nsIPref, prefs, NS_PREF_CONTRACTID, &rv); NS_WITH_SERVICE(nsIPref, prefs, NS_PREF_CONTRACTID, &rv);
if (NS_FAILED(rv)) if (NS_FAILED(rv))
return 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)) if (NS_FAILED(rv))
return rv; return rv;
@ -91,6 +130,12 @@ static nsresult installPrefListeners(nsDiskCacheDevice* device)
if (NS_FAILED(rv)) if (NS_FAILED(rv))
return 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); rv = prefs->SetFileXPref(CACHE_DIR_PREF, cacheDirectory);
if (NS_FAILED(rv)) if (NS_FAILED(rv))
return rv; return rv;
@ -185,7 +230,7 @@ ensureDiskCacheEntry(nsCacheEntry * entry)
// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
nsDiskCacheDevice::nsDiskCacheDevice() nsDiskCacheDevice::nsDiskCacheDevice()
: mScannedEntries(PR_FALSE), mTotalCachedDataSize(LL_ZERO) : mScannedEntries(PR_FALSE), mCacheCapacity(0), mCacheSize(0)
{ {
} }
@ -347,21 +392,25 @@ nsDiskCacheDevice::GetTransportForEntry(nsCacheEntry * entry,
nsresult nsresult
nsDiskCacheDevice::OnDataSizeChange(nsCacheEntry * entry, PRInt32 deltaSize) nsDiskCacheDevice::OnDataSizeChange(nsCacheEntry * entry, PRInt32 deltaSize)
{ {
PRInt64 deltaSize64; mCacheSize += deltaSize;
LL_I2L(deltaSize64, deltaSize); return NS_OK;
LL_ADD(mTotalCachedDataSize, mTotalCachedDataSize, deltaSize64); }
nsresult
nsDiskCacheDevice::Visit(nsICacheVisitor * visitor)
{
return NS_OK; return NS_OK;
} }
void nsDiskCacheDevice::setCacheDirectory(nsILocalFile* cacheDirectory) void nsDiskCacheDevice::setCacheDirectory(nsILocalFile* cacheDirectory)
{ {
mCacheDirectory = cacheDirectory; mCacheDirectory = cacheDirectory;
}
// make sure the Cache directory exists. void nsDiskCacheDevice::setCacheCapacity(PRUint32 capacity)
PRBool exists; {
nsresult rv = cacheDirectory->Exists(&exists); // XXX start evicting entries if the new size is smaller!
if (NS_SUCCEEDED(rv) && !exists) mCacheCapacity = capacity;
cacheDirectory->Create(nsIFile::DIRECTORY_TYPE, 0777);
} }
nsresult nsDiskCacheDevice::getFileForKey(const char* key, PRBool meta, nsIFile ** result) nsresult nsDiskCacheDevice::getFileForKey(const char* key, PRBool meta, nsIFile ** result)

12
netwerk/cache/src/nsDiskCacheDevice.h поставляемый
Просмотреть файл

@ -49,9 +49,12 @@ public:
nsITransport ** result); nsITransport ** result);
virtual nsresult OnDataSizeChange(nsCacheEntry * entry, PRInt32 deltaSize); virtual nsresult OnDataSizeChange(nsCacheEntry * entry, PRInt32 deltaSize);
virtual nsresult Visit(nsICacheVisitor * visitor);
/* private: */ /* private: */
void setCacheDirectory(nsILocalFile* directory); void setCacheDirectory(nsILocalFile* directory);
void setCacheCapacity(PRUint32 capacity);
private: private:
nsresult getFileForKey(const char* key, PRBool meta, nsIFile**); nsresult getFileForKey(const char* key, PRBool meta, nsIFile**);
@ -63,10 +66,11 @@ private:
nsresult deleteDiskCacheEntry(nsCacheEntry* entry); nsresult deleteDiskCacheEntry(nsCacheEntry* entry);
private: private:
nsCOMPtr<nsILocalFile> mCacheDirectory; nsCOMPtr<nsILocalFile> mCacheDirectory;
nsCacheEntryHashTable mBoundEntries; nsCacheEntryHashTable mBoundEntries;
PRBool mScannedEntries; PRBool mScannedEntries;
PRUint64 mTotalCachedDataSize; PRUint32 mCacheCapacity;
PRUint32 mCacheSize;
}; };
#endif // _nsDiskCacheDevice_h_ #endif // _nsDiskCacheDevice_h_

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

@ -214,6 +214,13 @@ nsMemoryCacheDevice::OnDataSizeChange( nsCacheEntry * entry, PRInt32 deltaSize)
} }
nsresult
nsMemoryCacheDevice::Visit(nsICacheVisitor * visitor)
{
return NS_OK;
}
nsresult nsresult
nsMemoryCacheDevice::AdjustMemoryLimits(PRUint32 softLimit, PRUint32 hardLimit) nsMemoryCacheDevice::AdjustMemoryLimits(PRUint32 softLimit, PRUint32 hardLimit)
{ {

2
netwerk/cache/src/nsMemoryCacheDevice.h поставляемый
Просмотреть файл

@ -50,6 +50,8 @@ public:
virtual nsresult OnDataSizeChange( nsCacheEntry * entry, PRInt32 deltaSize ); virtual nsresult OnDataSizeChange( nsCacheEntry * entry, PRInt32 deltaSize );
virtual nsresult Visit( nsICacheVisitor * visitor );
static int PR_CALLBACK MemoryCacheSizeChanged(const char * pref, void * closure); static int PR_CALLBACK MemoryCacheSizeChanged(const char * pref, void * closure);
private: private: