679 // We successfully saved (flush) body |
679 // We successfully saved (flush) body |
680 entry->SetState( CHttpCacheEntry::ECacheComplete ); |
680 entry->SetState( CHttpCacheEntry::ECacheComplete ); |
681 iStreamHandler->Detach( *entry ); |
681 iStreamHandler->Detach( *entry ); |
682 |
682 |
683 // Clear the flushed cache buffer, we were using for incoming body |
683 // Clear the flushed cache buffer, we were using for incoming body |
684 entry->SetCacheBufferL( KBufferSizeZero ); |
684 TRAP_IGNORE( entry->SetCacheBufferL( KBufferSizeZero ) ); |
685 } |
685 } |
686 } |
686 } |
687 else if( entry->State() == CHttpCacheEntry::ECacheDestroyed ) |
687 else if( entry->State() == CHttpCacheEntry::ECacheDestroyed ) |
688 { |
688 { |
689 iStreamHandler->Detach( *entry ); |
689 iStreamHandler->Detach( *entry ); |
1001 #endif // __CACHELOG__ |
1001 #endif // __CACHELOG__ |
1002 |
1002 |
1003 CArrayPtrFlat<CHttpCacheEntry>* evictedList = iEvictionHandler->EvictL( aSize ); |
1003 CArrayPtrFlat<CHttpCacheEntry>* evictedList = iEvictionHandler->EvictL( aSize ); |
1004 if ( evictedList && evictedList->Count() ) |
1004 if ( evictedList && evictedList->Count() ) |
1005 { |
1005 { |
1006 // destroy items |
1006 // Delete entry items marked for eviction |
1007 CHttpCacheEntry* entry; |
1007 CHttpCacheEntry* entry; |
1008 for( TInt i = 0; i < evictedList->Count(); i++ ) |
1008 for ( TInt i = 0; i < evictedList->Count(); i++ ) |
1009 { |
1009 { |
1010 // |
|
1011 entry = evictedList->At( i ); |
1010 entry = evictedList->At( i ); |
1012 if( entry ) |
1011 |
|
1012 if ( entry ) |
1013 { |
1013 { |
1014 // destroy |
1014 // Handle removing valid and invalid entries. Check entry |
1015 iLookupTable->Remove( entry->Url() ); |
1015 // for validity, and if in lookup table. It has been |
|
1016 // found that the evictList can have invalid entries in it. |
|
1017 // These invalid entries are not in the lookup table. |
|
1018 TInt lookupTableIndex( -1 ); |
|
1019 iLookupTable->FindCacheEntryIndex( *entry, &lookupTableIndex ); |
|
1020 |
|
1021 TInt sizeBody = entry->BodySize(); |
|
1022 if ( sizeBody == 0 && lookupTableIndex >= 0 ) |
|
1023 { |
|
1024 // This is an empty body cache entry that exists |
|
1025 // in the lookup table, remove it from file system and |
|
1026 // lookup table. |
|
1027 // Use CreateNewFilesL() to open file handles, so we can delete |
|
1028 // the files associated with the cache entry. We don't check |
|
1029 // return value of RemoveByPosition(), because we already |
|
1030 // checked for index in FindCacheEntryIndex(). |
|
1031 iStreamHandler->CreateNewFilesL( *entry ); |
|
1032 iStreamHandler->EraseCacheFile( *entry ); |
|
1033 iLookupTable->RemoveByPosition( lookupTableIndex ); |
|
1034 } |
|
1035 else if ( lookupTableIndex >= 0 ) |
|
1036 { |
|
1037 // Remove valid entries that are found in lookup table |
|
1038 iLookupTable->Remove( entry->Url() ); |
|
1039 } |
1016 } |
1040 } |
1017 } |
1041 } |
1018 |
1042 |
1019 // ok = ETrue if there is enough space |
1043 // ok = ETrue if there is enough space |
1020 ok = ( iStreamHandler->SavedContentSize() + aSize < iSize ); |
1044 ok = ( iStreamHandler->SavedContentSize() + aSize < iSize ); |
1210 break; |
1236 break; |
1211 } |
1237 } |
1212 } |
1238 } |
1213 if( ret == KErrNone ) |
1239 if( ret == KErrNone ) |
1214 { |
1240 { |
1215 CleanupClosePushL( readStream ); |
1241 TRAPD ( err, aLookupTable->InternalizeL( readStream, iDirectory->Des() ) ); |
1216 aLookupTable->InternalizeL( readStream, iDirectory->Des() ); |
1242 readStream.Close(); |
1217 CleanupStack::PopAndDestroy(1); // readStream |
1243 if ( err != KErrNone ) |
|
1244 { |
|
1245 // In case Bad Things Happen (TM), do RemoveAllL() which clears this cache's |
|
1246 // in-memory data structures + saves an updated lookup table to disk replacing the old one. |
|
1247 TRAP_IGNORE( RemoveAllL() ); |
|
1248 } |
1218 } |
1249 } |
1219 } |
1250 } |
1220 |
1251 |
1221 // ----------------------------------------------------------------------------- |
1252 // ----------------------------------------------------------------------------- |
1222 // CHttpCacheHandler::SaveLookupTableL |
1253 // CHttpCacheHandler::SaveLookupTableL |
1230 #endif |
1261 #endif |
1231 // save entries to index.dat |
1262 // save entries to index.dat |
1232 RFileWriteStream writeStream; |
1263 RFileWriteStream writeStream; |
1233 |
1264 |
1234 // Don't get notified about own changes |
1265 // Don't get notified about own changes |
1235 iHttpCacheObserver->Cancel(); |
1266 if ( iHttpCacheObserver ) |
|
1267 iHttpCacheObserver->Cancel(); |
|
1268 |
1236 TInt ret = KErrNone; |
1269 TInt ret = KErrNone; |
1237 TInt tryCount = 0; |
1270 TInt tryCount = 0; |
1238 for (tryCount = 0; tryCount < 5; tryCount++) |
1271 for (tryCount = 0; tryCount < 5; tryCount++) |
1239 { |
1272 { |
1240 ret = writeStream.Replace( iRfs, iIndexFile->Des(), EFileWrite ); |
1273 ret = writeStream.Replace( iRfs, iIndexFile->Des(), EFileWrite ); |
1254 CleanupClosePushL( writeStream ); |
1287 CleanupClosePushL( writeStream ); |
1255 iLookupTable->ExternalizeL( writeStream ); |
1288 iLookupTable->ExternalizeL( writeStream ); |
1256 writeStream.CommitL(); |
1289 writeStream.CommitL(); |
1257 CleanupStack::PopAndDestroy(); // writeStream |
1290 CleanupStack::PopAndDestroy(); // writeStream |
1258 } |
1291 } |
1259 iHttpCacheObserver->StartObserver(); |
1292 |
|
1293 if ( iHttpCacheObserver ) |
|
1294 iHttpCacheObserver->StartObserver(); |
1260 } |
1295 } |
1261 |
1296 |
1262 // ----------------------------------------------------------------------------- |
1297 // ----------------------------------------------------------------------------- |
1263 // CHttpCacheHandler::DeleteCacheEntry |
1298 // CHttpCacheHandler::DeleteCacheEntry |
1264 // |
1299 // |
1325 // ----------------------------------------------------------------------------- |
1360 // ----------------------------------------------------------------------------- |
1326 // |
1361 // |
1327 void CHttpCacheHandler::UpdateLookupTable() |
1362 void CHttpCacheHandler::UpdateLookupTable() |
1328 { |
1363 { |
1329 TRAP_IGNORE(UpdateLookupTableL()); |
1364 TRAP_IGNORE(UpdateLookupTableL()); |
1330 iHttpCacheObserver->StartObserver(); |
1365 |
|
1366 if ( iHttpCacheObserver ) |
|
1367 iHttpCacheObserver->StartObserver(); |
1331 } |
1368 } |
1332 |
1369 |
1333 // ----------------------------------------------------------------------------- |
1370 // ----------------------------------------------------------------------------- |
1334 // CHttpCacheHandler::UpdateLookupTableL |
1371 // CHttpCacheHandler::UpdateLookupTableL |
1335 // Slow method due to much file-system interaction. Don't call it from performance critical code. |
1372 // Slow method due to much file-system interaction. Don't call it from performance critical code. |