diff options
author | Vladimir Byko-Ianko <v.bykoianko@corp.mail.ru> | 2017-05-10 13:36:21 +0300 |
---|---|---|
committer | Vladimir Byko-Ianko <v.bykoianko@corp.mail.ru> | 2017-05-10 17:55:16 +0300 |
commit | 4676de4fd80e8d1e9a4d8977b8141090fadc80f4 (patch) | |
tree | c8aac1eddf642d7a89d4965751fae214d08dcfe7 /storage | |
parent | c801275db147d51e0a3efe84d0ffc4e2f2d56007 (diff) |
Calculating correct value of max mwm size.
Diffstat (limited to 'storage')
-rw-r--r-- | storage/storage.cpp | 21 | ||||
-rw-r--r-- | storage/storage.hpp | 6 | ||||
-rw-r--r-- | storage/storage_helpers.cpp | 10 | ||||
-rw-r--r-- | storage/storage_helpers.hpp | 4 |
4 files changed, 32 insertions, 9 deletions
diff --git a/storage/storage.cpp b/storage/storage.cpp index 515b0ce6dc..8b874ec683 100644 --- a/storage/storage.cpp +++ b/storage/storage.cpp @@ -114,18 +114,24 @@ Storage::Storage(string const & pathToCountriesFile /* = COUNTRIES_FILE */, , m_currentSlotId(0) , m_dataDir(dataDir) , m_downloadMapOnTheMap(nullptr) + , m_maxMwmSizeBytes(0) { SetLocale(languages::GetCurrentTwine()); LoadCountriesFile(pathToCountriesFile, m_dataDir); + CalMaxMwmSizeBytes(); } Storage::Storage(string const & referenceCountriesTxtJsonForTesting, unique_ptr<MapFilesDownloader> mapDownloaderForTesting) - : m_downloader(move(mapDownloaderForTesting)), m_currentSlotId(0), m_downloadMapOnTheMap(nullptr) + : m_downloader(move(mapDownloaderForTesting)) + , m_currentSlotId(0) + , m_downloadMapOnTheMap(nullptr) + , m_maxMwmSizeBytes(0) { m_currentVersion = LoadCountries(referenceCountriesTxtJsonForTesting, m_countries, m_affiliations); CHECK_LESS_OR_EQUAL(0, m_currentVersion, ("Can't load test countries file")); + CalMaxMwmSizeBytes(); } void Storage::Init(TUpdateCallback const & didDownload, TDeleteCallback const & willDelete) @@ -1310,6 +1316,19 @@ bool Storage::IsDisputed(TCountryTreeNode const & node) const return found.size() > 1; } +void Storage::CalMaxMwmSizeBytes() +{ + m_maxMwmSizeBytes = 0; + m_countries.GetRoot().ForEachInSubtree([&](TCountryTree::Node const & node) { + if (node.ChildrenCount() == 0) + { + TMwmSize mwmSizeBytes = node.Value().GetSubtreeMwmSizeBytes(); + if (mwmSizeBytes > m_maxMwmSizeBytes) + m_maxMwmSizeBytes = mwmSizeBytes; + } + }); +} + StatusAndError Storage::GetNodeStatusInfo( TCountryTreeNode const & node, vector<pair<TCountryId, NodeStatus>> & disputedTerritories, bool isDisputedTerritoriesCounted) const diff --git a/storage/storage.hpp b/storage/storage.hpp index 57e9c8a92f..cf753e040f 100644 --- a/storage/storage.hpp +++ b/storage/storage.hpp @@ -240,6 +240,8 @@ private: // Note. |m_affiliations| is empty in case of countries_obsolete.txt. TMappingAffiliations m_affiliations; + TMwmSize m_maxMwmSizeBytes; + ThreadChecker m_threadChecker; void DownloadNextCountryFromQueue(); @@ -532,6 +534,8 @@ public: /// Sets and gets locale, which is used to get localized counries names void SetLocale(string const & locale); string GetLocale() const; + + TMwmSize GetMaxMwmSizeBytes() const { return m_maxMwmSizeBytes; } // for testing: void SetDownloaderForTesting(unique_ptr<MapFilesDownloader> && downloader); @@ -635,6 +639,8 @@ private: void ForEachAncestorExceptForTheRoot(vector<TCountryTreeNode const *> const & nodes, ToDo && toDo) const; /// Returns true if |node.Value().Name()| is a disputed territory and false otherwise. bool IsDisputed(TCountryTreeNode const & node) const; + + void CalMaxMwmSizeBytes(); }; void GetQueuedCountries(Storage::TQueue const & queue, TCountriesSet & resultCountries); diff --git a/storage/storage_helpers.cpp b/storage/storage_helpers.cpp index 4764c89681..a636902b67 100644 --- a/storage/storage_helpers.cpp +++ b/storage/storage_helpers.cpp @@ -20,12 +20,12 @@ bool IsDownloadFailed(Status status) status == Status::EUnknown; } -bool IsEnoughSpaceForDownload(TMwmSize size) +bool IsEnoughSpaceForDownload(TMwmSize mwmSize, TMwmSize maxMwmSize) { - // Mwm size is less than kMaxMwmSizeBytes. In case of map update at first we download updated map + // Mwm size is less than |maxMwmSize|. In case of map update at first we download updated map // and only after that we do delete the obsolete map. So in such a case we might need up to // kMaxMwmSizeBytes of extra space. - return GetPlatform().GetWritableStorageStatus(size + kMaxMwmSizeBytes) == + return GetPlatform().GetWritableStorageStatus(mwmSize + maxMwmSize) == Platform::TStorageStatus::STORAGE_OK; } @@ -35,7 +35,7 @@ bool IsEnoughSpaceForDownload(TCountryId const & countryId, Storage const & stor storage.GetNodeAttrs(countryId, nodeAttrs); return IsEnoughSpaceForDownload(nodeAttrs.m_mwmSize > nodeAttrs.m_localMwmSize ? nodeAttrs.m_mwmSize - nodeAttrs.m_localMwmSize - : 0); + : 0, storage.GetMaxMwmSizeBytes()); } bool IsEnoughSpaceForUpdate(TCountryId const & countryId, Storage const & storage) @@ -44,7 +44,7 @@ bool IsEnoughSpaceForUpdate(TCountryId const & countryId, Storage const & storag storage.GetUpdateInfo(countryId, updateInfo); TMwmSize spaceNeedForUpdate = updateInfo.m_sizeDifference > 0 ? updateInfo.m_sizeDifference : 0; - return IsEnoughSpaceForDownload(spaceNeedForUpdate); + return IsEnoughSpaceForDownload(spaceNeedForUpdate, storage.GetMaxMwmSizeBytes()); } m2::RectD CalcLimitRect(TCountryId const & countryId, diff --git a/storage/storage_helpers.hpp b/storage/storage_helpers.hpp index d0593742c9..edf85bd0ec 100644 --- a/storage/storage_helpers.hpp +++ b/storage/storage_helpers.hpp @@ -13,8 +13,6 @@ namespace storage class CountryInfoGetter; class Storage; -TMwmSize constexpr kMaxMwmSizeBytes = 100 /*Mb*/ * 1024 * 1024; - /// \returns true if |position| is covered by a downloaded mwms and false otherwise. /// \note |position| has coordinates in mercator. /// \note This method takes into acount only maps enumerated in countries.txt. @@ -24,7 +22,7 @@ bool IsPointCoveredByDownloadedMaps(m2::PointD const & position, bool IsDownloadFailed(Status status); -bool IsEnoughSpaceForDownload(TMwmSize size); +bool IsEnoughSpaceForDownload(TMwmSize mwmSize, TMwmSize maxMwmSize); bool IsEnoughSpaceForDownload(TCountryId const & countryId, Storage const & storage); bool IsEnoughSpaceForUpdate(TCountryId const & countryId, Storage const & storage); |