33 #include "thumbnailpanic.h" |
33 #include "thumbnailpanic.h" |
34 #include "thumbnailmanagerconstants.h" |
34 #include "thumbnailmanagerconstants.h" |
35 #include "thumbnailserver.h" |
35 #include "thumbnailserver.h" |
36 |
36 |
37 |
37 |
38 _LIT8( KThumbnailSqlConfig, "page_size=32768; cache_size=32;" ); |
38 _LIT8( KThumbnailSqlConfig, "page_size=32768; cache_size=64;" ); |
39 |
39 |
40 const TInt KStreamBufferSize = 1024 * 8; |
40 const TInt KStreamBufferSize = 1024 * 8; |
41 const TInt KMajor = 3; |
41 const TInt KMajor = 3; |
42 const TInt KMinor = 2; |
42 const TInt KMinor = 2; |
43 |
43 |
297 // --------------------------------------------------------------------------- |
297 // --------------------------------------------------------------------------- |
298 TInt CThumbnailStore::OpenDatabaseL( TBool aNewDatabase ) |
298 TInt CThumbnailStore::OpenDatabaseL( TBool aNewDatabase ) |
299 { |
299 { |
300 TN_DEBUG2( "CThumbnailStore::OpenDatabaseL() drive: %d", iDrive ); |
300 TN_DEBUG2( "CThumbnailStore::OpenDatabaseL() drive: %d", iDrive ); |
301 |
301 |
|
302 CloseStatements(); |
302 iDatabase.Close(); |
303 iDatabase.Close(); |
303 iUnrecoverable = ETrue; |
304 iUnrecoverable = ETrue; |
304 |
305 |
305 TInt checkError = KErrNone; |
306 TInt checkError = KErrNone; |
306 TInt blistError = KErrNone; |
307 TInt blistError = KErrNone; |
527 } |
529 } |
528 |
530 |
529 // delete db if not fully complete |
531 // delete db if not fully complete |
530 if (prepareErr < 0 || mediaidErr < 0) |
532 if (prepareErr < 0 || mediaidErr < 0) |
531 { |
533 { |
|
534 CloseStatements(); |
532 iDatabase.Close(); |
535 iDatabase.Close(); |
533 TN_DEBUG1( "CThumbnailStore::RecreateDatabaseL() delete database" ); |
536 TN_DEBUG1( "CThumbnailStore::RecreateDatabaseL() delete database" ); |
534 TInt del = iDatabase.Delete(pathPtr); |
537 TInt del = iDatabase.Delete(pathPtr); |
535 TN_DEBUG2( "CThumbnailStore::RecreateDatabaseL() deleted database, err: %d", del ); |
538 TN_DEBUG2( "CThumbnailStore::RecreateDatabaseL() deleted database, err: %d", del ); |
536 } |
539 } |
1551 |
1554 |
1552 TInt paramIndex = 0; |
1555 TInt paramIndex = 0; |
1553 TInt found = KErrNotFound; |
1556 TInt found = KErrNotFound; |
1554 TInt rowStatus = 0; |
1557 TInt rowStatus = 0; |
1555 TInt column = 0; |
1558 TInt column = 0; |
1556 TBool inTempTable = ETrue; |
|
1557 |
1559 |
1558 TN_DEBUG1( "CThumbnailStore::FetchThumbnailL() -- TEMP TABLE lookup" ); |
1560 TN_DEBUG1( "CThumbnailStore::FetchThumbnailL() -- TEMP TABLE lookup" ); |
1559 |
1561 |
1560 RSqlStatement* stmt = NULL; |
1562 RSqlStatement* stmt = NULL; |
1561 stmt = &iStmt_KThumbnailSelectTempInfoByPath; |
1563 stmt = &iStmt_KThumbnailSelectTempInfoByPath; |
1573 |
1575 |
1574 //if not found from temp table, look from real table |
1576 //if not found from temp table, look from real table |
1575 if(rowStatus != KSqlAtRow) |
1577 if(rowStatus != KSqlAtRow) |
1576 { |
1578 { |
1577 TN_DEBUG1( "CThumbnailStore::FetchThumbnailL() -- MAIN TABLE lookup" ); |
1579 TN_DEBUG1( "CThumbnailStore::FetchThumbnailL() -- MAIN TABLE lookup" ); |
1578 inTempTable = EFalse; |
|
1579 |
1580 |
1580 CleanupStack::PopAndDestroy( stmt ); |
1581 CleanupStack::PopAndDestroy( stmt ); |
1581 stmt = &iStmt_KThumbnailSelectInfoByPath; |
1582 stmt = &iStmt_KThumbnailSelectInfoByPath; |
1582 CleanupStack::PushL(TCleanupItem(ResetStatement, stmt)); |
1583 CleanupStack::PushL(TCleanupItem(ResetStatement, stmt)); |
1583 |
1584 |
1600 // If thumbnail is marked as blacklisted and timestamp has |
1601 // If thumbnail is marked as blacklisted and timestamp has |
1601 // changed, delete thumbnails from tables and leave with |
1602 // changed, delete thumbnails from tables and leave with |
1602 // KErrNotFound to get thumbnail regenerated. |
1603 // KErrNotFound to get thumbnail regenerated. |
1603 column = 4; |
1604 column = 4; |
1604 TInt flags = stmt->ColumnInt( column ); |
1605 TInt flags = stmt->ColumnInt( column ); |
1605 if( flags & KThumbnailDbFlagBlacklisted && (*path).Length() ) |
1606 if( flags & KThumbnailDbFlagDeleted ) |
1606 { |
1607 { |
1607 TBool modified = EFalse; |
1608 CleanupStack::PopAndDestroy( stmt ); |
1608 CheckModifiedByPathL( aPath, inTempTable, modified ); |
1609 |
1609 if( modified ) |
1610 // delete existing blacklisted thumbs |
1610 { |
1611 DeleteThumbnailsL(*path, ETrue); |
1611 // Close db to get deletion of thumbnails executed. |
1612 |
1612 CleanupStack::PopAndDestroy( &stmt ); |
1613 CleanupStack::PopAndDestroy( path ); |
1613 DeleteThumbnailsL( *path ); |
1614 |
1614 User::Leave( KErrNotFound ); |
1615 User::Leave( KErrNotFound ); |
1615 } |
1616 } |
1616 else |
1617 else if( flags & KThumbnailDbFlagBlacklisted ) |
1617 { |
1618 { |
1618 User::Leave( KErrCompletion ); |
1619 CleanupStack::PopAndDestroy( stmt ); |
1619 } |
1620 CleanupStack::PopAndDestroy( path ); |
|
1621 |
|
1622 User::Leave( KErrCompletion ); |
1620 } |
1623 } |
1621 else if( !(flags & KThumbnailDbFlagBlacklisted) ) |
1624 else if( !(flags & KThumbnailDbFlagBlacklisted) ) |
1622 { |
1625 { |
1623 found = KErrNone; |
1626 found = KErrNone; |
1624 column = 0; |
1627 column = 0; |
1797 //remove delete mark |
1800 //remove delete mark |
1798 User::LeaveIfError( iDatabase.Exec( KThumbnailSqlDeleteFromDeleted ) ); |
1801 User::LeaveIfError( iDatabase.Exec( KThumbnailSqlDeleteFromDeleted ) ); |
1799 } |
1802 } |
1800 else |
1803 else |
1801 { |
1804 { |
1802 TN_DEBUG1( "CThumbnailStore::DeleteThumbnailByPathL() -- add to Deleted" ); |
1805 TN_DEBUG1( "CThumbnailStore::DeleteThumbnailByPathL() -- MAIN TABLE lookup" ); |
1803 |
1806 |
1804 // only add path to deleted table |
1807 stmt = &iStmt_KThumbnailSqlSelectRowIDInfoByPath; |
1805 stmt = &iStmt_KThumbnailSqlInsertDeleted; |
|
1806 CleanupStack::PushL(TCleanupItem(ResetStatement, stmt)); |
1808 CleanupStack::PushL(TCleanupItem(ResetStatement, stmt)); |
1807 |
1809 |
1808 paramIndex = stmt->ParameterIndex( KThumbnailSqlParamPath ); |
1810 paramIndex = stmt->ParameterIndex( KThumbnailSqlParamPath ); |
1809 User::LeaveIfError( paramIndex ); |
1811 User::LeaveIfError( paramIndex ); |
1810 User::LeaveIfError( stmt->BindText( paramIndex, *path )); |
1812 User::LeaveIfError( stmt->BindText( paramIndex, *path )); |
1811 |
1813 |
1812 count = stmt->Exec(); |
1814 rowStatus = stmt->Next(); |
1813 |
1815 |
1814 CleanupStack::PopAndDestroy( stmt ); |
1816 CleanupStack::PopAndDestroy( stmt ); |
|
1817 |
|
1818 // there were matching rows in main table |
|
1819 if (rowStatus == KSqlAtRow) |
|
1820 { |
|
1821 TN_DEBUG1( "CThumbnailStore::DeleteThumbnailByPathL() -- add to Deleted" ); |
|
1822 |
|
1823 // only add path to deleted table |
|
1824 stmt = &iStmt_KThumbnailSqlInsertDeleted; |
|
1825 CleanupStack::PushL(TCleanupItem(ResetStatement, stmt)); |
|
1826 |
|
1827 paramIndex = stmt->ParameterIndex( KThumbnailSqlParamPath ); |
|
1828 User::LeaveIfError( paramIndex ); |
|
1829 User::LeaveIfError( stmt->BindText( paramIndex, *path )); |
|
1830 |
|
1831 count = stmt->Exec(); |
|
1832 |
|
1833 CleanupStack::PopAndDestroy( stmt ); |
|
1834 } |
|
1835 else |
|
1836 { |
|
1837 TN_DEBUG1( "CThumbnailStore::DeleteThumbnailByPathL() -- no thumbs in MAIN" ); |
|
1838 } |
1815 } |
1839 } |
1816 |
1840 |
1817 if (aTransaction) |
1841 if (aTransaction) |
1818 { |
1842 { |
1819 transaction.CommitL(); |
1843 transaction.CommitL(); |
1947 { |
1972 { |
1948 TN_DEBUG2( "CThumbnailStore::FlushCacheTable() error checking MTP sync: %d", ret); |
1973 TN_DEBUG2( "CThumbnailStore::FlushCacheTable() error checking MTP sync: %d", ret); |
1949 } |
1974 } |
1950 |
1975 |
1951 //set init max flush delay |
1976 //set init max flush delay |
1952 TInt aMaxFlushDelay(KMaxFlushDelay); |
1977 TReal32 aMaxFlushDelay(KMaxFlushDelay); |
|
1978 TReal32 aPreviousFlushDelay(iPreviousFlushDelay); |
|
1979 TReal32 aBatchFlushItemCount(iBatchFlushItemCount); |
1953 |
1980 |
1954 if(MPXHarvesting) |
1981 if(MPXHarvesting) |
1955 { |
1982 { |
1956 //MTP or MPX harvesting active, allow longer flush -> bigger batch size |
1983 //MTP or MPX harvesting active, allow longer flush -> bigger batch size |
1957 TN_DEBUG1("CThumbnailStore::FlushCacheTable() MTP sync, longer flush.."); |
1984 TN_DEBUG1("CThumbnailStore::FlushCacheTable() MTP sync, longer flush.."); |
1959 } |
1986 } |
1960 |
1987 |
1961 //1st item in batch |
1988 //1st item in batch |
1962 if( iBatchItemCount == 1) |
1989 if( iBatchItemCount == 1) |
1963 { |
1990 { |
|
1991 TN_DEBUG2("CThumbnailStore::FlushCacheTable() calculate new batch size iPreviousFlushDelay = %d", iPreviousFlushDelay); |
1964 //adjust batch size dynamically between min and max based on previous flush speed |
1992 //adjust batch size dynamically between min and max based on previous flush speed |
1965 if(iPreviousFlushDelay > 0 ) |
1993 if( iPreviousFlushDelay > 0 ) |
1966 { |
1994 { |
1967 iBatchFlushItemCount = (aMaxFlushDelay/iPreviousFlushDelay)*iBatchFlushItemCount; |
1995 TReal32 aNewBatchFlushItemCount = aMaxFlushDelay / aPreviousFlushDelay * aBatchFlushItemCount; |
1968 |
1996 iBatchFlushItemCount = (TInt)aNewBatchFlushItemCount; |
1969 if(iBatchFlushItemCount < KMInBatchItems) |
1997 |
|
1998 TN_DEBUG2("CThumbnailStore::FlushCacheTable() aMaxFlushDelay %e", aMaxFlushDelay); |
|
1999 TN_DEBUG2("CThumbnailStore::FlushCacheTable() aPreviousFlushDelay %e", aPreviousFlushDelay); |
|
2000 TN_DEBUG2("CThumbnailStore::FlushCacheTable() aBatchFlushItemCount %e", aBatchFlushItemCount); |
|
2001 TN_DEBUG2("CThumbnailStore::FlushCacheTable() aNewBatchFlushItemCount %e", aNewBatchFlushItemCount); |
|
2002 TN_DEBUG2("CThumbnailStore::FlushCacheTable() iBatchFlushItemCount %d", iBatchFlushItemCount); |
|
2003 |
|
2004 if( iBatchFlushItemCount < KMInBatchItems ) |
1970 { |
2005 { |
1971 iBatchFlushItemCount = KMInBatchItems; |
2006 iBatchFlushItemCount = KMInBatchItems; |
1972 } |
2007 } |
1973 else if(iBatchFlushItemCount > KMaxBatchItems) |
2008 else if( iBatchFlushItemCount > KMaxBatchItems ) |
1974 { |
2009 { |
1975 iBatchFlushItemCount = KMaxBatchItems; |
2010 iBatchFlushItemCount = KMaxBatchItems; |
1976 } |
2011 } |
1977 } |
2012 } |
1978 else |
2013 else |
2201 TBool finished = EFalse; |
2236 TBool finished = EFalse; |
2202 |
2237 |
2203 TRAPD( err, finished = self->FileExistenceCheckL() ); |
2238 TRAPD( err, finished = self->FileExistenceCheckL() ); |
2204 if (err != KErrNone) |
2239 if (err != KErrNone) |
2205 { |
2240 { |
2206 TN_DEBUG2( "CThumbnailStore::MaintenanceTimerCallBack() - file existance check failed, err %d", err); |
2241 TN_DEBUG2( "CThumbnailStore::MaintenanceTimerCallBack() - file existence check failed, err %d", err); |
2207 return err; |
2242 return err; |
2208 } |
2243 } |
2209 |
2244 |
2210 // all files checked. |
2245 // all files checked. |
2211 if (finished) |
2246 if (finished) |
2212 { |
2247 { |
2213 TN_DEBUG2( "CThumbnailStore::MaintenanceTimerCallBack() - file existance check finished, store %d", self->iDrive); |
2248 TN_DEBUG2( "CThumbnailStore::MaintenanceTimerCallBack() - file existence check finished, store %d", self->iDrive); |
2214 self->iCheckFilesExist = EFalse; |
2249 self->iCheckFilesExist = EFalse; |
2215 } |
2250 } |
2216 } |
2251 } |
2217 |
2252 |
2218 // next round |
2253 // next round |
2286 } |
2321 } |
2287 else if (oldModified == aModified) |
2322 else if (oldModified == aModified) |
2288 { |
2323 { |
2289 TN_DEBUG1( "CThumbnailStore::CheckModifiedL() -- timestamp is the same as original" ); |
2324 TN_DEBUG1( "CThumbnailStore::CheckModifiedL() -- timestamp is the same as original" ); |
2290 } |
2325 } |
2291 } |
2326 |
2292 |
2327 rowStatus = stmt->Next(); |
2293 rowStatus = stmt->Next(); |
2328 } |
2294 |
2329 |
2295 //switch to main table if modified not found from temp |
2330 //switch to main table if modified not found from temp |
2296 if(rowStatus != KSqlAtRow && !checkMain && !modifiedChanged) |
2331 if(rowStatus != KSqlAtRow && !checkMain && !modifiedChanged) |
2297 { |
2332 { |
2298 TN_DEBUG1( "CThumbnailStore::CheckModifiedL() -- main" ); |
2333 TN_DEBUG1( "CThumbnailStore::CheckModifiedL() -- main" ); |