summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <tmpsantos@gmail.com>2019-05-24 17:47:27 +0300
committerThiago Marcos P. Santos <tmpsantos@gmail.com>2019-05-28 16:30:49 +0300
commitcc26ef17d52367a768a134140c6c95cb2b880733 (patch)
treee61b3b464273b7950ee0d74b8a7e39bcc845ed93
parent2f97a2660ada44cd18f2e02b4de4eb42cfcb07b1 (diff)
downloadqtlocation-mapboxgl-cc26ef17d52367a768a134140c6c95cb2b880733.tar.gz
[core] Introduce usage tag for resources
Make the distinction if a resource is being requested for offline usage or if it will be used immediately. Fixes #14746
-rw-r--r--include/mbgl/storage/resource.hpp7
-rw-r--r--platform/default/include/mbgl/storage/offline_download.hpp2
-rw-r--r--platform/default/src/mbgl/storage/offline_download.cpp30
-rw-r--r--test/storage/offline_download.test.cpp9
4 files changed, 39 insertions, 9 deletions
diff --git a/include/mbgl/storage/resource.hpp b/include/mbgl/storage/resource.hpp
index 97b9fbcaf0..d828877e10 100644
--- a/include/mbgl/storage/resource.hpp
+++ b/include/mbgl/storage/resource.hpp
@@ -29,6 +29,11 @@ public:
Low
};
+ enum class Usage : bool {
+ Online,
+ Offline
+ };
+
struct TileData {
std::string urlTemplate;
uint8_t pixelRatio;
@@ -60,6 +65,7 @@ public:
}
void setPriority(Priority p) { priority = p; }
+ void setUsage(Usage u) { usage = u; }
bool hasLoadingMethod(LoadingMethod method);
@@ -83,6 +89,7 @@ public:
Kind kind;
LoadingMethod loadingMethod;
+ Usage usage{ Usage::Online };
Priority priority;
std::string url;
diff --git a/platform/default/include/mbgl/storage/offline_download.hpp b/platform/default/include/mbgl/storage/offline_download.hpp
index 1e77ff1d35..84b319fb5a 100644
--- a/platform/default/include/mbgl/storage/offline_download.hpp
+++ b/platform/default/include/mbgl/storage/offline_download.hpp
@@ -62,7 +62,7 @@ private:
std::deque<Resource> resourcesRemaining;
std::list<std::tuple<Resource, Response>> buffer;
- void queueResource(Resource);
+ void queueResource(Resource&&);
void queueTiles(style::SourceType, uint16_t tileSize, const Tileset&);
};
diff --git a/platform/default/src/mbgl/storage/offline_download.cpp b/platform/default/src/mbgl/storage/offline_download.cpp
index d60ae786dd..bdcc99cc15 100644
--- a/platform/default/src/mbgl/storage/offline_download.cpp
+++ b/platform/default/src/mbgl/storage/offline_download.cpp
@@ -223,8 +223,12 @@ void OfflineDownload::activateDownload() {
status = OfflineRegionStatus();
status.downloadState = OfflineRegionDownloadState::Active;
status.requiredResourceCount++;
- ensureResource(Resource::style(definition.match([](auto& reg){ return reg.styleURL; }), Resource::Priority::Low),
- [&](Response styleResponse) {
+
+ auto styleResource = Resource::style(definition.match([](auto& reg){ return reg.styleURL; }));
+ styleResource.setPriority(Resource::Priority::Low);
+ styleResource.setUsage(Resource::Usage::Offline);
+
+ ensureResource(styleResource, [&](Response styleResponse) {
status.requiredResourceCountIsPrecise = true;
style::Parser parser;
@@ -242,7 +246,11 @@ void OfflineDownload::activateDownload() {
status.requiredResourceCount++;
requiredSourceURLs.insert(url);
- ensureResource(Resource::source(url, Resource::Priority::Low), [=](Response sourceResponse) {
+ auto sourceResource = Resource::source(url);
+ sourceResource.setPriority(Resource::Priority::Low);
+ sourceResource.setUsage(Resource::Usage::Offline);
+
+ ensureResource(sourceResource, [=](Response sourceResponse) {
style::conversion::Error error;
optional<Tileset> tileset = style::conversion::convertJSON<Tileset>(*sourceResponse.data, error);
if (tileset) {
@@ -361,8 +369,9 @@ void OfflineDownload::deactivateDownload() {
requests.clear();
}
-void OfflineDownload::queueResource(Resource resource) {
+void OfflineDownload::queueResource(Resource&& resource) {
resource.setPriority(Resource::Priority::Low);
+ resource.setUsage(Resource::Usage::Offline);
status.requiredResourceCount++;
resourcesRemaining.push_front(std::move(resource));
}
@@ -370,15 +379,22 @@ void OfflineDownload::queueResource(Resource resource) {
void OfflineDownload::queueTiles(SourceType type, uint16_t tileSize, const Tileset& tileset) {
tileCover(definition, type, tileSize, tileset.zoomRange, [&](const auto& tile) {
status.requiredResourceCount++;
- resourcesRemaining.push_back(Resource::tile(
- tileset.tiles[0], definition.match([](auto& def) { return def.pixelRatio; }), tile.x,
- tile.y, tile.z, tileset.scheme, Resource::Priority::Low));
+
+ auto tileResource = Resource::tile(
+ tileset.tiles[0], definition.match([](auto& def) { return def.pixelRatio; }),
+ tile.x, tile.y, tile.z, tileset.scheme);
+
+ tileResource.setPriority(Resource::Priority::Low);
+ tileResource.setUsage(Resource::Usage::Offline);
+
+ resourcesRemaining.push_back(std::move(tileResource));
});
}
void OfflineDownload::ensureResource(const Resource& resource,
std::function<void(Response)> callback) {
assert(resource.priority == Resource::Priority::Low);
+ assert(resource.usage == Resource::Usage::Offline);
auto workRequestsIt = requests.insert(requests.begin(), nullptr);
*workRequestsIt = util::RunLoop::Get()->invokeCancellable([=]() {
diff --git a/test/storage/offline_download.test.cpp b/test/storage/offline_download.test.cpp
index 68f8ea2484..9cdafaaf1e 100644
--- a/test/storage/offline_download.test.cpp
+++ b/test/storage/offline_download.test.cpp
@@ -740,7 +740,7 @@ TEST(OfflineDownload, Deactivate) {
}
-TEST(OfflineDownload, AllOfflineRequestsHaveLowPriority) {
+TEST(OfflineDownload, AllOfflineRequestsHaveLowPriorityAndOfflineUsage) {
OfflineTest test;
auto region = test.createRegion();
ASSERT_TRUE(region);
@@ -751,36 +751,43 @@ TEST(OfflineDownload, AllOfflineRequestsHaveLowPriority) {
test.fileSource.styleResponse = [&] (const Resource& resource) {
EXPECT_TRUE(resource.priority == Resource::Priority::Low);
+ EXPECT_TRUE(resource.usage == Resource::Usage::Offline);
return test.response("style.json");
};
test.fileSource.spriteImageResponse = [&] (const Resource& resource) {
EXPECT_TRUE(resource.priority == Resource::Priority::Low);
+ EXPECT_TRUE(resource.usage == Resource::Usage::Offline);
return test.response("sprite.png");
};
test.fileSource.imageResponse = [&] (const Resource& resource) {
EXPECT_TRUE(resource.priority == Resource::Priority::Low);
+ EXPECT_TRUE(resource.usage == Resource::Usage::Offline);
return test.response("radar.gif");
};
test.fileSource.spriteJSONResponse = [&] (const Resource& resource) {
EXPECT_TRUE(resource.priority == Resource::Priority::Low);
+ EXPECT_TRUE(resource.usage == Resource::Usage::Offline);
return test.response("sprite.json");
};
test.fileSource.glyphsResponse = [&] (const Resource& resource) {
EXPECT_TRUE(resource.priority == Resource::Priority::Low);
+ EXPECT_TRUE(resource.usage == Resource::Usage::Offline);
return test.response("glyph.pbf");
};
test.fileSource.sourceResponse = [&] (const Resource& resource) {
EXPECT_TRUE(resource.priority == Resource::Priority::Low);
+ EXPECT_TRUE(resource.usage == Resource::Usage::Offline);
return test.response("streets.json");
};
test.fileSource.tileResponse = [&] (const Resource& resource) {
EXPECT_TRUE(resource.priority == Resource::Priority::Low);
+ EXPECT_TRUE(resource.usage == Resource::Usage::Offline);
return test.response("0-0-0.vector.pbf");
};