diff --git a/qt/update_dialog.cpp b/qt/update_dialog.cpp index 2ed8d2a3dc..bdee24c990 100644 --- a/qt/update_dialog.cpp +++ b/qt/update_dialog.cpp @@ -234,7 +234,7 @@ namespace qt NodeAttrs attrs; st.GetNodeAttrs(countryId, attrs); - size.first = attrs.m_downloadingMwmSize; + size.first = attrs.m_downloadingProgress.first; size.second = attrs.m_mwmSize; switch (attrs.m_status) diff --git a/storage/simple_tree.hpp b/storage/simple_tree.hpp index 0568463f6d..2a43a3df69 100644 --- a/storage/simple_tree.hpp +++ b/storage/simple_tree.hpp @@ -6,6 +6,10 @@ #include "std/unique_ptr.hpp" #include "std/vector.hpp" +/// This class is developed for using in Storage. It's a implementation of a tree. +/// It should be filled with AddAtDepth method. Before calling AddAtDepth for a node +/// ReserveAtDepth should be called for the node. The tree can be filled only +/// according to BFS order. template class SimpleTree { @@ -34,8 +38,11 @@ public: return m_value; } - /// \brief Reserves child size vector. This method should be called once before filling - /// children vector with correct |n| size to prevent m_children relocation while filling. + /// \brief Reserves child size vector. This method should be called once for every node + /// just before filling children vector of the node to prevent m_children vector + /// relocation while filling. + /// \param level depth of node which children vector will be reserved. + /// \n number of vector elements will be reserved. void ReserveAtDepth(int level, size_t n) { SimpleTree * node = this; diff --git a/storage/storage.cpp b/storage/storage.cpp index 5c4a9a36d3..226191e5eb 100644 --- a/storage/storage.cpp +++ b/storage/storage.cpp @@ -441,7 +441,6 @@ void Storage::DownloadCountry(TCountryId const & countryId, MapOptions opt) } m_failedCountries.erase(countryId); - m_justDownloaded.clear(); m_queue.push_back(QueuedCountry(countryId, opt)); if (m_queue.size() == 1) DownloadNextCountryFromQueue(); @@ -532,7 +531,10 @@ void Storage::DownloadNextCountryFromQueue() OnMapDownloadFinished(countryId, false /* success */, queuedCountry.GetInitOptions()); NotifyStatusChanged(countryId); m_queue.pop_front(); - m_justDownloaded.insert(countryId); + if (m_queue.empty()) + m_justDownloaded.clear(); + else + m_justDownloaded.insert(countryId); DownloadNextCountryFromQueue(); return; } @@ -670,7 +672,6 @@ void Storage::OnMapFileDownloadFinished(bool success, void Storage::ReportProgress(TCountryId const & countryId, pair const & p) { ASSERT_THREAD_CHECKER(m_threadChecker, ()); - for (CountryObservers const & o : m_observers) o.m_progressFn(countryId, p); } @@ -1038,7 +1039,10 @@ bool Storage::DeleteCountryFilesFromDownloader(TCountryId const & countryId, Map if (queuedCountry->GetInitOptions() == MapOptions::Nothing) { m_queue.erase(find(m_queue.begin(), m_queue.end(), countryId)); - m_justDownloaded.insert(countryId); + if (m_queue.empty()) + m_justDownloaded.clear(); + else + m_justDownloaded.insert(countryId); } if (!m_queue.empty() && m_downloader->IsIdle()) @@ -1275,7 +1279,7 @@ void Storage::GetNodeAttrs(TCountryId const & countryId, NodeAttrs & nodeAttrs) descendants.push_back(d.Value().Name()); }); TCountryId const & downloadingMwm = IsDownloadInProgress() ? GetCurrentDownloadingCountryId() - : kInvalidCountryId; + : kInvalidCountryId; MapFilesDownloader::TProgress downloadingMwmProgress = m_downloader->IsIdle() ? make_pair(0LL, 0LL) : m_downloader->GetDownloadingProgress(); @@ -1283,7 +1287,6 @@ void Storage::GetNodeAttrs(TCountryId const & countryId, NodeAttrs & nodeAttrs) HashFromQueue(m_queue, hashQueue); nodeAttrs.m_downloadingProgress = CalculateProgress(descendants, downloadingMwm, downloadingMwmProgress, hashQueue); - nodeAttrs.m_downloadingMwmSize = nodeAttrs.m_downloadingProgress.first; nodeAttrs.m_parentInfo.clear(); nodeAttrs.m_parentInfo.reserve(nodes.size()); @@ -1318,7 +1321,7 @@ void Storage::DoClickOnDownloadMap(TCountryId const & countryId) pair Storage::CalculateProgress(TCountriesVec const & descendants, TCountryId const & downloadingMwm, pair const & downloadingMwmProgress, - TCountriesUnorderedSet const & hashQueue) const + TCountriesUnorderedSet const & mwmsInQueue) const { pair localAndRemoteBytes = make_pair(0, 0); for (auto const & d : descendants) @@ -1326,7 +1329,7 @@ pair Storage::CalculateProgress(TCountriesVec const & descenda if (d == downloadingMwm) continue; - if (hashQueue.count(d) != 0) + if (mwmsInQueue.count(d) != 0) { CountryFile const & remoteCountryFile = GetCountryFile(d); localAndRemoteBytes.second += remoteCountryFile.GetRemoteSize(MapOptions::Map); @@ -1336,7 +1339,8 @@ pair Storage::CalculateProgress(TCountriesVec const & descenda if (m_justDownloaded.count(d) != 0) { CountryFile const & localCountryFile = GetCountryFile(d); - localAndRemoteBytes.second += localCountryFile.GetRemoteSize(MapOptions::Map); + localAndRemoteBytes.first += localCountryFile.GetRemoteSize(MapOptions::Map); + localAndRemoteBytes.second += localAndRemoteBytes.first; } } if (downloadingMwm != kInvalidCountryId) diff --git a/storage/storage.hpp b/storage/storage.hpp index 99f825af3b..2e940f90d4 100644 --- a/storage/storage.hpp +++ b/storage/storage.hpp @@ -32,7 +32,7 @@ struct CountryIdAndName struct NodeAttrs { NodeAttrs() : m_mwmCounter(0), m_localMwmCounter(0), m_mwmSize(0), m_localMwmSize(0), - m_downloadingMwmSize(0), m_downloadingProgress(make_pair(0, 0)), + m_downloadingProgress(make_pair(0, 0)), m_status(NodeStatus::Undefined), m_error(NodeErrorCode::NoError), m_present(false) {} /// If the node is expandable (a big country) |m_mwmCounter| is number of mwm files (leaves) @@ -53,12 +53,6 @@ struct NodeAttrs /// have been downloaded. size_t m_localMwmSize; - /// If downloading or updating an mwm is in progress apart from a local mwm - /// which is currently used there's a partly downloading mwm of the same region. - /// |m_downloadingMwmSize| is size of partly downloaded mwm if downloading is in progress. - /// And |m_downloadingMwmSize| == 0 otherwise. - size_t m_downloadingMwmSize; - /// The name of the node in a local language. That means the language dependent on /// a device locale. string m_nodeLocalName; @@ -116,7 +110,7 @@ private: /// When a mwm file is downloaded it's moved from |m_queue| to |m_justDownloaded|. /// When a new mwm file is added to |m_queue| |m_justDownloaded| is cleared. /// Note. This set is necessary for implementation of downloading progress of - /// expandable mwm. + /// mwm group. TCountriesUnorderedSet m_justDownloaded; /// stores countries whose download has failed recently @@ -508,17 +502,17 @@ private: /// Will be removed in future after refactoring. TCountriesVec FindAllIndexesByFile(TCountryId const & name) const; - /// Calculates progress of downloading for non-expandable nodes in country tree. + /// Calculates progress of downloading for expandable nodes in country tree. /// |descendants| All descendants of the parent node. /// |downloadingMwm| Downloading leaf node country id if any. If not, downloadingMwm == kInvalidCountryId. /// If downloadingMwm != kInvalidCountryId |downloadingMwmProgress| is a progress of downloading /// the leaf node in bytes. |downloadingMwmProgress.first| == number of downloaded bytes. /// |downloadingMwmProgress.second| == number of bytes in downloading files. - /// |hashQueue| hash table made from |m_queue|. + /// |mwmsInQueue| hash table made from |m_queue|. pair CalculateProgress(TCountriesVec const & descendants, TCountryId const & downloadingMwm, pair const & downloadingMwmProgress, - TCountriesUnorderedSet const & hashQueue) const; + TCountriesUnorderedSet const & mwmsInQueue) const; }; template diff --git a/storage/storage_tests/storage_tests.cpp b/storage/storage_tests/storage_tests.cpp index 1c030913ea..fef2392474 100644 --- a/storage/storage_tests/storage_tests.cpp +++ b/storage/storage_tests/storage_tests.cpp @@ -1229,7 +1229,6 @@ UNIT_TEST(StorageTest_GetNodeAttrsSingleMwm) TEST_EQUAL(nodeAttrs.m_parentInfo[0].m_id, "Countries", ()); TEST_EQUAL(nodeAttrs.m_downloadingProgress.first, 0, ()); TEST_EQUAL(nodeAttrs.m_downloadingProgress.second, 0, ()); - TEST_EQUAL(nodeAttrs.m_downloadingMwmSize, 0, ()); storage.GetNodeAttrs("Algeria", nodeAttrs); TEST_EQUAL(nodeAttrs.m_mwmCounter, 2, ()); @@ -1240,7 +1239,6 @@ UNIT_TEST(StorageTest_GetNodeAttrsSingleMwm) TEST_EQUAL(nodeAttrs.m_parentInfo[0].m_id, "Countries", ()); TEST_EQUAL(nodeAttrs.m_downloadingProgress.first, 0, ()); TEST_EQUAL(nodeAttrs.m_downloadingProgress.second, 0, ()); - TEST_EQUAL(nodeAttrs.m_downloadingMwmSize, 0, ()); storage.GetNodeAttrs("Algeria_Coast", nodeAttrs); TEST_EQUAL(nodeAttrs.m_mwmCounter, 1, ()); @@ -1251,7 +1249,6 @@ UNIT_TEST(StorageTest_GetNodeAttrsSingleMwm) TEST_EQUAL(nodeAttrs.m_parentInfo[0].m_id, "Algeria", ()); TEST_EQUAL(nodeAttrs.m_downloadingProgress.first, 0, ()); TEST_EQUAL(nodeAttrs.m_downloadingProgress.second, 0, ()); - TEST_EQUAL(nodeAttrs.m_downloadingMwmSize, 0, ()); storage.GetNodeAttrs("South Korea_South", nodeAttrs); TEST_EQUAL(nodeAttrs.m_mwmCounter, 1, ()); @@ -1262,7 +1259,6 @@ UNIT_TEST(StorageTest_GetNodeAttrsSingleMwm) TEST_EQUAL(nodeAttrs.m_parentInfo[0].m_id, "Countries", ()); TEST_EQUAL(nodeAttrs.m_downloadingProgress.first, 0, ()); TEST_EQUAL(nodeAttrs.m_downloadingProgress.second, 0, ()); - TEST_EQUAL(nodeAttrs.m_downloadingMwmSize, 0, ()); storage.GetNodeAttrs("Disputable Territory", nodeAttrs); TEST_EQUAL(nodeAttrs.m_mwmCounter, 1, ()); @@ -1275,7 +1271,6 @@ UNIT_TEST(StorageTest_GetNodeAttrsSingleMwm) TEST_EQUAL(nodeAttrs.m_parentInfo[1].m_id, "Country2", ()); TEST_EQUAL(nodeAttrs.m_downloadingProgress.first, 0, ()); TEST_EQUAL(nodeAttrs.m_downloadingProgress.second, 0, ()); - TEST_EQUAL(nodeAttrs.m_downloadingMwmSize, 0, ()); } UNIT_TEST(StorageTest_ParseStatus)