webengine/osswebengine/cache/src/HttpCacheEntry.cpp
changeset 1 7c90e6132015
parent 0 dd21522fd290
child 10 a359256acfc6
--- a/webengine/osswebengine/cache/src/HttpCacheEntry.cpp	Mon Mar 30 12:54:55 2009 +0300
+++ b/webengine/osswebengine/cache/src/HttpCacheEntry.cpp	Fri May 08 08:25:06 2009 +0300
@@ -27,7 +27,7 @@
 // EXTERNAL FUNCTION PROTOTYPES
 
 // CONSTANTS
-const TInt CHttpCacheEntry::iOffset = _FOFF( CHttpCacheEntry, iSlink );
+const TInt CHttpCacheEntry::iOffset = _FOFF( CHttpCacheEntry, iSqlQueLink );
 
 // MACROS
 
@@ -49,8 +49,7 @@
 // might leave.
 // -----------------------------------------------------------------------------
 //
-CHttpCacheEntry::CHttpCacheEntry(
-    CHttpCacheEvictionHandler& aEvictionHandler )
+CHttpCacheEntry::CHttpCacheEntry( CHttpCacheEvictionHandler& aEvictionHandler )
     : iState( ECacheUninitialized ),
       iEvictionHandler( &aEvictionHandler )
     {
@@ -61,8 +60,7 @@
 // Symbian 2nd phase constructor can leave.
 // -----------------------------------------------------------------------------
 //
-void CHttpCacheEntry::ConstructL(
-    const TDesC8& aUrl )
+void CHttpCacheEntry::ConstructL( const TDesC8& aUrl )
     {
     iUrl = aUrl.AllocL();
     iFileName = KNullDesC().AllocL();
@@ -100,15 +98,29 @@
     return self;
     }
 
+// -----------------------------------------------------------------------------
 // Destructor
+// -----------------------------------------------------------------------------
+//
 CHttpCacheEntry::~CHttpCacheEntry()
     {
-  if( iVictim && iEvictionHandler)
-    {
-    iEvictionHandler->Remove( *this );
-    }
+    // Clean up eviction handler
+    if ( iEvictionCandidate && iEvictionHandler )
+        {
+        iEvictionHandler->Remove( *this );
+        }
+
+    // Close files, this will commit changes
+    if ( iCacheFilesOpened )
+        {
+        iHeaderFile.Close();
+        iBodyFile.Close();
+        }
+
+    // Clean up our memory
     delete iUrl;
     delete iFileName;
+    delete iCacheBuffer;
     }
 
 // -----------------------------------------------------------------------------
@@ -116,30 +128,29 @@
 //
 // -----------------------------------------------------------------------------
 //
-void CHttpCacheEntry::SetState(
-    TCacheEntryState aState )
+void CHttpCacheEntry::SetState( TCacheEntryState aState )
     {
-    // add entry to the eviction table once it gets completed
-    if( aState == ECacheComplete && !iVictim )
+    // Add entry to the eviction table once it gets completed
+    if ( aState == ECacheComplete && !iEvictionCandidate )
         {
         // don't add it twice
         iEvictionHandler->Insert( *this );
-        iVictim = ETrue;
+        iEvictionCandidate = ETrue;
         }
+
     iState = aState;
     }
 
-
 // -----------------------------------------------------------------------------
 // CHttpCacheEntry::SetFileNameL
 //
 // -----------------------------------------------------------------------------
 //
-void CHttpCacheEntry::SetFileNameL(
-    const TFileName& aFileName )
+void CHttpCacheEntry::SetFileNameL( const TFileName& aFileName )
     {
     delete iFileName;
     iFileName = NULL;
+    
     iFileName = aFileName.AllocL();
     }
 
@@ -153,42 +164,41 @@
     {
     TTime now;
     now.HomeTime();
-
     iLastAccessed = now.Int64();
 
     iRef++;
-    if( iVictim )
+
+    if ( iEvictionCandidate )
         {
         iEvictionHandler->Accessed( *this );
         }
+
 #ifdef __CACHELOG__
     _LIT( KAccessFormat, "entry accessed: %d" );
     TBuf<100> buf;
     buf.Format( KAccessFormat, iRef );
     HttpCacheUtil::WriteUrlToLog( 0, buf, iUrl->Des() );
 #endif // __CACHELOG__
+
     }
 
 // -----------------------------------------------------------------------------
-// CHttpCacheEntry::SetSize
+// CHttpCacheEntry::SetBodySize
 //
 // -----------------------------------------------------------------------------
 //
-void CHttpCacheEntry::SetSize(
-    TUint aSize )
+void CHttpCacheEntry::SetBodySize( TUint aBodySize )
     {
-    if( iSize && !aSize )
+    if ( iBodySize && !aBodySize )
         {
-        // body removal
-        // remove itself from the eviction table.
-        // this is no longer a victim
-      if( iVictim )
-        {
-        iEvictionHandler->Remove( *this );
-            iVictim = EFalse;
+        // Remove from the eviction table, this is no longer a candidate
+        if ( iEvictionCandidate )
+            {
+            iEvictionHandler->Remove( *this );
+            iEvictionCandidate = EFalse;
+            }
         }
-        }
-    iSize = aSize;
+    iBodySize = aBodySize;
     }
 
 // -----------------------------------------------------------------------------
@@ -199,9 +209,11 @@
 void CHttpCacheEntry::SetProtected()
     {
     iProtected = ETrue;
-    // iRef
     iRef = 50;
-    HttpCacheUtil::WriteLog( 0, _L( "protected item" ) );
+
+#ifdef __CACHELOG__
+    HttpCacheUtil::WriteLog( 0, _L( "CHttpCacheEntry::SetProtected - protected item" ) );
+#endif
     }
 
 // -----------------------------------------------------------------------------
@@ -209,45 +221,47 @@
 //
 // -----------------------------------------------------------------------------
 //
-TInt CHttpCacheEntry::Internalize(
-    RFileReadStream& aReadStream )
+TInt CHttpCacheEntry::Internalize( RFileReadStream& aReadStream )
     {
-    TRAPD( err,
-     TInt len;
-    
     // url length
-    len = aReadStream.ReadInt32L();
-    delete iUrl;
-    iUrl=NULL;
-    iUrl = HBufC8::NewL( len );
-    TPtr8 ptr8( iUrl->Des() );
-    // url
-    aReadStream.ReadL( ptr8, len );
+    TRAPD( err,
+     	TInt len;
     
-    // filename length
-    len = aReadStream.ReadInt32L();
-    HBufC* filename = HBufC::NewLC( len );
-    TPtr ptr( filename->Des() );
-    // url
-    aReadStream.ReadL( ptr, len );
-    //
-    SetFileNameL( filename->Des() );
-    //
-    CleanupStack::PopAndDestroy(); // filename
-    // la
-    TReal64 la;
-    la = aReadStream.ReadReal64L();
-    iLastAccessed = la;
-    // ref
-    iRef = aReadStream.ReadUint32L();
-    // size
-    iSize = aReadStream.ReadUint32L( );
-    // size
-    iHeaderSize = aReadStream.ReadUint32L( );
-    // protected
-    iProtected = aReadStream.ReadInt32L();
-    //
-    SetState( ECacheComplete ); );
+    	// url length
+    	len = aReadStream.ReadInt32L();
+        delete iUrl;
+        iUrl=NULL;
+        iUrl = HBufC8::NewL( len );
+        TPtr8 ptr8( iUrl->Des() );
+        // url
+        aReadStream.ReadL( ptr8, len );
+        
+        // filename length
+        len = aReadStream.ReadInt32L();
+        HBufC* filename = HBufC::NewLC( len );
+        TPtr ptr( filename->Des() );
+        // url
+        aReadStream.ReadL( ptr, len );
+        //
+        SetFileNameL( filename->Des() );
+        //
+        CleanupStack::PopAndDestroy(); // filename
+        // la
+        TReal64 la;
+        la = aReadStream.ReadReal64L();
+        iLastAccessed = la;
+        // ref
+        iRef = aReadStream.ReadUint32L();
+        // size
+        iBodySize = aReadStream.ReadUint32L( );
+        // size
+        iHeaderSize = aReadStream.ReadUint32L( );
+        // protected
+        iProtected = aReadStream.ReadInt32L();
+        //
+        SetState( ECacheComplete );
+    );	// end of TRAPD
+
     return err;
     }
 
@@ -256,28 +270,29 @@
 //
 // -----------------------------------------------------------------------------
 //
-TInt CHttpCacheEntry::Externalize(
-    RFileWriteStream& aWriteStream )
+TInt CHttpCacheEntry::Externalize( RFileWriteStream& aWriteStream )
     {
     TRAPD( err,
-    // url length
-    aWriteStream.WriteInt32L( iUrl->Length() );
-    // url
-    aWriteStream.WriteL( iUrl->Des() );
-    // filename length
-    aWriteStream.WriteInt32L( iFileName->Length() );
-    // filename
-    aWriteStream.WriteL( iFileName->Des() );
-    // la
-    aWriteStream.WriteReal64L( iLastAccessed );
-    // ref
-    aWriteStream.WriteUint32L( iRef );
-    // size
-    aWriteStream.WriteUint32L( iSize );
-    // size
-    aWriteStream.WriteUint32L( iHeaderSize );
-    // protected
-    aWriteStream.WriteInt32L( iProtected ); );
+        // url length
+        aWriteStream.WriteInt32L( iUrl->Length() );
+        // url
+        aWriteStream.WriteL( iUrl->Des() );
+        // filename length
+        aWriteStream.WriteInt32L( iFileName->Length() );
+        // filename
+        aWriteStream.WriteL( iFileName->Des() );
+        // la
+        aWriteStream.WriteReal64L( iLastAccessed );
+        // ref
+        aWriteStream.WriteUint32L( iRef );
+        // size
+        aWriteStream.WriteUint32L( iBodySize );
+        // size
+        aWriteStream.WriteUint32L( iHeaderSize );
+        // protected
+        aWriteStream.WriteInt32L( iProtected );
+    );  // end of TRAPD
+
     return err;
     }
 
