mirror of
https://codeberg.org/comaps/comaps
synced 2026-01-03 11:23:48 +00:00
committed by
Konstantin Pastbin
parent
c9cbb64f12
commit
76ffc99abd
44
libs/storage/downloading_policy.hpp
Normal file
44
libs/storage/downloading_policy.hpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#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;
|
||||
};
|
||||
Reference in New Issue
Block a user