summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAlexander Shalamov <alexander.shalamov@mapbox.com>2019-10-04 15:02:01 +0300
committerAlexander Shalamov <alexander.shalamov@mapbox.com>2020-01-13 10:57:23 +0200
commit879c44f661c5eb762c93a721b657859a71aabfc7 (patch)
tree3a542777434e0d685811ce1c66b752dc9ca36e92 /include
parent86a360534994cb37d3dddc53b71a2858d97419c3 (diff)
downloadqtlocation-mapboxgl-879c44f661c5eb762c93a721b657859a71aabfc7.tar.gz
[core] Modularize FileSource codebase (#15768)
* [core] Introduce FileSourceManager and use it for default platform impl - Add `FileSourceManager` interface that provides access to `FileSource` instances and means of registering / unregistering `FileSource` factories - Split `DefaultFileSource` into smaller parts - Add `DatabaseFileSource` interface and it's default implementation - Remove inter-dependencies between concrete `FileSource` classes * [build] Add files to next build system * [core] Add generic property setters / getters * [core] Remove setOnlineStatus from OnlineFileSource interface * [core] Hide threading implementation details from DatabaseFileSource interface * [core] Make DB file source methods virtual * [core] Add documentation for DatabaseFileSource and rename one method * [core] Use simple callback instead of ActorRef * [core] Remove ActorRef from OnlineFileSource public header * [core] Add callback to FileSource::forward async API * [core] Pass OfflineRegionDefinition by value * [core] Update tests to use modular file sources * [core] Update unit tests * [core] Update unit tests after rebase * [core] Backport low prio fix for cached requests * [core] Backport pack database * [core] Return removed factory from unRegisterFileSourceFactory * [core] Rename shadowed args in onlinefilesource * [core] Remove simple std::function callback aliases * [core] Expose online file source property keys in public header file * [test-runner] Add proxy file source test runner * [cache] Update mbgl-cache utility to use new file source * [metrics] Rebaseline binary size metrics * [offline] Update offline utility * [core] Update changelog
Diffstat (limited to 'include')
-rw-r--r--include/mbgl/storage/database_file_source.hpp (renamed from include/mbgl/storage/default_file_source.hpp)295
-rw-r--r--include/mbgl/storage/file_source.hpp63
-rw-r--r--include/mbgl/storage/file_source_manager.hpp50
-rw-r--r--include/mbgl/storage/online_file_source.hpp42
-rw-r--r--include/mbgl/storage/resource.hpp4
-rw-r--r--include/mbgl/storage/resource_options.hpp15
-rw-r--r--include/mbgl/storage/resource_transform.hpp13
-rw-r--r--include/mbgl/style/style.hpp2
-rw-r--r--include/mbgl/util/constants.hpp3
9 files changed, 261 insertions, 226 deletions
diff --git a/include/mbgl/storage/default_file_source.hpp b/include/mbgl/storage/database_file_source.hpp
index fdd430ccad..8ccb5ce39b 100644
--- a/include/mbgl/storage/default_file_source.hpp
+++ b/include/mbgl/storage/database_file_source.hpp
@@ -1,45 +1,128 @@
#pragma once
-#include <mbgl/actor/actor_ref.hpp>
#include <mbgl/storage/file_source.hpp>
#include <mbgl/storage/offline.hpp>
-#include <mbgl/util/constants.hpp>
-#include <mbgl/util/optional.hpp>
#include <mbgl/util/expected.hpp>
-
-#include <vector>
-#include <mutex>
+#include <mbgl/util/optional.hpp>
namespace mbgl {
-namespace util {
-template <typename T> class Thread;
-} // namespace util
+class ResourceOptions;
-class ResourceTransform;
+// TODO: Split DatabaseFileSource into Ambient cache and Database interfaces.
+class DatabaseFileSource : public FileSource {
+public:
+ explicit DatabaseFileSource(const ResourceOptions& options);
+ ~DatabaseFileSource() override;
-// TODO: the callback should include a potential error info when https://github.com/mapbox/mapbox-gl-native/issues/14759 is resolved
-using PathChangeCallback = std::function<void ()>;
+ // FileSource overrides
+ std::unique_ptr<AsyncRequest> request(const Resource&, Callback) override;
+ void forward(const Resource&, const Response&, std::function<void()> callback) override;
+ bool canRequest(const Resource&) const override;
+ void setProperty(const std::string&, const mapbox::base::Value&) override;
-class DefaultFileSource : public FileSource {
-public:
- 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;
+ // Methods common to Ambient cache and Offline functionality
- bool supportsCacheOnlyRequests() const override;
+ /*
+ * Sets path of a database to be used by DatabaseFileSource and invokes provided
+ * callback when a database path is set.
+ */
+ virtual void setDatabasePath(const std::string&, std::function<void()> callback);
- void setAPIBaseURL(const std::string&);
- std::string getAPIBaseURL();
+ /*
+ * Delete existing database and re-initialize.
+ *
+ * When the operation is complete or encounters an error, the given callback will be
+ * executed on the database thread; it is the responsibility of the SDK bindings
+ * to re-execute a user-provided callback on the main thread.
+ */
+ virtual void resetDatabase(std::function<void(std::exception_ptr)>);
- void setAccessToken(const std::string&);
- std::string getAccessToken();
+ /*
+ * Packs the existing database file into a minimal amount of disk space.
+ *
+ * This operation has a performance impact as it will vacuum the database,
+ * forcing it to move pages on the filesystem.
+ *
+ * When the operation is complete or encounters an error, the given callback will be
+ * executed on the database thread; it is the responsibility of the SDK bindings
+ * to re-execute a user-provided callback on the main thread.
+ */
+ virtual void packDatabase(std::function<void(std::exception_ptr)> callback);
- void setResourceTransform(optional<ActorRef<ResourceTransform>>&&);
+ /*
+ * Sets whether packing the database file occurs automatically after an offline
+ * region is deleted (deleteOfflineRegion()) or the ambient cache is cleared
+ * (clearAmbientCache()).
+ *
+ * By default, packing is enabled. If disabled, disk space will not be freed
+ * after resources are removed unless packDatabase() is explicitly called.
+ */
+ virtual void runPackDatabaseAutomatically(bool);
- void setResourceCachePath(const std::string&, optional<ActorRef<PathChangeCallback>>&&);
+ // Ambient cache
- std::unique_ptr<AsyncRequest> request(const Resource&, Callback) override;
+ /*
+ * Insert the provided resource into the ambient cache
+ *
+ * Consumers of the resource will expect the uncompressed version; the
+ * OfflineDatabase will determine whether to compress the data on disk.
+ * This call is asynchronous: the data may not be immediately available
+ * for in-progress requests, although subsequent requests should have
+ * access to the cached data.
+ */
+ virtual void put(const Resource&, const Response&);
+
+ /*
+ * Forces revalidation of the ambient cache.
+ *
+ * Forces Mapbox GL Native to revalidate resources stored in the ambient
+ * cache with the tile server before using them, making sure they
+ * are the latest version. This is more efficient than cleaning the
+ * cache because if the resource is considered valid after the server
+ * lookup, it will not get downloaded again.
+ *
+ * Resources overlapping with offline regions will not be affected
+ * by this call.
+ */
+ virtual void invalidateAmbientCache(std::function<void(std::exception_ptr)>);
+
+ /*
+ * Erase resources from the ambient cache, freeing storage space.
+ *
+ * Erases the ambient cache, freeing resources.
+ *
+ * Note that this operation can be potentially slow if packing the database
+ * occurs automatically (see runPackDatabaseAutomatically() and packDatabase()).
+ *
+ * Resources overlapping with offline regions will not be affected
+ * by this call.
+ */
+ virtual void clearAmbientCache(std::function<void(std::exception_ptr)>);
+
+ /*
+ * Sets the maximum size in bytes for the ambient cache.
+ *
+ * This call is potentially expensive because it will try
+ * to trim the data in case the database is larger than the
+ * size defined. The size of offline regions are not affected
+ * by this settings, but the ambient cache will always try
+ * to not exceed the maximum size defined, taking into account
+ * the current size for the offline regions.
+ *
+ * If the maximum size is set to 50 MB and 40 MB are already
+ * used by offline regions, the cache size will be effectively
+ * 10 MB.
+ *
+ * Setting the size to 0 will disable the cache if there is no
+ * offline region on the database.
+ *
+ * This method should always be called before using the database,
+ * otherwise the default maximum size will be used.
+ */
+ virtual void setMaximumAmbientCacheSize(uint64_t size, std::function<void(std::exception_ptr)> callback);
+
+ // Offline
/*
* Retrieve all regions in the offline database.
@@ -48,7 +131,7 @@ public:
* callback, which will be executed on the database thread; it is the responsibility
* of the SDK bindings to re-execute a user-provided callback on the main thread.
*/
- void listOfflineRegions(std::function<void (expected<OfflineRegions, std::exception_ptr>)>);
+ virtual void listOfflineRegions(std::function<void(expected<OfflineRegions, std::exception_ptr>)>);
/*
* Create an offline region in the database.
@@ -61,25 +144,25 @@ public:
* downloading resources, call `setOfflineRegionDownloadState(OfflineRegionDownloadState::Active)`,
* optionally registering an `OfflineRegionObserver` beforehand.
*/
- void createOfflineRegion(const OfflineRegionDefinition& definition,
- const OfflineRegionMetadata& metadata,
- std::function<void (expected<OfflineRegion, std::exception_ptr>)>);
-
+ virtual void createOfflineRegion(const OfflineRegionDefinition& definition,
+ const OfflineRegionMetadata& metadata,
+ std::function<void(expected<OfflineRegion, std::exception_ptr>)>);
/*
* Update an offline region metadata in the database.
*/
- void updateOfflineMetadata(const int64_t regionID,
- const OfflineRegionMetadata& metadata,
- std::function<void (expected<OfflineRegionMetadata, std::exception_ptr>)>);
+ virtual void updateOfflineMetadata(const int64_t regionID,
+ const OfflineRegionMetadata& metadata,
+ std::function<void(expected<OfflineRegionMetadata, std::exception_ptr>)>);
+
/*
* Register an observer to be notified when the state of the region changes.
*/
- void setOfflineRegionObserver(OfflineRegion&, std::unique_ptr<OfflineRegionObserver>);
+ virtual void setOfflineRegionObserver(OfflineRegion&, std::unique_ptr<OfflineRegionObserver>);
/*
* Pause or resume downloading of regional resources.
*/
- void setOfflineRegionDownloadState(OfflineRegion&, OfflineRegionDownloadState);
+ virtual void setOfflineRegionDownloadState(OfflineRegion&, OfflineRegionDownloadState);
/*
* Retrieve the current status of the region. The query will be executed
@@ -87,9 +170,8 @@ public:
* executed on the database thread; it is the responsibility of the SDK bindings
* to re-execute a user-provided callback on the main thread.
*/
- void getOfflineRegionStatus(
- OfflineRegion&,
- std::function<void (expected<OfflineRegionStatus, std::exception_ptr>)>) const;
+ virtual void getOfflineRegionStatus(OfflineRegion&,
+ std::function<void(expected<OfflineRegionStatus, std::exception_ptr>)>) const;
/*
* Merge offline regions from a secondary database into the main offline database.
@@ -111,8 +193,8 @@ public:
* Merged regions may not be in a completed status if the secondary database
* does not contain all the tiles or resources required by the region definition.
*/
- void mergeOfflineRegions(const std::string& sideDatabasePath,
- std::function<void (expected<OfflineRegions, std::exception_ptr>)>);
+ virtual void mergeOfflineRegions(const std::string& sideDatabasePath,
+ std::function<void(expected<OfflineRegions, std::exception_ptr>)>);
/*
* Remove an offline region from the database and perform any resources evictions
@@ -132,7 +214,7 @@ public:
* executed on the database thread; it is the responsibility of the SDK bindings
* to re-execute a user-provided callback on the main thread.
*/
- void deleteOfflineRegion(OfflineRegion&&, std::function<void(std::exception_ptr)>);
+ virtual void deleteOfflineRegion(OfflineRegion, std::function<void(std::exception_ptr)>);
/*
* Invalidate all the tiles from an offline region forcing Mapbox GL to revalidate
@@ -140,140 +222,17 @@ public:
* offline region and downloading it again because if the data on the cache matches
* the server, no new data gets transmitted.
*/
- void invalidateOfflineRegion(OfflineRegion&, std::function<void(std::exception_ptr)>);
+ virtual void invalidateOfflineRegion(OfflineRegion&, std::function<void(std::exception_ptr)>);
/*
* Changing or bypassing this limit without permission from Mapbox is prohibited
* by the Mapbox Terms of Service.
*/
- void setOfflineMapboxTileCountLimit(uint64_t) const;
-
- /*
- * Pause file request activity.
- *
- * If pause is called then no revalidation or network request activity
- * will occur.
- */
- void pause();
-
- /*
- * Resume file request activity.
- *
- * Calling resume will unpause the file source and process any tasks that
- * expired while the file source was paused.
- */
- void resume();
-
- /*
- * Insert the provided resource into the ambient cache
- *
- * Consumers of the resource will expect the uncompressed version; the
- * OfflineDatabase will determine whether to compress the data on disk.
- * This call is asynchronous: the data may not be immediately available
- * for in-progress requests, although subsequent requests should have
- * access to the cached data.
- */
- void put(const Resource&, const Response&);
-
- /*
- * Delete existing database and re-initialize.
- *
- * When the operation is complete or encounters an error, the given callback will be
- * executed on the database thread; it is the responsibility of the SDK bindings
- * to re-execute a user-provided callback on the main thread.
- */
- void resetDatabase(std::function<void(std::exception_ptr)>);
-
- /*
- * Packs the existing database file into a minimal amount of disk space.
- *
- * This operation has a performance impact as it will vacuum the database,
- * forcing it to move pages on the filesystem.
- *
- * When the operation is complete or encounters an error, the given callback will be
- * executed on the database thread; it is the responsibility of the SDK bindings
- * to re-execute a user-provided callback on the main thread.
- */
- void packDatabase(std::function<void(std::exception_ptr)> callback);
-
- /*
- * Sets whether packing the database file occurs automatically after an offline
- * region is deleted (deleteOfflineRegion()) or the ambient cache is cleared
- * (clearAmbientCache()).
- *
- * By default, packing is enabled. If disabled, disk space will not be freed
- * after resources are removed unless packDatabase() is explicitly called.
- */
- void runPackDatabaseAutomatically(bool);
-
- /*
- * Forces revalidation of the ambient cache.
- *
- * Forces Mapbox GL Native to revalidate resources stored in the ambient
- * cache with the tile server before using them, making sure they
- * are the latest version. This is more efficient than cleaning the
- * cache because if the resource is considered valid after the server
- * lookup, it will not get downloaded again.
- *
- * Resources overlapping with offline regions will not be affected
- * by this call.
- */
- void invalidateAmbientCache(std::function<void (std::exception_ptr)>);
-
- /*
- * Erase resources from the ambient cache, freeing storage space.
- *
- * Erases the ambient cache, freeing resources.
- *
- * Note that this operation can be potentially slow if packing the database
- * occurs automatically (see runPackDatabaseAutomatically() and packDatabase()).
- *
- * Resources overlapping with offline regions will not be affected
- * by this call.
- */
- void clearAmbientCache(std::function<void (std::exception_ptr)>);
-
- /*
- * Sets the maximum size in bytes for the ambient cache.
- *
- * This call is potentially expensive because it will try
- * to trim the data in case the database is larger than the
- * size defined. The size of offline regions are not affected
- * by this settings, but the ambient cache will always try
- * to not exceed the maximum size defined, taking into account
- * the current size for the offline regions.
- *
- * If the maximum size is set to 50 MB and 40 MB are already
- * used by offline regions, the cache size will be effectively
- * 10 MB.
- *
- * Setting the size to 0 will disable the cache if there is no
- * offline region on the database.
- *
- * This method should always be called before using the database,
- * otherwise the default maximum size will be used.
- */
- void setMaximumAmbientCacheSize(uint64_t size, std::function<void (std::exception_ptr)> callback);
-
- // For testing only.
- void setOnlineStatus(bool);
- void reopenDatabaseReadOnlyForTesting();
- void setMaximumConcurrentRequests(uint32_t);
-
- class Impl;
+ virtual void setOfflineMapboxTileCountLimit(uint64_t) const;
private:
- // Shared so destruction is done on this thread
- const std::shared_ptr<FileSource> assetFileSource;
- const std::unique_ptr<util::Thread<Impl>> impl;
-
- std::mutex cachedBaseURLMutex;
- std::string cachedBaseURL = mbgl::util::API_BASE_URL;
-
- std::mutex cachedAccessTokenMutex;
- std::string cachedAccessToken;
-
- const bool supportCacheOnlyRequests;
+ class Impl;
+ const std::unique_ptr<Impl> impl;
};
} // namespace mbgl
diff --git a/include/mbgl/storage/file_source.hpp b/include/mbgl/storage/file_source.hpp
index 2270038c49..f05f1473e9 100644
--- a/include/mbgl/storage/file_source.hpp
+++ b/include/mbgl/storage/file_source.hpp
@@ -1,19 +1,34 @@
#pragma once
-#include <mbgl/actor/actor_ref.hpp>
#include <mbgl/storage/response.hpp>
-#include <mbgl/storage/resource.hpp>
-#include <mbgl/util/async_request.hpp>
+#include <mapbox/value.hpp>
#include <functional>
#include <memory>
namespace mbgl {
-class ResourceOptions;
-class ResourceTransform;
+class AsyncRequest;
+class Resource;
+// TODO: Rename to ResourceProviderType
+enum FileSourceType : uint8_t {
+ Asset,
+ // TODO: split to separate types
+ // - Cache for fast KV store (FASTER, LevelDB, RocksDB)
+ // - Database for read-only offline use-cases
+ Database,
+ FileSystem,
+ Network,
+ // Resource loader acts as a proxy and has logic
+ // for request delegation to Asset, Cache, and other
+ // file sources.
+ ResourceLoader
+};
+
+// TODO: Rename to ResourceProvider to avoid confusion with
+// GeoJSONSource, RasterSource, VectorSource, CustomGeometrySource and other *Sources.
class FileSource {
public:
FileSource(const FileSource&) = delete;
@@ -29,22 +44,44 @@ public:
// not be executed.
virtual std::unique_ptr<AsyncRequest> request(const Resource&, Callback) = 0;
+ // Allows to forward response from one source to another.
+ // Optionally, callback can be provided to receive notification for forward
+ // operation.
+ virtual void forward(const Resource&, const Response&, std::function<void()> = {}) {}
+
// When a file source supports consulting a local cache only, it must return true.
// Cache-only requests are requests that aren't as urgent, but could be useful, e.g.
// to cover part of the map while loading. The FileSource should only do cheap actions to
// retrieve the data, e.g. load it from a cache, but not from the internet.
- virtual bool supportsCacheOnlyRequests() const {
- return false;
- }
+ virtual bool supportsCacheOnlyRequests() const { return false; }
+
+ // Checks whether a resource could be requested from this file source.
+ virtual bool canRequest(const Resource&) const = 0;
+
+ /*
+ * Pause file request activity.
+ *
+ * If pause is called then no revalidation or network request activity
+ * will occur.
+ */
+ virtual void pause() {}
+
+ /*
+ * Resume file request activity.
+ *
+ * Calling resume will unpause the file source and process any tasks that
+ * expired while the file source was paused.
+ */
+ virtual void resume() {}
- // Singleton for obtaining the shared platform-specific file source. A single instance of a file source is provided
- // for each unique combination of a Mapbox API base URL, access token, cache path and platform context.
- static std::shared_ptr<FileSource> getSharedFileSource(const ResourceOptions&);
+ /*
+ * Generic property setter / getter methods.
+ */
+ virtual void setProperty(const std::string&, const mapbox::base::Value&){};
+ virtual mapbox::base::Value getProperty(const std::string&) const { return {}; };
protected:
FileSource() = default;
- // Factory for creating a platform-specific file source.
- static std::shared_ptr<FileSource> createPlatformFileSource(const ResourceOptions&);
};
} // namespace mbgl
diff --git a/include/mbgl/storage/file_source_manager.hpp b/include/mbgl/storage/file_source_manager.hpp
new file mode 100644
index 0000000000..2b2a43cbec
--- /dev/null
+++ b/include/mbgl/storage/file_source_manager.hpp
@@ -0,0 +1,50 @@
+#pragma once
+
+#include <mbgl/storage/file_source.hpp>
+
+namespace mbgl {
+
+class ResourceOptions;
+
+/**
+ * @brief A singleton class responsible for managing file sources.
+ *
+ * The FileSourceManager provides following functionality:
+ *
+ * - provides access to file sources of a specific type and configuration
+ * - caches previously created file sources of a (type, configuration) tuples
+ * - allows to register and unregister file source factories
+ */
+class FileSourceManager {
+public:
+ using FileSourceFactory = std::function<std::unique_ptr<FileSource>(const ResourceOptions&)>;
+
+ /**
+ * @brief A singleton getter.
+ *
+ * @return FileSourceManager*
+ */
+ static FileSourceManager* get() noexcept;
+
+ // Returns shared instance of a file source for (type, options) tuple.
+ // Creates new instance via registered factory if needed. If new instance cannot be
+ // created, nullptr would be returned.
+ std::shared_ptr<FileSource> getFileSource(FileSourceType, const ResourceOptions&) noexcept;
+
+ // Registers file source factory for a provided FileSourceType type. If factory for the
+ // same type was already registered, will unregister previously registered factory.
+ // Provided factory must not be null.
+ virtual void registerFileSourceFactory(FileSourceType, FileSourceFactory&&) noexcept;
+
+ // Unregisters file source factory. If there are no registered factories for a FileSourceType
+ // invocation has no effect.
+ virtual FileSourceFactory unRegisterFileSourceFactory(FileSourceType) noexcept;
+
+protected:
+ FileSourceManager();
+ class Impl;
+ std::unique_ptr<Impl> impl;
+ virtual ~FileSourceManager();
+};
+
+} // namespace mbgl
diff --git a/include/mbgl/storage/online_file_source.hpp b/include/mbgl/storage/online_file_source.hpp
index b2e9b43e5d..8969d21871 100644
--- a/include/mbgl/storage/online_file_source.hpp
+++ b/include/mbgl/storage/online_file_source.hpp
@@ -1,42 +1,46 @@
#pragma once
-#include <mbgl/actor/actor_ref.hpp>
#include <mbgl/storage/file_source.hpp>
-#include <mbgl/util/constants.hpp>
#include <mbgl/util/optional.hpp>
namespace mbgl {
class ResourceTransform;
+// Properties that may be supported by online file sources.
+
+// Property name to set / get an access token.
+// type: std::string
+constexpr const char* ACCESS_TOKEN_KEY = "access-token";
+
+// Property name to set / get base url.
+// type: std::string
+constexpr const char* API_BASE_URL_KEY = "api-base-url";
+
+// Property name to set / get maximum number of concurrent requests.
+// type: unsigned
+constexpr const char* MAX_CONCURRENT_REQUESTS_KEY = "max-concurrent-requests";
+
class OnlineFileSource : public FileSource {
public:
OnlineFileSource();
~OnlineFileSource() override;
- void setAPIBaseURL(const std::string& t) { apiBaseURL = t; }
- std::string getAPIBaseURL() const { return apiBaseURL; }
-
- void setAccessToken(const std::string& t) { accessToken = t; }
- std::string getAccessToken() const { return accessToken; }
-
- void setResourceTransform(optional<ActorRef<ResourceTransform>>&&);
-
+ // FileSource overrides
std::unique_ptr<AsyncRequest> request(const Resource&, Callback) override;
+ bool canRequest(const Resource&) const override;
+ void pause() override;
+ void resume() override;
+ void setProperty(const std::string&, const mapbox::base::Value&) override;
+ mapbox::base::Value getProperty(const std::string&) const override;
- void setMaximumConcurrentRequests(uint32_t);
- uint32_t getMaximumConcurrentRequests() const;
-
- // For testing only.
- void setOnlineStatus(bool);
+ // OnlineFileSource interface.
+ // TODO: Would be nice to drop it to get uniform interface.
+ virtual void setResourceTransform(ResourceTransform);
private:
- friend class OnlineFileRequest;
-
class Impl;
const std::unique_ptr<Impl> impl;
- std::string accessToken;
- std::string apiBaseURL = mbgl::util::API_BASE_URL;
};
} // namespace mbgl
diff --git a/include/mbgl/storage/resource.hpp b/include/mbgl/storage/resource.hpp
index d00f336669..b21265ef54 100644
--- a/include/mbgl/storage/resource.hpp
+++ b/include/mbgl/storage/resource.hpp
@@ -64,7 +64,7 @@ public:
void setPriority(Priority p) { priority = p; }
void setUsage(Usage u) { usage = u; }
- bool hasLoadingMethod(LoadingMethod method);
+ bool hasLoadingMethod(LoadingMethod method) const;
static Resource style(const std::string& url);
static Resource source(const std::string& url);
@@ -97,7 +97,7 @@ public:
std::shared_ptr<const std::string> priorData;
};
-inline bool Resource::hasLoadingMethod(Resource::LoadingMethod method) {
+inline bool Resource::hasLoadingMethod(Resource::LoadingMethod method) const {
return (loadingMethod & method);
}
diff --git a/include/mbgl/storage/resource_options.hpp b/include/mbgl/storage/resource_options.hpp
index 00dc6e10df..6d603b8cca 100644
--- a/include/mbgl/storage/resource_options.hpp
+++ b/include/mbgl/storage/resource_options.hpp
@@ -97,21 +97,6 @@ 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 cacheOnly Whether or not cache-only requests are supported.
- * @return reference to ResourceOptions for chaining options together.
- */
- ResourceOptions& withCacheOnlyRequestsSupport(bool cacheOnly);
-
- /**
* @brief Sets the platform context. A platform context is usually an object
* that assists the creation of a file source.
*
diff --git a/include/mbgl/storage/resource_transform.hpp b/include/mbgl/storage/resource_transform.hpp
index b8e3dbac76..29d19bb4ec 100644
--- a/include/mbgl/storage/resource_transform.hpp
+++ b/include/mbgl/storage/resource_transform.hpp
@@ -1,6 +1,5 @@
#pragma once
-#include <mbgl/actor/actor_ref.hpp>
#include <mbgl/storage/resource.hpp>
#include <functional>
@@ -8,16 +7,14 @@
namespace mbgl {
-class Mailbox;
-
class ResourceTransform {
public:
- using TransformCallback = std::function<std::string(Resource::Kind kind, const std::string& url)>;
- using FinishedCallback = std::function<void(const std::string&&)>;
-
- ResourceTransform(ActorRef<ResourceTransform>, TransformCallback&&);
+ using FinishedCallback = std::function<void(const std::string&)>;
+ using TransformCallback = std::function<void(Resource::Kind kind, const std::string& url, FinishedCallback)>;
- void transform(Resource::Kind, const std::string& url, FinishedCallback&&);
+ ResourceTransform(TransformCallback = {});
+ void transform(Resource::Kind, const std::string& url, FinishedCallback);
+ explicit operator bool() const { return bool(transformCallback); }
private:
TransformCallback transformCallback;
diff --git a/include/mbgl/style/style.hpp b/include/mbgl/style/style.hpp
index 4a6a542b88..83d6ad5bb4 100644
--- a/include/mbgl/style/style.hpp
+++ b/include/mbgl/style/style.hpp
@@ -21,7 +21,7 @@ class Layer;
class Style {
public:
- Style(FileSource&, float pixelRatio);
+ Style(std::shared_ptr<FileSource>, float pixelRatio);
~Style();
void loadJSON(const std::string&);
diff --git a/include/mbgl/util/constants.hpp b/include/mbgl/util/constants.hpp
index ffdc4b2b30..56f42ac894 100644
--- a/include/mbgl/util/constants.hpp
+++ b/include/mbgl/util/constants.hpp
@@ -60,6 +60,9 @@ constexpr UnitBezier DEFAULT_TRANSITION_EASE = { 0, 0, 0.25, 1 };
constexpr int DEFAULT_RATE_LIMIT_TIMEOUT = 5;
constexpr const char* API_BASE_URL = "https://api.mapbox.com";
+constexpr const char* ASSET_PROTOCOL = "asset://";
+constexpr const char* FILE_PROTOCOL = "file://";
+constexpr uint32_t DEFAULT_MAXIMUM_CONCURRENT_REQUESTS = 20;
constexpr uint8_t TERRAIN_RGB_MAXZOOM = 15;