1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 : *
3 : * ***** BEGIN LICENSE BLOCK *****
4 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 : *
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/
10 : *
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.
15 : *
16 : * The Original Code is nsDiskCacheBinding.h, released
17 : * May 10, 2001.
18 : *
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.
23 : *
24 : * Contributor(s):
25 : * Gordon Sheridan <gordon@netscape.com>
26 : * Patrick C. Beard <beard@netscape.com>
27 : *
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.
39 : *
40 : * ***** END LICENSE BLOCK ***** */
41 :
42 :
43 : #ifndef _nsDiskCacheBinding_h_
44 : #define _nsDiskCacheBinding_h_
45 :
46 : #include "nspr.h"
47 : #include "pldhash.h"
48 :
49 : #include "nsISupports.h"
50 : #include "nsCacheEntry.h"
51 :
52 : #include "nsDiskCacheMap.h"
53 : #include "nsDiskCacheStreams.h"
54 :
55 :
56 : /******************************************************************************
57 : * nsDiskCacheBinding
58 : *
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.
62 : *
63 : *****************************************************************************/
64 :
65 : class nsDiskCacheDeviceDeactivateEntryEvent;
66 :
67 : class nsDiskCacheBinding : public nsISupports, public PRCList {
68 : public:
69 : NS_DECL_ISUPPORTS
70 :
71 : nsDiskCacheBinding(nsCacheEntry* entry, nsDiskCacheRecord * record);
72 : virtual ~nsDiskCacheBinding();
73 :
74 : nsresult EnsureStreamIO();
75 0 : bool IsActive() { return mCacheEntry != nsnull;}
76 :
77 : // XXX make friends
78 : public:
79 : nsCacheEntry* mCacheEntry; // back pointer to parent nsCacheEntry
80 : nsDiskCacheRecord mRecord;
81 : nsDiskCacheStreamIO* mStreamIO; // strong reference
82 : bool mDoomed; // record is not stored in cache map
83 : PRUint8 mGeneration; // possibly just reservation
84 :
85 : // If set, points to a pending event which will deactivate |mCacheEntry|.
86 : // If not set then either |mCacheEntry| is not deactivated, or it has been
87 : // deactivated but the device returned it from FindEntry() before the event
88 : // fired. In both two latter cases this binding is to be considered valid.
89 : nsDiskCacheDeviceDeactivateEntryEvent *mDeactivateEvent;
90 : };
91 :
92 :
93 : /******************************************************************************
94 : * Utility Functions
95 : *****************************************************************************/
96 :
97 : nsDiskCacheBinding * GetCacheEntryBinding(nsCacheEntry * entry);
98 :
99 :
100 :
101 : /******************************************************************************
102 : * nsDiskCacheBindery
103 : *
104 : * Used to keep track of nsDiskCacheBinding associated with active/bound (and
105 : * possibly doomed) entries. Lookups on 4 byte disk hash to find collisions
106 : * (which need to be doomed, instead of just evicted. Collisions are linked
107 : * using a PRCList to keep track of current generation number.
108 : *
109 : * Used to detect hash number collisions, and find available generation numbers.
110 : *
111 : * Not all nsDiskCacheBinding have a generation number.
112 : *
113 : * Generation numbers may be aquired late, or lost (when data fits in block file)
114 : *
115 : * Collisions can occur:
116 : * BindEntry() - hashnumbers collide (possibly different keys)
117 : *
118 : * Generation number required:
119 : * DeactivateEntry() - metadata written to disk, may require file
120 : * GetFileForEntry() - force data to require file
121 : * writing to stream - data size may require file
122 : *
123 : * Binding can be kept in PRCList in order of generation numbers.
124 : * Binding with no generation number can be Appended to PRCList (last).
125 : *
126 : *****************************************************************************/
127 :
128 : class nsDiskCacheBindery {
129 : public:
130 : nsDiskCacheBindery();
131 : ~nsDiskCacheBindery();
132 :
133 : nsresult Init();
134 : void Reset();
135 :
136 : nsDiskCacheBinding * CreateBinding(nsCacheEntry * entry,
137 : nsDiskCacheRecord * record);
138 :
139 : nsDiskCacheBinding * FindActiveBinding(PRUint32 hashNumber);
140 : void RemoveBinding(nsDiskCacheBinding * binding);
141 : bool ActiveBindings();
142 :
143 : private:
144 : nsresult AddBinding(nsDiskCacheBinding * binding);
145 :
146 : // member variables
147 : static PLDHashTableOps ops;
148 : PLDHashTable table;
149 : bool initialized;
150 : };
151 :
152 : #endif /* _nsDiskCacheBinding_h_ */
|