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