filemanager/bkupengine/src/CMMCScBkupStateGetDataOwners.cpp
branchRCL_3
changeset 38 491b3ed49290
parent 36 95243422089a
child 39 65326cf895ed
equal deleted inserted replaced
36:95243422089a 38:491b3ed49290
     1 /*
       
     2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0""
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: CMMCScBkupStateGetDataOwners implementation
       
    15 *
       
    16 *
       
    17 */
       
    18 
       
    19 #include "CMMCScBkupStateGetDataOwners.h"
       
    20 
       
    21 #include <bldvariant.hrh>
       
    22 // User includes
       
    23 #include "MMCScBkupLogger.h"
       
    24 #include "CMMCScBkupDataOwnerCollection.h"
       
    25 #include "MMCScBkupSBEUtils.h"
       
    26 
       
    27 // Constants
       
    28 const TInt KMMCScBkupDataOwnerGranularity = 20;
       
    29 
       
    30 
       
    31 
       
    32 // ========================= MEMBER FUNCTIONS ================================
       
    33 
       
    34 // ---------------------------------------------------------------------------
       
    35 // CMMCScBkupStateGetDataOwners::CMMCScBkupStateGetDataOwners()
       
    36 // 
       
    37 // C++ constructor.
       
    38 // ---------------------------------------------------------------------------
       
    39 CMMCScBkupStateGetDataOwners::CMMCScBkupStateGetDataOwners( MMMCScBkupDriver& aDriver )
       
    40 :   CMMCScBkupState( aDriver )
       
    41     {
       
    42     __LOG1("CMMCScBkupStateGetDataOwners::CMMCScBkupStateGetDataOwners() - 0x%08x", StateId().iUid );
       
    43     }
       
    44 
       
    45 
       
    46 // ---------------------------------------------------------------------------
       
    47 // CMMCScBkupStateGetDataOwners::NewL()
       
    48 // 
       
    49 // 
       
    50 // ---------------------------------------------------------------------------
       
    51 CMMCScBkupStateGetDataOwners* CMMCScBkupStateGetDataOwners::NewL( MMMCScBkupDriver& aDriver )
       
    52     {
       
    53     CMMCScBkupStateGetDataOwners* self = new(ELeave) CMMCScBkupStateGetDataOwners( aDriver );
       
    54     return self;
       
    55     }
       
    56 
       
    57 
       
    58 // ---------------------------------------------------------------------------
       
    59 // CMMCScBkupStateGetDataOwners::StateId()
       
    60 // 
       
    61 // 
       
    62 // ---------------------------------------------------------------------------
       
    63 TMMCScBkupStateId CMMCScBkupStateGetDataOwners::StateId() const
       
    64     {
       
    65     return KMMCScBkupStateIdGetDataOwners;
       
    66     }
       
    67 
       
    68 
       
    69 // ---------------------------------------------------------------------------
       
    70 // CMMCScBkupStateGetDataOwners::NextStateId()
       
    71 // 
       
    72 // 
       
    73 // ---------------------------------------------------------------------------
       
    74 TMMCScBkupStateId CMMCScBkupStateGetDataOwners::NextStateId() const
       
    75     {
       
    76     // This is the same for backup & restore
       
    77     return KMMCScBkupStateIdSetPhoneMode;
       
    78     }
       
    79 
       
    80 
       
    81 // ---------------------------------------------------------------------------
       
    82 // CMMCScBkupStateGetDataOwners::PerformStateInitL()
       
    83 // 
       
    84 // 
       
    85 // ---------------------------------------------------------------------------
       
    86 void CMMCScBkupStateGetDataOwners::PerformStateInitL()
       
    87     {
       
    88     // Query asynchronously
       
    89     CompleteSelf();
       
    90     }
       
    91 
       
    92 
       
    93 // ---------------------------------------------------------------------------
       
    94 // CMMCScBkupStateGetDataOwners::PerformAsynchronousStateStepL()
       
    95 // 
       
    96 // 
       
    97 // ---------------------------------------------------------------------------
       
    98 void CMMCScBkupStateGetDataOwners::PerformAsynchronousStateStepL()
       
    99     {
       
   100     RMMCScBkupPointerArray<CDataOwnerInfo> dataOwners(KMMCScBkupDataOwnerGranularity);
       
   101     CleanupClosePushL( dataOwners );
       
   102 
       
   103     // Get data owner listing from secure backup engine
       
   104     Driver().DrvSecureBackupClient().ListOfDataOwnersL(dataOwners);
       
   105 
       
   106     // Inform driver of result
       
   107 #ifdef RD_FILE_MANAGER_BACKUP
       
   108     RPointerArray<CMMCScBkupDataOwnerCollection>& dataOwnerLists = Driver().DrvDataOwnersAll();
       
   109     TInt count = dataOwners.Count();
       
   110     
       
   111     // Construct an info array to get introduced for every category
       
   112     for(TInt i = count-1; i >= 0; i--)
       
   113         {
       
   114         // Ownership is immediately transferred to the backup owner info object
       
   115         // so we should remove it from the array prior to passing into NewLC
       
   116         conn::CDataOwnerInfo* sbDataOwner = dataOwners[i];
       
   117         
       
   118         dataOwners.Remove( i ); // Ensures it won't be deleted twice
       
   119         
       
   120         const TSBDerivedType type = sbDataOwner->Identifier().DerivedTypeL();
       
   121         if  ( type == EJavaDerivedType || type == EJavaTransferDerivedType )
       
   122             {
       
   123             HBufC* hash = MMCScBkupSBEUtils::JavaHashFromGenericLC( sbDataOwner->Identifier() );
       
   124             __LOG1("CMMCScBkupStateGetDataOwners::PerformAsynchronousStateStepL() - Assigning java owner with hash %S for categories", 
       
   125                 hash );
       
   126             CleanupStack::PopAndDestroy( hash );
       
   127             }
       
   128         else
       
   129             {
       
   130             __LOG1("CMMCScBkupStateGetDataOwners::PerformAsynchronousStateStepL() - Assigning data owner 0x%08x for categories", 
       
   131                 MMCScBkupSBEUtils::SecureIdFromGenericL( sbDataOwner->Identifier() ).iId );
       
   132             }
       
   133 
       
   134         // We have to create copy of original data owner for each category, so we have to externalize it
       
   135         RPointerArray<CDataOwnerInfo> sbDataOwnerCopies(dataOwnerLists.Count());
       
   136         CleanupClosePushL( sbDataOwnerCopies );
       
   137         HBufC8* dataOwner = sbDataOwner->ExternaliseL();
       
   138         CleanupStack::PushL( dataOwner );
       
   139         // Delete original data owner instance 
       
   140         delete sbDataOwner;
       
   141         
       
   142         // Create copies for each category (even if they do not eventually end up to those lists)
       
   143         for(TInt j = 0; j < dataOwnerLists.Count(); j++)
       
   144             {
       
   145             conn::CDataOwnerInfo* sbDataOwnerCopy = conn::CDataOwnerInfo::NewL(*dataOwner);
       
   146             CleanupStack::PushL( sbDataOwnerCopy );
       
   147             sbDataOwnerCopies.AppendL(sbDataOwnerCopy);
       
   148             CleanupStack::Pop( sbDataOwnerCopy );
       
   149             }
       
   150         CleanupStack::PopAndDestroy( dataOwner );
       
   151         
       
   152         // Loop through all lists and assign copied data owners there
       
   153         for(TInt j = 0; j < dataOwnerLists.Count(); j++)
       
   154             {
       
   155             // Again we have to create instances for each category, 
       
   156             // because each has to have own copy of data owner
       
   157             CMMCScBkupDataOwnerInfo* info = CMMCScBkupDataOwnerInfo::NewLC( sbDataOwnerCopies[j] );
       
   158             
       
   159             if(dataOwnerLists[j]->AssignL( *info ))
       
   160                 {
       
   161                 CleanupStack::Pop( info );
       
   162                 }
       
   163             else
       
   164                 {
       
   165                 CleanupStack::PopAndDestroy( info );
       
   166                 }
       
   167             }
       
   168             
       
   169             CleanupStack::PopAndDestroy( &sbDataOwnerCopies );
       
   170         }
       
   171     
       
   172 #if defined(__MMCSCBKUPLOGGING_ENABLED__)
       
   173     __LOG("CMMCScBkupStateGetDataOwners::PerformAsynchronousStateStepL() - Data owners per categories:");
       
   174     
       
   175     for(TInt i = 0; i < dataOwnerLists.Count(); i++)
       
   176         {
       
   177         __LOG2("CMMCScBkupStateGetDataOwners::PerformAsynchronousStateStepL() - Category 0x%x contains %d data owners", 
       
   178             dataOwnerLists[i]->Category().iFlags, dataOwnerLists[i]->Count() );
       
   179         
       
   180         for(TInt j = 0; j < dataOwnerLists[i]->Count(); j++)
       
   181             {
       
   182             CMMCScBkupDataOwnerInfo* entry = &dataOwnerLists[i]->Owner(j);
       
   183             
       
   184             const TSBDerivedType type = entry->Owner().Identifier().DerivedTypeL();
       
   185             if  ( type == EJavaDerivedType || type == EJavaTransferDerivedType )
       
   186                 {
       
   187                 HBufC* hash = MMCScBkupSBEUtils::JavaHashFromGenericLC( entry->Owner().Identifier() );
       
   188                 __LOG1("CMMCScBkupStateGetDataOwners::PerformAsynchronousStateStepL() - java data owner with hash %S", 
       
   189                     hash );
       
   190                 CleanupStack::PopAndDestroy( hash );
       
   191                 }
       
   192             else
       
   193                 {
       
   194                 __LOG1("CMMCScBkupStateGetDataOwners::PerformAsynchronousStateStepL() - data owner 0x%08x", 
       
   195                     MMCScBkupSBEUtils::SecureIdFromGenericL( entry->Owner().Identifier() ).iId );
       
   196                 }
       
   197             }
       
   198         }
       
   199 #endif
       
   200 
       
   201 #else // RD_FILE_MANAGER_BACKUP
       
   202     Driver().DrvDataOwners().AssignL( dataOwners );
       
   203 #endif // RD_FILE_MANAGER_BACKUP
       
   204     
       
   205     CleanupStack::PopAndDestroy( &dataOwners );
       
   206     }