summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorŁukasz Paczos <lukas.paczos@gmail.com>2019-05-14 14:54:24 +0200
committerŁukasz Paczos <lukasz.paczos@mapbox.com>2019-05-24 15:03:55 +0200
commit46ef2d86d2065aaaa63e8c83c750e46c74932777 (patch)
tree22e1e0321281830c11d08b22b901250dbc137860
parent749044f1b084b7172bd0ac93b0a450599f246f56 (diff)
downloadqtlocation-mapboxgl-46ef2d86d2065aaaa63e8c83c750e46c74932777.tar.gz
[core] invoke optional resource path change completion listener
-rw-r--r--include/mbgl/storage/default_file_source.hpp5
-rw-r--r--platform/default/src/mbgl/storage/default_file_source.cpp9
-rw-r--r--test/storage/default_file_source.test.cpp12
3 files changed, 22 insertions, 4 deletions
diff --git a/include/mbgl/storage/default_file_source.hpp b/include/mbgl/storage/default_file_source.hpp
index 10a836094c..2a1e32baed 100644
--- a/include/mbgl/storage/default_file_source.hpp
+++ b/include/mbgl/storage/default_file_source.hpp
@@ -18,6 +18,9 @@ template <typename T> class Thread;
class ResourceTransform;
+// 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 ()>;
+
class DefaultFileSource : public FileSource {
public:
/*
@@ -47,7 +50,7 @@ public:
void setResourceTransform(optional<ActorRef<ResourceTransform>>&&);
- void setResourceCachePath(const std::string&);
+ void setResourceCachePath(const std::string&, optional<ActorRef<PathChangeCallback>>&&);
std::unique_ptr<AsyncRequest> request(const Resource&, Callback) override;
diff --git a/platform/default/src/mbgl/storage/default_file_source.cpp b/platform/default/src/mbgl/storage/default_file_source.cpp
index 2768f9d113..eabb7b45c3 100644
--- a/platform/default/src/mbgl/storage/default_file_source.cpp
+++ b/platform/default/src/mbgl/storage/default_file_source.cpp
@@ -46,8 +46,11 @@ public:
onlineFileSource.setResourceTransform(std::move(transform));
}
- void setResourceCachePath(const std::string& path) {
+ void setResourceCachePath(const std::string& path, optional<ActorRef<PathChangeCallback>>&& callback) {
offlineDatabase->changePath(path);
+ if (callback) {
+ callback->invoke(&PathChangeCallback::operator());
+ }
}
void listRegions(std::function<void (expected<OfflineRegions, std::exception_ptr>)> callback) {
@@ -252,8 +255,8 @@ void DefaultFileSource::setResourceTransform(optional<ActorRef<ResourceTransform
impl->actor().invoke(&Impl::setResourceTransform, std::move(transform));
}
-void DefaultFileSource::setResourceCachePath(const std::string& path) {
- impl->actor().invoke(&Impl::setResourceCachePath, path);
+void DefaultFileSource::setResourceCachePath(const std::string& path, optional<ActorRef<PathChangeCallback>>&& callback) {
+ impl->actor().invoke(&Impl::setResourceCachePath, path, std::move(callback));
}
std::unique_ptr<AsyncRequest> DefaultFileSource::request(const Resource& resource, Callback callback) {
diff --git a/test/storage/default_file_source.test.cpp b/test/storage/default_file_source.test.cpp
index e1c5df6895..64b23e315c 100644
--- a/test/storage/default_file_source.test.cpp
+++ b/test/storage/default_file_source.test.cpp
@@ -572,6 +572,18 @@ TEST(DefaultFileSource, TEST_REQUIRES_SERVER(SetResourceTransform)) {
loop.run();
}
+TEST(DefaultFileSource, SetResourceCachePath) {
+ util::RunLoop loop;
+ DefaultFileSource fs(":memory:", ".");
+
+ Actor<PathChangeCallback> callback(loop, [&]() -> void {
+ loop.stop();
+ });
+
+ fs.setResourceCachePath("./new_offline.db", callback.self());
+ loop.run();
+}
+
// Test that a stale cache file that has must-revalidate set will trigger a response.
TEST(DefaultFileSource, TEST_REQUIRES_SERVER(RespondToStaleMustRevalidate)) {
util::RunLoop loop;