Welcome to mirror list, hosted at ThFree Co, Russian Federation.

downloading_policy.hpp « storage - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 78fd6119fa93471d7dc2a705c43af0587a896581 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#pragma once

#include "storage/index.hpp"

#include "base/deferred_task.hpp"

#include "std/chrono.hpp"
#include "std/function.hpp"

class DownloadingPolicy
{
public:
  using TProcessFunc = function<void(storage::TCountriesSet const &)>;
  virtual bool IsDownloadingAllowed() { return true; }
  virtual void ScheduleRetry(storage::TCountriesSet 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;
  my::DeferredTask m_autoRetryWorker;

  time_point<steady_clock> m_disableCellularTime;

public:
  StorageDownloadingPolicy() : m_autoRetryWorker(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::TCountriesSet const & failedCountries,
                     TProcessFunc const & func) override;
};