summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <tmpsantos@gmail.com>2019-02-19 18:16:25 +0200
committerThiago Marcos P. Santos <tmpsantos@gmail.com>2019-02-19 18:16:25 +0200
commit960e855bbbec2f9af803281979239bebc8c13dcb (patch)
tree81b2ad180f77e6406d323fe5adc4f2ea2c623ad7
parent056073a904361ef9b18e0c38abd7f5c6a187ef22 (diff)
downloadqtlocation-mapboxgl-upstream/tmpsantos-qt_filesource_token.tar.gz
[qt] Share the same file source only if using the same access tokenupstream/tmpsantos-qt_filesource_token
If access tokens are different, we cannot share the file source, because it will override the previously set access token.
-rw-r--r--platform/qt/src/qmapboxgl.cpp27
1 files changed, 14 insertions, 13 deletions
diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp
index 721bba8ff0..08e3733437 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 {