webengine/osswebengine/cache/inc/HttpCacheHandler.h
changeset 10 a359256acfc6
parent 1 7c90e6132015
child 11 c8a366e56285
equal deleted inserted replaced
5:10e98eab6f85 10:a359256acfc6
    19 #define CHTTPCACHEHANDLER_H
    19 #define CHTTPCACHEHANDLER_H
    20 
    20 
    21 //  INCLUDES
    21 //  INCLUDES
    22 #include <e32base.h>
    22 #include <e32base.h>
    23 #include <BrCtlDefs.h>
    23 #include <BrCtlDefs.h>
    24 #include <http\rhttpsession.h>
    24 #include <http/rhttpsession.h>
    25 #include <stringpool.h>
    25 #include <stringpool.h>
    26 
    26 
    27 // CONSTANTS
    27 // CONSTANTS
    28 
    28 
    29 // MACROS
    29 // MACROS
    42 class MHTTPDataSupplier;
    42 class MHTTPDataSupplier;
    43 class CIdle;
    43 class CIdle;
    44 class CHttpCacheEvictionHandler;
    44 class CHttpCacheEvictionHandler;
    45 class THttpCacheEntry;
    45 class THttpCacheEntry;
    46 class CHttpCacheObserver;
    46 class CHttpCacheObserver;
       
    47 class CHttpCacheFileWriteHandler;
    47 
    48 
    48 // CLASS DECLARATION
    49 // CLASS DECLARATION
       
    50 
       
    51 NONSHARABLE_CLASS( THttpCachePostponeParameters )
       
    52     {
       
    53     public:
       
    54         THttpCachePostponeParameters();
       
    55 
       
    56         TBool   iEnabled;
       
    57         TInt    iFreeRamThreshold;
       
    58         TInt    iImmediateWriteThreshold;
       
    59         TInt    iWriteTimeout;
       
    60     };
       
    61 
       
    62 NONSHARABLE_CLASS( TCompressedEntry )
       
    63     {
       
    64     public:
       
    65         ~TCompressedEntry() { if(!IsCompressed()) delete iName.iNameAsHBuf; };
       
    66         static TCompressedEntry *NewL( const TEntry& aEntry );
       
    67 
       
    68     private:
       
    69         TCompressedEntry(){};
       
    70         void ConstructL( const TEntry& aEntry );
       
    71         enum {
       
    72             EFilenameStoredAsUint32 = 0x01
       
    73         };
       
    74 
       
    75     public:
       
    76         TBool IsCompressed() { return (iFlags && TCompressedEntry::EFilenameStoredAsUint32); };
       
    77         static TBool ConvertANameToUint32( const TDesC& aName, TUint32& aConverted);
       
    78         static TInt ConvertAsciiToIntSingleHexDigit(const TUint16& aDigitChar);
       
    79         TUint32 GetSize() { return iSize; };
       
    80         HBufC* GetNameL();
       
    81         TUint32 GetCompressedName() { return iName.iNameAsUint32; };
       
    82 
       
    83     private:
       
    84         TUint32 iFlags;
       
    85         TUint32 iSize;
       
    86         union {
       
    87             TUint32 iNameAsUint32;
       
    88             HBufC*  iNameAsHBuf;
       
    89         }iName;
       
    90     };
       
    91 
       
    92 NONSHARABLE_CLASS( CCustomCacheDirList ) : public CBase
       
    93     {
       
    94     public:
       
    95         static CCustomCacheDirList* NewL(CDir *aSrc);
       
    96         ~CCustomCacheDirList() { iDirList.ResetAndDestroy(); };
       
    97 
       
    98     public:
       
    99         TBool ValidateCacheEntryL( const CHttpCacheEntry& aEntry );
       
   100         TInt Count();
       
   101         HBufC* NameAtL( TInt aIndex );
       
   102 
       
   103     private:
       
   104         CCustomCacheDirList();
       
   105         void ConstructL(CDir *aSrc);
       
   106 
       
   107     private:
       
   108         RPointerArray<TCompressedEntry> iDirList;
       
   109     };
       
   110 
       
   111 NONSHARABLE_CLASS( CCacheDirectoryFiles ) : public CBase
       
   112     {
       
   113     public:
       
   114         static CCacheDirectoryFiles* NewL(RFs aRfs, const TDesC& aDir);
       
   115         static CCacheDirectoryFiles* NewLC(RFs aRfs, const TDesC& aDir);
       
   116 
       
   117     public:
       
   118         /*
       
   119          * Check to see if the entry passed in has a valid file in the directory listing
       
   120          * returns ETrue if file present and size matches entry
       
   121          * otherwise EFalse.
       
   122          * Removes matching files from stored list.
       
   123          */
       
   124         TBool ValidateEntryL(const CHttpCacheEntry& aEntry);
       
   125 
       
   126         /*
       
   127          * Delete any files in the stored list from the filesystem
       
   128          * Intended to be called after you have validated all the entries
       
   129          * against the list - the content of the list will now only be the
       
   130          * orphan files in the cache subdirectories.
       
   131          * IMPORTANT: only call this once you've looked at all your entries.
       
   132          */
       
   133         void RemoveLeftoverFilesL();
       
   134 
       
   135     private:
       
   136         CCacheDirectoryFiles(RFs aRfs, const TDesC& aDir) : iRfs(aRfs), iDir(aDir) {};
       
   137         ~CCacheDirectoryFiles();
       
   138         void ConstructL();
       
   139 
       
   140     private:
       
   141         RFs iRfs;
       
   142         const TDesC& iDir;
       
   143 
       
   144         RPointerArray<CCustomCacheDirList> iDirContent;
       
   145     };
    49 
   146 
    50 /**
   147 /**
    51 *
   148 *
    52 *  @lib
   149 *  @lib
    53 *  @since 3.1
   150 *  @since 3.1
    61         * @since 3.1
   158         * @since 3.1
    62         * @param
   159         * @param
    63         * @param
   160         * @param
    64         * @return CacheHandler object.
   161         * @return CacheHandler object.
    65         */
   162         */
    66         static CHttpCacheHandler* NewL( TInt aSize, 
   163         static CHttpCacheHandler* NewL( TInt aSize,
    67             const TDesC& aDirectory,
   164             const TDesC& aDirectory,
    68             const TDesC& aIndexFile,
   165             const TDesC& aIndexFile,
    69             TInt aCriticalLevel );
   166             TInt aCriticalLevel,
       
   167             const THttpCachePostponeParameters& aPostpone);
    70 
   168 
    71         /**
   169         /**
    72         * Destructor.
   170         * Destructor.
    73         */
   171         */
    74         virtual ~CHttpCacheHandler();
   172         virtual ~CHttpCacheHandler();
   143         *
   241         *
   144         * @since 7.1
   242         * @since 7.1
   145         * @param
   243         * @param
   146         * @return
   244         * @return
   147         */
   245         */
   148         TInt CHttpCacheHandler::ListFiles(RPointerArray<TDesC>& aFilenameList);
   246         TInt ListFiles(RPointerArray<TDesC>& aFilenameList);
   149         
   247 
   150         /**
   248         /**
   151         *
   249         *
   152         * @since 3.1
   250         * @since 3.1
   153         * @param
   251         * @param
   154         * @return
   252         * @return
   196         * @param
   294         * @param
   197         * @return
   295         * @return
   198         */
   296         */
   199         void UpdateLookupTable();
   297         void UpdateLookupTable();
   200 
   298 
       
   299         /**
       
   300         *
       
   301         * @since 3.1
       
   302         * @param
       
   303         * @param
       
   304         * @return
       
   305         */
       
   306         void SaveLookupTableL();
       
   307 
   201     private:
   308     private:
   202 
   309 
   203         /**
   310         /**
   204         * Construct.
   311         * Construct.
   205         * @since 3.1
   312         * @since 3.1
   210         CHttpCacheHandler( TInt aSize );
   317         CHttpCacheHandler( TInt aSize );
   211 
   318 
   212         /**
   319         /**
   213         * By default Symbian 2nd phase constructor is private.
   320         * By default Symbian 2nd phase constructor is private.
   214         */
   321         */
   215         void ConstructL( const TDesC& aDirectory, const TDesC& aIndexFile,  TInt aCriticalLevel);
   322         void ConstructL( const TDesC& aDirectory, const TDesC& aIndexFile,  TInt aCriticalLevel, const THttpCachePostponeParameters& aPostpone);
   216 
   323 
   217     private: //
   324     private: //
   218 
   325 
   219         /**
   326         /**
   220         * Some other application modified the cache and the lookup table needs to be updated
   327         * Some other application modified the cache and the lookup table needs to be updated
   275         * @since 3.1
   382         * @since 3.1
   276         * @param
   383         * @param
   277         * @param
   384         * @param
   278         * @return
   385         * @return
   279         */
   386         */
   280         void SaveLookupTableL();
       
   281 
       
   282         /**
       
   283         *
       
   284         * @since 3.1
       
   285         * @param
       
   286         * @param
       
   287         * @return
       
   288         */
       
   289         void OpenLookupTableL();
   387         void OpenLookupTableL();
   290 
   388 
   291         /**
   389         /**
   292         *
   390         *
   293         * @since 3.1
   391         * @since 3.1
   313         * @param
   411         * @param
   314         * @param
   412         * @param
   315         * @return
   413         * @return
   316         */
   414         */
   317         TBool SaveBuffer( CHttpCacheEntry& aEntry, const TDesC8& aBuffer, TBool aBody = EFalse );
   415         TBool SaveBuffer( CHttpCacheEntry& aEntry, const TDesC8& aBuffer, TBool aBody = EFalse );
       
   416 
       
   417         /**
       
   418          *
       
   419          * @since 7.1
       
   420          * @param
       
   421          * @return
       
   422          */
       
   423         void GenerateValidationFilename(TDes& aFilename, const TDesC& aIndexFilename) const;
       
   424 
       
   425         /**
       
   426          *
       
   427          * @since 7.1
       
   428          * @param
       
   429          * @return
       
   430          */
       
   431         void ValidateCacheEntriesL();
   318 
   432 
   319     private:    // Data
   433     private:    // Data
   320 
   434 
   321         // hash table for cache entries
   435         // hash table for cache entries
   322         CHttpCacheLookupTable*          iLookupTable;   // owned
   436         CHttpCacheLookupTable*          iLookupTable;   // owned
   330         HBufC*                          iDirectory; // owned
   444         HBufC*                          iDirectory; // owned
   331         // name of the index file
   445         // name of the index file
   332         HBufC*                          iIndexFile; // owned
   446         HBufC*                          iIndexFile; // owned
   333         // Observing changes in cache
   447         // Observing changes in cache
   334         CHttpCacheObserver* iHttpCacheObserver; // owned
   448         CHttpCacheObserver* iHttpCacheObserver; // owned
   335     	// An opened and configured file server session
   449         // An opened and configured file server session
   336     	RFs iRfs;
   450         RFs iRfs;
       
   451         //
       
   452         CHttpCacheFileWriteHandler*     iPostponeHandler;   // owned
   337     };
   453     };
   338 
   454 
   339 #endif      // CHTTPCACHEHANDLER_H
   455 #endif      // CHTTPCACHEHANDLER_H
   340 
   456 
   341 // End of File
   457 // End of File