Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Functions | Variables
nsDiskCacheDeviceSQL.cpp File Reference
#include "private/pprio.h"
#include "prlong.h"
#include "nsCache.h"
#include "nsDiskCache.h"
#include "nsDiskCacheDeviceSQL.h"
#include "nsNetUtil.h"
#include "nsAutoPtr.h"
#include "nsString.h"
#include "nsPrintfCString.h"
#include "nsCRT.h"
#include "mozIStorageService.h"
#include "mozIStorageStatement.h"
#include "mozStorageCID.h"
#include "nsICacheVisitor.h"
#include "nsISeekableStream.h"

Go to the source code of this file.


class  AutoResetStatement
class  nsDiskCacheDeviceInfo
class  nsDiskCacheBinding
class  nsDiskCacheRecord
class  nsDiskCacheEntryInfo


#define LOG(args)   CACHE_LOG_DEBUG(args)
#define DCACHE_HASH_BITS   64


static nsresult EnsureDir (nsIFile *dir)
static PRBool DecomposeCacheEntryKey (const nsCString *fullKey, const char **cid, const char **key, nsCString &buf)
static PRUint64 DCacheHash (const char *key)
 nsDiskCache::Hash(const char * key)
static nsresult GetCacheDataFile (nsIFile *cacheDir, const char *cid, const char *key, int generation, nsCOMPtr< nsIFile > &file)
static nsCacheEntryCreateCacheEntry (nsDiskCacheDevice *device, const nsCString *fullKey, const nsDiskCacheRecord &rec)


static const char DISK_CACHE_DEVICE_ID [] = { "disk" }

Define Documentation

Definition at line 134 of file nsDiskCacheDeviceSQL.cpp.

Definition at line 133 of file nsDiskCacheDeviceSQL.cpp.

Definition at line 79 of file nsDiskCacheDeviceSQL.cpp.

Function Documentation

static nsCacheEntry* CreateCacheEntry ( nsDiskCacheDevice device,
const nsCString fullKey,
const nsDiskCacheRecord rec 
) [static]

Definition at line 395 of file nsDiskCacheDeviceSQL.cpp.

  if (rec.flags != 0)
    LOG(("refusing to load busy entry\n"));
    return nsnull;

  nsCacheEntry *entry;
  nsresult rv = nsCacheEntry::Create(fullKey->get(), // XXX enable sharing
                                     device, &entry);
  if (NS_FAILED(rv))
    return nsnull;

  entry->SetFetchCount((PRUint32) rec.fetchCount);
  entry->SetDataSize((PRUint32) rec.dataSize);

  entry->UnflattenMetaData((const char *) rec.metaData, rec.metaDataLen);

  // create a binding object for this entry
  nsDiskCacheBinding *binding =
  if (!binding)
    delete entry;
    return nsnull;

  return entry;

Here is the call graph for this function:

static PRUint64 DCacheHash ( const char *  key) [static]

nsDiskCache::Hash(const char * key)

This algorithm of this method implies nsDiskCacheRecords will be stored in a certain order on disk. If the algorithm changes, existing cache map files may become invalid, and therefore the kCurrentVersion needs to be revised.

Definition at line 145 of file nsDiskCacheDeviceSQL.cpp.

  PRUint64 h = 0;
  for (const PRUint8* s = (PRUint8*) key; *s != '\0'; ++s)
    h = (h >> (DCACHE_HASH_BITS - 4)) ^ (h << 4) ^ *s;
  return (h == 0 ? DCACHE_HASH_MAX : h);

Here is the caller graph for this function:

static PRBool DecomposeCacheEntryKey ( const nsCString fullKey,
const char **  cid,
const char **  key,
nsCString buf 
) [static]

Definition at line 97 of file nsDiskCacheDeviceSQL.cpp.

  buf = *fullKey;

  PRInt32 colon = buf.FindChar(':');
  if (colon == kNotFound)
    NS_ERROR("Invalid key");
    return PR_FALSE;
  buf.SetCharAt('\0', colon);

  *cid = buf.get();
  *key = buf.get() + colon + 1;

  return PR_TRUE;

Here is the call graph for this function:

Here is the caller graph for this function:

static nsresult EnsureDir ( nsIFile dir) [static]

Definition at line 87 of file nsDiskCacheDeviceSQL.cpp.

  PRBool exists;
  nsresult rv = dir->Exists(&exists);
  if (NS_SUCCEEDED(rv) && !exists)
    rv = dir->Create(nsIFile::DIRECTORY_TYPE, 0700);
  return rv;
static nsresult GetCacheDataFile ( nsIFile cacheDir,
const char *  cid,
const char *  key,
int  generation,
nsCOMPtr< nsIFile > &  file 
) [static]

Definition at line 347 of file nsDiskCacheDeviceSQL.cpp.

  if (!file)

  nsCAutoString fullKey;

  PRUint64 hash = DCacheHash(fullKey.get());

  PRUint32 dir1 = (PRUint32) (hash & 0x0F);
  PRUint32 dir2 = (PRUint32)((hash & 0xF0) >> 4);

  hash >>= 8;

  file->AppendNative(nsPrintfCString("%X", dir1));
  file->AppendNative(nsPrintfCString("%X", dir2));

  char leaf[64];
  PR_snprintf(leaf, sizeof(leaf), "%014llX-%X", hash, generation);
  return file->AppendNative(nsDependentCString(leaf));

Here is the call graph for this function:

Variable Documentation

const char DISK_CACHE_DEVICE_ID[] = { "disk" } [static]

Definition at line 77 of file nsDiskCacheDeviceSQL.cpp.