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

downloading_policy.cpp « storage - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 758f152af8a681f67e6a0fc05d16b6c293fea628 (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
43
#include "storage/downloading_policy.hpp"

#include "platform/platform.hpp"

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::TCountriesSet 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().RunOnGuiThread(action); });
  }
  else
  {
    if (!failedCountries.empty())
      m_downloadRetryFailed = true;
    m_autoRetryCounter = kAutoRetryCounterMax;
  }
}