Kaydet (Commit) ba7492eb authored tarafından Ivan Safonov's avatar Ivan Safonov Kaydeden (comit) Stephan Bergmann

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/41477Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarStephan Bergmann <sbergman@redhat.com>
üst f0809a84
......@@ -33,6 +33,7 @@
#include <com/sun/star/ucb/NameClash.hpp>
#include <com/sun/star/container/XNameAccess.hpp>
#include <com/sun/star/configuration/theDefaultProvider.hpp>
#include <com/sun/star/frame/Desktop.hpp>
#include <com/sun/star/frame/theGlobalEventBroadcaster.hpp>
#include <com/sun/star/frame/XLoadable.hpp>
......@@ -69,7 +70,7 @@
#include <com/sun/star/task/XStatusIndicator.hpp>
#include <com/sun/star/util/XModifyListener.hpp>
#include <comphelper/configurationhelper.hxx>
#include <comphelper/configuration.hxx>
#include <cppuhelper/basemutex.hxx>
#include <cppuhelper/exc_hlp.hxx>
#include <cppuhelper/compbase.hxx>
......@@ -93,6 +94,8 @@
#include <unotools/configmgr.hxx>
#include <svl/documentlockfile.hxx>
#include <tools/urlobj.hxx>
#include <officecfg/Office/Recovery.hxx>
#include <officecfg/Setup.hxx>
#include <general.h>
#include <stdtypes.h>
......@@ -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<css::lang::XMultiServiceFactory> xConfigProvider(
css::configuration::theDefaultProvider::get(m_xContext));
std::vector<css::uno::Any> 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<css::container::XNameAccess> 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<css::container::XNameAccess> 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<c; ++i)
{
css::uno::Reference< css::beans::XPropertySet > xItem;
xRecoveryList->getByName(pItems[i]) >>= xItem;
if (!xItem.is())
continue;
for (i=0; i<c; ++i)
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))
{
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<comphelper::ConfigurationChanges> 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<css::container::XNameAccess> 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<comphelper::ConfigurationChanges> 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<comphelper::ConfigurationChanges> 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<comphelper::ConfigurationChanges> 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<comphelper::ConfigurationChanges> 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();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment