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.

     1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     2  *
     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
    24  *
    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.
    28  *
    29  *****************************************************************************/
    31 class nsDiskCacheDeviceDeactivateEntryEvent;
    33 class nsDiskCacheBinding : public nsISupports, public PRCList {
    34 public:
    35     NS_DECL_THREADSAFE_ISUPPORTS
    37     nsDiskCacheBinding(nsCacheEntry* entry, nsDiskCacheRecord * record);
    38     virtual ~nsDiskCacheBinding();
    40     nsresult EnsureStreamIO();
    41     bool     IsActive() { return mCacheEntry != nullptr;}
    43 // XXX make friends
    44 public:
    45     nsCacheEntry*           mCacheEntry;    // back pointer to parent nsCacheEntry
    46     nsDiskCacheRecord       mRecord;
    47     nsDiskCacheStreamIO*    mStreamIO;      // strong reference
    48     bool                    mDoomed;        // record is not stored in cache map
    49     uint8_t                 mGeneration;    // possibly just reservation
    51     // If set, points to a pending event which will deactivate |mCacheEntry|.
    52     // If not set then either |mCacheEntry| is not deactivated, or it has been
    53     // deactivated but the device returned it from FindEntry() before the event
    54     // fired. In both two latter cases this binding is to be considered valid.
    55     nsDiskCacheDeviceDeactivateEntryEvent *mDeactivateEvent;
    56 };
    59 /******************************************************************************
    60  *  Utility Functions
    61  *****************************************************************************/
    63 nsDiskCacheBinding *   GetCacheEntryBinding(nsCacheEntry * entry);
    67 /******************************************************************************
    68  *  nsDiskCacheBindery
    69  *
    70  *  Used to keep track of nsDiskCacheBinding associated with active/bound (and
    71  *  possibly doomed) entries.  Lookups on 4 byte disk hash to find collisions
    72  *  (which need to be doomed, instead of just evicted.  Collisions are linked
    73  *  using a PRCList to keep track of current generation number.
    74  *
    75  *  Used to detect hash number collisions, and find available generation numbers.
    76  *
    77  *  Not all nsDiskCacheBinding have a generation number.
    78  *
    79  *  Generation numbers may be aquired late, or lost (when data fits in block file)
    80  *
    81  *  Collisions can occur:
    82  *      BindEntry()       - hashnumbers collide (possibly different keys)
    83  *
    84  *  Generation number required:
    85  *      DeactivateEntry() - metadata written to disk, may require file
    86  *      GetFileForEntry() - force data to require file
    87  *      writing to stream - data size may require file
    88  *
    89  *  Binding can be kept in PRCList in order of generation numbers.
    90  *  Binding with no generation number can be Appended to PRCList (last).
    91  *
    92  *****************************************************************************/
    94 class nsDiskCacheBindery {
    95 public:
    96     nsDiskCacheBindery();
    97     ~nsDiskCacheBindery();
    99     nsresult                Init();
   100     void                    Reset();
   102     nsDiskCacheBinding *    CreateBinding(nsCacheEntry *       entry,
   103                                           nsDiskCacheRecord *  record);
   105     nsDiskCacheBinding *    FindActiveBinding(uint32_t  hashNumber);
   106     void                    RemoveBinding(nsDiskCacheBinding * binding);
   107     bool                    ActiveBindings();
   109     size_t                 SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf);
   111 private:
   112     nsresult                AddBinding(nsDiskCacheBinding * binding);
   114     // member variables
   115     static const PLDHashTableOps ops;
   116     PLDHashTable           table;
   117     bool                   initialized;
   118 };
   120 #endif /* _nsDiskCacheBinding_h_ */

mercurial