From aac681e5307e6f5c98f1c14c5017854644a23910 Mon Sep 17 00:00:00 2001 From: Sergey Yershov Date: Wed, 27 Apr 2016 17:38:07 +0300 Subject: [PATCH] [downloader] Refactor logic for disable downloading on cellular network and retry download on lost connection --- storage/downloading_policy.cpp | 4 ++-- storage/downloading_policy.hpp | 6 ++---- storage/storage.hpp | 3 +-- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/storage/downloading_policy.cpp b/storage/downloading_policy.cpp index a51567f178..6903a778d1 100644 --- a/storage/downloading_policy.cpp +++ b/storage/downloading_policy.cpp @@ -8,8 +8,8 @@ bool StorageDownloadingPolicy::IsDownloadingAllowed() const !IsCellularDownloadEnabled()); } -void StorageDownloadingPolicy::ScheduleRetry( - storage::TCountriesSet const & failedCountries, TProcessFunc const & func) +void StorageDownloadingPolicy::ScheduleRetry(storage::TCountriesSet const & failedCountries, + TProcessFunc const & func) { if (IsDownloadingAllowed() && !failedCountries.empty() && m_autoRetryCounter > 0) { diff --git a/storage/downloading_policy.hpp b/storage/downloading_policy.hpp index 1322ecb345..9b72c56941 100644 --- a/storage/downloading_policy.hpp +++ b/storage/downloading_policy.hpp @@ -11,7 +11,6 @@ class DownloadingPolicy { public: using TProcessFunc = function; - virtual bool IsDownloadingAllowed() const { return true; } virtual void ScheduleRetry(storage::TCountriesSet const &, TProcessFunc const &) {} }; @@ -19,14 +18,13 @@ public: class StorageDownloadingPolicy : public DownloadingPolicy { bool m_cellularDownloadEnabled = false; - static size_t constexpr kAutoRetryCounterMax = 3; size_t m_autoRetryCounter = kAutoRetryCounterMax; my::DeferredTask m_autoRetryWorker; - + public: StorageDownloadingPolicy() : m_autoRetryWorker(seconds(20)) {} - + inline void EnableCellularDownload(bool value) { m_cellularDownloadEnabled = value; } inline bool IsCellularDownloadEnabled() const { return m_cellularDownloadEnabled; } inline bool IsAutoRetryDownloadFailed() const { return m_autoRetryCounter == 0; } diff --git a/storage/storage.hpp b/storage/storage.hpp index f22381cefc..4201552ee6 100644 --- a/storage/storage.hpp +++ b/storage/storage.hpp @@ -187,7 +187,6 @@ private: DownloadingPolicy m_defaultDownloadingPolicy; DownloadingPolicy * m_downloadingPolicy = &m_defaultDownloadingPolicy; - /// @name Communicate with GUI //@{ @@ -289,7 +288,7 @@ public: unique_ptr mapDownloaderForTesting); void Init(TUpdateCallback const & didDownload, TDeleteCallback const & willDelete); - + inline void SetDownloadingPolicy(DownloadingPolicy * policy) { m_downloadingPolicy = policy; } /// @name Interface with clients (Android/iOS).