michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: michael@0: #ifndef _nsDiskCacheBinding_h_ michael@0: #define _nsDiskCacheBinding_h_ michael@0: michael@0: #include "mozilla/MemoryReporting.h" michael@0: #include "nspr.h" michael@0: #include "pldhash.h" michael@0: michael@0: #include "nsISupports.h" michael@0: #include "nsCacheEntry.h" michael@0: michael@0: #include "nsDiskCacheMap.h" michael@0: #include "nsDiskCacheStreams.h" michael@0: michael@0: michael@0: /****************************************************************************** michael@0: * nsDiskCacheBinding michael@0: * michael@0: * Created for disk cache specific data and stored in nsCacheEntry.mData as michael@0: * an nsISupports. Also stored in nsDiskCacheHashTable, with collisions michael@0: * linked by the PRCList. michael@0: * michael@0: *****************************************************************************/ michael@0: michael@0: class nsDiskCacheDeviceDeactivateEntryEvent; michael@0: michael@0: class nsDiskCacheBinding : public nsISupports, public PRCList { michael@0: public: michael@0: NS_DECL_THREADSAFE_ISUPPORTS michael@0: michael@0: nsDiskCacheBinding(nsCacheEntry* entry, nsDiskCacheRecord * record); michael@0: virtual ~nsDiskCacheBinding(); michael@0: michael@0: nsresult EnsureStreamIO(); michael@0: bool IsActive() { return mCacheEntry != nullptr;} michael@0: michael@0: // XXX make friends michael@0: public: michael@0: nsCacheEntry* mCacheEntry; // back pointer to parent nsCacheEntry michael@0: nsDiskCacheRecord mRecord; michael@0: nsDiskCacheStreamIO* mStreamIO; // strong reference michael@0: bool mDoomed; // record is not stored in cache map michael@0: uint8_t mGeneration; // possibly just reservation michael@0: michael@0: // If set, points to a pending event which will deactivate |mCacheEntry|. michael@0: // If not set then either |mCacheEntry| is not deactivated, or it has been michael@0: // deactivated but the device returned it from FindEntry() before the event michael@0: // fired. In both two latter cases this binding is to be considered valid. michael@0: nsDiskCacheDeviceDeactivateEntryEvent *mDeactivateEvent; michael@0: }; michael@0: michael@0: michael@0: /****************************************************************************** michael@0: * Utility Functions michael@0: *****************************************************************************/ michael@0: michael@0: nsDiskCacheBinding * GetCacheEntryBinding(nsCacheEntry * entry); michael@0: michael@0: michael@0: michael@0: /****************************************************************************** michael@0: * nsDiskCacheBindery michael@0: * michael@0: * Used to keep track of nsDiskCacheBinding associated with active/bound (and michael@0: * possibly doomed) entries. Lookups on 4 byte disk hash to find collisions michael@0: * (which need to be doomed, instead of just evicted. Collisions are linked michael@0: * using a PRCList to keep track of current generation number. michael@0: * michael@0: * Used to detect hash number collisions, and find available generation numbers. michael@0: * michael@0: * Not all nsDiskCacheBinding have a generation number. michael@0: * michael@0: * Generation numbers may be aquired late, or lost (when data fits in block file) michael@0: * michael@0: * Collisions can occur: michael@0: * BindEntry() - hashnumbers collide (possibly different keys) michael@0: * michael@0: * Generation number required: michael@0: * DeactivateEntry() - metadata written to disk, may require file michael@0: * GetFileForEntry() - force data to require file michael@0: * writing to stream - data size may require file michael@0: * michael@0: * Binding can be kept in PRCList in order of generation numbers. michael@0: * Binding with no generation number can be Appended to PRCList (last). michael@0: * michael@0: *****************************************************************************/ michael@0: michael@0: class nsDiskCacheBindery { michael@0: public: michael@0: nsDiskCacheBindery(); michael@0: ~nsDiskCacheBindery(); michael@0: michael@0: nsresult Init(); michael@0: void Reset(); michael@0: michael@0: nsDiskCacheBinding * CreateBinding(nsCacheEntry * entry, michael@0: nsDiskCacheRecord * record); michael@0: michael@0: nsDiskCacheBinding * FindActiveBinding(uint32_t hashNumber); michael@0: void RemoveBinding(nsDiskCacheBinding * binding); michael@0: bool ActiveBindings(); michael@0: michael@0: size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf); michael@0: michael@0: private: michael@0: nsresult AddBinding(nsDiskCacheBinding * binding); michael@0: michael@0: // member variables michael@0: static const PLDHashTableOps ops; michael@0: PLDHashTable table; michael@0: bool initialized; michael@0: }; michael@0: michael@0: #endif /* _nsDiskCacheBinding_h_ */