webengine/osswebengine/cache/src/HttpCacheManager.cpp
changeset 16 a359256acfc6
parent 8 7c90e6132015
child 17 c8a366e56285
equal deleted inserted replaced
13:10e98eab6f85 16:a359256acfc6
    17 
    17 
    18 // INCLUDE FILES
    18 // INCLUDE FILES
    19 #include "HttpCacheManager.h"
    19 #include "HttpCacheManager.h"
    20 #include "HttpCacheHandler.h"
    20 #include "HttpCacheHandler.h"
    21 #include "HttpCacheUtil.h"
    21 #include "HttpCacheUtil.h"
       
    22 #include "HttpCacheFileWriteHandler.h"
    22 #include <CenRepNotifyHandler.h>
    23 #include <CenRepNotifyHandler.h>
    23 #include <HttpCacheManagerInternalCRKeys.h>
    24 #include <HttpCacheManagerInternalCRKeys.h>
    24 #include <CoreApplicationUIsSDKCRKeys.h>
    25 #include <CoreApplicationUIsSDKCRKeys.h>
    25 #include <centralrepository.h>
    26 #include <centralrepository.h>
    26 #include <FeatMgr.h>
    27 #include <FeatMgr.h>
    38 // CONSTANTS
    39 // CONSTANTS
    39 
    40 
    40 // kbyte
    41 // kbyte
    41 const TUint KDefaultCacheSize = 1048576; // 1MB = 1024*1024
    42 const TUint KDefaultCacheSize = 1048576; // 1MB = 1024*1024
    42 _LIT( KDefaultCacheDir, "c:\\cache\\");
    43 _LIT( KDefaultCacheDir, "c:\\cache\\");
       
    44 _LIT( KDefaultOperatorCacheDir, "c:\\cache\\op\\");
       
    45 _LIT( KDefaultVssCacheDir, "c:\\cache\\vss\\");
    43 _LIT( KDefaultIndexFile, "index.dat" );
    46 _LIT( KDefaultIndexFile, "index.dat" );
    44 _LIT( KDefaultOpIndexFile, "index_op.dat" );
    47 _LIT( KDefaultOpIndexFile, "index_op.dat" );
    45 _LIT( KDefaultVSSIndexFile, "index_vss.dat" );
    48 _LIT( KDefaultVSSIndexFile, "index_vss.dat" );
    46 _LIT( KIndexFileExtension, ".dat" );
    49 _LIT( KIndexFileExtension, ".dat" );
       
    50 _LIT( KValidationFileExtension, ".val" );
    47 _LIT8( KVSSHeaderFileldName, "X-Vodafone-Content" );
    51 _LIT8( KVSSHeaderFileldName, "X-Vodafone-Content" );
    48 _LIT8( KVSSHeaderFileldValue, "Portal" );
    52 _LIT8( KVSSHeaderFileldValue, "Portal" );
    49 
    53 
    50 
    54 
    51 // MACROS
    55 // MACROS
   113     CleanupStack::Pop();
   117     CleanupStack::Pop();
   114 
   118 
   115     return self;
   119     return self;
   116     }
   120     }
   117 
   121 
       
   122 // -----------------------------------------------------------------------------
   118 // Destructor
   123 // Destructor
       
   124 // -----------------------------------------------------------------------------
   119 CHttpCacheManager::~CHttpCacheManager()
   125 CHttpCacheManager::~CHttpCacheManager()
   120     {
   126     {
   121     delete iOfflineNotifyHandler;
   127     delete iOfflineNotifyHandler;
   122     delete iOfflineRepository;
   128     delete iOfflineRepository;
   123     delete iCache;
   129     delete iCache;
   124     delete iOperatorCache;
   130     delete iOperatorCache;
   125     delete iOpDomain;
   131     delete iOpDomain;
   126     delete iphoneSpecificCache;
   132     delete iphoneSpecificCache;
   127     delete iVSSWhiteList;
   133     delete iVSSWhiteList;
       
   134     delete iFileWriteHandler;
   128     }
   135     }
   129 
   136 
   130 // -----------------------------------------------------------------------------
   137 // -----------------------------------------------------------------------------
   131 // CHttpCacheManager::VSSRequestCheck
   138 // CHttpCacheManager::VSSRequestCheck
   132 //
   139 //
   133 // -----------------------------------------------------------------------------
   140 // -----------------------------------------------------------------------------
   134 //
   141 //
   135 TBool CHttpCacheManager::VSSRequestCheck( const RHTTPTransaction& aTrans,
   142 TBool CHttpCacheManager::VSSRequestCheckL( const RHTTPTransaction& aTrans,
   136                                           const RHTTPHeaders& aHttpHeader,
   143                                            const RHTTPHeaders& aHttpHeader,
   137                                           const TDesC8& aUrl )
   144                                            const TDesC8& aUrl )
   138     {
   145     {
   139     TBool VSSTransaction ( EFalse );
   146     TBool VSSTransaction ( EFalse );
   140     if ( iVSSCacheEnabled && HttpCacheUtil::VSSCacheContent( aUrl, iVSSWhiteList ) )
   147     if ( iVSSCacheEnabled && HttpCacheUtil::VSSCacheContent( aUrl, iVSSWhiteList ) )
   141         {
   148         {
   142         RStringPool strP = aTrans.Session().StringPool();
   149         RStringPool strP = aTrans.Session().StringPool();
   176                 }
   183                 }
   177             CleanupStack::PopAndDestroy(); // VSSValueStr
   184             CleanupStack::PopAndDestroy(); // VSSValueStr
   178             }
   185             }
   179         CleanupStack::PopAndDestroy(); // VSSnameStr
   186         CleanupStack::PopAndDestroy(); // VSSnameStr
   180         } //end if( iVSSCacheEnabled && HttpCacheUtil::VSSCacheContent( aUrl, iVSSWhiteList ) )
   187         } //end if( iVSSCacheEnabled && HttpCacheUtil::VSSCacheContent( aUrl, iVSSWhiteList ) )
   181 
       
   182     return VSSTransaction;
   188     return VSSTransaction;
   183     }
   189     }
       
   190 
   184 // -----------------------------------------------------------------------------
   191 // -----------------------------------------------------------------------------
   185 // CHttpCacheManager::RequestL
   192 // CHttpCacheManager::RequestL
   186 //
   193 //
   187 // -----------------------------------------------------------------------------
   194 // -----------------------------------------------------------------------------
   188 //
   195 //
   212              if( status == KErrNotFound && iVSSCacheEnabled )
   219              if( status == KErrNotFound && iVSSCacheEnabled )
   213                 {
   220                 {
   214                  status = iphoneSpecificCache->RequestL( aTrans, aCacheMode, aCacheEntry );
   221                  status = iphoneSpecificCache->RequestL( aTrans, aCacheMode, aCacheEntry );
   215                  if( (status  == KErrNotReady) || (status == KErrNone ) )
   222                  if( (status  == KErrNotReady) || (status == KErrNone ) )
   216                  {
   223                  {
   217                  aCacheEntry.iCacheHandler = iphoneSpecificCache; 
   224                  aCacheEntry.iCacheHandler = iphoneSpecificCache;
   218                  }
   225                  }
   219                  else
   226                  else
   220                  {
   227                  {
   221                  // No entry found in any cache. Default to normal cache
   228                  // No entry found in any cache. Default to normal cache
   222                  aCacheEntry.iCacheHandler = cache;   
   229                  aCacheEntry.iCacheHandler = cache;
   223                  }
   230                  }
   224                 } 
   231                 }
   225             else
   232             else
   226             {
   233             {
   227             aCacheEntry.iCacheHandler = cache;  
   234             aCacheEntry.iCacheHandler = cache;
   228             }                
   235             }
   229            } //end if( cache )
   236            } //end if( cache )
   230 
   237 
   231         }//end  if( iCacheEnabled || iVSSCacheEnabled )
   238         }//end  if( iCacheEnabled || iVSSCacheEnabled )
   232     return status;
   239     return status;
   233     }
   240     }
   258     RHTTPTransaction& aTrans,
   265     RHTTPTransaction& aTrans,
   259     TBool& aLastChunk,
   266     TBool& aLastChunk,
   260     THttpCacheEntry& aCacheEntry )
   267     THttpCacheEntry& aCacheEntry )
   261     {
   268     {
   262     HBufC8* bodyStr = NULL;
   269     HBufC8* bodyStr = NULL;
   263 
       
   264     if( ( iCacheEnabled || iVSSCacheEnabled ) && aCacheEntry.iCacheHandler )
   270     if( ( iCacheEnabled || iVSSCacheEnabled ) && aCacheEntry.iCacheHandler )
   265         {
   271         {
   266         bodyStr = aCacheEntry.iCacheHandler->RequestNextChunkL( aTrans, aLastChunk, aCacheEntry );
   272         bodyStr = aCacheEntry.iCacheHandler->RequestNextChunkL( aTrans, aLastChunk, aCacheEntry );
   267         }
   273         }
       
   274 
   268     return bodyStr;
   275     return bodyStr;
   269     }
   276     }
   270 
   277 
   271 // -----------------------------------------------------------------------------
   278 // -----------------------------------------------------------------------------
   272 // CHttpCacheManager::RequestClosed
   279 // CHttpCacheManager::RequestClosed
   290 //
   297 //
   291 EXPORT_C void CHttpCacheManager::ReceivedResponseHeadersL(
   298 EXPORT_C void CHttpCacheManager::ReceivedResponseHeadersL(
   292   RHTTPTransaction& aTrans,
   299   RHTTPTransaction& aTrans,
   293     THttpCacheEntry& aCacheEntry )
   300     THttpCacheEntry& aCacheEntry )
   294     {
   301     {
   295     if( iCacheEnabled || iVSSCacheEnabled )
   302     if ( iCacheEnabled || iVSSCacheEnabled )
   296         {
   303         {
   297         if( iVSSCacheEnabled && VSSRequestCheck( aTrans, aTrans.Response().GetHeaderCollection(),
   304         if ( iVSSCacheEnabled &&
   298             aTrans.Request().URI().UriDes() ) )
   305              VSSRequestCheckL( aTrans, aTrans.Response().GetHeaderCollection(),
       
   306                                aTrans.Request().URI().UriDes() ) )
   299             {
   307             {
   300             //Modify the cache handler if VSS specific
   308             //Modify the cache handler if VSS specific
   301             aCacheEntry.iCacheHandler = iphoneSpecificCache;
   309             aCacheEntry.iCacheHandler = iphoneSpecificCache;
   302             }
   310             }
   303         if( aCacheEntry.iCacheHandler )
   311         if ( aCacheEntry.iCacheHandler )
   304             {
   312             {
   305             aCacheEntry.iCacheHandler->ReceivedResponseHeadersL( aTrans, aCacheEntry );
   313             aCacheEntry.iCacheHandler->ReceivedResponseHeadersL( aTrans, aCacheEntry );
   306             }
   314             }
   307         }
   315         }
   308     }
   316     }
   338         }
   346         }
   339     }
   347     }
   340 
   348 
   341 // -----------------------------------------------------------------------------
   349 // -----------------------------------------------------------------------------
   342 // CHttpCacheManager::RemoveAllL
   350 // CHttpCacheManager::RemoveAllL
   343 // Removes all files from HTTP cache. Also tries to remove orphaned files, 
   351 // Removes all files from HTTP cache. Also tries to remove orphaned files,
   344 // i.e files found on disk, but not registered in the cache's lookup table
   352 // i.e files found on disk, but not registered in the cache's lookup table
   345 // -----------------------------------------------------------------------------
   353 // -----------------------------------------------------------------------------
   346 //
   354 //
   347 EXPORT_C TInt CHttpCacheManager::RemoveAllL()
   355 EXPORT_C TInt CHttpCacheManager::RemoveAllL()
   348     {
   356     {
   350     // do not remove op cache
   358     // do not remove op cache
   351     if( iCacheEnabled )
   359     if( iCacheEnabled )
   352         {
   360         {
   353         numOfBytes = iCache->RemoveAllL();
   361         numOfBytes = iCache->RemoveAllL();
   354         }
   362         }
   355         
   363 
   356     //failure here is not mission critical
   364     //failure here is not mission critical
   357     TRAP_IGNORE( RemoveOrphanedFilesL() ); 
   365     TRAP_IGNORE( RemoveOrphanedFilesL() );
   358     
   366 
   359     return numOfBytes;
   367     return numOfBytes;
   360     }
   368     }
   361 
   369 
   362 
   370 // -----------------------------------------------------------------------------
       
   371 // FilePathHash
   363 // Hash function for Symbian file paths: discards case first
   372 // Hash function for Symbian file paths: discards case first
       
   373 // -----------------------------------------------------------------------------
   364 static TUint32 FilepathHash(const TDesC& aDes)
   374 static TUint32 FilepathHash(const TDesC& aDes)
   365 {
   375 {
   366     //since this function is intensively used by the HashMap, 
   376     //since this function is intensively used by the HashMap,
   367     //keeping (slow) heap allocation out of it. 
   377     //keeping (slow) heap allocation out of it.
   368     TBuf<KMaxPath> normalized ( aDes ); 
   378     TBuf<KMaxPath> normalized ( aDes );
   369      
   379 
   370     normalized.LowerCase();
   380     normalized.LowerCase();
   371     return DefaultHash::Des16( normalized );
   381     return DefaultHash::Des16( normalized );
   372 }
   382 }
   373 
   383 
   374 // Comparator for Symbian file paths: Use case-insensitive compare  
   384 // -----------------------------------------------------------------------------
       
   385 // FilepathIdent
       
   386 // Comparator for Symbian file paths: Use case-insensitive compare
       
   387 // -----------------------------------------------------------------------------
   375 static TBool FilepathIdent(const TDesC& aL, const TDesC& aR)
   388 static TBool FilepathIdent(const TDesC& aL, const TDesC& aR)
   376 {
   389 {
   377     return ( aL.CompareF(aR) == 0 );  
   390     return ( aL.CompareF(aR) == 0 );
   378 }
   391 }
   379 
   392 
   380 
   393 // -----------------------------------------------------------------------------
   381 // -----------------------------------------------------------------------------
   394 // CHttpCacheManager::RemoveOrphanedFilesL
   382 // CHttpCacheManager::RemoveOrphanedFilesL 
       
   383 // Removes header/body files that exist on the file-system, but are not known to the in-memory Cache lookup table(s)
   395 // Removes header/body files that exist on the file-system, but are not known to the in-memory Cache lookup table(s)
   384 // We do this because cache performance degrades substantially if there are too many files in a Symbian FAT32 directory. 
   396 // We do this because cache performance degrades substantially if there are too many files in a Symbian FAT32 directory.
   385 // Browser crash or out-of-battery situations may cause SaveLookuptable() to be not called, leading to such "orphaned files". 
   397 // Browser crash or out-of-battery situations may cause SaveLookuptable() to be not called, leading to such "orphaned files".
   386 // Due to high file-server interaction, don't call this method from performance critical code. 
   398 // Due to high file-server interaction, don't call this method from performance critical code.
   387 // -----------------------------------------------------------------------------
   399 // -----------------------------------------------------------------------------
   388 void CHttpCacheManager::RemoveOrphanedFilesL()
   400 void CHttpCacheManager::RemoveOrphanedFilesL()
   389     {
   401     {
   390 
   402     //Map that contains pointers to fully-qualified file paths as Keys, and "to be deleted flag" as Value.
   391     //Map that contains pointers to fully-qualified file paths as Keys, and "to be deleted flag" as Value. 
       
   392     RPtrHashMap<TDesC, TInt> onDiskFilesMap(&FilepathHash, &FilepathIdent);
   403     RPtrHashMap<TDesC, TInt> onDiskFilesMap(&FilepathHash, &FilepathIdent);
   393     CleanupClosePushL( onDiskFilesMap );
   404     CleanupClosePushL( onDiskFilesMap );
   394 
   405 
   395     //Pointers to the following TInt are used as VALUES in the HashMap...
   406     //Pointers to the following TInt are used as VALUES in the HashMap...
   396     // so they must be in scope for the lifecycle of the HashMap.
   407     // so they must be in scope for the lifecycle of the HashMap.
   397     const TInt needsDelete( 1 );
   408     const TInt needsDelete( 1 );
   398     const TInt noDelete( 0 );
   409     const TInt noDelete( 0 );
   399 
   410 
   400     //collects objects that need to be deleted later on 
   411     //collects objects that need to be deleted later on
   401     RPointerArray<HBufC> cleanupList;
   412     RPointerArray<HBufC> cleanupList;
   402     CleanupResetAndDestroyPushL( cleanupList );
   413     CleanupResetAndDestroyPushL( cleanupList );
   403 
   414 
   404     RFs rfs = CCoeEnv::Static()->FsSession();
   415     RFs rfs = CCoeEnv::Static()->FsSession();
   405     CDirScan* scanner = CDirScan::NewLC( rfs );
   416     CDirScan* scanner = CDirScan::NewLC( rfs );
   409     CDir* matchingFiles( 0 );
   420     CDir* matchingFiles( 0 );
   410 
   421 
   411     //Step 1. Find out all files on disk: by walking the directory hierarchy, one directory at a time
   422     //Step 1. Find out all files on disk: by walking the directory hierarchy, one directory at a time
   412     for (;;)
   423     for (;;)
   413         {
   424         {
   414         //1a. Get list of files in current directory, NULL if no directory left in tree 
   425         //1a. Get list of files in current directory, NULL if no directory left in tree
   415         scanner->NextL( matchingFiles );
   426         scanner->NextL( matchingFiles );
   416         if ( !matchingFiles )
   427         if ( !matchingFiles )
   417             break;
   428             break;
   418 
   429 
   419         TPtrC dir( scanner->FullPath() );       
   430         TPtrC dir( scanner->FullPath() );
   420         
   431 
   421         //1b. Add any files found to the HashTable
   432         //1b. Add any files found to the HashTable
   422         const TInt nMatches = matchingFiles->Count();
   433         const TInt nMatches = matchingFiles->Count();
   423         for ( TInt i = 0; i < nMatches; i++ )
   434         for ( TInt i = 0; i < nMatches; i++ )
   424             {
   435             {
   425             TEntry entry ( (*matchingFiles)[i] ) ; 
   436             TEntry entry ( (*matchingFiles)[i] ) ;
   426             if (entry.iName.Right( KIndexFileExtension().Length() ).
   437             TPtrC ext( entry.iName.Right( KIndexFileExtension().Length() ));
   427                     CompareF( KIndexFileExtension ) != 0) // ignore any .dat index files
   438 
       
   439             if ( ext.CompareF( KIndexFileExtension ) != 0 && // ignore any .dat index files
       
   440                  ext.CompareF( KValidationFileExtension ) != 0 ) // ignore any .val index files
   428                 {
   441                 {
   429                 HBufC* fullPath = HBufC::NewL( dir.Length() +  entry.iName.Length() );
   442                 HBufC* fullPath = HBufC::NewL( dir.Length() +  entry.iName.Length() );
   430                 cleanupList.Append( fullPath ); //keep object safe for later destruction
   443                 cleanupList.Append( fullPath ); //keep object safe for later destruction
   431                 fullPath->Des().Append( dir );
   444                 fullPath->Des().Append( dir );
   432                 fullPath->Des().Append( entry.iName ); //a fully qualified file path
   445                 fullPath->Des().Append( entry.iName ); //a fully qualified file path
   433                 onDiskFilesMap.Insert( fullPath, &needsDelete ); //add to the hash
   446                 onDiskFilesMap.Insert( fullPath, &needsDelete ); //add to the hash
   434                 }
   447                 }
   435             }
   448             }
   436             
       
   437 
   449 
   438         delete matchingFiles;
   450         delete matchingFiles;
   439         } // End of step 1: adding all known files on disk to Map
   451         } // End of step 1: adding all known files on disk to Map
   440 
   452 
   441     CleanupStack::PopAndDestroy( 1, scanner );
   453     CleanupStack::PopAndDestroy( 1, scanner );
   442 
   454 
   443 #ifdef __CACHELOG__
   455 #ifdef __CACHELOG__
   444     {
   456     {
   445     RDebug::Print(_L("-----------START PRINTING MAP OF SIZE %d---------"), onDiskFilesMap.Count());
   457     HttpCacheUtil::WriteFormatLog(0, _L("-----------START PRINTING MAP OF SIZE %d---------"), onDiskFilesMap.Count());
   446     TPtrHashMapIter<TDesC, TInt> iter(onDiskFilesMap);
   458     TPtrHashMapIter<TDesC, TInt> iter(onDiskFilesMap);
   447     const TDesC* key;
   459     const TDesC* key;
   448     while ((key = iter.NextKey()) != 0)
   460     while ((key = iter.NextKey()) != 0)
   449         {
   461         {
   450         const TInt val = *(iter.CurrentValue());
   462         const TInt val = *(iter.CurrentValue());
   451         RDebug::Print(_L("MAP WALK: %S, with value = %d "), key, val);
   463         HttpCacheUtil::WriteFormatLog(0, _L("MAP WALK: %S, with value = %d "), key, val);
   452         }
   464         }
   453     RDebug::Print(_L("-----------DONE PRINTING MAP-------------"));
   465     HttpCacheUtil::WriteFormatLog(0, _L("-----------DONE PRINTING MAP-------------"));
   454     }
   466     }
   455 #endif
   467 #endif
   456     
   468 
   457     //Step 2. Get list of known (non-orphaned) files in each Cache's in-memory lookup table. Flag them as DO NOT DELETE
   469     //Step 2. Get list of known (non-orphaned) files in each Cache's in-memory lookup table. Flag them as DO NOT DELETE
   458     RPointerArray<TDesC> knownFiles; 
   470     RPointerArray<TDesC> knownFiles;
   459     CleanupClosePushL( knownFiles );
   471     CleanupClosePushL( knownFiles );
   460     //Ask CacheHandlers to add their KNOWN files to this array. No ownership transfer occurs. 
   472     //Ask CacheHandlers to add their KNOWN files to this array. No ownership transfer occurs.
   461     //Don't go ahead if any of the cache handlers choke to insure correct deletion of files.
   473     //Don't go ahead if any of the cache handlers choke to insure correct deletion of files.
   462     if (iCache)
   474     if (iCache)
   463         User::LeaveIfError( iCache->ListFiles( knownFiles ) ); 
   475         User::LeaveIfError( iCache->ListFiles( knownFiles ) );
   464     if (iOperatorCache)
   476     if (iOperatorCache)
   465         User::LeaveIfError( iOperatorCache->ListFiles( knownFiles ) );
   477         User::LeaveIfError( iOperatorCache->ListFiles( knownFiles ) );
   466     if (iphoneSpecificCache)
   478     if (iphoneSpecificCache)
   467         User::LeaveIfError( iphoneSpecificCache->ListFiles( knownFiles ) ); 
   479         User::LeaveIfError( iphoneSpecificCache->ListFiles( knownFiles ) );
   468 
   480 
   469     //2a. HashTable lookup, and modification of flag
   481     //2a. HashTable lookup, and modification of flag
   470     for (TInt i = 0; i < knownFiles.Count(); i++)
   482     for (TInt i = 0; i < knownFiles.Count(); i++)
   471         {
   483         {
   472         //lookup filename
   484         //lookup filename
   473         TInt* ptr = onDiskFilesMap.Find( *(knownFiles[i]) );
   485         TInt* ptr = onDiskFilesMap.Find( *(knownFiles[i]) );
   474         if (ptr)
   486         if (ptr)
   475             {
   487             {
   476             // Reinsert into Map, this time with NO DELETE
   488             // Reinsert into Map, this time with NO DELETE
   477             onDiskFilesMap.Insert( knownFiles[i], &noDelete ); 
   489             onDiskFilesMap.Insert( knownFiles[i], &noDelete );
   478             
   490 #if 0 // no header files any more.
   479             // Add the header file to HashMap
   491             // Add the header file to HashMap
   480             HBufC* headerFile = HBufC::NewL( KHttpCacheHeaderExt().Length() +  (*(knownFiles[i])).Length() ); 
   492             HBufC* headerFile = HBufC::NewL( KHttpCacheHeaderExt().Length() +  (*(knownFiles[i])).Length() );
   481             cleanupList.Append( headerFile ); //keep for later destruction
   493             cleanupList.Append( headerFile ); //keep for later destruction
   482             TPtr ptr( headerFile->Des() ); 
   494             TPtr ptr( headerFile->Des() );
   483             HttpCacheUtil::GetHeaderFileName( *(knownFiles[i]), ptr );
   495             HttpCacheUtil::GetHeaderFileName( *(knownFiles[i]), ptr );
   484             onDiskFilesMap.Insert( headerFile, &noDelete ); // register Header files as NO DELETE
   496             onDiskFilesMap.Insert( headerFile, &noDelete ); // register Header files as NO DELETE
   485             }
   497 #endif
   486         }
   498             }
   487 
   499         }
   488     knownFiles.Close(); 
   500 
       
   501     knownFiles.Close();
   489     CleanupStack::Pop( 1, &knownFiles );
   502     CleanupStack::Pop( 1, &knownFiles );
   490 
   503 
   491     //Step 3. Delete all files on disk that don't belong to any of the Cache Handlers.
   504     //Step 3. Delete all files on disk that don't belong to any of the Cache Handlers.
   492     CFileMan* fileMan = CFileMan::NewL( rfs );
   505     CFileMan* fileMan = CFileMan::NewL( rfs );
   493     TPtrHashMapIter<TDesC, TInt> iter( onDiskFilesMap );
   506     TPtrHashMapIter<TDesC, TInt> iter( onDiskFilesMap );
   499             fileMan->Delete( *key );
   512             fileMan->Delete( *key );
   500         }
   513         }
   501         }
   514         }
   502     delete fileMan;
   515     delete fileMan;
   503 
   516 
   504     CleanupStack::Pop(1, &cleanupList); 
   517     CleanupStack::Pop(1, &cleanupList);
   505     cleanupList.ResetAndDestroy(); //should delete all HBufC objects
   518     cleanupList.ResetAndDestroy(); //should delete all HBufC objects
   506     
   519 
   507     CleanupStack::Pop(1, &onDiskFilesMap);
   520     CleanupStack::Pop(1, &onDiskFilesMap);
   508     onDiskFilesMap.Close(); // doesn't own any K,V object
   521     onDiskFilesMap.Close(); // doesn't own any K,V object
   509     
   522 
   510     }
   523     }
   511 
   524 
   512 // -----------------------------------------------------------------------------
   525 // -----------------------------------------------------------------------------
   513 // CHttpCacheManager::RemoveL
   526 // CHttpCacheManager::RemoveL
   514 //
   527 //
   665     // read cache settings
   678     // read cache settings
   666     CRepository* repository = CRepository::NewLC( KCRUidCacheManager );
   679     CRepository* repository = CRepository::NewLC( KCRUidCacheManager );
   667     CRepository* repositoryDiskLevel = CRepository::NewLC( KCRUidDiskLevel );
   680     CRepository* repositoryDiskLevel = CRepository::NewLC( KCRUidDiskLevel );
   668     TInt err;
   681     TInt err;
   669 
   682 
       
   683     // Get Cache Postpone Parameters.
       
   684     //
       
   685     THttpCachePostponeParameters postpone;
       
   686 
       
   687     if (KErrNone == repository->Get(KCacheWritePostponeEnabled, postpone.iEnabled) )
       
   688         {
       
   689         User::LeaveIfError( repository->Get( KCacheWritePostponeFreeRAMThreshold, postpone.iFreeRamThreshold ) );
       
   690         User::LeaveIfError( repository->Get( KCacheWritePostponeImmediateWriteThreshold, postpone.iImmediateWriteThreshold ) );
       
   691         User::LeaveIfError( repository->Get( KCacheWritePostponeWriteTimeout, postpone.iWriteTimeout ) );
       
   692         }
       
   693 
   670     // cache on/off
   694     // cache on/off
   671     TInt cacheEnabled( 0 );
   695     TInt cacheEnabled( 0 );
   672     err = repository->Get( KCacheManagerHttpCacheEnabled, cacheEnabled );
   696     err = repository->Get( KCacheManagerHttpCacheEnabled, cacheEnabled );
   673 
   697 
   674     iCacheEnabled = cacheEnabled;
   698     iCacheEnabled = cacheEnabled;
   682         // unless it is already there
   706         // unless it is already there
   683         if( iCacheFolder.LocateReverse( '\\' ) != iCacheFolder.Length() - 1  )
   707         if( iCacheFolder.LocateReverse( '\\' ) != iCacheFolder.Length() - 1  )
   684             {
   708             {
   685             iCacheFolder.Append( _L("\\") );
   709             iCacheFolder.Append( _L("\\") );
   686             }
   710             }
   687         
   711 
   688 	// get drive letter for sysutil
   712     // get drive letter for sysutil
   689 	TParsePtrC pathParser( iCacheFolder );
   713     TParsePtrC pathParser( iCacheFolder );
   690 	TDriveUnit drive = pathParser.Drive();
   714     TDriveUnit drive = pathParser.Drive();
   691 	// get critical level
   715     // get critical level
   692 	// RAM drive can have different critical level
   716     // RAM drive can have different critical level
   693 	TVolumeInfo vinfo;
   717     TVolumeInfo vinfo;
   694 	User::LeaveIfError( CCoeEnv::Static()->FsSession().Volume( vinfo, drive ) );
   718     User::LeaveIfError( CCoeEnv::Static()->FsSession().Volume( vinfo, drive ) );
   695 	//
   719     //
   696 	TInt criticalLevel;
   720     TInt criticalLevel;
   697 	User::LeaveIfError( repositoryDiskLevel->Get( ( vinfo.iDrive.iType == EMediaRam ? KRamDiskCriticalLevel : KDiskCriticalThreshold ),
   721     User::LeaveIfError( repositoryDiskLevel->Get( ( vinfo.iDrive.iType == EMediaRam ? KRamDiskCriticalLevel : KDiskCriticalThreshold ),
   698 		criticalLevel ) );
   722         criticalLevel ) );
   699 
   723 
   700     if( (err == KErrNone) && iCacheEnabled )
   724     if ( (err == KErrNone) && iCacheEnabled )
   701         {
   725         {
   702         // create cache handler
   726         // create cache handler
   703         iCache = CHttpCacheHandler::NewL( cacheSize, iCacheFolder, KDefaultIndexFile(), criticalLevel );
   727         iCache = CHttpCacheHandler::NewL( cacheSize, iCacheFolder, KDefaultIndexFile(), criticalLevel, postpone);
   704 
   728 
   705         // create operator cache. same settings
   729         // create operator cache. same settings
   706         if( FeatureManager::FeatureSupported( KFeatureIdOperatorCache ) )
   730         if ( FeatureManager::FeatureSupported( KFeatureIdOperatorCache ) )
   707             {
   731             {
   708             TBuf<512> url;
   732             TBuf<512> url;
   709             // if domain is missing, then no need to read further
   733             // if domain is missing, then no need to read further
   710             if( repository->Get( KOperatorDomainUrl, url ) == KErrNone )
   734             if ( repository->Get( KOperatorDomainUrl, url ) == KErrNone )
   711                 {
   735                 {
   712 
   736 
   713                 HBufC8* opDomain8 = HBufC8::NewL( url.Length() );
   737                 HBufC8* opDomain8 = HBufC8::NewL( url.Length() );
   714             CleanupStack::PushL(opDomain8);
   738                 CleanupStack::PushL(opDomain8);
   715             opDomain8->Des().Append( url );
   739                 opDomain8->Des().Append( url );
   716 
   740 
   717             TInt slashPos = opDomain8->LocateReverse('/');
   741                 TInt slashPos = opDomain8->LocateReverse('/');
   718             if(slashPos == -1)
   742                 if (slashPos == -1)
   719             {
   743                     {
   720                 slashPos = 0;
   744                     slashPos = 0;
   721             }
   745                     }
   722             TPtrC8 temp = opDomain8->Left(slashPos);
   746 
   723             iOpDomain = temp.AllocL();
   747                 TPtrC8 temp = opDomain8->Left(slashPos);
   724             CleanupStack::PopAndDestroy(opDomain8);
   748                 iOpDomain = temp.AllocL();
       
   749                 CleanupStack::PopAndDestroy(opDomain8);
   725 
   750 
   726                 // op cache size
   751                 // op cache size
   727                 TInt opCacheSize( KDefaultCacheSize );
   752                 TInt opCacheSize( KDefaultCacheSize );
   728                 repository->Get( KOperatorCacheSize, opCacheSize );
   753                 repository->Get( KOperatorCacheSize, opCacheSize );
   729 
   754 
   730                 // op cache folder
   755                 // op cache folder
   731                 TFileName opCacheFolder( KDefaultCacheDir );
   756                 TFileName opCacheFolder( KDefaultOperatorCacheDir );
   732                 repository->Get( KOperatorCacheFolder, opCacheFolder );
   757                 repository->Get( KOperatorCacheFolder, opCacheFolder );
   733 
   758 
   734                 if( opCacheFolder.LocateReverse( '\\' ) != opCacheFolder.Length() - 1  )
   759                 if ( opCacheFolder.LocateReverse( '\\' ) != opCacheFolder.Length() - 1  )
   735                     {
   760                     {
   736                     opCacheFolder.Append( _L("\\") );
   761                     opCacheFolder.Append( _L("\\") );
   737                     }
   762                     }
   738 
   763 
   739                 // create op cache
   764                 // create op cache
   740                 iOperatorCache = CHttpCacheHandler::NewL( opCacheSize, opCacheFolder, KDefaultOpIndexFile(), criticalLevel );
   765                 iOperatorCache = CHttpCacheHandler::NewL( opCacheSize, opCacheFolder, KDefaultOpIndexFile(), criticalLevel, postpone);
   741         }
   766                 }
   742             } //end if( FeatureManager::FeatureSupported( KFeatureIdOperatorCache ) )
   767             } //end if( FeatureManager::FeatureSupported( KFeatureIdOperatorCache ) )
   743         } //end if( iCacheEnabled )
   768         } //end if( iCacheEnabled )
   744 
   769 
   745     TInt VSScacheEnabled( 0 );
   770     TInt VSScacheEnabled( 0 );
   746     err = repository->Get( KPhoneSpecificCacheEnabled, VSScacheEnabled );
   771     err = repository->Get( KPhoneSpecificCacheEnabled, VSScacheEnabled );
   747 
   772 
   748     iVSSCacheEnabled = VSScacheEnabled;
   773     iVSSCacheEnabled = VSScacheEnabled;
   749  
   774 
   750     if( (err == KErrNone) && iVSSCacheEnabled )
   775     if ( (err == KErrNone) && iVSSCacheEnabled )
   751         {
   776         {
   752         // cache size
   777         // cache size
   753         TInt VSScacheSize( KDefaultCacheSize );
   778         TInt VSScacheSize( KDefaultCacheSize );
   754         repository->Get( KPhoneSpecificCacheSize, VSScacheSize );
   779         repository->Get( KPhoneSpecificCacheSize, VSScacheSize );
   755 
   780 
   756         // cache folder
   781         // cache folder
   757         TFileName VSScacheFolder( KDefaultCacheDir );
   782         TFileName VSScacheFolder( KDefaultVssCacheDir );
   758         // ignore cache folder. use c:\ to save memory. (same for operator cache. see below)
   783         // ignore cache folder. use c:\ to save memory. (same for operator cache. see below)
   759         repository->Get( KPhoneSpecificCacheFolder, VSScacheFolder );
   784         repository->Get( KPhoneSpecificCacheFolder, VSScacheFolder );
   760         // fix folder by appending trailing \\ to the end -symbian thing
   785         // fix folder by appending trailing \\ to the end -symbian thing
   761         // unless it is already there
   786         // unless it is already there
   762         if( VSScacheFolder.LocateReverse( '\\' ) != VSScacheFolder.Length() - 1  )
   787         if( VSScacheFolder.LocateReverse( '\\' ) != VSScacheFolder.Length() - 1  )
   765             }
   790             }
   766 
   791 
   767         //Get the white list
   792         //Get the white list
   768         TBuf<2048> whiteList;
   793         TBuf<2048> whiteList;
   769 
   794 
   770         if( repository->Get( KPhoneSpecificCacheDomainUrl, whiteList ) == KErrNone )
   795         if ( repository->Get( KPhoneSpecificCacheDomainUrl, whiteList ) == KErrNone )
   771             {
   796             {
   772             iVSSWhiteList = HBufC8::NewL( whiteList.Length() );
   797             iVSSWhiteList = HBufC8::NewL( whiteList.Length() );
   773             iVSSWhiteList->Des().Append( whiteList );
   798             iVSSWhiteList->Des().Append( whiteList );
   774             }
   799             }
   775         else
   800         else
   776             {
   801             {
   777             iVSSWhiteList = NULL;
   802             iVSSWhiteList = NULL;
   778             }
   803             }
   779 
   804 
   780         // create cache handler
   805         // create cache handler
   781         iphoneSpecificCache = CHttpCacheHandler::NewL( VSScacheSize, VSScacheFolder, KDefaultVSSIndexFile(), criticalLevel );
   806         iphoneSpecificCache = CHttpCacheHandler::NewL( VSScacheSize, VSScacheFolder, KDefaultVSSIndexFile(), criticalLevel, postpone);
   782         }
   807         }
       
   808 
   783     CleanupStack::PopAndDestroy(2); // repository, , repositoryDiskLevel
   809     CleanupStack::PopAndDestroy(2); // repository, , repositoryDiskLevel
   784     }
   810     }
   785 
   811 
   786 // -----------------------------------------------------------------------------
   812 // -----------------------------------------------------------------------------
   787 // CHttpCacheManager::CacheHandler
   813 // CHttpCacheManager::CacheHandler
   802         cache = ( ( iOpDomain && HttpCacheUtil::OperatorCacheContent( iOpDomain->Des(), aUrl ) ) ? iOperatorCache : iCache );
   828         cache = ( ( iOpDomain && HttpCacheUtil::OperatorCacheContent( iOpDomain->Des(), aUrl ) ) ? iOperatorCache : iCache );
   803         }
   829         }
   804     return cache;
   830     return cache;
   805     }
   831     }
   806 //  End of File
   832 //  End of File
   807