1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
16 * The Original Code is nsDiskCacheDevice.h, released
19 * The Initial Developer of the Original Code is
20 * Netscape Communications Corporation.
21 * Portions created by the Initial Developer are Copyright (C) 2001
22 * the Initial Developer. All Rights Reserved.
25 * Gordon Sheridan <gordon@netscape.com>
26 * Patrick C. Beard <beard@netscape.com>
28 * Alternatively, the contents of this file may be used under the terms of
29 * either the GNU General Public License Version 2 or later (the "GPL"), or
30 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
31 * in which case the provisions of the GPL or the LGPL are applicable instead
32 * of those above. If you wish to allow use of your version of this file only
33 * under the terms of either the GPL or the LGPL, and not to allow others to
34 * use your version of this file under the terms of the MPL, indicate your
35 * decision by deleting the provisions above and replace them with the notice
36 * and other provisions required by the GPL or the LGPL. If you do not delete
37 * the provisions above, a recipient may use your version of this file under
38 * the terms of any one of the MPL, the GPL or the LGPL.
40 * ***** END LICENSE BLOCK ***** */
42 #ifndef _nsDiskCacheDevice_h_
43 #define _nsDiskCacheDevice_h_
45 #include "nsCacheDevice.h"
46 #include "nsDiskCacheBinding.h"
47 #include "nsDiskCacheBlockFile.h"
48 #include "nsDiskCacheEntry.h"
50 #include "nsILocalFile.h"
51 #include "nsIObserver.h"
52 #include "nsCOMArray.h"
57 class nsDiskCacheDevice
: public nsCacheDevice
{
60 virtual ~nsDiskCacheDevice();
62 virtual nsresult
Init();
63 virtual nsresult
Shutdown();
65 virtual const char * GetDeviceID(void);
66 virtual nsCacheEntry
* FindEntry(nsCString
* key
, PRBool
*collision
);
67 virtual nsresult
DeactivateEntry(nsCacheEntry
* entry
);
68 virtual nsresult
BindEntry(nsCacheEntry
* entry
);
69 virtual void DoomEntry( nsCacheEntry
* entry
);
71 virtual nsresult
OpenInputStreamForEntry(nsCacheEntry
* entry
,
72 nsCacheAccessMode mode
,
74 nsIInputStream
** result
);
76 virtual nsresult
OpenOutputStreamForEntry(nsCacheEntry
* entry
,
77 nsCacheAccessMode mode
,
79 nsIOutputStream
** result
);
81 virtual nsresult
GetFileForEntry(nsCacheEntry
* entry
,
84 virtual nsresult
OnDataSizeChange(nsCacheEntry
* entry
, PRInt32 deltaSize
);
86 virtual nsresult
Visit(nsICacheVisitor
* visitor
);
88 virtual nsresult
EvictEntries(const char * clientID
);
91 * Preference accessors
93 void SetCacheParentDirectory(nsILocalFile
* parentDir
);
94 void SetCapacity(PRUint32 capacity
);
98 void getCacheDirectory(nsILocalFile
** result
);
99 PRUint32
getCacheCapacity();
100 PRUint32
getCacheSize();
101 PRUint32
getEntryCount();
103 nsDiskCacheMap
* CacheMap() { return &mCacheMap
; }
110 PRBool
Initialized() { return mInitialized
; }
112 nsresult
Shutdown_Private(PRBool flush
);
114 nsresult
OpenDiskCache();
115 nsresult
ClearDiskCache();
117 nsresult
EvictDiskCacheEntries(PRUint32 targetCapacity
);
122 nsCOMPtr
<nsILocalFile
> mCacheDirectory
;
123 nsDiskCacheBindery mBindery
;
124 PRUint32 mCacheCapacity
; // Unit is KiB's
125 // XXX need soft/hard limits, currentTotal
126 nsDiskCacheMap mCacheMap
;
127 PRPackedBool mInitialized
;
130 #endif // _nsDiskCacheDevice_h_