diff options
author | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2019-06-13 18:56:35 +0300 |
---|---|---|
committer | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2019-06-25 20:10:21 +0300 |
commit | 1a9e07e4ed930f33a28d0eac800bccaa2a84570e (patch) | |
tree | da680c8cb603e4427c42ac90ad54480011ffeec2 | |
parent | 8367c2ed5c32eae1364e5fc27e734631cf69aae3 (diff) | |
download | qtlocation-mapboxgl-1a9e07e4ed930f33a28d0eac800bccaa2a84570e.tar.gz |
[core] DefaultFileSource dynamic support for cache-only requests
-rw-r--r-- | include/mbgl/storage/default_file_source.hpp | 17 | ||||
-rw-r--r-- | include/mbgl/storage/resource_options.hpp | 15 | ||||
-rw-r--r-- | platform/default/src/mbgl/storage/default_file_source.cpp | 13 | ||||
-rw-r--r-- | platform/default/src/mbgl/storage/file_source.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/storage/resource_options.cpp | 10 |
5 files changed, 40 insertions, 17 deletions
diff --git a/include/mbgl/storage/default_file_source.hpp b/include/mbgl/storage/default_file_source.hpp index f46f41771e..4f4c7136c6 100644 --- a/include/mbgl/storage/default_file_source.hpp +++ b/include/mbgl/storage/default_file_source.hpp @@ -23,20 +23,11 @@ using PathChangeCallback = std::function<void ()>; class DefaultFileSource : public FileSource { public: - /* - * The maximumCacheSize parameter is a limit applied to non-offline resources only, - * i.e. resources added to the database for the "ambient use" caching functionality. - * There is no size limit for offline resources. If a user never creates any offline - * regions, we want the database to remain fairly small (order tens or low hundreds - * of megabytes). - */ - DefaultFileSource(const std::string& cachePath, const std::string& assetPath); - DefaultFileSource(const std::string& cachePath, std::unique_ptr<FileSource>&& assetFileSource); + DefaultFileSource(const std::string& cachePath, const std::string& assetPath, bool supportCacheOnlyRequests = true); + DefaultFileSource(const std::string& cachePath, std::unique_ptr<FileSource>&& assetFileSource, bool supportCacheOnlyRequests = true); ~DefaultFileSource() override; - bool supportsCacheOnlyRequests() const override { - return true; - } + bool supportsCacheOnlyRequests() const override; void setAPIBaseURL(const std::string&); std::string getAPIBaseURL(); @@ -253,6 +244,8 @@ private: std::mutex cachedAccessTokenMutex; std::string cachedAccessToken; + + const bool supportCacheOnlyRequests; }; } // namespace mbgl diff --git a/include/mbgl/storage/resource_options.hpp b/include/mbgl/storage/resource_options.hpp index 6d603b8cca..53350f55c2 100644 --- a/include/mbgl/storage/resource_options.hpp +++ b/include/mbgl/storage/resource_options.hpp @@ -97,6 +97,21 @@ public: uint64_t maximumCacheSize() const; /** + * @brief Sets whether to support cache-only requests. + * + * @return Whether or not cache-only requests are supported. + */ + bool supportsCacheOnlyRequests() const; + + /** + * @brief Gets the previously set (or default) support for cache-only requests. + * + * @param Whether or not cache-only requests are supported. + * @return reference to ResourceOptions for chaining options together. + */ + ResourceOptions& withCacheOnlyRequestsSupport(bool); + + /** * @brief Sets the platform context. A platform context is usually an object * that assists the creation of a file source. * diff --git a/platform/default/src/mbgl/storage/default_file_source.cpp b/platform/default/src/mbgl/storage/default_file_source.cpp index 19932d8d00..dc4b2908a8 100644 --- a/platform/default/src/mbgl/storage/default_file_source.cpp +++ b/platform/default/src/mbgl/storage/default_file_source.cpp @@ -224,17 +224,22 @@ private: std::unordered_map<int64_t, std::unique_ptr<OfflineDownload>> downloads; }; -DefaultFileSource::DefaultFileSource(const std::string& cachePath, const std::string& assetPath) - : DefaultFileSource(cachePath, std::make_unique<AssetFileSource>(assetPath)) { +DefaultFileSource::DefaultFileSource(const std::string& cachePath, const std::string& assetPath, bool supportCacheOnlyRequests_) + : DefaultFileSource(cachePath, std::make_unique<AssetFileSource>(assetPath), supportCacheOnlyRequests_) { } -DefaultFileSource::DefaultFileSource(const std::string& cachePath, std::unique_ptr<FileSource>&& assetFileSource_) +DefaultFileSource::DefaultFileSource(const std::string& cachePath, std::unique_ptr<FileSource>&& assetFileSource_, bool supportCacheOnlyRequests_) : assetFileSource(std::move(assetFileSource_)) - , impl(std::make_unique<util::Thread<Impl>>("DefaultFileSource", assetFileSource, cachePath)) { + , impl(std::make_unique<util::Thread<Impl>>("DefaultFileSource", assetFileSource, cachePath)) + , supportCacheOnlyRequests(supportCacheOnlyRequests_) { } DefaultFileSource::~DefaultFileSource() = default; +bool DefaultFileSource::supportsCacheOnlyRequests() const { + return supportCacheOnlyRequests; +} + void DefaultFileSource::setAPIBaseURL(const std::string& baseURL) { impl->actor().invoke(&Impl::setAPIBaseURL, baseURL); diff --git a/platform/default/src/mbgl/storage/file_source.cpp b/platform/default/src/mbgl/storage/file_source.cpp index a7bbe82f5a..4e800cc8f4 100644 --- a/platform/default/src/mbgl/storage/file_source.cpp +++ b/platform/default/src/mbgl/storage/file_source.cpp @@ -6,7 +6,7 @@ namespace mbgl { std::shared_ptr<FileSource> FileSource::createPlatformFileSource(const ResourceOptions& options) { - auto fileSource = std::make_shared<DefaultFileSource>(options.cachePath(), options.assetPath()); + auto fileSource = std::make_shared<DefaultFileSource>(options.cachePath(), options.assetPath(), options.supportsCacheOnlyRequests()); fileSource->setAccessToken(options.accessToken()); fileSource->setAPIBaseURL(options.baseURL()); return fileSource; diff --git a/src/mbgl/storage/resource_options.cpp b/src/mbgl/storage/resource_options.cpp index c56a22540b..21ecca979a 100644 --- a/src/mbgl/storage/resource_options.cpp +++ b/src/mbgl/storage/resource_options.cpp @@ -10,6 +10,7 @@ public: std::string cachePath = ":memory:"; std::string assetPath = "."; uint64_t maximumSize = mbgl::util::DEFAULT_MAX_CACHE_SIZE; + bool supportCacheOnlyRequests = true; void* platformContext = nullptr; }; @@ -68,6 +69,15 @@ uint64_t ResourceOptions::maximumCacheSize() const { return impl_->maximumSize; } +ResourceOptions& ResourceOptions::withCacheOnlyRequestsSupport(bool supportCacheOnlyRequests) { + impl_->supportCacheOnlyRequests = supportCacheOnlyRequests; + return *this; +} + +bool ResourceOptions::supportsCacheOnlyRequests() const { + return impl_->supportCacheOnlyRequests; +} + ResourceOptions& ResourceOptions::withPlatformContext(void* context) { impl_->platformContext = context; return *this; |