emailservices/emailstore/base_plugin/src/baseplugindelayedops.cpp
branchRCL_3
changeset 35 e64954c2c8e2
parent 8 e1b6206813b4
child 24 b5fbb9b25d57
--- a/emailservices/emailstore/base_plugin/src/baseplugindelayedops.cpp	Wed Apr 14 15:42:15 2010 +0300
+++ b/emailservices/emailstore/base_plugin/src/baseplugindelayedops.cpp	Tue Apr 27 16:20:14 2010 +0300
@@ -18,7 +18,7 @@
 
 #include "baseplugindelayedops.h"
 #include "baseplugindelayedopsprivate.h"
-
+#include "NestedAO.h"
 
 ///////////////////////////////////////////////////
 // CDelayedOp                                    //
@@ -228,7 +228,63 @@
     __LOG_DESTRUCT
     }
 
+/**
+ * 
+ */
+/*public virtual*/TBool CDelayedDeleteMessagesOp::DeleteMessagesInChunksL( TInt aStartIndex )
+    {
+    __LOG_ENTER( "DeleteMessagesInChunksL" );
+    TBool done=EFalse;
+    TInt endIndex;
+    if( aStartIndex + KSizeOfChunk < iMessages.Count() )
+        {
+            endIndex = aStartIndex + KSizeOfChunk;
+        }
+    else
+        {
+        endIndex = iMessages.Count();   
+        done=ETrue;
+        }
+    CMailboxInfo& mailBoxInfo
+        = GetPlugin().GetMailboxInfoL( iMailBoxId );
+    CMsgStoreMailBox& mailBox = mailBoxInfo();
 
+    for ( TInt i = aStartIndex; i < endIndex; ++i )
+        {
+        TMsgStoreId msgId = iMessages[i];
+        
+        if ( EFalse == iImmediateDelete )
+            {
+            //try to find the message in the deleted items folder.
+            CMsgStoreMessage* theMessage = NULL;
+            TRAP_IGNORE( theMessage = mailBox.FetchMessageL(
+              msgId, mailBoxInfo.iRootFolders.iFolders[EFSDeleted] ) );
+            
+            if ( NULL == theMessage )
+                {
+                //if not in deleted items then move it there.
+                __LOG_WRITE8_FORMAT1_INFO("Moving message 0x%X to the deleted items.", msgId );
+                mailBox.MoveMessageL(
+                   msgId, KMsgStoreInvalidId,
+                   mailBoxInfo.iRootFolders.iFolders[EFSDeleted] );
+                }
+            else
+                {
+                //in deleted items, really delete it.
+                __LOG_WRITE8_FORMAT1_INFO( "Deleting message 0x%X.", msgId );
+
+                delete theMessage;
+                mailBox.DeleteMessageL( msgId, iFolderId );
+                }
+            }
+        else
+            {
+            mailBox.DeleteMessageL( msgId, iFolderId );
+            }
+        }
+    __LOG_EXIT;
+    return done;    
+    }
 /**
  * 
  */
@@ -265,7 +321,7 @@
     TMsgStoreId aFolderId )
     :
     iMailBoxId( aMailBoxId ), iFolderId( aFolderId ),
-    iImmediateDelete( EFalse )
+    iImmediateDelete( EFalse ), iState ( EFree )
     {
     }
 
@@ -275,47 +331,21 @@
 /*private*/ void CDelayedDeleteMessagesOp::ExecuteOpL()
     {
     __LOG_ENTER( "ExecuteOpL" );
-    
-    CMailboxInfo& mailBoxInfo
-        = GetPlugin().GetMailboxInfoL( iMailBoxId );
-    CMsgStoreMailBox& mailBox = mailBoxInfo();
-
-    TInt count = iMessages.Count();
-    for ( TInt i = 0; i < count; ++i )
+    if ( iState != EFree )
         {
-        TMsgStoreId msgId = iMessages[i];
-        
-        if ( EFalse == iImmediateDelete )
-            {
-            //try to find the message in the deleted items folder.
-            CMsgStoreMessage* theMessage = NULL;
-            TRAP_IGNORE( theMessage = mailBox.FetchMessageL(
-              msgId, mailBoxInfo.iRootFolders.iFolders[EFSDeleted] ) );
-            
-            if ( NULL == theMessage )
-                {
-                //if not in deleted items then move it there.
-                __LOG_WRITE8_FORMAT1_INFO(
-                     "Moving message 0x%X to the deleted items.", msgId );
-                mailBox.MoveMessageL(
-                   msgId, KMsgStoreInvalidId,
-                   mailBoxInfo.iRootFolders.iFolders[EFSDeleted] );
-                }
-            else
-                {
-                //in deleted items, really delete it.
-                __LOG_WRITE8_FORMAT1_INFO( "Deleting message 0x%X.", msgId );
-
-                delete theMessage;
-                mailBox.DeleteMessageL( msgId, iFolderId );
-                }
-            }
-        else
-            {
-            mailBox.DeleteMessageL( msgId, iFolderId );
-            }
+        //this code becomes re-entrant now because we use nested AS.
+        // so if we are already authenticating, return right away.
+        return;
         }
-
+    iState=EInProgress;
+    CNestedAO* nestedAO = CNestedAO::NewL( *this );
+    //this is a blocking call with nested active scheduler
+    //This method makes a callback periodically to DeleteMessagesInChunks
+    //to delete the messages one chunk at a time
+    nestedAO->DeleteMessagesAsync();
+    //continue execution here
+    delete nestedAO;
+    iState = EFree;
     __LOG_EXIT;
     }