[core] invoke optional resource path change completion listener

This commit is contained in:
Łukasz Paczos
2019-05-14 14:54:24 +02:00
committed by Łukasz Paczos
parent 749044f1b0
commit 46ef2d86d2
3 changed files with 22 additions and 4 deletions

View File

@@ -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;

View File

@@ -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) {

View File

@@ -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;