@@ -286,14 +301,15 @@
 //
 // -----------------------------------------------------------------------------
 //
-void CHttpCacheEntry::Accessed(TInt64 aLastAccessed, TUint16 aRef)
+void CHttpCacheEntry::Accessed( TInt64 aLastAccessed, TUint16 aRef )
     {
     iLastAccessed = aLastAccessed;
     iRef = aRef;
-    if( iVictim )
+    if ( iEvictionCandidate )
         {
         iEvictionHandler->Accessed( *this );
         }
+
 #ifdef __CACHELOG__
     _LIT( KAccessFormat, "entry accessed: %d" );
     TBuf<100> buf;
@@ -303,4 +319,62 @@
 
     }
 
+// -----------------------------------------------------------------------------
+// CHttpCacheEntry::SetCacheFilesOpened
+//
+// -----------------------------------------------------------------------------
+//
+void CHttpCacheEntry::SetCacheFilesOpened( TBool aCacheFilesOpened )
+    {
+    // Set our files open flag
+    iCacheFilesOpened = aCacheFilesOpened;
+    }
+
+// -----------------------------------------------------------------------------
+// CHttpCacheEntry::CacheBuffer
+// NOTE: Cache buffer is created on:
+// 1. Normal content entrypoint into CacheManager
+//    CacheManager::ReceivedResponseHeadersL -> CacheHandler::ReceivedResponseHeadersL ->
+//    CacheHandler::HandleResponseOkL (calls method - SetCacheBuffer, needed to
+//    accumulate body content on multiple CacheHandler::ReceivedBodyDataL calls)
+// 2. Multipart content entrypoint into CacheManager
+//    CacheManager::SaveL -> CacheHandler::SaveL -> CacheHandler::SaveBuffer ->
+//    CacheStreamHandler::SaveBodyData (calls this method - CacheBuffer, needed
+//    because cacheBuffer=null and single call made, no accumulation of body data) 
+// -----------------------------------------------------------------------------
+//
+TPtr8 CHttpCacheEntry::CacheBuffer()
+    {
+    if ( iCacheBuffer == NULL )
+        {
+        // Create the cache buffer, if needed
+        iCacheBuffer = HBufC8::New( KBufferSize32k );
+        if ( iCacheBuffer == NULL )
+			{
+			// OOM, return empty cache buffer
+			TPtr8 emptyCacheBuffer( NULL, 0, 0 );
+			return emptyCacheBuffer;
+			}
+		}
+
+    return iCacheBuffer->Des();
+    }
+
+// -----------------------------------------------------------------------------
+// CHttpCacheEntry::SetCacheBufferL
+//
+// -----------------------------------------------------------------------------
+//
+void CHttpCacheEntry::SetCacheBufferL( TInt aCacheBufferSize )
+    {
+    if ( aCacheBufferSize > 0 && iCacheBuffer == NULL )
+        {
+        iCacheBuffer = HBufC8::NewL( aCacheBufferSize );
+        }
+    else if ( aCacheBufferSize <= 0 )
+        {
+        delete iCacheBuffer;
+        iCacheBuffer = NULL;
+        }
+    }
 //  End of File