netwerk/cache/nsDiskCacheBinding.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/netwerk/cache/nsDiskCacheBinding.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,120 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     1.5 + *
     1.6 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +
    1.11 +#ifndef _nsDiskCacheBinding_h_
    1.12 +#define _nsDiskCacheBinding_h_
    1.13 +
    1.14 +#include "mozilla/MemoryReporting.h"
    1.15 +#include "nspr.h"
    1.16 +#include "pldhash.h"
    1.17 +
    1.18 +#include "nsISupports.h"
    1.19 +#include "nsCacheEntry.h"
    1.20 +
    1.21 +#include "nsDiskCacheMap.h"
    1.22 +#include "nsDiskCacheStreams.h"
    1.23 +
    1.24 +
    1.25 +/******************************************************************************
    1.26 + *  nsDiskCacheBinding
    1.27 + *
    1.28 + *  Created for disk cache specific data and stored in nsCacheEntry.mData as
    1.29 + *  an nsISupports.  Also stored in nsDiskCacheHashTable, with collisions
    1.30 + *  linked by the PRCList.
    1.31 + *
    1.32 + *****************************************************************************/
    1.33 +
    1.34 +class nsDiskCacheDeviceDeactivateEntryEvent;
    1.35 +
    1.36 +class nsDiskCacheBinding : public nsISupports, public PRCList {
    1.37 +public:
    1.38 +    NS_DECL_THREADSAFE_ISUPPORTS
    1.39 +
    1.40 +    nsDiskCacheBinding(nsCacheEntry* entry, nsDiskCacheRecord * record);
    1.41 +    virtual ~nsDiskCacheBinding();
    1.42 +
    1.43 +    nsresult EnsureStreamIO();
    1.44 +    bool     IsActive() { return mCacheEntry != nullptr;}
    1.45 +
    1.46 +// XXX make friends
    1.47 +public:
    1.48 +    nsCacheEntry*           mCacheEntry;    // back pointer to parent nsCacheEntry
    1.49 +    nsDiskCacheRecord       mRecord;
    1.50 +    nsDiskCacheStreamIO*    mStreamIO;      // strong reference
    1.51 +    bool                    mDoomed;        // record is not stored in cache map
    1.52 +    uint8_t                 mGeneration;    // possibly just reservation
    1.53 +
    1.54 +    // If set, points to a pending event which will deactivate |mCacheEntry|.
    1.55 +    // If not set then either |mCacheEntry| is not deactivated, or it has been
    1.56 +    // deactivated but the device returned it from FindEntry() before the event
    1.57 +    // fired. In both two latter cases this binding is to be considered valid.
    1.58 +    nsDiskCacheDeviceDeactivateEntryEvent *mDeactivateEvent;
    1.59 +};
    1.60 +
    1.61 +
    1.62 +/******************************************************************************
    1.63 + *  Utility Functions
    1.64 + *****************************************************************************/
    1.65 +
    1.66 +nsDiskCacheBinding *   GetCacheEntryBinding(nsCacheEntry * entry);
    1.67 +
    1.68 +
    1.69 +
    1.70 +/******************************************************************************
    1.71 + *  nsDiskCacheBindery
    1.72 + *
    1.73 + *  Used to keep track of nsDiskCacheBinding associated with active/bound (and
    1.74 + *  possibly doomed) entries.  Lookups on 4 byte disk hash to find collisions
    1.75 + *  (which need to be doomed, instead of just evicted.  Collisions are linked
    1.76 + *  using a PRCList to keep track of current generation number.
    1.77 + *
    1.78 + *  Used to detect hash number collisions, and find available generation numbers.
    1.79 + *
    1.80 + *  Not all nsDiskCacheBinding have a generation number.
    1.81 + *
    1.82 + *  Generation numbers may be aquired late, or lost (when data fits in block file)
    1.83 + *
    1.84 + *  Collisions can occur:
    1.85 + *      BindEntry()       - hashnumbers collide (possibly different keys)
    1.86 + *
    1.87 + *  Generation number required:
    1.88 + *      DeactivateEntry() - metadata written to disk, may require file
    1.89 + *      GetFileForEntry() - force data to require file
    1.90 + *      writing to stream - data size may require file
    1.91 + *
    1.92 + *  Binding can be kept in PRCList in order of generation numbers.
    1.93 + *  Binding with no generation number can be Appended to PRCList (last).
    1.94 + *
    1.95 + *****************************************************************************/
    1.96 +
    1.97 +class nsDiskCacheBindery {
    1.98 +public:
    1.99 +    nsDiskCacheBindery();
   1.100 +    ~nsDiskCacheBindery();
   1.101 +
   1.102 +    nsresult                Init();
   1.103 +    void                    Reset();
   1.104 +
   1.105 +    nsDiskCacheBinding *    CreateBinding(nsCacheEntry *       entry,
   1.106 +                                          nsDiskCacheRecord *  record);
   1.107 +
   1.108 +    nsDiskCacheBinding *    FindActiveBinding(uint32_t  hashNumber);
   1.109 +    void                    RemoveBinding(nsDiskCacheBinding * binding);
   1.110 +    bool                    ActiveBindings();
   1.111 +
   1.112 +    size_t                 SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf);
   1.113 +
   1.114 +private:
   1.115 +    nsresult                AddBinding(nsDiskCacheBinding * binding);
   1.116 +
   1.117 +    // member variables
   1.118 +    static const PLDHashTableOps ops;
   1.119 +    PLDHashTable           table;
   1.120 +    bool                   initialized;
   1.121 +};
   1.122 +
   1.123 +#endif /* _nsDiskCacheBinding_h_ */

mercurial