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-08 15:49:23 +0200
commit671a31238fcff6d744cfbaca44a81a996268d840 (patch)
tree77cf8737d6c76fc36d0870b95a2ee9851bb51fce
parente0db35cf3b6eb8f188726a569021b459b9825ab1 (diff)
downloadqtlocation-mapboxgl-671a31238fcff6d744cfbaca44a81a996268d840.tar.gz
[core] Extend DefaultFileSource API
Add `packDatabase()` and `deleteOfflineRegionSkipPackDatabase()` methods.
-rw-r--r--include/mbgl/storage/default_file_source.hpp19
-rw-r--r--platform/default/src/mbgl/storage/default_file_source.cpp17
2 files changed, 33 insertions, 3 deletions
diff --git a/include/mbgl/storage/default_file_source.hpp b/include/mbgl/storage/default_file_source.hpp
index 4f4c7136c6..c06609b71c 100644
--- a/include/mbgl/storage/default_file_source.hpp
+++ b/include/mbgl/storage/default_file_source.hpp
@@ -132,6 +132,16 @@ public:
void deleteOfflineRegion(OfflineRegion&&, std::function<void (std::exception_ptr)>);
/*
+ * Same as the method above but skipping database file packing for performance reasons.
+ *
+ * After this operation is complete, the database file does not shrink.
+ * Database file packing can be done later with `packDatabase()`.
+ *
+ * This method is useful optimization e.g. when several regions should be deleted in a row.
+ */
+ void deleteOfflineRegionSkipPackDatabase(OfflineRegion&&, std::function<void(std::exception_ptr)>);
+
+ /*
* Invalidate all the tiles from an offline region forcing Mapbox GL to revalidate
* the tiles with the server before using. This is more efficient than deleting the
* offline region and downloading it again because if the data on the cache matches
@@ -182,6 +192,15 @@ public:
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.
*
* Forces Mapbox GL Native to revalidate resources stored in the ambient
diff --git a/platform/default/src/mbgl/storage/default_file_source.cpp b/platform/default/src/mbgl/storage/default_file_source.cpp
index dc4b2908a8..584b07c807 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, bool skipPack, std::function<void(std::exception_ptr)> callback) {
downloads.erase(region.getID());
- callback(offlineDatabase->deleteRegion(std::move(region)));
+ callback(offlineDatabase->deleteRegion(std::move(region), skipPack));
}
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);
@@ -309,7 +311,12 @@ void DefaultFileSource::updateOfflineMetadata(const int64_t regionID,
}
void DefaultFileSource::deleteOfflineRegion(OfflineRegion&& region, std::function<void (std::exception_ptr)> callback) {
- impl->actor().invoke(&Impl::deleteRegion, std::move(region), callback);
+ impl->actor().invoke(&Impl::deleteRegion, std::move(region), false /*skipPack*/, callback);
+}
+
+void DefaultFileSource::deleteOfflineRegionSkipPackDatabase(OfflineRegion&& region,
+ std::function<void(std::exception_ptr)> callback) {
+ impl->actor().invoke(&Impl::deleteRegion, std::move(region), true /*skipPack*/, callback);
}
void DefaultFileSource::invalidateOfflineRegion(OfflineRegion& region, std::function<void (std::exception_ptr)> callback) {
@@ -348,6 +355,10 @@ 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));
}