summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2019-11-08 15:47:29 +0200
committerMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2019-11-12 17:24:50 +0200
commitf567a79dd8c198e6ea7bd581c4461f8c6dc16bce (patch)
tree45cbc10efb827ba1694f907d08e22ce9a2f16e4c
parent615e095ed6d40771a1e38d5078cf3d821b0d7217 (diff)
downloadqtlocation-mapboxgl-f567a79dd8c198e6ea7bd581c4461f8c6dc16bce.tar.gz
[core] Extend DefaultFileSource API
Add `packDatabase()` method and `bool pack` argument to the `deleteOfflineRegion()` method.
-rw-r--r--include/mbgl/storage/default_file_source.hpp20
-rw-r--r--platform/default/src/mbgl/storage/default_file_source.cpp21
2 files changed, 32 insertions, 9 deletions
diff --git a/include/mbgl/storage/default_file_source.hpp b/include/mbgl/storage/default_file_source.hpp
index 4f4c7136c6..8fc8ed50df 100644
--- a/include/mbgl/storage/default_file_source.hpp
+++ b/include/mbgl/storage/default_file_source.hpp
@@ -121,6 +121,11 @@ public:
* Eviction works by removing the least-recently requested resources not also required
* by other regions, until the database shrinks below a certain size.
*
+ * If the |pack| argument is `false` the database file packing is skipped and the
+ * database file does not shrink after this operation completes. Database file
+ * packing can be done later with `packDatabase()`. It is a useful optimization
+ * e.g. when several regions should be deleted in a row.
+ *
* Note that this method takes ownership of the input, reflecting the fact that once
* region deletion is initiated, it is not legal to perform further actions with the
* region.
@@ -129,7 +134,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)>);
+ void deleteOfflineRegion(OfflineRegion&&, std::function<void(std::exception_ptr)>, bool pack = true);
/*
* Invalidate all the tiles from an offline region forcing Mapbox GL to revalidate
@@ -137,7 +142,7 @@ 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)>);
+ void invalidateOfflineRegion(OfflineRegion&, std::function<void(std::exception_ptr)>);
/*
* Changing or bypassing this limit without permission from Mapbox is prohibited
@@ -179,7 +184,16 @@ 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 resetDatabase(std::function<void (std::exception_ptr)>);
+ void resetDatabase(std::function<void(std::exception_ptr)>);
+
+ /*
+ * Packs the existing database file into a minimal amount of disk space.
+ *
+ * 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);
/*
* Forces revalidation of the ambient cache.
diff --git a/platform/default/src/mbgl/storage/default_file_source.cpp b/platform/default/src/mbgl/storage/default_file_source.cpp
index dc4b2908a8..3982f3dbc7 100644
--- a/platform/default/src/mbgl/storage/default_file_source.cpp
+++ b/platform/default/src/mbgl/storage/default_file_source.cpp
@@ -82,9 +82,9 @@ public:
}
}
- void deleteRegion(OfflineRegion&& region, std::function<void (std::exception_ptr)> callback) {
+ void deleteRegion(OfflineRegion&& region, std::function<void(std::exception_ptr)> callback, bool pack) {
downloads.erase(region.getID());
- callback(offlineDatabase->deleteRegion(std::move(region)));
+ callback(offlineDatabase->deleteRegion(std::move(region), pack));
}
void invalidateRegion(int64_t regionID, std::function<void (std::exception_ptr)> callback) {
@@ -200,6 +200,8 @@ public:
callback(offlineDatabase->setMaximumAmbientCacheSize(size));
}
+ void packDatabase(std::function<void(std::exception_ptr)> callback) { callback(offlineDatabase->pack()); }
+
private:
expected<OfflineDownload*, std::exception_ptr> getDownload(int64_t regionID) {
auto it = downloads.find(regionID);
@@ -308,11 +310,14 @@ void DefaultFileSource::updateOfflineMetadata(const int64_t regionID,
impl->actor().invoke(&Impl::updateMetadata, regionID, metadata, callback);
}
-void DefaultFileSource::deleteOfflineRegion(OfflineRegion&& region, std::function<void (std::exception_ptr)> callback) {
- impl->actor().invoke(&Impl::deleteRegion, std::move(region), callback);
+void DefaultFileSource::deleteOfflineRegion(OfflineRegion&& region,
+ std::function<void(std::exception_ptr)> callback,
+ bool pack) {
+ impl->actor().invoke(&Impl::deleteRegion, std::move(region), callback, pack);
}
-void DefaultFileSource::invalidateOfflineRegion(OfflineRegion& region, std::function<void (std::exception_ptr)> callback) {
+void DefaultFileSource::invalidateOfflineRegion(OfflineRegion& region,
+ std::function<void(std::exception_ptr)> callback) {
impl->actor().invoke(&Impl::invalidateRegion, region.getID(), callback);
}
@@ -348,11 +353,15 @@ void DefaultFileSource::resetDatabase(std::function<void (std::exception_ptr)> c
impl->actor().invoke(&Impl::resetDatabase, std::move(callback));
}
+void DefaultFileSource::packDatabase(std::function<void(std::exception_ptr)> callback) {
+ impl->actor().invoke(&Impl::packDatabase, std::move(callback));
+}
+
void DefaultFileSource::invalidateAmbientCache(std::function<void (std::exception_ptr)> callback) {
impl->actor().invoke(&Impl::invalidateAmbientCache, std::move(callback));
}
-void DefaultFileSource::clearAmbientCache(std::function<void (std::exception_ptr)> callback) {
+void DefaultFileSource::clearAmbientCache(std::function<void(std::exception_ptr)> callback) {
impl->actor().invoke(&Impl::clearAmbientCache, std::move(callback));
}