summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortobrun <tobrun.van.nuland@gmail.com>2019-12-03 21:47:11 +0100
committertobrun <tobrun.van.nuland@gmail.com>2019-12-03 21:47:11 +0100
commitbf57c0e9d0287b0af7573b8e204e393d3a55dff4 (patch)
tree5abdcbc17fe487b7f05f95f9265b8eee96df340d
parente373d8a5924e4f4cf3904ecacbf1d1cf86a5d60f (diff)
downloadqtlocation-mapboxgl-upstream/tvn-only-cancel-when-needed.tar.gz
[android] only cancel request when neededupstream/tvn-only-cancel-when-needed
-rw-r--r--platform/android/src/http_file_source.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/platform/android/src/http_file_source.cpp b/platform/android/src/http_file_source.cpp
index 7066918fef..2ed5e844eb 100644
--- a/platform/android/src/http_file_source.cpp
+++ b/platform/android/src/http_file_source.cpp
@@ -38,6 +38,7 @@ private:
Resource resource;
FileSource::Callback callback;
Response response;
+ bool executed = false;
util::AsyncTask async { [this] {
// Calling `callback` may result in deleting `this`. Copy data to temporaries first.
@@ -97,10 +98,11 @@ HTTPRequest::HTTPRequest(jni::JNIEnv& env, const Resource& resource_, FileSource
HTTPRequest::~HTTPRequest() {
android::UniqueEnv env = android::AttachEnv();
- static auto& javaClass = jni::Class<HTTPRequest>::Singleton(*env);
- static auto cancel = javaClass.GetMethod<void ()>(*env, "cancel");
-
- javaRequest.Call(*env, cancel);
+ if (!executed) {
+ static auto& javaClass = jni::Class<HTTPRequest>::Singleton(*env);
+ static auto cancel = javaClass.GetMethod<void ()>(*env, "cancel");
+ javaRequest.Call(*env, cancel);
+ }
}
void HTTPRequest::onResponse(jni::JNIEnv& env, int code,
@@ -108,7 +110,7 @@ void HTTPRequest::onResponse(jni::JNIEnv& env, int code,
const jni::String& cacheControl, const jni::String& expires,
const jni::String& jRetryAfter, const jni::String& jXRateLimitReset,
const jni::Array<jni::jbyte>& body) {
-
+ executed = true;
using Error = Response::Error;
if (etag) {
@@ -163,6 +165,7 @@ void HTTPRequest::onResponse(jni::JNIEnv& env, int code,
}
void HTTPRequest::onFailure(jni::JNIEnv& env, int type, const jni::String& message) {
+ executed = true;
std::string messageStr = jni::Make<std::string>(env, message);
using Error = Response::Error;