diff options
author | Thiago Marcos P. Santos <tmpsantos@gmail.com> | 2019-02-19 18:16:25 +0200 |
---|---|---|
committer | Thiago Marcos P. Santos <tmpsantos@gmail.com> | 2019-02-27 13:31:21 +0200 |
commit | edc6a5dd8bc293a9869581257d18ad1e054f724f (patch) | |
tree | a173c9069e6a7d0fe25b6c246b0a3ab4346b3c0e /platform/qt | |
parent | 0a41bb1e666c7c16b49993152682c67a6a1f49c8 (diff) | |
download | qtlocation-mapboxgl-edc6a5dd8bc293a9869581257d18ad1e054f724f.tar.gz |
[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.
Diffstat (limited to 'platform/qt')
-rw-r--r-- | platform/qt/src/qmapboxgl.cpp | 27 |
1 files 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<std::shared_ptr<mbgl::util::RunLoop>> loop; -std::shared_ptr<mbgl::DefaultFileSource> sharedDefaultFileSource( - const std::string& cachePath, const std::string& assetRoot, uint64_t maximumCacheSize) { +std::shared_ptr<mbgl::DefaultFileSource> sharedDefaultFileSource(const QMapboxGLSettings &settings) { static std::mutex mutex; static std::unordered_map<std::string, std::weak_ptr<mbgl::DefaultFileSource>> fileSources; + const std::string cachePath = settings.cacheDatabasePath().toStdString(); + const std::string accessToken = settings.accessToken().toStdString(); + std::lock_guard<std::mutex> lock(mutex); // Purge entries no longer in use. @@ -107,17 +109,23 @@ std::shared_ptr<mbgl::DefaultFileSource> 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<mbgl::DefaultFileSource>( - 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::Actor<mbgl::ResourceTransform>>(*mbgl::Scheduler::GetCurrent(), [callback = settings.resourceTransform()] (mbgl::Resource::Kind, const std::string &&url_) -> std::string { |