[not part of build] Changed nsCacheEntry data members from PRTime to PRUint32. Changed //** comments to // XXX to make it easier to search for 'to do' items. Added dooming of expired entries.

This commit is contained in:
gordon%netscape.com 2001-03-04 00:11:30 +00:00
parent 49b1062eb3
commit 14f776650c
11 changed files with 133 additions and 82 deletions

View File

@ -52,7 +52,7 @@ public:
virtual nsresult OnDataSizeChange( nsCacheEntry * entry, PRInt32 deltaSize ) = 0; virtual nsresult OnDataSizeChange( nsCacheEntry * entry, PRInt32 deltaSize ) = 0;
//** need to define methods for enumerating entries // XXX need to define methods for enumerating entries
}; };
#endif // _nsCacheDevice_h_ #endif // _nsCacheDevice_h_

View File

@ -30,14 +30,19 @@
#include "nsError.h" #include "nsError.h"
#include "nsICacheService.h" #include "nsICacheService.h"
#define ONE_YEAR (PR_USEC_PER_SEC * 60 * 60 * 24 * 365)
// XXX find better place to put this
// Convert PRTime to unix-style time_t, i.e. seconds since the epoch
PRUint32 ConvertPRTimeToSeconds(PRTime time64);
nsCacheEntry::nsCacheEntry(nsCString * key, nsCacheEntry::nsCacheEntry(nsCString * key,
PRBool streamBased, PRBool streamBased,
nsCacheStoragePolicy storagePolicy) nsCacheStoragePolicy storagePolicy)
: mKey(key), : mKey(key),
mFetchCount(0), mFetchCount(0),
mLastValidated(LL_ZERO), mLastValidated(0),
mExpirationTime(LL_ZERO), mExpirationTime(0),
mFlags(0), mFlags(0),
mDataSize(0), mDataSize(0),
mMetaSize(0), mMetaSize(0),
@ -49,7 +54,7 @@ nsCacheEntry::nsCacheEntry(nsCString * key,
PR_INIT_CLIST(&mRequestQ); PR_INIT_CLIST(&mRequestQ);
PR_INIT_CLIST(&mDescriptorQ); PR_INIT_CLIST(&mDescriptorQ);
mLastFetched = PR_Now(); mLastFetched = ConvertPRTimeToSeconds(PR_Now());
if (streamBased) MarkStreamBased(); if (streamBased) MarkStreamBased();
@ -225,9 +230,9 @@ nsCacheEntry::Open(nsCacheRequest * request, nsICacheEntryDescriptor ** result)
} else if (rv == NS_ERROR_CACHE_WAIT_FOR_VALIDATION) { } else if (rv == NS_ERROR_CACHE_WAIT_FOR_VALIDATION) {
// queue request // queue request
PR_APPEND_LINK(request->GetListNode(), &mRequestQ); PR_APPEND_LINK(request->GetListNode(), &mRequestQ);
//** allocate PRCondVar for request, if none // XXX allocate PRCondVar for request, if none
//** release service lock // XXX release service lock
//** wait until valid or doomed // XXX wait until valid or doomed
} }
return rv; return rv;
} }
@ -244,11 +249,11 @@ nsCacheEntry::AsyncOpen(nsCacheRequest * request)
nsICacheEntryDescriptor * descriptor; nsICacheEntryDescriptor * descriptor;
rv = nsCacheEntryDescriptor::Create(this, accessGranted, &descriptor); rv = nsCacheEntryDescriptor::Create(this, accessGranted, &descriptor);
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
//** queue the descriptor // XXX queue the descriptor
//** post event to call listener with // XXX post event to call listener with
} }
} else if (rv == NS_ERROR_CACHE_WAIT_FOR_VALIDATION) { } else if (rv == NS_ERROR_CACHE_WAIT_FOR_VALIDATION) {
//** queue request and we're done (MarkValid will notify pending requests) // XXX queue request and we're done (MarkValid will notify pending requests)
} }
return rv; return rv;
} }
@ -257,7 +262,7 @@ nsCacheEntry::AsyncOpen(nsCacheRequest * request)
PRBool PRBool
nsCacheEntry::RemoveRequest(nsCacheRequest * request) nsCacheEntry::RemoveRequest(nsCacheRequest * request)
{ {
//** if debug: verify this request belongs to this entry // XXX if debug: verify this request belongs to this entry
PR_REMOVE_AND_INIT_LINK(request->GetListNode()); PR_REMOVE_AND_INIT_LINK(request->GetListNode());
// return true if this entry should stay active // return true if this entry should stay active
@ -269,7 +274,7 @@ nsCacheEntry::RemoveRequest(nsCacheRequest * request)
PRBool PRBool
nsCacheEntry::RemoveDescriptor(nsCacheEntryDescriptor * descriptor) nsCacheEntry::RemoveDescriptor(nsCacheEntryDescriptor * descriptor)
{ {
//** if debug: verify this descriptor belongs to this entry // XXX if debug: verify this descriptor belongs to this entry
PR_REMOVE_AND_INIT_LINK(descriptor->GetListNode()); PR_REMOVE_AND_INIT_LINK(descriptor->GetListNode());
if (!PR_CLIST_IS_EMPTY(&mDescriptorQ)) if (!PR_CLIST_IS_EMPTY(&mDescriptorQ))
@ -278,7 +283,7 @@ nsCacheEntry::RemoveDescriptor(nsCacheEntryDescriptor * descriptor)
if (PR_CLIST_IS_EMPTY(&mRequestQ)) if (PR_CLIST_IS_EMPTY(&mRequestQ))
return PR_FALSE; // no descriptors or requests, we can deactivate return PR_FALSE; // no descriptors or requests, we can deactivate
//** find next best request to give a descriptor to // XXX find next best request to give a descriptor to
return PR_TRUE; return PR_TRUE;
} }
@ -363,7 +368,7 @@ nsCacheEntryHashTable::RemoveEntry( nsCacheEntry *cacheEntry)
NS_ASSERTION(initialized, "nsCacheEntryHashTable not initialized"); NS_ASSERTION(initialized, "nsCacheEntryHashTable not initialized");
if (!cacheEntry) return NS_ERROR_NULL_POINTER; if (!cacheEntry) return NS_ERROR_NULL_POINTER;
//** debug code to make sure we have the entry we're trying to remove // XXX debug code to make sure we have the entry we're trying to remove
(void) PL_DHashTableOperate(&table, cacheEntry->mKey, PL_DHASH_REMOVE); (void) PL_DHashTableOperate(&table, cacheEntry->mKey, PL_DHASH_REMOVE);
return NS_OK; return NS_OK;

View File

@ -59,23 +59,23 @@ public:
nsCString * Key(void) { return mKey; } nsCString * Key(void) { return mKey; }
PRInt32 FetchCount(void) { return mFetchCount;} PRInt32 FetchCount(void) { return mFetchCount;}
void SetFetchCount( PRInt32 count) { mFetchCount = count;} void SetFetchCount( PRInt32 count) { mFetchCount = count;}
PRTime LastFetched(void) { return mLastFetched;} PRUint32 LastFetched(void) { return mLastFetched;}
void SetLastFetched( PRTime lastFetched) { mLastFetched = lastFetched;} void SetLastFetched( PRUint32 lastFetched) { mLastFetched = lastFetched;}
PRTime LastValidated(void) { return mLastValidated;} PRUint32 LastValidated(void) { return mLastValidated;}
void SetLastValidated( PRTime lastValidated) { mLastValidated = lastValidated;} void SetLastValidated( PRUint32 lastValidated) { mLastValidated = lastValidated;}
PRTime ExpirationTime(void) { return mExpirationTime;} PRUint32 ExpirationTime(void) { return mExpirationTime;}
void SetExpirationTime( PRTime expires) { mExpirationTime = expires;} void SetExpirationTime( PRUint32 expires) { mExpirationTime = expires;}
PRUint32 DataSize(void) { return mDataSize;} PRUint32 DataSize(void) { return mDataSize;}
void SetDataSize( PRUint32 size) { mDataSize = size;} void SetDataSize( PRUint32 size) { mDataSize = size;}
PRUint32 MetaDataSize(void) { return mMetaSize;} PRUint32 MetaDataSize(void) { return mMetaSize;}
void SetMetaDataSize( PRUint32 size) { mMetaSize = size;} void SetMetaDataSize( PRUint32 size) { mMetaSize = size;}
nsCacheDevice * CacheDevice(void) { return mCacheDevice;} nsCacheDevice * CacheDevice(void) { return mCacheDevice;}
void SetCacheDevice( nsCacheDevice * device) { mCacheDevice = device;} void SetCacheDevice( nsCacheDevice * device) { mCacheDevice = device;}
@ -91,7 +91,7 @@ public:
nsresult FlattenMetaData(char ** data, PRUint32 * size); nsresult FlattenMetaData(char ** data, PRUint32 * size);
nsresult UnflattenMetaData(char * data, PRUint32 size); nsresult UnflattenMetaData(char * data, PRUint32 size);
//** enumerate MetaData method // XXX enumerate MetaData method
enum CacheEntryFlags { enum CacheEntryFlags {
@ -161,11 +161,11 @@ private:
void MarkInactive() { mFlags &= ~eActiveMask; } void MarkInactive() { mFlags &= ~eActiveMask; }
PRCList mListLink; // 8 for holding entry on various lists PRCList mListLink; // 8 for holding entry on various lists
nsCString * mKey; // 4 //** ask scc about const'ness nsCString * mKey; // 4 // XXX ask scc about const'ness
PRUint32 mFetchCount; // 4 PRUint32 mFetchCount; // 4
PRTime mLastFetched; // 8 PRUint32 mLastFetched; // 8
PRTime mLastValidated; // 8 PRUint32 mLastValidated; // 8
PRTime mExpirationTime; // 8 PRUint32 mExpirationTime; // 8
PRUint32 mFlags; // 4 PRUint32 mFlags; // 4
PRUint32 mDataSize; // 4 PRUint32 mDataSize; // 4
PRUint32 mMetaSize; // 4 PRUint32 mMetaSize; // 4
@ -194,7 +194,7 @@ public:
nsCacheEntry *GetEntry( const nsCString * key); nsCacheEntry *GetEntry( const nsCString * key);
nsresult AddEntry( nsCacheEntry *entry); nsresult AddEntry( nsCacheEntry *entry);
nsresult RemoveEntry( nsCacheEntry *entry); nsresult RemoveEntry( nsCacheEntry *entry);
//** enumerate entries? // XXX enumerate entries?
private: private:

View File

@ -114,7 +114,7 @@ nsCacheEntryDescriptor::GetLastFetched(PRTime *result)
NS_ENSURE_ARG_POINTER(result); NS_ENSURE_ARG_POINTER(result);
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
*result = mCacheEntry->LastFetched(); *result = ConvertSecondsToPRTime(mCacheEntry->LastFetched());
return NS_OK; return NS_OK;
} }
@ -125,7 +125,7 @@ nsCacheEntryDescriptor::GetLastValidated(PRTime *result)
NS_ENSURE_ARG_POINTER(result); NS_ENSURE_ARG_POINTER(result);
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
*result = mCacheEntry->LastValidated(); *result = ConvertSecondsToPRTime(mCacheEntry->LastValidated());
return NS_OK; return NS_OK;
} }
@ -136,7 +136,7 @@ nsCacheEntryDescriptor::GetExpirationTime(PRTime *result)
NS_ENSURE_ARG_POINTER(result); NS_ENSURE_ARG_POINTER(result);
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
*result = mCacheEntry->ExpirationTime(); *result = ConvertSecondsToPRTime(mCacheEntry->ExpirationTime());
return NS_OK; return NS_OK;
} }
@ -146,7 +146,7 @@ nsCacheEntryDescriptor::SetExpirationTime(PRTime expirationTime)
{ {
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
mCacheEntry->SetExpirationTime(expirationTime); mCacheEntry->SetExpirationTime(ConvertPRTimeToSeconds(expirationTime));
return NS_OK; return NS_OK;
} }
@ -156,7 +156,7 @@ NS_IMETHODIMP nsCacheEntryDescriptor::IsStreamBased(PRBool *result)
NS_ENSURE_ARG_POINTER(result); NS_ENSURE_ARG_POINTER(result);
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
*result = mCacheEntry->IsStreamData(); //** which name is better? *result = mCacheEntry->IsStreamData(); // XXX which name is better?
return NS_OK; return NS_OK;
} }
@ -177,7 +177,7 @@ nsCacheEntryDescriptor::RequestDataSizeChange(PRInt32 deltaSize)
nsresult rv; nsresult rv;
rv = nsCacheService::GlobalInstance()->OnDataSizeChange(mCacheEntry, deltaSize); rv = nsCacheService::GlobalInstance()->OnDataSizeChange(mCacheEntry, deltaSize);
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
//** review for signed/unsigned math errors // XXX review for signed/unsigned math errors
PRUint32 newDataSize = mCacheEntry->DataSize() + deltaSize; PRUint32 newDataSize = mCacheEntry->DataSize() + deltaSize;
mCacheEntry->SetDataSize(newDataSize); mCacheEntry->SetDataSize(newDataSize);
} }
@ -190,7 +190,7 @@ nsCacheEntryDescriptor::SetDataSize(PRUint32 dataSize)
{ {
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
//** review for signed/unsigned math errors // XXX review for signed/unsigned math errors
PRInt32 deltaSize = dataSize - mCacheEntry->DataSize(); PRInt32 deltaSize = dataSize - mCacheEntry->DataSize();
// this had better be NS_OK, this call instance is advisory // this had better be NS_OK, this call instance is advisory
@ -328,7 +328,7 @@ nsCacheEntryDescriptor::SetMetaDataElement(const char *key, const char *value)
if (!key) return NS_ERROR_NULL_POINTER; if (!key) return NS_ERROR_NULL_POINTER;
//** allow null value, for clearing key? // XXX allow null value, for clearing key?
nsresult rv = mCacheEntry->SetMetaDataElement(nsLiteralCString(key), nsresult rv = mCacheEntry->SetMetaDataElement(nsLiteralCString(key),
nsLiteralCString(value)); nsLiteralCString(value));
return rv; return rv;
@ -483,7 +483,7 @@ nsCacheOutputStream::WriteSegments(nsReadSegmentFun reader, void * closure, PRUi
nsresult nsresult
nsCacheOutputStream::OnWrite(PRUint32 count) nsCacheOutputStream::OnWrite(PRUint32 count)
{ {
//** if count > 2^31 error_write_too_big // XXX if count > 2^31 error_write_too_big
return mDescriptor->RequestDataSizeChange((PRInt32)count); return mDescriptor->RequestDataSizeChange((PRInt32)count);
#if 0 #if 0

View File

@ -50,7 +50,6 @@ nsCacheMetaData::nsCacheMetaData()
nsCacheMetaData::~nsCacheMetaData() nsCacheMetaData::~nsCacheMetaData()
{ {
//** maybe we should finalize the table...
PL_DHashTableFinish(&table); PL_DHashTableFinish(&table);
} }
@ -90,8 +89,8 @@ nsCacheMetaData::GetElement(const nsAReadableCString * key)
PLDHashEntryHdr * hashEntry; PLDHashEntryHdr * hashEntry;
nsCString * result = nsnull; nsCString * result = nsnull;
//** need to copy string until we have scc's new flat string abstract class // XXX need to copy string until we have scc's new flat string abstract class
//** see nsCacheMetaData::HashKey below (bug 70075) // XXX see nsCacheMetaData::HashKey below (bug 70075)
nsCString * tempKey = new nsCString(*key); nsCString * tempKey = new nsCString(*key);
if (!tempKey) return result; if (!tempKey) return result;
@ -114,12 +113,12 @@ nsCacheMetaData::SetElement(const nsAReadableCString& key,
NS_ASSERTION(initialized, "nsCacheMetaDataHashTable not initialized"); NS_ASSERTION(initialized, "nsCacheMetaDataHashTable not initialized");
//** need to copy string until we have scc's new flat string abstract class // XXX need to copy string until we have scc's new flat string abstract class
//** see nsCacheMetaData::HashKey below (bug 70075) // XXX see nsCacheMetaData::HashKey below (bug 70075)
nsCString * tempKey = new nsCString(key); nsCString * tempKey = new nsCString(key);
if (!tempKey) return NS_ERROR_OUT_OF_MEMORY; if (!tempKey) return NS_ERROR_OUT_OF_MEMORY;
//** should empty value remove the key? // XXX should empty value remove the key?
metaEntry = (nsCacheMetaDataHashTableEntry *) metaEntry = (nsCacheMetaDataHashTableEntry *)
PL_DHashTableOperate(&table, tempKey, PL_DHASH_ADD); PL_DHashTableOperate(&table, tempKey, PL_DHASH_ADD);
@ -135,7 +134,7 @@ nsCacheMetaData::SetElement(const nsAReadableCString& key,
metaEntry->value = new nsCString(value); metaEntry->value = new nsCString(value);
if (metaEntry->value == nsnull) { if (metaEntry->value == nsnull) {
//** remove key? // XXX remove key?
delete tempKey; delete tempKey;
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
} }
@ -195,7 +194,7 @@ nsCacheMetaData::GetKey( PLDHashTable * /* table */, PLDHashEntryHdr *hashEntry)
PLDHashNumber PLDHashNumber
nsCacheMetaData::HashKey( PLDHashTable * table, const void *key) nsCacheMetaData::HashKey( PLDHashTable * table, const void *key)
{ {
//** need scc's new flat string abstract class here (bug 70075) // XXX need scc's new flat string abstract class here (bug 70075)
return PL_DHashStringKey(table, ((nsCString *)key)->get()); return PL_DHashStringKey(table, ((nsCString *)key)->get());
} }

View File

@ -53,10 +53,10 @@ private:
PR_INIT_CLIST(&mListLink); PR_INIT_CLIST(&mListLink);
} }
virtual ~nsCacheRequest() ~nsCacheRequest()
{ {
// delete mKey; delete mKey;
// XXX need to do anything with mListLink? NS_ASSERTION(PR_CLIST_IS_EMPTY(&mListLink), "request still on a list");
} }

View File

@ -112,9 +112,9 @@ nsCacheService::Shutdown()
"can't shutdown nsCacheService unless it has been initialized."); "can't shutdown nsCacheService unless it has been initialized.");
if (mCacheServiceLock) { if (mCacheServiceLock) {
//** check for pending requests... // XXX check for pending requests...
//** finalize active entries // XXX finalize active entries
// deallocate memory and disk caches // deallocate memory and disk caches
delete mMemoryDevice; delete mMemoryDevice;
@ -221,12 +221,12 @@ nsCacheService::OpenCacheEntry(nsCacheSession * session,
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
while (1) { while (1) {
//** acquire lock // XXX acquire lock
rv = ActivateEntry(request, &entry); rv = ActivateEntry(request, &entry);
if (NS_FAILED(rv)) break; if (NS_FAILED(rv)) break;
//** check for NS_ERROR_CACHE_KEY_NOT_FOUND & READ-ONLY request // XXX check for NS_ERROR_CACHE_KEY_NOT_FOUND & READ-ONLY request
rv = entry->Open(request, result); //** release lock before waiting on request rv = entry->Open(request, result); // XXX release lock before waiting on request
if (rv != NS_ERROR_CACHE_ENTRY_DOOMED) break; if (rv != NS_ERROR_CACHE_ENTRY_DOOMED) break;
} }
@ -250,10 +250,10 @@ nsCacheService::AsyncOpenCacheEntry(nsCacheSession * session,
nsresult rv = CreateRequest(session, key, accessRequested, listener, &request); nsresult rv = CreateRequest(session, key, accessRequested, listener, &request);
//** acquire service lock PR_Lock(mCacheServiceLock); // XXX acquire service lock PR_Lock(mCacheServiceLock);
rv = ActivateEntry(request, &entry); rv = ActivateEntry(request, &entry);
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
entry->AsyncOpen(request); //** release lock after request queued, etc. entry->AsyncOpen(request); // XXX release lock after request queued, etc.
} }
return rv; return rv;
@ -286,11 +286,16 @@ nsCacheService::ActivateEntry(nsCacheRequest * request,
goto error; goto error;
} }
if (entry && (request->mAccessRequested == nsICache::ACCESS_WRITE)) { if (entry &&
// this is FORCE-WRITE request ((request->mAccessRequested == nsICache::ACCESS_WRITE) ||
(entry->mExpirationTime &&
entry->mExpirationTime < ConvertPRTimeToSeconds(PR_Now()))))
// XXX beginning to look a lot like lisp
{
// this is FORCE-WRITE request or the entry has expired
rv = DoomEntry_Internal(entry); rv = DoomEntry_Internal(entry);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
//** what to do? // XXX what to do? Increment FailedDooms counter?
} }
if (entry->IsNotInUse()) { if (entry->IsNotInUse()) {
@ -306,7 +311,7 @@ nsCacheService::ActivateEntry(nsCacheRequest * request,
if (!entry) if (!entry)
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
//** we could perform an early bind in some cases based on storage policy // XXX we could perform an early bind in some cases based on storage policy
} }
rv = mActiveEntries.AddEntry(entry); rv = mActiveEntries.AddEntry(entry);
@ -319,7 +324,7 @@ nsCacheService::ActivateEntry(nsCacheRequest * request,
error: error:
*result = nsnull; *result = nsnull;
if (entry) { if (entry) {
//** clean up // XXX clean up
} }
return rv; return rv;
} }
@ -368,8 +373,8 @@ nsCacheService::BindEntry(nsCacheEntry * entry)
nsresult nsresult
nsCacheService::ValidateEntry(nsCacheEntry * entry) nsCacheService::ValidateEntry(nsCacheEntry * entry)
{ {
//** bind if not bound // XXX bind if not bound
//** convert pending requests to descriptors, etc. // XXX convert pending requests to descriptors, etc.
entry->MarkValid(); entry->MarkValid();
return NS_OK; return NS_OK;
} }
@ -394,7 +399,7 @@ nsCacheService::DoomEntry_Internal(nsCacheEntry * entry)
nsCacheDevice * device = entry->CacheDevice(); nsCacheDevice * device = entry->CacheDevice();
if (device) { if (device) {
rv = device->DoomEntry(entry); rv = device->DoomEntry(entry);
//** check rv, but what can we really do... // XXX check rv, but what can we really do...
} }
if (entry->IsActive()) { if (entry->IsActive()) {
@ -402,7 +407,7 @@ nsCacheService::DoomEntry_Internal(nsCacheEntry * entry)
rv = mActiveEntries.RemoveEntry(entry); rv = mActiveEntries.RemoveEntry(entry);
entry->MarkInactive(); entry->MarkInactive();
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
//** what to do // XXX what to do
} }
} }
// put on doom list to wait for descriptors to close // put on doom list to wait for descriptors to close
@ -497,3 +502,30 @@ nsCacheService::DeactivateEntry(nsCacheEntry * entry)
delete entry; // because no one else will delete entry; // because no one else will
} }
} }
/**
* Cache Service Utility Functions
*/
// time conversion utils from nsCachedNetData.cpp
// Convert PRTime to unix-style time_t, i.e. seconds since the epoch
PRUint32
ConvertPRTimeToSeconds(PRTime time64)
{
double fpTime;
LL_L2D(fpTime, time64);
return (PRUint32)(fpTime * 1e-6 + 0.5);
}
// Convert unix-style time_t, i.e. seconds since the epoch, to PRTime
PRTime
ConvertSecondsToPRTime(PRUint32 seconds)
{
PRInt64 t64;
LL_I2L(t64, seconds);
PRInt64 mil;
LL_I2L(mil, 1000000);
LL_MUL(t64, t64, mil);
return t64;
}

