netwerk/cache/nsDiskCacheBinding.h

Thu, 15 Jan 2015 15:55:04 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:55:04 +0100
branch
TOR_BUG_9701
changeset 9
a63d609f5ebe
permissions
-rw-r--r--

Back out 97036ab72558 which inappropriately compared turds to third parties.

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

mercurial