Back to index

lightning-sunbird  0.9+nobinonly
nsDiskCacheDevice.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
00002  *
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is nsDiskCacheDevice.h, released
00017  * February 20, 2001.
00018  *
00019  * The Initial Developer of the Original Code is
00020  * Netscape Communications Corporation.
00021  * Portions created by the Initial Developer are Copyright (C) 2001
00022  * the Initial Developer. All Rights Reserved.
00023  *
00024  * Contributor(s):
00025  *   Gordon Sheridan <gordon@netscape.com>
00026  *   Patrick C. Beard <beard@netscape.com>
00027  *
00028  * Alternatively, the contents of this file may be used under the terms of
00029  * either the GNU General Public License Version 2 or later (the "GPL"), or
00030  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00031  * in which case the provisions of the GPL or the LGPL are applicable instead
00032  * of those above. If you wish to allow use of your version of this file only
00033  * under the terms of either the GPL or the LGPL, and not to allow others to
00034  * use your version of this file under the terms of the MPL, indicate your
00035  * decision by deleting the provisions above and replace them with the notice
00036  * and other provisions required by the GPL or the LGPL. If you do not delete
00037  * the provisions above, a recipient may use your version of this file under
00038  * the terms of any one of the MPL, the GPL or the LGPL.
00039  *
00040  * ***** END LICENSE BLOCK ***** */
00041 
00042 #ifndef _nsDiskCacheDevice_h_
00043 #define _nsDiskCacheDevice_h_
00044 
00045 #include "nsCacheDevice.h"
00046 #include "nsDiskCacheBinding.h"
00047 #include "nsDiskCacheBlockFile.h"
00048 #include "nsDiskCacheEntry.h"
00049 
00050 #include "nsILocalFile.h"
00051 #include "nsIObserver.h"
00052 #include "nsCOMArray.h"
00053 
00054 class nsDiskCacheMap;
00055 
00056 
00057 class nsDiskCacheDevice : public nsCacheDevice {
00058 public:
00059     nsDiskCacheDevice();
00060     virtual ~nsDiskCacheDevice();
00061 
00062     virtual nsresult        Init();
00063     virtual nsresult        Shutdown();
00064 
00065     virtual const char *    GetDeviceID(void);
00066     virtual nsCacheEntry *  FindEntry(nsCString * key, PRBool *collision);
00067     virtual nsresult        DeactivateEntry(nsCacheEntry * entry);
00068     virtual nsresult        BindEntry(nsCacheEntry * entry);
00069     virtual void            DoomEntry( nsCacheEntry * entry );
00070 
00071     virtual nsresult OpenInputStreamForEntry(nsCacheEntry *    entry,
00072                                              nsCacheAccessMode mode,
00073                                              PRUint32          offset,
00074                                              nsIInputStream ** result);
00075 
00076     virtual nsresult OpenOutputStreamForEntry(nsCacheEntry *     entry,
00077                                               nsCacheAccessMode  mode,
00078                                               PRUint32           offset,
00079                                               nsIOutputStream ** result);
00080 
00081     virtual nsresult        GetFileForEntry(nsCacheEntry *    entry,
00082                                             nsIFile **        result);
00083 
00084     virtual nsresult        OnDataSizeChange(nsCacheEntry * entry, PRInt32 deltaSize);
00085     
00086     virtual nsresult        Visit(nsICacheVisitor * visitor);
00087 
00088     virtual nsresult        EvictEntries(const char * clientID);
00089 
00093     void                    SetCacheParentDirectory(nsILocalFile * parentDir);
00094     void                    SetCapacity(PRUint32  capacity);
00095 
00096 
00097 /* private: */
00098 
00099     void                    getCacheDirectory(nsILocalFile ** result);
00100     PRUint32                getCacheCapacity();
00101     PRUint32                getCacheSize();
00102     PRUint32                getEntryCount();
00103     
00104     PRBool                  Initialized() { return mInitialized; }
00105     nsDiskCacheMap *        CacheMap()    { return mCacheMap; }
00106     nsresult                Shutdown_Private(PRBool flush);
00107     
00108 private:    
00113     nsresult    OpenDiskCache();
00114     nsresult    ClearDiskCache();
00115     nsresult    InitializeCacheDirectory();
00116 
00117 
00118     nsresult    EvictDiskCacheEntries(PRInt32  targetCapacity);
00119     
00123     nsCOMPtr<nsILocalFile>  mCacheDirectory;
00124     nsDiskCacheBindery      mBindery;
00125     PRUint32                mCacheCapacity;     // XXX need soft/hard limits, currentTotal
00126     nsDiskCacheMap *        mCacheMap;
00127     PRPackedBool            mInitialized;
00128 };
00129 
00130 #endif // _nsDiskCacheDevice_h_