Index: trunk/src/VBox/Main/src-server/CloudProviderManagerImpl.cpp
===================================================================
--- trunk/src/VBox/Main/src-server/CloudProviderManagerImpl.cpp	(revision 73716)
+++ trunk/src/VBox/Main/src-server/CloudProviderManagerImpl.cpp	(revision 73716)
@@ -0,0 +1,209 @@
+/* $Id$ */
+/** @file
+ * ICloudProviderManager  COM class implementations.
+ */
+
+/*
+ * Copyright (C) 2008-2018 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ */
+
+
+#include <VBox/com/array.h>
+
+#include "VirtualBoxImpl.h"
+#include "CloudProviderManagerImpl.h"
+#ifdef VBOX_WITH_CLOUD_PROVIDERS_IN_EXTPACK
+# include "ExtPackManagerImpl.h"
+#else
+# include "OCIProvider.h"
+#endif
+#include "AutoCaller.h"
+#include "Logging.h"
+
+using namespace std;
+
+////////////////////////////////////////////////////////////////////////////////
+//
+// CloudProviderManager constructor / destructor
+//
+// ////////////////////////////////////////////////////////////////////////////////
+CloudProviderManager::CloudProviderManager()
+{
+}
+
+CloudProviderManager::~CloudProviderManager()
+{
+}
+
+
+HRESULT CloudProviderManager::FinalConstruct()
+{
+    return BaseFinalConstruct();
+}
+
+void CloudProviderManager::FinalRelease()
+{
+    uninit();
+
+    BaseFinalRelease();
+}
+
+HRESULT CloudProviderManager::init(VirtualBox *aParent)
+{
+    // Enclose the state transition NotReady->InInit->Ready.
+    AutoInitSpan autoInitSpan(this);
+    AssertReturn(autoInitSpan.isOk(), E_FAIL);
+
+    m_apCloudProviders.clear();
+
+#ifdef VBOX_WITH_CLOUD_PROVIDERS_IN_EXTPACK
+    // Engage the extension pack manager and get all the implementations of
+    // this class and all implemented cloud providers.
+    ExtPackManager *pExtPackMgr = aParent->i_getExtPackManager();
+    mpExtPackMgr = pExtPackMgr;
+    if (pExtPackMgr)
+    {
+        mcExtPackMgrUpdate = pExtPackMgr->i_getUpdateCounter();
+        // Make sure that the current value doesn't match, forcing a refresh.
+        mcExtPackMgrUpdate--;
+        iRefreshProviders();
+    }
+#else
+    ComObjPtr<OCIProvider> pOCIProvider;
+    HRESULT hrc = pOCIProvider.createObject();
+    if (FAILED(hrc))
+        return hrc;
+    hrc = pOCIProvider->init(aParent);
+    if (FAILED(hrc))
+        return hrc;
+    m_apCloudProviders.push_back(pOCIProvider);
+#endif
+
+    autoInitSpan.setSucceeded();
+    return S_OK;
+}
+
+void CloudProviderManager::uninit()
+{
+    // Enclose the state transition Ready->InUninit->NotReady.
+    AutoUninitSpan autoUninitSpan(this);
+    if (autoUninitSpan.uninitDone())
+        return;
+}
+
+#ifdef VBOX_WITH_CLOUD_PROVIDERS_IN_EXTPACK
+void CloudProviderManager::i_refreshProviders()
+{
+    {
+        AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
+        uint64_t cExtPackMgrUpdate = mpExtPackMgr->i_getUpdateCounter();
+        if (cExtPackMgrUpdate == mcExtPackMgrUpdate)
+            return;
+    }
+
+    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
+    // Reread the current value to figure out if some other thead did the work
+    // already before this thread got hold of the write lock.
+    cExtPackMgrUpdate = pExtPackMgr->i_getUpdateCounter();
+    if (cExtPackMgrUpdate == mcExtPackMgrUpdate)
+        return;
+    mcExtPackMgrUpdate = cExtPackMgrUpdate;
+
+    if (!m_mapCloudProviderManagers.empty())
+    {
+        /// @todo The code below will need to be extended to handle extpack
+        // install and uninstall safely (and the latter needs non-trivial
+        // checks if any extpack related cloud activity is pending.
+        return;
+    }
+
+    std::vector<ComPtr<IUnknown> > apObjects;
+    std::vector<com::Utf8Str> astrExtPackNames;
+    com::Guid idObj(COM_IIDOF(ICloudProviderManager));
+    pExtPackMgr->i_queryObjects(idObj.toString(), apObjects, &astrExtPackNames);
+    for (unsigned i = 0; i < apObjects.size(); i++)
+    {
+        ComPtr<ICloudProviderManager> pTmp;
+        HRESULT hrc = apObjects[i].queryInterfaceTo(pTmp.asOutParam());
+        if (SUCCEEDED(hrc))
+            m_mapCloudProviderManagers[astrExtPackNames[i]] = pTmp;
+        SafeIfaceArray<ICloudProvider> apProvidersFromCurrExtPack;
+        hrc = pTmp->COMGETTER(Providers)(ComSafeArrayAsOutParam(apProvidersFromCurrExtPack));
+        if (SUCCEEDED(hrc))
+        {
+            for (unsigned j = 0; j < apProvidersFromCurrExtPack.size(); j++)
+                m_apCloudProviders.push_back(apProvidersFromCurrExtPack[i]);
+        }
+    }
+}
+#endif
+
+HRESULT CloudProviderManager::getProviders(std::vector<ComPtr<ICloudProvider> > &aProviders)
+{
+    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
+    aProviders = m_apCloudProviders;
+    return S_OK;
+}
+
+HRESULT CloudProviderManager::getProviderById(const com::Guid &aProviderId,
+                                              ComPtr<ICloudProvider> &aProvider)
+{
+    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
+    for (size_t i = 0; i < m_apCloudProviders.size(); i++)
+    {
+        Bstr bstrId;
+        HRESULT hrc = m_apCloudProviders[i]->COMGETTER(Id)(bstrId.asOutParam());
+        if (SUCCEEDED(hrc) && aProviderId == bstrId)
+        {
+            aProvider = m_apCloudProviders[i];
+            return S_OK;
+        }
+    }
+    return setError(VBOX_E_OBJECT_NOT_FOUND, tr("Could not find a cloud provider with UUID {%RTuuid}"),
+                    aProviderId.raw());
+}
+
+HRESULT CloudProviderManager::getProviderByShortName(const com::Utf8Str &aProviderName,
+                                                     ComPtr<ICloudProvider> &aProvider)
+{
+    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
+    for (size_t i = 0; i < m_apCloudProviders.size(); i++)
+    {
+        Bstr bstrName;
+        HRESULT hrc = m_apCloudProviders[i]->COMGETTER(ShortName)(bstrName.asOutParam());
+        if (SUCCEEDED(hrc) && bstrName.equals(aProviderName))
+        {
+            aProvider = m_apCloudProviders[i];
+            return S_OK;
+        }
+    }
+    return setError(VBOX_E_OBJECT_NOT_FOUND, tr("Could not find a cloud provider with short name '%s'"),
+                    aProviderName.c_str());
+}
+
+HRESULT CloudProviderManager::getProviderByName(const com::Utf8Str &aProviderName,
+                                                ComPtr<ICloudProvider> &aProvider)
+{
+    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
+    for (size_t i = 0; i < m_apCloudProviders.size(); i++)
+    {
+        Bstr bstrName;
+        HRESULT hrc = m_apCloudProviders[i]->COMGETTER(Name)(bstrName.asOutParam());
+        if (SUCCEEDED(hrc) && bstrName.equals(aProviderName))
+        {
+            aProvider = m_apCloudProviders[i];
+            return S_OK;
+        }
+    }
+    return setError(VBOX_E_OBJECT_NOT_FOUND, tr("Could not find a cloud provider with name '%s'"),
+                    aProviderName.c_str());
+}
+
Index: trunk/src/VBox/Main/src-server/CloudUserProfileManagerImpl.cpp
===================================================================
--- trunk/src/VBox/Main/src-server/CloudUserProfileManagerImpl.cpp	(revision 73665)
+++ 	(revision )
@@ -1,236 +1,0 @@
-/* $Id$ */
-/** @file
- * ICloudProviderManager  COM class implementations.
- */
-
-/*
- * Copyright (C) 2008-2018 Oracle Corporation
- *
- * This file is part of VirtualBox Open Source Edition (OSE), as
- * available from http://www.virtualbox.org. This file is free software;
- * you can redistribute it and/or modify it under the terms of the GNU
- * General Public License (GPL) as published by the Free Software
- * Foundation, in version 2 as it comes in the "COPYING" file of the
- * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
- * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
- */
-
-
-#include <iprt/path.h>
-#include <iprt/cpp/utils.h>
-#include <VBox/com/array.h>
-#include <map>
-
-#include "CloudUserProfileManagerImpl.h"
-#include "CloudUserProfilesImpl.h"
-#include "VirtualBoxImpl.h"
-#include "ExtPackManagerImpl.h"
-#include "Global.h"
-#include "ProgressImpl.h"
-#include "MachineImpl.h"
-#include "AutoCaller.h"
-#include "Logging.h"
-
-using namespace std;
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// CloudProviderManager constructor / destructor
-//
-// ////////////////////////////////////////////////////////////////////////////////
-CloudProviderManager::CloudProviderManager()
-    : mParent(NULL)
-{
-}
-
-CloudProviderManager::~CloudProviderManager()
-{
-}
-
-
-HRESULT CloudProviderManager::FinalConstruct()
-{
-    return BaseFinalConstruct();
-}
-
-void CloudProviderManager::FinalRelease()
-{
-    uninit();
-
-    BaseFinalRelease();
-}
-
-HRESULT CloudProviderManager::init(VirtualBox *aParent)
-{
-    /* Enclose the state transition NotReady->InInit->Ready */
-    AutoInitSpan autoInitSpan(this);
-    AssertReturn(autoInitSpan.isOk(), E_FAIL);
-
-    unconst(mParent) = aParent;
-
-#ifdef VBOX_WITH_CLOUD_PROVIDERS_IN_EXTPACK
-    /*
-     * Engage the extension pack manager and get all the implementations of this class.
-     */
-    ExtPackManager *pExtPackMgr = aParent->i_getExtPackManager();
-    std::vector<ComPtr<IUnknown> > Objects;
-    com::Guid idObj(COM_IIDOF(ICloudProviderManager));
-    pExtPackMgr->i_queryObjects(idObj.toString(), Objects);
-    for (unsigned i = 0; i < Objects.size(); i++)
-    {
-        ComPtr<ICloudProviderManager> ptrTmp;
-        HRESULT hrc = Objects[i].queryInterfaceTo(ptrTmp.asOutParam());
-        if (SUCCEEDED(hrc))
-            mUserProfileManagers.push_back(ptrTmp);
-    }
-#else
-
-    mSupportedProviders.clear();
-    mSupportedProviders.push_back("OCI");
-
-#endif
-
-    autoInitSpan.setSucceeded();
-    return S_OK;
-}
-
-void CloudProviderManager::uninit()
-{
-    /* Enclose the state transition Ready->InUninit->NotReady */
-    AutoUninitSpan autoUninitSpan(this);
-    if (autoUninitSpan.uninitDone())
-        return;
-
-    unconst(mParent) = NULL;
-}
-
-HRESULT CloudProviderManager::getSupportedProviders(std::vector<Utf8Str> &aSupportedProviders)
-{
-#ifdef VBOX_WITH_CLOUD_PROVIDERS_IN_EXTPACK
-    /*
-     * Collect all the provider names from all the extension pack objects.
-     */
-    HRESULT hrc = S_OK;
-    for (unsigned i = 0; i < mUserProfileManagers.size(); i++)
-    {
-        SafeArray<Utf8Str> FromCurrent;
-        HRESULT hrc2 = mUserProfileManagers[i]->COMGETTER(SupportedProviders)(ComSafeArrayAsOutParam(FromCurrent));
-        if (SUCCEEDED(hrc2))
-            for (size_t j = 0; j < FromCurrent.size(); j++)
-                aSupportedProviders.push_back(FromCurrent[j]);
-        else if (SUCCEEDED(hrc))
-            hrc = hrc2;
-    }
-    if (aSupportedProviders.size() > 0)
-        hrc = S_OK;
-    return hrc;
-#else
-    aSupportedProviders = mSupportedProviders;
-    return S_OK;
-#endif
-}
-
-HRESULT CloudProviderManager::getAllProfiles(std::vector<ComPtr<ICloudProvider> > &aProfilesList)
-{
-#ifdef VBOX_WITH_CLOUD_PROVIDERS_IN_EXTPACK
-    /*
-     * Collect all the cloud providers from all the extension pack objects.
-     */
-    HRESULT hrc = S_OK;
-    for (unsigned i = 0; i < mUserProfileManagers.size(); i++)
-    {
-        SafeIfaceArray<ICloudProvider> FromCurrent;
-        HRESULT hrc2 = mUserProfileManagers[i]->GetAllProfiles(ComSafeArrayAsOutParam(FromCurrent));
-        if (SUCCEEDED(hrc2))
-            for (size_t j = 0; j < FromCurrent.size(); j++)
-                aProfilesList.push_back(FromCurrent[j]);
-        else if (SUCCEEDED(hrc))
-            hrc = hrc2;
-    }
-    if (aProfilesList.size() > 0)
-        hrc = S_OK;
-    return hrc;
-
-#else
-    HRESULT hrc = S_OK;
-    std::vector<ComPtr<ICloudProvider> > lProfilesList;
-    for (size_t i=0;i<mSupportedProviders.size();++i)
-    {
-        ComPtr<ICloudProvider> lProfiles;
-        hrc = getProfilesByProvider(mSupportedProviders.at(i), lProfiles);
-        if (FAILED(hrc))
-            break;
-
-        lProfilesList.push_back(lProfiles);
-    }
-
-    if (SUCCEEDED(hrc))
-        aProfilesList = lProfilesList;
-
-    return hrc;
-#endif
-}
-
-HRESULT CloudProviderManager::getProfilesByProvider(const com::Utf8Str &aProviderName,
-                                                    ComPtr<ICloudProvider> &aProfiles)
-{
-#ifdef VBOX_WITH_CLOUD_PROVIDERS_IN_EXTPACK
-    /*
-     * Return the first provider we get.
-     */
-    HRESULT hrc = VBOX_E_OBJECT_NOT_FOUND;
-    for (unsigned i = 0; i < mUserProfileManagers.size(); i++)
-    {
-        hrc = mUserProfileManagers[i]->GetProfilesByProvider(aProviderType, aProfiles.asOutParam());
-        if (SUCCEEDED(hrc))
-            break;
-    }
-    return hrc;
-
-#else
-
-    ComObjPtr<CloudProvider> ptrCloudProvider;
-    HRESULT hrc = ptrCloudProvider.createObject();
-    if (aProviderName.equals("OCI"))
-    {
-        ComObjPtr<OCIUserProfiles> ptrOCIUserProfiles;
-        hrc = ptrOCIUserProfiles.createObject();
-        if (SUCCEEDED(hrc))
-        {
-            AutoReadLock wlock(this COMMA_LOCKVAL_SRC_POS);
-
-            hrc = ptrOCIUserProfiles->init(mParent);
-            if (SUCCEEDED(hrc))
-            {
-                char szOciConfigPath[RTPATH_MAX];
-                int vrc = RTPathUserHome(szOciConfigPath, sizeof(szOciConfigPath));
-                if (RT_SUCCESS(vrc))
-                    vrc = RTPathAppend(szOciConfigPath, sizeof(szOciConfigPath), ".oci" RTPATH_SLASH_STR "config");
-                if (RT_SUCCESS(vrc))
-                {
-                    LogRel(("config = %s\n", szOciConfigPath));
-                    if (RTFileExists(szOciConfigPath))
-                    {
-                        hrc = ptrOCIUserProfiles->readProfiles(szOciConfigPath);
-                        if (SUCCEEDED(hrc))
-                            LogRel(("Reading profiles from %s has been done\n", szOciConfigPath));
-                        else
-                            LogRel(("Reading profiles from %s hasn't been done\n", szOciConfigPath));
-
-                        ptrCloudProvider = ptrOCIUserProfiles;
-                        hrc = ptrCloudProvider.queryInterfaceTo(aProfiles.asOutParam());
-                    }
-                    else
-                        hrc = setErrorBoth(E_FAIL, VERR_FILE_NOT_FOUND, tr("Could not locate the config file '%s'"),
-                                           szOciConfigPath);
-                }
-                else
-                    hrc = setErrorVrc(vrc);
-            }
-        }
-    }
-
-    return hrc;
-#endif
-}
-
Index: trunk/src/VBox/Main/src-server/CloudUserProfilesImpl.cpp
===================================================================
--- trunk/src/VBox/Main/src-server/CloudUserProfilesImpl.cpp	(revision 73665)
+++ 	(revision )
@@ -1,579 +1,0 @@
-/* $Id$ */
-/** @file
- * ICloudProvider COM class implementations.
- */
-
-/*
- * Copyright (C) 2008-2018 Oracle Corporation
- *
- * This file is part of VirtualBox Open Source Edition (OSE), as
- * available from http://www.virtualbox.org. This file is free software;
- * you can redistribute it and/or modify it under the terms of the GNU
- * General Public License (GPL) as published by the Free Software
- * Foundation, in version 2 as it comes in the "COPYING" file of the
- * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
- * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
- */
-
-
-#include <iprt/path.h>
-#include <iprt/cpp/utils.h>
-#include <VBox/com/array.h>
-
-#include "CloudUserProfilesImpl.h"
-#include "VirtualBoxImpl.h"
-#include "Global.h"
-#include "ProgressImpl.h"
-#include "MachineImpl.h"
-#include "AutoCaller.h"
-#include "Logging.h"
-
-using namespace std;
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// SimpleConfigFile implementation
-//
-////////////////////////////////////////////////////////////////////////////////
-SimpleConfigFile::SimpleConfigFile(VirtualBoxBase *pSetError, const char *pszFilename)
-    : GeneralTextScript(pSetError, pszFilename)
-{
-    LogRel(("SimpleConfigFile::SimpleConfigFile(VirtualBoxBase *pSetError,...)\n"));
-}
-
-SimpleConfigFile::~SimpleConfigFile()
-{
-    LogRel(("SimpleConfigFile::~SimpleConfigFile()\n"));
-}
-
-HRESULT SimpleConfigFile::parse()
-{
-    LogRel(("Starting to parse the existing profiles\n"));
-    HRESULT hrc = S_OK;
-    hrc = GeneralTextScript::parse();
-    if (SUCCEEDED(hrc))
-    {
-        size_t lines = getLineNumbersOfScript();
-        LogRel(("Initial parsing (GeneralTextScript::parse()) was succeeded \n"));
-        LogRel(("Read lines is %d \n", lines));
-        size_t startSectionPos=0;
-        bool fInSection = false;
-        std::map <Utf8Str, Utf8Str> sectionConfiguration;
-        Utf8Str strSectionName("Default section ");
-
-        for (size_t i=0; i<lines; ++i)
-        {
-            //find the beginning of section, it starts from the line like "[section name]"
-            //next find the end of section, it ends up when we find the beginning
-            //of the next section or reach the end of the contents.
-            //Go through the found lines and split each of them up by "=".
-            //Each correct line must look like "key=value"
-            //if there is not the character "=" in the line one is skipped
-            //class Utf8Str contains the function parseKeyValue() for this action
-            LogRel(("Parsing the line %d \n", i));
-            Utf8Str strLineContent = getContentOfLine(i);
-            if (strLineContent.isEmpty() || strLineContent.startsWith("#"))
-                continue;
-
-            LogRel(("Content of the line %d is %s \n", i, strLineContent.c_str()));
-
-            //strips the white-space characters from the string. It's needed for strings on Windows with "\n\r".
-            strLineContent = strLineContent.strip();
-            if ( strLineContent.startsWith("[") && strLineContent.endsWith("]") )
-            {
-                LogRel(("Found section in the line %d\n", i));
-                if ( fInSection == true )
-                {
-                    if ( i > startSectionPos )//at least we can have here 1 line in the section
-                    {
-                        LogRel(("Add section \"%s\" to the map \n", strSectionName.c_str()));
-                        mSections.insert(make_pair(strSectionName, sectionConfiguration));
-                        sectionConfiguration.clear();
-                        strSectionName.append(Utf8StrFmt("%d",i).c_str());
-                    }
-                }
-
-                strSectionName = strLineContent.substr(strLineContent.find("[")+1,
-                                                       strLineContent.find("]")-1);
-                LogRel(("Section name is \"%s\" \n", strSectionName.c_str()));
-                fInSection = true;
-                startSectionPos = i+1;
-            }
-            else
-            {
-                if ( fInSection == true )
-                {
-                    LogRel(("Continue to parse section \"%s\" \n", strSectionName.c_str()));
-                    if ( i >= startSectionPos )
-                    {
-                        LogRel(("Extracting key and value:\n"));
-                        Utf8Str key, value;
-                        size_t offEnd = strLineContent.parseKeyValue(key, value);
-                        if (offEnd == strLineContent.length())
-                        {
-                            LogRel(("%s=%s \n", key.c_str(), value.c_str()));
-                            sectionConfiguration.insert(make_pair(key,value));
-                        }
-                        else
-                        {
-                            //else something goes wrong, skip the line
-                            LogRel(("Coudn't extract key and value from the line %d\n", i));
-                        }
-                    }
-                }
-                else
-                {
-                    LogRel(("Goes to the next line %d\n", i+1));
-                }
-            }
-        }
-
-        if (fInSection == false)//there is not any section
-        {
-            LogRel(("There are not any sections in the config\n"));
-            hrc = E_FAIL;
-        }
-        else //the last section hasn't a close tag (the close tag is just the beginning of next section)
-        {
-            //just insert the last section into the map
-            LogRel(("Add the last section %s to the map \n", strSectionName.c_str()));
-            mSections.insert(make_pair(strSectionName, sectionConfiguration));
-        }
-    }
-
-    return hrc;
-}
-
-HRESULT SimpleConfigFile::addSection(const Utf8Str &aSectionName, const std::map <Utf8Str, Utf8Str>& section)
-{
-    HRESULT hrc = S_OK;
-    if (aSectionName.isEmpty())
-        hrc = E_FAIL;
-    else
-        mSections.insert(make_pair(aSectionName, section));
-
-    return hrc;
-}
-
-std::vector <Utf8Str> SimpleConfigFile::getSectionsNames() const
-{
-    std::vector <Utf8Str> res;
-    std::map < Utf8Str, std::map <Utf8Str, Utf8Str> >::const_iterator cit = mSections.begin();
-    while (cit!=mSections.end())
-    {
-        res.push_back(cit->first);
-        ++cit;
-    }
-    return res;
-}
-
-std::map <Utf8Str, Utf8Str> SimpleConfigFile::getSectionByName (const Utf8Str &strSectionName) const
-{
-    std::map <Utf8Str, Utf8Str> res;
-    std::map < Utf8Str, std::map <Utf8Str, Utf8Str> >::const_iterator cit;
-    if ( (cit=mSections.find(strSectionName)) != mSections.end() )
-    {
-        res=cit->second;
-    }
-    return res;
-}
-
-HRESULT SimpleConfigFile::updateSection (const Utf8Str &strSectionName,
-                                         const std::map <Utf8Str, Utf8Str> &newSection)
-{
-    HRESULT hrc = S_OK;
-    std::map <Utf8Str, Utf8Str> oldSection = getSectionByName(strSectionName);
-    if (oldSection.empty())
-    {
-        //add new section
-        hrc = addSection(strSectionName, newSection);
-    }
-    else
-    {
-        //update old section by new values or add new pair key/value if there isn't such key
-        std::map <Utf8Str, Utf8Str>::const_iterator cit = newSection.begin();
-        while (cit != newSection.end())
-        {
-            oldSection[cit->first] = cit->second;
-            ++cit;
-        }
-
-    }
-    return hrc;
-}
-
-bool SimpleConfigFile::isSectionExist(const Utf8Str &strSectionName) const
-{
-    return ((mSections.find(strSectionName) == mSections.end()) ? false : true);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// ICloudProvider implementation
-//
-////////////////////////////////////////////////////////////////////////////////
-CloudProvider::CloudProvider()
-    : mParent(NULL)
-{
-}
-
-CloudProvider::~CloudProvider()
-{
-    LogRel(("CloudProvider::~CloudProvider()\n"));
-    unconst(mParent) = NULL;
-}
-
-HRESULT CloudProvider::FinalConstruct()
-{
-    return BaseFinalConstruct();
-}
-
-void CloudProvider::FinalRelease()
-{
-    uninit();
-
-    BaseFinalRelease();
-}
-
-void CloudProvider::uninit()
-{
-    /* Enclose the state transition Ready->InUninit->NotReady */
-    AutoUninitSpan autoUninitSpan(this);
-    if (autoUninitSpan.uninitDone())
-        return;
-
-    unconst(mParent) = NULL;
-}
-
-HRESULT CloudProvider::init(VirtualBox *aParent)
-{
-    /* Enclose the state transition NotReady->InInit->Ready */
-    AutoInitSpan autoInitSpan(this);
-    AssertReturn(autoInitSpan.isOk(), E_FAIL);
-
-    unconst(mParent) = aParent;
-
-    autoInitSpan.setSucceeded();
-    return S_OK;
-}
-
-
-HRESULT CloudProvider::getSupportedPropertiesNames(std::vector<com::Utf8Str> &aPropertiesNames)
-{
-    LogRel(("CloudProvider::getSupportedPropertiesNames:\n"));
-    aPropertiesNames.clear();
-    return setErrorBoth(E_FAIL, VERR_NOT_IMPLEMENTED, tr("Not implemented"));
-}
-
-HRESULT CloudProvider::readProfiles(const Utf8Str &strConfigPath)
-{
-    LogRel(("CloudProvider::readProfiles: %s\n", strConfigPath.c_str()));
-    return setErrorBoth(E_FAIL, VERR_NOT_IMPLEMENTED, tr("Not implemented"));
-}
-
-HRESULT CloudProvider::getProvider(CloudProviderId_T *aProvider)
-{
-    *aProvider = CloudProviderId_Unknown;
-    LogRel(("CloudProvider::getProvider: %d\n", *aProvider));
-    return setErrorBoth(E_FAIL, VERR_NOT_IMPLEMENTED, tr("Not implemented"));
-}
-
-HRESULT CloudProvider::createProfile(const com::Utf8Str &aProfileName,
-                                            const std::vector<com::Utf8Str> &aNames,
-                                            const std::vector<com::Utf8Str> &aValues)
-{
-    LogRel(("CloudProvider::createProfile: %s, %d, %d\n", aProfileName.c_str(), aNames.size(), aValues.size()));
-    return setErrorBoth(E_FAIL, VERR_NOT_IMPLEMENTED, tr("Not implemented"));
-}
-
-HRESULT CloudProvider::updateProfile(const com::Utf8Str &aProfileName,
-                                            const std::vector<com::Utf8Str> &aNames,
-                                            const std::vector<com::Utf8Str> &aValues)
-{
-    LogRel(("CloudProvider::updateProfile: %s, %d, %d\n", aProfileName.c_str(), aNames.size(), aValues.size()));
-    return setErrorBoth(E_FAIL, VERR_NOT_IMPLEMENTED, tr("Not implemented"));
-}
-
-HRESULT CloudProvider::getStoredProfilesNames(std::vector<com::Utf8Str> &aProfilesNames)
-{
-
-    LogRel(("CloudProvider::getStoredProfilesNames:\n"));
-    aProfilesNames.clear();
-    return setErrorBoth(E_FAIL, VERR_NOT_IMPLEMENTED, tr("Not implemented"));
-}
-
-HRESULT CloudProvider::getProfileProperties(const com::Utf8Str &aProfileName,
-                                              std::vector<com::Utf8Str> &aReturnNames,
-                                              std::vector<com::Utf8Str> &aReturnValues)
-{
-    LogRel(("CloudProvider::getProfileProperties: %s\n", aProfileName.c_str()));
-    aReturnNames.clear();
-    aReturnValues.clear();
-    return setErrorBoth(E_FAIL, VERR_NOT_IMPLEMENTED, tr("Not implemented"));
-}
-
-HRESULT CloudProvider::getPropertyDescription(const com::Utf8Str &aName,
-                                                     com::Utf8Str &aDescription)
-{
-    LogRel(("CloudProvider::getPropertyDescription: %s, %s\n", aName.c_str(), aDescription.c_str()));
-    return setErrorBoth(E_FAIL, VERR_NOT_IMPLEMENTED, tr("Not implemented"));
-}
-
-HRESULT CloudProvider::createCloudClient(const com::Utf8Str &aProfileName,
-                                                ComPtr<ICloudClient> &aCloudClient)
-{
-    LogRel(("CloudProvider::createCloudClient: %s\n", aProfileName.c_str()));
-
-    if (aCloudClient.isNull())
-    {
-        LogRel(("aCloudClient is NULL\n"));
-    }
-
-    return setErrorBoth(E_FAIL, VERR_NOT_IMPLEMENTED, tr("Not implemented"));
-}
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// CloudConnectionOCI implementation
-//
-////////////////////////////////////////////////////////////////////////////////
-static struct
-{
-    const char *pszOCIConfigEntry, *pszDesciption;
-} const g_aOCIConfigEntryToDescription[] =
-{
-    { "user",               "OCID of the user calling the API." },
-    { "tenancy",            "OCID of your tenancy." },
-    { "compartment",        "OCID of your compartment." },
-    { "fingerprint",        "Fingerprint for the key pair being used." },
-    { "key_file",           "Full path and filename of the private key."
-                            "If you encrypted the key with a passphrase, you must also include "
-                            "the pass_phrase entry in the config file."},
-    { "pass_phrase",        "Passphrase used for the key, if it is encrypted." },
-    { "region",             "An Oracle Cloud Infrastructure region" },
-};
-
-
-OCIUserProfiles::OCIUserProfiles()
-{
-    LogRel(("OCIUserProfiles::OCIUserProfiles()\n"));
-    mpProfiles = new SimpleConfigFile(mParent);
-    LogRel(("Succeeded create SimpleConfigFile\n"));
-}
-
-OCIUserProfiles::~OCIUserProfiles()
-{
-    LogRel(("OCIUserProfiles::~OCIUserProfiles()\n"));
-    if (mpProfiles)
-        delete mpProfiles;
-}
-
-HRESULT OCIUserProfiles::createCloudClient(const com::Utf8Str &aProfileName,
-                                              ComPtr<ICloudClient> &aCloudClient)
-{
-    HRESULT hrc = S_OK;
-    CloudProviderId_T providerId;
-    hrc = getProvider(&providerId);
-
-    ComObjPtr<CloudClient> ptrCloudClient;
-    hrc = ptrCloudClient.createObject();
-    if (SUCCEEDED(hrc))
-    {
-        ComObjPtr<CloudClientOCI> ptrCloudClientOCI;
-        hrc = ptrCloudClientOCI.createObject();
-        AutoReadLock wlock(this COMMA_LOCKVAL_SRC_POS);
-        hrc = ptrCloudClientOCI->initCloudClient(this, mParent, providerId, aProfileName);
-        if (SUCCEEDED(hrc))
-        {
-            ptrCloudClient = ptrCloudClientOCI;
-            hrc = ptrCloudClient.queryInterfaceTo(aCloudClient.asOutParam());
-        }
-    }
-
-    return hrc;
-}
-
-HRESULT OCIUserProfiles::readProfiles(const Utf8Str &strConfigPath)
-{
-    LogRel(("Reading profiles from %s\n", strConfigPath.c_str()));
-    HRESULT hrc = S_OK;
-    if ( !strConfigPath.isEmpty() )
-    {
-        mStrConfigPath = strConfigPath;
-        hrc = mpProfiles->read(mStrConfigPath);
-        if (SUCCEEDED(hrc))
-        {
-            LogRel(("Successfully read the profiles from the config %s\n", mStrConfigPath.c_str()));
-            hrc = mpProfiles->parse();
-            if (FAILED(hrc))
-            {
-                return hrc;
-            }
-            LogRel(("Successfully parsed %d profiles\n", mpProfiles->getNumberOfSections()));
-        }
-    }
-    else
-    {
-        LogRel(("Empty path to config file\n"));
-        hrc = setErrorBoth(E_FAIL, VERR_INVALID_PARAMETER, tr("Empty path to config file"));
-    }
-
-    return hrc;
-}
-
-HRESULT OCIUserProfiles::createProfile(const com::Utf8Str &aProfileName,
-                                          const std::vector<com::Utf8Str> &aNames,
-                                          const std::vector<com::Utf8Str> &aValues)
-{
-    HRESULT hrc = S_OK;
-
-    if (!mpProfiles->isSectionExist(aProfileName))
-    {
-        std::map <Utf8Str, Utf8Str> newProfile;
-
-        for (size_t i=0;i<aNames.size();++i)
-        {
-            com::Utf8Str newValue = (i<aValues.size()) ? aValues.at(i) : "";
-            newProfile[aNames.at(i)] = newValue;
-        }
-
-        hrc = mpProfiles->addSection(aProfileName, newProfile);
-    }
-    else
-        hrc = setErrorBoth(E_FAIL, VERR_ALREADY_EXISTS, tr("Profile '%s' has already exested"), aProfileName.c_str());
-
-    return hrc;
-}
-
-HRESULT OCIUserProfiles::updateProfile(const com::Utf8Str &aProfileName,
-                                          const std::vector<com::Utf8Str> &aNames,
-                                          const std::vector<com::Utf8Str> &aValues)
-{
-    HRESULT hrc = S_OK;
-    if (mpProfiles->isSectionExist(aProfileName))
-    {
-        std::map <Utf8Str, Utf8Str> newProfile;
-
-        for (size_t i=0;i<aNames.size();++i)
-        {
-            com::Utf8Str newValue = (i<aValues.size()) ? aValues.at(i) : "";
-            newProfile[aNames.at(i)] = newValue;
-        }
-
-        hrc = mpProfiles->updateSection(aProfileName, newProfile);
-    }
-    else
-        hrc = setErrorBoth(E_FAIL, VERR_NOT_FOUND, tr("Profile '%s' wasn't found"), aProfileName.c_str());
-
-    return hrc;
-}
-
-HRESULT OCIUserProfiles::getStoredProfilesNames(std::vector<com::Utf8Str> &aProfilesNames)
-{
-    HRESULT hrc = S_OK;
-    aProfilesNames = mpProfiles->getSectionsNames();
-    if (aProfilesNames.empty())
-        hrc = setErrorBoth(E_FAIL, VERR_NOT_FOUND, tr("There aren't any profiles in the config"));
-
-    return hrc;
-}
-
-HRESULT OCIUserProfiles::getProfileProperties(const com::Utf8Str &aProfileName,
-                                                 std::vector<com::Utf8Str> &aReturnNames,
-                                                 std::vector<com::Utf8Str> &aReturnValues)
-{
-    HRESULT hrc = S_OK;
-
-    if (mpProfiles->isSectionExist(aProfileName))
-    {
-        std::map <Utf8Str, Utf8Str> profile;
-        hrc = i_getProfileProperties(aProfileName, profile);
-        if (SUCCEEDED(hrc))
-        {
-            aReturnNames.clear();
-            aReturnValues.clear();
-            std::map <Utf8Str, Utf8Str>::const_iterator cit = profile.begin();
-            while (cit!=profile.end())
-            {
-                aReturnNames.push_back(cit->first);
-                aReturnValues.push_back(cit->second);
-                ++cit;
-            }
-        }
-    }
-    else
-        hrc = setErrorBoth(E_FAIL, VERR_NOT_FOUND, tr("Profile '%s' wasn't found"), aProfileName.c_str());
-
-    return hrc;
-}
-
-HRESULT OCIUserProfiles::getSupportedPropertiesNames(std::vector<com::Utf8Str> &aPropertiesNames)
-{
-    HRESULT hrc = S_OK;
-    for (size_t i = 0; i < RT_ELEMENTS(g_aOCIConfigEntryToDescription); ++i)
-        aPropertiesNames.push_back(g_aOCIConfigEntryToDescription[i].pszOCIConfigEntry);
-    return hrc;
-}
-
-HRESULT OCIUserProfiles::getPropertyDescription(const com::Utf8Str &aName, com::Utf8Str &aDescription)
-{
-    HRESULT hrc = S_OK;
-    for (size_t i = 0; i < RT_ELEMENTS(g_aOCIConfigEntryToDescription); ++i)
-        if (aName.contains(g_aOCIConfigEntryToDescription[i].pszOCIConfigEntry, Utf8Str::CaseInsensitive))
-        {
-            aDescription = g_aOCIConfigEntryToDescription[i].pszDesciption;
-        }
-    return hrc;
-}
-
-
-HRESULT OCIUserProfiles::i_createProfile(const com::Utf8Str &aProfileName,
-                                           const std::map <Utf8Str, Utf8Str> &aProfile)
-{
-    HRESULT hrc = S_OK;
-
-    hrc = mpProfiles->addSection(aProfileName, aProfile);
-
-    return hrc;
-}
-
-HRESULT OCIUserProfiles::i_updateProfile(const com::Utf8Str &aProfileName,
-                                           const std::map <Utf8Str, Utf8Str> &aProfile)
-{
-    HRESULT hrc = S_OK;
-    if (mpProfiles->isSectionExist(aProfileName))
-        hrc = mpProfiles->updateSection(aProfileName, aProfile);
-    else
-        hrc = setErrorBoth(E_FAIL, VERR_NOT_FOUND, tr("Profile '%s' wasn't found"), aProfileName.c_str());
-
-
-    return hrc;
-}
-
-HRESULT OCIUserProfiles::i_getProfileProperties(const com::Utf8Str &aProfileName,
-                                                  std::map <Utf8Str, Utf8Str> &aProfile)
-{
-    HRESULT hrc = S_OK;
-    std::map <Utf8Str, Utf8Str> defProfile = mpProfiles->getSectionByName("DEFAULT");
-    std::map <Utf8Str, Utf8Str> reqProfile = mpProfiles->getSectionByName(aProfileName);
-
-    std::map <Utf8Str, Utf8Str>::iterator itDefProfile = defProfile.begin();
-    while (itDefProfile != defProfile.end())
-    {
-        std::map <Utf8Str, Utf8Str>::iterator itProfile = reqProfile.find(itDefProfile->first);
-        if (itProfile == reqProfile.end())
-        {
-            //Add a key=value pair from defProfile into the reqProfile if the key doesn't exist in the reqProfile.
-            reqProfile.insert(*itDefProfile);
-        }
-        ++itDefProfile;
-    }
-
-    if (!reqProfile.empty())
-        aProfile = reqProfile;
-    else
-        hrc = setErrorBoth(E_FAIL, VERR_NOT_FOUND, tr("Profile '%s' wasn't found"), aProfileName.c_str());
-
-    return hrc;
-}
-
Index: trunk/src/VBox/Main/src-server/OCIProfile.cpp
===================================================================
--- trunk/src/VBox/Main/src-server/OCIProfile.cpp	(revision 73716)
+++ trunk/src/VBox/Main/src-server/OCIProfile.cpp	(revision 73716)
@@ -0,0 +1,238 @@
+/* $Id$ */
+/** @file
+ * ICloudProfile COM class implementation (OCI).
+ */
+
+/*
+ * Copyright (C) 2008-2018 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ */
+
+#include "OCIProfile.h"
+#include "OCIProvider.h"
+#include "CloudClientImpl.h"
+#include "AutoCaller.h"
+#define LOG_GROUP_MAIN_OVERRIDE LOG_GROUP_MAIN_CLOUDPROFILE
+#include "Logging.h"
+
+#include <iprt/cpp/utils.h>
+
+
+////////////////////////////////////////////////////////////////////////////////
+//
+// OCIProfile implementation
+//
+////////////////////////////////////////////////////////////////////////////////
+OCIProfile::OCIProfile()
+    : mVirtualBox(NULL), mParent(NULL)
+{
+}
+
+OCIProfile::~OCIProfile()
+{
+    LogRel(("OCIProfile::~OCIProfile()\n"));
+    unconst(mVirtualBox) = NULL;
+    unconst(mParent).setNull();
+}
+
+HRESULT OCIProfile::FinalConstruct()
+{
+    return BaseFinalConstruct();
+}
+
+void OCIProfile::FinalRelease()
+{
+    uninit();
+
+    BaseFinalRelease();
+}
+
+void OCIProfile::uninit()
+{
+    // Enclose the state transition Ready->InUninit->NotReady.
+    AutoUninitSpan autoUninitSpan(this);
+    if (autoUninitSpan.uninitDone())
+        return;
+
+    unconst(mVirtualBox) = NULL;
+    unconst(mParent).setNull();
+}
+
+HRESULT OCIProfile::initFromConfig(VirtualBox *aVirtualBox,
+                                   OCIProvider *aParent,
+                                   const com::Utf8Str &aProfileName)
+{
+    // Enclose the state transition NotReady->InInit->Ready.
+    AutoInitSpan autoInitSpan(this);
+    AssertReturn(autoInitSpan.isOk(), E_FAIL);
+#ifndef VBOX_WITH_CLOUD_PROVIDERS_IN_EXTPACK
+    AssertReturn(aVirtualBox, E_INVALIDARG);
+#endif
+    AssertReturn(aParent, E_INVALIDARG);
+    AssertReturn(!aProfileName.isEmpty(), E_INVALIDARG);
+
+    unconst(mVirtualBox) = aVirtualBox;
+    unconst(mParent) = aParent;
+    unconst(mName) = aProfileName;
+
+    autoInitSpan.setSucceeded();
+    return S_OK;
+}
+
+HRESULT OCIProfile::initNew(VirtualBox *aVirtualBox,
+                            OCIProvider *aParent,
+                            const com::Utf8Str &aProfileName,
+                            const std::vector<com::Utf8Str> &aNames,
+                            const std::vector<com::Utf8Str> &aValues)
+{
+    // Enclose the state transition NotReady->InInit->Ready.
+    AutoInitSpan autoInitSpan(this);
+    AssertReturn(autoInitSpan.isOk(), E_FAIL);
+#ifndef VBOX_WITH_CLOUD_PROVIDERS_IN_EXTPACK
+    AssertReturn(aVirtualBox, E_INVALIDARG);
+#endif
+    AssertReturn(aParent, E_INVALIDARG);
+    AssertReturn(!aProfileName.isEmpty(), E_INVALIDARG);
+
+    unconst(mVirtualBox) = aVirtualBox;
+    unconst(mParent) = aParent;
+    unconst(mName) = aProfileName;
+
+    HRESULT hrc = S_OK;
+    if (!aParent->i_existsProfile(aProfileName))
+        hrc = aParent->i_addProfile(aProfileName, aNames, aValues);
+    else
+        hrc = setError(E_FAIL, tr("Profile '%s' already exists"), aProfileName.c_str());
+
+    if (SUCCEEDED(hrc))
+        autoInitSpan.setSucceeded();
+    return hrc;
+}
+
+void OCIProfile::i_getProfile(StringMap &aProfile) const
+{
+    AutoCaller autoCaller(mParent);
+    if (FAILED(autoCaller.rc()))
+        return;
+    AutoReadLock plock(mParent COMMA_LOCKVAL_SRC_POS);
+
+    mParent->i_getProfileMap(mName, aProfile);
+}
+
+
+static struct
+{
+    const char *pszOCIConfigEntry, *pszDesciption;
+} const g_aOCIConfigEntryToDescription[] =
+{
+    { "user",               "OCID of the user calling the API." },
+    { "tenancy",            "OCID of your tenancy." },
+    { "compartment",        "OCID of your compartment." },
+    { "fingerprint",        "Fingerprint for the key pair being used." },
+    { "key_file",           "Full path and filename of the private key."
+                            "If you encrypted the key with a passphrase, you must also include "
+                            "the pass_phrase entry in the config file."},
+    { "pass_phrase",        "Passphrase used for the key, if it is encrypted." },
+    { "region",             "An Oracle Cloud Infrastructure region" },
+};
+
+
+HRESULT OCIProfile::getName(com::Utf8Str &aName)
+{
+    // mName is constant during life time, no need to lock.
+    aName = mName;
+    return S_OK;
+}
+
+HRESULT OCIProfile::getProviderId(com::Guid &aProviderId)
+{
+    // provider id is constant during life time, no need to lock.
+    aProviderId = mParent->i_getId();
+    return S_OK;
+}
+
+HRESULT OCIProfile::getSupportedPropertyNames(std::vector<com::Utf8Str> &aSupportedPropertyNames)
+{
+    // g_aOCIConfigEntryToDescription is constant during life time, no need to lock.
+    for (size_t i = 0; i < RT_ELEMENTS(g_aOCIConfigEntryToDescription); ++i)
+        aSupportedPropertyNames.push_back(g_aOCIConfigEntryToDescription[i].pszOCIConfigEntry);
+    return S_OK;
+}
+
+HRESULT OCIProfile::getProperty(const com::Utf8Str &aName,
+                                Utf8Str &aReturnValue)
+{
+    AutoCaller autoCaller(mParent);
+    if (FAILED(autoCaller.rc()))
+        return autoCaller.rc();
+    AutoReadLock alock(mParent COMMA_LOCKVAL_SRC_POS);
+    mParent->i_getProfileProperty(mName, aName, aReturnValue);
+    return S_OK;
+}
+
+HRESULT OCIProfile::setProperty(const com::Utf8Str &aName,
+                                const com::Utf8Str &aValue)
+{
+    AutoCaller autoCaller(mParent);
+    if (FAILED(autoCaller.rc()))
+        return autoCaller.rc();
+    AutoWriteLock alock(mParent COMMA_LOCKVAL_SRC_POS);
+    mParent->i_updateProfileProperty(mName, aName, aValue);
+    return S_OK;
+}
+
+HRESULT OCIProfile::getProperties(const com::Utf8Str &aNames,
+                                  std::vector<com::Utf8Str> &aReturnNames,
+                                  std::vector<com::Utf8Str> &aReturnValues)
+{
+    AutoCaller autoCaller(mParent);
+    if (FAILED(autoCaller.rc()))
+        return autoCaller.rc();
+    AutoReadLock alock(mParent COMMA_LOCKVAL_SRC_POS);
+    /// @todo: implement name filtering (everywhere... lots of similar code in many places handling properties. */
+    RT_NOREF(aNames);
+    mParent->i_getProfile(mName, aReturnNames, aReturnValues);
+    return S_OK;
+}
+
+HRESULT OCIProfile::setProperties(const std::vector<com::Utf8Str> &aNames,
+                                  const std::vector<com::Utf8Str> &aValues)
+{
+    AutoCaller autoCaller(mParent);
+    if (FAILED(autoCaller.rc()))
+        return autoCaller.rc();
+    AutoWriteLock alock(mParent COMMA_LOCKVAL_SRC_POS);
+    return mParent->i_updateProfile(mName, aNames, aValues);
+}
+
+HRESULT OCIProfile::getPropertyDescription(const com::Utf8Str &aName, com::Utf8Str &aDescription)
+{
+    // g_aOCIConfigEntryToDescription is constant during life time, no need to lock.
+    for (size_t i = 0; i < RT_ELEMENTS(g_aOCIConfigEntryToDescription); ++i)
+        if (aName.contains(g_aOCIConfigEntryToDescription[i].pszOCIConfigEntry, Utf8Str::CaseInsensitive))
+        {
+            aDescription = g_aOCIConfigEntryToDescription[i].pszDesciption;
+        }
+    return S_OK;
+}
+
+
+HRESULT OCIProfile::createCloudClient(ComPtr<ICloudClient> &aCloudClient)
+{
+    ComObjPtr<CloudClientOCI> pCloudClientOCI;
+    HRESULT hrc = pCloudClientOCI.createObject();
+    if (FAILED(hrc))
+        return hrc;
+    hrc = pCloudClientOCI->initCloudClient(mVirtualBox, this);
+    if (SUCCEEDED(hrc))
+        hrc = pCloudClientOCI.queryInterfaceTo(aCloudClient.asOutParam());
+
+    return hrc;
+}
Index: trunk/src/VBox/Main/src-server/UnattendedScript.cpp
===================================================================
--- trunk/src/VBox/Main/src-server/UnattendedScript.cpp	(revision 73665)
+++ trunk/src/VBox/Main/src-server/UnattendedScript.cpp	(revision 73716)
@@ -196,4 +196,6 @@
     return hrc;
 }
