diff options
Diffstat (limited to 'src/mbgl/storage/http_request.hpp')
-rw-r--r-- | src/mbgl/storage/http_request.hpp | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/mbgl/storage/http_request.hpp b/src/mbgl/storage/http_request.hpp new file mode 100644 index 0000000000..7cc72101d5 --- /dev/null +++ b/src/mbgl/storage/http_request.hpp @@ -0,0 +1,58 @@ +#ifndef MBGL_STORAGE_HTTP_REQUEST +#define MBGL_STORAGE_HTTP_REQUEST + +#include <mbgl/storage/resource_type.hpp> +#include <mbgl/storage/base_request.hpp> +#include <mbgl/storage/http_request_baton.hpp> + +#include <string> +#include <memory> +#include <cassert> +#include <thread> + +typedef struct uv_loop_s uv_loop_t; +typedef struct uv_timer_s uv_timer_t; + +namespace mbgl { + +struct CacheRequestBaton; +struct HTTPRequestBaton; +struct CacheEntry; +class SQLiteStore; + +class HTTPRequest : public BaseRequest { +public: + HTTPRequest(ResourceType type, const std::string &path, uv_loop_t *loop, util::ptr<SQLiteStore> store); + ~HTTPRequest(); + + void cancel(); + void retryImmediately(); + +private: + void startCacheRequest(); + void handleCacheResponse(std::unique_ptr<Response> &&response); + void startHTTPRequest(std::unique_ptr<Response> &&res); + void handleHTTPResponse(HTTPResponseType responseType, std::unique_ptr<Response> &&response); + + void retryHTTPRequest(std::unique_ptr<Response> &&res, uint64_t timeout); + + void removeCacheBaton(); + void removeHTTPBaton(); + void removeBackoffTimer(); + +private: + const std::thread::id threadId; + uv_loop_t *const loop; + CacheRequestBaton *cacheBaton = nullptr; + util::ptr<HTTPRequestBaton> httpBaton; + uv_timer_t *backoffTimer = nullptr; + util::ptr<SQLiteStore> store; + const ResourceType type; + uint8_t attempts = 0; + + friend struct HTTPRequestBaton; +}; + +} + +#endif |