зеркало из https://github.com/mozilla/gecko-dev.git
Begin implementing enumeration of MetaData for cache devices.
This commit is contained in:
Родитель
6ba783661a
Коммит
ecb52c437c
|
@ -113,6 +113,21 @@ nsCacheEntry::SetMetaDataElement( const nsAReadableCString& key,
|
|||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsCacheEntry::MarkValid()
|
||||
{
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
|
||||
#include "nsICache.h"
|
||||
#include "nsICacheEntryDescriptor.h"
|
||||
#include "nsCacheMetaData.h"
|
||||
|
||||
|
||||
class nsCacheDevice;
|
||||
|
@ -40,6 +41,7 @@ class nsCacheMetaData;
|
|||
class nsCacheRequest;
|
||||
class nsCacheEntryDescriptor;
|
||||
|
||||
|
||||
class nsCacheEntry
|
||||
{
|
||||
public:
|
||||
|
@ -80,6 +82,9 @@ public:
|
|||
nsresult SetMetaDataElement( const nsAReadableCString& key,
|
||||
const nsAReadableCString& value);
|
||||
|
||||
nsresult GetKeyValueArray(nsCacheMetaDataKeyValuePair ** array,
|
||||
PRUint32 * count);
|
||||
|
||||
//** enumerate MetaData method
|
||||
|
||||
|
||||
|
|
|
@ -52,6 +52,7 @@ nsCacheMetaData::nsCacheMetaData()
|
|||
nsCacheMetaData::~nsCacheMetaData()
|
||||
{
|
||||
//** maybe we should finalize the table...
|
||||
PL_DHashTableFinish(&table);
|
||||
}
|
||||
|
||||
|
||||
|
@ -115,6 +116,23 @@ nsCacheMetaData::SetElement(const nsAReadableCString * key,
|
|||
|
||||
|
||||
//** enumerate MetaData elements
|
||||
nsresult
|
||||
nsCacheMetaData::GetKeyValueArray(nsCacheMetaDataKeyValuePair ** array,
|
||||
PRUint32 * count)
|
||||
{
|
||||
// count elements
|
||||
PRUint32 total = 0;
|
||||
PRUint32 totalEntries = PL_DHashTableEnumerate(&table, CountElements, &total);
|
||||
|
||||
if (total != totalEntries) {
|
||||
//** just checking
|
||||
}
|
||||
// allocate array
|
||||
|
||||
// fill array
|
||||
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -162,16 +180,59 @@ nsCacheMetaData::MoveEntry(PLDHashTable * /* table */,
|
|||
|
||||
void
|
||||
nsCacheMetaData::ClearEntry(PLDHashTable * /* table */,
|
||||
PLDHashEntryHdr * hashEntry)
|
||||
PLDHashEntryHdr * hashEntry)
|
||||
{
|
||||
((nsCacheMetaDataHashTableEntry *)hashEntry)->keyHash = 0;
|
||||
((nsCacheMetaDataHashTableEntry *)hashEntry)->key = 0;
|
||||
((nsCacheMetaDataHashTableEntry *)hashEntry)->value = 0;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsCacheMetaData::Finalize(PLDHashTable * /* table */)
|
||||
nsCacheMetaData::Finalize(PLDHashTable * table)
|
||||
{
|
||||
//** gee, if there's anything left in the table, maybe we should get rid of it.
|
||||
(void) PL_DHashTableEnumerate(table, FreeElements, nsnull);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* hash table enumeration callback functions
|
||||
*/
|
||||
|
||||
PLDHashOperator
|
||||
nsCacheMetaData::CountElements(PLDHashTable *table,
|
||||
PLDHashEntryHdr *hdr,
|
||||
PRUint32 number,
|
||||
void *arg)
|
||||
{
|
||||
++*(PRUint32 *)arg;
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
|
||||
PLDHashOperator
|
||||
nsCacheMetaData::AccumulateElements(PLDHashTable *table,
|
||||
PLDHashEntryHdr *hdr,
|
||||
PRUint32 number,
|
||||
void *arg)
|
||||
{
|
||||
nsCacheMetaDataHashTableEntry *entry = (nsCacheMetaDataHashTableEntry *)hdr;
|
||||
nsCacheMetaDataKeyValuePair *pair = (nsCacheMetaDataKeyValuePair *)arg;
|
||||
|
||||
pair->key = entry->key;
|
||||
pair->value = entry->value;
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
|
||||
PLDHashOperator
|
||||
nsCacheMetaData::FreeElements(PLDHashTable *table,
|
||||
PLDHashEntryHdr *hdr,
|
||||
PRUint32 number,
|
||||
void *arg)
|
||||
{
|
||||
nsCacheMetaDataHashTableEntry *entry = (nsCacheMetaDataHashTableEntry *)hdr;
|
||||
delete entry->key;
|
||||
delete entry->value;
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
|
|
@ -31,6 +31,11 @@
|
|||
#include "nsString.h"
|
||||
// #include "nsAReadableString.h"
|
||||
|
||||
typedef struct {
|
||||
nsCString * key;
|
||||
nsCString * value;
|
||||
} nsCacheMetaDataKeyValuePair;
|
||||
|
||||
|
||||
typedef struct {
|
||||
PLDHashNumber keyHash;
|
||||
|
@ -51,6 +56,9 @@ public:
|
|||
nsresult SetElement(const nsAReadableCString * key,
|
||||
const nsAReadableCString * value);
|
||||
|
||||
nsresult GetKeyValueArray(nsCacheMetaDataKeyValuePair ** array,
|
||||
PRUint32 * count);
|
||||
|
||||
private:
|
||||
// PLDHashTable operation callbacks
|
||||
static const void * GetKey( PLDHashTable *table, PLDHashEntryHdr *entry);
|
||||
|
@ -69,6 +77,25 @@ private:
|
|||
|
||||
static void Finalize( PLDHashTable *table);
|
||||
|
||||
static
|
||||
PLDHashOperator CountElements(PLDHashTable *table,
|
||||
PLDHashEntryHdr *hdr,
|
||||
PRUint32 number,
|
||||
void *arg);
|
||||
|
||||
|
||||
static
|
||||
PLDHashOperator AccumulateElements(PLDHashTable *table,
|
||||
PLDHashEntryHdr *hdr,
|
||||
PRUint32 number,
|
||||
void *arg);
|
||||
|
||||
static
|
||||
PLDHashOperator FreeElements(PLDHashTable *table,
|
||||
PLDHashEntryHdr *hdr,
|
||||
PRUint32 number,
|
||||
void *arg);
|
||||
|
||||
// member variables
|
||||
static PLDHashTableOps ops;
|
||||
PLDHashTable table;
|
||||
|
|
Загрузка…
Ссылка в новой задаче