From ba7492ebe6f943976fc41274672ec41c035b4fbb Mon Sep 17 00:00:00 2001 From: Ivan Safonov Date: Wed, 23 Aug 2017 23:04:12 +0300 Subject: tdf#46037: Replace ConfigurationHelper with new configuration API Remove all occurences of ConfigurationHelper in /framework/source/services/autorecovery.cxx. com.sun.star.configuration.ConfigurationAccess used only to receive configuration updates. In the second version of the patch corrected the indentation and fdo replaced with tdf in the patch title. comphelper::ConfigurationChanges::create returns shared_ptr, using unique_ptr can result in bugs. Also rebase this patch. Change-Id: I27d34dd4d4b59e2e9cc701d4726bcd7f5fb45b3c Reviewed-on: https://gerrit.libreoffice.org/41477 Tested-by: Jenkins Reviewed-by: Stephan Bergmann --- framework/source/services/autorecovery.cxx | 272 +++++++++++------------------ 1 file changed, 105 insertions(+), 167 deletions(-) (limited to 'framework/source') diff --git a/framework/source/services/autorecovery.cxx b/framework/source/services/autorecovery.cxx index ae1558256933..bde4a609c068 100644 --- a/framework/source/services/autorecovery.cxx +++ b/framework/source/services/autorecovery.cxx @@ -33,6 +33,7 @@ #include #include +#include #include #include #include @@ -69,7 +70,7 @@ #include #include -#include +#include #include #include #include @@ -93,6 +94,8 @@ #include #include #include +#include +#include #include #include @@ -529,15 +532,12 @@ private: m_xCFG, open it on demand and cache it afterwards. - @return [com.sun.star.container.XNameAccess] - the configuration object - @throw [com.sun.star.uno.RuntimeException] if config could not be opened successfully! @threadsafe */ - css::uno::Reference< css::container::XNameAccess > implts_openConfig(); + void implts_openConfig(); /** @short read the underlying configuration. @@ -988,21 +988,10 @@ private: // recovery.xcu static const char CFG_PACKAGE_RECOVERY[] = "org.openoffice.Office.Recovery/"; -static const char CFG_ENTRY_RECOVERYLIST[] = "RecoveryList"; -static const char CFG_PATH_RECOVERYINFO[] = "RecoveryInfo"; -static const char CFG_ENTRY_CRASHED[] = "Crashed"; -static const char CFG_ENTRY_SESSIONDATA[] = "SessionData"; static const char CFG_ENTRY_AUTOSAVE_ENABLED[] = "AutoSave/Enabled"; static const char CFG_ENTRY_AUTOSAVE_TIMEINTERVALL[] = "AutoSave/TimeIntervall"; //sic! -static const char CFG_ENTRY_USERAUTOSAVE_ENABLED[] = "AutoSave/UserAutoSaveEnabled"; - -static const char CFG_PATH_AUTOSAVE[] = "AutoSave"; -static const char CFG_ENTRY_MINSPACE_DOCSAVE[] = "MinSpaceDocSave"; -static const char CFG_ENTRY_MINSPACE_CONFIGSAVE[] = "MinSpaceConfigSave"; - -static const char CFG_PACKAGE_MODULES[] = "org.openoffice.Setup/Office/Factories"; static const char CFG_ENTRY_REALDEFAULTFILTER[] = "ooSetupFactoryActualFilter"; static const char CFG_ENTRY_PROP_TEMPURL[] = "TempURL"; @@ -1698,39 +1687,40 @@ void SAL_CALL AutoRecovery::disposing(const css::lang::EventObject& aEvent) } /* SAFE */ } -css::uno::Reference< css::container::XNameAccess > AutoRecovery::implts_openConfig() +void AutoRecovery::implts_openConfig() { /* SAFE */ { osl::MutexGuard g(cppu::WeakComponentImplHelperBase::rBHelper.rMutex); if (m_xRecoveryCFG.is()) - return m_xRecoveryCFG; - + return; } /* SAFE */ - OUString sCFG_PACKAGE_RECOVERY(CFG_PACKAGE_RECOVERY); + css::uno::Reference xConfigProvider( + css::configuration::theDefaultProvider::get(m_xContext)); + + std::vector lParams; + css::beans::PropertyValue aParam; + + // set root path + aParam.Name = "nodepath"; + aParam.Value <<= OUString(CFG_PACKAGE_RECOVERY); + lParams.push_back(css::uno::Any(aParam)); + // throws a RuntimeException if an error occurs! - css::uno::Reference< css::container::XNameAccess > xCFG( - ::comphelper::ConfigurationHelper::openConfig(m_xContext, sCFG_PACKAGE_RECOVERY, ::comphelper::EConfigurationModes::Standard), - css::uno::UNO_QUERY); + css::uno::Reference xCFG( + xConfigProvider->createInstanceWithArguments( + "com.sun.star.configuration.ConfigurationAccess", + comphelper::containerToSequence(lParams)), + css::uno::UNO_QUERY); sal_Int32 nMinSpaceDocSave = MIN_DISCSPACE_DOCSAVE; sal_Int32 nMinSpaceConfigSave = MIN_DISCSPACE_CONFIGSAVE; try { - OUString sCFG_PATH_AUTOSAVE(CFG_PATH_AUTOSAVE); - ::comphelper::ConfigurationHelper::readDirectKey(m_xContext, - sCFG_PACKAGE_RECOVERY, - sCFG_PATH_AUTOSAVE, - CFG_ENTRY_MINSPACE_DOCSAVE, - ::comphelper::EConfigurationModes::Standard) >>= nMinSpaceDocSave; - - ::comphelper::ConfigurationHelper::readDirectKey(m_xContext, - sCFG_PACKAGE_RECOVERY, - sCFG_PATH_AUTOSAVE, - CFG_ENTRY_MINSPACE_CONFIGSAVE, - ::comphelper::EConfigurationModes::Standard) >>= nMinSpaceConfigSave; + nMinSpaceDocSave = officecfg::Office::Recovery::AutoSave::MinSpaceDocSave::get(m_xContext); + nMinSpaceConfigSave = officecfg::Office::Recovery::AutoSave::MinSpaceConfigSave::get(m_xContext); } catch(const css::uno::Exception&) { @@ -1746,26 +1736,21 @@ css::uno::Reference< css::container::XNameAccess > AutoRecovery::implts_openConf m_nMinSpaceDocSave = nMinSpaceDocSave; m_nMinSpaceConfigSave = nMinSpaceConfigSave; } /* SAFE */ - - return xCFG; } void AutoRecovery::implts_readAutoSaveConfig() { - css::uno::Reference< css::container::XHierarchicalNameAccess > xCommonRegistry(implts_openConfig(), css::uno::UNO_QUERY); + implts_openConfig(); // AutoSave [bool] - bool bEnabled = false; - xCommonRegistry->getByHierarchicalName(CFG_ENTRY_AUTOSAVE_ENABLED) >>= bEnabled; - - // UserAutoSave [bool] - bool bUserEnabled = false; - xCommonRegistry->getByHierarchicalName(CFG_ENTRY_USERAUTOSAVE_ENABLED) >>= bUserEnabled; + bool bEnabled(officecfg::Office::Recovery::AutoSave::Enabled::get(m_xContext)); /* SAFE */ { osl::MutexGuard g(cppu::WeakComponentImplHelperBase::rBHelper.rMutex); if (bEnabled) { + bool bUserEnabled(officecfg::Office::Recovery::AutoSave::UserAutoSaveEnabled::get(m_xContext)); + m_eJob |= AutoRecovery::E_AUTO_SAVE; m_eTimerType = AutoRecovery::E_NORMAL_AUTOSAVE_INTERVALL; @@ -1786,8 +1771,7 @@ void AutoRecovery::implts_readAutoSaveConfig() } /* SAFE */ // AutoSaveTimeIntervall [int] in min - sal_Int32 nTimeIntervall = 10; - xCommonRegistry->getByHierarchicalName(CFG_ENTRY_AUTOSAVE_TIMEINTERVALL) >>= nTimeIntervall; + sal_Int32 nTimeIntervall(officecfg::Office::Recovery::AutoSave::TimeIntervall::get(m_xContext)); /* SAFE */ { osl::MutexGuard g(cppu::WeakComponentImplHelperBase::rBHelper.rMutex); @@ -1799,8 +1783,6 @@ void AutoRecovery::implts_readConfig() { implts_readAutoSaveConfig(); - css::uno::Reference< css::container::XHierarchicalNameAccess > xCommonRegistry(implts_openConfig(), css::uno::UNO_QUERY); - // REENTRANT -> -------------------------------- CacheLockGuard aCacheLock(this, cppu::WeakComponentImplHelperBase::rBHelper.rMutex, m_nDocCacheLock, LOCK_FOR_CACHE_ADD_REMOVE); @@ -1814,70 +1796,63 @@ void AutoRecovery::implts_readConfig() aCacheLock.unlock(); // <- REENTRANT -------------------------------- - css::uno::Any aValue; + css::uno::Reference xRecoveryList( + officecfg::Office::Recovery::RecoveryList::get(m_xContext)); + const OUString sRECOVERY_ITEM_BASE_IDENTIFIER(RECOVERY_ITEM_BASE_IDENTIFIER); + const css::uno::Sequence< OUString > lItems = xRecoveryList->getElementNames(); + const OUString* pItems = lItems.getConstArray(); + sal_Int32 c = lItems.getLength(); + sal_Int32 i = 0; - // RecoveryList [set] - aValue = xCommonRegistry->getByHierarchicalName(CFG_ENTRY_RECOVERYLIST); - css::uno::Reference< css::container::XNameAccess > xList; - aValue >>= xList; - if (xList.is()) - { - const OUString sRECOVERY_ITEM_BASE_IDENTIFIER(RECOVERY_ITEM_BASE_IDENTIFIER); - const css::uno::Sequence< OUString > lItems = xList->getElementNames(); - const OUString* pItems = lItems.getConstArray(); - sal_Int32 c = lItems.getLength(); - sal_Int32 i = 0; + // REENTRANT -> -------------------------- + aCacheLock.lock(LOCK_FOR_CACHE_ADD_REMOVE); - // REENTRANT -> -------------------------- - aCacheLock.lock(LOCK_FOR_CACHE_ADD_REMOVE); + for (i=0; i xItem; + xRecoveryList->getByName(pItems[i]) >>= xItem; + if (!xItem.is()) + continue; - for (i=0; igetPropertyValue(CFG_ENTRY_PROP_ORIGINALURL) >>= aInfo.OrgURL; + xItem->getPropertyValue(CFG_ENTRY_PROP_TEMPURL) >>= aInfo.OldTempURL; + xItem->getPropertyValue(CFG_ENTRY_PROP_TEMPLATEURL) >>= aInfo.TemplateURL; + xItem->getPropertyValue(CFG_ENTRY_PROP_FILTER) >>= aInfo.RealFilter; + xItem->getPropertyValue(CFG_ENTRY_PROP_DOCUMENTSTATE) >>= aInfo.DocumentState; + xItem->getPropertyValue(CFG_ENTRY_PROP_MODULE) >>= aInfo.AppModule; + xItem->getPropertyValue(CFG_ENTRY_PROP_TITLE) >>= aInfo.Title; + xItem->getPropertyValue(CFG_ENTRY_PROP_VIEWNAMES) >>= aInfo.ViewNames; + implts_specifyAppModuleAndFactory(aInfo); + implts_specifyDefaultFilterAndExtension(aInfo); + + if (pItems[i].startsWith(sRECOVERY_ITEM_BASE_IDENTIFIER)) { - css::uno::Reference< css::beans::XPropertySet > xItem; - xList->getByName(pItems[i]) >>= xItem; - if (!xItem.is()) - continue; - - AutoRecovery::TDocumentInfo aInfo; - aInfo.NewTempURL.clear(); - aInfo.Document.clear(); - xItem->getPropertyValue(CFG_ENTRY_PROP_ORIGINALURL) >>= aInfo.OrgURL; - xItem->getPropertyValue(CFG_ENTRY_PROP_TEMPURL) >>= aInfo.OldTempURL; - xItem->getPropertyValue(CFG_ENTRY_PROP_TEMPLATEURL) >>= aInfo.TemplateURL; - xItem->getPropertyValue(CFG_ENTRY_PROP_FILTER) >>= aInfo.RealFilter; - xItem->getPropertyValue(CFG_ENTRY_PROP_DOCUMENTSTATE) >>= aInfo.DocumentState; - xItem->getPropertyValue(CFG_ENTRY_PROP_MODULE) >>= aInfo.AppModule; - xItem->getPropertyValue(CFG_ENTRY_PROP_TITLE) >>= aInfo.Title; - xItem->getPropertyValue(CFG_ENTRY_PROP_VIEWNAMES) >>= aInfo.ViewNames; - implts_specifyAppModuleAndFactory(aInfo); - implts_specifyDefaultFilterAndExtension(aInfo); - - if (pItems[i].startsWith(sRECOVERY_ITEM_BASE_IDENTIFIER)) - { - OUString sID = pItems[i].copy(sRECOVERY_ITEM_BASE_IDENTIFIER.getLength()); - aInfo.ID = sID.toInt32(); - /* SAFE */ { - osl::MutexGuard g(cppu::WeakComponentImplHelperBase::rBHelper.rMutex); - if (aInfo.ID > m_nIdPool) - { - m_nIdPool = aInfo.ID+1; - SAL_WARN_IF(m_nIdPool<0, "fwk.autorecovery", "AutoRecovery::implts_readConfig(): Overflow of IDPool detected!"); - } - } /* SAFE */ - } - else - SAL_INFO("fwk.autorecovery", "AutoRecovery::implts_readConfig(): Who changed numbering of recovery items? Cache will be inconsistent then! I do not know, what will happen next time .-)"); - + OUString sID = pItems[i].copy(sRECOVERY_ITEM_BASE_IDENTIFIER.getLength()); + aInfo.ID = sID.toInt32(); /* SAFE */ { osl::MutexGuard g(cppu::WeakComponentImplHelperBase::rBHelper.rMutex); - m_lDocCache.push_back(aInfo); + if (aInfo.ID > m_nIdPool) + { + m_nIdPool = aInfo.ID+1; + SAL_WARN_IF(m_nIdPool<0, "fwk.autorecovery", "AutoRecovery::implts_readConfig(): Overflow of IDPool detected!"); + } } /* SAFE */ } + else + SAL_INFO("fwk.autorecovery", "AutoRecovery::implts_readConfig(): Who changed numbering of recovery items? Cache will be inconsistent then! I do not know, what will happen next time .-)"); - aCacheLock.unlock(); - // <- REENTRANT -------------------------- + /* SAFE */ { + osl::MutexGuard g(cppu::WeakComponentImplHelperBase::rBHelper.rMutex); + m_lDocCache.push_back(aInfo); + } /* SAFE */ } + aCacheLock.unlock(); + // <- REENTRANT -------------------------- + implts_updateTimer(); } @@ -1900,10 +1875,10 @@ void AutoRecovery::implts_specifyDefaultFilterAndExtension(AutoRecovery::TDocume { if (! xCFG.is()) { + implts_openConfig(); // open module config on demand and cache the update access - xCFG.set( ::comphelper::ConfigurationHelper::openConfig(m_xContext, CFG_PACKAGE_MODULES, - ::comphelper::EConfigurationModes::Standard), - css::uno::UNO_QUERY_THROW); + xCFG.set(officecfg::Setup::Office::Factories::get(m_xContext), + css::uno::UNO_QUERY_THROW); /* SAFE */ { osl::MutexGuard g2(cppu::WeakComponentImplHelperBase::rBHelper.rMutex); @@ -2016,14 +1991,15 @@ void AutoRecovery::implts_persistAllActiveViewNames() void AutoRecovery::implts_flushConfigItem(const AutoRecovery::TDocumentInfo& rInfo, bool bRemoveIt) { - css::uno::Reference< css::container::XHierarchicalNameAccess > xCFG; + std::shared_ptr batch( + comphelper::ConfigurationChanges::create(m_xContext)); try { - xCFG.set(implts_openConfig(), css::uno::UNO_QUERY_THROW); + implts_openConfig(); - css::uno::Reference< css::container::XNameAccess > xCheck; - xCFG->getByHierarchicalName(CFG_ENTRY_RECOVERYLIST) >>= xCheck; + css::uno::Reference xCheck( + officecfg::Office::Recovery::RecoveryList::get(batch)); css::uno::Reference< css::container::XNameContainer > xModify(xCheck, css::uno::UNO_QUERY_THROW); css::uno::Reference< css::lang::XSingleServiceFactory > xCreate(xCheck, css::uno::UNO_QUERY_THROW); @@ -2085,8 +2061,7 @@ void AutoRecovery::implts_flushConfigItem(const AutoRecovery::TDocumentInfo& rIn { try { - css::uno::Reference< css::util::XChangesBatch > xFlush(xCFG, css::uno::UNO_QUERY_THROW); - xFlush->commitChanges(); + batch->commit(); #ifdef TRIGGER_FULL_DISC_CHECK throw css::uno::Exception(); @@ -3674,13 +3649,11 @@ void AutoRecovery::implts_doEmergencySave(const DispatchParams& aParams) // Write a hint "we crashed" into the configuration, so // the error report tool is started too in case no recovery // documents exists and was saved. - ::comphelper::ConfigurationHelper::writeDirectKey( - m_xContext, - CFG_PACKAGE_RECOVERY, - CFG_PATH_RECOVERYINFO, - CFG_ENTRY_CRASHED, - css::uno::makeAny(true), - ::comphelper::EConfigurationModes::Standard); + + std::shared_ptr batch( + comphelper::ConfigurationChanges::create(m_xContext)); + officecfg::Office::Recovery::RecoveryInfo::Crashed::set(true, batch); + batch->commit(); // for all docs, store their current view/names in the configurtion implts_persistAllActiveViewNames(); @@ -3734,13 +3707,10 @@ void AutoRecovery::implts_doRecovery(const DispatchParams& aParams) implts_resetHandleStates(); // Reset the configuration hint "we was crashed"! - ::comphelper::ConfigurationHelper::writeDirectKey( - m_xContext, - CFG_PACKAGE_RECOVERY, - CFG_PATH_RECOVERYINFO, - CFG_ENTRY_CRASHED, - css::uno::makeAny(false), - ::comphelper::EConfigurationModes::Standard); + std::shared_ptr batch( + comphelper::ConfigurationChanges::create(m_xContext)); + officecfg::Office::Recovery::RecoveryInfo::Crashed::set(false, batch); + batch->commit(); } void AutoRecovery::implts_doSessionSave(const DispatchParams& aParams) @@ -3799,13 +3769,10 @@ void AutoRecovery::implts_doSessionQuietQuit() // Write a hint for "stored session data" into the configuration, so // the on next startup we know what's happen last time - ::comphelper::ConfigurationHelper::writeDirectKey( - m_xContext, - CFG_PACKAGE_RECOVERY, - CFG_PATH_RECOVERYINFO, - CFG_ENTRY_SESSIONDATA, - css::uno::makeAny(true), - ::comphelper::EConfigurationModes::Standard); + std::shared_ptr batch( + comphelper::ConfigurationChanges::create(m_xContext)); + officecfg::Office::Recovery::RecoveryInfo::SessionData::set(true, batch); + batch->commit(); // flush config cached back to disc. impl_flushALLConfigChanges(); @@ -3834,13 +3801,10 @@ void AutoRecovery::implts_doSessionRestore(const DispatchParams& aParams) // Reset the configuration hint for "session save"! SAL_INFO("fwk.autorecovery", "... reset config key 'SessionData'"); - ::comphelper::ConfigurationHelper::writeDirectKey( - m_xContext, - CFG_PACKAGE_RECOVERY, - CFG_PATH_RECOVERYINFO, - CFG_ENTRY_SESSIONDATA, - css::uno::makeAny(false), - ::comphelper::EConfigurationModes::Standard); + std::shared_ptr batch( + comphelper::ConfigurationChanges::create(m_xContext)); + officecfg::Office::Recovery::RecoveryInfo::SessionData::set(false, batch); + batch->commit(); SAL_INFO("fwk.autorecovery", "... AutoRecovery::implts_doSessionRestore()"); } @@ -3964,14 +3928,7 @@ void SAL_CALL AutoRecovery::getFastPropertyValue(css::uno::Any& aValue , { case AUTORECOVERY_PROPHANDLE_EXISTS_RECOVERYDATA : { - bool bSessionData = false; - ::comphelper::ConfigurationHelper::readDirectKey( - m_xContext, - CFG_PACKAGE_RECOVERY, - CFG_PATH_RECOVERYINFO, - CFG_ENTRY_SESSIONDATA, - ::comphelper::EConfigurationModes::ReadOnly) >>= bSessionData; - + bool bSessionData = officecfg::Office::Recovery::RecoveryInfo::SessionData::get(m_xContext); bool bRecoveryData = m_lDocCache.size() > 0; // exists session data ... => then we can't say, that these @@ -3984,21 +3941,11 @@ void SAL_CALL AutoRecovery::getFastPropertyValue(css::uno::Any& aValue , break; case AUTORECOVERY_PROPHANDLE_CRASHED : - aValue = ::comphelper::ConfigurationHelper::readDirectKey( - m_xContext, - CFG_PACKAGE_RECOVERY, - CFG_PATH_RECOVERYINFO, - CFG_ENTRY_CRASHED, - ::comphelper::EConfigurationModes::ReadOnly); + aValue <<= officecfg::Office::Recovery::RecoveryInfo::Crashed::get(m_xContext); break; case AUTORECOVERY_PROPHANDLE_EXISTS_SESSIONDATA : - aValue = ::comphelper::ConfigurationHelper::readDirectKey( - m_xContext, - CFG_PACKAGE_RECOVERY, - CFG_PATH_RECOVERYINFO, - CFG_ENTRY_SESSIONDATA, - ::comphelper::EConfigurationModes::ReadOnly); + aValue <<= officecfg::Office::Recovery::RecoveryInfo::SessionData::get(m_xContext); break; } } @@ -4252,15 +4199,6 @@ void AutoRecovery::impl_flushALLConfigChanges() { try { - css::uno::Reference< css::uno::XInterface > xRecoveryCfg; - /* SAFE */ { - osl::MutexGuard g(cppu::WeakComponentImplHelperBase::rBHelper.rMutex); - xRecoveryCfg.set(m_xRecoveryCFG, css::uno::UNO_QUERY); - } /* SAFE */ - - if (xRecoveryCfg.is()) - ::comphelper::ConfigurationHelper::flush(xRecoveryCfg); - // SOLAR SAFE -> SolarMutexGuard aGuard; ::utl::ConfigManager::storeConfigItems(); -- cgit