mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:18:48 +00:00
3f81116a93
- Bug 1168007 (part 6) - Use PLDHashTable2 in nsSecureBrowserUIImpl. r=froydnj. (a6bf60fab)
- Bug 1168007 (part 7) - Use PLDHashTable2 in nsCertTree. r=froydnj. (7a0114da5)
- Bug 1168007 (part 8) - Use PLDHashTable2 in nsCycleCollector. r=froydnj. (61936a5b9)
- Bug 1168007 (part 9) - Use PLDHashTable2 in nsCacheEntry. r=froydnj. (64940f663)
- Bug 1168007 (part 10) - Use PLDHashTable2 in nsDiskCacheBindery. r=froydnj. (cb9993d4c)
- Bug 1168007 (part 11) - Use PLDHashTable2 exclusively in TestPLDHash. r=froydnj. (a871dfaa4)
- Bug 1170416 (part 1) - Remove PL_DHashTable{Init,Finish,Destroy){} and PL_NewDHashTable(). r=froydnj. (c7def8fcd)
- Bug 1170416 (part 2) - Merge PLDHashTable2 back into PLDHashTable. r=froydnj. (84783ae50)
- Bug 1168027 - Use PLDHashTable2 in nsTHashtable. r=froydnj. (ded8e0d51)
- Bug 1166598 (part 8) - Use PLDHashTable2 in nsHostResolver. r=froydnj. (b05946f51)
- Bug 1166598 (part 1) - Use PLDHashTable2 in nsScriptNameSpaceManager. r=froydnj. (cb9a9405f)
- Bug 1166598 (part 7) - Use PLDHashTable2 in nsLoadGroup. r=froydnj. (f886096a1)
- Bug 1166598 (part 2) - Use PLDHashTable2 in SpanningCellSorter. r=froydnj,dbaron. (67368e477)
- Bug 1166598 (part 3) - Use PLDHashTable2 in nsCommandParams. r=froydnj. (c4ea9cf33)
- Bug 1166598 (part 4) - Use PLDHashTable2 in RDFServiceImpl. r=froydnj. (26f9c3ab6)
- Bug 1166598 (part 5) - Use PLDHashTable2 in InMemoryDataSource. r=froydnj. (d2e130043)
- Bug 1166598 (part 6) - Clean up nsStaticCaseInsensitiveNameTable. r=froydnj. (eb8532cba)
- Bug 1166586 (part 1) - Remove all uses of PL_NewDHashTable() and PL_HashTableDestroy(). r=froydnj. (fc7222f1f)
- Bug 1129786 (part 1) - Instantiate RuleHash::m*Table eagerly. r=bz. (b95efc9aa)
- Bug 1129786 (part 2) - Instantiate nsDOMAttributeMap::mAttributeCache eagerly. r=bz. (f15221fa8)
- Bug 1166586 (part 2) - Convert some easy PL_DHashTable{Init,Finish} cases. r=froydnj. (a861a32c1)
- Bug 1165206 - Tweak nsTHashtable's move constructor. r=froydnj. (92724c440)
- Bug 1170069 - Use PLDHashTable2 in FontNameCache. r=froydnj. (150259ee5)
- Bug 1170416 (part 3) - Remove the PLDHashTable2 typedef. r=froydnj. (0c8123b29)
- Bug 1170416 (part 4) - Remove some unnecessary casts. r=froydnj. (5892abc55)
- Bug 1165786 - Remove PLDHashTable::SetOps(). r=froydnj. (75075e448)
- Bug 1170416 (part 5) - Remove PLDHashTable::IsInitialized(). r=froydnj. (9d6df3e68)
315 lines
12 KiB
C++
315 lines
12 KiB
C++
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#ifndef _nsCacheEntry_h_
|
|
#define _nsCacheEntry_h_
|
|
|
|
#include "nsICache.h"
|
|
#include "nsICacheEntryDescriptor.h"
|
|
#include "nsIThread.h"
|
|
#include "nsCacheMetaData.h"
|
|
|
|
#include "nspr.h"
|
|
#include "pldhash.h"
|
|
#include "nsAutoPtr.h"
|
|
#include "nscore.h"
|
|
#include "nsCOMPtr.h"
|
|
#include "nsString.h"
|
|
#include "nsAString.h"
|
|
|
|
class nsCacheDevice;
|
|
class nsCacheMetaData;
|
|
class nsCacheRequest;
|
|
class nsCacheEntryDescriptor;
|
|
|
|
/******************************************************************************
|
|
* nsCacheEntry
|
|
*******************************************************************************/
|
|
class nsCacheEntry : public PRCList
|
|
{
|
|
public:
|
|
|
|
nsCacheEntry(const nsACString & key,
|
|
bool streamBased,
|
|
nsCacheStoragePolicy storagePolicy);
|
|
~nsCacheEntry();
|
|
|
|
|
|
static nsresult Create( const char * key,
|
|
bool streamBased,
|
|
nsCacheStoragePolicy storagePolicy,
|
|
nsCacheDevice * device,
|
|
nsCacheEntry ** result);
|
|
|
|
nsCString * Key() { return &mKey; }
|
|
|
|
int32_t FetchCount() { return mFetchCount; }
|
|
void SetFetchCount( int32_t count) { mFetchCount = count; }
|
|
void Fetched();
|
|
|
|
uint32_t LastFetched() { return mLastFetched; }
|
|
void SetLastFetched( uint32_t lastFetched) { mLastFetched = lastFetched; }
|
|
|
|
uint32_t LastModified() { return mLastModified; }
|
|
void SetLastModified( uint32_t lastModified) { mLastModified = lastModified; }
|
|
|
|
uint32_t ExpirationTime() { return mExpirationTime; }
|
|
void SetExpirationTime( uint32_t expires) { mExpirationTime = expires; }
|
|
|
|
uint32_t Size()
|
|
{ return mDataSize + mMetaData.Size() + mKey.Length() ; }
|
|
|
|
nsCacheDevice * CacheDevice() { return mCacheDevice; }
|
|
void SetCacheDevice( nsCacheDevice * device) { mCacheDevice = device; }
|
|
void SetCustomCacheDevice( nsCacheDevice * device )
|
|
{ mCustomDevice = device; }
|
|
nsCacheDevice * CustomCacheDevice() { return mCustomDevice; }
|
|
const char * GetDeviceID();
|
|
|
|
/**
|
|
* Data accessors
|
|
*/
|
|
nsISupports *Data() { return mData; }
|
|
void SetData( nsISupports * data);
|
|
|
|
int64_t PredictedDataSize() { return mPredictedDataSize; }
|
|
void SetPredictedDataSize(int64_t size) { mPredictedDataSize = size; }
|
|
|
|
uint32_t DataSize() { return mDataSize; }
|
|
void SetDataSize( uint32_t size) { mDataSize = size; }
|
|
|
|
void TouchData();
|
|
|
|
/**
|
|
* Meta data accessors
|
|
*/
|
|
const char * GetMetaDataElement( const char * key) { return mMetaData.GetElement(key); }
|
|
nsresult SetMetaDataElement( const char * key,
|
|
const char * value) { return mMetaData.SetElement(key, value); }
|
|
nsresult VisitMetaDataElements( nsICacheMetaDataVisitor * visitor) { return mMetaData.VisitElements(visitor); }
|
|
nsresult FlattenMetaData(char * buffer, uint32_t bufSize) { return mMetaData.FlattenMetaData(buffer, bufSize); }
|
|
nsresult UnflattenMetaData(const char * buffer, uint32_t bufSize) { return mMetaData.UnflattenMetaData(buffer, bufSize); }
|
|
uint32_t MetaDataSize() { return mMetaData.Size(); }
|
|
|
|
void TouchMetaData();
|
|
|
|
|
|
/**
|
|
* Security Info accessors
|
|
*/
|
|
nsISupports* SecurityInfo() { return mSecurityInfo; }
|
|
void SetSecurityInfo( nsISupports * info) { mSecurityInfo = info; }
|
|
|
|
|
|
// XXX enumerate MetaData method
|
|
|
|
|
|
enum CacheEntryFlags {
|
|
eStoragePolicyMask = 0x000000FF,
|
|
eDoomedMask = 0x00000100,
|
|
eEntryDirtyMask = 0x00000200,
|
|
eDataDirtyMask = 0x00000400,
|
|
eMetaDataDirtyMask = 0x00000800,
|
|
eStreamDataMask = 0x00001000,
|
|
eActiveMask = 0x00002000,
|
|
eInitializedMask = 0x00004000,
|
|
eValidMask = 0x00008000,
|
|
eBindingMask = 0x00010000,
|
|
ePrivateMask = 0x00020000
|
|
};
|
|
|
|
void MarkBinding() { mFlags |= eBindingMask; }
|
|
void ClearBinding() { mFlags &= ~eBindingMask; }
|
|
bool IsBinding() { return (mFlags & eBindingMask) != 0; }
|
|
|
|
void MarkEntryDirty() { mFlags |= eEntryDirtyMask; }
|
|
void MarkEntryClean() { mFlags &= ~eEntryDirtyMask; }
|
|
void MarkDataDirty() { mFlags |= eDataDirtyMask; }
|
|
void MarkDataClean() { mFlags &= ~eDataDirtyMask; }
|
|
void MarkMetaDataDirty() { mFlags |= eMetaDataDirtyMask; }
|
|
void MarkMetaDataClean() { mFlags &= ~eMetaDataDirtyMask; }
|
|
void MarkStreamData() { mFlags |= eStreamDataMask; }
|
|
void MarkValid() { mFlags |= eValidMask; }
|
|
void MarkInvalid() { mFlags &= ~eValidMask; }
|
|
void MarkPrivate() { mFlags |= ePrivateMask; }
|
|
void MarkPublic() { mFlags &= ~ePrivateMask; }
|
|
// void MarkAllowedInMemory() { mFlags |= eAllowedInMemoryMask; }
|
|
// void MarkAllowedOnDisk() { mFlags |= eAllowedOnDiskMask; }
|
|
|
|
bool IsDoomed() { return (mFlags & eDoomedMask) != 0; }
|
|
bool IsEntryDirty() { return (mFlags & eEntryDirtyMask) != 0; }
|
|
bool IsDataDirty() { return (mFlags & eDataDirtyMask) != 0; }
|
|
bool IsMetaDataDirty() { return (mFlags & eMetaDataDirtyMask) != 0; }
|
|
bool IsStreamData() { return (mFlags & eStreamDataMask) != 0; }
|
|
bool IsActive() { return (mFlags & eActiveMask) != 0; }
|
|
bool IsInitialized() { return (mFlags & eInitializedMask) != 0; }
|
|
bool IsValid() { return (mFlags & eValidMask) != 0; }
|
|
bool IsInvalid() { return (mFlags & eValidMask) == 0; }
|
|
bool IsInUse() { return IsBinding() ||
|
|
!(PR_CLIST_IS_EMPTY(&mRequestQ) &&
|
|
PR_CLIST_IS_EMPTY(&mDescriptorQ)); }
|
|
bool IsNotInUse() { return !IsInUse(); }
|
|
bool IsPrivate() { return (mFlags & ePrivateMask) != 0; }
|
|
|
|
|
|
bool IsAllowedInMemory()
|
|
{
|
|
return (StoragePolicy() == nsICache::STORE_ANYWHERE) ||
|
|
(StoragePolicy() == nsICache::STORE_IN_MEMORY);
|
|
}
|
|
|
|
bool IsAllowedOnDisk()
|
|
{
|
|
return !IsPrivate() && ((StoragePolicy() == nsICache::STORE_ANYWHERE) ||
|
|
(StoragePolicy() == nsICache::STORE_ON_DISK));
|
|
}
|
|
|
|
bool IsAllowedOffline()
|
|
{
|
|
return (StoragePolicy() == nsICache::STORE_OFFLINE);
|
|
}
|
|
|
|
nsCacheStoragePolicy StoragePolicy()
|
|
{
|
|
return (nsCacheStoragePolicy)(mFlags & eStoragePolicyMask);
|
|
}
|
|
|
|
void SetStoragePolicy(nsCacheStoragePolicy policy)
|
|
{
|
|
NS_ASSERTION(policy <= 0xFF, "too many bits in nsCacheStoragePolicy");
|
|
mFlags &= ~eStoragePolicyMask; // clear storage policy bits
|
|
mFlags |= policy;
|
|
}
|
|
|
|
|
|
// methods for nsCacheService
|
|
nsresult RequestAccess( nsCacheRequest * request, nsCacheAccessMode *accessGranted);
|
|
nsresult CreateDescriptor( nsCacheRequest * request,
|
|
nsCacheAccessMode accessGranted,
|
|
nsICacheEntryDescriptor ** result);
|
|
|
|
bool RemoveRequest( nsCacheRequest * request);
|
|
bool RemoveDescriptor( nsCacheEntryDescriptor * descriptor,
|
|
bool * doomEntry);
|
|
|
|
void GetDescriptors(nsTArray<nsRefPtr<nsCacheEntryDescriptor> > &outDescriptors);
|
|
|
|
private:
|
|
friend class nsCacheEntryHashTable;
|
|
friend class nsCacheService;
|
|
|
|
void DetachDescriptors();
|
|
|
|
// internal methods
|
|
void MarkDoomed() { mFlags |= eDoomedMask; }
|
|
void MarkStreamBased() { mFlags |= eStreamDataMask; }
|
|
void MarkInitialized() { mFlags |= eInitializedMask; }
|
|
void MarkActive() { mFlags |= eActiveMask; }
|
|
void MarkInactive() { mFlags &= ~eActiveMask; }
|
|
|
|
nsCString mKey;
|
|
uint32_t mFetchCount; // 4
|
|
uint32_t mLastFetched; // 4
|
|
uint32_t mLastModified; // 4
|
|
uint32_t mLastValidated; // 4
|
|
uint32_t mExpirationTime; // 4
|
|
uint32_t mFlags; // 4
|
|
int64_t mPredictedDataSize; // Size given by ContentLength.
|
|
uint32_t mDataSize; // 4
|
|
nsCacheDevice * mCacheDevice; // 4
|
|
nsCacheDevice * mCustomDevice; // 4
|
|
nsCOMPtr<nsISupports> mSecurityInfo; //
|
|
nsISupports * mData; // strong ref
|
|
nsCOMPtr<nsIThread> mThread;
|
|
nsCacheMetaData mMetaData; // 4
|
|
PRCList mRequestQ; // 8
|
|
PRCList mDescriptorQ; // 8
|
|
};
|
|
|
|
|
|
/******************************************************************************
|
|
* nsCacheEntryInfo
|
|
*******************************************************************************/
|
|
class nsCacheEntryInfo : public nsICacheEntryInfo {
|
|
public:
|
|
NS_DECL_ISUPPORTS
|
|
NS_DECL_NSICACHEENTRYINFO
|
|
|
|
explicit nsCacheEntryInfo(nsCacheEntry* entry)
|
|
: mCacheEntry(entry)
|
|
{
|
|
}
|
|
|
|
void DetachEntry() { mCacheEntry = nullptr; }
|
|
|
|
private:
|
|
nsCacheEntry * mCacheEntry;
|
|
|
|
virtual ~nsCacheEntryInfo() {}
|
|
};
|
|
|
|
|
|
/******************************************************************************
|
|
* nsCacheEntryHashTable
|
|
*******************************************************************************/
|
|
typedef struct {
|
|
PLDHashNumber keyHash;
|
|
nsCacheEntry *cacheEntry;
|
|
} nsCacheEntryHashTableEntry;
|
|
|
|
|
|
class nsCacheEntryHashTable
|
|
{
|
|
public:
|
|
nsCacheEntryHashTable();
|
|
~nsCacheEntryHashTable();
|
|
|
|
void Init();
|
|
void Shutdown();
|
|
|
|
nsCacheEntry *GetEntry( const nsCString * key);
|
|
nsresult AddEntry( nsCacheEntry *entry);
|
|
void RemoveEntry( nsCacheEntry *entry);
|
|
|
|
void VisitEntries( PLDHashEnumerator etor, void *arg);
|
|
|
|
private:
|
|
// PLDHashTable operation callbacks
|
|
static PLDHashNumber HashKey( PLDHashTable *table, const void *key);
|
|
|
|
static bool MatchEntry( PLDHashTable * table,
|
|
const PLDHashEntryHdr * entry,
|
|
const void * key);
|
|
|
|
static void MoveEntry( PLDHashTable *table,
|
|
const PLDHashEntryHdr *from,
|
|
PLDHashEntryHdr *to);
|
|
|
|
static void ClearEntry( PLDHashTable *table, PLDHashEntryHdr *entry);
|
|
|
|
static void Finalize( PLDHashTable *table);
|
|
|
|
static
|
|
PLDHashOperator FreeCacheEntries(PLDHashTable * table,
|
|
PLDHashEntryHdr * hdr,
|
|
uint32_t number,
|
|
void * arg);
|
|
static
|
|
PLDHashOperator VisitEntry(PLDHashTable * table,
|
|
PLDHashEntryHdr * hdr,
|
|
uint32_t number,
|
|
void * arg);
|
|
|
|
// member variables
|
|
static const PLDHashTableOps ops;
|
|
PLDHashTable table;
|
|
bool initialized;
|
|
|
|
static const uint32_t kInitialTableLength = 256;
|
|
};
|
|
|
|
#endif // _nsCacheEntry_h_
|