Back to index

lightning-sunbird  0.9+nobinonly
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Friends
nsCacheEntry Class Reference

#include <nsCacheEntry.h>

Collaboration diagram for nsCacheEntry:
Collaboration graph
[legend]

List of all members.

Public Types

enum  CacheEntryFlags {
  eStoragePolicyMask = 0x000000FF, eDoomedMask = 0x00000100, eEntryDirtyMask = 0x00000200, eDataDirtyMask = 0x00000400,
  eMetaDataDirtyMask = 0x00000800, eStreamDataMask = 0x00001000, eActiveMask = 0x00002000, eInitializedMask = 0x00004000,
  eValidMask = 0x00008000, eBindingMask = 0x00010000
}

Public Member Functions

 nsCacheEntry (nsCString *key, PRBool streamBased, nsCacheStoragePolicy storagePolicy)
 ~nsCacheEntry ()
nsCStringKey ()
PRInt32 FetchCount ()
void SetFetchCount (PRInt32 count)
void Fetched ()
PRUint32 LastFetched ()
void SetLastFetched (PRUint32 lastFetched)
PRUint32 LastModified ()
void SetLastModified (PRUint32 lastModified)
PRUint32 ExpirationTime ()
void SetExpirationTime (PRUint32 expires)
PRUint32 Size ()
nsCacheDeviceCacheDevice ()
void SetCacheDevice (nsCacheDevice *device)
const char * GetDeviceID ()
nsISupports * Data ()
 Data accessors.
void SetData (nsISupports *data)
PRUint32 DataSize ()
void SetDataSize (PRUint32 size)
void TouchData ()
void SetThread (PRThread *aThread)
const char * GetMetaDataElement (const char *key)
 Meta data accessors.
nsresult SetMetaDataElement (const char *key, const char *value)
nsresult VisitMetaDataElements (nsICacheMetaDataVisitor *visitor)
nsresult FlattenMetaData (char *buffer, PRUint32 bufSize)
nsresult UnflattenMetaData (const char *buffer, PRUint32 bufSize)
PRUint32 MetaDataSize ()
void TouchMetaData ()
nsresult GetSecurityInfo (nsISupports **result)
 Security Info accessors.
void SetSecurityInfo (nsISupports *info)
void MarkBinding ()
void ClearBinding ()
PRBool IsBinding ()
void MarkEntryDirty ()
void MarkEntryClean ()
void MarkDataDirty ()
void MarkDataClean ()
void MarkMetaDataDirty ()
void MarkMetaDataClean ()
void MarkStreamData ()
void MarkValid ()
void MarkInvalid ()
PRBool IsDoomed ()
PRBool IsEntryDirty ()
PRBool IsDataDirty ()
PRBool IsMetaDataDirty ()
PRBool IsStreamData ()
PRBool IsActive ()
PRBool IsInitialized ()
PRBool IsValid ()
PRBool IsInvalid ()
PRBool IsInUse ()
PRBool IsNotInUse ()
PRBool IsAllowedInMemory ()
PRBool IsAllowedOnDisk ()
nsCacheStoragePolicy StoragePolicy ()
void SetStoragePolicy (nsCacheStoragePolicy policy)
nsresult RequestAccess (nsCacheRequest *request, nsCacheAccessMode *accessGranted)
 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 CreateDescriptor (nsCacheRequest *request, nsCacheAccessMode accessGranted, nsICacheEntryDescriptor **result)
PRBool RemoveRequest (nsCacheRequest *request)
PRBool RemoveDescriptor (nsCacheEntryDescriptor *descriptor)

Static Public Member Functions

static nsresult Create (const char *key, PRBool streamBased, nsCacheStoragePolicy storagePolicy, nsCacheDevice *device, nsCacheEntry **result)

Private Member Functions

void DetachDescriptors (void)
void MarkDoomed ()
void MarkStreamBased ()
void MarkInitialized ()
void MarkActive ()
void MarkInactive ()

