webengine/osswebengine/cache/src/HttpCacheManager.cpp
changeset 11 c8a366e56285
parent 10 a359256acfc6
child 25 0ed94ceaa377
equal deleted inserted replaced
10:a359256acfc6 11:c8a366e56285
    38 
    38 
    39 // CONSTANTS
    39 // CONSTANTS
    40 
    40 
    41 // kbyte
    41 // kbyte
    42 const TUint KDefaultCacheSize = 1048576; // 1MB = 1024*1024
    42 const TUint KDefaultCacheSize = 1048576; // 1MB = 1024*1024
    43 _LIT( KDefaultCacheDir, "c:\\cache\\");
    43 const TUint KDefaultOperatorCacheSize = 300*1024; // 300KB
    44 _LIT( KDefaultOperatorCacheDir, "c:\\cache\\op\\");
    44 _LIT( KDefaultCacheDrive, "c");
    45 _LIT( KDefaultVssCacheDir, "c:\\cache\\vss\\");
    45 _LIT( KDefaultCacheDir, "c:\\system\\cache\\");
       
    46 _LIT( KDefaultOperatorCacheDir, "c:\\system\\cache\\");
       
    47 _LIT( KDefaultVssCacheDir, "c:\\system\\cache\\vss\\");
    46 _LIT( KDefaultIndexFile, "index.dat" );
    48 _LIT( KDefaultIndexFile, "index.dat" );
    47 _LIT( KDefaultOpIndexFile, "index_op.dat" );
    49 _LIT( KDefaultOpIndexFile, "index_op.dat" );
    48 _LIT( KDefaultVSSIndexFile, "index_vss.dat" );
    50 _LIT( KDefaultVSSIndexFile, "index_vss.dat" );
    49 _LIT( KIndexFileExtension, ".dat" );
    51 _LIT( KIndexFileExtension, ".dat" );
       
    52 _LIT( KCrashCheck, "browser.val");
    50 _LIT( KValidationFileExtension, ".val" );
    53 _LIT( KValidationFileExtension, ".val" );
    51 _LIT8( KVSSHeaderFileldName, "X-Vodafone-Content" );
    54 _LIT8( KVSSHeaderFieldName, "X-Vodafone-Content" );
    52 _LIT8( KVSSHeaderFileldValue, "Portal" );
    55 _LIT8( KVSSHeaderFieldValue, "Portal" );
    53 
    56 // default override string, browser gets 2MB, widgetUI gets 1MB, OVI Store gets 1MB : max 4MB.
       
    57 _LIT( KDefaultOverrideString, "10008D39;1;2048;C;10282822;1;1024;C;102829A0;1;1024;C" );
    54 
    58 
    55 // MACROS
    59 // MACROS
       
    60 #define KUIDBROWSERNG 0x10008D39
       
    61 #define KUIDWIDGETUI 0x10282822
       
    62 #define KUIDBROWSERCACHECLEANER 0x20026777
       
    63 #define KUIDOPERATORMENU 0x100039CE
       
    64 #define KUIDOVISTORE 0x102829A0
    56 
    65 
    57 // LOCAL CONSTANTS AND MACROS
    66 // LOCAL CONSTANTS AND MACROS
    58 
    67 
    59 // MODULE DATA STRUCTURES
    68 // MODULE DATA STRUCTURES
    60 
    69 
    61 // LOCAL FUNCTION PROTOTYPES
    70 // LOCAL FUNCTION PROTOTYPES
    62 
    71 
    63 // FORWARD DECLARATIONS
    72 // FORWARD DECLARATIONS
       
    73 
       
    74 TBool IsBrowser()
       
    75     {
       
    76     RProcess process;
       
    77     TSecureId secId = process.SecureId();
       
    78     TUint32 secIdInt = secId;
       
    79     
       
    80     return ( secIdInt == KUIDBROWSERNG );
       
    81     }
    64 
    82 
    65 
    83 
    66 // ============================ MEMBER FUNCTIONS ===============================
    84 // ============================ MEMBER FUNCTIONS ===============================
    67 
    85 
    68 // -----------------------------------------------------------------------------
    86 // -----------------------------------------------------------------------------
    80 // Symbian 2nd phase constructor can leave.
    98 // Symbian 2nd phase constructor can leave.
    81 // -----------------------------------------------------------------------------
    99 // -----------------------------------------------------------------------------
    82 //
   100 //
    83 void CHttpCacheManager::ConstructL()
   101 void CHttpCacheManager::ConstructL()
    84     {
   102     {
       
   103 #ifdef __CACHELOG__
       
   104     HttpCacheUtil::WriteLog( 0, _L("-------------------------------------------"));
       
   105     HttpCacheUtil::WriteLog( 0, _L("| Creating new CHttpCacheManager Instance |"), (TInt)this);
       
   106     HttpCacheUtil::WriteLog( 0, _L("-------------------------------------------"));
       
   107 #endif
       
   108     
    85     CreateCacheHandlersL();
   109     CreateCacheHandlersL();
       
   110 #ifdef __CACHELOG__
       
   111     HttpCacheUtil::WriteLog( 0, _L("Created cache handlers"), (TInt)this);
       
   112 #endif
    86 
   113 
    87     // read offline mode
   114     // read offline mode
    88     if( FeatureManager::FeatureSupported( KFeatureIdOfflineMode ) )
   115     if( FeatureManager::FeatureSupported( KFeatureIdOfflineMode ) )
    89         {
   116         {
    90         // check if connection is not allowed and
   117         // check if connection is not allowed and
   122 // -----------------------------------------------------------------------------
   149 // -----------------------------------------------------------------------------
   123 // Destructor
   150 // Destructor
   124 // -----------------------------------------------------------------------------
   151 // -----------------------------------------------------------------------------
   125 CHttpCacheManager::~CHttpCacheManager()
   152 CHttpCacheManager::~CHttpCacheManager()
   126     {
   153     {
       
   154 #ifdef __CACHELOG__
       
   155     HttpCacheUtil::WriteLog( 0, _L("-----------------------------------------"));
       
   156     HttpCacheUtil::WriteLog( 0, _L("| Destroying CHttpCacheManager Instance | "), (TInt)this);
       
   157     HttpCacheUtil::WriteLog( 0, _L("-----------------------------------------"));
       
   158 #endif
       
   159     
       
   160     if( IsBrowser() )    // only enabled in browser
       
   161         {
       
   162         // delete crashcheck.dat file
       
   163         RFs rfs;
       
   164         rfs.Connect();
       
   165         rfs.SetSessionPath( iCacheFolder );
       
   166         rfs.Delete(KCrashCheck());
       
   167         rfs.Close();
       
   168         }
       
   169     
   127     delete iOfflineNotifyHandler;
   170     delete iOfflineNotifyHandler;
   128     delete iOfflineRepository;
   171     delete iOfflineRepository;
   129     delete iCache;
   172     delete iCache;
   130     delete iOperatorCache;
   173     delete iOperatorCache;
   131     delete iOpDomain;
   174     delete iOpDomain;
   163             HttpCacheUtil::WriteLog( 0, _L("========== VSS Header End =========\n") );
   206             HttpCacheUtil::WriteLog( 0, _L("========== VSS Header End =========\n") );
   164             delete responseHeaderStr;
   207             delete responseHeaderStr;
   165             }
   208             }
   166 #endif
   209 #endif
   167 
   210 
   168         TPtrC8 nameStr ( KVSSHeaderFileldName() );
   211         TPtrC8 nameStr ( KVSSHeaderFieldName() );
   169 
   212 
   170         RStringF VSSnameStr = strP.OpenFStringL( nameStr );
   213         RStringF VSSnameStr = strP.OpenFStringL( nameStr );
   171         CleanupClosePushL<RStringF>( VSSnameStr);
   214         CleanupClosePushL<RStringF>( VSSnameStr);
   172 
   215 
   173         THTTPHdrVal tempVal;
   216         THTTPHdrVal tempVal;
   174         if ( aHttpHeader.GetField( VSSnameStr, 0, tempVal ) == KErrNone )
   217         if ( aHttpHeader.GetField( VSSnameStr, 0, tempVal ) == KErrNone )
   175             {
   218             {
   176             TPtrC8 valueStr ( KVSSHeaderFileldValue() );
   219             TPtrC8 valueStr ( KVSSHeaderFieldValue() );
   177             RStringF VSSValueStr = strP.OpenFStringL( valueStr );
   220             RStringF VSSValueStr = strP.OpenFStringL( valueStr );
   178             CleanupClosePushL<RStringF>( VSSValueStr );
   221             CleanupClosePushL<RStringF>( VSSValueStr );
   179 
   222 
   180             if ( tempVal == VSSValueStr )
   223             if ( tempVal == VSSValueStr )
   181                 {
   224                 {
   201     //
   244     //
   202     TInt status( KErrNotFound );
   245     TInt status( KErrNotFound );
   203     if( iCacheEnabled || iVSSCacheEnabled )
   246     if( iCacheEnabled || iVSSCacheEnabled )
   204         {
   247         {
   205         CHttpCacheHandler* cache = CacheHandler( aTrans.Request().URI().UriDes(), NULL ) ;
   248         CHttpCacheHandler* cache = CacheHandler( aTrans.Request().URI().UriDes(), NULL ) ;
   206         __ASSERT_DEBUG( cache, User::Panic( _L("cacheHandler Panic"), KErrCorrupt ) );
       
   207         // adjust cache mode in case of offline operation
   249         // adjust cache mode in case of offline operation
   208         if( iOfflineMode )
   250         if( iOfflineMode )
   209             {
   251             {
   210             aCacheMode = TBrCtlDefs::ECacheModeOnlyCache;
   252             aCacheMode = TBrCtlDefs::ECacheModeOnlyCache;
   211             }
   253             }
   366 
   408 
   367     return numOfBytes;
   409     return numOfBytes;
   368     }
   410     }
   369 
   411 
   370 // -----------------------------------------------------------------------------
   412 // -----------------------------------------------------------------------------
   371 // FilePathHash
       
   372 // Hash function for Symbian file paths: discards case first
       
   373 // -----------------------------------------------------------------------------
       
   374 static TUint32 FilepathHash(const TDesC& aDes)
       
   375 {
       
   376     //since this function is intensively used by the HashMap,
       
   377     //keeping (slow) heap allocation out of it.
       
   378     TBuf<KMaxPath> normalized ( aDes );
       
   379 
       
   380     normalized.LowerCase();
       
   381     return DefaultHash::Des16( normalized );
       
   382 }
       
   383 
       
   384 // -----------------------------------------------------------------------------
       
   385 // FilepathIdent
       
   386 // Comparator for Symbian file paths: Use case-insensitive compare
       
   387 // -----------------------------------------------------------------------------
       
   388 static TBool FilepathIdent(const TDesC& aL, const TDesC& aR)
       
   389 {
       
   390     return ( aL.CompareF(aR) == 0 );
       
   391 }
       
   392 
       
   393 // -----------------------------------------------------------------------------
       
   394 // CHttpCacheManager::RemoveOrphanedFilesL
   413 // CHttpCacheManager::RemoveOrphanedFilesL
   395 // Removes header/body files that exist on the file-system, but are not known to the in-memory Cache lookup table(s)
   414 // Removes header/body files that exist on the file-system, but are not known to the in-memory Cache lookup table(s)
   396 // We do this because cache performance degrades substantially if there are too many files in a Symbian FAT32 directory.
   415 // We do this because cache performance degrades substantially if there are too many files in a Symbian FAT32 directory.
   397 // Browser crash or out-of-battery situations may cause SaveLookuptable() to be not called, leading to such "orphaned files".
   416 // Browser crash or out-of-battery situations may cause SaveLookuptable() to be not called, leading to such "orphaned files".
   398 // Due to high file-server interaction, don't call this method from performance critical code.
   417 // Due to high file-server interaction, don't call this method from performance critical code.
   399 // -----------------------------------------------------------------------------
   418 // -----------------------------------------------------------------------------
   400 void CHttpCacheManager::RemoveOrphanedFilesL()
   419 void CHttpCacheManager::RemoveOrphanedFilesL()
   401     {
   420     {
   402     //Map that contains pointers to fully-qualified file paths as Keys, and "to be deleted flag" as Value.
   421     // Only proceed if we are running the browser configuration, otherwise we will accidentally
   403     RPtrHashMap<TDesC, TInt> onDiskFilesMap(&FilepathHash, &FilepathIdent);
   422     // remove content we shouldn't.
   404     CleanupClosePushL( onDiskFilesMap );
   423     // get our SID.
   405 
   424     if( !IsBrowser() )
   406     //Pointers to the following TInt are used as VALUES in the HashMap...
   425         return;
   407     // so they must be in scope for the lifecycle of the HashMap.
   426     
   408     const TInt needsDelete( 1 );
   427     // Step 1. Get map of disk content
   409     const TInt noDelete( 0 );
   428     RFs rfs;
   410 
   429     User::LeaveIfError( rfs.Connect() );
   411     //collects objects that need to be deleted later on
   430     CleanupClosePushL( rfs );
   412     RPointerArray<HBufC> cleanupList;
   431     
   413     CleanupResetAndDestroyPushL( cleanupList );
   432     // Map that contains pointers to fully-qualified file paths as Keys, and "to be deleted flag" as Value.
   414 
   433     // Initially we mark everything as a candidate for deletion.
   415     RFs rfs = CCoeEnv::Static()->FsSession();
   434     CHttpCacheFileHash *onDiskFilesMap = NULL;
   416     CDirScan* scanner = CDirScan::NewLC( rfs );
   435     HttpCacheUtil::GenerateCacheContentHashMapL( onDiskFilesMap, rfs, iCacheFolder, KCacheFileNeedsDelete );
   417 
   436     CleanupStack::PushL( onDiskFilesMap );
   418     //Configure CDirScan to tell you all contents of a particular directory hierarchy
   437     
   419     scanner->SetScanDataL( iCacheFolder, KEntryAttNormal, ESortNone );
   438     // mark everything in the cache as no delete needed.
   420     CDir* matchingFiles( 0 );
   439     MarkAllCacheContentAsNoDelete( onDiskFilesMap );
   421 
   440 
   422     //Step 1. Find out all files on disk: by walking the directory hierarchy, one directory at a time
   441     // tell any other clients that we are about to remove their cached content
   423     for (;;)
   442     WipeAllOtherIndexFilesL( onDiskFilesMap, rfs );
   424         {
   443     
   425         //1a. Get list of files in current directory, NULL if no directory left in tree
   444     // delete any remaining marked files
   426         scanner->NextL( matchingFiles );
   445     DeleteMarkedFilesL( onDiskFilesMap, rfs );
   427         if ( !matchingFiles )
   446 
       
   447     CleanupStack::PopAndDestroy(1, onDiskFilesMap );
       
   448     CleanupStack::PopAndDestroy(1, &rfs );
       
   449     }
       
   450 
       
   451 void CHttpCacheManager::MarkAllCacheContentAsNoDelete( CHttpCacheFileHash* aOnDiskFilesMap )
       
   452     {
       
   453     //Step 2. Get list of known (non-orphaned) files in each Cache's in-memory lookup table. Flag them as DO NOT DELETE
       
   454     //Ask CacheHandlers to add their KNOWN files to this array. No ownership transfer occurs.
       
   455     //Don't go ahead if any of the cache handlers choke to insure correct deletion of files.
       
   456     if( iCache )
       
   457         iCache->ValidateCacheEntriesL(aOnDiskFilesMap);
       
   458     if( iOperatorCache )
       
   459         iOperatorCache->ValidateCacheEntriesL(aOnDiskFilesMap);
       
   460     if( iphoneSpecificCache )
       
   461         iphoneSpecificCache->ValidateCacheEntriesL(aOnDiskFilesMap);
       
   462     }
       
   463 
       
   464 void CHttpCacheManager::GenerateEmptyIndexFileL(const TDesC& aIndexFile, RFs& aRfs )
       
   465     {
       
   466     // Going to remove non-web client cache files in OrphanedFilesL call,
       
   467     // Signal to these clients by emptying (or creating) an 'empty' index file
       
   468     // do this before we start cleaning up files, to lessen the chances that any
       
   469     // of the files are in use when we're trying to delete them.
       
   470     
       
   471     // 'adopt' code from httpcachelookuptable for dealing with indexes.
       
   472     // save entries to index.dat
       
   473     RFileWriteStream writeStream;
       
   474 
       
   475     TInt ret = KErrNone;
       
   476     TInt tryCount = 0;
       
   477     for (tryCount = 0; tryCount < 5; tryCount++) 
       
   478         {
       
   479         ret = writeStream.Replace( aRfs, aIndexFile, EFileWrite );
       
   480         if (ret == KErrInUse)
       
   481             {
       
   482             // When the cache is full, it takes 65 - 85 miliseconds to write the index.
       
   483             // So wait 50 miliseconds and try again
       
   484             User::After(50000);
       
   485             }
       
   486         else
       
   487             {
   428             break;
   488             break;
   429 
   489             }
   430         TPtrC dir( scanner->FullPath() );
   490         }
   431 
   491     if( ret == KErrNone )
   432         //1b. Add any files found to the HashTable
   492         {
   433         const TInt nMatches = matchingFiles->Count();
   493         CleanupClosePushL( writeStream );
   434         for ( TInt i = 0; i < nMatches; i++ )
   494         writeStream.WriteInt32L( KCacheVersionNumber );
   435             {
   495         writeStream.WriteInt32L( 0 ); // no entries in the index.
   436             TEntry entry ( (*matchingFiles)[i] ) ;
   496         writeStream.CommitL();
   437             TPtrC ext( entry.iName.Right( KIndexFileExtension().Length() ));
   497         CleanupStack::PopAndDestroy(); // writeStream
   438 
   498         }
   439             if ( ext.CompareF( KIndexFileExtension ) != 0 && // ignore any .dat index files
   499     }
   440                  ext.CompareF( KValidationFileExtension ) != 0 ) // ignore any .val index files
   500 
   441                 {
   501 void CHttpCacheManager::WipeAllOtherIndexFilesL( CHttpCacheFileHash* aOnDiskFilesMap, RFs& aRfs )
   442                 HBufC* fullPath = HBufC::NewL( dir.Length() +  entry.iName.Length() );
   502     {
   443                 cleanupList.Append( fullPath ); //keep object safe for later destruction
   503     // look through hashmap for any .dat files which don't belong to the instantiated caches and overwrite them with blank ones.
   444                 fullPath->Des().Append( dir );
   504     THttpCacheFileHashIter iter( aOnDiskFilesMap->HashMap() );
   445                 fullPath->Des().Append( entry.iName ); //a fully qualified file path
       
   446                 onDiskFilesMap.Insert( fullPath, &needsDelete ); //add to the hash
       
   447                 }
       
   448             }
       
   449 
       
   450         delete matchingFiles;
       
   451         } // End of step 1: adding all known files on disk to Map
       
   452 
       
   453     CleanupStack::PopAndDestroy( 1, scanner );
       
   454 
       
   455 #ifdef __CACHELOG__
       
   456     {
       
   457     HttpCacheUtil::WriteFormatLog(0, _L("-----------START PRINTING MAP OF SIZE %d---------"), onDiskFilesMap.Count());
       
   458     TPtrHashMapIter<TDesC, TInt> iter(onDiskFilesMap);
       
   459     const TDesC* key;
   505     const TDesC* key;
   460     while ((key = iter.NextKey()) != 0)
   506     while ((key = iter.NextKey()) != 0)
   461         {
   507         {
   462         const TInt val = *(iter.CurrentValue());
   508         const TFileInfo* value ( (iter.CurrentValue()) );
   463         HttpCacheUtil::WriteFormatLog(0, _L("MAP WALK: %S, with value = %d "), key, val);
   509         if( value->iUserInt == KCacheFileNeedsDelete )
   464         }
   510             {
   465     HttpCacheUtil::WriteFormatLog(0, _L("-----------DONE PRINTING MAP-------------"));
   511             TPtrC ext( key->Right(KIndexFileExtension().Length()) );
   466     }
   512             if (    ext.CompareF( KIndexFileExtension ) == 0 ) // find any .dat index files
   467 #endif
   513                 { 
   468 
   514                 GenerateEmptyIndexFileL( *key , aRfs );
   469     //Step 2. Get list of known (non-orphaned) files in each Cache's in-memory lookup table. Flag them as DO NOT DELETE
   515                 }
   470     RPointerArray<TDesC> knownFiles;
   516             }
   471     CleanupClosePushL( knownFiles );
   517         }
   472     //Ask CacheHandlers to add their KNOWN files to this array. No ownership transfer occurs.
   518     }
   473     //Don't go ahead if any of the cache handlers choke to insure correct deletion of files.
   519 
   474     if (iCache)
   520 void CHttpCacheManager::DeleteMarkedFilesL( CHttpCacheFileHash* aOnDiskFilesMap, RFs& aRfs )
   475         User::LeaveIfError( iCache->ListFiles( knownFiles ) );
   521     {
   476     if (iOperatorCache)
       
   477         User::LeaveIfError( iOperatorCache->ListFiles( knownFiles ) );
       
   478     if (iphoneSpecificCache)
       
   479         User::LeaveIfError( iphoneSpecificCache->ListFiles( knownFiles ) );
       
   480 
       
   481     //2a. HashTable lookup, and modification of flag
       
   482     for (TInt i = 0; i < knownFiles.Count(); i++)
       
   483         {
       
   484         //lookup filename
       
   485         TInt* ptr = onDiskFilesMap.Find( *(knownFiles[i]) );
       
   486         if (ptr)
       
   487             {
       
   488             // Reinsert into Map, this time with NO DELETE
       
   489             onDiskFilesMap.Insert( knownFiles[i], &noDelete );
       
   490 #if 0 // no header files any more.
       
   491             // Add the header file to HashMap
       
   492             HBufC* headerFile = HBufC::NewL( KHttpCacheHeaderExt().Length() +  (*(knownFiles[i])).Length() );
       
   493             cleanupList.Append( headerFile ); //keep for later destruction
       
   494             TPtr ptr( headerFile->Des() );
       
   495             HttpCacheUtil::GetHeaderFileName( *(knownFiles[i]), ptr );
       
   496             onDiskFilesMap.Insert( headerFile, &noDelete ); // register Header files as NO DELETE
       
   497 #endif
       
   498             }
       
   499         }
       
   500 
       
   501     knownFiles.Close();
       
   502     CleanupStack::Pop( 1, &knownFiles );
       
   503 
       
   504     //Step 3. Delete all files on disk that don't belong to any of the Cache Handlers.
   522     //Step 3. Delete all files on disk that don't belong to any of the Cache Handlers.
   505     CFileMan* fileMan = CFileMan::NewL( rfs );
   523     CFileMan* fileMan = CFileMan::NewL( aRfs );
   506     TPtrHashMapIter<TDesC, TInt> iter( onDiskFilesMap );
   524     THttpCacheFileHashIter iter( aOnDiskFilesMap->HashMap() );
   507     const TDesC* key;
   525     const TDesC* key;
   508     while ((key = iter.NextKey()) != 0)
   526     while ((key = iter.NextKey()) != 0)
   509         {
   527         {
   510         const TInt value ( *(iter.CurrentValue()) );
   528         const TFileInfo* value ( (iter.CurrentValue()) );
   511         if ( value == 1 ) { // file needs deletion
   529         if( value->iUserInt == KCacheFileNeedsDelete )
   512             fileMan->Delete( *key );
   530             {
   513         }
   531             TPtrC ext( key->Right(KIndexFileExtension().Length()) );
       
   532             if (    ext.CompareF( KIndexFileExtension ) != 0 && // ignore any .dat index files
       
   533                     ext.CompareF( KValidationFileExtension ) != 0 ) // ignore any .val files
       
   534                 { 
       
   535                 fileMan->Delete( *key );
       
   536                 }
       
   537             }
   514         }
   538         }
   515     delete fileMan;
   539     delete fileMan;
   516 
       
   517     CleanupStack::Pop(1, &cleanupList);
       
   518     cleanupList.ResetAndDestroy(); //should delete all HBufC objects
       
   519 
       
   520     CleanupStack::Pop(1, &onDiskFilesMap);
       
   521     onDiskFilesMap.Close(); // doesn't own any K,V object
       
   522 
       
   523     }
   540     }
   524 
   541 
   525 // -----------------------------------------------------------------------------
   542 // -----------------------------------------------------------------------------
   526 // CHttpCacheManager::RemoveL
   543 // CHttpCacheManager::RemoveL
   527 //
   544 //
   550     TBool found( EFalse );
   567     TBool found( EFalse );
   551     //
   568     //
   552     if( iCacheEnabled || iVSSCacheEnabled )
   569     if( iCacheEnabled || iVSSCacheEnabled )
   553         {
   570         {
   554         CHttpCacheHandler* cache = CacheHandler( aUrl, NULL );
   571         CHttpCacheHandler* cache = CacheHandler( aUrl, NULL );
   555 
       
   556         __ASSERT_DEBUG( cache, User::Panic( _L("cacheHandler Panic"), KErrCorrupt ) );
       
   557         //
   572         //
   558         if( cache )
   573         if( cache )
   559             {
   574             {
   560             found = cache->Find( aUrl );
   575             found = cache->Find( aUrl );
   561             }
   576             }
   576 TBool CHttpCacheManager::VSSHeaderCheck( TDes8*  aHttpHeaderString ) const
   591 TBool CHttpCacheManager::VSSHeaderCheck( TDes8*  aHttpHeaderString ) const
   577     {
   592     {
   578     TBool found ( EFalse );
   593     TBool found ( EFalse );
   579     if( aHttpHeaderString->Size() > 0 )
   594     if( aHttpHeaderString->Size() > 0 )
   580         {
   595         {
   581         TPtrC8 nameStr8( KVSSHeaderFileldName() );
   596         TPtrC8 nameStr8( KVSSHeaderFieldName() );
   582 
   597 
   583         TInt VSSnameLocation = aHttpHeaderString->FindC( nameStr8 ) ;
   598         TInt VSSnameLocation = aHttpHeaderString->FindC( nameStr8 ) ;
   584 
   599 
   585         if ( VSSnameLocation != KErrNotFound )
   600         if ( VSSnameLocation != KErrNotFound )
   586             {
   601             {
   587             TPtrC8 valueStr8( KVSSHeaderFileldValue() );
   602             TPtrC8 valueStr8( KVSSHeaderFieldValue() );
   588             TInt VSSvalueLocation = aHttpHeaderString->FindC( KVSSHeaderFileldValue() );
   603             TInt VSSvalueLocation = aHttpHeaderString->FindC( KVSSHeaderFieldValue() );
   589 
   604 
   590             if ( (VSSvalueLocation != KErrNotFound ) && ( VSSnameLocation < VSSvalueLocation ) )
   605             if ( (VSSvalueLocation != KErrNotFound ) && ( VSSnameLocation < VSSvalueLocation ) )
   591                 {
   606                 {
   592                 found = ETrue;
   607                 found = ETrue;
   593                 }
   608                 }
   615         HBufC8* headerStr = HBufC8::NewL( aHttpHeaderString.Length() );
   630         HBufC8* headerStr = HBufC8::NewL( aHttpHeaderString.Length() );
   616         headerStr->Des().Copy( aHttpHeaderString );
   631         headerStr->Des().Copy( aHttpHeaderString );
   617         TPtr8 headerStrPtr8 ( headerStr->Des() ); //Any Type of TPtrc8
   632         TPtr8 headerStrPtr8 ( headerStr->Des() ); //Any Type of TPtrc8
   618         CHttpCacheHandler* cache = CacheHandler( aUrl, &headerStrPtr8 );
   633         CHttpCacheHandler* cache = CacheHandler( aUrl, &headerStrPtr8 );
   619         delete headerStr;
   634         delete headerStr;
   620         __ASSERT_DEBUG( cache, User::Panic( _L("cacheHandler Panic"), KErrCorrupt ) );
       
   621         //
   635         //
   622         if( cache )
   636         if( cache )
   623             {
   637             {
   624             saved = cache->SaveL( aUrl, aHeader, aContent );
   638             saved = cache->SaveL( aUrl, aHeader, aContent );
   625             }
   639             }
   640     TBool status( KErrNotFound );
   654     TBool status( KErrNotFound );
   641     //
   655     //
   642     if( iCacheEnabled || iVSSCacheEnabled )
   656     if( iCacheEnabled || iVSSCacheEnabled )
   643         {
   657         {
   644         CHttpCacheHandler* cache = CacheHandler( aUrl, NULL );
   658         CHttpCacheHandler* cache = CacheHandler( aUrl, NULL );
   645         __ASSERT_DEBUG( cache, User::Panic( _L("cacheHandler Panic"), KErrCorrupt ) );
       
   646         //
   659         //
   647         if( cache )
   660         if( cache )
   648             {
   661             {
   649             status = cache->AddHeaderL( aUrl, aName, aValue );
   662             status = cache->AddHeaderL( aUrl, aName, aValue );
   650             }
   663             }
   673 //
   686 //
   674 // -----------------------------------------------------------------------------
   687 // -----------------------------------------------------------------------------
   675 //
   688 //
   676 void CHttpCacheManager::CreateCacheHandlersL()
   689 void CHttpCacheManager::CreateCacheHandlersL()
   677     {
   690     {
   678     // read cache settings
   691     // get our SID.
   679     CRepository* repository = CRepository::NewLC( KCRUidCacheManager );
   692     RProcess process;
   680     CRepository* repositoryDiskLevel = CRepository::NewLC( KCRUidDiskLevel );
   693     TSecureId secId = process.SecureId();
   681     TInt err;
   694     TUint32 secIdInt = secId;
       
   695 
       
   696     CRepository* repository = CRepository::NewLC(KCRUidCacheManager);
       
   697     CRepository* repositoryDiskLevel = CRepository::NewLC(KCRUidDiskLevel);
   682 
   698 
   683     // Get Cache Postpone Parameters.
   699     // Get Cache Postpone Parameters.
   684     //
       
   685     THttpCachePostponeParameters postpone;
   700     THttpCachePostponeParameters postpone;
   686 
   701     TBool newCentrepPresent;
   687     if (KErrNone == repository->Get(KCacheWritePostponeEnabled, postpone.iEnabled) )
   702     GetPostponeParamsL( newCentrepPresent, postpone, repository );
   688         {
   703 
   689         User::LeaveIfError( repository->Get( KCacheWritePostponeFreeRAMThreshold, postpone.iFreeRamThreshold ) );
   704     // apply default cache configuration - no cache for anyone, sizes set to default.
   690         User::LeaveIfError( repository->Get( KCacheWritePostponeImmediateWriteThreshold, postpone.iImmediateWriteThreshold ) );
   705     iCacheEnabled = EFalse;
   691         User::LeaveIfError( repository->Get( KCacheWritePostponeWriteTimeout, postpone.iWriteTimeout ) );
   706     TInt cacheSize( KDefaultCacheSize );
   692         }
   707     iCacheFolder.Copy( KDefaultCacheDir );
   693 
   708    
   694     // cache on/off
   709     TBool opCacheEnabled( EFalse );
   695     TInt cacheEnabled( 0 );
   710     iOperatorCache = 0;
   696     err = repository->Get( KCacheManagerHttpCacheEnabled, cacheEnabled );
   711     TInt opCacheSize = KDefaultOperatorCacheSize;
   697 
   712     TFileName opCacheFolder( KDefaultOperatorCacheDir );
   698     iCacheEnabled = cacheEnabled;
   713     
   699 
   714     iVSSCacheEnabled = EFalse;
       
   715     TInt vssCacheSize = KDefaultOperatorCacheSize;
       
   716     TFileName vssCacheFolder( KDefaultVssCacheDir );
       
   717 
       
   718     if(newCentrepPresent)
       
   719         {
       
   720         // if the new Centrep file is present, we trust it's configured properly.
       
   721         GetHttpCacheConfigL( *repository, iCacheEnabled, cacheSize, iCacheFolder );
       
   722         GetOperatorCacheConfigL( *repository, opCacheEnabled, opCacheSize, opCacheFolder );
       
   723         GetVSSCacheConfigL( *repository, iVSSCacheEnabled, vssCacheSize, vssCacheFolder );
       
   724         }
       
   725     
       
   726     // look for per-process overrides in central repository.  Do this before we get drive critical levels so we're on the right
       
   727     // drive.
       
   728     // This has a default string which applies the new per-client default configuration
       
   729     ApplyCacheOverridesL(*repository, secIdInt, iCacheEnabled, cacheSize, opCacheEnabled, iVSSCacheEnabled, iCacheFolder, KDefaultCacheDrive());
       
   730 
       
   731     TInt criticalLevel = 0;
       
   732     GetCriticalDriveLevelsL( *repositoryDiskLevel, iCacheFolder, criticalLevel );
       
   733     
       
   734     // Create any caches we should be using.
       
   735     if (iCacheEnabled)
       
   736         {
       
   737         CreateHttpCacheL( secIdInt, cacheSize, criticalLevel, postpone );
       
   738 
       
   739         if (opCacheEnabled)
       
   740             {
       
   741             CreateOperatorCacheL( *repository, opCacheFolder, opCacheSize, criticalLevel, postpone );
       
   742             }
       
   743         } //end if( iCacheEnabled )
       
   744 
       
   745     if ( iVSSCacheEnabled )
       
   746         {
       
   747         CreateVssCacheL( *repository, vssCacheFolder, vssCacheSize, criticalLevel, postpone );
       
   748         }
       
   749 
       
   750     CleanupStack::PopAndDestroy(2); // repository, repositoryDiskLevel
       
   751     CrashCheckL( secIdInt );
       
   752     }
       
   753 
       
   754 void CHttpCacheManager::ApplyCacheOverridesL(CRepository& aRepository, const TUint32& aSecIdInt, TBool& aCacheEnabled, TInt& aCacheSize, TBool& aOpCacheEnabled, TBool& aVssCacheEnabled, TDes& aPath, const TDesC& aDefaultDrive)
       
   755     {
       
   756     TDriveUnit drive(aDefaultDrive);
       
   757     
       
   758     // set defaults
       
   759     if(aSecIdInt == KUIDBROWSERNG)       // for the browser, force use of Operator and VSS caches
       
   760         {
       
   761         aOpCacheEnabled = ETrue;
       
   762         aVssCacheEnabled = ETrue;
       
   763         }
       
   764     
       
   765     // read override string from centrep
       
   766     HBufC16 *overrideBuf = HBufC16::NewLC(64);
       
   767     TPtr overrideStr(overrideBuf->Des());
       
   768     TInt strLen;
       
   769     TInt err = aRepository.Get(KCacheManagerHttpCacheProcessOverride, overrideStr, strLen);
       
   770     if(strLen > overrideBuf->Length())
       
   771         {
       
   772         overrideBuf = overrideBuf->ReAllocL(strLen);
       
   773         // make sure cleanup stack contains correct pointer since ReAllocL always allocates a new des for larger space.
       
   774         CleanupStack::Pop();
       
   775         CleanupStack::PushL(overrideBuf);
       
   776         // reassign the TPtr
       
   777         overrideStr.Set(overrideBuf->Des());
       
   778         // pull in the whole string
       
   779         aRepository.Get(KCacheManagerHttpCacheProcessOverride, overrideStr, strLen);
       
   780         }
       
   781     // if we failed to load an override string, use the default.
       
   782     if( overrideStr.Length() == 0 )
       
   783         {
       
   784         CleanupStack::PopAndDestroy( overrideBuf );
       
   785         overrideBuf = KDefaultOverrideString().AllocLC();
       
   786         overrideStr.Set( overrideBuf->Des() );
       
   787         }
       
   788     // Built in Lex likes white space to separate strings, but easier to enter with ; separators.  Replace all ; with spaces.
       
   789     TInt pos=0;
       
   790     do{
       
   791         if(overrideStr[pos] == ';')
       
   792             {
       
   793             overrideStr[pos] = ' ';
       
   794             }
       
   795         pos++;
       
   796     }while(pos < overrideStr.Length());
       
   797     
       
   798     TLex overrideLex(overrideStr);
       
   799     do{
       
   800         TUint32 tempId;
       
   801         User::LeaveIfError(overrideLex.BoundedVal(tempId,EHex,KMaxTUint32));
       
   802         if(overrideLex.TokenLength() != 8)  // if we're not pointing at an SID in the string, we are incorrect and the override is broken.
       
   803             User::Leave(KErrCorrupt);
       
   804         overrideLex.SkipSpace();
       
   805         TInt32 tempCacheEnabled;
       
   806         User::LeaveIfError(overrideLex.BoundedVal(tempCacheEnabled,KMaxTInt32));
       
   807         overrideLex.SkipSpace();
       
   808         TInt32 tempCacheSize;
       
   809         User::LeaveIfError(overrideLex.BoundedVal(tempCacheSize,KMaxTInt32));
       
   810         overrideLex.SkipSpace();
       
   811         TDriveUnit tempDrive(overrideLex.NextToken());
       
   812         overrideLex.SkipSpaceAndMark();
       
   813         // found a hex SID matching ours, use the parameters.
       
   814         if(tempId == aSecIdInt)
       
   815             {
       
   816             aCacheEnabled = tempCacheEnabled;
       
   817             aCacheSize = tempCacheSize * 1024; // conf is in KB
       
   818             drive = tempDrive;
       
   819             break;
       
   820             }
       
   821     }while(!overrideLex.Eos());
       
   822 
       
   823     // Modify drive letter on aPath to match
       
   824     TParsePtr parsePath(aPath);
       
   825     TPtrC pathStr(parsePath.Path());
       
   826     TPath tempPath;
       
   827     tempPath.Format(_L("%c:%S"), TInt(drive)+'A', &pathStr);
       
   828     aPath.Copy(tempPath);
       
   829     HttpCacheUtil::EnsureTrailingSlash( aPath );
       
   830     
       
   831     CleanupStack::PopAndDestroy(overrideBuf);
       
   832     }
       
   833 
       
   834 // -----------------------------------------------------------------------------
       
   835 // CHttpCacheManager::CacheHandler
       
   836 //
       
   837 // -----------------------------------------------------------------------------
       
   838 //
       
   839 CHttpCacheHandler* CHttpCacheManager::CacheHandler(
       
   840     const TDesC8& aUrl,
       
   841     TDes8* aHttpHeaderString ) const
       
   842     {
       
   843     CHttpCacheHandler* cache;
       
   844     if( iVSSCacheEnabled && aHttpHeaderString && VSSHeaderCheck( aHttpHeaderString ) )
       
   845         {
       
   846         cache = iphoneSpecificCache;
       
   847         }
       
   848     else
       
   849         {
       
   850         cache = ( ( iOpDomain && HttpCacheUtil::OperatorCacheContent( iOpDomain->Des(), aUrl ) ) ? iOperatorCache : iCache );
       
   851         }
       
   852     return cache;
       
   853     }
       
   854 
       
   855 void CHttpCacheManager::GetPostponeParamsL( TBool& aNewCentrepPresent, THttpCachePostponeParameters& aParams, CRepository* aRepo )
       
   856     {
       
   857     aNewCentrepPresent = EFalse;
       
   858     if (KErrNone == aRepo->Get(KCacheWritePostponeEnabled,
       
   859             aParams.iEnabled))
       
   860         {
       
   861         User::LeaveIfError(aRepo->Get(
       
   862                 KCacheWritePostponeFreeRAMThreshold,
       
   863                 aParams.iFreeRamThreshold));
       
   864         User::LeaveIfError(aRepo->Get(
       
   865                 KCacheWritePostponeImmediateWriteThreshold,
       
   866                 aParams.iImmediateWriteThreshold));
       
   867         User::LeaveIfError(aRepo->Get(KCacheWritePostponeWriteTimeout,
       
   868                 aParams.iWriteTimeout));
       
   869         
       
   870         aNewCentrepPresent = ETrue;
       
   871         }
       
   872     }
       
   873 
       
   874 void CHttpCacheManager::GetHttpCacheConfigL( CRepository& aRepository, TBool& aCacheEnabled, TInt& aCacheSize, TDes& aCacheFolder )
       
   875     {
       
   876     // General HTTP Cache
       
   877     TBool cacheEnabled( EFalse );
       
   878     aCacheFolder.Copy( KDefaultCacheDir );
       
   879     
       
   880     TInt err = aRepository.Get(KCacheManagerHttpCacheEnabled, cacheEnabled);
       
   881     aCacheEnabled = cacheEnabled;
       
   882     if( err == KErrNone )
       
   883         {
   700         // cache size
   884         // cache size
   701         TInt cacheSize( KDefaultCacheSize );
   885         TInt tempCacheSize;
   702         repository->Get( KCacheManagerHttpCacheSize, cacheSize );
   886         if( aRepository.Get(KCacheManagerHttpCacheSize, tempCacheSize) == KErrNone )
   703 
   887             aCacheSize = tempCacheSize;
   704          repository->Get( KCacheManagerHttpCacheFolder, iCacheFolder );
   888 
   705         // fix folder by appending trailing \\ to the end -symbian thing
   889         // cache location
   706         // unless it is already there
   890         TFileName tempCacheLocation;
   707         if( iCacheFolder.LocateReverse( '\\' ) != iCacheFolder.Length() - 1  )
   891         if( aRepository.Get(KCacheManagerHttpCacheFolder, tempCacheLocation) == KErrNone )
   708             {
   892             aCacheFolder.Copy( tempCacheLocation );
   709             iCacheFolder.Append( _L("\\") );
   893         }
   710             }
   894     HttpCacheUtil::EnsureTrailingSlash( aCacheFolder );
   711 
   895     }
       
   896 
       
   897 void CHttpCacheManager::GetOperatorCacheConfigL( CRepository& aRepository, TBool& aOpCacheEnabled, TInt& aOpCacheSize, TDes& aOpCacheFolder )
       
   898     {
       
   899     // Operator Cache
       
   900     aOpCacheEnabled = FeatureManager::FeatureSupported(KFeatureIdOperatorCache);
       
   901     if( aOpCacheEnabled )
       
   902         {
       
   903         TInt tempOpCacheSize;
       
   904         if( aRepository.Get(KOperatorCacheSize, tempOpCacheSize) == KErrNone )
       
   905             aOpCacheSize = tempOpCacheSize;
       
   906 
       
   907         // op cache folder
       
   908         TFileName tempOpCacheFolder;
       
   909         if( aRepository.Get(KOperatorCacheFolder, tempOpCacheFolder) == KErrNone )
       
   910             aOpCacheFolder.Copy( tempOpCacheFolder );
       
   911         }
       
   912     HttpCacheUtil::EnsureTrailingSlash( aOpCacheFolder );
       
   913     }
       
   914 
       
   915 void CHttpCacheManager::GetVSSCacheConfigL( CRepository& aRepository, TBool& aVSSCacheEnabled, TInt& aVssCacheSize, TDes& aVssCacheFolder )
       
   916     {
       
   917     // VSS Cache
       
   918     TInt VSScacheEnabled(0);
       
   919     TInt err = aRepository.Get(KPhoneSpecificCacheEnabled, VSScacheEnabled);
       
   920     aVSSCacheEnabled = VSScacheEnabled;
       
   921 
       
   922     if ( err == KErrNone && aVSSCacheEnabled )
       
   923         {
       
   924         TInt tempVSSCacheSize;
       
   925         if( aRepository.Get(KPhoneSpecificCacheSize, tempVSSCacheSize) == KErrNone )
       
   926             aVssCacheSize = tempVSSCacheSize;
       
   927 
       
   928         TFileName tempVSScacheFolder;
       
   929         if( aRepository.Get(KPhoneSpecificCacheFolder, tempVSScacheFolder) == KErrNone )
       
   930             aVssCacheFolder.Copy( tempVSScacheFolder );
       
   931         }
       
   932     HttpCacheUtil::EnsureTrailingSlash( aVssCacheFolder );
       
   933     }
       
   934 
       
   935 void CHttpCacheManager::GetCriticalDriveLevelsL( CRepository& aRepository, const TDesC& aCacheFolder, TInt& aCriticalLevel )
       
   936     {
   712     // get drive letter for sysutil
   937     // get drive letter for sysutil
   713     TParsePtrC pathParser( iCacheFolder );
   938     TParsePtrC pathParser( aCacheFolder );
   714     TDriveUnit drive = pathParser.Drive();
   939     TDriveUnit drive = pathParser.Drive();
       
   940 
   715     // get critical level
   941     // get critical level
   716     // RAM drive can have different critical level
   942     // RAM drive can have different critical level
   717     TVolumeInfo vinfo;
   943     TVolumeInfo vinfo;
   718     User::LeaveIfError( CCoeEnv::Static()->FsSession().Volume( vinfo, drive ) );
   944     User::LeaveIfError(CCoeEnv::Static()->FsSession().Volume(vinfo, drive));
   719     //
   945     //
   720     TInt criticalLevel;
   946     User::LeaveIfError(aRepository.Get((vinfo.iDrive.iType == EMediaRam ? KRamDiskCriticalLevel : KDiskCriticalThreshold), aCriticalLevel));
   721     User::LeaveIfError( repositoryDiskLevel->Get( ( vinfo.iDrive.iType == EMediaRam ? KRamDiskCriticalLevel : KDiskCriticalThreshold ),
   947     }
   722         criticalLevel ) );
   948 
   723 
   949 void CHttpCacheManager::CreateHttpCacheL( const TInt& aSecIdInt, const TInt& aCacheSize, const TInt& aCriticalLevel, const THttpCachePostponeParameters& aPostpone )
   724     if ( (err == KErrNone) && iCacheEnabled )
   950     {
   725         {
   951     // browser gets the normal index.dat name, other clients get <SID>.dat
   726         // create cache handler
   952     TFileName indexFile( KDefaultIndexFile() );
   727         iCache = CHttpCacheHandler::NewL( cacheSize, iCacheFolder, KDefaultIndexFile(), criticalLevel, postpone);
   953     if( aSecIdInt != KUIDBROWSERNG )
   728 
   954         {
   729         // create operator cache. same settings
   955         indexFile.Format(_L("%08x.dat"), aSecIdInt);
   730         if ( FeatureManager::FeatureSupported( KFeatureIdOperatorCache ) )
   956         }
   731             {
   957     // create cache handler
   732             TBuf<512> url;
   958     iCache = CHttpCacheHandler::NewL( aCacheSize, iCacheFolder, indexFile, aCriticalLevel, aPostpone);
   733             // if domain is missing, then no need to read further
   959     }
   734             if ( repository->Get( KOperatorDomainUrl, url ) == KErrNone )
   960 
   735                 {
   961 void CHttpCacheManager::CreateOperatorCacheL( CRepository& aRepository, const TDesC& aOpCacheFolder, const TInt& aOpCacheSize, const TInt& aCriticalLevel, const THttpCachePostponeParameters& aPostpone )
   736 
   962     {
   737                 HBufC8* opDomain8 = HBufC8::NewL( url.Length() );
   963     TBuf<512> url;
   738                 CleanupStack::PushL(opDomain8);
   964     // if domain is missing, then no need to read further
   739                 opDomain8->Des().Append( url );
   965     if (aRepository.Get(KOperatorDomainUrl, url) == KErrNone)
   740 
   966         {
   741                 TInt slashPos = opDomain8->LocateReverse('/');
   967         HBufC8* opDomain8 = HBufC8::NewL(url.Length());
   742                 if (slashPos == -1)
   968         CleanupStack::PushL(opDomain8);
   743                     {
   969         opDomain8->Des().Append(url);
   744                     slashPos = 0;
   970     
   745                     }
   971         TInt slashPos = opDomain8->LocateReverse('/');
   746 
   972         if (slashPos == -1)
   747                 TPtrC8 temp = opDomain8->Left(slashPos);
   973             {
   748                 iOpDomain = temp.AllocL();
   974             slashPos = 0;
   749                 CleanupStack::PopAndDestroy(opDomain8);
   975             }
   750 
   976     
   751                 // op cache size
   977         TPtrC8 temp = opDomain8->Left(slashPos);
   752                 TInt opCacheSize( KDefaultCacheSize );
   978         iOpDomain = temp.AllocL();
   753                 repository->Get( KOperatorCacheSize, opCacheSize );
   979         CleanupStack::PopAndDestroy(opDomain8);
   754 
   980     
   755                 // op cache folder
   981         // create op cache
   756                 TFileName opCacheFolder( KDefaultOperatorCacheDir );
   982         iOperatorCache = CHttpCacheHandler::NewL( aOpCacheSize, aOpCacheFolder, KDefaultOpIndexFile(), aCriticalLevel, aPostpone);
   757                 repository->Get( KOperatorCacheFolder, opCacheFolder );
   983         }
   758 
   984     }
   759                 if ( opCacheFolder.LocateReverse( '\\' ) != opCacheFolder.Length() - 1  )
   985 
   760                     {
   986 void CHttpCacheManager::CreateVssCacheL( CRepository& aRepository, const TDesC& aVssCacheFolder, const TInt& aVssCacheSize, const TInt& aCriticalLevel, const THttpCachePostponeParameters& aPostpone )
   761                     opCacheFolder.Append( _L("\\") );
   987     {
   762                     }
   988     //Get the white list
   763 
   989     TBuf<2048> whiteList;
   764                 // create op cache
   990     
   765                 iOperatorCache = CHttpCacheHandler::NewL( opCacheSize, opCacheFolder, KDefaultOpIndexFile(), criticalLevel, postpone);
   991     if (aRepository.Get(KPhoneSpecificCacheDomainUrl, whiteList) == KErrNone)
   766                 }
   992         {
   767             } //end if( FeatureManager::FeatureSupported( KFeatureIdOperatorCache ) )
   993         iVSSWhiteList = HBufC8::NewL(whiteList.Length());
   768         } //end if( iCacheEnabled )
   994         iVSSWhiteList->Des().Append(whiteList);
   769 
       
   770     TInt VSScacheEnabled( 0 );
       
   771     err = repository->Get( KPhoneSpecificCacheEnabled, VSScacheEnabled );
       
   772 
       
   773     iVSSCacheEnabled = VSScacheEnabled;
       
   774 
       
   775     if ( (err == KErrNone) && iVSSCacheEnabled )
       
   776         {
       
   777         // cache size
       
   778         TInt VSScacheSize( KDefaultCacheSize );
       
   779         repository->Get( KPhoneSpecificCacheSize, VSScacheSize );
       
   780 
       
   781         // cache folder
       
   782         TFileName VSScacheFolder( KDefaultVssCacheDir );
       
   783         // ignore cache folder. use c:\ to save memory. (same for operator cache. see below)
       
   784         repository->Get( KPhoneSpecificCacheFolder, VSScacheFolder );
       
   785         // fix folder by appending trailing \\ to the end -symbian thing
       
   786         // unless it is already there
       
   787         if( VSScacheFolder.LocateReverse( '\\' ) != VSScacheFolder.Length() - 1  )
       
   788             {
       
   789             VSScacheFolder.Append( _L("\\") );
       
   790             }
       
   791 
       
   792         //Get the white list
       
   793         TBuf<2048> whiteList;
       
   794 
       
   795         if ( repository->Get( KPhoneSpecificCacheDomainUrl, whiteList ) == KErrNone )
       
   796             {
       
   797             iVSSWhiteList = HBufC8::NewL( whiteList.Length() );
       
   798             iVSSWhiteList->Des().Append( whiteList );
       
   799             }
       
   800         else
       
   801             {
       
   802             iVSSWhiteList = NULL;
       
   803             }
       
   804 
       
   805         // create cache handler
       
   806         iphoneSpecificCache = CHttpCacheHandler::NewL( VSScacheSize, VSScacheFolder, KDefaultVSSIndexFile(), criticalLevel, postpone);
       
   807         }
       
   808 
       
   809     CleanupStack::PopAndDestroy(2); // repository, , repositoryDiskLevel
       
   810     }
       
   811 
       
   812 // -----------------------------------------------------------------------------
       
   813 // CHttpCacheManager::CacheHandler
       
   814 //
       
   815 // -----------------------------------------------------------------------------
       
   816 //
       
   817 CHttpCacheHandler* CHttpCacheManager::CacheHandler(
       
   818     const TDesC8& aUrl,
       
   819     TDes8* aHttpHeaderString ) const
       
   820     {
       
   821     CHttpCacheHandler* cache;
       
   822     if( iVSSCacheEnabled && aHttpHeaderString && VSSHeaderCheck( aHttpHeaderString ) )
       
   823         {
       
   824         cache = iphoneSpecificCache;
       
   825         }
   995         }
   826     else
   996     else
   827         {
   997         {
   828         cache = ( ( iOpDomain && HttpCacheUtil::OperatorCacheContent( iOpDomain->Des(), aUrl ) ) ? iOperatorCache : iCache );
   998         iVSSWhiteList = NULL;
   829         }
   999         }
   830     return cache;
  1000     
   831     }
  1001     // create cache handler
       
  1002     iphoneSpecificCache = CHttpCacheHandler::NewL(aVssCacheSize, aVssCacheFolder, KDefaultVSSIndexFile(), aCriticalLevel, aPostpone);
       
  1003     }
       
  1004 
       
  1005 void CHttpCacheManager::CrashCheckL( const TInt& aSecIdInt )
       
  1006     {
       
  1007     if( aSecIdInt == KUIDBROWSERNG )
       
  1008         {
       
  1009         //////////////////////////////////////////////////////////////////////////////////////////////////////
       
  1010         // Remove orphan files if browser didn't close cache properly - should only happen very occasionally
       
  1011         //
       
  1012         // We leave a file on the drive when we are in use and remove it when we close properly
       
  1013         // If the file is already there we expect files in the cache which have not been added to the index.
       
  1014         //
       
  1015         //////////////////////////////////////////////////////////////////////////////////////////////////////
       
  1016         RFs rfs;
       
  1017         User::LeaveIfError( rfs.Connect() );
       
  1018         CleanupClosePushL( rfs );
       
  1019         rfs.SetSessionPath( iCacheFolder );
       
  1020         RFile crashTest;
       
  1021         TInt err = crashTest.Create(rfs,KCrashCheck(),EFileRead);
       
  1022         crashTest.Close();  
       
  1023         if ( err == KErrAlreadyExists )
       
  1024             {
       
  1025     #ifdef __CACHELOG__
       
  1026             HttpCacheUtil::WriteLog(0, _L("Crash detected - removing orphan files"));
       
  1027     #endif
       
  1028             RemoveOrphanedFilesL();
       
  1029             }
       
  1030         CleanupStack::PopAndDestroy( &rfs );
       
  1031         }
       
  1032     }
       
  1033 
   832 //  End of File
  1034 //  End of File