summaryrefslogtreecommitdiff
path: root/src/mbgl/platform/factory.cpp
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2019-03-07 23:24:52 +0200
committerBruno de Oliveira Abinader <bruno@mapbox.com>2019-03-08 18:37:41 +0200
commit2144e3f3b0b8f08b65c854225d7360847633f689 (patch)
tree16cadc63b1c3d438c5ddd4bf67aadb2e72e23130 /src/mbgl/platform/factory.cpp
parent2f88e8257b83b77f6c06c86c99f542976e7d5199 (diff)
downloadqtlocation-mapboxgl-upstream/map-refactor.tar.gz
[core] Implement platform::Factory::sharedFileSource()upstream/map-refactor
Diffstat (limited to 'src/mbgl/platform/factory.cpp')
-rw-r--r--src/mbgl/platform/factory.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/mbgl/platform/factory.cpp b/src/mbgl/platform/factory.cpp
new file mode 100644
index 0000000000..6f595f9866
--- /dev/null
+++ b/src/mbgl/platform/factory.cpp
@@ -0,0 +1,27 @@
+#include <mbgl/platform/factory.hpp>
+#include <mbgl/storage/default_file_source.hpp>
+
+namespace mbgl {
+namespace platform {
+
+std::shared_ptr<FileSource> Factory::sharedFileSource(const FileSourceOptions& options, std::shared_ptr<FileSource> initial) {
+ static std::weak_ptr<FileSource> weak;
+
+ if (initial) {
+ // We can only assign a custom initial value if the weak pointer object has zero references.
+ assert(weak.use_count() == 0);
+ weak = initial;
+ }
+
+ std::shared_ptr<FileSource> strong = weak.lock();
+ if (!strong) {
+ auto defaultFileSource = std::make_shared<DefaultFileSource>(options.cachePath(), options.assetRoot(), options.maximumCacheSize());
+ defaultFileSource->setAccessToken(options.accessToken());
+ weak = strong = defaultFileSource;
+ }
+
+ return strong;
+}
+
+} // namespace platform
+} // namespace mbgl