Bug 458861. Validate TrueType headers before activating downloaded font. r=roc, sr...
[wine-gecko.git] / netwerk / cache / src / nsMemoryCacheDevice.h
blob87cbd97f1a253bee0e8b7dcd9c527b23c7ae9aad
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
14 * License.
16 * The Original Code is nsMemoryCacheDevice.h, released
17 * February 20, 2001.
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.
24 * Contributor(s):
25 * Gordon Sheridan, 20-February-2001
26 * Brian Ryner <bryner@brianryner.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 _nsMemoryCacheDevice_h_
43 #define _nsMemoryCacheDevice_h_
45 #include "nsCacheDevice.h"
46 #include "pldhash.h"
47 #include "nsCacheEntry.h"
50 class nsMemoryCacheDeviceInfo;
52 /******************************************************************************
53 * nsMemoryCacheDevice
54 ******************************************************************************/
55 class nsMemoryCacheDevice : public nsCacheDevice
57 public:
58 nsMemoryCacheDevice();
59 virtual ~nsMemoryCacheDevice();
61 virtual nsresult Init();
62 virtual nsresult Shutdown();
64 virtual const char * GetDeviceID(void);
66 virtual nsresult BindEntry( nsCacheEntry * entry );
67 virtual nsCacheEntry * FindEntry( nsCString * key, PRBool *collision );
68 virtual void DoomEntry( nsCacheEntry * entry );
69 virtual nsresult DeactivateEntry( nsCacheEntry * entry );
71 virtual nsresult OpenInputStreamForEntry(nsCacheEntry * entry,
72 nsCacheAccessMode mode,
73 PRUint32 offset,
74 nsIInputStream ** result);
76 virtual nsresult OpenOutputStreamForEntry(nsCacheEntry * entry,
77 nsCacheAccessMode mode,
78 PRUint32 offset,
79 nsIOutputStream ** result);
81 virtual nsresult GetFileForEntry( nsCacheEntry * entry,
82 nsIFile ** result );
84 virtual nsresult OnDataSizeChange( nsCacheEntry * entry, PRInt32 deltaSize );
86 virtual nsresult Visit( nsICacheVisitor * visitor );
88 virtual nsresult EvictEntries(const char * clientID);
90 void SetCapacity(PRInt32 capacity);
92 private:
93 friend class nsMemoryCacheDeviceInfo;
94 enum { DELETE_ENTRY = PR_TRUE,
95 DO_NOT_DELETE_ENTRY = PR_FALSE };
97 void AdjustMemoryLimits( PRInt32 softLimit, PRInt32 hardLimit);
98 void EvictEntry( nsCacheEntry * entry , PRBool deleteEntry);
99 void EvictEntriesIfNecessary();
100 int EvictionList(nsCacheEntry * entry, PRInt32 deltaSize);
102 #ifdef DEBUG
103 void CheckEntryCount();
104 #endif
106 * Data members
108 enum {
109 kQueueCount = 24 // entries > 2^23 (8Mb) start in last queue
112 nsCacheEntryHashTable mMemCacheEntries;
113 PRBool mInitialized;
115 PRCList mEvictionList[kQueueCount];
116 PRInt32 mEvictionThreshold;
118 PRInt32 mHardLimit;
119 PRInt32 mSoftLimit;
121 PRInt32 mTotalSize;
122 PRInt32 mInactiveSize;
124 PRInt32 mEntryCount;
125 PRInt32 mMaxEntryCount;
127 // XXX what other stats do we want to keep?
131 /******************************************************************************
132 * nsMemoryCacheDeviceInfo - used to call nsIVisitor for about:cache
133 ******************************************************************************/
134 class nsMemoryCacheDeviceInfo : public nsICacheDeviceInfo {
135 public:
136 NS_DECL_ISUPPORTS
137 NS_DECL_NSICACHEDEVICEINFO
139 nsMemoryCacheDeviceInfo(nsMemoryCacheDevice* device)
140 : mDevice(device)
144 virtual ~nsMemoryCacheDeviceInfo() {}
146 private:
147 nsMemoryCacheDevice* mDevice;
151 #endif // _nsMemoryCacheDevice_h_