forked from organicmaps/organicmaps
[downloader] Mandatory disable cellular network downloading after one hour
This commit is contained in:
parent
b4d8c1c997
commit
a3b40108e4
2 changed files with 32 additions and 12 deletions
|
@ -2,7 +2,21 @@
|
|||
|
||||
#include "platform/platform.hpp"
|
||||
|
||||
bool StorageDownloadingPolicy::IsDownloadingAllowed() const
|
||||
void StorageDownloadingPolicy::EnableCellularDownload(bool enabled)
|
||||
{
|
||||
m_cellularDownloadEnabled = enabled;
|
||||
m_disableCellularTime = steady_clock::now() + hours(1);
|
||||
}
|
||||
|
||||
bool StorageDownloadingPolicy::IsCellularDownloadEnabled()
|
||||
{
|
||||
if (m_cellularDownloadEnabled && steady_clock::now() > m_disableCellularTime)
|
||||
m_cellularDownloadEnabled = false;
|
||||
|
||||
return m_cellularDownloadEnabled;
|
||||
}
|
||||
|
||||
bool StorageDownloadingPolicy::IsDownloadingAllowed()
|
||||
{
|
||||
return !(GetPlatform().ConnectionStatus() == Platform::EConnectionType::CONNECTION_WWAN &&
|
||||
!IsCellularDownloadEnabled());
|
||||
|
@ -14,8 +28,7 @@ void StorageDownloadingPolicy::ScheduleRetry(storage::TCountriesSet const & fail
|
|||
if (IsDownloadingAllowed() && !failedCountries.empty() && m_autoRetryCounter > 0)
|
||||
{
|
||||
m_downloadRetryFailed = false;
|
||||
auto action = [this, func, failedCountries]
|
||||
{
|
||||
auto action = [this, func, failedCountries] {
|
||||
--m_autoRetryCounter;
|
||||
func(failedCountries);
|
||||
};
|
||||
|
@ -23,7 +36,7 @@ void StorageDownloadingPolicy::ScheduleRetry(storage::TCountriesSet const & fail
|
|||
}
|
||||
else
|
||||
{
|
||||
if(!failedCountries.empty())
|
||||
if (!failedCountries.empty())
|
||||
m_downloadRetryFailed = true;
|
||||
m_autoRetryCounter = kAutoRetryCounterMax;
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ class DownloadingPolicy
|
|||
{
|
||||
public:
|
||||
using TProcessFunc = function<void(storage::TCountriesSet const &)>;
|
||||
virtual bool IsDownloadingAllowed() const { return true; }
|
||||
virtual bool IsDownloadingAllowed() { return true; }
|
||||
virtual void ScheduleRetry(storage::TCountriesSet const &, TProcessFunc const &) {}
|
||||
};
|
||||
|
||||
|
@ -22,14 +22,21 @@ class StorageDownloadingPolicy : public DownloadingPolicy
|
|||
static size_t constexpr kAutoRetryCounterMax = 3;
|
||||
size_t m_autoRetryCounter = kAutoRetryCounterMax;
|
||||
my::DeferredTask m_autoRetryWorker;
|
||||
|
||||
|
||||
time_point<steady_clock> m_disableCellularTime;
|
||||
|
||||
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_downloadRetryFailed || m_autoRetryCounter == 0; }
|
||||
void EnableCellularDownload(bool enabled);
|
||||
bool IsCellularDownloadEnabled();
|
||||
|
||||
bool IsDownloadingAllowed() const override;
|
||||
void ScheduleRetry(storage::TCountriesSet const & failedCountries, TProcessFunc const & func) override;
|
||||
inline bool IsAutoRetryDownloadFailed() const
|
||||
{
|
||||
return m_downloadRetryFailed || m_autoRetryCounter == 0;
|
||||
}
|
||||
|
||||
// DownloadingPolicy overrides:
|
||||
bool IsDownloadingAllowed() override;
|
||||
void ScheduleRetry(storage::TCountriesSet const & failedCountries,
|
||||
TProcessFunc const & func) override;
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue