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:
authorSergey Yershov <yershov@corp.mail.ru>2016-04-21 15:58:53 +0300
committerSergey Yershov <yershov@corp.mail.ru>2016-04-21 19:06:00 +0300
commitc8d8dd7a88bae225bfa0e36ab6d80f7383887308 (patch)
treed4ac9fd0c732a4fe42b06ffa14279fc25b0b581a /storage
parentb786254cafb7561689e80e7f701ac271bf3c3cf8 (diff)
[downloader] Add auto retry download if internet connection blinked
Diffstat (limited to 'storage')
-rw-r--r--storage/storage.cpp33
-rw-r--r--storage/storage.hpp7
2 files changed, 36 insertions, 4 deletions
diff --git a/storage/storage.cpp b/storage/storage.cpp
index 511a59e5a8..b4a8857072 100644
--- a/storage/storage.cpp
+++ b/storage/storage.cpp
@@ -22,6 +22,7 @@
#include "std/algorithm.hpp"
#include "std/bind.hpp"
+#include "std/chrono.hpp"
#include "std/sstream.hpp"
#include "std/target_os.hpp"
@@ -108,8 +109,9 @@ MapFilesDownloader::TProgress Storage::GetOverallProgress(TCountriesVec const &
}
Storage::Storage(string const & pathToCountriesFile /* = COUNTRIES_FILE */, string const & dataDir /* = string() */)
- : m_downloader(new HttpMapFilesDownloader()), m_currentSlotId(0), m_dataDir(dataDir),
- m_downloadMapOnTheMap(nullptr)
+ : m_downloader(new HttpMapFilesDownloader()), m_currentSlotId(0), m_dataDir(dataDir)
+ , m_autoRetryWorker(seconds(20))
+ , m_downloadMapOnTheMap(nullptr)
{
SetLocale(languages::GetCurrentTwine());
LoadCountriesFile(pathToCountriesFile, m_dataDir);
@@ -117,8 +119,9 @@ Storage::Storage(string const & pathToCountriesFile /* = COUNTRIES_FILE */, stri
Storage::Storage(string const & referenceCountriesTxtJsonForTesting,
unique_ptr<MapFilesDownloader> mapDownloaderForTesting)
- : m_downloader(move(mapDownloaderForTesting)), m_currentSlotId(0),
- m_downloadMapOnTheMap(nullptr)
+ : m_downloader(move(mapDownloaderForTesting)), m_currentSlotId(0)
+ , m_autoRetryWorker(seconds(20))
+ , m_downloadMapOnTheMap(nullptr)
{
m_currentVersion =
LoadCountries(referenceCountriesTxtJsonForTesting, m_countries, m_affiliations);
@@ -546,7 +549,29 @@ void Storage::DownloadNextCountryFromQueue()
ASSERT_THREAD_CHECKER(m_threadChecker, ());
if (m_queue.empty())
+ {
+ if (!m_failedCountries.empty() && m_autoRetryCounter > 0)
+ {
+ auto needReload = m_failedCountries;
+ auto action = [this, needReload]
+ {
+ --m_autoRetryCounter;
+ for (auto const & country : needReload)
+ {
+ NodeStatuses status;
+ GetNodeStatuses(country, status);
+ if (status.m_error == NodeErrorCode::NoInetConnection)
+ RetryDownloadNode(country);
+ }
+ };
+ m_autoRetryWorker.RestartWith([action]{Platform().RunOnGuiThread(action);});
+ }
+ else
+ {
+ m_autoRetryCounter = kAutoRetryCounterMax;
+ }
return;
+ }
QueuedCountry & queuedCountry = m_queue.front();
TCountryId const & countryId = queuedCountry.GetCountryId();
diff --git a/storage/storage.hpp b/storage/storage.hpp
index bbcf36bb42..eec72a493d 100644
--- a/storage/storage.hpp
+++ b/storage/storage.hpp
@@ -11,6 +11,7 @@
#include "platform/local_country_file.hpp"
+#include "base/deferred_task.hpp"
#include "base/thread_checker.hpp"
#include "std/function.hpp"
@@ -237,6 +238,12 @@ private:
ThreadChecker m_threadChecker;
+ static size_t constexpr kAutoRetryCounterMax = 3;
+ size_t m_autoRetryCounter = kAutoRetryCounterMax;
+ my::DeferredTask m_autoRetryWorker;
+
+ inline bool IsAutoRetryDownloadFailed() const { return m_autoRetryCounter == 0; }
+
void DownloadNextCountryFromQueue();
void LoadCountriesFile(string const & pathToCountriesFile, string const & dataDir,