+
+#ifdef VBOX_WITH_UNATTENDED
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -636,4 +638,6 @@
 }
 
+#endif /* VBOX_WITH_UNATTENDED */
+
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////
Index: trunk/src/VBox/Main/src-server/VirtualBoxImpl.cpp
===================================================================
--- trunk/src/VBox/Main/src-server/VirtualBoxImpl.cpp	(revision 73665)
+++ trunk/src/VBox/Main/src-server/VirtualBoxImpl.cpp	(revision 73716)
@@ -80,5 +80,5 @@
 #include "Logging.h"
 
-# include "CloudUserProfileManagerImpl.h"
+# include "CloudProviderManagerImpl.h"
 
 #include <QMTranslator.h>
@@ -300,4 +300,7 @@
 #endif
 
+    /** The reference to the cloud provider manager singleton. */
+    const ComObjPtr<CloudProviderManager> pCloudProviderManager;
+
     /** The global autostart database for the user. */
     AutostartDb * const                 pAutostartDb;
@@ -472,6 +475,7 @@
 
         /* create the system properties object, someone may need it too */
-        unconst(m->pSystemProperties).createObject();
-        rc = m->pSystemProperties->init(this);
+        rc = unconst(m->pSystemProperties).createObject();
+        if (SUCCEEDED(rc))
+            rc = m->pSystemProperties->init(this);
         ComAssertComRCThrowRC(rc);
 
