diff options
author | Jesse Bounds <jesse@rebounds.net> | 2016-03-15 21:42:09 -0700 |
---|---|---|
committer | Jesse Bounds <jesse@rebounds.net> | 2016-03-17 15:52:18 -0700 |
commit | bcb3bb0931cbe0a85cb0f4ee9a311eceec7689c7 (patch) | |
tree | f77db05a29b025a813ebabd6403d508c5c1810f3 /platform | |
parent | 5130ca8843a342a1b708bb63263fd44c6c908120 (diff) | |
download | qtlocation-mapboxgl-bcb3bb0931cbe0a85cb0f4ee9a311eceec7689c7.tar.gz |
[core] Stop download when tile limit is reached
The tile limit guard (when used) stops a download from continuing
when the tile limit is reached. This wraps the guard in a method
and employs it in both places currently necessary to ensure the
guard has a chance to function. Tests have been updated to
ensure the fix works for a less trivial tile limit scenario.
Diffstat (limited to 'platform')
-rw-r--r-- | platform/default/mbgl/storage/offline_download.cpp | 24 | ||||
-rw-r--r-- | platform/default/mbgl/storage/offline_download.hpp | 3 |
2 files changed, 20 insertions, 7 deletions
diff --git a/platform/default/mbgl/storage/offline_download.cpp b/platform/default/mbgl/storage/offline_download.cpp index 36b6f5d502..cda00bf8df 100644 --- a/platform/default/mbgl/storage/offline_download.cpp +++ b/platform/default/mbgl/storage/offline_download.cpp @@ -229,12 +229,8 @@ void OfflineDownload::ensureResource(const Resource& resource, std::function<voi return; } - - if (resource.kind == Resource::Kind::Tile - && util::mapbox::isMapboxURL(resource.url) - && offlineDatabase.offlineMapboxTileCountLimitExceeded()) { - observer->mapboxTileCountLimitExceeded(offlineDatabase.getOfflineMapboxTileCountLimit()); - setState(OfflineRegionDownloadState::Inactive); + + if (checkTileCountLimit(resource)) { return; } @@ -256,6 +252,10 @@ void OfflineDownload::ensureResource(const Resource& resource, std::function<voi observer->statusChanged(status); + if (checkTileCountLimit(resource)) { + return; + } + if (status.complete()) { setState(OfflineRegionDownloadState::Inactive); } @@ -263,4 +263,16 @@ void OfflineDownload::ensureResource(const Resource& resource, std::function<voi }); } +bool OfflineDownload::checkTileCountLimit(const Resource& resource) { + if (resource.kind == Resource::Kind::Tile + && util::mapbox::isMapboxURL(resource.url) + && offlineDatabase.offlineMapboxTileCountLimitExceeded()) { + observer->mapboxTileCountLimitExceeded(offlineDatabase.getOfflineMapboxTileCountLimit()); + setState(OfflineRegionDownloadState::Inactive); + return true; + } + + return false; +} + } // namespace mbgl diff --git a/platform/default/mbgl/storage/offline_download.hpp b/platform/default/mbgl/storage/offline_download.hpp index d5ba801540..be8e90b251 100644 --- a/platform/default/mbgl/storage/offline_download.hpp +++ b/platform/default/mbgl/storage/offline_download.hpp @@ -49,7 +49,8 @@ private: */ void ensureResource(const Resource&, std::function<void (Response)> = {}); void ensureTiles(SourceType, uint16_t, const SourceInfo&); - + bool checkTileCountLimit(const Resource& resource); + int64_t id; OfflineRegionDefinition definition; OfflineDatabase& offlineDatabase; |