LCOV - code coverage report
Current view: directory - netwerk/cache - nsDiskCacheDevice.h (source / functions) Found Hit Coverage
Test: app.info Lines: 6 6 100.0 %
Date: 2012-06-02 Functions: 3 3 100.0 %

       1                 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
       2                 :  *
       3                 :  * ***** BEGIN LICENSE BLOCK *****
       4                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       5                 :  *
       6                 :  * The contents of this file are subject to the Mozilla Public License Version
       7                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       8                 :  * the License. You may obtain a copy of the License at
       9                 :  * http://www.mozilla.org/MPL/
      10                 :  *
      11                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      12                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      13                 :  * for the specific language governing rights and limitations under the
      14                 :  * License.
      15                 :  *
      16                 :  * The Original Code is nsDiskCacheDevice.h, released
      17                 :  * February 20, 2001.
      18                 :  *
      19                 :  * The Initial Developer of the Original Code is
      20                 :  * Netscape Communications Corporation.
      21                 :  * Portions created by the Initial Developer are Copyright (C) 2001
      22                 :  * the Initial Developer. All Rights Reserved.
      23                 :  *
      24                 :  * Contributor(s):
      25                 :  *   Gordon Sheridan <gordon@netscape.com>
      26                 :  *   Patrick C. Beard <beard@netscape.com>
      27                 :  *
      28                 :  * Alternatively, the contents of this file may be used under the terms of
      29                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      30                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      31                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      32                 :  * of those above. If you wish to allow use of your version of this file only
      33                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      34                 :  * use your version of this file under the terms of the MPL, indicate your
      35                 :  * decision by deleting the provisions above and replace them with the notice
      36                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      37                 :  * the provisions above, a recipient may use your version of this file under
      38                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      39                 :  *
      40                 :  * ***** END LICENSE BLOCK ***** */
      41                 : 
      42                 : #ifndef _nsDiskCacheDevice_h_
      43                 : #define _nsDiskCacheDevice_h_
      44                 : 
      45                 : #include "nsCacheDevice.h"
      46                 : #include "nsDiskCacheBinding.h"
      47                 : #include "nsDiskCacheBlockFile.h"
      48                 : #include "nsDiskCacheEntry.h"
      49                 : 
      50                 : #include "nsILocalFile.h"
      51                 : #include "nsIObserver.h"
      52                 : #include "nsCOMArray.h"
      53                 : 
      54                 : class nsDiskCacheMap;
      55                 : 
      56                 : 
      57                 : class nsDiskCacheDevice : public nsCacheDevice {
      58                 : public:
      59                 :     nsDiskCacheDevice();
      60                 :     virtual ~nsDiskCacheDevice();
      61                 : 
      62                 :     virtual nsresult        Init();
      63                 :     virtual nsresult        Shutdown();
      64                 : 
      65                 :     virtual const char *    GetDeviceID(void);
      66                 :     virtual nsCacheEntry *  FindEntry(nsCString * key, bool *collision);
      67                 :     virtual nsresult        DeactivateEntry(nsCacheEntry * entry);
      68                 :     virtual nsresult        BindEntry(nsCacheEntry * entry);
      69                 :     virtual void            DoomEntry( nsCacheEntry * entry );
      70                 : 
      71                 :     virtual nsresult OpenInputStreamForEntry(nsCacheEntry *    entry,
      72                 :                                              nsCacheAccessMode mode,
      73                 :                                              PRUint32          offset,
      74                 :                                              nsIInputStream ** result);
      75                 : 
      76                 :     virtual nsresult OpenOutputStreamForEntry(nsCacheEntry *     entry,
      77                 :                                               nsCacheAccessMode  mode,
      78                 :                                               PRUint32           offset,
      79                 :                                               nsIOutputStream ** result);
      80                 : 
      81                 :     virtual nsresult        GetFileForEntry(nsCacheEntry *    entry,
      82                 :                                             nsIFile **        result);
      83                 : 
      84                 :     virtual nsresult        OnDataSizeChange(nsCacheEntry * entry, PRInt32 deltaSize);
      85                 :     
      86                 :     virtual nsresult        Visit(nsICacheVisitor * visitor);
      87                 : 
      88                 :     virtual nsresult        EvictEntries(const char * clientID);
      89                 : 
      90                 :     bool                    EntryIsTooBig(PRInt64 entrySize);
      91                 : 
      92                 :     /**
      93                 :      * Preference accessors
      94                 :      */
      95                 :     void                    SetCacheParentDirectory(nsILocalFile * parentDir);
      96                 :     void                    SetCapacity(PRUint32  capacity);
      97                 :     void                    SetMaxEntrySize(PRInt32  maxSizeInKilobytes);
      98                 : 
      99                 : /* private: */
     100                 : 
     101                 :     void                    getCacheDirectory(nsILocalFile ** result);
     102                 :     PRUint32                getCacheCapacity();
     103                 :     PRUint32                getCacheSize();
     104                 :     PRUint32                getEntryCount();
     105                 :     
     106             871 :     nsDiskCacheMap *        CacheMap()    { return &mCacheMap; }
     107                 :     
     108                 : private:    
     109                 :     friend class nsDiskCacheDeviceDeactivateEntryEvent;
     110                 :     friend class nsEvictDiskCacheEntriesEvent;
     111                 :     /**
     112                 :      *  Private methods
     113                 :      */
     114                 : 
     115            2868 :     inline bool IsValidBinding(nsDiskCacheBinding *binding)
     116                 :     {
     117            2868 :         NS_ASSERTION(binding, "  binding == nsnull");
     118            2868 :         NS_ASSERTION(binding->mDeactivateEvent == nsnull,
     119                 :                      "  entry in process of deactivation");
     120            2868 :         return (binding && !binding->mDeactivateEvent);
     121                 :     }
     122                 : 
     123            3042 :     bool                    Initialized() { return mInitialized; }
     124                 : 
     125                 :     nsresult                Shutdown_Private(bool flush);
     126                 :     nsresult                DeactivateEntry_Private(nsCacheEntry * entry,
     127                 :                                                     nsDiskCacheBinding * binding);
     128                 : 
     129                 :     nsresult                OpenDiskCache();
     130                 :     nsresult                ClearDiskCache();
     131                 : 
     132                 :     nsresult                EvictDiskCacheEntries(PRUint32  targetCapacity);
     133                 :     
     134                 :     /**
     135                 :      *  Member variables
     136                 :      */
     137                 :     nsCOMPtr<nsILocalFile>  mCacheDirectory;
     138                 :     nsDiskCacheBindery      mBindery;
     139                 :     PRUint32                mCacheCapacity;     // Unit is KiB's
     140                 :     PRInt32                 mMaxEntrySize;      // Unit is bytes internally
     141                 :     // XXX need soft/hard limits, currentTotal
     142                 :     nsDiskCacheMap          mCacheMap;
     143                 :     bool                    mInitialized;
     144                 : };
     145                 : 
     146                 : #endif // _nsDiskCacheDevice_h_

Generated by: LCOV version 1.7