webengine/osswebengine/cache/inc/HttpCacheStreamHandler.h
changeset 0 dd21522fd290
child 1 7c90e6132015
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Definition of CHttpCacheStreamHandler  
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef CHTTPCACHESTREAMHANDLER_H
       
    19 #define CHTTPCACHESTREAMHANDLER_H
       
    20 
       
    21 //  INCLUDES
       
    22 #include <e32base.h>
       
    23 #include <f32file.h>
       
    24 #include <s32file.h>
       
    25 
       
    26 // CONSTANTS
       
    27 
       
    28 // MACROS
       
    29 
       
    30 // DATA TYPES
       
    31 
       
    32 // FUNCTION PROTOTYPES
       
    33 
       
    34 // FORWARD DECLARATIONS
       
    35 class CHttpCacheEntry;
       
    36 class RFileWriteStream;
       
    37 class RFileReadStream;
       
    38 
       
    39 // CLASS DECLARATION
       
    40 
       
    41 /**
       
    42 *
       
    43 *  @lib
       
    44 *  @since 3.1
       
    45 */
       
    46 class CHttpCacheStreamEntry : public CBase
       
    47     {
       
    48     public:  // Constructors and destructor
       
    49 
       
    50         /**
       
    51         * Two-phased constructor.
       
    52         * @since 3.1
       
    53         * @param
       
    54         * @param
       
    55         * @return CHttpCacheStreamEntry object.
       
    56         */
       
    57         static CHttpCacheStreamEntry* NewL( RFs& aRfs, CHttpCacheEntry& aHttpCacheEntry, TDriveUnit aDrive,
       
    58             TInt64 aCriticalLevel );
       
    59 
       
    60         /**
       
    61         * Destructor.
       
    62         */
       
    63         virtual ~CHttpCacheStreamEntry();
       
    64 
       
    65     public: // new functions
       
    66 
       
    67         /**
       
    68         *
       
    69         * @since 3.1
       
    70         * @param
       
    71         * @return
       
    72         */
       
    73         inline CHttpCacheEntry* CacheEntry() const { return iHttpCacheEntry; }
       
    74 
       
    75         /**
       
    76         *
       
    77         * @since 3.1
       
    78         * @param
       
    79         * @return
       
    80         */
       
    81         void Erase();
       
    82 
       
    83         /**
       
    84         *
       
    85         * @since 3.1
       
    86         * @param
       
    87         * @return
       
    88         */
       
    89         HBufC8* HeadersL();
       
    90 
       
    91         /**
       
    92         *
       
    93         * @since 3.1
       
    94         * @param
       
    95         * @return
       
    96         */
       
    97         HBufC8* NextChunkL( TBool& aLastChunk );
       
    98 
       
    99         /**
       
   100         *
       
   101         * @since 3.1
       
   102         * @param
       
   103         * @return
       
   104         */
       
   105         TInt SaveHeaders( const TDesC8& aHeaderStr );
       
   106 
       
   107         /**
       
   108         *
       
   109         * @since 3.1
       
   110         * @param
       
   111         * @return
       
   112         */
       
   113         void RemoveHeaders();
       
   114 
       
   115         /**
       
   116         *
       
   117         * @since 3.1
       
   118         * @param
       
   119         * @return
       
   120         */
       
   121         TInt SaveBodyData( const TDesC8& aBodyStr );
       
   122 
       
   123         /**
       
   124         *
       
   125         * @since 3.1
       
   126         * @param
       
   127         * @return
       
   128         */
       
   129         void RemoveBodyData();
       
   130 
       
   131         /**
       
   132         * Flush
       
   133         * @since 3.1
       
   134         * @param
       
   135         * @return
       
   136         */
       
   137         TInt Flush();
       
   138 
       
   139     private:
       
   140 
       
   141         /**
       
   142         * Construct.
       
   143         * @since 3.1
       
   144         * @param
       
   145         * @param
       
   146         * @return CHttpCacheStreamEntry object.
       
   147         */
       
   148         CHttpCacheStreamEntry( RFs& aRfs, CHttpCacheEntry& aHttpCacheEntry, TDriveUnit aDrive,
       
   149             TInt64 aCriticalLevel );
       
   150 
       
   151         /**
       
   152         * By default Symbian 2nd phase constructor is private.
       
   153         */
       
   154         void ConstructL();
       
   155 
       
   156     private: //
       
   157 
       
   158         /**
       
   159         *
       
   160         * @since 3.1
       
   161         * @param
       
   162         * @return
       
   163         */
       
   164         void GetHeaderFileName( const TFileName& aBodyFileName, TFileName& aHeaderFileName );
       
   165 
       
   166         /**
       
   167         *
       
   168         * @since 3.1
       
   169         * @param
       
   170         * @return
       
   171         */
       
   172         TBool OpenCacheFiles();
       
   173 
       
   174         /**
       
   175         *
       
   176         * @since 3.1
       
   177         * @param
       
   178         * @return
       
   179         */
       
   180         TBool CreateNewFilesL();
       
   181 
       
   182         /**
       
   183         *
       
   184         * @since 3.1
       
   185         * @param
       
   186         * @return
       
   187         */
       
   188         void BodyFileName( TFileName& aBodyFileName );
       
   189 
       
   190         /**
       
   191         *
       
   192         * @since 3.1
       
   193         * @param
       
   194         * @return
       
   195         */
       
   196         TBool DiskSpaceBelowCriticalLevel( TInt aContentSize );
       
   197 
       
   198     private:    // Data
       
   199 
       
   200         //
       
   201         TBool               iFileOk;
       
   202         //
       
   203         RFs                 iRfs;       // not owned
       
   204         //
       
   205         RFile               iHeaderFile;      // owned
       
   206         //
       
   207         RFile               iBodyFile;      // owned
       
   208         //
       
   209         CHttpCacheEntry*    iHttpCacheEntry; // not owned
       
   210         //
       
   211         TDriveUnit          iDrive;
       
   212         //
       
   213         TInt64              iCriticalLevel;
       
   214         //
       
   215         HBufC8*             iCacheBuffer;   // owned
       
   216     };
       
   217 
       
   218 /**
       
   219 *
       
   220 *  @lib
       
   221 *  @since 3.1
       
   222 */
       
   223 class CHttpCacheStreamHandler : public CBase
       
   224     {
       
   225     public:  // Constructors and destructor
       
   226 
       
   227         /**
       
   228         * Two-phased constructor.
       
   229         * @since 3.1
       
   230         * @param
       
   231         * @param
       
   232         * @return CHttpCacheStreamHandler object.
       
   233         */
       
   234         static CHttpCacheStreamHandler* NewL( const TDesC& aDirectory, TInt aCriticalLevel );
       
   235 
       
   236         /**
       
   237         * Destructor.
       
   238         */
       
   239         virtual ~CHttpCacheStreamHandler();
       
   240 
       
   241     public: // new functions
       
   242 
       
   243         /**
       
   244         *
       
   245         * @since 3.1
       
   246         * @param
       
   247         * @return
       
   248         */
       
   249         inline TInt SavedContentSize() const { return iContentSize; }
       
   250 
       
   251         /**
       
   252         *
       
   253         * @since 3.1
       
   254         * @param
       
   255         * @return
       
   256         */
       
   257         TBool AttachL( CHttpCacheEntry& aCacheEntry );
       
   258 
       
   259         /**
       
   260         *
       
   261         * @since 3.1
       
   262         * @param
       
   263         * @return
       
   264         */
       
   265         void Detach( const CHttpCacheEntry& aCacheEntry );
       
   266 
       
   267         /**
       
   268         *
       
   269         * @since 3.1
       
   270         * @param
       
   271         * @return
       
   272         */
       
   273         void Erase( const CHttpCacheEntry& aCacheEntry );
       
   274 
       
   275         /**
       
   276         *
       
   277         * @since 3.1
       
   278         * @param
       
   279         * @return
       
   280         */
       
   281         HBufC8* HeadersL( CHttpCacheEntry& aCacheEntry );
       
   282 
       
   283         /**
       
   284         *
       
   285         * @since 3.1
       
   286         * @param
       
   287         * @return
       
   288         */
       
   289         HBufC8* NextChunkL( CHttpCacheEntry& aCacheEntry, TBool& aLastChunk );
       
   290 
       
   291         /**
       
   292         *
       
   293         * @since 3.1
       
   294         * @param
       
   295         * @return
       
   296         */
       
   297         TBool SaveHeaders( CHttpCacheEntry& aCacheEntry, const TDesC8& aHeaderStr );
       
   298 
       
   299         /**
       
   300         *
       
   301         * @since 3.1
       
   302         * @param
       
   303         * @return
       
   304         */
       
   305         void RemoveHeaders( CHttpCacheEntry& aCacheEntry );
       
   306 
       
   307         /**
       
   308         *
       
   309         * @since 3.1
       
   310         * @param
       
   311         * @return
       
   312         */
       
   313         TBool SaveBodyData( CHttpCacheEntry& aCacheEntry, const TDesC8& aBodyStr );
       
   314 
       
   315         /**
       
   316         *
       
   317         * @since 3.1
       
   318         * @param
       
   319         * @return
       
   320         */
       
   321         void RemoveBodyData( CHttpCacheEntry& aCacheEntry );
       
   322 
       
   323         /**
       
   324         * Flush
       
   325         * @since 3.1
       
   326         * @param
       
   327         * @return
       
   328         */
       
   329         TBool Flush( CHttpCacheEntry& aCacheEntry );
       
   330 
       
   331         /**
       
   332         *
       
   333         * @since 3.1
       
   334         * @param
       
   335         * @return
       
   336         */
       
   337         inline void SetStartupCacheSize( TInt aContentSize ) { iContentSize = aContentSize; }
       
   338 
       
   339 #ifdef _DEBUG
       
   340         /**
       
   341         *
       
   342         * @since 3.1
       
   343         * @param
       
   344         * @return
       
   345         */
       
   346         inline TBool Find( const CHttpCacheEntry& aCacheEntry ) { return ( FindStreamEntry( aCacheEntry ) != NULL );  }
       
   347 #endif // _DEBUG
       
   348     private:
       
   349 
       
   350         /**
       
   351         * Construct.
       
   352         * @since 3.1
       
   353         * @param
       
   354         * @param
       
   355         * @return CacheHandler object.
       
   356         */
       
   357         CHttpCacheStreamHandler();
       
   358 
       
   359         /**
       
   360         * By default Symbian 2nd phase constructor is private.
       
   361         */
       
   362         void ConstructL( const TDesC& aDirectory, TInt aCriticalLevel );
       
   363 
       
   364     private:
       
   365 
       
   366         /**
       
   367         *
       
   368         * @since 3.1
       
   369         * @param
       
   370         * @return
       
   371         */
       
   372         CHttpCacheStreamEntry* FindStreamEntry( const CHttpCacheEntry& aCacheEntry, TInt* aIndex = NULL );
       
   373 
       
   374 
       
   375 
       
   376     private:    // Data
       
   377 
       
   378         //
       
   379         RFs                                         iRfs;               // owned
       
   380         // attached entries
       
   381         CArrayPtrFlat<CHttpCacheStreamEntry>*       iActiveEntries;     // owned
       
   382         //
       
   383         TInt                                        iContentSize;
       
   384         //
       
   385         TDriveUnit          iDrive;
       
   386         //
       
   387         TInt64              iCriticalLevel;
       
   388         //
       
   389         TInt                iDiskFull;
       
   390     };
       
   391 
       
   392 #endif      // CHTTPCACHESTREAMHANDLER_H
       
   393 
       
   394 // End of File