View File

@ -137,4 +137,16 @@ private:
}; };
/**
* Cache Service Utility Functions
*/
// time conversion utils from nsCachedNetData.cpp
// Convert PRTime to unix-style time_t, i.e. seconds since the epoch
PRUint32 ConvertPRTimeToSeconds(PRTime time64);
// Convert unix-style time_t, i.e. seconds since the epoch, to PRTime
PRTime ConvertSecondsToPRTime(PRUint32 seconds);
#endif // _nsCacheService_h_ #endif // _nsCacheService_h_

View File

@ -148,6 +148,8 @@ private:
}; };
NS_IMPL_ISUPPORTS0(DiskCacheEntry); NS_IMPL_ISUPPORTS0(DiskCacheEntry);
#if 0
// get rid of warning on linux until this routine is used.
static DiskCacheEntry* static DiskCacheEntry*
getDiskCacheEntry(nsCacheEntry * entry) getDiskCacheEntry(nsCacheEntry * entry)
{ {
@ -155,6 +157,7 @@ getDiskCacheEntry(nsCacheEntry * entry)
entry->GetData(getter_AddRefs(data)); entry->GetData(getter_AddRefs(data));
return (DiskCacheEntry*) data.get(); return (DiskCacheEntry*) data.get();
} }
#endif
static DiskCacheEntry* static DiskCacheEntry*
ensureDiskCacheEntry(nsCacheEntry * entry) ensureDiskCacheEntry(nsCacheEntry * entry)
@ -240,7 +243,7 @@ nsDiskCacheDevice::FindEntry(nsCString * key)
} }
} }
//** find eviction element and move it to the tail of the queue // XXX find eviction element and move it to the tail of the queue
return entry; return entry;
} }
@ -428,9 +431,9 @@ nsresult nsDiskCacheDevice::scanEntries()
struct MetaDataHeader { struct MetaDataHeader {
PRUint32 mHeaderSize; PRUint32 mHeaderSize;
PRInt32 mFetchCount; PRInt32 mFetchCount;
PRTime mLastFetched; PRUint32 mLastFetched;
PRTime mLastValidated; // NOT NEEDED PRUint32 mLastValidated; // NOT NEEDED
PRTime mExpirationTime; PRUint32 mExpirationTime;
PRUint32 mDataSize; PRUint32 mDataSize;
PRUint32 mKeySize; PRUint32 mKeySize;
PRUint32 mMetaDataSize; PRUint32 mMetaDataSize;
@ -714,4 +717,4 @@ nsresult nsDiskCacheDevice::deleteDiskCacheEntry(nsCacheEntry* entry)
return NS_OK; return NS_OK;
} }
//** need methods for enumerating entries // XXX need methods for enumerating entries

