From 1cb62e0e64ba3bae126eaedf1a1216a69fafa1bb Mon Sep 17 00:00:00 2001 From: Maxim Pimenov Date: Fri, 8 Feb 2019 16:59:49 +0300 Subject: [PATCH] [storage] Storing the CountryId of the latest request explicitly. It was stored as the m_frozen field in the QueuedCountry before. Now we store it directly in Storage. Another solution would be to send a query to DiffManager but due to its asynchronicity we observed the following: - A cancel request arrives from the user. It is sent to the diff manager. - The download queue is updated. The country is now in the "not downloaded" state because we are not sure which state it is in exactly and cannot afford to wait for the diff manager on the UI thread. - Diff manager processes the request. The download queue is updated again, the country is now in the "diff downloaded but not applied" state. --- storage/diff_scheme/diff_manager.hpp | 2 +- storage/queued_country.hpp | 3 --- storage/storage.cpp | 10 ++++++---- storage/storage.hpp | 2 ++ 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/storage/diff_scheme/diff_manager.hpp b/storage/diff_scheme/diff_manager.hpp index a993498c6a..0d10c19569 100644 --- a/storage/diff_scheme/diff_manager.hpp +++ b/storage/diff_scheme/diff_manager.hpp @@ -41,7 +41,7 @@ public: }; using OnDiffApplicationFinished = - std::function; + std::function; // If the diff is available, sets |size| to its size and returns true. // Otherwise, returns false. diff --git a/storage/queued_country.hpp b/storage/queued_country.hpp index 31f0f99ad3..fb5028c258 100644 --- a/storage/queued_country.hpp +++ b/storage/queued_country.hpp @@ -21,9 +21,6 @@ public: void ResetToDefaultOptions(); bool SwitchToNextFile(); - void SetFrozen(bool isFrozen) { m_isFrozen = isFrozen; } - bool IsFrozen() const { return m_isFrozen; } - inline CountryId const & GetCountryId() const { return m_countryId; } inline MapOptions GetInitOptions() const { return m_init; } inline MapOptions GetCurrentFileOptions() const { return m_current; } diff --git a/storage/storage.cpp b/storage/storage.cpp index d3dc57c1c4..a9a1da3173 100644 --- a/storage/storage.cpp +++ b/storage/storage.cpp @@ -951,8 +951,6 @@ void Storage::RegisterDownloadedFiles(CountryId const & countryId, MapOptions op if (options == MapOptions::Diff) { - m_queue.begin()->SetFrozen(true); - NotifyStatusChangedForHierarchy(countryId); ApplyDiff(countryId, fn); return; } @@ -1171,7 +1169,7 @@ bool Storage::IsDiffApplyingInProgressToCountry(CountryId const & countryId) con if (!IsCountryFirstInQueue(countryId)) return false; - return m_queue.front().IsFrozen(); + return m_queue.front().GetCountryId() == m_latestDiffRequest; } void Storage::SetLocale(string const & locale) { m_countryNameGetter.SetLocale(locale); } @@ -1288,7 +1286,7 @@ bool Storage::DeleteCountryFilesFromDownloader(CountryId const & countryId) if (!queuedCountry) return false; - if (queuedCountry->IsFrozen()) + if (m_latestDiffRequest && m_latestDiffRequest == countryId) m_diffsCancellable.Cancel(); MapOptions const opt = queuedCountry->GetInitOptions(); @@ -1558,6 +1556,8 @@ void Storage::LoadDiffScheme() void Storage::ApplyDiff(CountryId const & countryId, function const & fn) { m_diffsCancellable.Reset(); + m_latestDiffRequest = countryId; + NotifyStatusChangedForHierarchy(countryId); diffs::Manager::ApplyDiffParams params; params.m_diffFile = @@ -1569,6 +1569,7 @@ void Storage::ApplyDiff(CountryId const & countryId, function m_latestDiffRequest; + DownloadingPolicy m_defaultDownloadingPolicy; DownloadingPolicy * m_downloadingPolicy = &m_defaultDownloadingPolicy;