Back to index

lightning-sunbird  0.9+nobinonly
Classes | Functions
nsDiskCacheEntry.h File Reference
#include "nsDiskCacheMap.h"
#include "nsCacheEntry.h"
#include "nsICacheVisitor.h"
#include "nspr.h"
#include "nscore.h"
#include "nsError.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  nsDiskCacheEntry
class  nsDiskCacheEntryInfo

Functions

nsDiskCacheEntryCreateDiskCacheEntry (nsDiskCacheBinding *binding)
 CreateDiskCacheEntry(nsCacheEntry * entry)

Function Documentation

CreateDiskCacheEntry(nsCacheEntry * entry)

Prepare an nsCacheEntry for writing to disk

Definition at line 113 of file nsDiskCacheEntry.cpp.

{
    nsCacheEntry * entry = binding->mCacheEntry;
    if (!entry)  return nsnull;
    
    PRUint32  keySize  = entry->Key()->Length() + 1;
    PRUint32  metaSize = entry->MetaDataSize();
    PRUint32  size     = sizeof(nsDiskCacheEntry) + keySize + metaSize;
    
    // pad size so we can write to block files without overrunning buffer
    PRInt32 pad;
    if      (size <=  1024) pad = (((size-1)/ 256) + 1) *  256;
    else if (size <=  4096) pad = (((size-1)/1024) + 1) * 1024;
    else if (size <= 16384) pad = (((size-1)/4096) + 1) * 4096;
    else return nsnull; // unexpected size!
    
    nsDiskCacheEntry * diskEntry = (nsDiskCacheEntry *)new char[pad];
    if (!diskEntry)  return nsnull;
    
    diskEntry->mHeaderVersion   = nsDiskCache::kCurrentVersion;
    diskEntry->mMetaLocation    = binding->mRecord.MetaLocation();
    diskEntry->mFetchCount      = entry->FetchCount();
    diskEntry->mLastFetched     = entry->LastFetched();
    diskEntry->mLastModified    = entry->LastModified();
    diskEntry->mExpirationTime  = entry->ExpirationTime();
    diskEntry->mDataSize        = entry->DataSize();
    diskEntry->mKeySize         = keySize;
    diskEntry->mMetaDataSize    = metaSize;
    
    memcpy(diskEntry->mKeyStart, entry->Key()->get(),keySize);
    
    nsresult rv = entry->FlattenMetaData(&diskEntry->mKeyStart[keySize], metaSize);
    if (NS_FAILED(rv)) {
        delete [] (char *)diskEntry;
        return nsnull;
    }
        
    pad -= diskEntry->Size();
    NS_ASSERTION(pad >= 0, "under allocated buffer for diskEntry.");
    if (pad > 0)
        memset(&diskEntry->mKeyStart[keySize+metaSize], 0, pad);
    
    return  diskEntry;
}

Here is the call graph for this function:

Here is the caller graph for this function: