From 19b35b6224a906d299dfba689806450686cf59dd Mon Sep 17 00:00:00 2001 From: Sergey Yershov Date: Wed, 24 Feb 2016 14:59:15 +0300 Subject: [PATCH] [new downloader] Refactor Storage::DownloadNode --- storage/storage.cpp | 25 ++++++++++++------------- storage/storage.hpp | 2 +- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/storage/storage.cpp b/storage/storage.cpp index 9d073f2ebb..cb045aae41 100644 --- a/storage/storage.cpp +++ b/storage/storage.cpp @@ -1188,23 +1188,22 @@ bool Storage::IsNodeDownloaded(TCountryId const & countryId) const return false; } -bool Storage::DownloadNode(TCountryId const & countryId) +void Storage::DownloadNode(TCountryId const & countryId) { ASSERT_THREAD_CHECKER(m_threadChecker, ()); - // @TODO(bykoianko) Before downloading it's necessary to check if file(s) has been downloaded. - // If so, the method should be left with false. TCountriesContainer const * const node = m_countries.FindFirst(Country(countryId)); - CHECK(node, ()); - node->ForEachInSubtree([this](TCountriesContainer const & descendantNode) - { - if (descendantNode.ChildrenCount() == 0) - { - this->DownloadCountry(descendantNode.Value().Name(), - MapOptions::MapWithCarRouting); - } - }); - return true; + + if (!node) + return; + + auto downloadAction = [this](TCountriesContainer const & descendantNode) + { + if (descendantNode.ChildrenCount() == 0) + this->DownloadCountry(descendantNode.Value().Name(), MapOptions::MapWithCarRouting); + }; + + node->ForEachInSubtree(downloadAction); } void Storage::DeleteNode(TCountryId const & countryId) diff --git a/storage/storage.hpp b/storage/storage.hpp index fd43472ef3..5f4d31ee61 100644 --- a/storage/storage.hpp +++ b/storage/storage.hpp @@ -277,7 +277,7 @@ public: /// \brief Downloads one node (expandable or not) by countryId. /// If node is expandable downloads all children (grandchildren) by the node /// until they havn't been downloaded before. Update all downloaded mwm if it's necessary. - bool DownloadNode(TCountryId const & countryId); + void DownloadNode(TCountryId const & countryId); /// \brief Delete node with all children (expandable or not). void DeleteNode(TCountryId const & countryId);