phonebookui/Phonebook2/remotecontactlookup/engine/src/cpbk2remotecontactlookupaccounts.cpp
branchRCL_3
changeset 15 34879f5cfc63
parent 11 2828b4d142c0
--- a/phonebookui/Phonebook2/remotecontactlookup/engine/src/cpbk2remotecontactlookupaccounts.cpp	Wed Jun 09 09:26:27 2010 +0300
+++ b/phonebookui/Phonebook2/remotecontactlookup/engine/src/cpbk2remotecontactlookupaccounts.cpp	Mon Jun 21 15:24:27 2010 +0300
@@ -122,12 +122,29 @@
     // The actual ECom loading is implemented in CPbkxRemoteContactLookupProtocolAdapter.
     for ( TInt i = 0; i < implArray.Count(); i++ )
         {
-        CPbkxRemoteContactLookupProtocolAdapter* adapter = NULL;
-        adapter = CPbkxRemoteContactLookupProtocolAdapter::NewL(
-            implArray[i]->ImplementationUid(), *iProtocolEnv );
-        CleanupStack::PushL( adapter );
-        User::LeaveIfError( iAdapters.Append( adapter ) );
-        CleanupStack::Pop( adapter );
+        CPbkxRemoteContactLookupProtocolAdapter* volatile adapter = NULL;
+        
+        // Trap the error code of loading one specific protocal adapter, if the error is not 
+        // extremly harmful like "No memory", then go on loading remaining possibly working 
+        // adapters.
+        TRAPD(err,
+        		{
+                adapter = CPbkxRemoteContactLookupProtocolAdapter::NewL(
+                implArray[i]->ImplementationUid(), *iProtocolEnv );
+        		}
+        );
+        
+        if( err == KErrNoMemory )
+            {
+            User::Leave( KErrNoMemory );
+            }
+        
+        if ( adapter )
+        	{
+            CleanupStack::PushL( adapter );
+            User::LeaveIfError( iAdapters.Append( adapter ) );
+            CleanupStack::Pop( adapter );
+        	}
         }
     CleanupStack::PopAndDestroy(); // cleanupItem 
     }
@@ -153,23 +170,32 @@
         RPointerArray<CPbkxRemoteContactLookupProtocolAccount> protocolAccountsTmp;
         TCleanupItem cleanupItemAcc(CleanupResetAndDestroyAccArray, &protocolAccountsTmp);
         CleanupStack::PushL(cleanupItemAcc);
-        adapter.GetAllProtocolAccountsL( protocolAccountsTmp );
+        
+        TRAPD( err,
+        		{
+                adapter.GetAllProtocolAccountsL( protocolAccountsTmp );
+        		}
+        );
+        
+        if( err == KErrNoMemory )
+            {
+            User::Leave( KErrNoMemory );
+            }
         
         // Move accounts from temp array to main array
         
         // First expand the main array so that we can move ownership in one go.
         // TODO OOPS, METHOD NOT AVAILABLE iAdapters.SetReserveL( iAdapters.Count() + protocolAccountsTmp.Count() );
 
-        
-        // Don't need the cleanup item anymore since iAdapters will take ownership,
-        // and the iAdapters has already been expanded.
-        CleanupStack::Pop(); // cleanupItemAcc
-        for ( TInt x = 0; x < protocolAccountsTmp.Count(); x++ )
+        const TInt count = protocolAccountsTmp.Count();
+        for ( TInt x = 0; x < count; x++ )
             {
             // Ownership is passed
-            User::LeaveIfError( aAccounts.Append( protocolAccountsTmp[ x ] ) );
+            User::LeaveIfError( aAccounts.Append( protocolAccountsTmp[ 0 ] ) );
+            protocolAccountsTmp.Remove( 0 );
             }
-        // just let protocolAccountsTmp pass out of scope. It doesn't own anything now.
+        
+        CleanupStack::PopAndDestroy( &protocolAccountsTmp );
         }
     CleanupStack::Pop();
     }