diff --git a/src/mbgl/storage/file_source_manager.cpp b/src/mbgl/storage/file_source_manager.cpp index 6817717f1a1..62fd5e8f98c 100644 --- a/src/mbgl/storage/file_source_manager.cpp +++ b/src/mbgl/storage/file_source_manager.cpp @@ -2,16 +2,26 @@ #include #include +#include +#include #include #include #include namespace mbgl { +struct FileSourceInfo { + FileSourceInfo(FileSourceType type_, std::string id_, std::weak_ptr fileSource_) + : type(type_), id(std::move(id_)), fileSource(std::move(fileSource_)) {} + + FileSourceType type; + std::string id; + std::weak_ptr fileSource; +}; + class FileSourceManager::Impl { public: - using Key = std::tuple; - std::map> fileSources; + std::list fileSources; std::map fileSourceFactories; std::recursive_mutex mutex; }; @@ -26,25 +36,27 @@ std::shared_ptr FileSourceManager::getFileSource(FileSourceType type // Remove released file sources. for (auto it = impl->fileSources.begin(); it != impl->fileSources.end();) { - it = it->second.expired() ? impl->fileSources.erase(it) : ++it; + it = it->fileSource.expired() ? impl->fileSources.erase(it) : ++it; } const auto context = reinterpret_cast(options.platformContext()); - const std::string optionsKey = + std::string id = options.baseURL() + '|' + options.accessToken() + '|' + options.cachePath() + '|' + util::toString(context); - const auto key = std::tie(type, optionsKey); std::shared_ptr fileSource; - auto tuple = impl->fileSources.find(key); - if (tuple != impl->fileSources.end()) { - fileSource = tuple->second.lock(); + auto fileSourceIt = std::find_if(impl->fileSources.begin(), impl->fileSources.end(), [type, &id](const auto& info) { + return info.type == type && info.id == id; + }); + if (fileSourceIt != impl->fileSources.end()) { + fileSource = fileSourceIt->fileSource.lock(); } if (!fileSource) { auto it = impl->fileSourceFactories.find(type); if (it != impl->fileSourceFactories.end()) { assert(it->second); - impl->fileSources[key] = fileSource = it->second(options); + fileSource = it->second(options); + impl->fileSources.emplace_back(type, std::move(id), fileSource); } }