@@ -545,4 +549,11 @@
         if (SUCCEEDED(rc = unconst(m->pEventSource).createObject()))
             rc = m->pEventSource->init();
+        if (FAILED(rc)) throw rc;
+
+        /* cloud provider manager */
+        rc = unconst(m->pCloudProviderManager).createObject();
+        if (SUCCEEDED(rc))
+            rc = m->pCloudProviderManager->init(this);
+        ComAssertComRCThrowRC(rc);
         if (FAILED(rc)) throw rc;
     }
@@ -807,4 +818,10 @@
      * uninitializing (as for example, mSystemProperties which owns
      * MediumFormat objects which Medium objects refer to) */
+    if (m->pCloudProviderManager)
+    {
+        m->pCloudProviderManager->uninit();
+        unconst(m->pCloudProviderManager).setNull();
+    }
+
     if (m->pSystemProperties)
     {
@@ -826,4 +843,12 @@
     }
 #endif /* VBOX_WITH_RESOURCE_USAGE_API */
+
+#ifdef VBOX_WITH_EXTPACK
+    if (m->ptrExtPackManager)
+    {
+        m->ptrExtPackManager->uninit();
+        unconst(m->ptrExtPackManager).setNull();
+    }
+#endif
 
     LogFlowThisFunc(("Terminating the async event handler...\n"));