Private Attributes

nsCStringmKey
PRUint32 mFetchCount
PRUint32 mLastFetched
PRUint32 mLastModified
PRUint32 mLastValidated
PRUint32 mExpirationTime
PRUint32 mFlags
PRUint32 mDataSize
nsCacheDevicemCacheDevice
nsCOMPtr< nsISupports > mSecurityInfo
nsCOMPtr< nsISupports > mData
PRThreadmThread
nsCacheMetaData mMetaData
PRCList mRequestQ
PRCList mDescriptorQ

Friends

class nsCacheEntryHashTable
class nsCacheService

Detailed Description

Definition at line 65 of file nsCacheEntry.h.


Member Enumeration Documentation

Enumerator:
eStoragePolicyMask 
eDoomedMask 
eEntryDirtyMask 
eDataDirtyMask 
eMetaDataDirtyMask 
eStreamDataMask 
eActiveMask 
eInitializedMask 
eValidMask 
eBindingMask 

Definition at line 139 of file nsCacheEntry.h.

                         {
        eStoragePolicyMask   = 0x000000FF,
        eDoomedMask          = 0x00000100,
        eEntryDirtyMask      = 0x00000200,
        eDataDirtyMask       = 0x00000400,
        eMetaDataDirtyMask   = 0x00000800,
        eStreamDataMask      = 0x00001000,
        eActiveMask          = 0x00002000,
        eInitializedMask     = 0x00004000,
        eValidMask           = 0x00008000,
        eBindingMask         = 0x00010000
    };

Constructor & Destructor Documentation

nsCacheEntry::nsCacheEntry ( nsCString key,
PRBool  streamBased,
nsCacheStoragePolicy  storagePolicy 
)

Definition at line 55 of file nsCacheEntry.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 78 of file nsCacheEntry.cpp.

{
    MOZ_COUNT_DTOR(nsCacheEntry);
    delete mKey;
    
    if (IsStreamData())  return;

    // proxy release of of memory cache nsISupports objects
    if (!mData)  return;
    
    nsISupports * data = mData;
    NS_ADDREF(data);    // this reference will be owned by the proxy
    mData = nsnull;     // release our reference before switching threads

    nsCacheService::ProxyObjectRelease(data, mThread);
}

Here is the call graph for this function:


Member Function Documentation

Definition at line 98 of file nsCacheEntry.h.

{ return mCacheDevice; }

Here is the caller graph for this function:

Definition at line 153 of file nsCacheEntry.h.

Here is the caller graph for this function:

nsresult nsCacheEntry::Create ( const char *  key,
PRBool  streamBased,
nsCacheStoragePolicy  storagePolicy,
nsCacheDevice device,
nsCacheEntry **  result 
) [static]

Definition at line 97 of file nsCacheEntry.cpp.

