Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArsentiy Milchakov <milcars@mapswithme.com>2019-04-25 18:44:59 +0300
committerArsentiy Milchakov <milcars@mapswithme.com>2019-05-08 16:49:33 +0300
commit201c2b2d9ffd3cbb75c62930462b58a19b3411b9 (patch)
tree8a18e91e92f4c7ce91e85a66cd9d3f385c1e0c72 /storage
parentbeb9e881b46ecdd1d3bc059823e0f8e1daf9058a (diff)
[storage][android] autoupdate displayed sizes fix
Diffstat (limited to 'storage')
-rw-r--r--storage/diff_scheme/diff_manager.cpp56
-rw-r--r--storage/diff_scheme/diff_manager.hpp5
-rw-r--r--storage/diff_scheme/diff_types.hpp1
-rw-r--r--storage/storage.cpp4
4 files changed, 52 insertions, 14 deletions
diff --git a/storage/diff_scheme/diff_manager.cpp b/storage/diff_scheme/diff_manager.cpp
index 0b60321d7d..61fe844c00 100644
--- a/storage/diff_scheme/diff_manager.cpp
+++ b/storage/diff_scheme/diff_manager.cpp
@@ -10,6 +10,19 @@
#include "3party/Alohalytics/src/alohalytics.h"
+namespace
+{
+bool IsDiffsAvailable(storage::diffs::NameDiffInfoMap const & diffs)
+{
+ for (auto const & d : diffs)
+ {
+ if (!d.second.m_isApplied)
+ return true;
+ }
+
+ return false;
+}
+} // namespace
namespace storage
{
namespace diffs
@@ -23,12 +36,12 @@ void Manager::Load(LocalMapsInfo && info)
}
m_workerThread.Push([this, localMapsInfo] {
- NameDiffInfoMap const diffs = Checker::Check(localMapsInfo);
+ NameDiffInfoMap diffs = Checker::Check(localMapsInfo);
std::lock_guard<std::mutex> lock(m_mutex);
- m_diffs = diffs;
- if (diffs.empty())
+ m_diffs = std::move(diffs);
+ if (m_diffs.empty())
{
m_status = Status::NotAvailable;
@@ -128,22 +141,44 @@ Status Manager::GetStatus() const
bool Manager::SizeFor(storage::CountryId const & countryId, uint64_t & size) const
{
- return WithDiff(countryId, [&size](DiffInfo const & info) { size = info.m_size; });
+ std::lock_guard<std::mutex> lock(m_mutex);
+ if (m_status != Status::Available)
+ return false;
+
+ auto const it = m_diffs.find(countryId);
+ if (it == m_diffs.cend())
+ return false;
+
+ size = it->second.m_size;
+ return true;
}
bool Manager::SizeToDownloadFor(storage::CountryId const & countryId, uint64_t & size) const
{
- return WithDiff(countryId, [&size](DiffInfo const & info) { size = info.m_size; });
+ return WithNotAppliedDiff(countryId, [&size](DiffInfo const & info) { size = info.m_size; });
}
-bool Manager::VersionFor(storage::CountryId const & countryId, uint64_t & version) const
+bool Manager::VersionFor(storage::CountryId const & countryId, uint64_t & v) const
{
- return WithDiff(countryId, [&version](DiffInfo const & info) { version = info.m_version; });
+ return WithNotAppliedDiff(countryId, [&v](DiffInfo const & info) { v = info.m_version; });
}
bool Manager::HasDiffFor(storage::CountryId const & countryId) const
{
- return WithDiff(countryId, [](DiffInfo const &) {});
+ return WithNotAppliedDiff(countryId, [](DiffInfo const &) {});
+}
+
+void Manager::MarkAsApplied(storage::CountryId const & countryId)
+{
+ std::lock_guard<std::mutex> lock(m_mutex);
+ auto const it = m_diffs.find(countryId);
+ if (it == m_diffs.end())
+ return;
+
+ it->second.m_isApplied = true;
+
+ if (!IsDiffsAvailable(m_diffs))
+ m_status = Status::NotAvailable;
}
void Manager::RemoveDiffForCountry(storage::CountryId const & countryId)
@@ -151,7 +186,7 @@ void Manager::RemoveDiffForCountry(storage::CountryId const & countryId)
std::lock_guard<std::mutex> lock(m_mutex);
m_diffs.erase(countryId);
- if (m_diffs.empty())
+ if (m_diffs.empty() || !IsDiffsAvailable(m_diffs))
m_status = Status::NotAvailable;
}
@@ -171,7 +206,8 @@ bool Manager::IsPossibleToAutoupdate() const
for (auto const & nameVersion : m_localMapsInfo.m_localMaps)
{
- if (m_diffs.find(nameVersion.first) == m_diffs.end())
+ auto const it = m_diffs.find(nameVersion.first);
+ if (it == m_diffs.end() || it->second.m_isApplied)
return false;
}
return true;
diff --git a/storage/diff_scheme/diff_manager.hpp b/storage/diff_scheme/diff_manager.hpp
index 6dfcf5e882..4bfcd67eea 100644
--- a/storage/diff_scheme/diff_manager.hpp
+++ b/storage/diff_scheme/diff_manager.hpp
@@ -60,6 +60,7 @@ public:
// has been downloaded.
bool HasDiffFor(storage::CountryId const & countryId) const;
+ void MarkAsApplied(storage::CountryId const & countryId);
void RemoveDiffForCountry(storage::CountryId const & countryId);
void AbortDiffScheme();
@@ -74,14 +75,14 @@ public:
private:
template <typename Fn>
- bool WithDiff(storage::CountryId const & countryId, Fn && fn) const
+ bool WithNotAppliedDiff(storage::CountryId const & countryId, Fn && fn) const
{
std::lock_guard<std::mutex> lock(m_mutex);
if (m_status != Status::Available)
return false;
auto const it = m_diffs.find(countryId);
- if (it == m_diffs.cend())
+ if (it == m_diffs.cend() || it->second.m_isApplied)
return false;
fn(it->second);
diff --git a/storage/diff_scheme/diff_types.hpp b/storage/diff_scheme/diff_types.hpp
index 6f31bd1a1c..1a86a1f044 100644
--- a/storage/diff_scheme/diff_types.hpp
+++ b/storage/diff_scheme/diff_types.hpp
@@ -24,6 +24,7 @@ struct DiffInfo final
uint64_t m_size;
uint64_t m_version;
+ bool m_isApplied = false;
};
using NameDiffInfoMap = std::unordered_map<storage::CountryId, DiffInfo>;
diff --git a/storage/storage.cpp b/storage/storage.cpp
index 8145e140ce..25c7d5594a 100644
--- a/storage/storage.cpp
+++ b/storage/storage.cpp
@@ -1342,7 +1342,7 @@ uint64_t Storage::GetDownloadSize(QueuedCountry const & queuedCountry) const
uint64_t size;
if (queuedCountry.GetInitOptions() == MapOptions::Diff)
{
- CHECK_NOT_EQUAL(m_diffManager.SizeFor(countryId, size), 0, ());
+ CHECK(m_diffManager.SizeToDownloadFor(countryId, size), ());
return size;
}
@@ -1619,7 +1619,7 @@ void Storage::ApplyDiff(CountryId const & countryId, function<void(bool isSucces
{
RegisterCountryFiles(diffFile);
Platform::DisableBackupForFile(diffFile->GetPath(MapOptions::Map));
- m_diffManager.RemoveDiffForCountry(countryId);
+ m_diffManager.MarkAsApplied(countryId);
fn(true);
break;
}