summaryrefslogtreecommitdiff
path: root/src/mbgl/map/tile_data.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/map/tile_data.cpp')
-rw-r--r--src/mbgl/map/tile_data.cpp31
1 files changed, 16 insertions, 15 deletions
diff --git a/src/mbgl/map/tile_data.cpp b/src/mbgl/map/tile_data.cpp
index f89ff15baf..9d48041239 100644
--- a/src/mbgl/map/tile_data.cpp
+++ b/src/mbgl/map/tile_data.cpp
@@ -6,29 +6,33 @@
#include <mbgl/util/string.hpp>
#include <mbgl/storage/file_source.hpp>
#include <mbgl/util/uv_detail.hpp>
+#include <mbgl/platform/log.hpp>
using namespace mbgl;
-TileData::TileData(Tile::ID const& id_, const SourceInfo& source_)
+TileData::TileData(Tile::ID const& id_, const SourceInfo& source_, FileSource& fileSource_)
: id(id_),
name(id),
state(State::initial),
source(source_),
+ fileSource(fileSource_),
debugBucket(debugFontBuffer) {
// Initialize tile debug coordinates
debugFontBuffer.addText(name.c_str(), 50, 200, 5);
}
TileData::~TileData() {
- cancel();
+ if (req) {
+ fileSource.cancel(req);
+ }
}
const std::string TileData::toString() const {
return std::string { "[tile " } + name + "]";
}
-void TileData::request(uv::worker& worker, FileSource& fileSource,
- float pixelRatio, std::function<void ()> callback) {
+void TileData::request(uv::worker &worker, uv_loop_t &loop,
+ float pixelRatio, std::function<void()> callback) {
if (source.tiles.empty())
return;
@@ -51,8 +55,7 @@ void TileData::request(uv::worker& worker, FileSource& fileSource,
// Note: Somehow this feels slower than the change to request_http()
std::weak_ptr<TileData> weak_tile = shared_from_this();
- req = fileSource.request(ResourceType::Tile, url);
- req->onload([weak_tile, url, callback, &worker](const Response &res) {
+ req = fileSource.request({ Resource::Kind::Tile, url }, &loop, [weak_tile, url, callback, &worker](const Response &res) {
util::ptr<TileData> tile = weak_tile.lock();
if (!tile || tile->state == State::obsolete) {
// noop. Tile is obsolete and we're now just waiting for the refcount
@@ -61,9 +64,9 @@ void TileData::request(uv::worker& worker, FileSource& fileSource,
}
// Clear the request object.
- tile->req.reset();
+ tile->req = nullptr;
- if (res.code == 200) {
+ if (res.status == Response::Successful) {
tile->state = State::loaded;
tile->data = res.data;
@@ -71,9 +74,7 @@ void TileData::request(uv::worker& worker, FileSource& fileSource,
// Schedule tile parsing in another thread
tile->reparse(worker, callback);
} else {
-#if defined(DEBUG)
- fprintf(stderr, "[%s] tile loading failed: %ld, %s\n", url.c_str(), res.code, res.message.c_str());
-#endif
+ Log::Error(Event::HttpRequest, "[%s] tile loading failed: %s", url.c_str(), res.message.c_str());
}
});
}
@@ -81,10 +82,10 @@ void TileData::request(uv::worker& worker, FileSource& fileSource,
void TileData::cancel() {
if (state != State::obsolete) {
state = State::obsolete;
- if (req) {
- req->cancel();
- req.reset();
- }
+ }
+ if (req) {
+ fileSource.cancel(req);
+ req = nullptr;
}
}