diff options
author | Xisco Fauli <anistenis@gmail.com> | 2016-06-15 19:42:05 +0200 |
---|---|---|
committer | Noel Grandin <noelgrandin@gmail.com> | 2016-06-16 06:45:34 +0000 |
commit | 3c31796bedc77dc55ee645987da0922c17162454 (patch) | |
tree | 3e4849eb5af2ce7c0bd4cb6c85f9a8e38cb48879 /unotools/source/config/securityoptions.cxx | |
parent | 6cf574071e83663f8e1bcf70b0135a6258788a29 (diff) |
tdf#89329: use shared_ptr for pImpl in securityoptions
Change-Id: I91c9c9dcbb9df644836c87d4789521d668c2ba49
Reviewed-on: https://gerrit.libreoffice.org/26319
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'unotools/source/config/securityoptions.cxx')
-rw-r--r-- | unotools/source/config/securityoptions.cxx | 72 |
1 files changed, 30 insertions, 42 deletions
diff --git a/unotools/source/config/securityoptions.cxx b/unotools/source/config/securityoptions.cxx index 61d277d2a416..d89ba665646f 100644 --- a/unotools/source/config/securityoptions.cxx +++ b/unotools/source/config/securityoptions.cxx @@ -930,23 +930,18 @@ Sequence< OUString > SvtSecurityOptions_Impl::GetPropertyNames() return seqPropertyNames; } -// initialize static member -// DON'T DO IT IN YOUR HEADER! -// see definition for further information - -SvtSecurityOptions_Impl* SvtSecurityOptions::m_pDataContainer = nullptr; -sal_Int32 SvtSecurityOptions::m_nRefCount = 0; +std::weak_ptr<SvtSecurityOptions_Impl> m_pSecurityOptions; SvtSecurityOptions::SvtSecurityOptions() { // Global access, must be guarded (multithreading!). MutexGuard aGuard( GetInitMutex() ); - // Increase our refcount ... - ++m_nRefCount; - // ... and initialize our data container only if it not already exist! - if( m_pDataContainer == nullptr ) + + m_pImpl = m_pSecurityOptions.lock(); + if( !m_pImpl ) { - m_pDataContainer = new SvtSecurityOptions_Impl; + m_pImpl = std::make_shared<SvtSecurityOptions_Impl>(); + m_pSecurityOptions = m_pImpl; ItemHolder1::holdConfigItem(E_SECURITYOPTIONS); } @@ -956,33 +951,26 @@ SvtSecurityOptions::~SvtSecurityOptions() { // Global access, must be guarded (multithreading!) MutexGuard aGuard( GetInitMutex() ); - // Decrease our refcount. - --m_nRefCount; - // If last instance was deleted ... - // we must destroy our static data container! - if( m_nRefCount <= 0 ) - { - delete m_pDataContainer; - m_pDataContainer = nullptr; - } + + m_pImpl.reset(); } bool SvtSecurityOptions::IsReadOnly( EOption eOption ) const { MutexGuard aGuard( GetInitMutex() ); - return m_pDataContainer->IsReadOnly(eOption); + return m_pImpl->IsReadOnly(eOption); } Sequence< OUString > SvtSecurityOptions::GetSecureURLs() const { MutexGuard aGuard( GetInitMutex() ); - return m_pDataContainer->GetSecureURLs(); + return m_pImpl->GetSecureURLs(); } void SvtSecurityOptions::SetSecureURLs( const Sequence< OUString >& seqURLList ) { MutexGuard aGuard( GetInitMutex() ); - m_pDataContainer->SetSecureURLs( seqURLList ); + m_pImpl->SetSecureURLs( seqURLList ); } bool SvtSecurityOptions::isSecureMacroUri( @@ -1006,18 +994,18 @@ bool SvtSecurityOptions::isSecureMacroUri( bool SvtSecurityOptions::isUntrustedReferer(OUString const & referer) const { MutexGuard g(GetInitMutex()); - return m_pDataContainer->IsOptionSet(E_BLOCKUNTRUSTEDREFERERLINKS) + return m_pImpl->IsOptionSet(E_BLOCKUNTRUSTEDREFERERLINKS) && !(referer.isEmpty() || referer.startsWithIgnoreAsciiCase("private:") || isTrustedLocationUri(referer)); } bool SvtSecurityOptions::isTrustedLocationUri(OUString const & uri) const { MutexGuard g(GetInitMutex()); - for (sal_Int32 i = 0; i != m_pDataContainer->m_seqSecureURLs.getLength(); + for (sal_Int32 i = 0; i != m_pImpl->m_seqSecureURLs.getLength(); ++i) { if (UCBContentHelper::IsSubPath( - m_pDataContainer->m_seqSecureURLs[i], uri)) + m_pImpl->m_seqSecureURLs[i], uri)) { return true; } @@ -1036,49 +1024,49 @@ bool SvtSecurityOptions::isTrustedLocationUriForUpdatingLinks( sal_Int32 SvtSecurityOptions::GetMacroSecurityLevel() const { MutexGuard aGuard( GetInitMutex() ); - return m_pDataContainer->GetMacroSecurityLevel(); + return m_pImpl->GetMacroSecurityLevel(); } void SvtSecurityOptions::SetMacroSecurityLevel( sal_Int32 _nLevel ) { MutexGuard aGuard( GetInitMutex() ); - m_pDataContainer->SetMacroSecurityLevel( _nLevel ); + m_pImpl->SetMacroSecurityLevel( _nLevel ); } bool SvtSecurityOptions::IsMacroDisabled() const { MutexGuard aGuard( GetInitMutex() ); - return m_pDataContainer->IsMacroDisabled(); + return m_pImpl->IsMacroDisabled(); } Sequence< SvtSecurityOptions::Certificate > SvtSecurityOptions::GetTrustedAuthors() const { MutexGuard aGuard( GetInitMutex() ); - return m_pDataContainer->GetTrustedAuthors(); + return m_pImpl->GetTrustedAuthors(); } void SvtSecurityOptions::SetTrustedAuthors( const Sequence< Certificate >& rAuthors ) { MutexGuard aGuard( GetInitMutex() ); - m_pDataContainer->SetTrustedAuthors( rAuthors ); + m_pImpl->SetTrustedAuthors( rAuthors ); } bool SvtSecurityOptions::IsOptionSet( EOption eOption ) const { MutexGuard aGuard( GetInitMutex() ); - return m_pDataContainer->IsOptionSet( eOption ); + return m_pImpl->IsOptionSet( eOption ); } void SvtSecurityOptions::SetOption( EOption eOption, bool bValue ) { MutexGuard aGuard( GetInitMutex() ); - m_pDataContainer->SetOption( eOption, bValue ); + m_pImpl->SetOption( eOption, bValue ); } bool SvtSecurityOptions::IsOptionEnabled( EOption eOption ) const { MutexGuard aGuard( GetInitMutex() ); - return m_pDataContainer->IsOptionEnabled( eOption ); + return m_pImpl->IsOptionEnabled( eOption ); } namespace @@ -1137,49 +1125,49 @@ void SvtSecurityOptions_Impl::SetConfirmationEnabled( bool bSet ) bool SvtSecurityOptions::IsExecutePlugins() const { MutexGuard aGuard( GetInitMutex() ); - return m_pDataContainer->IsExecutePlugins(); + return m_pImpl->IsExecutePlugins(); } void SvtSecurityOptions::SetExecutePlugins( bool bSet ) { MutexGuard aGuard( GetInitMutex() ); - m_pDataContainer->SetExecutePlugins( bSet ); + m_pImpl->SetExecutePlugins( bSet ); } bool SvtSecurityOptions::IsWarningEnabled() const { MutexGuard aGuard( GetInitMutex() ); - return m_pDataContainer->IsWarningEnabled(); + return m_pImpl->IsWarningEnabled(); } void SvtSecurityOptions::SetWarningEnabled( bool bSet ) { MutexGuard aGuard( GetInitMutex() ); - m_pDataContainer->SetWarningEnabled( bSet ); + m_pImpl->SetWarningEnabled( bSet ); } bool SvtSecurityOptions::IsConfirmationEnabled() const { MutexGuard aGuard( GetInitMutex() ); - return m_pDataContainer->IsConfirmationEnabled(); + return m_pImpl->IsConfirmationEnabled(); } void SvtSecurityOptions::SetConfirmationEnabled( bool bSet ) { MutexGuard aGuard( GetInitMutex() ); - m_pDataContainer->SetConfirmationEnabled( bSet ); + m_pImpl->SetConfirmationEnabled( bSet ); } void SvtSecurityOptions::SetBasicMode( EBasicSecurityMode eMode ) { MutexGuard aGuard( GetInitMutex() ); - m_pDataContainer->SetBasicMode( eMode ); + m_pImpl->SetBasicMode( eMode ); } EBasicSecurityMode SvtSecurityOptions::GetBasicMode() const { MutexGuard aGuard( GetInitMutex() ); - return m_pDataContainer->GetBasicMode(); + return m_pImpl->GetBasicMode(); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |