summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/mbgl/storage/default_file_source.hpp1
-rw-r--r--include/mbgl/storage/network_status.hpp4
-rw-r--r--platform/default/default_file_source.cpp12
-rw-r--r--test/api/offline.cpp5
4 files changed, 8 insertions, 14 deletions
diff --git a/include/mbgl/storage/default_file_source.hpp b/include/mbgl/storage/default_file_source.hpp
index 93d6297651..dd67cff9b8 100644
--- a/include/mbgl/storage/default_file_source.hpp
+++ b/include/mbgl/storage/default_file_source.hpp
@@ -102,7 +102,6 @@ public:
// For testing only.
void put(const Resource&, const Response&);
- void goOffline();
class Impl;
diff --git a/include/mbgl/storage/network_status.hpp b/include/mbgl/storage/network_status.hpp
index 4202793661..d5ea13e07e 100644
--- a/include/mbgl/storage/network_status.hpp
+++ b/include/mbgl/storage/network_status.hpp
@@ -18,8 +18,8 @@ public:
Offline,
};
- Status Get();
- void Set(Status);
+ static Status Get();
+ static void Set(Status);
static void Reachable();
diff --git a/platform/default/default_file_source.cpp b/platform/default/default_file_source.cpp
index 24297374c9..80666ca122 100644
--- a/platform/default/default_file_source.cpp
+++ b/platform/default/default_file_source.cpp
@@ -1,5 +1,6 @@
#include <mbgl/storage/default_file_source.hpp>
#include <mbgl/storage/asset_file_source.hpp>
+#include <mbgl/storage/network_status.hpp>
#include <mbgl/storage/online_file_source.hpp>
#include <mbgl/storage/offline_database.hpp>
#include <mbgl/storage/offline_download.hpp>
@@ -39,7 +40,7 @@ public:
callback(*offlineResponse);
}
- if (!impl->offline) {
+ if (NetworkStatus::Get() == NetworkStatus::Status::Online) {
onlineRequest = impl->onlineFileSource.request(revalidation, [=] (Response onlineResponse) {
impl->offlineDatabase.put(revalidation, onlineResponse);
callback(onlineResponse);
@@ -121,10 +122,6 @@ public:
offlineDatabase.put(resource, response);
}
- void goOffline() {
- offline = true;
- }
-
private:
OfflineDownload& getDownload(int64_t regionID) {
auto it = downloads.find(regionID);
@@ -139,7 +136,6 @@ private:
OnlineFileSource onlineFileSource;
std::unordered_map<FileRequest*, std::unique_ptr<Task>> tasks;
std::unordered_map<int64_t, std::unique_ptr<OfflineDownload>> downloads;
- bool offline = false;
};
DefaultFileSource::DefaultFileSource(const std::string& cachePath,
@@ -219,8 +215,4 @@ void DefaultFileSource::put(const Resource& resource, const Response& response)
thread->invokeSync(&Impl::put, resource, response);
}
-void DefaultFileSource::goOffline() {
- thread->invokeSync(&Impl::goOffline);
-}
-
} // namespace mbgl
diff --git a/test/api/offline.cpp b/test/api/offline.cpp
index f168ff71f5..9940432e3f 100644
--- a/test/api/offline.cpp
+++ b/test/api/offline.cpp
@@ -2,6 +2,7 @@
#include <mbgl/platform/default/headless_display.hpp>
#include <mbgl/platform/default/headless_view.hpp>
+#include <mbgl/storage/network_status.hpp>
#include <mbgl/storage/offline_database.hpp>
#include <mbgl/storage/default_file_source.hpp>
@@ -38,7 +39,7 @@ TEST(API, Offline) {
fileSource.put(Resource::spriteImage(prefix + "/offline/sprite", 1.0), expiredItem("offline/sprite.png"));
fileSource.put(Resource::tile(prefix + "/offline/{z}-{x}-{y}.vector.pbf", 1.0, 0, 0, 0), expiredItem("offline/0-0-0.vector.pbf"));
fileSource.put(Resource::glyphs(prefix + "/offline/{fontstack}/{range}.pbf", "Helvetica", {0, 255}), expiredItem("offline/glyph.pbf"));
- fileSource.goOffline();
+ NetworkStatus::Set(NetworkStatus::Status::Offline);
Map map(view, fileSource, MapMode::Still);
map.setStyleURL(prefix + "/offline/style.json");
@@ -47,4 +48,6 @@ TEST(API, Offline) {
test::render(map),
0.0015,
0.1);
+
+ NetworkStatus::Set(NetworkStatus::Status::Online);
}