webengine/osswebengine/cache/src/HttpCacheUtil.cpp
changeset 11 c8a366e56285
parent 10 a359256acfc6
child 25 0ed94ceaa377
equal deleted inserted replaced
10:a359256acfc6 11:c8a366e56285
  1176 
  1176 
  1177     if ( log )
  1177     if ( log )
  1178         {
  1178         {
  1179         VA_LIST args;
  1179         VA_LIST args;
  1180         VA_START(args, aBuf);
  1180         VA_START(args, aBuf);
  1181         // Be careful of string length when debugging
       
  1182         TBuf16<1024> string;
  1181         TBuf16<1024> string;
  1183         // TDes16OverflowIgnore, not supported in 3.2.3
  1182         TDes16IgnoreOverflow overflow;
  1184         // TDes16OverflowIgnore overflow;
  1183         string.AppendFormatList(aBuf, args, &overflow);
  1185         // string.AppendFormatList(aBuf, args, &overflow);
       
  1186         string.AppendFormatList(aBuf, args);
       
  1187         RFileLogger::WriteFormat(_L("Browser"), fileName, EFileLoggingModeAppend, string);
  1184         RFileLogger::WriteFormat(_L("Browser"), fileName, EFileLoggingModeAppend, string);
  1188         VA_END(args);
  1185         VA_END(args);
  1189         }
  1186         }
  1190 #else // __CACHELOG__
  1187 #else // __CACHELOG__
  1191     (void)aLogLevel;
  1188     (void)aLogLevel;
  1831         }
  1828         }
  1832     User::Free( valuestr );
  1829     User::Free( valuestr );
  1833     return status;
  1830     return status;
  1834     }
  1831     }
  1835 
  1832 
       
  1833 
       
  1834 // -----------------------------------------------------------------------------
       
  1835 // FilePathHash
       
  1836 // Hash function for Symbian file paths: discards case first
       
  1837 // -----------------------------------------------------------------------------
       
  1838 static TUint32 FilepathHash(const TDesC& aDes)
       
  1839 {
       
  1840     //since this function is intensively used by the HashMap,
       
  1841     //keeping (slow) heap allocation out of it.
       
  1842     TBuf<KMaxPath> normalized ( aDes );
       
  1843 
       
  1844     normalized.LowerCase();
       
  1845     return DefaultHash::Des16( normalized );
       
  1846 }
       
  1847 
       
  1848 // -----------------------------------------------------------------------------
       
  1849 // FilepathIdent
       
  1850 // Comparator for Symbian file paths: Use case-insensitive compare
       
  1851 // -----------------------------------------------------------------------------
       
  1852 static TBool FilepathIdent(const TDesC& aL, const TDesC& aR)
       
  1853 {
       
  1854     return ( aL.CompareF(aR) == 0 );
       
  1855 }
       
  1856 
       
  1857 
       
  1858 void HttpCacheUtil::GenerateCacheContentHashMapL(CHttpCacheFileHash*& aHashMap, RFs& aRfs, const TDesC& aCacheFolder, const TInt aInitialValue)
       
  1859     {
       
  1860     // need to be able to initialise hash here, but use it sensibly in calling function hence rather strange object construction
       
  1861     aHashMap = CHttpCacheFileHash::NewLC(aInitialValue);
       
  1862     
       
  1863     CDirScan* scanner = CDirScan::NewLC( aRfs );
       
  1864 
       
  1865     //Configure CDirScan to tell you all contents of a particular directory hierarchy
       
  1866     scanner->SetScanDataL( aCacheFolder, KEntryAttNormal, ESortNone );
       
  1867     CDir* matchingFiles( 0 );
       
  1868 
       
  1869     //Step 1. Find out all files on disk: by walking the directory hierarchy, one directory at a time
       
  1870     for (;;)
       
  1871         {
       
  1872         //1a. Get list of files in current directory, NULL if no directory left in tree
       
  1873         scanner->NextL( matchingFiles );
       
  1874         if ( !matchingFiles )
       
  1875             break;
       
  1876 
       
  1877         TPtrC dir( scanner->FullPath() );
       
  1878 
       
  1879         //1b. Add any files found to the HashTable
       
  1880         const TInt nMatches = matchingFiles->Count();
       
  1881         for ( TInt i = 0; i < nMatches; i++ )
       
  1882             {
       
  1883             TEntry entry ( (*matchingFiles)[i] ) ;
       
  1884             aHashMap->InsertAndStoreL( entry, dir );
       
  1885             }
       
  1886 
       
  1887         delete matchingFiles;
       
  1888         } // End of step 1: adding all known files on disk to Map
       
  1889 
       
  1890     CleanupStack::PopAndDestroy( 1, scanner );
       
  1891     CleanupStack::Pop( aHashMap );
       
  1892     
       
  1893 #ifdef __CACHELOG__
       
  1894     {
       
  1895     HttpCacheUtil::WriteFormatLog(0, _L("-----------START PRINTING MAP OF SIZE %d---------"), aHashMap->HashMap().Count());
       
  1896     THttpCacheFileHashIter iter(aHashMap->HashMap());
       
  1897     const TDesC* key;
       
  1898     while ((key = iter.NextKey()) != 0)
       
  1899         {
       
  1900         const TFileInfo* val = iter.CurrentValue();
       
  1901         HttpCacheUtil::WriteFormatLog(0, _L("MAP WALK: %S, with size = %d, value = %d "), key, val->iFileSize, val->iUserInt);
       
  1902         }
       
  1903     HttpCacheUtil::WriteFormatLog(0, _L("-----------DONE PRINTING MAP-------------"));
       
  1904     }
       
  1905 #endif
       
  1906     }
       
  1907 
       
  1908 void HttpCacheUtil::EnsureTrailingSlash( TDes& aPath )
       
  1909     {
       
  1910     // fix folder by appending trailing \\ to the end -symbian thing
       
  1911     // unless it is already there
       
  1912     if (aPath.LocateReverse('\\') != aPath.Length() - 1)
       
  1913         {
       
  1914         aPath.Append(_L("\\"));
       
  1915         }
       
  1916     
       
  1917     }
       
  1918 
       
  1919 
       
  1920 CHttpCacheFileHash::CHttpCacheFileHash(const TInt aInitialValue, const THashFunction32<TDesC>& aHash, const TIdentityRelation<TDesC>& aIdentity) : iHashMap(aHash, aIdentity), iInitialValue(aInitialValue)
       
  1921     {
       
  1922     }
       
  1923 
       
  1924 CHttpCacheFileHash* CHttpCacheFileHash::NewLC(const TInt iInitialValue)
       
  1925     {
       
  1926     CHttpCacheFileHash* obj = new (ELeave) CHttpCacheFileHash(iInitialValue, &FilepathHash, &FilepathIdent);
       
  1927     CleanupStack::PushL(obj);
       
  1928     obj->ConstructL();
       
  1929     return obj;
       
  1930     }
       
  1931 
       
  1932 CHttpCacheFileHash::~CHttpCacheFileHash()
       
  1933     {
       
  1934     iStringStorage.ResetAndDestroy();
       
  1935     delete iFileInfoStorage;
       
  1936     iHashMap.Close();
       
  1937     }
       
  1938 
       
  1939 void CHttpCacheFileHash::ConstructL()
       
  1940     {
       
  1941     iFileInfoStorage = new (ELeave) CArrayFixSeg<TFileInfo>(64);    // 64 objects at a time
       
  1942     }
       
  1943 
       
  1944 void CHttpCacheFileHash::InsertAndStoreL(const TEntry& aEntry, const TDesC& aDir)
       
  1945     {
       
  1946     TFileInfo& info = iFileInfoStorage->ExtendL();
       
  1947     info.iFileSize = aEntry.iSize;
       
  1948     info.iUserInt = iInitialValue;
       
  1949     HBufC* fullPath = HBufC::NewL( aDir.Length() + aEntry.iName.Length() );
       
  1950     iStringStorage.AppendL( fullPath ); //keep object safe for later destruction
       
  1951     TPtr path(fullPath->Des());
       
  1952     path.Copy( aDir );
       
  1953     path.Append( aEntry.iName );
       
  1954     iHashMap.Insert( fullPath , &info );
       
  1955     }
       
  1956 
  1836 //  End of File
  1957 //  End of File