2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
*
|
2012-05-21 04:12:37 -07:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* 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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifndef _nsDiskCacheDevice_h_
|
|
|
|
#define _nsDiskCacheDevice_h_
|
|
|
|
|
2013-06-23 05:03:39 -07:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsCacheDevice.h"
|
|
|
|
#include "nsDiskCacheBinding.h"
|
|
|
|
#include "nsDiskCacheBlockFile.h"
|
|
|
|
#include "nsDiskCacheEntry.h"
|
|
|
|
|
2012-06-05 19:08:30 -07:00
|
|
|
#include "nsIFile.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIObserver.h"
|
|
|
|
#include "nsCOMArray.h"
|
|
|
|
|
|
|
|
class nsDiskCacheMap;
|
|
|
|
|
|
|
|
|
|
|
|
class nsDiskCacheDevice : public nsCacheDevice {
|
|
|
|
public:
|
|
|
|
nsDiskCacheDevice();
|
|
|
|
virtual ~nsDiskCacheDevice();
|
|
|
|
|
|
|
|
virtual nsresult Init();
|
|
|
|
virtual nsresult Shutdown();
|
|
|
|
|
|
|
|
virtual const char * GetDeviceID(void);
|
2011-09-28 23:19:26 -07:00
|
|
|
virtual nsCacheEntry * FindEntry(nsCString * key, bool *collision);
|
2007-03-22 10:30:00 -07:00
|
|
|
virtual nsresult DeactivateEntry(nsCacheEntry * entry);
|
|
|
|
virtual nsresult BindEntry(nsCacheEntry * entry);
|
|
|
|
virtual void DoomEntry( nsCacheEntry * entry );
|
|
|
|
|
|
|
|
virtual nsresult OpenInputStreamForEntry(nsCacheEntry * entry,
|
|
|
|
nsCacheAccessMode mode,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t offset,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIInputStream ** result);
|
|
|
|
|
|
|
|
virtual nsresult OpenOutputStreamForEntry(nsCacheEntry * entry,
|
|
|
|
nsCacheAccessMode mode,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t offset,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIOutputStream ** result);
|
|
|
|
|
|
|
|
virtual nsresult GetFileForEntry(nsCacheEntry * entry,
|
|
|
|
nsIFile ** result);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
virtual nsresult OnDataSizeChange(nsCacheEntry * entry, int32_t deltaSize);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
virtual nsresult Visit(nsICacheVisitor * visitor);
|
|
|
|
|
|
|
|
virtual nsresult EvictEntries(const char * clientID);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
bool EntryIsTooBig(int64_t entrySize);
|
2010-09-07 15:39:28 -07:00
|
|
|
|
2013-06-23 05:03:39 -07:00
|
|
|
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf);
|
2012-11-05 10:22:33 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Preference accessors
|
|
|
|
*/
|
2012-06-05 19:08:30 -07:00
|
|
|
void SetCacheParentDirectory(nsIFile * parentDir);
|
2012-08-22 08:56:38 -07:00
|
|
|
void SetCapacity(uint32_t capacity);
|
|
|
|
void SetMaxEntrySize(int32_t maxSizeInKilobytes);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/* private: */
|
|
|
|
|
2012-06-05 19:08:30 -07:00
|
|
|
void getCacheDirectory(nsIFile ** result);
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t getCacheCapacity();
|
|
|
|
uint32_t getCacheSize();
|
|
|
|
uint32_t getEntryCount();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsDiskCacheMap * CacheMap() { return &mCacheMap; }
|
|
|
|
|
|
|
|
private:
|
2011-04-17 10:31:15 -07:00
|
|
|
friend class nsDiskCacheDeviceDeactivateEntryEvent;
|
2012-01-06 07:19:10 -08:00
|
|
|
friend class nsEvictDiskCacheEntriesEvent;
|
2012-08-23 19:23:10 -07:00
|
|
|
friend class nsDiskCacheMap;
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Private methods
|
|
|
|
*/
|
|
|
|
|
2011-04-17 10:31:15 -07:00
|
|
|
inline bool IsValidBinding(nsDiskCacheBinding *binding)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ASSERTION(binding, " binding == nullptr");
|
|
|
|
NS_ASSERTION(binding->mDeactivateEvent == nullptr,
|
2011-04-17 10:31:15 -07:00
|
|
|
" entry in process of deactivation");
|
|
|
|
return (binding && !binding->mDeactivateEvent);
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool Initialized() { return mInitialized; }
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
nsresult Shutdown_Private(bool flush);
|
2011-04-17 10:31:15 -07:00
|
|
|
nsresult DeactivateEntry_Private(nsCacheEntry * entry,
|
|
|
|
nsDiskCacheBinding * binding);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsresult OpenDiskCache();
|
|
|
|
nsresult ClearDiskCache();
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
nsresult EvictDiskCacheEntries(uint32_t targetCapacity);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Member variables
|
|
|
|
*/
|
2012-06-05 19:08:30 -07:00
|
|
|
nsCOMPtr<nsIFile> mCacheDirectory;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsDiskCacheBindery mBindery;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mCacheCapacity; // Unit is KiB's
|
|
|
|
int32_t mMaxEntrySize; // Unit is bytes internally
|
2007-03-22 10:30:00 -07:00
|
|
|
// XXX need soft/hard limits, currentTotal
|
|
|
|
nsDiskCacheMap mCacheMap;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mInitialized;
|
2012-04-12 09:27:38 -07:00
|
|
|
bool mClearingDiskCache;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // _nsDiskCacheDevice_h_
|