Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrachytski <siarhei.rachytski@gmail.com>2012-05-23 15:26:04 +0400
committerAlex Zolotarev <alex@maps.me>2015-09-23 01:38:46 +0300
commitae42c13a459e6282e959092de72aa353eac473c4 (patch)
tree3792531da6d42ccd5b8c181210baca71674c5f34 /android/jni/com/mapswithme/maps/DownloadResourcesActivity.cpp
parent4a0e176be0ae3bebb7df915cf0ed7cf8b7316f29 (diff)
using shared_ptr to control lifetime of HttpRequest.
Diffstat (limited to 'android/jni/com/mapswithme/maps/DownloadResourcesActivity.cpp')
-rw-r--r--android/jni/com/mapswithme/maps/DownloadResourcesActivity.cpp18
1 files changed, 10 insertions, 8 deletions
diff --git a/android/jni/com/mapswithme/maps/DownloadResourcesActivity.cpp b/android/jni/com/mapswithme/maps/DownloadResourcesActivity.cpp
index daf86a09c8..ade38912dc 100644
--- a/android/jni/com/mapswithme/maps/DownloadResourcesActivity.cpp
+++ b/android/jni/com/mapswithme/maps/DownloadResourcesActivity.cpp
@@ -20,6 +20,7 @@
#include "../../../../../std/vector.hpp"
#include "../../../../../std/string.hpp"
#include "../../../../../std/bind.hpp"
+#include "../../../../../std/shared_ptr.hpp"
#include "../core/jni_helper.hpp"
@@ -50,7 +51,7 @@ static string g_sdcardPath;
static vector<FileToDownload> g_filesToDownload;
static int g_totalDownloadedBytes;
static int g_totalBytesToDownload;
-static downloader::HttpRequest * g_currentRequest;
+static shared_ptr<downloader::HttpRequest> g_currentRequest;
extern "C"
{
@@ -127,7 +128,7 @@ extern "C"
};
g_totalBytesToDownload = totalBytesToDownload;
- g_currentRequest = 0;
+ g_currentRequest.reset();
return res;
}
@@ -148,6 +149,8 @@ extern "C"
break;
};
+ g_currentRequest.reset();
+
if (errorCode == ERR_DOWNLOAD_SUCCESS)
{
FileToDownload & curFile = g_filesToDownload.back();
@@ -219,13 +222,13 @@ extern "C"
LOG(LDEBUG, (curFile.m_urls[i]));
}
- g_currentRequest = downloader::HttpRequest::GetFile(curFile.m_urls,
+ g_currentRequest.reset(downloader::HttpRequest::GetFile(curFile.m_urls,
curFile.m_pathOnSdcard,
curFile.m_fileSize,
onFinish,
onProgress,
64 * 1024,
- false);
+ false));
}
}
@@ -233,8 +236,7 @@ extern "C"
Java_com_mapswithme_maps_DownloadResourcesActivity_cancelCurrentFile(JNIEnv * env, jobject thiz)
{
LOG(LINFO, ("pauseDownload, currentRequest=", g_currentRequest));
- delete g_currentRequest;
- g_currentRequest = 0;
+ g_currentRequest.reset();
}
JNIEXPORT int JNICALL
@@ -251,11 +253,11 @@ extern "C"
downloader::HttpRequest::CallbackT onFinish(bind(&DownloadFileFinished, jni::make_global_ref(observer), _1));
downloader::HttpRequest::CallbackT onProgress(bind(&DownloadFileProgress, jni::make_global_ref(observer), _1));
- g_currentRequest = downloader::HttpRequest::PostJson(GetPlatform().MetaServerUrl(),
+ g_currentRequest.reset(downloader::HttpRequest::PostJson(GetPlatform().MetaServerUrl(),
curFile.m_fileName,
bind(&DownloadURLListFinished, _1,
onFinish,
- onProgress));
+ onProgress)));
return ERR_FILE_IN_PROGRESS;
}