diff --git a/src/core/kprotocolinfofactory.cpp b/src/core/kprotocolinfofactory.cpp --- a/src/core/kprotocolinfofactory.cpp +++ b/src/core/kprotocolinfofactory.cpp @@ -37,16 +37,16 @@ } KProtocolInfoFactory::KProtocolInfoFactory() - : m_allProtocolsLoaded(false) + : m_cacheDirty(true) { } KProtocolInfoFactory::~KProtocolInfoFactory() { QMutexLocker locker(&m_mutex); qDeleteAll(m_cache); m_cache.clear(); - m_allProtocolsLoaded = false; + m_cacheDirty = true; } QStringList KProtocolInfoFactory::protocols() @@ -71,31 +71,32 @@ { QMutexLocker locker(&m_mutex); - // fill cache, if not already done and use it - fillCache(); + const bool filled = fillCache(); + KProtocolInfoPrivate *info = m_cache.value(protocol); - if (!info) { + if (!info && !filled) { // Unknown protocol! Maybe it just got installed and our cache is out of date? qCDebug(KIO_CORE) << "Refilling KProtocolInfoFactory cache in the hope to find" << protocol; - m_allProtocolsLoaded = false; - qDeleteAll(m_cache); - m_cache.clear(); + m_cacheDirty = true; fillCache(); info = m_cache.value(protocol); } return info; } -void KProtocolInfoFactory::fillCache() +bool KProtocolInfoFactory::fillCache() { // mutex MUST be locked from the outside! Q_ASSERT(!m_mutex.tryLock()); // no work if filled - if (m_allProtocolsLoaded) { - return; + if (!m_cacheDirty) { + return false; } + qDeleteAll(m_cache); + m_cache.clear(); + // first: search for meta data protocol info, that might be bundled with applications // we search in all library paths inside kf5/kio Q_FOREACH (const KPluginMetaData &md, KPluginLoader::findPlugins("kf5/kio")) { @@ -134,5 +135,6 @@ } // all done, don't do it again - m_allProtocolsLoaded = true; + m_cacheDirty = false; + return true; } diff --git a/src/core/kprotocolinfofactory_p.h b/src/core/kprotocolinfofactory_p.h --- a/src/core/kprotocolinfofactory_p.h +++ b/src/core/kprotocolinfofactory_p.h @@ -69,11 +69,11 @@ /** * Fill the internal cache. */ - void fillCache(); + bool fillCache(); typedef QHash ProtocolCache; ProtocolCache m_cache; - bool m_allProtocolsLoaded; + bool m_cacheDirty; mutable QMutex m_mutex; // protects m_cache and m_allProtocolsLoaded };