osl::Mutex->std::mutex in BaseContainer

Change-Id: I66fcebb897446a5839ebde03e8e0a91d75a5e57c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147402
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Noel Grandin 2023-02-21 13:59:13 +02:00
parent cc0654cab1
commit c060e7851b
7 changed files with 108 additions and 152 deletions

View file

@ -33,7 +33,6 @@ namespace filter::config{
BaseContainer::BaseContainer()
: m_eType()
, m_lListener (m_aMutex)
{
GetTheFilterCache().load(FilterCache::E_CONTAINS_STANDARD);
}
@ -49,7 +48,7 @@ void BaseContainer::init(const OUString&
FilterCache::EItemType eType )
{
// SAFE ->
osl::MutexGuard aLock(m_aMutex);
std::unique_lock aLock(m_aMutex);
m_sImplementationName = sImplementationName;
m_lServiceNames = lServiceNames ;
@ -58,12 +57,9 @@ void BaseContainer::init(const OUString&
}
void BaseContainer::impl_loadOnDemand()
void BaseContainer::impl_loadOnDemand(std::unique_lock<std::mutex>& /*rGuard*/)
{
#ifdef LOAD_IMPLICIT
// SAFE ->
osl::MutexGuard aLock(m_aMutex);
// A generic container needs all items of a set of our cache!
// Of course it can block for a while, till the cache is really filled.
// Note: don't load all sets supported by the cache here!
@ -89,33 +85,26 @@ void BaseContainer::impl_loadOnDemand()
}
GetTheFilterCache().load(eRequiredState);
// <- SAFE
#endif
}
void BaseContainer::impl_initFlushMode()
void BaseContainer::impl_initFlushMode(std::unique_lock<std::mutex>& /*rGuard*/)
{
// SAFE ->
osl::MutexGuard aLock(m_aMutex);
if (!m_pFlushCache)
m_pFlushCache = GetTheFilterCache().clone();
if (!m_pFlushCache)
throw css::uno::RuntimeException( "Can not create write copy of internal used cache on demand.",
static_cast< OWeakObject* >(this));
// <- SAFE
}
FilterCache* BaseContainer::impl_getWorkingCache() const
FilterCache* BaseContainer::impl_getWorkingCache(std::unique_lock<std::mutex>& /*rGuard*/) const
{
// SAFE ->
osl::MutexGuard aLock(m_aMutex);
if (m_pFlushCache)
return m_pFlushCache.get();
else
return &GetTheFilterCache();
// <- SAFE
}
@ -154,15 +143,15 @@ void SAL_CALL BaseContainer::insertByName(const OUString& sItem ,
throw css::lang::IllegalArgumentException(ex.Message, static_cast< css::container::XNameContainer* >(this), 2);
}
impl_loadOnDemand();
// SAFE -> ----------------------------------
osl::MutexGuard aLock(m_aMutex);
std::unique_lock aLock(m_aMutex);
impl_loadOnDemand(aLock);
// create write copy of used cache on demand ...
impl_initFlushMode();
impl_initFlushMode(aLock);
FilterCache* pCache = impl_getWorkingCache();
FilterCache* pCache = impl_getWorkingCache(aLock);
if (pCache->hasItem(m_eType, sItem))
throw css::container::ElementExistException(OUString(), static_cast< css::container::XNameContainer* >(this));
pCache->setItem(m_eType, sItem, aItem);
@ -172,15 +161,15 @@ void SAL_CALL BaseContainer::insertByName(const OUString& sItem ,
void SAL_CALL BaseContainer::removeByName(const OUString& sItem)
{
impl_loadOnDemand();
// SAFE -> ----------------------------------
osl::MutexGuard aLock(m_aMutex);
std::unique_lock aLock(m_aMutex);
impl_loadOnDemand(aLock);
// create write copy of used cache on demand ...
impl_initFlushMode();
impl_initFlushMode(aLock);
FilterCache* pCache = impl_getWorkingCache();
FilterCache* pCache = impl_getWorkingCache(aLock);
pCache->removeItem(m_eType, sItem); // throw exceptions automatically
// <- SAFE ----------------------------------
}
@ -204,15 +193,15 @@ void SAL_CALL BaseContainer::replaceByName(const OUString& sItem ,
throw css::lang::IllegalArgumentException(ex.Message, static_cast< css::container::XNameContainer* >(this), 2);
}
impl_loadOnDemand();
// SAFE -> ----------------------------------
osl::MutexGuard aLock(m_aMutex);
std::unique_lock aLock(m_aMutex);
impl_loadOnDemand(aLock);
// create write copy of used cache on demand ...
impl_initFlushMode();
impl_initFlushMode(aLock);
FilterCache* pCache = impl_getWorkingCache();
FilterCache* pCache = impl_getWorkingCache(aLock);
if (!pCache->hasItem(m_eType, sItem))
throw css::container::NoSuchElementException(OUString(), static_cast< css::container::XNameContainer* >(this));
pCache->setItem(m_eType, sItem, aItem);
@ -228,14 +217,14 @@ css::uno::Any SAL_CALL BaseContainer::getByName(const OUString& sItem)
css::uno::Any aValue;
impl_loadOnDemand();
// SAFE ->
osl::MutexGuard aLock(m_aMutex);
std::unique_lock aLock(m_aMutex);
impl_loadOnDemand(aLock);
try
{
FilterCache* pCache = impl_getWorkingCache();
FilterCache* pCache = impl_getWorkingCache(aLock);
aValue = pCache->getItemWithStateProps(m_eType, sItem);
}
catch(const css::container::NoSuchElementException&)
@ -257,14 +246,14 @@ css::uno::Sequence< OUString > SAL_CALL BaseContainer::getElementNames()
{
css::uno::Sequence< OUString > lNames;
impl_loadOnDemand();
// SAFE ->
osl::MutexGuard aLock(m_aMutex);
std::unique_lock aLock(m_aMutex);
impl_loadOnDemand(aLock);
try
{
FilterCache* pCache = impl_getWorkingCache();
FilterCache* pCache = impl_getWorkingCache(aLock);
std::vector<OUString> lKeys = pCache->getItemNames(m_eType);
lNames = comphelper::containerToSequence(lKeys);
}
@ -284,14 +273,14 @@ sal_Bool SAL_CALL BaseContainer::hasByName(const OUString& sItem)
{
bool bHasOne = false;
impl_loadOnDemand();
// SAFE ->
osl::MutexGuard aLock(m_aMutex);
std::unique_lock aLock(m_aMutex);
impl_loadOnDemand(aLock);
try
{
FilterCache* pCache = impl_getWorkingCache();
FilterCache* pCache = impl_getWorkingCache(aLock);
bHasOne = pCache->hasItem(m_eType, sItem);
}
catch(const css::uno::Exception&)
@ -318,14 +307,14 @@ sal_Bool SAL_CALL BaseContainer::hasElements()
{
bool bHasSome = false;
impl_loadOnDemand();
// SAFE ->
osl::MutexGuard aLock(m_aMutex);
std::unique_lock aLock(m_aMutex);
impl_loadOnDemand(aLock);
try
{
FilterCache* pCache = impl_getWorkingCache();
FilterCache* pCache = impl_getWorkingCache(aLock);
bHasSome = pCache->hasItems(m_eType);
}
catch(const css::uno::Exception&)
@ -352,16 +341,16 @@ css::uno::Reference< css::container::XEnumeration > SAL_CALL BaseContainer::crea
{
std::vector<OUString> lKeys;
impl_loadOnDemand();
// SAFE ->
osl::MutexGuard aLock(m_aMutex);
std::unique_lock aLock(m_aMutex);
impl_loadOnDemand(aLock);
try
{
// search the key names of all items, where its properties match
// the given ones in its minimum
FilterCache* pCache = impl_getWorkingCache();
FilterCache* pCache = impl_getWorkingCache(aLock);
lKeys = pCache->getMatchingItemsByProps(m_eType, o3tl::span<const css::beans::NamedValue>( lProperties.getConstArray(), lProperties.getLength() ));
}
catch(const css::uno::Exception&)
@ -390,7 +379,7 @@ css::uno::Reference< css::container::XEnumeration > SAL_CALL BaseContainer::crea
void SAL_CALL BaseContainer::flush()
{
// SAFE ->
osl::ClearableMutexGuard aLock(m_aMutex);
std::unique_lock aLock(m_aMutex);
if (!m_pFlushCache)
throw css::lang::WrappedTargetRuntimeException(
@ -423,52 +412,24 @@ void SAL_CALL BaseContainer::flush()
m_pFlushCache.reset();
aLock.clear();
// <- SAFE
// notify listener outside the lock!
// The used listener helper lives if we live
// and is threadsafe by itself.
// Further it's not a good idea to hold the own lock
// if an outside object is called :-)
css::lang::EventObject aSource (static_cast< css::util::XFlushable* >(this));
comphelper::OInterfaceContainerHelper2* pContainer = m_lListener.getContainer(cppu::UnoType<css::util::XFlushListener>::get());
if (!pContainer)
return;
m_lListener.notifyEach( aLock, &css::util::XFlushListener::flushed, aSource);
comphelper::OInterfaceIteratorHelper2 pIterator(*pContainer);
while (pIterator.hasMoreElements())
{
try
{
// ... this pointer can be interesting to find out, where will be called as listener
// Don't optimize it to a direct iterator cast :-)
css::util::XFlushListener* pListener = static_cast<css::util::XFlushListener*>(pIterator.next());
pListener->flushed(aSource);
}
catch(const css::uno::Exception&)
{
// ignore any "damaged" flush listener!
// May its remote reference is broken ...
pIterator.remove();
}
}
// <- SAFE
}
void SAL_CALL BaseContainer::addFlushListener(const css::uno::Reference< css::util::XFlushListener >& xListener)
{
// no locks necessary
// used helper lives if we live and is threadsafe by itself ...
m_lListener.addInterface(cppu::UnoType<css::util::XFlushListener>::get(), xListener);
std::unique_lock g(m_aMutex);
m_lListener.addInterface(g, xListener);
}
void SAL_CALL BaseContainer::removeFlushListener(const css::uno::Reference< css::util::XFlushListener >& xListener)
{
// no locks necessary
// used helper lives if we live and is threadsafe by itself ...
m_lListener.removeInterface(cppu::UnoType<css::util::XFlushListener>::get(), xListener);
std::unique_lock g(m_aMutex);
m_lListener.removeInterface(g, xListener);
}
} // namespace filter::config

View file

@ -27,7 +27,7 @@
#include <com/sun/star/container/XNameContainer.hpp>
#include <com/sun/star/container/XContainerQuery.hpp>
#include <com/sun/star/util/XFlushable.hpp>
#include <comphelper/multicontainer2.hxx>
#include <comphelper/interfacecontainer4.hxx>
#include <cppuhelper/implbase.hxx>
#include <cppuhelper/weakref.hxx>
#include <rtl/ustring.hxx>
@ -49,8 +49,7 @@ namespace filter::config {
present by this base class!) was full initialized inside our own
ctor as first!
*/
class BaseContainer : public cppu::BaseMutex
, public ::cppu::WeakImplHelper< css::lang::XServiceInfo ,
class BaseContainer : public ::cppu::WeakImplHelper< css::lang::XServiceInfo ,
css::container::XNameContainer , // => XNameReplace => XNameAccess => XElementAccess
css::container::XContainerQuery ,
css::util::XFlushable >
@ -59,6 +58,7 @@ class BaseContainer : public cppu::BaseMutex
// member
protected:
mutable std::mutex m_aMutex;
/** @short the implementation name of our derived class, which we provide
at the interface XServiceInfo of our class... */
@ -90,7 +90,7 @@ class BaseContainer : public cppu::BaseMutex
FilterCache::EItemType m_eType;
/** @short holds all listener, which are registered at this instance. */
comphelper::OMultiTypeInterfaceContainerHelper2 m_lListener;
comphelper::OInterfaceContainerHelper4<css::util::XFlushListener> m_lListener;
// native interface
@ -155,7 +155,7 @@ class BaseContainer : public cppu::BaseMutex
/** @short check if the underlying configuration data was already loaded
and do it if necessary automatically.
*/
void impl_loadOnDemand();
void impl_loadOnDemand(std::unique_lock<std::mutex>& rGuard);
/** @short it creates the global instance m_pFilterCache, which is a copy
@ -167,7 +167,7 @@ class BaseContainer : public cppu::BaseMutex
@throws css::uno::RuntimeException
*/
void impl_initFlushMode();
void impl_initFlushMode(std::unique_lock<std::mutex>& rGuard);
/** @short returns a pointer to the current used cache member.
@ -188,7 +188,7 @@ class BaseContainer : public cppu::BaseMutex
aLock.clear();
// after this point p can't b e guaranteed any longer!
*/
FilterCache* impl_getWorkingCache() const;
FilterCache* impl_getWorkingCache(std::unique_lock<std::mutex>& rGuard) const;
// uno interface

View file

@ -52,7 +52,7 @@ css::uno::Reference< css::uno::XInterface > SAL_CALL ContentHandlerFactory::crea
css::uno::Reference< css::uno::XInterface > xHandler;
// SAFE ->
osl::MutexGuard aLock(m_aMutex);
std::unique_lock aLock(m_aMutex);
auto & cache = GetTheFilterCache();

View file

@ -77,7 +77,7 @@ css::uno::Reference< css::uno::XInterface > SAL_CALL FilterFactory::createInstan
const css::uno::Sequence< css::uno::Any >& lArguments)
{
// SAFE ->
osl::MutexGuard aLock(m_aMutex);
std::unique_lock aLock(m_aMutex);
auto & cache = GetTheFilterCache();
@ -166,10 +166,10 @@ css::uno::Reference< css::container::XEnumeration > SAL_CALL FilterFactory::crea
{
// SAFE -> ----------------------
{
osl::MutexGuard aLock(m_aMutex);
std::unique_lock aLock(m_aMutex);
// May be not all filters was loaded ...
// But we need it now!
impl_loadOnDemand();
impl_loadOnDemand(aLock);
}
// <- SAFE ----------------------
@ -251,10 +251,10 @@ std::vector<OUString> FilterFactory::impl_queryMatchByDocumentService(const Quer
nEFlags = pIt->second.toInt32();
// SAFE -> ----------------------
osl::ClearableMutexGuard aLock(m_aMutex);
std::unique_lock aLock(m_aMutex);
// search suitable filters
FilterCache* pCache = impl_getWorkingCache();
FilterCache* pCache = impl_getWorkingCache(aLock);
std::vector<OUString> lFilterNames = pCache->getItemNames(FilterCache::E_FILTER);
std::vector<OUString> lResult ;
@ -312,7 +312,7 @@ std::vector<OUString> FilterFactory::impl_queryMatchByDocumentService(const Quer
{ continue; }
}
aLock.clear();
aLock.unlock();
// <- SAFE ----------------------
return lResult;
@ -421,10 +421,10 @@ std::vector<OUString> FilterFactory::impl_getSortedFilterListForModule(const OUS
css::beans::NamedValue lIProps[] { { PROPNAME_DOCUMENTSERVICE, css::uno::Any(sModule) } };
// SAFE -> ----------------------
osl::ClearableMutexGuard aLock(m_aMutex);
FilterCache* pCache = impl_getWorkingCache();
std::unique_lock aLock(m_aMutex);
FilterCache* pCache = impl_getWorkingCache(aLock);
std::vector<OUString> lOtherFilters = pCache->getMatchingItemsByProps(FilterCache::E_FILTER, lIProps);
aLock.clear();
aLock.unlock();
// <- SAFE ----------------------
// bring "other" filters in an alphabetical order

View file

@ -50,7 +50,7 @@ css::uno::Reference< css::uno::XInterface > SAL_CALL FrameLoaderFactory::createI
const css::uno::Sequence< css::uno::Any >& lArguments)
{
// SAFE ->
osl::MutexGuard aLock(m_aMutex);
std::unique_lock aLock(m_aMutex);
auto & cache = GetTheFilterCache();

View file

@ -73,7 +73,7 @@ OUString SAL_CALL TypeDetection::queryTypeByURL(const OUString& sURL)
OUString sType;
// SAFE ->
osl::MutexGuard aLock(m_aMutex);
std::unique_lock aLock(m_aMutex);
css::util::URL aURL;
aURL.Complete = sURL;
@ -379,7 +379,7 @@ OUString SAL_CALL TypeDetection::queryTypeByDescriptor(css::uno::Sequence< css::
try
{
// SAFE -> ----------------------------------
osl::ClearableMutexGuard aLock(m_aMutex);
std::unique_lock aLock(m_aMutex);
// parse given URL to split it into e.g. main and jump marks ...
sURL = stlDescriptor.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_URL, OUString());
@ -400,14 +400,14 @@ OUString SAL_CALL TypeDetection::queryTypeByDescriptor(css::uno::Sequence< css::
{
// Caller specified the filter type. Honor it. Just get the default
// type for that filter, and bail out.
if (impl_validateAndSetFilterOnDescriptor(stlDescriptor, aSelectedFilter))
if (impl_validateAndSetFilterOnDescriptor(aLock, stlDescriptor, aSelectedFilter))
return stlDescriptor[utl::MediaDescriptor::PROP_TYPENAME].get<OUString>();
}
FlatDetection lFlatTypes;
impl_getAllFormatTypes(aURL, stlDescriptor, lFlatTypes);
impl_getAllFormatTypes(aLock, aURL, stlDescriptor, lFlatTypes);
aLock.clear();
aLock.unlock();
// <- SAFE ----------------------------------
// Properly prioritize all candidate types.
@ -489,7 +489,7 @@ void TypeDetection::impl_checkResultsAndAddBestFilter(utl::MediaDescriptor& rDes
OUString sRealType = sType;
// SAFE ->
::osl::ResettableMutexGuard aLock(m_aMutex);
std::unique_lock aLock(m_aMutex);
// Attention: For executing next lines of code, We must be sure that
// all filters already loaded :-(
@ -501,13 +501,13 @@ void TypeDetection::impl_checkResultsAndAddBestFilter(utl::MediaDescriptor& rDes
{ PROPNAME_TYPE, uno::Any(sRealType) } };
std::vector<OUString> lFilters = cache.getMatchingItemsByProps(FilterCache::E_FILTER, lIProps);
aLock.clear();
aLock.unlock();
// <- SAFE
for (auto const& filter : lFilters)
{
// SAFE ->
aLock.reset();
aLock.lock();
try
{
CacheItem aFilter = cache.getItem(FilterCache::E_FILTER, filter);
@ -520,7 +520,7 @@ void TypeDetection::impl_checkResultsAndAddBestFilter(utl::MediaDescriptor& rDes
break;
}
catch(const css::uno::Exception&) {}
aLock.clear();
aLock.unlock();
// <- SAFE
}
@ -547,13 +547,13 @@ void TypeDetection::impl_checkResultsAndAddBestFilter(utl::MediaDescriptor& rDes
try
{
// SAFE ->
osl::ClearableMutexGuard aLock(m_aMutex);
std::unique_lock aLock(m_aMutex);
CacheItem aType = cache.getItem(FilterCache::E_TYPE, sType);
aType[PROPNAME_PREFERREDFILTER] >>= sFilter;
cache.getItem(FilterCache::E_FILTER, sFilter);
aLock.clear();
aLock.unlock();
// <- SAFE
// no exception => found valid type and filter => set it on the given descriptor
@ -570,7 +570,7 @@ void TypeDetection::impl_checkResultsAndAddBestFilter(utl::MediaDescriptor& rDes
try
{
// SAFE ->
::osl::ResettableMutexGuard aLock(m_aMutex);
std::unique_lock aLock(m_aMutex);
// Attention: For executing next lines of code, We must be sure that
// all filters already loaded :-(
@ -581,7 +581,7 @@ void TypeDetection::impl_checkResultsAndAddBestFilter(utl::MediaDescriptor& rDes
{ PROPNAME_TYPE, uno::Any(sType) } };
std::vector<OUString> lFilters = cache.getMatchingItemsByProps(FilterCache::E_FILTER, lIProps);
aLock.clear();
aLock.unlock();
// <- SAFE
for (auto const& filter : lFilters)
@ -589,7 +589,7 @@ void TypeDetection::impl_checkResultsAndAddBestFilter(utl::MediaDescriptor& rDes
sFilter = filter;
// SAFE ->
aLock.reset();
aLock.lock();
try
{
CacheItem aFilter = cache.getItem(FilterCache::E_FILTER, sFilter);
@ -601,7 +601,7 @@ void TypeDetection::impl_checkResultsAndAddBestFilter(utl::MediaDescriptor& rDes
}
catch(const css::uno::Exception&)
{ continue; }
aLock.clear();
aLock.unlock();
// <- SAFE
sFilter.clear();
@ -620,6 +620,7 @@ void TypeDetection::impl_checkResultsAndAddBestFilter(utl::MediaDescriptor& rDes
bool TypeDetection::impl_getPreselectionForType(
std::unique_lock<std::mutex>& /*rGuard*/,
const OUString& sPreSelType, const util::URL& aParsedURL, FlatDetection& rFlatTypes, bool bDocService)
{
// Can be used to suppress execution of some parts of this method
@ -641,10 +642,7 @@ bool TypeDetection::impl_getPreselectionForType(
CacheItem aType;
try
{
// SAFE -> --------------------------
osl::MutexGuard aLock(m_aMutex);
aType = GetTheFilterCache().getItem(FilterCache::E_TYPE, sType);
// <- SAFE --------------------------
}
catch(const css::container::NoSuchElementException&)
{
@ -721,15 +719,13 @@ bool TypeDetection::impl_getPreselectionForType(
}
void TypeDetection::impl_getPreselectionForDocumentService(
std::unique_lock<std::mutex>& rGuard,
const OUString& sPreSelDocumentService, const util::URL& aParsedURL, FlatDetection& rFlatTypes)
{
// get all filters, which match to this doc service
std::vector<OUString> lFilters;
try
{
// SAFE -> --------------------------
osl::MutexGuard aLock(m_aMutex);
// Attention: For executing next lines of code, We must be sure that
// all filters already loaded :-(
// That can disturb our "load on demand feature". But we have no other chance!
@ -739,7 +735,6 @@ void TypeDetection::impl_getPreselectionForDocumentService(
css::beans::NamedValue lIProps[] {
{ PROPNAME_DOCUMENTSERVICE, css::uno::Any(sPreSelDocumentService) } };
lFilters = cache.getMatchingItemsByProps(FilterCache::E_FILTER, lIProps);
// <- SAFE --------------------------
}
catch (const css::container::NoSuchElementException&)
{
@ -753,20 +748,19 @@ void TypeDetection::impl_getPreselectionForDocumentService(
// is an easier job than removing them .-)
for (auto const& filter : lFilters)
{
OUString aType = impl_getTypeFromFilter(filter);
OUString aType = impl_getTypeFromFilter(rGuard, filter);
if (aType.isEmpty())
continue;
impl_getPreselectionForType(aType, aParsedURL, rFlatTypes, true);
impl_getPreselectionForType(rGuard, aType, aParsedURL, rFlatTypes, true);
}
}
OUString TypeDetection::impl_getTypeFromFilter(const OUString& rFilterName)
OUString TypeDetection::impl_getTypeFromFilter(std::unique_lock<std::mutex>& /*rGuard*/, const OUString& rFilterName)
{
CacheItem aFilter;
try
{
osl::MutexGuard aLock(m_aMutex);
aFilter = GetTheFilterCache().getItem(FilterCache::E_FILTER, rFilterName);
}
catch (const container::NoSuchElementException&)
@ -780,6 +774,7 @@ OUString TypeDetection::impl_getTypeFromFilter(const OUString& rFilterName)
}
void TypeDetection::impl_getAllFormatTypes(
std::unique_lock<std::mutex>& rGuard,
const util::URL& aParsedURL, utl::MediaDescriptor const & rDescriptor, FlatDetection& rFlatTypes)
{
rFlatTypes.clear();
@ -788,7 +783,6 @@ void TypeDetection::impl_getAllFormatTypes(
std::vector<OUString> aFilterNames;
try
{
osl::MutexGuard aLock(m_aMutex);
auto & cache = GetTheFilterCache();
cache.load(FilterCache::E_CONTAINS_FILTERS);
aFilterNames = cache.getItemNames(FilterCache::E_FILTER);
@ -801,7 +795,7 @@ void TypeDetection::impl_getAllFormatTypes(
// Retrieve the default type for each of these filters, and store them.
for (auto const& filterName : aFilterNames)
{
OUString aType = impl_getTypeFromFilter(filterName);
OUString aType = impl_getTypeFromFilter(rGuard, filterName);
if (aType.isEmpty())
continue;
@ -844,12 +838,12 @@ void TypeDetection::impl_getAllFormatTypes(
// Mark pre-selected type (if any) to have it prioritized.
OUString sSelectedType = rDescriptor.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_TYPENAME, OUString());
if (!sSelectedType.isEmpty())
impl_getPreselectionForType(sSelectedType, aParsedURL, rFlatTypes, false);
impl_getPreselectionForType(rGuard, sSelectedType, aParsedURL, rFlatTypes, false);
// Mark all types preferred by the current document service, to have it prioritized.
OUString sSelectedDoc = rDescriptor.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_DOCUMENTSERVICE, OUString());
if (!sSelectedDoc.isEmpty())
impl_getPreselectionForDocumentService(sSelectedDoc, aParsedURL, rFlatTypes);
impl_getPreselectionForDocumentService(rGuard, sSelectedDoc, aParsedURL, rFlatTypes);
}
@ -898,9 +892,9 @@ OUString TypeDetection::impl_detectTypeFlatAndDeep( utl::MediaDescriptor& r
try
{
// SAFE -> ----------------------------------
osl::ClearableMutexGuard aLock(m_aMutex);
std::unique_lock aLock(m_aMutex);
CacheItem aType = GetTheFilterCache().getItem(FilterCache::E_TYPE, sFlatType);
aLock.clear();
aLock.unlock();
OUString sDetectService;
aType[PROPNAME_DETECTSERVICE] >>= sDetectService;
@ -976,7 +970,7 @@ OUString TypeDetection::impl_askDetectService(const OUString& sDet
// SAFE ->
{
osl::MutexGuard aLock(m_aMutex);
std::unique_lock aLock(m_aMutex);
xContext = m_xContext;
}
// <- SAFE
@ -1090,9 +1084,11 @@ OUString TypeDetection::impl_askUserForTypeAndFilterIfAllowed(utl::MediaDescript
// too and no ambiguous filter registration disturb us .-)
OUString sFilter = aRequest.getFilter();
if (!impl_validateAndSetFilterOnDescriptor(rDescriptor, sFilter))
return OUString();
{
std::unique_lock aLock(m_aMutex);
if (!impl_validateAndSetFilterOnDescriptor(aLock, rDescriptor, sFilter))
return OUString();
}
OUString sType;
rDescriptor[utl::MediaDescriptor::PROP_TYPENAME] >>= sType;
return sType;
@ -1149,7 +1145,7 @@ bool TypeDetection::impl_validateAndSetTypeOnDescriptor( utl::MediaDescript
{
// SAFE ->
{
osl::MutexGuard aLock(m_aMutex);
std::unique_lock aLock(m_aMutex);
if (GetTheFilterCache().hasItem(FilterCache::E_TYPE, sType))
{
rDescriptor[utl::MediaDescriptor::PROP_TYPENAME] <<= sType;
@ -1164,22 +1160,17 @@ bool TypeDetection::impl_validateAndSetTypeOnDescriptor( utl::MediaDescript
}
bool TypeDetection::impl_validateAndSetFilterOnDescriptor( utl::MediaDescriptor& rDescriptor,
bool TypeDetection::impl_validateAndSetFilterOnDescriptor( std::unique_lock<std::mutex>& /*rGuard*/,
utl::MediaDescriptor& rDescriptor,
const OUString& sFilter )
{
try
{
// SAFE ->
osl::ClearableMutexGuard aLock(m_aMutex);
auto & cache = GetTheFilterCache();
CacheItem aFilter = cache.getItem(FilterCache::E_FILTER, sFilter);
OUString sType;
aFilter[PROPNAME_TYPE] >>= sType;
aLock.clear();
// <- SAFE
// found valid type and filter => set it on the given descriptor
rDescriptor[utl::MediaDescriptor::PROP_TYPENAME ] <<= sType ;
rDescriptor[utl::MediaDescriptor::PROP_FILTERNAME] <<= sFilter;

View file

@ -70,18 +70,21 @@ public:
private:
bool impl_getPreselectionForType(
static bool impl_getPreselectionForType(
std::unique_lock<std::mutex>& rGuard,
const OUString& sPreSelType, const css::util::URL& aParsedURL, FlatDetection& rFlatTypes, bool bDocService);
void impl_getPreselectionForDocumentService(
static void impl_getPreselectionForDocumentService(
std::unique_lock<std::mutex>& rGuard,
const OUString& sPreSelDocumentService, const css::util::URL& aParsedURL, FlatDetection& rFlatTypes);
OUString impl_getTypeFromFilter(const OUString& rFilterName);
static OUString impl_getTypeFromFilter(std::unique_lock<std::mutex>& rGuard, const OUString& rFilterName);
/**
* Get all format types that we handle.
*/
void impl_getAllFormatTypes(
static void impl_getAllFormatTypes(
std::unique_lock<std::mutex>& rGuard,
const css::util::URL& aParsedURL, utl::MediaDescriptor const & rDescriptor,
FlatDetection& rFlatTypes);
@ -251,7 +254,8 @@ private:
@return TRUE the specified type and its registrations was valid(!) and
could be set on the descriptor.
*/
bool impl_validateAndSetFilterOnDescriptor( utl::MediaDescriptor& rDescriptor,
static bool impl_validateAndSetFilterOnDescriptor( std::unique_lock<std::mutex>& rGuard,
utl::MediaDescriptor& rDescriptor,
const OUString& sFilter );