{
    nsCString* newKey = new nsCString(key);
    if (!newKey) return NS_ERROR_OUT_OF_MEMORY;
    
    nsCacheEntry* entry = new nsCacheEntry(newKey, streamBased, storagePolicy);
    if (!entry) { delete newKey; return NS_ERROR_OUT_OF_MEMORY; }
    
    entry->SetCacheDevice(device);
    
    *result = entry;
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 212 of file nsCacheEntry.cpp.

{
    NS_ENSURE_ARG_POINTER(request && result);

    nsCacheEntryDescriptor * descriptor =
        new nsCacheEntryDescriptor(this, accessGranted);

    // XXX check request is on q
    PR_REMOVE_AND_INIT_LINK(request); // remove request regardless of success

    if (descriptor == nsnull)
        return NS_ERROR_OUT_OF_MEMORY;

    PR_APPEND_LINK(descriptor, &mDescriptorQ);

    NS_ADDREF(*result = descriptor);
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsISupports* nsCacheEntry::Data ( ) [inline]

Data accessors.

Definition at line 105 of file nsCacheEntry.h.

{ return mData; }

Here is the caller graph for this function:

Definition at line 108 of file nsCacheEntry.h.

{ return mDataSize; }

Here is the caller graph for this function:

Definition at line 264 of file nsCacheEntry.cpp.

{
    nsCacheEntryDescriptor * descriptor =
        (nsCacheEntryDescriptor *)PR_LIST_HEAD(&mDescriptorQ);

    while (descriptor != &mDescriptorQ) {
        nsCacheEntryDescriptor * nextDescriptor =
            (nsCacheEntryDescriptor *)PR_NEXT_LINK(descriptor);
        
        descriptor->ClearCacheEntry();
        PR_REMOVE_AND_INIT_LINK(descriptor);
        descriptor = nextDescriptor;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 93 of file nsCacheEntry.h.

{ return mExpirationTime; }

Here is the caller graph for this function:

Definition at line 83 of file nsCacheEntry.h.

{ return mFetchCount; }

Here is the caller graph for this function:

Definition at line 117 of file nsCacheEntry.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsCacheEntry::FlattenMetaData ( char *  buffer,
PRUint32  bufSize 
) [inline]

Definition at line 122 of file nsCacheEntry.h.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 126 of file nsCacheEntry.cpp.

{
    if (mCacheDevice)  return mCacheDevice->GetDeviceID();
    return nsnull;
}

Here is the call graph for this function:

const char* nsCacheEntry::GetMetaDataElement ( const char *  key) [inline]

Meta data accessors.

Definition at line 118 of file nsCacheEntry.h.

{ return mMetaData.GetElement(key); }

Here is the call graph for this function:

nsresult nsCacheEntry::GetSecurityInfo ( nsISupports **  result)

Security Info accessors.

Definition at line 150 of file nsCacheEntry.cpp.

Definition at line 173 of file nsCacheEntry.h.

{ return (mFlags & eActiveMask) != 0; }

Here is the caller graph for this function:

Definition at line 183 of file nsCacheEntry.h.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 189 of file nsCacheEntry.h.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 154 of file nsCacheEntry.h.

{ return (mFlags & eBindingMask) != 0; }

Here is the caller graph for this function:

Definition at line 170 of file nsCacheEntry.h.

{ return (mFlags & eDataDirtyMask) != 0; }

Definition at line 168 of file nsCacheEntry.h.

{ return (mFlags & eDoomedMask) != 0; }

Here is the caller graph for this function:

Definition at line 169 of file nsCacheEntry.h.

{ return (mFlags & eEntryDirtyMask) != 0; }

Definition at line 174 of file nsCacheEntry.h.

{ return (mFlags & eInitializedMask) != 0; }

Here is the caller graph for this function:

Definition at line 177 of file nsCacheEntry.h.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 176 of file nsCacheEntry.h.

{ return (mFlags & eValidMask) == 0; }

Here is the caller graph for this function:

Definition at line 171 of file nsCacheEntry.h.

{ return (mFlags & eMetaDataDirtyMask) != 0; }

Definition at line 180 of file nsCacheEntry.h.

{ return !IsInUse(); }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 172 of file nsCacheEntry.h.

{ return (mFlags & eStreamDataMask) != 0; }

Here is the caller graph for this function:

Definition at line 175 of file nsCacheEntry.h.

{ return (mFlags & eValidMask) != 0; }

Here is the caller graph for this function:

Definition at line 81 of file nsCacheEntry.h.

{ return mKey; }

Here is the caller graph for this function:

Definition at line 87 of file nsCacheEntry.h.

{ return mLastFetched; }

Here is the caller graph for this function:

Definition at line 90 of file nsCacheEntry.h.

{ return mLastModified; }

Here is the caller graph for this function:

void nsCacheEntry::MarkActive ( ) [inline, private]

Definition at line 230 of file nsCacheEntry.h.

Here is the caller graph for this function:

Definition at line 152 of file nsCacheEntry.h.

Here is the caller graph for this function:

Definition at line 159 of file nsCacheEntry.h.

Definition at line 158 of file nsCacheEntry.h.

Here is the caller graph for this function:

void nsCacheEntry::MarkDoomed ( ) [inline, private]

Definition at line 227 of file nsCacheEntry.h.

Here is the caller graph for this function:

Definition at line 157 of file nsCacheEntry.h.

Definition at line 156 of file nsCacheEntry.h.

Here is the caller graph for this function:

void nsCacheEntry::MarkInactive ( ) [inline, private]

Definition at line 231 of file nsCacheEntry.h.

Here is the caller graph for this function:

void nsCacheEntry::MarkInitialized ( ) [inline, private]

Definition at line 229 of file nsCacheEntry.h.

Here is the caller graph for this function:

Definition at line 164 of file nsCacheEntry.h.

{ mFlags &= ~eValidMask; }

Here is the caller graph for this function:

Definition at line 161 of file nsCacheEntry.h.

Definition at line 160 of file nsCacheEntry.h.

Here is the caller graph for this function:

void nsCacheEntry::MarkStreamBased ( ) [inline, private]

Definition at line 228 of file nsCacheEntry.h.

Here is the caller graph for this function:

Definition at line 162 of file nsCacheEntry.h.

Definition at line 163 of file nsCacheEntry.h.

Here is the caller graph for this function:

Definition at line 124 of file nsCacheEntry.h.

{ return mMetaData.Size(); }  

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 247 of file nsCacheEntry.cpp.

{
    NS_ASSERTION(descriptor->CacheEntry() == this, "### Wrong cache entry!!");
    PR_REMOVE_AND_INIT_LINK(descriptor);
    descriptor->ClearCacheEntry();

    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

    return PR_TRUE;     // find next best request to give a descriptor to
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 235 of file nsCacheEntry.cpp.

{
    // XXX if debug: verify this request belongs to this entry
    PR_REMOVE_AND_INIT_LINK(request);

    // return true if this entry should stay active
    return !((PR_CLIST_IS_EMPTY(&mRequestQ)) &&
             (PR_CLIST_IS_EMPTY(&mDescriptorQ)));
}

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)

Definition at line 167 of file nsCacheEntry.cpp.

{
    nsresult  rv = NS_OK;
    
    if (!IsInitialized()) {
        // brand new, unbound entry
        request->mKey = nsnull;  // steal ownership of the key string
        if (request->IsStreamBased())  MarkStreamBased();
        MarkInitialized();

        *accessGranted = request->AccessRequested() & nsICache::ACCESS_WRITE;
        NS_ASSERTION(*accessGranted, "new cache entry for READ-ONLY request");
        PR_APPEND_LINK(request, &mRequestQ);
        return rv;
    }
    
    if (IsDoomed()) return NS_ERROR_CACHE_ENTRY_DOOMED;

    if (IsStreamData() != request->IsStreamBased()) {
        *accessGranted = nsICache::ACCESS_NONE;
        return request->IsStreamBased() ?
            NS_ERROR_CACHE_DATA_IS_NOT_STREAM : NS_ERROR_CACHE_DATA_IS_STREAM;
    }

    if (PR_CLIST_IS_EMPTY(&mDescriptorQ)) {
        // 1st descriptor for existing bound entry
        *accessGranted = request->AccessRequested();
        if (*accessGranted & nsICache::ACCESS_WRITE) {
            MarkInvalid();
        } else {
            MarkValid();
        }
    } else {
        // nth request for existing, bound entry
        *accessGranted = request->AccessRequested() & ~nsICache::ACCESS_WRITE;
        if (!IsValid())
            rv = NS_ERROR_CACHE_WAIT_FOR_VALIDATION;
    }
    PR_APPEND_LINK(request,&mRequestQ);

    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 99 of file nsCacheEntry.h.

{ mCacheDevice = device; }

Here is the caller graph for this function:

void nsCacheEntry::SetData ( nsISupports *  data) [inline]

Definition at line 106 of file nsCacheEntry.h.

{ mData = data; }

Here is the caller graph for this function:

Definition at line 109 of file nsCacheEntry.h.

{ mDataSize = size; }

Here is the caller graph for this function:

Definition at line 94 of file nsCacheEntry.h.

{ mExpirationTime = expires; }

Here is the caller graph for this function:

Definition at line 84 of file nsCacheEntry.h.

Here is the caller graph for this function:

void nsCacheEntry::SetLastFetched ( PRUint32  lastFetched) [inline]

Definition at line 88 of file nsCacheEntry.h.

{ mLastFetched = lastFetched; }

Here is the caller graph for this function:

void nsCacheEntry::SetLastModified ( PRUint32  lastModified) [inline]

Definition at line 91 of file nsCacheEntry.h.

{ mLastModified = lastModified; }

Here is the caller graph for this function:

nsresult nsCacheEntry::SetMetaDataElement ( const char *  key,
const char *  value 
) [inline]

Definition at line 119 of file nsCacheEntry.h.

                                                          { return mMetaData.SetElement(key, value); }

Here is the call graph for this function:

void nsCacheEntry::SetSecurityInfo ( nsISupports *  info) [inline]

Definition at line 133 of file nsCacheEntry.h.

Definition at line 201 of file nsCacheEntry.h.

    {
        NS_ASSERTION(policy <= 0xFF, "too many bits in nsCacheStoragePolicy");
        mFlags &= ~eStoragePolicyMask; // clear storage policy bits
        mFlags |= policy;
    }

Here is the caller graph for this function:

void nsCacheEntry::SetThread ( PRThread aThread) [inline]

Definition at line 113 of file nsCacheEntry.h.

{ mThread = aThread; }

Here is the caller graph for this function:

Definition at line 96 of file nsCacheEntry.h.

{ return mDataSize + mMetaData.Size(); }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 196 of file nsCacheEntry.h.

Here is the caller graph for this function:

Definition at line 134 of file nsCacheEntry.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 142 of file nsCacheEntry.cpp.

Here is the call graph for this function:

nsresult nsCacheEntry::UnflattenMetaData ( const char *  buffer,
PRUint32  bufSize 
) [inline]

Definition at line 123 of file nsCacheEntry.h.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 121 of file nsCacheEntry.h.

{ return mMetaData.VisitElements(visitor); }

Here is the call graph for this function:


Friends And Related Function Documentation

friend class nsCacheEntryHashTable [friend]

Definition at line 221 of file nsCacheEntry.h.

friend class nsCacheService [friend]

Definition at line 222 of file nsCacheEntry.h.


Member Data Documentation

Definition at line 241 of file nsCacheEntry.h.

nsCOMPtr<nsISupports> nsCacheEntry::mData [private]

Definition at line 243 of file nsCacheEntry.h.

Definition at line 240 of file nsCacheEntry.h.

PRCList nsCacheEntry::mDescriptorQ [private]

Definition at line 247 of file nsCacheEntry.h.

Definition at line 238 of file nsCacheEntry.h.

Definition at line 234 of file nsCacheEntry.h.

Definition at line 239 of file nsCacheEntry.h.

Definition at line 233 of file nsCacheEntry.h.

Definition at line 235 of file nsCacheEntry.h.

Definition at line 236 of file nsCacheEntry.h.

Definition at line 237 of file nsCacheEntry.h.

Definition at line 245 of file nsCacheEntry.h.

PRCList nsCacheEntry::mRequestQ [private]

Definition at line 246 of file nsCacheEntry.h.

nsCOMPtr<nsISupports> nsCacheEntry::mSecurityInfo [private]

Definition at line 242 of file nsCacheEntry.h.

Definition at line 244 of file nsCacheEntry.h.


The documentation for this class was generated from the following files: