2013-01-15 00:26:47 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* vim: set ts=8 sts=4 et sw=4 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2012-05-21 11:12:37 +00:00
|
|
|
* 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/. */
|
2001-02-23 13:18:01 +00:00
|
|
|
|
|
|
|
#ifndef _nsMemoryCacheDevice_h_
|
|
|
|
#define _nsMemoryCacheDevice_h_
|
|
|
|
|
|
|
|
#include "nsCacheDevice.h"
|
|
|
|
#include "pldhash.h"
|
|
|
|
#include "nsCacheEntry.h"
|
|
|
|
|
|
|
|
|
2013-01-15 00:26:47 +00:00
|
|
|
class nsIMemoryReporter;
|
2001-03-13 15:43:17 +00:00
|
|
|
class nsMemoryCacheDeviceInfo;
|
2001-02-23 13:18:01 +00:00
|
|
|
|
2001-03-20 22:42:03 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* nsMemoryCacheDevice
|
|
|
|
******************************************************************************/
|
2001-02-23 13:18:01 +00:00
|
|
|
class nsMemoryCacheDevice : public nsCacheDevice
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsMemoryCacheDevice();
|
|
|
|
virtual ~nsMemoryCacheDevice();
|
|
|
|
|
2001-03-29 05:54:58 +00:00
|
|
|
virtual nsresult Init();
|
|
|
|
virtual nsresult Shutdown();
|
2001-02-23 13:18:01 +00:00
|
|
|
|
2001-03-29 05:54:58 +00:00
|
|
|
virtual const char * GetDeviceID(void);
|
2001-03-13 15:43:17 +00:00
|
|
|
|
2001-03-29 05:54:58 +00:00
|
|
|
virtual nsresult BindEntry( nsCacheEntry * entry );
|
2011-09-29 06:19:26 +00:00
|
|
|
virtual nsCacheEntry * FindEntry( nsCString * key, bool *collision );
|
2001-03-29 05:54:58 +00:00
|
|
|
virtual void DoomEntry( nsCacheEntry * entry );
|
|
|
|
virtual nsresult DeactivateEntry( nsCacheEntry * entry );
|
2001-02-26 14:57:40 +00:00
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
virtual nsresult OpenInputStreamForEntry(nsCacheEntry * entry,
|
|
|
|
nsCacheAccessMode mode,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t offset,
|
2003-01-18 02:15:14 +00:00
|
|
|
nsIInputStream ** result);
|
|
|
|
|
|
|
|
virtual nsresult OpenOutputStreamForEntry(nsCacheEntry * entry,
|
|
|
|
nsCacheAccessMode mode,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t offset,
|
2003-01-18 02:15:14 +00:00
|
|
|
nsIOutputStream ** result);
|
2001-02-24 04:22:19 +00:00
|
|
|
|
2001-03-08 21:22:18 +00:00
|
|
|
virtual nsresult GetFileForEntry( nsCacheEntry * entry,
|
|
|
|
nsIFile ** result );
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
virtual nsresult OnDataSizeChange( nsCacheEntry * entry, int32_t deltaSize );
|
2001-03-07 09:27:36 +00:00
|
|
|
|
2001-03-08 21:00:02 +00:00
|
|
|
virtual nsresult Visit( nsICacheVisitor * visitor );
|
2001-03-29 05:54:58 +00:00
|
|
|
|
2001-06-28 01:30:26 +00:00
|
|
|
virtual nsresult EvictEntries(const char * clientID);
|
2012-05-24 15:31:54 +00:00
|
|
|
nsresult EvictPrivateEntries();
|
2001-03-08 21:00:02 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
void SetCapacity(int32_t capacity);
|
|
|
|
void SetMaxEntrySize(int32_t maxSizeInKilobytes);
|
2010-09-07 22:39:28 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
bool EntryIsTooBig(int64_t entrySize);
|
2011-07-19 01:22:36 +00:00
|
|
|
|
|
|
|
size_t TotalSize();
|
|
|
|
|
2001-02-23 13:18:01 +00:00
|
|
|
private:
|
2001-03-13 15:43:17 +00:00
|
|
|
friend class nsMemoryCacheDeviceInfo;
|
2011-10-17 14:59:28 +00:00
|
|
|
enum { DELETE_ENTRY = true,
|
|
|
|
DO_NOT_DELETE_ENTRY = false };
|
2003-03-25 07:05:33 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
void AdjustMemoryLimits( int32_t softLimit, int32_t hardLimit);
|
2011-09-29 06:19:26 +00:00
|
|
|
void EvictEntry( nsCacheEntry * entry , bool deleteEntry);
|
2001-04-04 03:30:45 +00:00
|
|
|
void EvictEntriesIfNecessary();
|
2012-08-22 15:56:38 +00:00
|
|
|
int EvictionList(nsCacheEntry * entry, int32_t deltaSize);
|
2001-03-07 09:27:36 +00:00
|
|
|
|
2012-05-24 15:31:54 +00:00
|
|
|
typedef bool (*EvictionMatcherFn)(nsCacheEntry* entry, void* args);
|
|
|
|
nsresult DoEvictEntries(EvictionMatcherFn matchFn, void* args);
|
|
|
|
|
2003-03-25 07:05:33 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
void CheckEntryCount();
|
|
|
|
#endif
|
2001-05-08 00:04:50 +00:00
|
|
|
/*
|
|
|
|
* Data members
|
|
|
|
*/
|
2003-03-25 07:05:33 +00:00
|
|
|
enum {
|
|
|
|
kQueueCount = 24 // entries > 2^23 (8Mb) start in last queue
|
|
|
|
};
|
2003-03-17 23:22:29 +00:00
|
|
|
|
2003-03-25 07:05:33 +00:00
|
|
|
nsCacheEntryHashTable mMemCacheEntries;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mInitialized;
|
2003-03-25 07:05:33 +00:00
|
|
|
|
|
|
|
PRCList mEvictionList[kQueueCount];
|
2001-02-23 13:18:01 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t mHardLimit;
|
|
|
|
int32_t mSoftLimit;
|
2001-02-23 13:18:01 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t mTotalSize;
|
|
|
|
int32_t mInactiveSize;
|
2001-03-07 09:27:36 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t mEntryCount;
|
|
|
|
int32_t mMaxEntryCount;
|
|
|
|
int32_t mMaxEntrySize; // internal unit is bytes
|
2003-03-17 23:22:29 +00:00
|
|
|
|
2001-03-04 00:11:30 +00:00
|
|
|
// XXX what other stats do we want to keep?
|
2013-01-15 00:26:47 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIMemoryReporter> mReporter;
|
2001-02-23 13:18:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2001-03-20 22:42:03 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* nsMemoryCacheDeviceInfo - used to call nsIVisitor for about:cache
|
|
|
|
******************************************************************************/
|
|
|
|
class nsMemoryCacheDeviceInfo : public nsICacheDeviceInfo {
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSICACHEDEVICEINFO
|
|
|
|
|
|
|
|
nsMemoryCacheDeviceInfo(nsMemoryCacheDevice* device)
|
|
|
|
: mDevice(device)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~nsMemoryCacheDeviceInfo() {}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsMemoryCacheDevice* mDevice;
|
|
|
|
};
|
2001-03-13 15:43:17 +00:00
|
|
|
|
|
|
|
|
2001-02-23 13:18:01 +00:00
|
|
|
#endif // _nsMemoryCacheDevice_h_
|