imagehandlingutilities/thumbnailmanager/thumbnailserver/src/thumbnailstore.cpp
changeset 17 ffa62e555b02
parent 15 7197e789b953
child 19 b790c5b3d11f
equal deleted inserted replaced
15:7197e789b953 17:ffa62e555b02
    42 const TInt KMinor = 2;
    42 const TInt KMinor = 2;
    43 
    43 
    44 const TInt KStoreUnrecoverableErr = KErrCorrupt;
    44 const TInt KStoreUnrecoverableErr = KErrCorrupt;
    45 
    45 
    46 // Database path without drive letter
    46 // Database path without drive letter
    47 _LIT( KThumbnailDatabaseName, ":[102830AB]thumbnail_v3.db" );
    47 _LIT( KThumbnailDatabaseName, ":[102830AB]thumbnail_v5.db" );
    48 
    48 
    49 _LIT( KDrv, ":");
    49 _LIT( KDrv, ":");
    50 
    50 
    51 // Allow access to database only for the server process
    51 // Allow access to database only for the server process
    52 const TSecurityPolicy KThumbnailDatabaseSecurityPolicy( TSecureId(
    52 const TSecurityPolicy KThumbnailDatabaseSecurityPolicy( TSecureId(
    66 // ---------------------------------------------------------------------------
    66 // ---------------------------------------------------------------------------
    67 // RThumbnailTransaction::BeginL()
    67 // RThumbnailTransaction::BeginL()
    68 // ---------------------------------------------------------------------------
    68 // ---------------------------------------------------------------------------
    69 //
    69 //
    70 void RThumbnailTransaction::BeginL()
    70 void RThumbnailTransaction::BeginL()
    71     {
    71     {    
       
    72     if (iDatabase.InTransaction())
       
    73         {
       
    74         TN_DEBUG1( "RThumbnailTransaction::BeginL() - error: old transaction open!" );
       
    75         __ASSERT_DEBUG(( !iDatabase.InTransaction() ), ThumbnailPanic( EThumbnailSQLTransaction ));
       
    76         
       
    77         // old transaction already open, don't open another
       
    78         iState = EOldOpen;
       
    79         
       
    80         return;
       
    81         }
       
    82     
    72     const TInt err = iDatabase.Exec( KThumbnailBeginTransaction );
    83     const TInt err = iDatabase.Exec( KThumbnailBeginTransaction );
    73     if ( err >= 0 )
    84     if ( err >= 0 )
    74         {
    85         {
    75         iState = EOpen;
    86         iState = EOpen;
    76         }
    87         }
    89 // RThumbnailTransaction::Close()
   100 // RThumbnailTransaction::Close()
    90 // ---------------------------------------------------------------------------
   101 // ---------------------------------------------------------------------------
    91 //
   102 //
    92 void RThumbnailTransaction::Close()
   103 void RThumbnailTransaction::Close()
    93     {
   104     {
    94     if ( iState != EClosed )
   105     if ( iState != EClosed && iState != EOldOpen )
    95         {
   106         {
    96         Rollback();
   107         Rollback();
    97         }
   108         }
    98     }
   109     }
    99 
   110 
   101 // RThumbnailTransaction::CommitL()
   112 // RThumbnailTransaction::CommitL()
   102 // ---------------------------------------------------------------------------
   113 // ---------------------------------------------------------------------------
   103 //
   114 //
   104 void RThumbnailTransaction::CommitL()
   115 void RThumbnailTransaction::CommitL()
   105     {
   116     {
   106     TInt ret = iDatabase.Exec( KThumbnailCommitTransaction );
   117     if ( iState != EOldOpen )
       
   118         {
       
   119         TInt ret = iDatabase.Exec( KThumbnailCommitTransaction );
   107     
   120     
   108 #ifdef _DEBUG
   121 #ifdef _DEBUG
   109     TPtrC errorMsg = iDatabase.LastErrorMessage();
   122     TPtrC errorMsg = iDatabase.LastErrorMessage();
   110     TN_DEBUG3( "RThumbnailTransaction::CommitL() lastError %S, ret = %d" , &errorMsg, ret);
   123     TN_DEBUG3( "RThumbnailTransaction::CommitL() lastError %S, ret = %d" , &errorMsg, ret);
   111 #endif  
   124 #endif  
   112     User::LeaveIfError( ret );
   125     User::LeaveIfError( ret );
       
   126         }
   113     
   127     
   114     iState = EClosed;
   128     iState = EClosed;
   115     }
   129     }
   116 
   130 
   117 // ---------------------------------------------------------------------------
   131 // ---------------------------------------------------------------------------
   118 // RThumbnailTransaction::Rollback()
   132 // RThumbnailTransaction::Rollback()
   119 // ---------------------------------------------------------------------------
   133 // ---------------------------------------------------------------------------
   120 //
   134 //
   121 TInt RThumbnailTransaction::Rollback()
   135 TInt RThumbnailTransaction::Rollback()
   122     {
   136     {
   123     const TInt err = iDatabase.Exec( KThumbnailRollbackTransaction );
   137     if ( iState != EOldOpen )
   124     if ( err >= 0 )
   138         {
   125         {
   139         const TInt err = iDatabase.Exec( KThumbnailRollbackTransaction );
   126         iState = EClosed;
   140         if ( err >= 0 )
   127         }
   141             {
   128     return err;
   142             iState = EClosed;
       
   143             }
       
   144         
       
   145         return err;
       
   146         }
       
   147     
       
   148     iState = EClosed;
       
   149     
       
   150     return KErrNone;
   129     }
   151     }
   130 
   152 
   131 
   153 
   132 // ======== MEMBER FUNCTIONS ========
   154 // ======== MEMBER FUNCTIONS ========
   133 
   155 
   165         {
   187         {
   166         delete iDiskFullNotifier;
   188         delete iDiskFullNotifier;
   167         iDiskFullNotifier = NULL;
   189         iDiskFullNotifier = NULL;
   168         }
   190         }
   169 
   191 
   170     if(!iServer->IsFormatting())
       
   171         {
       
   172  	    FlushCacheTable( ETrue );
       
   173         }
       
   174     if( iAutoFlushTimer )
   192     if( iAutoFlushTimer )
   175         {
   193         {
   176         iAutoFlushTimer->Cancel();
   194         iAutoFlushTimer->Cancel();
   177         delete iAutoFlushTimer;
   195         delete iAutoFlushTimer;
   178         iAutoFlushTimer = NULL;
   196         iAutoFlushTimer = NULL;
   179         }
   197         }
   180     
   198     
       
   199     if( iMaintenanceTimer )
       
   200         {
       
   201         iMaintenanceTimer->Cancel();
       
   202         delete iMaintenanceTimer;
       
   203         iMaintenanceTimer = NULL;
       
   204         }
       
   205     
       
   206     if(!iServer->IsFormatting())
       
   207         {
       
   208  	    FlushCacheTable( ETrue );
       
   209         }
       
   210     
   181     CloseStatements();   
   211     CloseStatements();   
   182     iDatabase.Close();
   212     iDatabase.Close();
   183     
   213     
   184     TN_DEBUG1( "CThumbnailStore::~CThumbnailStore() - database closed" );
   214     TN_DEBUG1( "CThumbnailStore::~CThumbnailStore() - database closed" );
   185     }
   215     }
   189 // C++ default constructor can NOT contain any code, that might leave.
   219 // C++ default constructor can NOT contain any code, that might leave.
   190 // ---------------------------------------------------------------------------
   220 // ---------------------------------------------------------------------------
   191 //
   221 //
   192 CThumbnailStore::CThumbnailStore( RFs& aFs, TInt aDrive, TDesC& aImei, CThumbnailServer* aServer ): 
   222 CThumbnailStore::CThumbnailStore( RFs& aFs, TInt aDrive, TDesC& aImei, CThumbnailServer* aServer ): 
   193     iFs( aFs ), iDrive( aDrive ), iDriveChar( 0 ), iBatchItemCount(0), iImei(aImei), 
   223     iFs( aFs ), iDrive( aDrive ), iDriveChar( 0 ), iBatchItemCount(0), iImei(aImei), 
   194     iServer(aServer), iDiskFull(EFalse), iUnrecoverable(ETrue)
   224     iServer(aServer), iDiskFull(EFalse), iUnrecoverable(ETrue), iBatchFlushItemCount(KMInBatchItems)
   195     {
   225     {
   196     // no implementation required
   226     // no implementation required
   197     }
   227     }
   198 
   228 
   199 // ---------------------------------------------------------------------------
   229 // ---------------------------------------------------------------------------
   291             if(checkError == KErrNone)
   321             if(checkError == KErrNone)
   292                 {
   322                 {
   293                 checkError = CheckRowIDs();
   323                 checkError = CheckRowIDs();
   294                 }
   324                 }
   295             }
   325             }
   296         else
   326 
   297             {
   327         // if db file not found, wrong version, corrupted database or other error opening db
   298             // if db file not found, wrong version, corrupted database or other error opening db
   328         if ( err != KErrNone || checkError == KErrNotSupported )
   299             if ( checkError == KErrNotSupported || err != KErrNone )
   329             {
   300                 {
   330             CleanupClosePushL(iDatabase);
   301                 CleanupClosePushL(iDatabase);
   331             RecreateDatabaseL(ETrue);
   302                 RecreateDatabaseL(ETrue);
   332             CleanupStack::Pop(&iDatabase);
   303                 CleanupStack::Pop(&iDatabase);
   333             
   304                 
   334             aNewDatabase = ETrue;
   305                 aNewDatabase = ETrue;
   335             }          
   306                 }
       
   307             }
       
   308         }    
   336         }    
   309    
   337    
   310     // opened existing database file
   338     // opened existing database file
   311     if(!aNewDatabase)
   339     if(!aNewDatabase)
   312         {       
   340         {       
   317         imeiError = CheckImei();
   345         imeiError = CheckImei();
   318        
   346        
   319         if(imeiError != KErrNone)
   347         if(imeiError != KErrNone)
   320             {
   348             {
   321             //take ownership
   349             //take ownership
   322             imeiError = UpdateImeiL();
   350             TRAP(imeiError, UpdateImeiL() );
   323             
   351             
   324             //Touch blacklisted items
   352             //Touch blacklisted items
   325             TRAP(blistError, PrepareBlacklistedItemsForRetryL() );
   353             TRAP(blistError, PrepareBlacklistedItemsForRetryL() );
   326             }
   354             }
   327        
   355        
   330             {
   358             {
   331             //Touch blacklisted items
   359             //Touch blacklisted items
   332             TRAP(blistError2, PrepareBlacklistedItemsForRetryL() );
   360             TRAP(blistError2, PrepareBlacklistedItemsForRetryL() );
   333             }
   361             }
   334         
   362         
   335         if(imeiError == KSqlErrCorrupt || imeiError == KErrCorrupt ||
   363         if(imeiError != KErrNone || blistError != KErrNone || blistError2 != KErrNone )
   336            blistError == KSqlErrCorrupt || blistError == KErrCorrupt || 
       
   337            blistError2 == KSqlErrCorrupt || blistError2 == KErrCorrupt )
       
   338             {
   364             {
   339             CleanupClosePushL(iDatabase);
   365             CleanupClosePushL(iDatabase);
   340             RecreateDatabaseL(ETrue);
   366             RecreateDatabaseL(ETrue);
   341             CleanupStack::Pop(&iDatabase);
   367             CleanupStack::Pop(&iDatabase);
   342             }
   368             }
   743 
   769 
   744 // -----------------------------------------------------------------------------
   770 // -----------------------------------------------------------------------------
   745 // UpdateImeiL()
   771 // UpdateImeiL()
   746 // -----------------------------------------------------------------------------
   772 // -----------------------------------------------------------------------------
   747 //
   773 //
   748 TInt CThumbnailStore::UpdateImeiL()
   774 void CThumbnailStore::UpdateImeiL()
   749     {
   775     {
   750     TN_DEBUG1( "CThumbnailStore::UpdateImeiL()" );
   776     TN_DEBUG1( "CThumbnailStore::UpdateImeiL()" );
   751     RSqlStatement stmt;
   777     RSqlStatement stmt;
   752     CleanupClosePushL( stmt );
   778     CleanupClosePushL( stmt );
   753             
   779             
   754     TInt ret = stmt.Prepare( iDatabase, KThumbnailUpdateIMEI );
   780     User::LeaveIfError( stmt.Prepare( iDatabase, KThumbnailUpdateIMEI ) );
   755     
   781     
   756     TInt paramIndex = stmt.ParameterIndex( KThumbnailSqlParamImei );
   782     TInt paramIndex = stmt.ParameterIndex( KThumbnailSqlParamImei );
   757     User::LeaveIfError( paramIndex );
   783     User::LeaveIfError( paramIndex );
   758     User::LeaveIfError( stmt.BindText( paramIndex, iImei ));
   784     User::LeaveIfError( stmt.BindText( paramIndex, iImei ));
   759     
   785     
   760     TInt err =  stmt.Exec();
   786     TInt err = stmt.Exec();
   761     
   787     
   762     if(err < 0)
   788     if(err < 0)
   763         {
   789         {
   764 #ifdef _DEBUG
   790 #ifdef _DEBUG
   765         TPtrC errorMsg2 = iDatabase.LastErrorMessage();
   791         TPtrC errorMsg = iDatabase.LastErrorMessage();
   766         TN_DEBUG2( "RThumbnailTransaction::ResetThumbnailIDs() lastError %S, ret = %d" , &errorMsg2);
   792         TN_DEBUG2( "RThumbnailTransaction::UpdateImeiL() lastError %S" , &errorMsg);
   767 #endif
   793 #endif
   768         return ret;
   794         User::Leave(err);
   769         }
   795         }
   770     
   796     
   771     CleanupStack::PopAndDestroy( &stmt );
   797     CleanupStack::PopAndDestroy( &stmt );
   772     return KErrNone;
       
   773     }
   798     }
   774 
   799 
   775 // ---------------------------------------------------------------------------
   800 // ---------------------------------------------------------------------------
   776 // CThumbnailStore::PrepareStatementsL()
   801 // CThumbnailStore::PrepareStatementsL()
   777 // ---------------------------------------------------------------------------
   802 // ---------------------------------------------------------------------------
   955     
   980     
   956     err = iStmt_KThumbnailSelectAllPaths.Prepare( iDatabase, KThumbnailSelectAllPaths );
   981     err = iStmt_KThumbnailSelectAllPaths.Prepare( iDatabase, KThumbnailSelectAllPaths );
   957 #ifdef _DEBUG
   982 #ifdef _DEBUG
   958     msg.Append( iDatabase.LastErrorMessage() );
   983     msg.Append( iDatabase.LastErrorMessage() );
   959     TN_DEBUG2( "CThumbnailStore::PrepareStatementsL() KThumbnailSelectAllPaths %S" , &msg );
   984     TN_DEBUG2( "CThumbnailStore::PrepareStatementsL() KThumbnailSelectAllPaths %S" , &msg );
       
   985     msg.Zero();
       
   986 #endif
       
   987     User::LeaveIfError( err );
       
   988     
       
   989     err = iStmt_KThumbnailRename.Prepare( iDatabase, KThumbnailRename );
       
   990 #ifdef _DEBUG
       
   991     msg.Append( iDatabase.LastErrorMessage() );
       
   992     TN_DEBUG2( "CThumbnailStore::PrepareStatementsL() KThumbnailRename %S" , &msg );
       
   993     msg.Zero();
       
   994 #endif
       
   995     User::LeaveIfError( err );
       
   996     
       
   997     err = iStmt_KThumbnailTempRename.Prepare( iDatabase, KThumbnailTempRename );
       
   998 #ifdef _DEBUG
       
   999     msg.Append( iDatabase.LastErrorMessage() );
       
  1000     TN_DEBUG2( "CThumbnailStore::PrepareStatementsL() KThumbnailTempRename %S" , &msg );
   960     msg.Zero();
  1001     msg.Zero();
   961 #endif
  1002 #endif
   962     User::LeaveIfError( err );
  1003     User::LeaveIfError( err );
   963     
  1004     
   964     TN_DEBUG1("CThumbnailStore::PrepareStatementsL() end");
  1005     TN_DEBUG1("CThumbnailStore::PrepareStatementsL() end");
  1003     iStmt_KThumbnailSqlInsertDeleted.Close();
  1044     iStmt_KThumbnailSqlInsertDeleted.Close();
  1004     iStmt_KThumbnailSqlSelectMarked.Close();
  1045     iStmt_KThumbnailSqlSelectMarked.Close();
  1005     iStmt_KThumbnailSqlDeleteInfoByRowID.Close();
  1046     iStmt_KThumbnailSqlDeleteInfoByRowID.Close();
  1006     iStmt_KThumbnailSqlDeleteInfoDataByRowID.Close();
  1047     iStmt_KThumbnailSqlDeleteInfoDataByRowID.Close();
  1007     iStmt_KThumbnailSelectAllPaths.Close();
  1048     iStmt_KThumbnailSelectAllPaths.Close();
       
  1049     iStmt_KThumbnailRename.Close();
       
  1050     iStmt_KThumbnailTempRename.Close();
  1008     
  1051     
  1009     TN_DEBUG1("CThumbnailStore::CloseStatements() end");
  1052     TN_DEBUG1("CThumbnailStore::CloseStatements() end");
  1010     }
  1053     }
  1011 
  1054 
  1012 // ---------------------------------------------------------------------------
  1055 // ---------------------------------------------------------------------------
  1345         TN_DEBUG1( "CThumbnailStore::FindDuplicateL() - duplicate in temp table" );
  1388         TN_DEBUG1( "CThumbnailStore::FindDuplicateL() - duplicate in temp table" );
  1346         
  1389         
  1347         found = ETrue;
  1390         found = ETrue;
  1348         }
  1391         }
  1349     
  1392     
       
  1393     CleanupStack::PopAndDestroy( stmt );
       
  1394     
  1350     // check if duplicate in Deleted
  1395     // check if duplicate in Deleted
  1351     if (found)
  1396     if (found)
  1352         {
  1397         {
  1353         CleanupStack::PopAndDestroy( stmt );
       
  1354         stmt = &iStmt_KThumbnailSqlFindDeleted;
  1398         stmt = &iStmt_KThumbnailSqlFindDeleted;
  1355         CleanupStack::PushL(TCleanupItem(ResetStatement, stmt));   
  1399         CleanupStack::PushL(TCleanupItem(ResetStatement, stmt));   
  1356             
  1400             
  1357         paramIndex = stmt->ParameterIndex( KThumbnailSqlParamPath );
  1401         paramIndex = stmt->ParameterIndex( KThumbnailSqlParamPath );
  1358         User::LeaveIfError( paramIndex );
  1402         User::LeaveIfError( paramIndex );
  1359         User::LeaveIfError( stmt->BindText( paramIndex, aPath ));
  1403         User::LeaveIfError( stmt->BindText( paramIndex, aPath ));
  1360         
  1404         
  1361         rowStatus = stmt->Next();
  1405         rowStatus = stmt->Next();
       
  1406         
       
  1407         CleanupStack::PopAndDestroy( stmt );
  1362         
  1408         
  1363         if(rowStatus == KSqlAtRow)
  1409         if(rowStatus == KSqlAtRow)
  1364             {
  1410             {
  1365             TN_DEBUG1( "CThumbnailStore::FindDuplicateL() - duplicate marked deleted" );
  1411             TN_DEBUG1( "CThumbnailStore::FindDuplicateL() - duplicate marked deleted" );
  1366             
  1412             
  1369             TN_DEBUG1( "CThumbnailStore::FindDuplicateL() - duplicate force-deleted" );
  1415             TN_DEBUG1( "CThumbnailStore::FindDuplicateL() - duplicate force-deleted" );
  1370             
  1416             
  1371             found = EFalse;
  1417             found = EFalse;
  1372             }
  1418             }
  1373         }
  1419         }
  1374     
       
  1375     CleanupStack::PopAndDestroy( stmt );
       
  1376     
  1420     
  1377     return found;
  1421     return found;
  1378     }
  1422     }
  1379 
  1423 
  1380 // ---------------------------------------------------------------------------
  1424 // ---------------------------------------------------------------------------
  1693         User::LeaveIfError( stmt->BindText( paramIndex, *path ));
  1737         User::LeaveIfError( stmt->BindText( paramIndex, *path ));
  1694        
  1738        
  1695         rowStatus = stmt->Next();   
  1739         rowStatus = stmt->Next();   
  1696         }
  1740         }
  1697     
  1741     
       
  1742     CleanupStack::PopAndDestroy( stmt_infodata );
       
  1743     CleanupStack::PopAndDestroy( stmt_info );
  1698     CleanupStack::PopAndDestroy( stmt );
  1744     CleanupStack::PopAndDestroy( stmt );
  1699     CleanupStack::PopAndDestroy( stmt_info );
  1745         
  1700     CleanupStack::PopAndDestroy( stmt_infodata );
       
  1701     
       
  1702     // if forcing instant delete
  1746     // if forcing instant delete
  1703     if (aForce)
  1747     if (aForce)
  1704         {
  1748         {
  1705         //look from real table 
  1749         //look from real table 
  1706         TN_DEBUG1( "CThumbnailStore::DeleteThumbnailByPathL() -- MAIN TABLE lookup" );
  1750         TN_DEBUG1( "CThumbnailStore::DeleteThumbnailByPathL() -- MAIN TABLE lookup" );
  1742             rowStatus = stmt->Next();
  1786             rowStatus = stmt->Next();
  1743             }
  1787             }
  1744         
  1788         
  1745         CleanupStack::PopAndDestroy( stmt_infodata );
  1789         CleanupStack::PopAndDestroy( stmt_infodata );
  1746         CleanupStack::PopAndDestroy( stmt_info );
  1790         CleanupStack::PopAndDestroy( stmt_info );
       
  1791         CleanupStack::PopAndDestroy( stmt );
       
  1792         
       
  1793 		//remove delete mark
       
  1794         User::LeaveIfError( iDatabase.Exec( KThumbnailSqlDeleteFromDeleted ) );
  1747         } 
  1795         } 
  1748     else
  1796     else
  1749         {
  1797         {
       
  1798         TN_DEBUG1( "CThumbnailStore::DeleteThumbnailByPathL() -- add to Deleted" );
       
  1799     
  1750         // only add path to deleted table
  1800         // only add path to deleted table
  1751         stmt = &iStmt_KThumbnailSqlInsertDeleted;
  1801         stmt = &iStmt_KThumbnailSqlInsertDeleted;
  1752         CleanupStack::PushL(TCleanupItem(ResetStatement, stmt));
  1802         CleanupStack::PushL(TCleanupItem(ResetStatement, stmt));
  1753         
  1803         
  1754         paramIndex = stmt->ParameterIndex( KThumbnailSqlParamPath );
  1804         paramIndex = stmt->ParameterIndex( KThumbnailSqlParamPath );
  1755         User::LeaveIfError( paramIndex );
  1805         User::LeaveIfError( paramIndex );
  1756         User::LeaveIfError( stmt->BindText( paramIndex, *path ));
  1806         User::LeaveIfError( stmt->BindText( paramIndex, *path ));
  1757         
  1807         
  1758         count = stmt->Exec();
  1808         count = stmt->Exec();
  1759         }
  1809         
  1760     
  1810         CleanupStack::PopAndDestroy( stmt );
  1761     CleanupStack::PopAndDestroy( stmt );    
  1811         }    
  1762     
  1812     
  1763     if (aTransaction)
  1813     if (aTransaction)
  1764         {
  1814         {
  1765         transaction.CommitL();
  1815         transaction.CommitL();
  1766         CleanupStack::PopAndDestroy( &transaction );
  1816         CleanupStack::PopAndDestroy( &transaction );
  1781         }
  1831         }
  1782     
  1832     
  1783     CleanupStack::PopAndDestroy( path );
  1833     CleanupStack::PopAndDestroy( path );
  1784     }
  1834     }
  1785 
  1835 
       
  1836 // -----------------------------------------------------------------------------
       
  1837 // Rename thumbnails
       
  1838 // -----------------------------------------------------------------------------
       
  1839 //
       
  1840 void CThumbnailStore::RenameThumbnailsL( const TDesC& aCurrentPath, const TDesC& aNewPath )
       
  1841     {
       
  1842     TN_DEBUG2( "CThumbnailStore::RenameThumbnailsL(%S)", &aCurrentPath );
       
  1843     
       
  1844 #ifdef _DEBUG
       
  1845     TTime aStart, aStop;
       
  1846     aStart.UniversalTime();
       
  1847 #endif
       
  1848     
       
  1849     User::LeaveIfError( CheckDbState() );
       
  1850     
       
  1851     TInt paramIndex = 0;
       
  1852 
       
  1853     HBufC* path = aCurrentPath.AllocLC();
       
  1854     TPtr ptr(path->Des());
       
  1855     StripDriveLetterL( ptr );
       
  1856     
       
  1857     HBufC* newPath = aNewPath.AllocLC();
       
  1858     TPtr ptr2(newPath->Des());
       
  1859     StripDriveLetterL( ptr2 );
       
  1860     
       
  1861     RThumbnailTransaction transaction( iDatabase );
       
  1862     CleanupClosePushL( transaction );    
       
  1863     transaction.BeginL();
       
  1864         
       
  1865     TN_DEBUG1( "CThumbnailStore::RenameThumbnailsL() -- TEMP TABLE" );
       
  1866     
       
  1867     RSqlStatement* stmt = NULL;
       
  1868     stmt = &iStmt_KThumbnailTempRename;
       
  1869     CleanupStack::PushL(TCleanupItem(ResetStatement, stmt));
       
  1870     
       
  1871     paramIndex = stmt->ParameterIndex( KThumbnailSqlParamPath );
       
  1872     User::LeaveIfError( paramIndex );
       
  1873     User::LeaveIfError( stmt->BindText( paramIndex, *path ));
       
  1874     
       
  1875     paramIndex = stmt->ParameterIndex( KThumbnailSqlParamNewPath );
       
  1876     User::LeaveIfError( paramIndex );
       
  1877     User::LeaveIfError( stmt->BindText( paramIndex, *newPath ));
       
  1878     
       
  1879     User::LeaveIfError( stmt->Exec() );
       
  1880     
       
  1881     TN_DEBUG1( "CThumbnailStore::RenameThumbnailsL() -- MAIN TABLE" );
       
  1882     
       
  1883     CleanupStack::PopAndDestroy( stmt );
       
  1884     stmt = &iStmt_KThumbnailRename;
       
  1885     CleanupStack::PushL(TCleanupItem(ResetStatement, stmt));
       
  1886     
       
  1887     paramIndex = stmt->ParameterIndex( KThumbnailSqlParamPath );
       
  1888     User::LeaveIfError( paramIndex );
       
  1889     User::LeaveIfError( stmt->BindText( paramIndex, *path ));
       
  1890     
       
  1891     paramIndex = stmt->ParameterIndex( KThumbnailSqlParamNewPath );
       
  1892     User::LeaveIfError( paramIndex );
       
  1893     User::LeaveIfError( stmt->BindText( paramIndex, *newPath ));
       
  1894     
       
  1895     User::LeaveIfError( stmt->Exec() );
       
  1896     
       
  1897     CleanupStack::PopAndDestroy( stmt );
       
  1898     
       
  1899     // if thumb was for some reason already marked deleted, clean from deleted
       
  1900     User::LeaveIfError( iDatabase.Exec( KThumbnailSqlDeleteFromDeleted ) );
       
  1901     
       
  1902     transaction.CommitL();
       
  1903     CleanupStack::PopAndDestroy( &transaction );
       
  1904     
       
  1905     CleanupStack::PopAndDestroy( newPath );
       
  1906     CleanupStack::PopAndDestroy( path );
       
  1907     
       
  1908 #ifdef _DEBUG
       
  1909     aStop.UniversalTime();
       
  1910     TN_DEBUG2( "CThumbnailStore::RenameThumbnailsL() took %d ms", (TInt)aStop.MicroSecondsFrom(aStart).Int64()/1000);
       
  1911 #endif      
       
  1912     }
       
  1913 
  1786 // ---------------------------------------------------------------------------
  1914 // ---------------------------------------------------------------------------
  1787 // CThumbnailStore::PersistentSizes()
  1915 // CThumbnailStore::PersistentSizes()
  1788 // ---------------------------------------------------------------------------
  1916 // ---------------------------------------------------------------------------
  1789 //
  1917 //
  1790 void CThumbnailStore::SetPersistentSizes(const RArray < TThumbnailPersistentSize > &aSizes)
  1918 void CThumbnailStore::SetPersistentSizes(const RArray < TThumbnailPersistentSize > &aSizes)
  1806         {
  1934         {
  1807         // cache empty or db unusable
  1935         // cache empty or db unusable
  1808         return;
  1936         return;
  1809         }
  1937         }
  1810     
  1938     
  1811     if(iBatchItemCount < KMaxBatchItems && !aForce)
  1939     // fixed batch size if MTP sync on
       
  1940     TInt MPXHarvesting(0);
       
  1941     TInt ret = RProperty::Get(KTAGDPSNotification, KMPXHarvesting, MPXHarvesting);
       
  1942     if(ret != KErrNone)
       
  1943         {
       
  1944         TN_DEBUG2( "CThumbnailStore::FlushCacheTable() error checking MTP sync: %d", ret);
       
  1945         }
       
  1946     
       
  1947     if(MPXHarvesting && iBatchItemCount < KMaxBatchItemsMTP && !aForce)
       
  1948         {
       
  1949         TN_DEBUG1("CThumbnailStore::FlushCacheTable() MTP sync, fixed batch...");
       
  1950     
       
  1951         //some items in cache
       
  1952         StartAutoFlush();
       
  1953         return;
       
  1954         }    
       
  1955     else if(!MPXHarvesting && iBatchItemCount < iBatchFlushItemCount && !aForce)
  1812        {
  1956        {
  1813        //some items in cache
  1957        //some items in cache
  1814        StartAutoFlush();
  1958        StartAutoFlush();
  1815        return;
  1959        return;
  1816        }
  1960        }    
  1817     
  1961     
  1818 #ifdef _DEBUG
  1962     iStartFlush.UniversalTime();
  1819     TTime aStart, aStop;
       
  1820     aStart.UniversalTime();
       
  1821 #endif
       
  1822     
  1963     
  1823     // Move data from temp table to main....
  1964     // Move data from temp table to main....
  1824     TInt err_begin = iDatabase.Exec( KThumbnailBeginTransaction );
  1965     TInt err_begin = iDatabase.Exec( KThumbnailBeginTransaction );
  1825     TN_DEBUG2("CThumbnailStore::FlushCacheTable() KThumbnailBeginTransaction %d", err_begin);
  1966     TN_DEBUG2("CThumbnailStore::FlushCacheTable() KThumbnailBeginTransaction %d", err_begin);
  1826     
  1967     
  1869         TN_DEBUG1("CThumbnailStore::FlushCacheTable() db corrupted");
  2010         TN_DEBUG1("CThumbnailStore::FlushCacheTable() db corrupted");
  1870     
  2011     
  1871         // open new
  2012         // open new
  1872         TRAP_IGNORE(OpenDatabaseL(ETrue));
  2013         TRAP_IGNORE(OpenDatabaseL(ETrue));
  1873         }
  2014         }
       
  2015    
       
  2016     iStopFlush.UniversalTime();
       
  2017     TInt aFlushDelay = (TInt)iStopFlush.MicroSecondsFrom(iStartFlush).Int64()/1000;
       
  2018     
       
  2019     TN_DEBUG2( "CThumbnailStore::FlushCacheTable() took %d ms", aFlushDelay);
       
  2020     
       
  2021     //adjust batch size dynamically between min and max based on read flush speed
       
  2022     if (!MPXHarvesting)
       
  2023         {
       
  2024         //increase batch count if there room for one more item (based on average time per item)
       
  2025         if( aFlushDelay < KMaxFlushDelay && iBatchFlushItemCount < KMaxBatchItems )
       
  2026             {
       
  2027             iBatchFlushItemCount++;
       
  2028             }
       
  2029         //decrease batch count if we exeeced max time allowed in flushing the TEMP table
       
  2030         else if(aFlushDelay > KMaxFlushDelay && iBatchFlushItemCount > KMInBatchItems )
       
  2031             {
       
  2032             iBatchFlushItemCount--;
       
  2033             }
       
  2034         }
  1874     
  2035     
  1875     //cache flushed
  2036     //cache flushed
  1876     iBatchItemCount = 0;
  2037     iBatchItemCount = 0;
  1877     
  2038 
  1878 #ifdef _DEBUG
  2039     TN_DEBUG2("CThumbnailStore::FlushCacheTable() out iBatchFlushItemCount = %d", iBatchFlushItemCount);
  1879     aStop.UniversalTime();
       
  1880     TN_DEBUG2( "CThumbnailStore::FlushCacheTable() took %d ms", (TInt)aStop.MicroSecondsFrom(aStart).Int64()/1000);
       
  1881 #endif
       
  1882 
       
  1883     TN_DEBUG1("CThumbnailStore::FlushCacheTable() out");
       
  1884     }
  2040     }
  1885 
  2041 
  1886 // -----------------------------------------------------------------------------
  2042 // -----------------------------------------------------------------------------
  1887 // StartAutoFlush()
  2043 // StartAutoFlush()
  1888 // -----------------------------------------------------------------------------
  2044 // -----------------------------------------------------------------------------
  2045         // next round
  2201         // next round
  2046         if (self->iIdle && ( self->iDeleteThumbs || self->iCheckFilesExist) )
  2202         if (self->iIdle && ( self->iDeleteThumbs || self->iCheckFilesExist) )
  2047             {
  2203             {
  2048             self->StartMaintenance();
  2204             self->StartMaintenance();
  2049             }  
  2205             }  
  2050         else
  2206         else if (!self->iDeleteThumbs && !self->iCheckFilesExist)
  2051             {
  2207             {
  2052             // no need to monitor activity anymore
  2208             // no need to monitor activity anymore
  2053             self->iActivityManager->Cancel();
  2209             self->iActivityManager->Cancel();
  2054             }
  2210             }
  2055         }
  2211         }