2001-02-23 13:18:01 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
|
|
|
*
|
|
|
|
* The Original Code is nsCacheEntry.cpp, released February 22, 2001.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape Communications
|
|
|
|
* Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 2001 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Gordon Sheridan, 22-February-2001
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "nspr.h"
|
|
|
|
#include "nsCacheEntry.h"
|
|
|
|
#include "nsCacheEntryDescriptor.h"
|
|
|
|
#include "nsCacheMetaData.h"
|
|
|
|
#include "nsCacheRequest.h"
|
|
|
|
#include "nsError.h"
|
|
|
|
#include "nsICacheService.h"
|
|
|
|
|
2001-03-04 00:11:30 +00:00
|
|
|
|
|
|
|
// XXX find better place to put this
|
|
|
|
// Convert PRTime to unix-style time_t, i.e. seconds since the epoch
|
|
|
|
PRUint32 ConvertPRTimeToSeconds(PRTime time64);
|
|
|
|
|
|
|
|
|
2001-02-28 03:54:16 +00:00
|
|
|
nsCacheEntry::nsCacheEntry(nsCString * key,
|
|
|
|
PRBool streamBased,
|
|
|
|
nsCacheStoragePolicy storagePolicy)
|
2001-02-23 13:18:01 +00:00
|
|
|
: mKey(key),
|
2001-03-05 07:17:58 +00:00
|
|
|
mFetchCount(1),
|
2001-03-04 00:11:30 +00:00
|
|
|
mLastValidated(0),
|
|
|
|
mExpirationTime(0),
|
2001-02-26 14:42:50 +00:00
|
|
|
mFlags(0),
|
|
|
|
mDataSize(0),
|
|
|
|
mMetaSize(0),
|
2001-02-23 13:18:01 +00:00
|
|
|
mCacheDevice(nsnull),
|
|
|
|
mData(nsnull),
|
|
|
|
mMetaData(nsnull)
|
|
|
|
{
|
2001-03-05 07:17:58 +00:00
|
|
|
PR_INIT_CLIST(this);
|
2001-02-23 13:18:01 +00:00
|
|
|
PR_INIT_CLIST(&mRequestQ);
|
|
|
|
PR_INIT_CLIST(&mDescriptorQ);
|
|
|
|
|
2001-03-04 00:11:30 +00:00
|
|
|
mLastFetched = ConvertPRTimeToSeconds(PR_Now());
|
2001-02-28 03:54:16 +00:00
|
|
|
|
|
|
|
if (streamBased) MarkStreamBased();
|
2001-02-26 14:42:50 +00:00
|
|
|
|
|
|
|
if ((storagePolicy == nsICache::STORE_IN_MEMORY) ||
|
|
|
|
(storagePolicy == nsICache::STORE_ANYWHERE)) {
|
|
|
|
MarkAllowedInMemory();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((storagePolicy == nsICache::STORE_ON_DISK) ||
|
|
|
|
(storagePolicy == nsICache::STORE_ANYWHERE)) {
|
|
|
|
MarkAllowedOnDisk();
|
|
|
|
}
|
2001-02-23 13:18:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsCacheEntry::~nsCacheEntry()
|
|
|
|
{
|
2001-03-02 01:51:41 +00:00
|
|
|
delete mKey;
|
|
|
|
delete mMetaData;
|
2001-02-23 13:18:01 +00:00
|
|
|
}
|
|
|
|
|
2001-03-08 05:37:00 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
nsCacheEntry::SetDataSize( PRUint32 size)
|
|
|
|
{
|
|
|
|
mDataSize = size;
|
|
|
|
mLastModified = ConvertPRTimeToSeconds(PR_Now());
|
2001-03-12 19:29:34 +00:00
|
|
|
MarkEntryDirty();
|
2001-03-08 05:37:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-03-07 09:27:36 +00:00
|
|
|
nsresult
|
|
|
|
nsCacheEntry::GetSecurityInfo( nsISupports ** result)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(result);
|
|
|
|
NS_IF_ADDREF(*result = mSecurityInfo);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsCacheEntry::SetSecurityInfo( nsISupports * info)
|
|
|
|
{
|
|
|
|
mSecurityInfo = info;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-02-23 13:18:01 +00:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsCacheEntry::GetData(nsISupports **result)
|
|
|
|
{
|
2001-03-12 22:41:28 +00:00
|
|
|
if (!result)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
2001-02-23 13:18:01 +00:00
|
|
|
|
2001-02-27 05:35:53 +00:00
|
|
|
NS_IF_ADDREF(*result = mData);
|
2001-02-23 13:18:01 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsCacheEntry::SetData(nsISupports * data)
|
|
|
|
{
|
2001-03-08 05:37:00 +00:00
|
|
|
mLastModified = ConvertPRTimeToSeconds(PR_Now());
|
2001-02-23 13:18:01 +00:00
|
|
|
mData = data;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsCacheEntry::GetMetaDataElement( const nsAReadableCString& key,
|
|
|
|
nsAReadableCString ** value)
|
|
|
|
{
|
|
|
|
*value = mMetaData ? mMetaData->GetElement(&key) : nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsCacheEntry::SetMetaDataElement( const nsAReadableCString& key,
|
|
|
|
const nsAReadableCString& value)
|
|
|
|
{
|
|
|
|
if (!mMetaData) {
|
2001-03-02 01:51:41 +00:00
|
|
|
mMetaData = nsCacheMetaData::Create();
|
2001-02-23 13:18:01 +00:00
|
|
|
if (!mMetaData)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2001-03-01 20:06:16 +00:00
|
|
|
nsresult rv = mMetaData->SetElement(key, value);
|
2001-03-13 15:43:17 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2001-03-01 20:06:16 +00:00
|
|
|
|
2001-03-13 15:43:17 +00:00
|
|
|
mMetaSize = mMetaData->Size(); // calc new meta data size
|
|
|
|
mLastModified = ConvertPRTimeToSeconds(PR_Now()); // time stamp the entry
|
|
|
|
MarkMetaDataDirty(); // mark it dirty
|
2001-03-01 20:06:16 +00:00
|
|
|
return rv;
|
2001-02-23 13:18:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-03-02 04:09:01 +00:00
|
|
|
#if 0
|
2001-02-28 07:13:32 +00:00
|
|
|
nsresult
|
|
|
|
nsCacheEntry::GetKeyValueArray(nsCacheMetaDataKeyValuePair ** array,
|
|
|
|
PRUint32 * count)
|
|
|
|
{
|
|
|
|
if (!array || !count) return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
if (!mMetaData) {
|
|
|
|
*array = nsnull;
|
|
|
|
*count = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return mMetaData->GetKeyValueArray(array, count);
|
|
|
|
}
|
2001-03-02 04:09:01 +00:00
|
|
|
#endif
|
2001-02-28 07:13:32 +00:00
|
|
|
|
2001-03-02 04:09:01 +00:00
|
|
|
nsresult
|
|
|
|
nsCacheEntry::FlattenMetaData(char ** data, PRUint32 * size)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(size);
|
|
|
|
|
|
|
|
if (mMetaData)
|
|
|
|
return mMetaData->FlattenMetaData(data, size);
|
|
|
|
|
|
|
|
if (data) *data = nsnull;
|
|
|
|
*size = 0;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsCacheEntry::UnflattenMetaData(char * data, PRUint32 size)
|
|
|
|
{
|
|
|
|
delete mMetaData;
|
|
|
|
mMetaData = nsCacheMetaData::Create();
|
|
|
|
if (!mMetaData)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
return mMetaData->UnflattenMetaData(data, size);
|
|
|
|
}
|
2001-02-28 07:13:32 +00:00
|
|
|
|
2001-02-23 13:18:01 +00:00
|
|
|
/**
|
|
|
|
* cache entry states
|
|
|
|
* 0 descriptors (new entry)
|
|
|
|
* 0 descriptors (existing, bound entry)
|
|
|
|
* n descriptors (existing, bound entry) valid
|
|
|
|
* n descriptors (existing, bound entry) not valid (wait until valid or doomed)
|
|
|
|
*/
|
|
|
|
|
|
|
|
nsresult
|
2001-03-05 07:17:58 +00:00
|
|
|
nsCacheEntry::RequestAccess(nsCacheRequest * request, nsCacheAccessMode *accessGranted)
|
2001-02-23 13:18:01 +00:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (!IsInitialized()) {
|
|
|
|
// brand new, unbound entry
|
2001-03-03 02:27:49 +00:00
|
|
|
request->mKey = nsnull; // steal ownership of the key string
|
2001-03-05 07:17:58 +00:00
|
|
|
if (request->IsStreamBased()) MarkStreamBased();
|
2001-02-23 13:18:01 +00:00
|
|
|
MarkInitialized();
|
2001-03-05 07:17:58 +00:00
|
|
|
|
|
|
|
*accessGranted = request->AccessRequested() & nsICache::ACCESS_WRITE;
|
|
|
|
NS_ASSERTION(*accessGranted, "new cache entry for READ-ONLY request");
|
|
|
|
PR_APPEND_LINK(request, &mRequestQ);
|
2001-02-23 13:18:01 +00:00
|
|
|
return rv;
|
|
|
|
}
|
2001-03-05 10:45:33 +00:00
|
|
|
|
|
|
|
if (IsDoomed()) return NS_ERROR_CACHE_ENTRY_DOOMED;
|
2001-02-23 13:18:01 +00:00
|
|
|
|
2001-03-05 07:17:58 +00:00
|
|
|
if (IsStreamData() != request->IsStreamBased()) {
|
2001-02-24 01:02:37 +00:00
|
|
|
*accessGranted = nsICache::ACCESS_NONE;
|
2001-03-05 07:17:58 +00:00
|
|
|
return request->IsStreamBased() ?
|
2001-02-23 13:18:01 +00:00
|
|
|
NS_ERROR_CACHE_DATA_IS_NOT_STREAM : NS_ERROR_CACHE_DATA_IS_STREAM;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PR_CLIST_IS_EMPTY(&mDescriptorQ)) {
|
2001-03-05 07:17:58 +00:00
|
|
|
// 1st descriptor for existing bound entry
|
|
|
|
*accessGranted = request->AccessRequested();
|
2001-03-07 09:27:36 +00:00
|
|
|
if (*accessGranted & nsICache::ACCESS_WRITE) {
|
|
|
|
MarkInvalid();
|
|
|
|
} else {
|
|
|
|
MarkValid();
|
|
|
|
}
|
2001-02-23 13:18:01 +00:00
|
|
|
} else {
|
|
|
|
// nth request for existing, bound entry
|
2001-03-05 07:17:58 +00:00
|
|
|
*accessGranted = request->AccessRequested() & ~nsICache::ACCESS_WRITE;
|
2001-02-23 13:18:01 +00:00
|
|
|
if (!IsValid())
|
|
|
|
rv = NS_ERROR_CACHE_WAIT_FOR_VALIDATION;
|
|
|
|
}
|
2001-03-05 07:17:58 +00:00
|
|
|
PR_APPEND_LINK(request,&mRequestQ);
|
|
|
|
|
2001-02-23 13:18:01 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-03-05 07:17:58 +00:00
|
|
|
nsresult
|
|
|
|
nsCacheEntry::CreateDescriptor(nsCacheRequest * request,
|
|
|
|
nsCacheAccessMode accessGranted,
|
|
|
|
nsICacheEntryDescriptor ** result)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(request && result);
|
|
|
|
|
|
|
|
nsCacheEntryDescriptor * descriptor =
|
|
|
|
new nsCacheEntryDescriptor(this, accessGranted);
|
|
|
|
|
2001-03-08 05:37:00 +00:00
|
|
|
// XXX check request is on q
|
|
|
|
PR_REMOVE_AND_INIT_LINK(request); // remove request regardless of success
|
|
|
|
|
2001-03-05 07:17:58 +00:00
|
|
|
if (descriptor == nsnull)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
PR_APPEND_LINK(descriptor, &mDescriptorQ);
|
|
|
|
|
|
|
|
NS_ADDREF(*result = descriptor);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-02-26 14:42:50 +00:00
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsCacheEntry::RemoveRequest(nsCacheRequest * request)
|
|
|
|
{
|
2001-03-04 00:11:30 +00:00
|
|
|
// XXX if debug: verify this request belongs to this entry
|
2001-03-05 07:17:58 +00:00
|
|
|
PR_REMOVE_AND_INIT_LINK(request);
|
2001-02-26 14:42:50 +00:00
|
|
|
|
|
|
|
// return true if this entry should stay active
|
|
|
|
return !((PR_CLIST_IS_EMPTY(&mRequestQ)) &&
|
|
|
|
(PR_CLIST_IS_EMPTY(&mDescriptorQ)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsCacheEntry::RemoveDescriptor(nsCacheEntryDescriptor * descriptor)
|
|
|
|
{
|
2001-03-04 00:11:30 +00:00
|
|
|
// XXX if debug: verify this descriptor belongs to this entry
|
2001-03-05 07:17:58 +00:00
|
|
|
PR_REMOVE_AND_INIT_LINK(descriptor);
|
2001-02-26 14:42:50 +00:00
|
|
|
|
|
|
|
if (!PR_CLIST_IS_EMPTY(&mDescriptorQ))
|
|
|
|
return PR_TRUE; // stay active if we still have open descriptors
|
|
|
|
|
|
|
|
if (PR_CLIST_IS_EMPTY(&mRequestQ))
|
|
|
|
return PR_FALSE; // no descriptors or requests, we can deactivate
|
|
|
|
|
2001-03-05 10:45:33 +00:00
|
|
|
return PR_TRUE; // find next best request to give a descriptor to
|
2001-02-26 14:42:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-03-13 15:43:17 +00:00
|
|
|
void
|
|
|
|
nsCacheEntry::DetachDescriptors(void)
|
|
|
|
{
|
|
|
|
nsCacheEntryDescriptor * descriptor =
|
|
|
|
(nsCacheEntryDescriptor *)PR_LIST_HEAD(&mDescriptorQ);
|
|
|
|
|
|
|
|
while (descriptor != &mDescriptorQ) {
|
|
|
|
nsCacheEntryDescriptor * next =
|
|
|
|
(nsCacheEntryDescriptor *)PR_NEXT_LINK(descriptor);
|
|
|
|
|
|
|
|
descriptor->ClearCacheEntry();
|
|
|
|
PR_REMOVE_AND_INIT_LINK(descriptor);
|
|
|
|
descriptor = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
2001-02-23 13:18:01 +00:00
|
|
|
* nsCacheEntryHashTable
|
2001-03-13 15:43:17 +00:00
|
|
|
*****************************************************************************/
|
2001-02-23 13:18:01 +00:00
|
|
|
|
|
|
|
PLDHashTableOps
|
|
|
|
nsCacheEntryHashTable::ops =
|
|
|
|
{
|
|
|
|
PL_DHashAllocTable,
|
|
|
|
PL_DHashFreeTable,
|
|
|
|
GetKey,
|
|
|
|
HashKey,
|
|
|
|
MatchEntry,
|
|
|
|
MoveEntry,
|
|
|
|
ClearEntry,
|
|
|
|
Finalize
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
nsCacheEntryHashTable::nsCacheEntryHashTable()
|
|
|
|
: initialized(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsCacheEntryHashTable::~nsCacheEntryHashTable()
|
|
|
|
{
|
2001-03-01 02:46:12 +00:00
|
|
|
PL_DHashTableFinish(&table);
|
2001-02-23 13:18:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsCacheEntryHashTable::Init()
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
initialized = PL_DHashTableInit(&table, &ops, nsnull,
|
|
|
|
sizeof(nsCacheEntryHashTableEntry), 512);
|
|
|
|
|
|
|
|
if (!initialized) rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsCacheEntry *
|
|
|
|
nsCacheEntryHashTable::GetEntry( const nsCString * key)
|
|
|
|
{
|
|
|
|
PLDHashEntryHdr *hashEntry;
|
|
|
|
nsCacheEntry *result = nsnull;
|
|
|
|
|
|
|
|
NS_ASSERTION(initialized, "nsCacheEntryHashTable not initialized");
|
|
|
|
hashEntry = PL_DHashTableOperate(&table, key, PL_DHASH_LOOKUP);
|
|
|
|
if (PL_DHASH_ENTRY_IS_BUSY(hashEntry)) {
|
|
|
|
result = ((nsCacheEntryHashTableEntry *)hashEntry)->cacheEntry;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-03-08 05:37:00 +00:00
|
|
|
|
2001-02-23 13:18:01 +00:00
|
|
|
nsresult
|
|
|
|
nsCacheEntryHashTable::AddEntry( nsCacheEntry *cacheEntry)
|
|
|
|
{
|
|
|
|
PLDHashEntryHdr *hashEntry;
|
|
|
|
|
|
|
|
NS_ASSERTION(initialized, "nsCacheEntryHashTable not initialized");
|
|
|
|
if (!cacheEntry) return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
hashEntry = PL_DHashTableOperate(&table, cacheEntry->mKey, PL_DHASH_ADD);
|
2001-03-12 22:41:28 +00:00
|
|
|
#ifndef DEBUG_dougt
|
2001-02-27 05:35:53 +00:00
|
|
|
NS_ASSERTION(((nsCacheEntryHashTableEntry *)hashEntry)->cacheEntry == 0,
|
2001-03-13 15:43:17 +00:00
|
|
|
"### nsCacheEntryHashTable::AddEntry - entry already used");
|
2001-03-12 22:41:28 +00:00
|
|
|
#endif
|
2001-02-23 13:18:01 +00:00
|
|
|
((nsCacheEntryHashTableEntry *)hashEntry)->cacheEntry = cacheEntry;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-03-08 05:37:00 +00:00
|
|
|
|
|
|
|
void
|
2001-02-23 13:18:01 +00:00
|
|
|
nsCacheEntryHashTable::RemoveEntry( nsCacheEntry *cacheEntry)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(initialized, "nsCacheEntryHashTable not initialized");
|
2001-03-13 15:43:17 +00:00
|
|
|
NS_ASSERTION(cacheEntry, "### cacheEntry == nsnull");
|
2001-02-23 13:18:01 +00:00
|
|
|
|
2001-03-13 15:43:17 +00:00
|
|
|
#if DEBUG
|
2001-03-04 00:11:30 +00:00
|
|
|
// XXX debug code to make sure we have the entry we're trying to remove
|
2001-03-13 15:43:17 +00:00
|
|
|
nsCacheEntry *check = GetEntry(cacheEntry->mKey);
|
|
|
|
NS_ASSERTION(check == cacheEntry, "### Attempting to remove unknown cache entry!!!");
|
|
|
|
#endif
|
2001-03-03 00:00:29 +00:00
|
|
|
(void) PL_DHashTableOperate(&table, cacheEntry->mKey, PL_DHASH_REMOVE);
|
2001-02-23 13:18:01 +00:00
|
|
|
}
|
|
|
|
|
2001-03-08 05:37:00 +00:00
|
|
|
|
2001-03-10 00:43:20 +00:00
|
|
|
void
|
|
|
|
nsCacheEntryHashTable::VisitEntries( nsCacheEntryHashTable::Visitor *visitor)
|
|
|
|
{
|
|
|
|
PL_DHashTableEnumerate(&table, VisitEntry, visitor);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PLDHashOperator
|
|
|
|
nsCacheEntryHashTable::VisitEntry(PLDHashTable *table,
|
|
|
|
PLDHashEntryHdr *hashEntry,
|
|
|
|
PRUint32 number,
|
|
|
|
void *arg)
|
|
|
|
{
|
|
|
|
nsCacheEntry *cacheEntry = ((nsCacheEntryHashTableEntry *)hashEntry)->cacheEntry;
|
|
|
|
nsCacheEntryHashTable::Visitor *visitor = (nsCacheEntryHashTable::Visitor*) arg;
|
|
|
|
return (visitor->VisitEntry(cacheEntry) ? PL_DHASH_NEXT : PL_DHASH_STOP);
|
|
|
|
}
|
|
|
|
|
2001-03-08 05:37:00 +00:00
|
|
|
/**
|
2001-02-23 13:18:01 +00:00
|
|
|
* hash table operation callback functions
|
|
|
|
*/
|
|
|
|
const void *
|
|
|
|
nsCacheEntryHashTable::GetKey( PLDHashTable * /*table*/, PLDHashEntryHdr *hashEntry)
|
|
|
|
{
|
|
|
|
nsCacheEntry *cacheEntry = ((nsCacheEntryHashTableEntry *)hashEntry)->cacheEntry;
|
|
|
|
return cacheEntry->mKey;
|
|
|
|
}
|
|
|
|
|
2001-02-26 14:42:50 +00:00
|
|
|
|
2001-02-24 04:22:19 +00:00
|
|
|
PLDHashNumber
|
|
|
|
nsCacheEntryHashTable::HashKey( PLDHashTable *table, const void *key)
|
|
|
|
{
|
2001-02-27 05:35:53 +00:00
|
|
|
return PL_DHashStringKey(table,((nsCString *)key)->get());
|
2001-02-24 04:22:19 +00:00
|
|
|
}
|
|
|
|
|
2001-02-23 13:18:01 +00:00
|
|
|
PRBool
|
|
|
|
nsCacheEntryHashTable::MatchEntry(PLDHashTable * /* table */,
|
|
|
|
const PLDHashEntryHdr * hashEntry,
|
|
|
|
const void * key)
|
|
|
|
{
|
2001-03-13 15:43:17 +00:00
|
|
|
NS_ASSERTION(key != nsnull, "### nsCacheEntryHashTable::MatchEntry : null key");
|
2001-02-23 13:18:01 +00:00
|
|
|
nsCacheEntry *cacheEntry = ((nsCacheEntryHashTableEntry *)hashEntry)->cacheEntry;
|
|
|
|
|
|
|
|
return nsStr::StrCompare(*cacheEntry->mKey, *(nsCString *)key, -1, PR_FALSE) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCacheEntryHashTable::MoveEntry(PLDHashTable * /* table */,
|
|
|
|
const PLDHashEntryHdr *from,
|
|
|
|
PLDHashEntryHdr *to)
|
|
|
|
{
|
|
|
|
to->keyHash = from->keyHash;
|
|
|
|
((nsCacheEntryHashTableEntry *)to)->cacheEntry =
|
|
|
|
((nsCacheEntryHashTableEntry *)from)->cacheEntry;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCacheEntryHashTable::ClearEntry(PLDHashTable * /* table */,
|
|
|
|
PLDHashEntryHdr * hashEntry)
|
|
|
|
{
|
|
|
|
((nsCacheEntryHashTableEntry *)hashEntry)->keyHash = 0;
|
|
|
|
((nsCacheEntryHashTableEntry *)hashEntry)->cacheEntry = 0;
|
|
|
|
}
|
|
|
|
|
2001-03-13 15:43:17 +00:00
|
|
|
|
2001-02-23 13:18:01 +00:00
|
|
|
void
|
2001-03-01 02:46:12 +00:00
|
|
|
nsCacheEntryHashTable::Finalize(PLDHashTable * table)
|
2001-02-23 13:18:01 +00:00
|
|
|
{
|
2001-03-01 02:46:12 +00:00
|
|
|
(void) PL_DHashTableEnumerate(table, FreeCacheEntries, nsnull);
|
2001-02-23 13:18:01 +00:00
|
|
|
}
|
|
|
|
|
2001-03-01 02:46:12 +00:00
|
|
|
|
|
|
|
PLDHashOperator
|
|
|
|
nsCacheEntryHashTable::FreeCacheEntries(PLDHashTable *table,
|
|
|
|
PLDHashEntryHdr *hdr,
|
|
|
|
PRUint32 number,
|
|
|
|
void *arg)
|
|
|
|
{
|
|
|
|
nsCacheEntryHashTableEntry *entry = (nsCacheEntryHashTableEntry *)hdr;
|
|
|
|
delete entry->cacheEntry;
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|