Files
comaps/storage/downloading_policy.hpp
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

45 lines
1.3 KiB
C++

#pragma once
#include "storage/storage_defines.hpp"
#include "base/deferred_task.hpp"
#include <chrono>
#include <cstddef>
#include <utility>
class DownloadingPolicy
{
public:
using TProcessFunc = std::function<void(storage::CountriesSet const &)>;
virtual ~DownloadingPolicy() = default;
virtual bool IsDownloadingAllowed() { return true; }
virtual void ScheduleRetry(storage::CountriesSet const &, TProcessFunc const &) {}
};
class StorageDownloadingPolicy : public DownloadingPolicy
{
bool m_cellularDownloadEnabled = false;
bool m_downloadRetryFailed = false;
static size_t constexpr kAutoRetryCounterMax = 3;
size_t m_autoRetryCounter = kAutoRetryCounterMax;
base::DeferredTask m_autoRetryWorker;
std::chrono::time_point<std::chrono::steady_clock> m_disableCellularTime;
public:
StorageDownloadingPolicy() : m_autoRetryWorker(std::chrono::seconds(20)) {}
void EnableCellularDownload(bool enabled);
bool IsCellularDownloadEnabled();
inline bool IsAutoRetryDownloadFailed() const
{
return m_downloadRetryFailed || m_autoRetryCounter == 0;
}
// DownloadingPolicy overrides:
bool IsDownloadingAllowed() override;
void ScheduleRetry(storage::CountriesSet const & failedCountries,
TProcessFunc const & func) override;
};