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 nsDiskCacheBinding.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 ***** */
43 #ifndef _nsDiskCacheBinding_h_
44 #define _nsDiskCacheBinding_h_
49 #include "nsISupports.h"
50 #include "nsCacheEntry.h"
52 #include "nsDiskCacheMap.h"
53 #include "nsDiskCacheStreams.h"
56 /******************************************************************************
59 * Created for disk cache specific data and stored in nsCacheEntry.mData as
60 * an nsISupports. Also stored in nsDiskCacheHashTable, with collisions
61 * linked by the PRCList.
63 *****************************************************************************/
65 class nsDiskCacheBinding
: public nsISupports
, public PRCList
{
69 nsDiskCacheBinding(nsCacheEntry
* entry
, nsDiskCacheRecord
* record
);
70 virtual ~nsDiskCacheBinding();
72 nsresult
EnsureStreamIO();
73 PRBool
IsActive() { return mCacheEntry
!= nsnull
;}
77 nsCacheEntry
* mCacheEntry
; // back pointer to parent nsCacheEntry
78 nsDiskCacheRecord mRecord
;
79 nsDiskCacheStreamIO
* mStreamIO
; // strong reference
80 PRBool mDoomed
; // record is not stored in cache map
81 PRUint8 mGeneration
; // possibly just reservation
85 /******************************************************************************
87 *****************************************************************************/
89 nsDiskCacheBinding
* GetCacheEntryBinding(nsCacheEntry
* entry
);
93 /******************************************************************************
96 * Used to keep track of nsDiskCacheBinding associated with active/bound (and
97 * possibly doomed) entries. Lookups on 4 byte disk hash to find collisions
98 * (which need to be doomed, instead of just evicted. Collisions are linked
99 * using a PRCList to keep track of current generation number.
101 * Used to detect hash number collisions, and find available generation numbers.
103 * Not all nsDiskCacheBinding have a generation number.
105 * Generation numbers may be aquired late, or lost (when data fits in block file)
107 * Collisions can occur:
108 * BindEntry() - hashnumbers collide (possibly different keys)
110 * Generation number required:
111 * DeactivateEntry() - metadata written to disk, may require file
112 * GetFileForEntry() - force data to require file
113 * writing to stream - data size may require file
115 * Binding can be kept in PRCList in order of generation numbers.
116 * Binding with no generation number can be Appended to PRCList (last).
118 *****************************************************************************/
120 class nsDiskCacheBindery
{
122 nsDiskCacheBindery();
123 ~nsDiskCacheBindery();
128 nsDiskCacheBinding
* CreateBinding(nsCacheEntry
* entry
,
129 nsDiskCacheRecord
* record
);
131 nsDiskCacheBinding
* FindActiveBinding(PRUint32 hashNumber
);
132 void RemoveBinding(nsDiskCacheBinding
* binding
);
133 PRBool
ActiveBindings();
136 nsresult
AddBinding(nsDiskCacheBinding
* binding
);
139 static PLDHashTableOps ops
;
144 #endif /* _nsDiskCacheBinding_h_ */