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:
-rw-r--r--android/jni/com/mapswithme/maps/DownloadResourcesActivity.cpp53
-rw-r--r--platform/chunks_download_strategy.hpp3
-rw-r--r--platform/http_request.cpp33
-rw-r--r--platform/http_request.hpp2
-rw-r--r--platform/platform.cpp16
-rw-r--r--platform/platform.hpp16
-rw-r--r--platform/platform.pro5
-rw-r--r--platform/servers_list.cpp54
-rw-r--r--platform/servers_list.hpp12
-rw-r--r--storage/storage.cpp29
-rw-r--r--storage/storage.hpp5
11 files changed, 124 insertions, 104 deletions
diff --git a/android/jni/com/mapswithme/maps/DownloadResourcesActivity.cpp b/android/jni/com/mapswithme/maps/DownloadResourcesActivity.cpp
index 9d6e9f450b..b9bdb2f722 100644
--- a/android/jni/com/mapswithme/maps/DownloadResourcesActivity.cpp
+++ b/android/jni/com/mapswithme/maps/DownloadResourcesActivity.cpp
@@ -10,6 +10,7 @@
#include "../../../../../platform/platform.hpp"
#include "../../../../../platform/http_request.hpp"
+#include "../../../../../platform/servers_list.hpp"
#include "../../../../../base/logging.hpp"
#include "../../../../../base/string_utils.hpp"
@@ -186,36 +187,28 @@ extern "C"
glbTotal, glbProgress);
}
+ typedef downloader::HttpRequest::CallbackT CallbackT;
+
void DownloadURLListFinished(downloader::HttpRequest & req,
- downloader::HttpRequest::CallbackT const & onFinish,
- downloader::HttpRequest::CallbackT const & onProgress)
+ CallbackT const & onFinish, CallbackT const & onProgress)
{
- if (req.Status() == downloader::HttpRequest::EFailed)
- onFinish(req);
- else
- {
- FileToDownload & curFile = g_filesToDownload.back();
+ FileToDownload & curFile = g_filesToDownload.back();
- LOG(LDEBUG, ("finished URL list download for", curFile.m_fileName));
+ LOG(LINFO, ("Finished URL list download for", curFile.m_fileName));
- downloader::ParseServerList(req.Data(), curFile.m_urls);
+ downloader::GetServerListFromRequest(req, curFile.m_urls);
- for (size_t i = 0; i < curFile.m_urls.size(); ++i)
- {
- curFile.m_urls[i] = curFile.m_urls[i] + OMIM_OS_NAME "/"
- + strings::to_string(g_framework->Storage().GetCurrentVersion()) + "/"
- + UrlEncode(curFile.m_fileName);
- LOG(LDEBUG, (curFile.m_urls[i]));
- }
-
- g_currentRequest.reset(downloader::HttpRequest::GetFile(curFile.m_urls,
- curFile.m_pathOnSdcard,
- curFile.m_fileSize,
- onFinish,
- onProgress,
- 64 * 1024,
- false));
+ storage::Storage const & storage = g_framework->Storage();
+ for (size_t i = 0; i < curFile.m_urls.size(); ++i)
+ {
+ curFile.m_urls[i] = storage.GetFileDownloadUrl(curFile.m_urls[i], curFile.m_fileName);
+ LOG(LINFO, (curFile.m_urls[i]));
}
+
+ g_currentRequest.reset(downloader::HttpRequest::GetFile(
+ curFile.m_urls, curFile.m_pathOnSdcard, curFile.m_fileSize,
+ onFinish, onProgress,
+ 64 * 1024, false));
}
JNIEXPORT void JNICALL
@@ -236,14 +229,12 @@ extern "C"
LOG(LDEBUG, ("downloading", curFile.m_fileName, "sized", curFile.m_fileSize, "bytes"));
- downloader::HttpRequest::CallbackT onFinish(bind(&DownloadFileFinished, jni::make_global_ref(observer), _1));
- downloader::HttpRequest::CallbackT onProgress(bind(&DownloadFileProgress, jni::make_global_ref(observer), _1));
+ CallbackT onFinish(bind(&DownloadFileFinished, jni::make_global_ref(observer), _1));
+ CallbackT onProgress(bind(&DownloadFileProgress, jni::make_global_ref(observer), _1));
- g_currentRequest.reset(downloader::HttpRequest::PostJson(GetPlatform().MetaServerUrl(),
- curFile.m_fileName,
- bind(&DownloadURLListFinished, _1,
- onFinish,
- onProgress)));
+ g_currentRequest.reset(downloader::HttpRequest::PostJson(
+ GetPlatform().MetaServerUrl(), curFile.m_fileName,
+ bind(&DownloadURLListFinished, _1, onFinish, onProgress)));
return ERR_FILE_IN_PROGRESS;
}
diff --git a/platform/chunks_download_strategy.hpp b/platform/chunks_download_strategy.hpp
index 07a7fbefad..d6ab853941 100644
--- a/platform/chunks_download_strategy.hpp
+++ b/platform/chunks_download_strategy.hpp
@@ -3,9 +3,8 @@
#include "../std/string.hpp"
#include "../std/vector.hpp"
#include "../std/utility.hpp"
-#include "../std/set.hpp"
#include "../std/stdint.hpp"
-#include "../std/cstdio.hpp"
+
namespace downloader
{
diff --git a/platform/http_request.cpp b/platform/http_request.cpp
index 2ce8fdb720..dd68ee3bf7 100644
--- a/platform/http_request.cpp
+++ b/platform/http_request.cpp
@@ -8,16 +8,12 @@
#include "../base/thread.hpp"
#endif
-#include "../base/std_serialization.hpp"
-#include "../base/logging.hpp"
-
-#include "../coding/file_writer_stream.hpp"
-#include "../coding/file_reader_stream.hpp"
#include "../coding/internal/file_data.hpp"
+#include "../coding/file_writer.hpp"
-#include "../std/scoped_ptr.hpp"
+#include "../base/logging.hpp"
-#include "../3party/jansson/myjansson.hpp"
+#include "../std/scoped_ptr.hpp"
#ifdef OMIM_OS_IPHONE
@@ -169,6 +165,8 @@ class FileHttpRequest : public HttpRequest, public IHttpThreadCallback
if (m_onProgress)
m_onProgress(*this);
}
+ else
+ LOG(LWARNING, (m_filePath, "HttpRequest error:", httpCode));
ChunksDownloadStrategy::ResultT const result = StartThreads();
@@ -281,25 +279,4 @@ HttpRequest * HttpRequest::GetFile(vector<string> const & urls, string const & f
return new FileHttpRequest(urls, filePath, fileSize, onFinish, onProgress, chunkSize, doCleanProgressFiles);
}
-bool ParseServerList(string const & jsonStr, vector<string> & outUrls)
-{
- outUrls.clear();
- try
- {
- my::Json root(jsonStr.c_str());
- for (size_t i = 0; i < json_array_size(root); ++i)
- {
- char const * url = json_string_value(json_array_get(root, i));
- if (url)
- outUrls.push_back(url);
- }
- }
- catch (std::exception const & e)
- {
- LOG(LERROR, ("Can't parse server list json", e.what(), jsonStr));
- }
- return !outUrls.empty();
-}
-
-
} // namespace downloader
diff --git a/platform/http_request.hpp b/platform/http_request.hpp
index 41ded14c91..8f03e033cc 100644
--- a/platform/http_request.hpp
+++ b/platform/http_request.hpp
@@ -56,6 +56,4 @@ public:
bool doCleanProgressFiles = true);
};
-bool ParseServerList(string const & jsonStr, vector<string> & outUrls);
-
} // namespace downloader
diff --git a/platform/platform.cpp b/platform/platform.cpp
index 8c6ea64a17..732a2be967 100644
--- a/platform/platform.cpp
+++ b/platform/platform.cpp
@@ -3,6 +3,7 @@
#include "../coding/sha2.hpp"
#include "../coding/base64.hpp"
+
string Platform::ReadPathForFile(string const & file) const
{
string fullPath = m_writableDir + file;
@@ -28,3 +29,18 @@ string Platform::HashUniqueID(string const & s)
return base64::encode(xoredHash);
}
+string Platform::MetaServerUrl() const
+{
+ if (IsFeatureSupported("search"))
+ return "http://active.servers.url";
+ else
+ return "http://active.servers.url";
+}
+
+string Platform::DefaultUrlsJSON() const
+{
+ if (IsFeatureSupported("search"))
+ return "[\"http://1st.default.server/\",\"http://2nd.default.server/\",\"http://3rd.default.server/\"]";
+ else
+ return "[\"http://1st.default.server/\",\"http://2nd.default.server/\",\"http://3rd.default.server/\"]";
+}
diff --git a/platform/platform.hpp b/platform/platform.hpp
index 0aff0867a7..cc94a804b3 100644
--- a/platform/platform.hpp
+++ b/platform/platform.hpp
@@ -119,22 +119,10 @@ public:
/// @return url for clients to download maps
/// Different urls are returned for versions with and without search support
- inline string MetaServerUrl() const
- {
- if (IsFeatureSupported("search"))
- return "http://active.servers.url";
- else
- return "http://active.servers.url";
- }
+ string MetaServerUrl() const;
/// @return JSON-encoded list of urls if metaserver is unreachable
- inline string DefaultUrlsJSON() const
- {
- if (IsFeatureSupported("search"))
- return "[\"http://1st.default.server/\",\"http://2nd.default.server/\",\"http://3rd.default.server/\"]";
- else
- return "[\"http://1st.default.server/\",\"http://2nd.default.server/\",\"http://3rd.default.server/\"]";
- }
+ string DefaultUrlsJSON() const;
};
extern "C" Platform & GetPlatform();
diff --git a/platform/platform.pro b/platform/platform.pro
index 65ad281b70..b378a653e8 100644
--- a/platform/platform.pro
+++ b/platform/platform.pro
@@ -60,6 +60,7 @@ HEADERS += \
http_request.hpp \
http_thread_callback.hpp \
chunks_download_strategy.hpp \
+ servers_list.hpp \
SOURCES += \
preferred_languages.cpp \
@@ -67,5 +68,5 @@ SOURCES += \
video_timer.cpp \
http_request.cpp \
chunks_download_strategy.cpp \
- platform.cpp
-
+ platform.cpp \
+ servers_list.cpp \
diff --git a/platform/servers_list.cpp b/platform/servers_list.cpp
new file mode 100644
index 0000000000..44d326c536
--- /dev/null
+++ b/platform/servers_list.cpp
@@ -0,0 +1,54 @@
+#include "servers_list.hpp"
+#include "http_request.hpp"
+#include "settings.hpp"
+#include "platform.hpp"
+
+#include "../base/logging.hpp"
+#include "../base/assert.hpp"
+
+#include "../3party/jansson/myjansson.hpp"
+
+
+#define SETTINGS_SERVERS_KEY "LastBaseUrls"
+
+
+namespace downloader
+{
+
+bool ParseServerList(string const & jsonStr, vector<string> & outUrls)
+{
+ outUrls.clear();
+ try
+ {
+ my::Json root(jsonStr.c_str());
+ for (size_t i = 0; i < json_array_size(root); ++i)
+ {
+ char const * url = json_string_value(json_array_get(root, i));
+ if (url)
+ outUrls.push_back(url);
+ }
+ }
+ catch (std::exception const & e)
+ {
+ LOG(LERROR, ("Can't parse server list json", e.what(), jsonStr));
+ }
+ return !outUrls.empty();
+}
+
+void GetServerListFromRequest(HttpRequest const & request, vector<string> & urls)
+{
+ if (request.Status() == HttpRequest::ECompleted &&
+ ParseServerList(request.Data(), urls))
+ {
+ Settings::Set(SETTINGS_SERVERS_KEY, request.Data());
+ }
+ else
+ {
+ string serverList;
+ if (!Settings::Get(SETTINGS_SERVERS_KEY, serverList))
+ serverList = GetPlatform().DefaultUrlsJSON();
+ VERIFY ( ParseServerList(serverList, urls), () );
+ }
+}
+
+}
diff --git a/platform/servers_list.hpp b/platform/servers_list.hpp
new file mode 100644
index 0000000000..a71e364977
--- /dev/null
+++ b/platform/servers_list.hpp
@@ -0,0 +1,12 @@
+#pragma once
+
+#include "../std/vector.hpp"
+#include "../std/string.hpp"
+
+
+namespace downloader
+{
+ class HttpRequest;
+
+ void GetServerListFromRequest(HttpRequest const & request, vector<string> & urls);
+}
diff --git a/storage/storage.cpp b/storage/storage.cpp
index 78564ebc6b..e4de24d0b2 100644
--- a/storage/storage.cpp
+++ b/storage/storage.cpp
@@ -2,20 +2,20 @@
#include "../defines.hpp"
-#include "../base/logging.hpp"
-#include "../base/string_utils.hpp"
-
#include "../indexer/data_factory.hpp"
#include "../indexer/search_index_builder.hpp"
#include "../platform/platform.hpp"
-#include "../platform/settings.hpp"
+#include "../platform/servers_list.hpp"
#include "../coding/file_writer.hpp"
#include "../coding/file_reader.hpp"
#include "../coding/file_container.hpp"
#include "../coding/url_encode.hpp"
+#include "../base/logging.hpp"
+#include "../base/string_utils.hpp"
+
#include "../version/version.hpp"
#include "../std/algorithm.hpp"
@@ -23,9 +23,6 @@
#include "../std/bind.hpp"
#include "../std/sstream.hpp"
-#include "../3party/jansson/myjansson.hpp"
-
-#define SETTINGS_SERVERS_KEY "LastBaseUrls"
using namespace downloader;
@@ -468,21 +465,11 @@ namespace storage
CountryFile const & file = CountryByIndex(m_queue.front()).Files().front();
vector<string> urls;
- if (request.Status() == HttpRequest::ECompleted
- && ParseServerList(request.Data(), urls))
- Settings::Set(SETTINGS_SERVERS_KEY, request.Data());
- else
- {
- string serverList;
- if (!Settings::Get(SETTINGS_SERVERS_KEY, serverList))
- serverList = GetPlatform().DefaultUrlsJSON();
- VERIFY(ParseServerList(serverList, urls), ());
- }
+ GetServerListFromRequest(request, urls);
// append actual version and file name
for (size_t i = 0; i < urls.size(); ++i)
- urls[i] = urls[i] + OMIM_OS_NAME "/"
- + strings::to_string(m_currentVersion) + "/" + UrlEncode(file.GetFileWithExt());
+ urls[i] = GetFileDownloadUrl(urls[i], file.GetFileWithExt());
m_request.reset(HttpRequest::GetFile(urls,
GetPlatform().WritablePathForFile(file.GetFileWithExt()),
@@ -491,9 +478,9 @@ namespace storage
bind(&Storage::OnMapDownloadProgress, this, _1)));
}
- int64_t Storage::GetCurrentVersion() const
+ string Storage::GetFileDownloadUrl(string const & baseUrl, string const & fName) const
{
- return m_currentVersion;
+ return baseUrl + OMIM_OS_NAME "/" + strings::to_string(m_currentVersion) + "/" + UrlEncode(fName);
}
TIndex const Storage::FindIndexByName(string const & name) const
diff --git a/storage/storage.hpp b/storage/storage.hpp
index 83f405018c..9f0aaecbc3 100644
--- a/storage/storage.hpp
+++ b/storage/storage.hpp
@@ -131,7 +131,6 @@ namespace storage
void ReportProgress(TIndex const & index, pair<int64_t, int64_t> const & p);
public:
-
Storage();
void Init(TAddMapFunction addFunc,
@@ -170,8 +169,6 @@ namespace storage
void NotifyStatusChanged(TIndex const & index) const;
- int64_t GetCurrentVersion() const;
+ string GetFileDownloadUrl(string const & baseUrl, string const & fName) const;
};
-
-
}