void CHttpCacheManager::ApplyCacheOverridesL(CRepository& aRepository, const TUint32& aSecIdInt, TBool& aCacheEnabled, TInt& aCacheSize, TBool& aOpCacheEnabled, TBool& aVssCacheEnabled, TDes& aPath, const TDesC& aDefaultDrive)
    {
    TDriveUnit drive(aDefaultDrive);
    
    // set defaults
    if(aSecIdInt == KUIDBROWSERNG)       // for the browser, force use of Operator and VSS caches
        {
        aOpCacheEnabled = ETrue;
        aVssCacheEnabled = ETrue;
        }
    
    // read override string from centrep
    HBufC16 *overrideBuf = HBufC16::NewLC(64);
    TPtr overrideStr(overrideBuf->Des());
    TInt strLen;
    TInt err = aRepository.Get(KCacheManagerHttpCacheProcessOverride, overrideStr, strLen);
    if(strLen > overrideBuf->Length())
        {
        overrideBuf = overrideBuf->ReAllocL(strLen);
        // make sure cleanup stack contains correct pointer since ReAllocL always allocates a new des for larger space.
        CleanupStack::Pop();
        CleanupStack::PushL(overrideBuf);
        // reassign the TPtr
        overrideStr.Set(overrideBuf->Des());
        // pull in the whole string
        aRepository.Get(KCacheManagerHttpCacheProcessOverride, overrideStr, strLen);
        }
    // if we failed to load an override string, use the default.
    if( overrideStr.Length() == 0 )
        {
        CleanupStack::PopAndDestroy( overrideBuf );
        overrideBuf = KDefaultOverrideString().AllocLC();
        overrideStr.Set( overrideBuf->Des() );
        }
    // Built in Lex likes white space to separate strings, but easier to enter with ; separators.  Replace all ; with spaces.
    TInt pos=0;
    do{
        if(overrideStr[pos] == ';')
            {
            overrideStr[pos] = ' ';
            }
        pos++;
    }while(pos < overrideStr.Length());
    
    TLex overrideLex(overrideStr);
    do{
        TUint32 tempId;
        User::LeaveIfError(overrideLex.BoundedVal(tempId,EHex,KMaxTUint32));
        if(overrideLex.TokenLength() != 8)  // if we're not pointing at an SID in the string, we are incorrect and the override is broken.
            User::Leave(KErrCorrupt);
        overrideLex.SkipSpace();
        TInt32 tempCacheEnabled;
        User::LeaveIfError(overrideLex.BoundedVal(tempCacheEnabled,KMaxTInt32));
        overrideLex.SkipSpace();
        TInt32 tempCacheSize;
        User::LeaveIfError(overrideLex.BoundedVal(tempCacheSize,KMaxTInt32));
        overrideLex.SkipSpace();
        TDriveUnit tempDrive(overrideLex.NextToken());
        overrideLex.SkipSpaceAndMark();
        // found a hex SID matching ours, use the parameters.
        if(tempId == aSecIdInt)
            {
            aCacheEnabled = tempCacheEnabled;
            aCacheSize = tempCacheSize * 1024; // conf is in KB
            drive = tempDrive;
            break;
            }
    }while(!overrideLex.Eos());

    // Modify drive letter on aPath to match
    TParsePtr parsePath(aPath);
    TPtrC pathStr(parsePath.Path());
    TPath tempPath;
    tempPath.Format(_L("%c:%S"), TInt(drive)+'A', &pathStr);
    aPath.Copy(tempPath);
    HttpCacheUtil::EnsureTrailingSlash( aPath );
    
    CleanupStack::PopAndDestroy(overrideBuf);
    }
// ---------------------------------------------------------------------------
// 2nd phase constructor
// ---------------------------------------------------------------------------
//
void CCatalogsHttpDownloadManager::ConstructL( TBool aCleanup )
{
    DLTRACEIN((""));
    User::LeaveIfError( iFs.Connect() );

    // shared so that RFiles can be given to Download manager
    User::LeaveIfError( iFs.ShareProtected() );

    QString DmgrUid(QString::number(KNCDEngineAppID));
    iDmgr =  new DownloadManager(DmgrUid);
    iDmgr->initialize();
    iQTmgr = new CCatalogsHttpQTDownloadManager(this,iDmgr);

    TUid sessionId( TUid::Uid( iSessionId ) );
    if ( aCleanup )
    {
        DLTRACE(("Cleaning download manager before connecting"));
        TUidName client( CleanUidName( sessionId ) );
        TPath path;
        path.Format( KCatalogsDownloadMgrPath, &client );

        CFileMan* fileman = CFileMan::NewL( iFs );
        CleanupStack::PushL( fileman );
        DLINFO(( _L("Clearing directory: %S"), &path ));
        // Ignoring errors
        fileman->Delete( path );
        CleanupStack::PopAndDestroy( fileman );
    }

    // Connect with the download manager
    // If the 3rd parameter == ETrue, this session inherits downloads
    // from other sessions that have the same UID.
    TInt err = KErrNone;
    TInt retries = KCatalogsDlMgrConnectRetryAttempts;

    do
    {
        if ( err != KErrNone )
        {
            DLERROR(("DL manager connection failed with err: %d, retry attempts left",
                     err, retries ));
            // This halts the whole thread which is not nice but shouldn't
            // be a problem since this should occur only when the download
            // manager is being shutdown when we try to connect to it
            User::After( KCatalogsDlMgrConnectRetryInterval );
        }
    }
    while ( err != KErrNone && retries-- );

    if( err != KErrNone )
    {
        DLINFO(("Leaving.. DL manager connection failed with: %d", err ));
        User::Leave( err );
    }

    DLTRACE(("ConnectL ok"));

    iDefaultConfig = CCatalogsHttpConfig::NewL();

    iNetworkManager = &CCatalogsHttpSessionManager::NetworkManagerL();
    iNetworkManager->AddObserverL( *this );

    // Restore downloads from previous sessions
//    RestoreDownloadsL();

    DLTRACEOUT((""));

}