1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 01:22:10 +01:00

IconProvider: Add mutex around icon cache

BUG: 406972
FIXED-IN: 3.1.1
This commit is contained in:
David Rosca 2019-05-24 21:47:20 +02:00
parent 8e57d0895c
commit 3075477492
No known key found for this signature in database
GPG Key ID: EBC3FC294452C6D8
2 changed files with 8 additions and 0 deletions

View File

@ -187,6 +187,8 @@ QImage IconProvider::imageForUrl(const QUrl &url, bool allowNull)
return allowNull ? QImage() : IconProvider::emptyWebImage(); return allowNull ? QImage() : IconProvider::emptyWebImage();
} }
QMutexLocker locker(&instance()->m_iconCacheMutex);
const QByteArray encodedUrl = encodeUrl(url); const QByteArray encodedUrl = encodeUrl(url);
if (QImage *img = instance()->m_urlImageCache.object(encodedUrl)) { if (QImage *img = instance()->m_urlImageCache.object(encodedUrl)) {
@ -224,6 +226,8 @@ QImage IconProvider::imageForDomain(const QUrl &url, bool allowNull)
return allowNull ? QImage() : IconProvider::emptyWebImage(); return allowNull ? QImage() : IconProvider::emptyWebImage();
} }
QMutexLocker locker(&instance()->m_iconCacheMutex);
foreach (const BufferedIcon &ic, instance()->m_iconBuffer) { foreach (const BufferedIcon &ic, instance()->m_iconBuffer) {
if (ic.first.host() == url.host()) { if (ic.first.host() == url.host()) {
return ic.second; return ic.second;
@ -249,6 +253,8 @@ IconProvider* IconProvider::instance()
void IconProvider::saveIconsToDatabase() void IconProvider::saveIconsToDatabase()
{ {
QMutexLocker locker(&instance()->m_iconCacheMutex);
foreach (const BufferedIcon &ic, m_iconBuffer) { foreach (const BufferedIcon &ic, m_iconBuffer) {
QByteArray ba; QByteArray ba;
QBuffer buffer(&ba); QBuffer buffer(&ba);

View File

@ -23,6 +23,7 @@
#include <QImage> #include <QImage>
#include <QUrl> #include <QUrl>
#include <QCache> #include <QCache>
#include <QMutex>
#include <functional> #include <functional>
@ -82,6 +83,7 @@ private:
QIcon m_bookmarkIcon; QIcon m_bookmarkIcon;
QVector<BufferedIcon> m_iconBuffer; QVector<BufferedIcon> m_iconBuffer;
QCache<QByteArray, QImage> m_urlImageCache; QCache<QByteArray, QImage> m_urlImageCache;
QMutex m_iconCacheMutex;
AutoSaver* m_autoSaver; AutoSaver* m_autoSaver;
}; };