emailservices/emailstore/base_plugin/src/baseplugindelayedops.cpp
branchRCL_3
changeset 16 b5fbb9b25d57
parent 14 b13141f05c3d
child 24 d189ee25cf9d
equal deleted inserted replaced
14:b13141f05c3d 16:b5fbb9b25d57
    16 */
    16 */
    17 #include "msgstorewritablepropertycontainer.h"
    17 #include "msgstorewritablepropertycontainer.h"
    18 
    18 
    19 #include "baseplugindelayedops.h"
    19 #include "baseplugindelayedops.h"
    20 #include "baseplugindelayedopsprivate.h"
    20 #include "baseplugindelayedopsprivate.h"
    21 #include "NestedAO.h"
       
    22 
    21 
    23 ///////////////////////////////////////////////////
    22 ///////////////////////////////////////////////////
    24 // CDelayedOp                                    //
    23 // CDelayedOp                                    //
    25 ///////////////////////////////////////////////////
    24 ///////////////////////////////////////////////////
    26 
    25 
    44     } 
    43     } 
    45 
    44 
    46 /**
    45 /**
    47  * 
    46  * 
    48  */
    47  */
       
    48 /*public*/ EXPORT_C void CDelayedOp::StartOp()
       
    49     {
       
    50     iStatus = KRequestPending;
       
    51     SetActive();
       
    52     TRequestStatus* pStatus = &iStatus;
       
    53     User::RequestComplete( pStatus, KErrNone );
       
    54     } 
       
    55 
       
    56 /**
       
    57  * 
       
    58  */
    49 /*protected*/ EXPORT_C CDelayedOp::CDelayedOp()
    59 /*protected*/ EXPORT_C CDelayedOp::CDelayedOp()
    50     : CAsyncOneShot( CActive::EPriorityIdle )
    60     : CActive( CActive::EPriorityIdle )
    51     {    
    61     {    
       
    62     CActiveScheduler::Add( this );
    52     }
    63     }
    53     
    64     
    54 /**
    65 /**
    55  * 
    66  * 
    56  */
    67  */
    57 /*private virtual*/ EXPORT_C void CDelayedOp::RunL()
    68 /*private virtual*/ EXPORT_C void CDelayedOp::RunL()
    58     {
    69     {
    59     __LOG_ENTER_SUPPRESS( "Run" );
    70     __LOG_ENTER_SUPPRESS( "Run" );
    60     TRAPD( err, ExecuteOpL() );
    71     TBool again( EFalse );
       
    72     
       
    73     TRAPD( err, again = ExecuteOpL() );
    61     
    74     
    62     if ( KErrNone != err )
    75     if ( KErrNone != err )
    63         {
    76         {
    64         __LOG_WRITE8_FORMAT1_INFO(
    77         __LOG_WRITE8_FORMAT1_INFO(
    65             "Error while executing delayed operation: %d.", err );
    78             "Error while executing delayed operation: %d.", err );
    66         }
    79         }
    67     
    80     
    68     //self-destroy.
    81     if ( again )
    69     iManager->DequeueOp( *this );
    82         {
    70     delete this;
    83         StartOp();
       
    84         }
       
    85     else
       
    86         {
       
    87         //self-destroy.
       
    88         iManager->DequeueOp( *this );
       
    89         delete this;
       
    90         }
    71     }
    91     }
    72     
    92     
    73 /**
    93 /**
    74  * 
    94  * 
    75  */
    95  */
   121  */
   141  */
   122 /*public virtual*/ void CDelayedOpsManager::EnqueueOpL( CDelayedOp* aOp )
   142 /*public virtual*/ void CDelayedOpsManager::EnqueueOpL( CDelayedOp* aOp )
   123     {
   143     {
   124     iDelayedOps.AppendL( aOp );
   144     iDelayedOps.AppendL( aOp );
   125     aOp->SetContext( iPlugin, *this );        
   145     aOp->SetContext( iPlugin, *this );        
   126     aOp->Call();
   146     aOp->StartOp();
   127     }
   147     }
   128     
   148     
   129 /**
   149 /**
   130  * 
   150  * 
   131  */
   151  */
   229     }
   249     }
   230 
   250 
   231 /**
   251 /**
   232  * 
   252  * 
   233  */
   253  */
   234 /*public virtual*/TBool CDelayedDeleteMessagesOp::DeleteMessagesInChunksL( TInt aStartIndex )
   254 /*private*/
   235     {
   255 void CDelayedDeleteMessagesOp::ConstructL(
   236     __LOG_ENTER( "DeleteMessagesInChunksL" );
   256     const RArray<TFSMailMsgId>& aMessages )
   237     TBool done=EFalse;
   257     {
   238     TInt endIndex;
   258     __LOG_CONSTRUCT( "baseplugin", "CDelayedDeleteMessagesOp" );
   239     if( aStartIndex + KSizeOfChunk < iMessages.Count() )
   259             
   240         {
   260     TInt count = aMessages.Count();
   241             endIndex = aStartIndex + KSizeOfChunk;
   261     for ( TInt i = 0; i < count; ++i )
   242         }
   262         {
   243     else
   263         iMessages.AppendL( aMessages[i].Id() );
       
   264         }
       
   265     }
       
   266 
       
   267 /**
       
   268  * 
       
   269  */
       
   270 /*private*/
       
   271 void CDelayedDeleteMessagesOp::ConstructL(
       
   272     TMsgStoreId aMsgId )
       
   273     {
       
   274     __LOG_CONSTRUCT( "baseplugin", "CDelayedDeleteMessagesOp" );
       
   275     iImmediateDelete = ETrue;
       
   276     iMessages.AppendL( aMsgId );
       
   277     }
       
   278 
       
   279 /**
       
   280  * 
       
   281  */
       
   282 /*private*/ CDelayedDeleteMessagesOp::CDelayedDeleteMessagesOp(
       
   283     TMsgStoreId aMailBoxId,
       
   284     TMsgStoreId aFolderId )
       
   285     :
       
   286     iMailBoxId( aMailBoxId ), iFolderId( aFolderId )
       
   287     {
       
   288     }
       
   289 
       
   290 /**
       
   291  * 
       
   292  */
       
   293 /*private*/ TBool CDelayedDeleteMessagesOp::ExecuteOpL()
       
   294     {
       
   295     __LOG_ENTER( "ExecuteOpL" );
       
   296 
       
   297     //Maximum number of messages deleted in one go
       
   298     const TInt KNumOfDeletesBeforeYield = 30;
       
   299 
       
   300     TBool runAgain = ETrue;
       
   301     TInt  endIndex = iIndex + KNumOfDeletesBeforeYield;
       
   302 
       
   303     if( endIndex >= iMessages.Count() )
   244         {
   304         {
   245         endIndex = iMessages.Count();   
   305         endIndex = iMessages.Count();   
   246         done=ETrue;
   306         runAgain = EFalse;  // last time, no need to run again.
   247         }
   307         }
   248     CMailboxInfo& mailBoxInfo
   308 
   249         = GetPlugin().GetMailboxInfoL( iMailBoxId );
   309     CMailboxInfo& mailBoxInfo = GetPlugin().GetMailboxInfoL( iMailBoxId );
   250     CMsgStoreMailBox& mailBox = mailBoxInfo();
   310     CMsgStoreMailBox& mailBox = mailBoxInfo();
   251 
   311 
   252     for ( TInt i = aStartIndex; i < endIndex; ++i )
   312     for ( ; iIndex < endIndex; iIndex++ )
   253         {
   313         {
   254         TMsgStoreId msgId = iMessages[i];
   314         TMsgStoreId msgId = iMessages[iIndex];
   255         
   315         
   256         if ( EFalse == iImmediateDelete )
   316         if ( EFalse == iImmediateDelete )
   257             {
   317             {
   258             //try to find the message in the deleted items folder.
   318             //try to find the message in the deleted items folder.
   259             CMsgStoreMessage* theMessage = NULL;
   319             CMsgStoreMessage* theMessage = NULL;
   260             TRAP_IGNORE( theMessage = mailBox.FetchMessageL(
   320             TRAP_IGNORE( theMessage = mailBox.FetchMessageL(
   261               msgId, mailBoxInfo.iRootFolders.iFolders[EFSDeleted] ) );
   321                     msgId, mailBoxInfo.iRootFolders.iFolders[ EFSDeleted ] ) );
   262             
   322             
   263             if ( NULL == theMessage )
   323             if ( NULL == theMessage )
   264                 {
   324                 {
   265                 //if not in deleted items then move it there.
   325                 //if not in deleted items then move it there.
   266                 __LOG_WRITE8_FORMAT1_INFO("Moving message 0x%X to the deleted items.", msgId );
   326                 __LOG_WRITE8_FORMAT1_INFO("Moving message 0x%X to the deleted items.", msgId );
   267                 mailBox.MoveMessageL(
   327                 mailBox.MoveMessageL( msgId, KMsgStoreInvalidId,
   268                    msgId, KMsgStoreInvalidId,
   328                                       mailBoxInfo.iRootFolders.iFolders[ EFSDeleted ] );
   269                    mailBoxInfo.iRootFolders.iFolders[EFSDeleted] );
       
   270                 }
   329                 }
   271             else
   330             else
   272                 {
   331                 {
   273                 //in deleted items, really delete it.
   332                 //in deleted items, really delete it.
   274                 __LOG_WRITE8_FORMAT1_INFO( "Deleting message 0x%X.", msgId );
   333                 __LOG_WRITE8_FORMAT1_INFO( "Deleting message 0x%X.", msgId );
   280         else
   339         else
   281             {
   340             {
   282             mailBox.DeleteMessageL( msgId, iFolderId );
   341             mailBox.DeleteMessageL( msgId, iFolderId );
   283             }
   342             }
   284         }
   343         }
       
   344 
   285     __LOG_EXIT;
   345     __LOG_EXIT;
   286     return done;    
   346     return runAgain;
   287     }
       
   288 /**
       
   289  * 
       
   290  */
       
   291 /*private*/
       
   292 void CDelayedDeleteMessagesOp::ConstructL(
       
   293     const RArray<TFSMailMsgId>& aMessages )
       
   294     {
       
   295     __LOG_CONSTRUCT( "baseplugin", "CDelayedDeleteMessagesOp" );
       
   296             
       
   297     TInt count = aMessages.Count();
       
   298     for ( TInt i = 0; i < count; ++i )
       
   299         {
       
   300         iMessages.AppendL( aMessages[i].Id() );
       
   301         }
       
   302     }
       
   303 
       
   304 /**
       
   305  * 
       
   306  */
       
   307 /*private*/
       
   308 void CDelayedDeleteMessagesOp::ConstructL(
       
   309     TMsgStoreId aMsgId )
       
   310     {
       
   311     __LOG_CONSTRUCT( "baseplugin", "CDelayedDeleteMessagesOp" );
       
   312     iImmediateDelete = ETrue;
       
   313     iMessages.AppendL( aMsgId );
       
   314     }
       
   315 
       
   316 /**
       
   317  * 
       
   318  */
       
   319 /*private*/ CDelayedDeleteMessagesOp::CDelayedDeleteMessagesOp(
       
   320     TMsgStoreId aMailBoxId,
       
   321     TMsgStoreId aFolderId )
       
   322     :
       
   323     iMailBoxId( aMailBoxId ), iFolderId( aFolderId ),
       
   324     iImmediateDelete( EFalse ), iState ( EFree )
       
   325     {
       
   326     }
       
   327 
       
   328 /**
       
   329  * 
       
   330  */
       
   331 /*private*/ void CDelayedDeleteMessagesOp::ExecuteOpL()
       
   332     {
       
   333     __LOG_ENTER( "ExecuteOpL" );
       
   334     if ( iState != EFree )
       
   335         {
       
   336         //this code becomes re-entrant now because we use nested AS.
       
   337         // so if we are already authenticating, return right away.
       
   338         return;
       
   339         }
       
   340     iState=EInProgress;
       
   341     CNestedAO* nestedAO = CNestedAO::NewL( *this );
       
   342     //this is a blocking call with nested active scheduler
       
   343     //This method makes a callback periodically to DeleteMessagesInChunks
       
   344     //to delete the messages one chunk at a time
       
   345     nestedAO->DeleteMessagesAsync();
       
   346     //continue execution here
       
   347     delete nestedAO;
       
   348     iState = EFree;
       
   349     __LOG_EXIT;
       
   350     }
   347     }
   351 
   348 
   352 
   349 
   353 ///////////////////////////////////////////////////
   350 ///////////////////////////////////////////////////
   354 // CDelayedStorePropertiesOp                     //
   351 // CDelayedStorePropertiesOp                     //
   417     }
   414     }
   418 
   415 
   419 /**
   416 /**
   420  * CDelayedOp::ExecuteOpL
   417  * CDelayedOp::ExecuteOpL
   421  */
   418  */
   422 /*public virtual*/ void CDelayedSetContentOp::ExecuteOpL()
   419 /*public virtual*/ TBool CDelayedSetContentOp::ExecuteOpL()
   423     {
   420     {
   424     __LOG_ENTER( "ExecuteOpL" )
   421     __LOG_ENTER( "ExecuteOpL" )
   425 
   422 
   426     CMsgStoreMessagePart* part = FetchMessagePartLC();
   423     CMsgStoreMessagePart* part = FetchMessagePartLC();
   427 
   424 
   444         part->StorePropertiesL();
   441         part->StorePropertiesL();
   445         __LOG_WRITE8_FORMAT1_INFO(
   442         __LOG_WRITE8_FORMAT1_INFO(
   446             "Updated the properties of part 0x%X.", part->Id() )
   443             "Updated the properties of part 0x%X.", part->Id() )
   447         }
   444         }
   448     
   445     
   449     CleanupStack::PopAndDestroy( part );    
   446     CleanupStack::PopAndDestroy( part );
       
   447 
   450     __LOG_EXIT
   448     __LOG_EXIT
       
   449     return EFalse;
   451     }
   450     }
   452 
   451 
   453 /**
   452 /**
   454  * 
   453  * 
   455  */
   454  */