From edc6a5dd8bc293a9869581257d18ad1e054f724f Mon Sep 17 00:00:00 2001 From: "Thiago Marcos P. Santos" Date: Tue, 19 Feb 2019 18:16:25 +0200 Subject: [qt] Share the same file source only if using the same access token If access tokens are different, we cannot share the file source, because it will override the previously set access token. --- platform/qt/src/qmapboxgl.cpp | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp index c0ea5efd34..203a1a5341 100644 --- a/platform/qt/src/qmapboxgl.cpp +++ b/platform/qt/src/qmapboxgl.cpp @@ -91,11 +91,13 @@ namespace { QThreadStorage> loop; -std::shared_ptr sharedDefaultFileSource( - const std::string& cachePath, const std::string& assetRoot, uint64_t maximumCacheSize) { +std::shared_ptr sharedDefaultFileSource(const QMapboxGLSettings &settings) { static std::mutex mutex; static std::unordered_map> fileSources; + const std::string cachePath = settings.cacheDatabasePath().toStdString(); + const std::string accessToken = settings.accessToken().toStdString(); + std::lock_guard lock(mutex); // Purge entries no longer in use. @@ -107,17 +109,23 @@ std::shared_ptr sharedDefaultFileSource( } } + const auto key = cachePath + "|" + accessToken; + // Return an existing FileSource if available. - auto sharedFileSource = fileSources.find(cachePath); + auto sharedFileSource = fileSources.find(key); if (sharedFileSource != fileSources.end()) { return sharedFileSource->second.lock(); } // New path, create a new FileSource. auto newFileSource = std::make_shared( - cachePath, assetRoot, maximumCacheSize); + cachePath, settings.assetPath().toStdString(), settings.cacheDatabaseMaximumSize()); + + // Setup the FileSource + newFileSource->setAccessToken(accessToken); + newFileSource->setAPIBaseURL(settings.apiBaseUrl().toStdString()); - fileSources[cachePath] = newFileSource; + fileSources[key] = newFileSource; return newFileSource; } @@ -1735,19 +1743,12 @@ void QMapboxGL::connectionEstablished() QMapboxGLPrivate::QMapboxGLPrivate(QMapboxGL *q, const QMapboxGLSettings &settings, const QSize &size, qreal pixelRatio_) : QObject(q) - , m_fileSourceObj(sharedDefaultFileSource( - settings.cacheDatabasePath().toStdString(), - settings.assetPath().toStdString(), - settings.cacheDatabaseMaximumSize())) + , m_fileSourceObj(sharedDefaultFileSource(settings)) , m_threadPool(mbgl::sharedThreadPool()) , m_mode(settings.contextMode()) , m_pixelRatio(pixelRatio_) , m_localFontFamily(settings.localFontFamily()) { - // Setup the FileSource - m_fileSourceObj->setAccessToken(settings.accessToken().toStdString()); - m_fileSourceObj->setAPIBaseURL(settings.apiBaseUrl().toStdString()); - if (settings.resourceTransform()) { m_resourceTransform = std::make_unique>(*mbgl::Scheduler::GetCurrent(), [callback = settings.resourceTransform()] (mbgl::Resource::Kind, const std::string &&url_) -> std::string { -- cgit v1.2.1