View File

@ -36,7 +36,7 @@ nsMemoryCacheDevice::nsMemoryCacheDevice()
nsMemoryCacheDevice::~nsMemoryCacheDevice() nsMemoryCacheDevice::~nsMemoryCacheDevice()
{ {
//** dealloc all memory // XXX dealloc all memory
} }
@ -47,7 +47,7 @@ nsMemoryCacheDevice::Init()
rv = mMemCacheEntries.Init(); rv = mMemCacheEntries.Init();
//** read user prefs for memory cache limits // XXX read user prefs for memory cache limits
return rv; return rv;
} }
@ -79,7 +79,7 @@ nsMemoryCacheDevice::DeactivateEntry(nsCacheEntry * entry)
{ {
if (entry->IsDoomed()) { if (entry->IsDoomed()) {
#if debug #if debug
//** verify we've removed it from mMemCacheEntries & eviction list // XXX verify we've removed it from mMemCacheEntries & eviction list
#endif #endif
delete entry; delete entry;
return NS_OK; return NS_OK;
@ -110,7 +110,7 @@ nsMemoryCacheDevice::BindEntry(nsCacheEntry * entry)
return rv; return rv;
} }
//** add size of entry to memory totals // XXX add size of entry to memory totals
return NS_OK; return NS_OK;
} }
@ -161,11 +161,11 @@ nsMemoryCacheDevice::GetTransportForEntry( nsCacheEntry * entry,
nsresult nsresult
nsMemoryCacheDevice::OnDataSizeChange( nsCacheEntry * entry, PRInt32 deltaSize) nsMemoryCacheDevice::OnDataSizeChange( nsCacheEntry * entry, PRInt32 deltaSize)
{ {
//** keep track of totals // XXX keep track of totals
return NS_OK; return NS_OK;
} }
//** need methods for enumerating entries // XXX need methods for enumerating entries
//** check entry->IsInUse() before evicting. // XXX check entry->IsInUse() before evicting.

View File

@ -59,7 +59,7 @@ private:
PRCList mEvictionList; PRCList mEvictionList;
//** what other stats do we want to keep? // XXX what other stats do we want to keep?
}; };