@@ -1235,4 +1260,10 @@
 
     return S_OK;
+}
+
+HRESULT VirtualBox::getCloudProviderManager(ComPtr<ICloudProviderManager> &aCloudProviderManager)
+{
+    HRESULT hrc = m->pCloudProviderManager.queryInterfaceTo(aCloudProviderManager.asOutParam());
+    return hrc;
 }
 
@@ -1820,18 +1851,4 @@
 }
 
-HRESULT VirtualBox::createCloudProviderManager(ComPtr<ICloudProviderManager> &aManager)
-{
-    ComObjPtr<CloudProviderManager> ptrCloudProviderManager;
-    HRESULT hrc = ptrCloudProviderManager.createObject();
-    if (SUCCEEDED(hrc))
-    {
-        AutoReadLock wlock(this COMMA_LOCKVAL_SRC_POS);
-        hrc = ptrCloudProviderManager->init(this);
-        if (SUCCEEDED(hrc))
-            hrc = ptrCloudProviderManager.queryInterfaceTo(aManager.asOutParam());
-    }
-    return hrc;
-}
-
 HRESULT VirtualBox::createMedium(const com::Utf8Str &aFormat,
                                  const com::Utf8Str &aLocation,
@@ -5197,6 +5214,6 @@
     return rc;
 #else
-    NOREF(aName);
-    NOREF(aNatNetwork);
+    NOREF(aNetworkName);
+    NOREF(aNetwork);
     return E_NOTIMPL;
 #endif
@@ -5233,6 +5250,6 @@
     return rc;
 #else
-    NOREF(aName);
     NOREF(aNetworkName);
+    NOREF(aNetwork);
     return E_NOTIMPL;
 #endif
