Files
comaps/storage/downloading_policy.cpp
Konstantin Pastbin e3e4a1985a Organic Maps sources as of 02.04.2025 (fad26bbf22ac3da75e01e62aa01e5c8e11861005)
To expand with full Organic Maps and Maps.ME commits history run:
  git remote add om-historic [om-historic.git repo url]
  git fetch --tags om-historic
  git replace squashed-history historic-commits
2025-05-08 21:10:51 +07:00

46 lines
1.3 KiB
C++

#include "storage/downloading_policy.hpp"
#include "platform/platform.hpp"
using namespace std::chrono;
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());
}
void StorageDownloadingPolicy::ScheduleRetry(storage::CountriesSet const & failedCountries,
TProcessFunc const & func)
{
if (IsDownloadingAllowed() && !failedCountries.empty() && m_autoRetryCounter > 0)
{
m_downloadRetryFailed = false;
auto action = [this, func, failedCountries] {
--m_autoRetryCounter;
func(failedCountries);
};
m_autoRetryWorker.RestartWith([action]{ GetPlatform().RunTask(Platform::Thread::Gui, action); });
}
else
{
if (!failedCountries.empty())
m_downloadRetryFailed = true;
m_autoRetryCounter = kAutoRetryCounterMax;
}
}