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_
|
|
|
|
|
|
|
|
#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,
|
|
|
|
PRUint32 offset,
|
|
|
|
nsIInputStream ** result);
|
|
|
|
|
|
|
|
virtual nsresult OpenOutputStreamForEntry(nsCacheEntry * entry,
|
|
|
|
nsCacheAccessMode mode,
|
|
|
|
PRUint32 offset,
|
|
|
|
nsIOutputStream ** result);
|
|
|
|
|
|
|
|
virtual nsresult GetFileForEntry(nsCacheEntry * entry,
|
|
|
|
nsIFile ** result);
|
|
|
|
|
|
|
|
virtual nsresult OnDataSizeChange(nsCacheEntry * entry, PRInt32 deltaSize);
|
|
|
|
|
|
|
|
virtual nsresult Visit(nsICacheVisitor * visitor);
|
|
|
|
|
|
|
|
virtual nsresult EvictEntries(const char * clientID);
|
|
|
|
|
2010-09-07 15:39:28 -07:00
|
|
|
bool EntryIsTooBig(PRInt64 entrySize);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Preference accessors
|
|
|
|
*/
|
2012-06-05 19:08:30 -07:00
|
|
|
void SetCacheParentDirectory(nsIFile * parentDir);
|
2007-03-22 10:30:00 -07:00
|
|
|
void SetCapacity(PRUint32 capacity);
|
2011-06-27 05:21:15 -07:00
|
|
|
void SetMaxEntrySize(PRInt32 maxSizeInKilobytes);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/* private: */
|
|
|
|
|
2012-06-05 19:08:30 -07:00
|
|
|
void getCacheDirectory(nsIFile ** result);
|
2007-03-22 10:30:00 -07:00
|
|
|
PRUint32 getCacheCapacity();
|
|
|
|
PRUint32 getCacheSize();
|
|
|
|
PRUint32 getEntryCount();
|
|
|
|
|
|
|
|
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;
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Private methods
|
|
|
|
*/
|
|
|
|
|
2011-04-17 10:31:15 -07:00
|
|
|
inline bool IsValidBinding(nsDiskCacheBinding *binding)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(binding, " binding == nsnull");
|
|
|
|
NS_ASSERTION(binding->mDeactivateEvent == nsnull,
|
|
|
|
" 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();
|
|
|
|
|
|
|
|
nsresult EvictDiskCacheEntries(PRUint32 targetCapacity);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Member variables
|
|
|
|
*/
|
2012-06-05 19:08:30 -07:00
|
|
|
nsCOMPtr<nsIFile> mCacheDirectory;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsDiskCacheBindery mBindery;
|
|
|
|
PRUint32 mCacheCapacity; // Unit is KiB's
|
2011-06-27 05:21:15 -07:00
|
|
|
PRInt32 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_
|