forked from organicmaps/organicmaps-tmp
[downloader] Refactor logic for disable downloading on cellular network and retry download on lost connection
This commit is contained in:
parent
64b7d04a2d
commit
aac681e530
3 changed files with 5 additions and 8 deletions
|
@ -8,8 +8,8 @@ bool StorageDownloadingPolicy::IsDownloadingAllowed() const
|
|||
!IsCellularDownloadEnabled());
|
||||
}
|
||||
|
||||
void StorageDownloadingPolicy::ScheduleRetry(
|
||||
storage::TCountriesSet const & failedCountries, TProcessFunc const & func)
|
||||
void StorageDownloadingPolicy::ScheduleRetry(storage::TCountriesSet const & failedCountries,
|
||||
TProcessFunc const & func)
|
||||
{
|
||||
if (IsDownloadingAllowed() && !failedCountries.empty() && m_autoRetryCounter > 0)
|
||||
{
|
||||
|
|
|
@ -11,7 +11,6 @@ class DownloadingPolicy
|
|||
{
|
||||
public:
|
||||
using TProcessFunc = function<void(storage::TCountriesSet const &)>;
|
||||
|
||||
virtual bool IsDownloadingAllowed() const { return true; }
|
||||
virtual void ScheduleRetry(storage::TCountriesSet const &, TProcessFunc const &) {}
|
||||
};
|
||||
|
@ -19,14 +18,13 @@ public:
|
|||
class StorageDownloadingPolicy : public DownloadingPolicy
|
||||
{
|
||||
bool m_cellularDownloadEnabled = false;
|
||||
|
||||
static size_t constexpr kAutoRetryCounterMax = 3;
|
||||
size_t m_autoRetryCounter = kAutoRetryCounterMax;
|
||||
my::DeferredTask m_autoRetryWorker;
|
||||
|
||||
|
||||
public:
|
||||
StorageDownloadingPolicy() : m_autoRetryWorker(seconds(20)) {}
|
||||
|
||||
|
||||
inline void EnableCellularDownload(bool value) { m_cellularDownloadEnabled = value; }
|
||||
inline bool IsCellularDownloadEnabled() const { return m_cellularDownloadEnabled; }
|
||||
inline bool IsAutoRetryDownloadFailed() const { return m_autoRetryCounter == 0; }
|
||||
|
|
|
@ -187,7 +187,6 @@ private:
|
|||
|
||||
DownloadingPolicy m_defaultDownloadingPolicy;
|
||||
DownloadingPolicy * m_downloadingPolicy = &m_defaultDownloadingPolicy;
|
||||
|
||||
/// @name Communicate with GUI
|
||||
//@{
|
||||
|
||||
|
@ -289,7 +288,7 @@ public:
|
|||
unique_ptr<MapFilesDownloader> mapDownloaderForTesting);
|
||||
|
||||
void Init(TUpdateCallback const & didDownload, TDeleteCallback const & willDelete);
|
||||
|
||||
|
||||
inline void SetDownloadingPolicy(DownloadingPolicy * policy) { m_downloadingPolicy = policy; }
|
||||
|
||||
/// @name Interface with clients (Android/iOS).
|
||||
|
|
Loading…
Add table
Reference in a new issue