Bumping gaia.json for 2 gaia revision(s) a=gaia-bump
[gecko.git] / netwerk / cache / nsDiskCacheBinding.h
blob56f12f3ad88e809b54ec5b8541f503f60e938eb0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #ifndef _nsDiskCacheBinding_h_
9 #define _nsDiskCacheBinding_h_
11 #include "mozilla/MemoryReporting.h"
12 #include "nspr.h"
13 #include "pldhash.h"
15 #include "nsISupports.h"
16 #include "nsCacheEntry.h"
18 #include "nsDiskCacheMap.h"
19 #include "nsDiskCacheStreams.h"
22 /******************************************************************************
23 * nsDiskCacheBinding
25 * Created for disk cache specific data and stored in nsCacheEntry.mData as
26 * an nsISupports. Also stored in nsDiskCacheHashTable, with collisions
27 * linked by the PRCList.
29 *****************************************************************************/
31 class nsDiskCacheDeviceDeactivateEntryEvent;
33 class nsDiskCacheBinding : public nsISupports, public PRCList {
34 virtual ~nsDiskCacheBinding();
36 public:
37 NS_DECL_THREADSAFE_ISUPPORTS
39 nsDiskCacheBinding(nsCacheEntry* entry, nsDiskCacheRecord * record);
41 nsresult EnsureStreamIO();
42 bool IsActive() { return mCacheEntry != nullptr;}
44 // XXX make friends
45 public:
46 nsCacheEntry* mCacheEntry; // back pointer to parent nsCacheEntry
47 nsDiskCacheRecord mRecord;
48 nsDiskCacheStreamIO* mStreamIO; // strong reference
49 bool mDoomed; // record is not stored in cache map
50 uint8_t mGeneration; // possibly just reservation
52 // If set, points to a pending event which will deactivate |mCacheEntry|.
53 // If not set then either |mCacheEntry| is not deactivated, or it has been
54 // deactivated but the device returned it from FindEntry() before the event
55 // fired. In both two latter cases this binding is to be considered valid.
56 nsDiskCacheDeviceDeactivateEntryEvent *mDeactivateEvent;
60 /******************************************************************************
61 * Utility Functions
62 *****************************************************************************/
64 nsDiskCacheBinding * GetCacheEntryBinding(nsCacheEntry * entry);
68 /******************************************************************************
69 * nsDiskCacheBindery
71 * Used to keep track of nsDiskCacheBinding associated with active/bound (and
72 * possibly doomed) entries. Lookups on 4 byte disk hash to find collisions
73 * (which need to be doomed, instead of just evicted. Collisions are linked
74 * using a PRCList to keep track of current generation number.
76 * Used to detect hash number collisions, and find available generation numbers.
78 * Not all nsDiskCacheBinding have a generation number.
80 * Generation numbers may be aquired late, or lost (when data fits in block file)
82 * Collisions can occur:
83 * BindEntry() - hashnumbers collide (possibly different keys)
85 * Generation number required:
86 * DeactivateEntry() - metadata written to disk, may require file
87 * GetFileForEntry() - force data to require file
88 * writing to stream - data size may require file
90 * Binding can be kept in PRCList in order of generation numbers.
91 * Binding with no generation number can be Appended to PRCList (last).
93 *****************************************************************************/
95 class nsDiskCacheBindery {
96 public:
97 nsDiskCacheBindery();
98 ~nsDiskCacheBindery();
100 nsresult Init();
101 void Reset();
103 nsDiskCacheBinding * CreateBinding(nsCacheEntry * entry,
104 nsDiskCacheRecord * record);
106 nsDiskCacheBinding * FindActiveBinding(uint32_t hashNumber);
107 void RemoveBinding(nsDiskCacheBinding * binding);
108 bool ActiveBindings();
110 size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf);
112 private:
113 nsresult AddBinding(nsDiskCacheBinding * binding);
115 // member variables
116 static const PLDHashTableOps ops;
117 PLDHashTable table;
118 bool initialized;
121 #endif /* _nsDiskCacheBinding_h_ */