mirror of
https://codeberg.org/comaps/comaps
synced 2026-01-02 11:03:44 +00:00
Format all C++ and Java code via clang-format
Signed-off-by: Konstantin Pastbin <konstantin.pastbin@gmail.com>
This commit is contained in:
@@ -18,36 +18,23 @@ class BackgroundDownloaderQueue : public QueueInterface
|
||||
public:
|
||||
using ForEachTaskInfoTypeFunction = std::function<void(TaskInfo const & info)>;
|
||||
|
||||
bool IsEmpty() const override
|
||||
{
|
||||
return m_queue.empty();
|
||||
}
|
||||
bool IsEmpty() const override { return m_queue.empty(); }
|
||||
|
||||
size_t Count() const override
|
||||
{
|
||||
return m_queue.size();
|
||||
}
|
||||
size_t Count() const override { return m_queue.size(); }
|
||||
|
||||
bool Contains(CountryId const & country) const override
|
||||
{
|
||||
return m_queue.find(country) != m_queue.cend();
|
||||
}
|
||||
bool Contains(CountryId const & country) const override { return m_queue.find(country) != m_queue.cend(); }
|
||||
|
||||
void ForEachCountry(ForEachCountryFunction const & fn) const override
|
||||
{
|
||||
for (auto const & item : m_queue)
|
||||
{
|
||||
fn(item.second.m_queuedCountry);
|
||||
}
|
||||
}
|
||||
|
||||
void ForEachTaskInfo(ForEachTaskInfoTypeFunction const & fn) const
|
||||
{
|
||||
for (auto const & item : m_queue)
|
||||
{
|
||||
if (item.second.m_taskInfo)
|
||||
fn(*item.second.m_taskInfo);
|
||||
}
|
||||
}
|
||||
|
||||
void Append(QueuedCountry && country)
|
||||
@@ -74,20 +61,11 @@ public:
|
||||
return it->second.m_taskInfo;
|
||||
}
|
||||
|
||||
QueuedCountry & GetCountryById(CountryId const & countryId)
|
||||
{
|
||||
return m_queue.at(countryId).m_queuedCountry;
|
||||
}
|
||||
QueuedCountry & GetCountryById(CountryId const & countryId) { return m_queue.at(countryId).m_queuedCountry; }
|
||||
|
||||
void Remove(CountryId const & countryId)
|
||||
{
|
||||
m_queue.erase(countryId);
|
||||
}
|
||||
void Remove(CountryId const & countryId) { m_queue.erase(countryId); }
|
||||
|
||||
void Clear()
|
||||
{
|
||||
m_queue.clear();
|
||||
}
|
||||
void Clear() { m_queue.clear(); }
|
||||
|
||||
private:
|
||||
struct TaskData
|
||||
|
||||
@@ -34,9 +34,9 @@ class Country
|
||||
public:
|
||||
Country() = default;
|
||||
explicit Country(CountryId const & name, CountryId const & parent = kInvalidCountryId)
|
||||
: m_name(name), m_parent(parent)
|
||||
{
|
||||
}
|
||||
: m_name(name)
|
||||
, m_parent(parent)
|
||||
{}
|
||||
|
||||
void SetFile(platform::CountryFile && file) { m_file = std::move(file); }
|
||||
void SetSubtreeAttrs(MwmCounter subtreeMwmNumber, MwmSize subtreeMwmSizeBytes)
|
||||
|
||||
@@ -14,7 +14,7 @@ void CountryInfo::FileName2FullName(string & fName)
|
||||
{
|
||||
// replace '_' with ", "
|
||||
fName[i] = ',';
|
||||
fName.insert(i+1, " ");
|
||||
fName.insert(i + 1, " ");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,10 +19,7 @@ namespace storage
|
||||
struct CountryDef
|
||||
{
|
||||
CountryDef() = default;
|
||||
CountryDef(CountryId const & countryId, m2::RectD const & rect)
|
||||
: m_countryId(countryId), m_rect(rect)
|
||||
{
|
||||
}
|
||||
CountryDef(CountryId const & countryId, m2::RectD const & rect) : m_countryId(countryId), m_rect(rect) {}
|
||||
|
||||
CountryId m_countryId;
|
||||
m2::RectD m_rect;
|
||||
@@ -36,8 +33,7 @@ struct CountryInfo
|
||||
// @TODO(bykoianko) Twine will be used intead of this function.
|
||||
// So id (fName) will be converted to a local name.
|
||||
static void FileName2FullName(std::string & fName);
|
||||
static void FullName2GroupAndMap(std::string const & fName, std::string & group,
|
||||
std::string & map);
|
||||
static void FullName2GroupAndMap(std::string const & fName, std::string & group, std::string & map);
|
||||
|
||||
bool IsNotEmpty() const { return !m_name.empty(); }
|
||||
|
||||
@@ -62,8 +58,7 @@ void Write(Sink & sink, CountryDef const & p)
|
||||
{
|
||||
rw::Write(sink, p.m_countryId);
|
||||
|
||||
std::pair<int64_t, int64_t> const r =
|
||||
RectToInt64Obsolete(p.m_rect, serial::GeometryCodingParams().GetCoordBits());
|
||||
std::pair<int64_t, int64_t> const r = RectToInt64Obsolete(p.m_rect, serial::GeometryCodingParams().GetCoordBits());
|
||||
|
||||
WriteVarInt(sink, r.first);
|
||||
WriteVarInt(sink, r.second);
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
#include <limits>
|
||||
#include <utility>
|
||||
|
||||
|
||||
namespace storage
|
||||
{
|
||||
namespace
|
||||
@@ -33,42 +32,33 @@ CountryId CountryInfoGetterBase::GetRegionCountryId(m2::PointD const & pt) const
|
||||
return id == kInvalidId ? kInvalidCountryId : m_countries[id].m_countryId;
|
||||
}
|
||||
|
||||
bool CountryInfoGetterBase::BelongsToAnyRegion(m2::PointD const & pt,
|
||||
RegionIdVec const & regions) const
|
||||
bool CountryInfoGetterBase::BelongsToAnyRegion(m2::PointD const & pt, RegionIdVec const & regions) const
|
||||
{
|
||||
for (auto const & id : regions)
|
||||
{
|
||||
if (BelongsToRegion(pt, id))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CountryInfoGetterBase::BelongsToAnyRegion(CountryId const & countryId,
|
||||
RegionIdVec const & regions) const
|
||||
bool CountryInfoGetterBase::BelongsToAnyRegion(CountryId const & countryId, RegionIdVec const & regions) const
|
||||
{
|
||||
for (auto const & id : regions)
|
||||
{
|
||||
if (m_countries[id].m_countryId == countryId)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
CountryInfoGetterBase::RegionId CountryInfoGetterBase::FindFirstCountry(m2::PointD const & pt) const
|
||||
{
|
||||
for (size_t id = 0; id < m_countries.size(); ++id)
|
||||
{
|
||||
if (BelongsToRegion(pt, id))
|
||||
return id;
|
||||
}
|
||||
|
||||
return kInvalidId;
|
||||
}
|
||||
|
||||
// CountryInfoGetter -------------------------------------------------------------------------------
|
||||
std::vector<CountryId> CountryInfoGetter::GetRegionsCountryIdByRect(m2::RectD const & rect,
|
||||
bool rough) const
|
||||
std::vector<CountryId> CountryInfoGetter::GetRegionsCountryIdByRect(m2::RectD const & rect, bool rough) const
|
||||
{
|
||||
std::vector<CountryId> result;
|
||||
for (size_t id = 0; id < m_countries.size(); ++id)
|
||||
@@ -94,10 +84,8 @@ void CountryInfoGetter::GetRegionsCountryId(m2::PointD const & pt, CountriesVec
|
||||
m2::RectD const lookupRect = mercator::RectByCenterXYAndSizeInMeters(pt, lookupRadiusM);
|
||||
|
||||
for (size_t id = 0; id < m_countries.size(); ++id)
|
||||
{
|
||||
if (m_countries[id].m_rect.IsIntersect(lookupRect) && IsCloseEnough(id, pt, lookupRadiusM))
|
||||
closestCoutryIds.emplace_back(m_countries[id].m_countryId);
|
||||
}
|
||||
}
|
||||
|
||||
void CountryInfoGetter::GetRegionInfo(m2::PointD const & pt, CountryInfo & info) const
|
||||
@@ -122,7 +110,8 @@ void CountryInfoGetter::GetRegionInfo(CountryId const & countryId, CountryInfo &
|
||||
|
||||
void CountryInfoGetter::CalcUSALimitRect(m2::RectD rects[3]) const
|
||||
{
|
||||
auto fn = [&](CountryDef const & c) {
|
||||
auto fn = [&](CountryDef const & c)
|
||||
{
|
||||
if (c.m_countryId == "USA_Alaska")
|
||||
rects[1] = c.m_rect;
|
||||
else if (c.m_countryId == "USA_Hawaii")
|
||||
@@ -137,10 +126,7 @@ void CountryInfoGetter::CalcUSALimitRect(m2::RectD rects[3]) const
|
||||
m2::RectD CountryInfoGetter::CalcLimitRect(std::string const & prefix) const
|
||||
{
|
||||
m2::RectD rect;
|
||||
ForEachCountry(prefix, [&rect](CountryDef const & c)
|
||||
{
|
||||
rect.Add(c.m_rect);
|
||||
});
|
||||
ForEachCountry(prefix, [&rect](CountryDef const & c) { rect.Add(c.m_rect); });
|
||||
return rect;
|
||||
}
|
||||
|
||||
@@ -159,8 +145,7 @@ m2::RectD CountryInfoGetter::GetLimitRectForLeaf(CountryId const & leafCountryId
|
||||
}
|
||||
}
|
||||
|
||||
void CountryInfoGetter::GetMatchedRegions(std::string const & affiliation,
|
||||
RegionIdVec & regions) const
|
||||
void CountryInfoGetter::GetMatchedRegions(std::string const & affiliation, RegionIdVec & regions) const
|
||||
{
|
||||
// Once set, m_affiliations ptr is never changed (same as the content).
|
||||
ASSERT(m_affiliations, ());
|
||||
@@ -170,10 +155,8 @@ void CountryInfoGetter::GetMatchedRegions(std::string const & affiliation,
|
||||
return;
|
||||
|
||||
for (size_t i = 0; i < m_countries.size(); ++i)
|
||||
{
|
||||
if (binary_search(it->second.begin(), it->second.end(), m_countries[i].m_countryId))
|
||||
regions.push_back(i);
|
||||
}
|
||||
}
|
||||
|
||||
void CountryInfoGetter::SetAffiliations(Affiliations const * affiliations)
|
||||
@@ -185,10 +168,8 @@ template <typename ToDo>
|
||||
void CountryInfoGetter::ForEachCountry(std::string const & prefix, ToDo && toDo) const
|
||||
{
|
||||
for (auto const & country : m_countries)
|
||||
{
|
||||
if (country.m_countryId.starts_with(prefix))
|
||||
toDo(country);
|
||||
}
|
||||
}
|
||||
|
||||
// CountryInfoReader -------------------------------------------------------------------------------
|
||||
@@ -197,8 +178,8 @@ std::unique_ptr<CountryInfoReader> CountryInfoReader::CreateCountryInfoReader(Pl
|
||||
{
|
||||
try
|
||||
{
|
||||
CountryInfoReader * result = new CountryInfoReader(platform.GetReader(PACKED_POLYGONS_FILE),
|
||||
platform.GetReader(COUNTRIES_FILE));
|
||||
CountryInfoReader * result =
|
||||
new CountryInfoReader(platform.GetReader(PACKED_POLYGONS_FILE), platform.GetReader(COUNTRIES_FILE));
|
||||
return std::unique_ptr<CountryInfoReader>(result);
|
||||
}
|
||||
catch (RootException const & e)
|
||||
@@ -229,7 +210,8 @@ void CountryInfoReader::LoadRegionsFromDisk(size_t id, std::vector<m2::RegionD>
|
||||
}
|
||||
|
||||
CountryInfoReader::CountryInfoReader(ModelReaderPtr polyR, ModelReaderPtr countryR)
|
||||
: m_reader(polyR), m_cache(3 /* logCacheSize */)
|
||||
: m_reader(polyR)
|
||||
, m_cache(3 /* logCacheSize */)
|
||||
|
||||
{
|
||||
ReaderSource<ModelReaderPtr> src(m_reader.GetReader(PACKED_POLYGONS_INFO_TAG));
|
||||
@@ -253,8 +235,7 @@ void CountryInfoReader::ClearCachesImpl() const
|
||||
}
|
||||
|
||||
template <typename Fn>
|
||||
std::invoke_result_t<Fn, std::vector<m2::RegionD>> CountryInfoReader::WithRegion(size_t id,
|
||||
Fn && fn) const
|
||||
std::invoke_result_t<Fn, std::vector<m2::RegionD>> CountryInfoReader::WithRegion(size_t id, Fn && fn) const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_cacheMutex);
|
||||
|
||||
@@ -272,12 +253,11 @@ bool CountryInfoReader::BelongsToRegion(m2::PointD const & pt, size_t id) const
|
||||
if (!m_countries[id].m_rect.IsPointInside(pt))
|
||||
return false;
|
||||
|
||||
auto contains = [&pt](std::vector<m2::RegionD> const & regions) {
|
||||
auto contains = [&pt](std::vector<m2::RegionD> const & regions)
|
||||
{
|
||||
for (auto const & region : regions)
|
||||
{
|
||||
if (region.Contains(pt))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
@@ -286,12 +266,12 @@ bool CountryInfoReader::BelongsToRegion(m2::PointD const & pt, size_t id) const
|
||||
|
||||
bool CountryInfoReader::IsIntersectedByRegion(m2::RectD const & rect, size_t id) const
|
||||
{
|
||||
std::vector<std::pair<m2::PointD, m2::PointD>> const edges = {
|
||||
{rect.LeftTop(), rect.RightTop()},
|
||||
{rect.RightTop(), rect.RightBottom()},
|
||||
{rect.RightBottom(), rect.LeftBottom()},
|
||||
{rect.LeftBottom(), rect.LeftTop()}};
|
||||
auto contains = [&edges](std::vector<m2::RegionD> const & regions) {
|
||||
std::vector<std::pair<m2::PointD, m2::PointD>> const edges = {{rect.LeftTop(), rect.RightTop()},
|
||||
{rect.RightTop(), rect.RightBottom()},
|
||||
{rect.RightBottom(), rect.LeftBottom()},
|
||||
{rect.LeftBottom(), rect.LeftTop()}};
|
||||
auto contains = [&edges](std::vector<m2::RegionD> const & regions)
|
||||
{
|
||||
for (auto const & region : regions)
|
||||
{
|
||||
for (auto const & edge : edges)
|
||||
@@ -313,12 +293,11 @@ bool CountryInfoReader::IsIntersectedByRegion(m2::RectD const & rect, size_t id)
|
||||
bool CountryInfoReader::IsCloseEnough(size_t id, m2::PointD const & pt, double distance) const
|
||||
{
|
||||
m2::RectD const lookupRect = mercator::RectByCenterXYAndSizeInMeters(pt, distance);
|
||||
auto isCloseEnough = [&](std::vector<m2::RegionD> const & regions) {
|
||||
auto isCloseEnough = [&](std::vector<m2::RegionD> const & regions)
|
||||
{
|
||||
for (auto const & region : regions)
|
||||
{
|
||||
if (region.Contains(pt) || region.AtBorder(pt, lookupRect.SizeX() / 2))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
@@ -339,14 +318,11 @@ void CountryInfoGetterForTesting::AddCountry(CountryDef const & country)
|
||||
m_idToInfo[name].m_name = name;
|
||||
}
|
||||
|
||||
void CountryInfoGetterForTesting::GetMatchedRegions(std::string const & affiliation,
|
||||
RegionIdVec & regions) const
|
||||
void CountryInfoGetterForTesting::GetMatchedRegions(std::string const & affiliation, RegionIdVec & regions) const
|
||||
{
|
||||
for (size_t i = 0; i < m_countries.size(); ++i)
|
||||
{
|
||||
if (m_countries[i].m_countryId == affiliation)
|
||||
regions.push_back(i);
|
||||
}
|
||||
}
|
||||
|
||||
void CountryInfoGetterForTesting::ClearCachesImpl() const {}
|
||||
@@ -363,8 +339,7 @@ bool CountryInfoGetterForTesting::IsIntersectedByRegion(m2::RectD const & rect,
|
||||
return rect.IsIntersect(m_countries[id].m_rect);
|
||||
}
|
||||
|
||||
bool CountryInfoGetterForTesting::IsCloseEnough(size_t id, m2::PointD const & pt,
|
||||
double distance) const
|
||||
bool CountryInfoGetterForTesting::IsCloseEnough(size_t id, m2::PointD const & pt, double distance) const
|
||||
{
|
||||
CHECK_LESS(id, m_countries.size(), ());
|
||||
|
||||
|
||||
@@ -33,8 +33,7 @@ CountryInfoReader::CountryInfoReader()
|
||||
}
|
||||
catch (FileReader::Exception const & exception)
|
||||
{
|
||||
LOG(LERROR,
|
||||
("Exception while reading file:", PACKED_POLYGONS_FILE, "reason:", exception.what()));
|
||||
LOG(LERROR, ("Exception while reading file:", PACKED_POLYGONS_FILE, "reason:", exception.what()));
|
||||
|
||||
m_reader.reset();
|
||||
m_countries.clear();
|
||||
@@ -66,10 +65,8 @@ bool CountryInfoReader::BelongsToRegion(m2::PointD const & pt, size_t id) const
|
||||
LoadRegionsFromDisk(id, regions);
|
||||
|
||||
for (auto const & region : regions)
|
||||
{
|
||||
if (region.Contains(pt))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
|
||||
namespace storage
|
||||
{
|
||||
CountryParentGetter::CountryParentGetter(std::string const & countriesFile,
|
||||
std::string const & countriesDir)
|
||||
CountryParentGetter::CountryParentGetter(std::string const & countriesFile, std::string const & countriesDir)
|
||||
{
|
||||
if (countriesFile.empty())
|
||||
m_storage = std::make_shared<Storage>();
|
||||
|
||||
@@ -10,8 +10,7 @@ namespace storage
|
||||
class CountryParentGetter
|
||||
{
|
||||
public:
|
||||
CountryParentGetter(std::string const & countriesFile = "",
|
||||
std::string const & countriesDir = "");
|
||||
CountryParentGetter(std::string const & countriesFile = "", std::string const & countriesDir = "");
|
||||
std::string operator()(std::string const & id) const;
|
||||
|
||||
Storage const & GetStorageForTesting() const { return *m_storage; }
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
namespace storage
|
||||
{
|
||||
using namespace std;
|
||||
@@ -28,17 +27,13 @@ class StoreInterface
|
||||
{
|
||||
public:
|
||||
virtual ~StoreInterface() = default;
|
||||
virtual Country * InsertToCountryTree(CountryId const & id, MwmSize mapSize,
|
||||
string const & mapSha1, size_t depth,
|
||||
virtual Country * InsertToCountryTree(CountryId const & id, MwmSize mapSize, string const & mapSha1, size_t depth,
|
||||
CountryId const & parent) = 0;
|
||||
virtual void InsertOldMwmMapping(CountryId const & newId, CountryId const & oldId) = 0;
|
||||
virtual void InsertAffiliation(CountryId const & countryId, string const & affilation) = 0;
|
||||
virtual void InsertCountryNameSynonym(CountryId const & countryId, string const & synonym) = 0;
|
||||
virtual void InsertMwmTopCityGeoId(CountryId const & countryId, uint64_t const & geoObjectId) {}
|
||||
virtual void InsertTopCountryGeoIds(CountryId const & countryId,
|
||||
vector<uint64_t> const & geoObjectIds)
|
||||
{
|
||||
}
|
||||
virtual void InsertTopCountryGeoIds(CountryId const & countryId, vector<uint64_t> const & geoObjectIds) {}
|
||||
virtual OldMwmMapping GetMapping() const = 0;
|
||||
};
|
||||
|
||||
@@ -52,16 +47,14 @@ class StoreCountries : public StoreInterface
|
||||
OldMwmMapping m_idsMapping;
|
||||
|
||||
public:
|
||||
StoreCountries(CountryTree & countries, Affiliations & affiliations,
|
||||
CountryNameSynonyms & countryNameSynonyms, MwmTopCityGeoIds & mwmTopCityGeoIds,
|
||||
MwmTopCountryGeoIds & mwmTopCountryGeoIds)
|
||||
StoreCountries(CountryTree & countries, Affiliations & affiliations, CountryNameSynonyms & countryNameSynonyms,
|
||||
MwmTopCityGeoIds & mwmTopCityGeoIds, MwmTopCountryGeoIds & mwmTopCountryGeoIds)
|
||||
: m_countries(countries)
|
||||
, m_affiliations(affiliations)
|
||||
, m_countryNameSynonyms(countryNameSynonyms)
|
||||
, m_mwmTopCityGeoIds(mwmTopCityGeoIds)
|
||||
, m_mwmTopCountryGeoIds(mwmTopCountryGeoIds)
|
||||
{
|
||||
}
|
||||
{}
|
||||
~StoreCountries()
|
||||
{
|
||||
for (auto & entry : m_affiliations)
|
||||
@@ -69,8 +62,8 @@ public:
|
||||
}
|
||||
|
||||
// StoreInterface overrides:
|
||||
Country * InsertToCountryTree(CountryId const & id, MwmSize mapSize, string const & mapSha1,
|
||||
size_t depth, CountryId const & parent) override
|
||||
Country * InsertToCountryTree(CountryId const & id, MwmSize mapSize, string const & mapSha1, size_t depth,
|
||||
CountryId const & parent) override
|
||||
{
|
||||
Country country(id, parent);
|
||||
if (mapSize)
|
||||
@@ -110,8 +103,7 @@ public:
|
||||
m_mwmTopCityGeoIds.emplace(countryId, std::move(id));
|
||||
}
|
||||
|
||||
void InsertTopCountryGeoIds(CountryId const & countryId,
|
||||
vector<uint64_t> const & geoObjectIds) override
|
||||
void InsertTopCountryGeoIds(CountryId const & countryId, vector<uint64_t> const & geoObjectIds) override
|
||||
{
|
||||
ASSERT(!countryId.empty(), ());
|
||||
ASSERT(!geoObjectIds.empty(), ());
|
||||
@@ -128,13 +120,10 @@ class StoreFile2Info : public StoreInterface
|
||||
map<string, CountryInfo> & m_file2info;
|
||||
|
||||
public:
|
||||
explicit StoreFile2Info(map<string, CountryInfo> & file2info) : m_file2info(file2info)
|
||||
{
|
||||
}
|
||||
explicit StoreFile2Info(map<string, CountryInfo> & file2info) : m_file2info(file2info) {}
|
||||
// StoreInterface overrides:
|
||||
Country * InsertToCountryTree(CountryId const & id, MwmSize /* mapSize */,
|
||||
string const & /* mapSha1 */, size_t /* depth */,
|
||||
CountryId const & /* parent */) override
|
||||
Country * InsertToCountryTree(CountryId const & id, MwmSize /* mapSize */, string const & /* mapSha1 */,
|
||||
size_t /* depth */, CountryId const & /* parent */) override
|
||||
{
|
||||
CountryInfo info(id);
|
||||
m_file2info[id] = std::move(info);
|
||||
@@ -143,15 +132,9 @@ public:
|
||||
|
||||
void InsertOldMwmMapping(CountryId const & /* newId */, CountryId const & /* oldId */) override {}
|
||||
|
||||
void InsertAffiliation(CountryId const & /* countryId */,
|
||||
string const & /* affilation */) override
|
||||
{
|
||||
}
|
||||
void InsertAffiliation(CountryId const & /* countryId */, string const & /* affilation */) override {}
|
||||
|
||||
void InsertCountryNameSynonym(CountryId const & /* countryId */,
|
||||
string const & /* synonym */) override
|
||||
{
|
||||
}
|
||||
void InsertCountryNameSynonym(CountryId const & /* countryId */, string const & /* synonym */) override {}
|
||||
|
||||
OldMwmMapping GetMapping() const override
|
||||
{
|
||||
@@ -236,8 +219,7 @@ void CountryTree::Node::ForEachAncestorExceptForTheRoot(CountryTree::Node::NodeC
|
||||
m_parent->ForEachAncestorExceptForTheRoot(f);
|
||||
}
|
||||
|
||||
void CountryTree::Node::ForEachAncestorExceptForTheRoot(
|
||||
CountryTree::Node::NodeCallback const & f) const
|
||||
void CountryTree::Node::ForEachAncestorExceptForTheRoot(CountryTree::Node::NodeCallback const & f) const
|
||||
{
|
||||
if (m_parent == nullptr || m_parent->m_parent == nullptr)
|
||||
return;
|
||||
@@ -325,15 +307,12 @@ CountryTree::Node const * CountryTree::FindFirstLeaf(CountryId const & key) cons
|
||||
Find(key, found);
|
||||
|
||||
for (auto node : found)
|
||||
{
|
||||
if (node->ChildrenCount() == 0)
|
||||
return node;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
MwmSubtreeAttrs LoadGroupImpl(size_t depth, json_t * node, CountryId const & parent,
|
||||
StoreInterface & store)
|
||||
MwmSubtreeAttrs LoadGroupImpl(size_t depth, json_t * node, CountryId const & parent, StoreInterface & store)
|
||||
{
|
||||
CountryId id;
|
||||
FromJSONObject(node, "id", id);
|
||||
@@ -408,10 +387,8 @@ bool LoadCountriesImpl(string const & jsonBuffer, StoreInterface & store)
|
||||
}
|
||||
}
|
||||
|
||||
int64_t LoadCountriesFromBuffer(string const & jsonBuffer, CountryTree & countries,
|
||||
Affiliations & affiliations,
|
||||
CountryNameSynonyms & countryNameSynonyms,
|
||||
MwmTopCityGeoIds & mwmTopCityGeoIds,
|
||||
int64_t LoadCountriesFromBuffer(string const & jsonBuffer, CountryTree & countries, Affiliations & affiliations,
|
||||
CountryNameSynonyms & countryNameSynonyms, MwmTopCityGeoIds & mwmTopCityGeoIds,
|
||||
MwmTopCountryGeoIds & mwmTopCountryGeoIds)
|
||||
{
|
||||
countries.Clear();
|
||||
@@ -423,8 +400,7 @@ int64_t LoadCountriesFromBuffer(string const & jsonBuffer, CountryTree & countri
|
||||
base::Json root(jsonBuffer.c_str());
|
||||
FromJSONObject(root.get(), "v", version);
|
||||
|
||||
StoreCountries store(countries, affiliations, countryNameSynonyms, mwmTopCityGeoIds,
|
||||
mwmTopCountryGeoIds);
|
||||
StoreCountries store(countries, affiliations, countryNameSynonyms, mwmTopCityGeoIds, mwmTopCountryGeoIds);
|
||||
if (!LoadCountriesImpl(jsonBuffer, store))
|
||||
return -1;
|
||||
}
|
||||
@@ -444,16 +420,13 @@ unique_ptr<Reader> GetReaderImpl(Platform & pl, string const & file, string cons
|
||||
return pl.GetReader(file, scope);
|
||||
}
|
||||
catch (RootException const &)
|
||||
{
|
||||
}
|
||||
{}
|
||||
return nullptr;
|
||||
}
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
int64_t LoadCountriesFromFile(string const & path, CountryTree & countries,
|
||||
Affiliations & affiliations,
|
||||
CountryNameSynonyms & countryNameSynonyms,
|
||||
MwmTopCityGeoIds & mwmTopCityGeoIds,
|
||||
int64_t LoadCountriesFromFile(string const & path, CountryTree & countries, Affiliations & affiliations,
|
||||
CountryNameSynonyms & countryNameSynonyms, MwmTopCityGeoIds & mwmTopCityGeoIds,
|
||||
MwmTopCountryGeoIds & mwmTopCountryGeoIds)
|
||||
{
|
||||
string json;
|
||||
@@ -468,8 +441,8 @@ int64_t LoadCountriesFromFile(string const & path, CountryTree & countries,
|
||||
if (reader)
|
||||
{
|
||||
reader->ReadAsString(json);
|
||||
version = LoadCountriesFromBuffer(json, countries, affiliations, countryNameSynonyms,
|
||||
mwmTopCityGeoIds, mwmTopCountryGeoIds);
|
||||
version = LoadCountriesFromBuffer(json, countries, affiliations, countryNameSynonyms, mwmTopCityGeoIds,
|
||||
mwmTopCountryGeoIds);
|
||||
}
|
||||
|
||||
reader = GetReaderImpl(pl, path, "w");
|
||||
@@ -482,8 +455,7 @@ int64_t LoadCountriesFromFile(string const & path, CountryTree & countries,
|
||||
MwmTopCountryGeoIds newCountryIds;
|
||||
|
||||
reader->ReadAsString(json);
|
||||
int64_t const newVersion = LoadCountriesFromBuffer(json, newCountries, newAffs, newSyms,
|
||||
newCityIds, newCountryIds);
|
||||
int64_t const newVersion = LoadCountriesFromBuffer(json, newCountries, newAffs, newSyms, newCityIds, newCountryIds);
|
||||
|
||||
if (newVersion > version)
|
||||
{
|
||||
|
||||
@@ -119,17 +119,12 @@ private:
|
||||
};
|
||||
|
||||
/// @return version of country file or -1 if error was encountered
|
||||
int64_t LoadCountriesFromBuffer(std::string const & buffer, CountryTree & countries,
|
||||
Affiliations & affiliations,
|
||||
CountryNameSynonyms & countryNameSynonyms,
|
||||
MwmTopCityGeoIds & mwmTopCityGeoIds,
|
||||
int64_t LoadCountriesFromBuffer(std::string const & buffer, CountryTree & countries, Affiliations & affiliations,
|
||||
CountryNameSynonyms & countryNameSynonyms, MwmTopCityGeoIds & mwmTopCityGeoIds,
|
||||
MwmTopCountryGeoIds & mwmTopCountryGeoIds);
|
||||
int64_t LoadCountriesFromFile(std::string const & path, CountryTree & countries,
|
||||
Affiliations & affiliations,
|
||||
CountryNameSynonyms & countryNameSynonyms,
|
||||
MwmTopCityGeoIds & mwmTopCityGeoIds,
|
||||
int64_t LoadCountriesFromFile(std::string const & path, CountryTree & countries, Affiliations & affiliations,
|
||||
CountryNameSynonyms & countryNameSynonyms, MwmTopCityGeoIds & mwmTopCityGeoIds,
|
||||
MwmTopCountryGeoIds & mwmTopCountryGeoIds);
|
||||
|
||||
void LoadCountryFile2CountryInfo(std::string const & jsonBuffer,
|
||||
std::map<std::string, CountryInfo> & id2info);
|
||||
void LoadCountryFile2CountryInfo(std::string const & jsonBuffer, std::map<std::string, CountryInfo> & id2info);
|
||||
} // namespace storage
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
#include "base/logging.hpp"
|
||||
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
namespace storage
|
||||
{
|
||||
@@ -23,10 +23,8 @@ CountryId GetTopmostParentFor(CountryTree const & countries, CountryId const & c
|
||||
CHECK(nodes[0]->HasParent(), ());
|
||||
auto const parentId = nodes[0]->Parent().Value().Name();
|
||||
for (size_t i = 1; i < nodes.size(); ++i)
|
||||
{
|
||||
if (nodes[i]->Parent().Value().Name() != parentId)
|
||||
return countryId;
|
||||
}
|
||||
return GetTopmostParentFor(countries, parentId);
|
||||
}
|
||||
|
||||
@@ -52,8 +50,8 @@ std::optional<CountryTree> LoadCountriesFromFile(std::string const & path)
|
||||
MwmTopCityGeoIds mwmTopCityGeoIds;
|
||||
MwmTopCountryGeoIds mwmTopCountryGeoIds;
|
||||
CountryTree countries;
|
||||
auto const res = LoadCountriesFromFile(path, countries, affiliations, countryNameSynonyms,
|
||||
mwmTopCityGeoIds, mwmTopCountryGeoIds);
|
||||
auto const res =
|
||||
LoadCountriesFromFile(path, countries, affiliations, countryNameSynonyms, mwmTopCityGeoIds, mwmTopCountryGeoIds);
|
||||
|
||||
if (res == -1)
|
||||
return {};
|
||||
|
||||
@@ -7,17 +7,16 @@
|
||||
#include "base/assert.hpp"
|
||||
#include "base/cancellable.hpp"
|
||||
|
||||
|
||||
namespace storage
|
||||
{
|
||||
namespace diffs
|
||||
{
|
||||
void ApplyDiff(ApplyDiffParams && p, base::Cancellable const & cancellable,
|
||||
OnDiffApplicationFinished const & task)
|
||||
void ApplyDiff(ApplyDiffParams && p, base::Cancellable const & cancellable, OnDiffApplicationFinished const & task)
|
||||
{
|
||||
using namespace generator::mwm_diff;
|
||||
|
||||
GetPlatform().RunTask(Platform::Thread::File, [p = std::move(p), &cancellable, task] {
|
||||
GetPlatform().RunTask(Platform::Thread::File, [p = std::move(p), &cancellable, task]
|
||||
{
|
||||
CHECK(p.m_diffFile, ());
|
||||
CHECK(p.m_oldMwmFile, ());
|
||||
|
||||
@@ -41,13 +40,9 @@ void ApplyDiff(ApplyDiffParams && p, base::Cancellable const & cancellable,
|
||||
std::string const newMwmPath = diffFile->GetPath(MapFileType::Map);
|
||||
std::string const diffApplyingInProgressPath = newMwmPath + DIFF_APPLYING_FILE_EXTENSION;
|
||||
|
||||
result = generator::mwm_diff::ApplyDiff(oldMwmPath, diffApplyingInProgressPath, diffPath,
|
||||
cancellable);
|
||||
if (result == DiffApplicationResult::Ok &&
|
||||
!base::RenameFileX(diffApplyingInProgressPath, newMwmPath))
|
||||
{
|
||||
result = generator::mwm_diff::ApplyDiff(oldMwmPath, diffApplyingInProgressPath, diffPath, cancellable);
|
||||
if (result == DiffApplicationResult::Ok && !base::RenameFileX(diffApplyingInProgressPath, newMwmPath))
|
||||
result = DiffApplicationResult::Failed;
|
||||
}
|
||||
|
||||
Platform::RemoveFileIfExists(diffApplyingInProgressPath);
|
||||
|
||||
@@ -57,23 +52,16 @@ void ApplyDiff(ApplyDiffParams && p, base::Cancellable const & cancellable,
|
||||
|
||||
switch (result)
|
||||
{
|
||||
case DiffApplicationResult::Ok:
|
||||
diffFile->DeleteFromDisk(MapFileType::Diff);
|
||||
break;
|
||||
case DiffApplicationResult::Cancelled:
|
||||
// The diff file will be deleted by storage.
|
||||
// Another way would be to leave it on disk but all consequences
|
||||
// of interacting with storage are much harder to be taken into account that way.
|
||||
break;
|
||||
case DiffApplicationResult::Failed:
|
||||
diffFile->DeleteFromDisk(MapFileType::Diff);
|
||||
break;
|
||||
case DiffApplicationResult::Ok: diffFile->DeleteFromDisk(MapFileType::Diff); break;
|
||||
case DiffApplicationResult::Cancelled:
|
||||
// The diff file will be deleted by storage.
|
||||
// Another way would be to leave it on disk but all consequences
|
||||
// of interacting with storage are much harder to be taken into account that way.
|
||||
break;
|
||||
case DiffApplicationResult::Failed: diffFile->DeleteFromDisk(MapFileType::Diff); break;
|
||||
}
|
||||
|
||||
GetPlatform().RunTask(Platform::Thread::Gui, [task, result]()
|
||||
{
|
||||
task(result);
|
||||
});
|
||||
GetPlatform().RunTask(Platform::Thread::Gui, [task, result]() { task(result); });
|
||||
});
|
||||
}
|
||||
} // namespace diffs
|
||||
|
||||
@@ -24,7 +24,6 @@ struct ApplyDiffParams
|
||||
|
||||
using OnDiffApplicationFinished = std::function<void(generator::mwm_diff::DiffApplicationResult)>;
|
||||
|
||||
void ApplyDiff(ApplyDiffParams && p, base::Cancellable const & cancellable,
|
||||
OnDiffApplicationFinished const & task);
|
||||
void ApplyDiff(ApplyDiffParams && p, base::Cancellable const & cancellable, OnDiffApplicationFinished const & task);
|
||||
} // namespace diffs
|
||||
} // namespace storage
|
||||
|
||||
@@ -137,12 +137,11 @@ namespace diffs
|
||||
// static
|
||||
void Loader::Load(LocalMapsInfo && info, DiffsReceivedCallback && callback)
|
||||
{
|
||||
GetPlatform().RunTask(Platform::Thread::Network, [info = std::move(info), callback = std::move(callback)]() {
|
||||
GetPlatform().RunTask(Platform::Thread::Network, [info = std::move(info), callback = std::move(callback)]()
|
||||
{
|
||||
auto result = ::Load(info);
|
||||
GetPlatform().RunTask(Platform::Thread::Gui,
|
||||
[result = std::move(result), callback = std::move(callback)]() mutable {
|
||||
callback(std::move(result));
|
||||
});
|
||||
GetPlatform().RunTask(Platform::Thread::Gui, [result = std::move(result), callback = std::move(callback)]() mutable
|
||||
{ callback(std::move(result)); });
|
||||
});
|
||||
}
|
||||
} // namespace diffs
|
||||
|
||||
@@ -2,13 +2,11 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
bool IsDiffsAvailable(storage::diffs::NameDiffInfoMap const & diffs)
|
||||
{
|
||||
return std::any_of(diffs.cbegin(), diffs.cend(),
|
||||
[](auto const & d) { return d.second.m_isApplied == false; });
|
||||
return std::any_of(diffs.cbegin(), diffs.cend(), [](auto const & d) { return d.second.m_isApplied == false; });
|
||||
}
|
||||
} // namespace
|
||||
|
||||
|
||||
@@ -7,4 +7,4 @@ namespace storage
|
||||
class MapFilesDownloader;
|
||||
|
||||
std::unique_ptr<MapFilesDownloader> GetDownloader();
|
||||
} // namespace downloader
|
||||
} // namespace storage
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "storage/storage_defines.hpp"
|
||||
#include "storage/queued_country.hpp"
|
||||
#include "storage/storage_defines.hpp"
|
||||
|
||||
namespace storage
|
||||
{
|
||||
|
||||
@@ -22,17 +22,13 @@ bool Queue::Contains(CountryId const & country) const
|
||||
void Queue::ForEachCountry(ForEachCountryFunction const & fn) const
|
||||
{
|
||||
for (auto const & queuedCountry : m_queue)
|
||||
{
|
||||
fn(queuedCountry);
|
||||
}
|
||||
}
|
||||
|
||||
void Queue::ForEachCountry(ForEachCountryMutable const & fn)
|
||||
{
|
||||
for (auto & queuedCountry : m_queue)
|
||||
{
|
||||
fn(queuedCountry);
|
||||
}
|
||||
}
|
||||
|
||||
CountryId const & Queue::GetFirstId() const
|
||||
@@ -49,7 +45,7 @@ QueuedCountry const & Queue::GetFirstCountry() const
|
||||
return m_queue.front();
|
||||
}
|
||||
|
||||
void Queue::Remove(const storage::CountryId & id)
|
||||
void Queue::Remove(storage::CountryId const & id)
|
||||
{
|
||||
auto it = std::find(m_queue.begin(), m_queue.end(), id);
|
||||
if (it != m_queue.end())
|
||||
|
||||
@@ -11,9 +11,9 @@ namespace storage
|
||||
struct DownloaderSearchResult
|
||||
{
|
||||
DownloaderSearchResult(CountryId const & countryId, std::string const & matchedName)
|
||||
: m_countryId(countryId), m_matchedName(matchedName)
|
||||
{
|
||||
}
|
||||
: m_countryId(countryId)
|
||||
, m_matchedName(matchedName)
|
||||
{}
|
||||
|
||||
bool operator==(DownloaderSearchResult const & rhs) const
|
||||
{
|
||||
|
||||
@@ -24,17 +24,17 @@ bool StorageDownloadingPolicy::IsDownloadingAllowed()
|
||||
!IsCellularDownloadEnabled());
|
||||
}
|
||||
|
||||
void StorageDownloadingPolicy::ScheduleRetry(storage::CountriesSet const & failedCountries,
|
||||
TProcessFunc const & func)
|
||||
void StorageDownloadingPolicy::ScheduleRetry(storage::CountriesSet const & failedCountries, TProcessFunc const & func)
|
||||
{
|
||||
if (IsDownloadingAllowed() && !failedCountries.empty() && m_autoRetryCounter > 0)
|
||||
{
|
||||
m_downloadRetryFailed = false;
|
||||
auto action = [this, func, failedCountries] {
|
||||
auto action = [this, func, failedCountries]
|
||||
{
|
||||
--m_autoRetryCounter;
|
||||
func(failedCountries);
|
||||
};
|
||||
m_autoRetryWorker.RestartWith([action]{ GetPlatform().RunTask(Platform::Thread::Gui, action); });
|
||||
m_autoRetryWorker.RestartWith([action] { GetPlatform().RunTask(Platform::Thread::Gui, action); });
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -32,13 +32,9 @@ public:
|
||||
void EnableCellularDownload(bool enabled);
|
||||
bool IsCellularDownloadEnabled();
|
||||
|
||||
inline bool IsAutoRetryDownloadFailed() const
|
||||
{
|
||||
return m_downloadRetryFailed || m_autoRetryCounter == 0;
|
||||
}
|
||||
inline bool IsAutoRetryDownloadFailed() const { return m_downloadRetryFailed || m_autoRetryCounter == 0; }
|
||||
|
||||
// DownloadingPolicy overrides:
|
||||
bool IsDownloadingAllowed() override;
|
||||
void ScheduleRetry(storage::CountriesSet const & failedCountries,
|
||||
TProcessFunc const & func) override;
|
||||
void ScheduleRetry(storage::CountriesSet const & failedCountries, TProcessFunc const & func) override;
|
||||
};
|
||||
|
||||
@@ -18,8 +18,7 @@ namespace
|
||||
class ErrorHttpRequest : public downloader::HttpRequest
|
||||
{
|
||||
public:
|
||||
explicit ErrorHttpRequest(std::string const & filePath)
|
||||
: HttpRequest(Callback(), Callback()), m_filePath(filePath)
|
||||
explicit ErrorHttpRequest(std::string const & filePath) : HttpRequest(Callback(), Callback()), m_filePath(filePath)
|
||||
{
|
||||
m_status = downloader::DownloadStatus::Failed;
|
||||
}
|
||||
@@ -65,8 +64,7 @@ void HttpMapFilesDownloader::Download()
|
||||
queuedCountry.OnStartDownloading();
|
||||
|
||||
m_request.reset(downloader::HttpRequest::GetFile(
|
||||
urls, path, size,
|
||||
std::bind(&HttpMapFilesDownloader::OnMapFileDownloaded, this, queuedCountry, _1),
|
||||
urls, path, size, std::bind(&HttpMapFilesDownloader::OnMapFileDownloaded, this, queuedCountry, _1),
|
||||
std::bind(&HttpMapFilesDownloader::OnMapFileDownloadingProgress, this, queuedCountry, _1)));
|
||||
}
|
||||
else
|
||||
@@ -115,8 +113,7 @@ QueueInterface const & HttpMapFilesDownloader::GetQueue() const
|
||||
return m_queue;
|
||||
}
|
||||
|
||||
void HttpMapFilesDownloader::OnMapFileDownloaded(QueuedCountry const & queuedCountry,
|
||||
downloader::HttpRequest & request)
|
||||
void HttpMapFilesDownloader::OnMapFileDownloaded(QueuedCountry const & queuedCountry, downloader::HttpRequest & request)
|
||||
{
|
||||
CHECK_THREAD_CHECKER(m_checker, ());
|
||||
// Because this method is called deferred on original thread,
|
||||
|
||||
@@ -35,8 +35,7 @@ private:
|
||||
void Download();
|
||||
|
||||
void OnMapFileDownloaded(QueuedCountry const & queuedCountry, downloader::HttpRequest & request);
|
||||
void OnMapFileDownloadingProgress(QueuedCountry const & queuedCountry,
|
||||
downloader::HttpRequest & request);
|
||||
void OnMapFileDownloadingProgress(QueuedCountry const & queuedCountry, downloader::HttpRequest & request);
|
||||
|
||||
std::unique_ptr<downloader::HttpRequest> m_request;
|
||||
Queue m_queue;
|
||||
|
||||
@@ -4,11 +4,11 @@
|
||||
|
||||
#include "platform/downloader_utils.hpp"
|
||||
#include "platform/http_client.hpp"
|
||||
#include "platform/locale.hpp"
|
||||
#include "platform/platform.hpp"
|
||||
#include "platform/products.hpp"
|
||||
#include "platform/servers_list.hpp"
|
||||
#include "platform/settings.hpp"
|
||||
#include "platform/products.hpp"
|
||||
#include "platform/locale.hpp"
|
||||
|
||||
#include "coding/url.hpp"
|
||||
|
||||
@@ -31,10 +31,7 @@ void MapFilesDownloader::DownloadMapFile(QueuedCountry && queuedCountry)
|
||||
{
|
||||
RunMetaConfigAsync([this]()
|
||||
{
|
||||
m_pendingRequests.ForEachCountry([this](QueuedCountry & country)
|
||||
{
|
||||
Download(std::move(country));
|
||||
});
|
||||
m_pendingRequests.ForEachCountry([this](QueuedCountry & country) { Download(std::move(country)); });
|
||||
|
||||
m_pendingRequests.Clear();
|
||||
});
|
||||
@@ -76,7 +73,7 @@ QueueInterface const & MapFilesDownloader::GetQueue() const
|
||||
return m_pendingRequests;
|
||||
}
|
||||
|
||||
void MapFilesDownloader::DownloadAsString(std::string url, std::function<bool (std::string const &)> && callback,
|
||||
void MapFilesDownloader::DownloadAsString(std::string url, std::function<bool(std::string const &)> && callback,
|
||||
bool forceReset /* = false */)
|
||||
{
|
||||
EnsureMetaConfigReady([this, forceReset, url = std::move(url), callback = std::move(callback)]()
|
||||
@@ -86,24 +83,24 @@ void MapFilesDownloader::DownloadAsString(std::string url, std::function<bool (s
|
||||
|
||||
// Servers are sorted from best to worst.
|
||||
m_fileRequest.reset(RequestT::Get(url::Join(m_serversList.front(), url),
|
||||
[this, callback = std::move(callback)](RequestT & request)
|
||||
[this, callback = std::move(callback)](RequestT & request)
|
||||
{
|
||||
bool deleteRequest = true;
|
||||
|
||||
auto const & buffer = request.GetData();
|
||||
if (!buffer.empty())
|
||||
{
|
||||
bool deleteRequest = true;
|
||||
// Update deleteRequest flag if new download was requested in callback.
|
||||
deleteRequest = !callback(buffer);
|
||||
}
|
||||
|
||||
auto const & buffer = request.GetData();
|
||||
if (!buffer.empty())
|
||||
{
|
||||
// Update deleteRequest flag if new download was requested in callback.
|
||||
deleteRequest = !callback(buffer);
|
||||
}
|
||||
|
||||
if (deleteRequest)
|
||||
m_fileRequest.reset();
|
||||
}));
|
||||
if (deleteRequest)
|
||||
m_fileRequest.reset();
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
void MapFilesDownloader::EnsureMetaConfigReady(std::function<void ()> && callback)
|
||||
void MapFilesDownloader::EnsureMetaConfigReady(std::function<void()> && callback)
|
||||
{
|
||||
/// @todo Implement logic if m_metaConfig is "outdated".
|
||||
/// Fetch new servers list on each download request?
|
||||
@@ -171,7 +168,7 @@ MetaConfig MapFilesDownloader::LoadMetaConfig()
|
||||
request.SetRawHeader("X-OM-DataVersion", std::to_string(m_dataVersion));
|
||||
request.SetRawHeader("X-OM-AppVersion", pl.Version());
|
||||
request.SetRawHeader("Accept-Language", GetAcceptLanguage());
|
||||
request.SetTimeout(10.0); // timeout in seconds
|
||||
request.SetTimeout(10.0); // timeout in seconds
|
||||
request.RunHttpRequest(httpResult);
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ public:
|
||||
* @param[in] url Final url part like "index.json" or "maps/210415/countries.txt".
|
||||
* @param[in] forceReset True - force reset current request, if any.
|
||||
*/
|
||||
void DownloadAsString(std::string url, std::function<bool (std::string const &)> && callback, bool forceReset = false);
|
||||
void DownloadAsString(std::string url, std::function<bool(std::string const &)> && callback, bool forceReset = false);
|
||||
|
||||
// Used in tests only.
|
||||
void SetServersList(ServersList const & serversList);
|
||||
@@ -68,7 +68,7 @@ public:
|
||||
|
||||
/// @name Legacy functions for Android resources downloading routine (initial World download).
|
||||
/// @{
|
||||
void EnsureMetaConfigReady(std::function<void ()> && callback);
|
||||
void EnsureMetaConfigReady(std::function<void()> && callback);
|
||||
std::vector<std::string> MakeUrlListLegacy(std::string const & fileName) const;
|
||||
/// @}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace storage
|
||||
{
|
||||
void MapFilesDownloaderWithPing::GetMetaConfig(MetaConfigCallback const & callback)
|
||||
{
|
||||
ASSERT(callback , ());
|
||||
ASSERT(callback, ());
|
||||
|
||||
MetaConfig metaConfig = LoadMetaConfig();
|
||||
CHECK(!metaConfig.m_serversList.empty(), ());
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
|
||||
#include <chrono>
|
||||
|
||||
|
||||
namespace pinger
|
||||
{
|
||||
auto constexpr kTimeoutInSeconds = 4.0;
|
||||
@@ -35,12 +34,13 @@ int64_t DoPing(std::string const & url)
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(LWARNING, ("Ping to server", url, "failed with code =", request.ErrorCode(), "; wasRedirected =", request.WasRedirected()));
|
||||
LOG(LWARNING, ("Ping to server", url, "failed with code =", request.ErrorCode(),
|
||||
"; wasRedirected =", request.WasRedirected()));
|
||||
}
|
||||
|
||||
return kInvalidPing;
|
||||
}
|
||||
} // namespace pinger
|
||||
} // namespace pinger
|
||||
|
||||
namespace storage
|
||||
{
|
||||
@@ -55,25 +55,15 @@ Pinger::Endpoints Pinger::ExcludeUnavailableAndSortEndpoints(Endpoints const & u
|
||||
{
|
||||
base::DelayedThreadPool pool(size, base::DelayedThreadPool::Exit::ExecPending);
|
||||
for (size_t i = 0; i < size; ++i)
|
||||
{
|
||||
pool.Push([&urls, &timeUrls, i]
|
||||
{
|
||||
timeUrls[i] = { pinger::DoPing(urls[i]), i };
|
||||
});
|
||||
}
|
||||
pool.Push([&urls, &timeUrls, i] { timeUrls[i] = {pinger::DoPing(urls[i]), i}; });
|
||||
}
|
||||
|
||||
std::sort(timeUrls.begin(), timeUrls.end(), [](EntryT const & e1, EntryT const & e2)
|
||||
{
|
||||
return e1.first < e2.first;
|
||||
});
|
||||
std::sort(timeUrls.begin(), timeUrls.end(), [](EntryT const & e1, EntryT const & e2) { return e1.first < e2.first; });
|
||||
|
||||
Endpoints readyUrls;
|
||||
for (auto const & [ping, index] : timeUrls)
|
||||
{
|
||||
if (ping >= 0)
|
||||
readyUrls.push_back(urls[index]);
|
||||
}
|
||||
|
||||
return readyUrls;
|
||||
}
|
||||
|
||||
@@ -9,9 +9,8 @@
|
||||
|
||||
namespace storage
|
||||
{
|
||||
QueuedCountry::QueuedCountry(platform::CountryFile const & countryFile, CountryId const & countryId,
|
||||
MapFileType type, int64_t currentDataVersion,
|
||||
std::string const & dataDir,
|
||||
QueuedCountry::QueuedCountry(platform::CountryFile const & countryFile, CountryId const & countryId, MapFileType type,
|
||||
int64_t currentDataVersion, std::string const & dataDir,
|
||||
diffs::DiffsSourcePtr const & diffs)
|
||||
: m_countryFile(countryFile)
|
||||
, m_countryId(countryId)
|
||||
|
||||
@@ -22,13 +22,13 @@ public:
|
||||
virtual void OnStartDownloading(QueuedCountry const & queuedCountry) = 0;
|
||||
virtual void OnDownloadProgress(QueuedCountry const & queuedCountry, downloader::Progress const & progress) = 0;
|
||||
virtual void OnDownloadFinished(QueuedCountry const & queuedCountry, downloader::DownloadStatus status) = 0;
|
||||
|
||||
protected:
|
||||
virtual ~Subscriber() = default;
|
||||
};
|
||||
|
||||
QueuedCountry(platform::CountryFile const & countryFile, CountryId const & m_countryId,
|
||||
MapFileType type, int64_t currentDataVersion, std::string const & dataDir,
|
||||
diffs::DiffsSourcePtr const & diffs);
|
||||
QueuedCountry(platform::CountryFile const & countryFile, CountryId const & m_countryId, MapFileType type,
|
||||
int64_t currentDataVersion, std::string const & dataDir, diffs::DiffsSourcePtr const & diffs);
|
||||
|
||||
void Subscribe(Subscriber & subscriber);
|
||||
void Unsubscribe();
|
||||
|
||||
@@ -3,12 +3,13 @@
|
||||
namespace routing
|
||||
{
|
||||
|
||||
std::unique_ptr<m4::Tree<routing::NumMwmId>> MakeNumMwmTree(
|
||||
NumMwmIds const & numMwmIds, storage::CountryInfoGetter const & countryInfoGetter)
|
||||
std::unique_ptr<m4::Tree<routing::NumMwmId>> MakeNumMwmTree(NumMwmIds const & numMwmIds,
|
||||
storage::CountryInfoGetter const & countryInfoGetter)
|
||||
{
|
||||
auto tree = std::make_unique<m4::Tree<NumMwmId>>();
|
||||
|
||||
numMwmIds.ForEachId([&](NumMwmId numMwmId) {
|
||||
numMwmIds.ForEachId([&](NumMwmId numMwmId)
|
||||
{
|
||||
auto const & countryName = numMwmIds.GetFile(numMwmId).GetName();
|
||||
tree->Add(numMwmId, countryInfoGetter.GetLimitRectForLeaf(countryName));
|
||||
});
|
||||
@@ -19,11 +20,8 @@ std::unique_ptr<m4::Tree<routing::NumMwmId>> MakeNumMwmTree(
|
||||
std::shared_ptr<routing::NumMwmIds> CreateNumMwmIds(storage::Storage const & storage)
|
||||
{
|
||||
auto numMwmIds = std::make_shared<routing::NumMwmIds>();
|
||||
storage.ForEachCountry([&](storage::Country const & country)
|
||||
{
|
||||
numMwmIds->RegisterFile(country.GetFile());
|
||||
});
|
||||
storage.ForEachCountry([&](storage::Country const & country) { numMwmIds->RegisterFile(country.GetFile()); });
|
||||
return numMwmIds;
|
||||
}
|
||||
|
||||
} // namespace routing
|
||||
} // namespace routing
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
namespace routing
|
||||
{
|
||||
std::unique_ptr<m4::Tree<routing::NumMwmId>> MakeNumMwmTree(
|
||||
NumMwmIds const & numMwmIds, storage::CountryInfoGetter const & countryInfoGetter);
|
||||
std::unique_ptr<m4::Tree<routing::NumMwmId>> MakeNumMwmTree(NumMwmIds const & numMwmIds,
|
||||
storage::CountryInfoGetter const & countryInfoGetter);
|
||||
std::shared_ptr<NumMwmIds> CreateNumMwmIds(storage::Storage const & storage);
|
||||
} // namespace routing
|
||||
} // namespace routing
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include "storage/country_tree_helpers.hpp"
|
||||
#include "storage/diff_scheme/apply_diff.hpp"
|
||||
//#include "storage/diff_scheme/diff_scheme_loader.hpp"
|
||||
// #include "storage/diff_scheme/diff_scheme_loader.hpp"
|
||||
#include "storage/downloader.hpp"
|
||||
#include "storage/map_files_downloader.hpp"
|
||||
#include "storage/storage_helpers.hpp"
|
||||
@@ -43,7 +43,6 @@ namespace
|
||||
{
|
||||
string const kDownloadQueueKey = "DownloadQueue";
|
||||
|
||||
|
||||
// Editing maps older than approximately three months old is disabled, since the data
|
||||
// is most likely already fixed on OSM. Not limited to the latest one or two versions,
|
||||
// because a user can forget to update maps after a new app version has been installed
|
||||
@@ -64,8 +63,7 @@ void DeleteFromDiskWithIndexes(LocalCountryFile const & localFile, MapFileType t
|
||||
localFile.DeleteFromDisk(type);
|
||||
}
|
||||
|
||||
CountryTree::Node const & LeafNodeFromCountryId(CountryTree const & root,
|
||||
CountryId const & countryId)
|
||||
CountryTree::Node const & LeafNodeFromCountryId(CountryTree const & root, CountryId const & countryId)
|
||||
{
|
||||
CountryTree::Node const * node = root.FindFirstLeaf(countryId);
|
||||
CHECK(node, ("Node with id =", countryId, "not found in country tree as a leaf."));
|
||||
@@ -97,10 +95,7 @@ bool IsFileDownloaded(string const fileDownloadPath, MapFileType type)
|
||||
CountriesSet GetQueuedCountries(QueueInterface const & queue)
|
||||
{
|
||||
CountriesSet result;
|
||||
queue.ForEachCountry([&result](QueuedCountry const & country)
|
||||
{
|
||||
result.insert(country.GetCountryId());
|
||||
});
|
||||
queue.ForEachCountry([&result](QueuedCountry const & country) { result.insert(country.GetCountryId()); });
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -129,8 +124,7 @@ Storage::Storage(int)
|
||||
// Do nothing here, used in RunCountriesCheckAsync() only.
|
||||
}
|
||||
|
||||
Storage::Storage(string const & pathToCountriesFile /* = COUNTRIES_FILE */,
|
||||
string const & dataDir /* = string() */)
|
||||
Storage::Storage(string const & pathToCountriesFile /* = COUNTRIES_FILE */, string const & dataDir /* = string() */)
|
||||
: m_downloader(GetDownloader())
|
||||
, m_dataDir(dataDir)
|
||||
{
|
||||
@@ -148,9 +142,8 @@ Storage::Storage(string const & referenceCountriesTxtJsonForTesting,
|
||||
{
|
||||
m_downloader->SetDownloadingPolicy(m_downloadingPolicy);
|
||||
|
||||
m_currentVersion =
|
||||
LoadCountriesFromBuffer(referenceCountriesTxtJsonForTesting, m_countries, m_affiliations,
|
||||
m_countryNameSynonyms, m_mwmTopCityGeoIds, m_mwmTopCountryGeoIds);
|
||||
m_currentVersion = LoadCountriesFromBuffer(referenceCountriesTxtJsonForTesting, m_countries, m_affiliations,
|
||||
m_countryNameSynonyms, m_mwmTopCityGeoIds, m_mwmTopCountryGeoIds);
|
||||
CHECK_LESS_OR_EQUAL(0, m_currentVersion, ("Can't load test countries file"));
|
||||
|
||||
m_downloader->SetDataVersion(m_currentVersion);
|
||||
@@ -213,8 +206,8 @@ Storage::WorldStatus Storage::GetForceDownloadWorlds(std::vector<platform::Count
|
||||
{
|
||||
CHECK_THREAD_CHECKER(m_threadChecker, ());
|
||||
|
||||
bool hasWorld[] = { false, false };
|
||||
string const worldName[] = { WORLD_FILE_NAME, WORLD_COASTS_FILE_NAME };
|
||||
bool hasWorld[] = {false, false};
|
||||
string const worldName[] = {WORLD_FILE_NAME, WORLD_COASTS_FILE_NAME};
|
||||
|
||||
{
|
||||
// Check if Worlds already present.
|
||||
@@ -223,10 +216,8 @@ Storage::WorldStatus Storage::GetForceDownloadWorlds(std::vector<platform::Count
|
||||
for (auto const & f : localFiles)
|
||||
{
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
if (f.GetCountryName() == worldName[i])
|
||||
hasWorld[i] = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (hasWorld[0] && hasWorld[1])
|
||||
@@ -238,8 +229,8 @@ Storage::WorldStatus Storage::GetForceDownloadWorlds(std::vector<platform::Count
|
||||
// Parse root data folder (we stored Worlds here in older versions).
|
||||
// Note that m_dataDir maybe empty and we take Platform::WritableDir.
|
||||
std::vector<platform::LocalCountryFile> rootFiles;
|
||||
(void)FindAllLocalMapsInDirectoryAndCleanup(m_dataDir.empty() ? pl.WritableDir() : m_dataDir,
|
||||
0 /* version */, -1 /* latestVersion */, rootFiles);
|
||||
(void)FindAllLocalMapsInDirectoryAndCleanup(m_dataDir.empty() ? pl.WritableDir() : m_dataDir, 0 /* version */,
|
||||
-1 /* latestVersion */, rootFiles);
|
||||
|
||||
bool anyWorldWasMoved = false;
|
||||
for (auto const & f : rootFiles)
|
||||
@@ -283,18 +274,16 @@ Storage::WorldStatus Storage::GetForceDownloadWorlds(std::vector<platform::Count
|
||||
return WorldStatus::ERROR_CREATE_FOLDER;
|
||||
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
if (!hasWorld[i])
|
||||
res.push_back(GetCountryFile(worldName[i]));
|
||||
}
|
||||
|
||||
return (anyWorldWasMoved && res.empty() ? WorldStatus::WAS_MOVED : WorldStatus::READY);
|
||||
}
|
||||
|
||||
void Storage::RegisterAllLocalMaps(bool enableDiffs /* = false */)
|
||||
{
|
||||
//CHECK_THREAD_CHECKER(m_threadChecker, ());
|
||||
//ASSERT(!IsDownloadInProgress(), ());
|
||||
// CHECK_THREAD_CHECKER(m_threadChecker, ());
|
||||
// ASSERT(!IsDownloadInProgress(), ());
|
||||
|
||||
m_localFiles.clear();
|
||||
m_localFilesForFakeCountries.clear();
|
||||
@@ -329,13 +318,13 @@ void Storage::RegisterAllLocalMaps(bool enableDiffs /* = false */)
|
||||
}
|
||||
|
||||
FindAllDiffs(m_dataDir, m_notAppliedDiffs);
|
||||
//if (enableDiffs)
|
||||
// LoadDiffScheme();
|
||||
// if (enableDiffs)
|
||||
// LoadDiffScheme();
|
||||
}
|
||||
|
||||
void Storage::GetLocalMaps(vector<LocalFilePtr> & maps) const
|
||||
{
|
||||
//CHECK_THREAD_CHECKER(m_threadChecker, ());
|
||||
// CHECK_THREAD_CHECKER(m_threadChecker, ());
|
||||
|
||||
for (auto const & p : m_localFiles)
|
||||
maps.push_back(GetLatestLocalFile(p.first));
|
||||
@@ -430,7 +419,7 @@ LocalFilePtr Storage::GetLatestLocalFile(CountryFile const & countryFile) const
|
||||
|
||||
LocalFilePtr Storage::GetLatestLocalFile(CountryId const & countryId) const
|
||||
{
|
||||
//CHECK_THREAD_CHECKER(m_threadChecker, ());
|
||||
// CHECK_THREAD_CHECKER(m_threadChecker, ());
|
||||
|
||||
auto const it = m_localFiles.find(countryId);
|
||||
if (it == m_localFiles.end() || it->second.empty())
|
||||
@@ -439,10 +428,8 @@ LocalFilePtr Storage::GetLatestLocalFile(CountryId const & countryId) const
|
||||
list<LocalFilePtr> const & files = it->second;
|
||||
LocalFilePtr latest = files.front();
|
||||
for (LocalFilePtr const & file : files)
|
||||
{
|
||||
if (file->GetVersion() > latest->GetVersion())
|
||||
latest = file;
|
||||
}
|
||||
return latest;
|
||||
}
|
||||
|
||||
@@ -494,9 +481,7 @@ void Storage::SaveDownloadQueue()
|
||||
|
||||
ostringstream ss;
|
||||
m_downloader->GetQueue().ForEachCountry([&ss](QueuedCountry const & country)
|
||||
{
|
||||
ss << (ss.str().empty() ? "" : ";") << country.GetCountryId();
|
||||
});
|
||||
{ ss << (ss.str().empty() ? "" : ";") << country.GetCountryId(); });
|
||||
|
||||
settings::Set(kDownloadQueueKey, ss.str());
|
||||
}
|
||||
@@ -510,10 +495,8 @@ void Storage::RestoreDownloadQueue()
|
||||
|
||||
strings::Tokenize(download, ";", [this](string_view v)
|
||||
{
|
||||
auto const it = base::FindIf(m_notAppliedDiffs, [this, v](LocalCountryFile const & localDiff)
|
||||
{
|
||||
return v == FindCountryId(localDiff);
|
||||
});
|
||||
auto const it = base::FindIf(
|
||||
m_notAppliedDiffs, [this, v](LocalCountryFile const & localDiff) { return v == FindCountryId(localDiff); });
|
||||
|
||||
if (it == m_notAppliedDiffs.end())
|
||||
{
|
||||
@@ -549,8 +532,7 @@ void Storage::DownloadCountry(CountryId const & countryId, MapFileType type)
|
||||
return;
|
||||
}
|
||||
|
||||
QueuedCountry queuedCountry(countryFile, countryId, type, m_currentVersion, m_dataDir,
|
||||
m_diffsDataSource);
|
||||
QueuedCountry queuedCountry(countryFile, countryId, type, m_currentVersion, m_dataDir, m_diffsDataSource);
|
||||
queuedCountry.Subscribe(*this);
|
||||
|
||||
m_downloader->DownloadMapFile(std::move(queuedCountry));
|
||||
@@ -607,10 +589,8 @@ void Storage::NotifyStatusChangedForHierarchy(CountryId const & countryId)
|
||||
NotifyStatusChanged(countryId);
|
||||
|
||||
// Notification status changing for ancestors in country tree.
|
||||
ForEachAncestorExceptForTheRoot(countryId,
|
||||
[&](CountryId const & parentId, CountryTree::Node const &) {
|
||||
NotifyStatusChanged(parentId);
|
||||
});
|
||||
ForEachAncestorExceptForTheRoot(
|
||||
countryId, [&](CountryId const & parentId, CountryTree::Node const &) { NotifyStatusChanged(parentId); });
|
||||
}
|
||||
|
||||
bool Storage::IsDownloadInProgress() const
|
||||
@@ -624,9 +604,8 @@ void Storage::LoadCountriesFile(string const & pathToCountriesFile)
|
||||
{
|
||||
if (m_countries.IsEmpty())
|
||||
{
|
||||
m_currentVersion =
|
||||
LoadCountriesFromFile(pathToCountriesFile, m_countries, m_affiliations,
|
||||
m_countryNameSynonyms, m_mwmTopCityGeoIds, m_mwmTopCountryGeoIds);
|
||||
m_currentVersion = LoadCountriesFromFile(pathToCountriesFile, m_countries, m_affiliations, m_countryNameSynonyms,
|
||||
m_mwmTopCityGeoIds, m_mwmTopCountryGeoIds);
|
||||
LOG(LINFO, ("Loaded countries list for version:", m_currentVersion));
|
||||
if (m_currentVersion < 0)
|
||||
LOG(LERROR, ("Can't load countries file", pathToCountriesFile));
|
||||
@@ -638,7 +617,7 @@ int Storage::Subscribe(ChangeCountryFunction change, ProgressFunction progress)
|
||||
CHECK_THREAD_CHECKER(m_threadChecker, ());
|
||||
|
||||
int const id = ++m_currentSlotId;
|
||||
m_observers.push_back({ std::move(change), std::move(progress), id });
|
||||
m_observers.push_back({std::move(change), std::move(progress), id});
|
||||
return id;
|
||||
}
|
||||
|
||||
@@ -668,11 +647,11 @@ void Storage::ReportProgressForHierarchy(CountryId const & countryId, Progress c
|
||||
// Reporting progress for a leaf in country tree.
|
||||
ReportProgress(countryId, leafProgress);
|
||||
|
||||
auto calcProgress = [&](CountryId const & parentId, CountryTree::Node const & parentNode) {
|
||||
auto calcProgress = [&](CountryId const & parentId, CountryTree::Node const & parentNode)
|
||||
{
|
||||
CountriesVec descendants;
|
||||
parentNode.ForEachDescendant([&descendants](CountryTree::Node const & container) {
|
||||
descendants.push_back(container.Value().Name());
|
||||
});
|
||||
parentNode.ForEachDescendant([&descendants](CountryTree::Node const & container)
|
||||
{ descendants.push_back(container.Value().Name()); });
|
||||
|
||||
Progress localAndRemoteBytes = CalculateProgress(descendants);
|
||||
ReportProgress(parentId, localAndRemoteBytes);
|
||||
@@ -721,7 +700,7 @@ void Storage::OnDownloadFinished(QueuedCountry const & queuedCountry, DownloadSt
|
||||
|
||||
auto const & countryId = queuedCountry.GetCountryId();
|
||||
auto const fileType = queuedCountry.GetFileType();
|
||||
auto const finishFn = [this, countryId, fileType] (DownloadStatus status)
|
||||
auto const finishFn = [this, countryId, fileType](DownloadStatus status)
|
||||
{
|
||||
OnMapDownloadFinished(countryId, status, fileType);
|
||||
OnFinishDownloading();
|
||||
@@ -734,9 +713,9 @@ void Storage::OnDownloadFinished(QueuedCountry const & queuedCountry, DownloadSt
|
||||
/// should make this kind of checks (taking expecting SHA as input). But now it's
|
||||
/// not so simple as it may seem ..
|
||||
|
||||
GetPlatform().RunTask(Platform::Thread::File, [path = GetFileDownloadPath(countryId, fileType),
|
||||
sha1 = GetCountryFile(countryId).GetSha1(),
|
||||
fn = std::move(finishFn)]()
|
||||
GetPlatform().RunTask(Platform::Thread::File,
|
||||
[path = GetFileDownloadPath(countryId, fileType), sha1 = GetCountryFile(countryId).GetSha1(),
|
||||
fn = std::move(finishFn)]()
|
||||
{
|
||||
DownloadStatus status = DownloadStatus::Completed;
|
||||
|
||||
@@ -764,7 +743,8 @@ void Storage::RegisterDownloadedFiles(CountryId const & countryId, MapFileType t
|
||||
{
|
||||
CHECK_THREAD_CHECKER(m_threadChecker, ());
|
||||
|
||||
auto const fn = [this, countryId, type](bool isSuccess) {
|
||||
auto const fn = [this, countryId, type](bool isSuccess)
|
||||
{
|
||||
CHECK_THREAD_CHECKER(m_threadChecker, ());
|
||||
|
||||
LOG(LINFO, ("Registering downloaded file:", countryId, type, "; success:", isSuccess));
|
||||
@@ -829,8 +809,7 @@ void Storage::RegisterDownloadedFiles(CountryId const & countryId, MapFileType t
|
||||
fn(true);
|
||||
}
|
||||
|
||||
void Storage::OnMapDownloadFinished(CountryId const & countryId, DownloadStatus status,
|
||||
MapFileType type)
|
||||
void Storage::OnMapDownloadFinished(CountryId const & countryId, DownloadStatus status, MapFileType type)
|
||||
{
|
||||
CHECK_THREAD_CHECKER(m_threadChecker, ());
|
||||
ASSERT(m_didDownload != nullptr, ("Storage::Init wasn't called"));
|
||||
@@ -915,10 +894,8 @@ LocalFilePtr Storage::GetLocalFile(CountryId const & countryId, int64_t version)
|
||||
return LocalFilePtr();
|
||||
|
||||
for (auto const & file : it->second)
|
||||
{
|
||||
if (file->GetVersion() == version)
|
||||
return file;
|
||||
}
|
||||
return LocalFilePtr();
|
||||
}
|
||||
|
||||
@@ -930,14 +907,10 @@ void Storage::RegisterCountryFiles(LocalFilePtr localFile)
|
||||
CountryId const & countryId = FindCountryId(*localFile);
|
||||
LocalFilePtr existingFile = GetLocalFile(countryId, localFile->GetVersion());
|
||||
if (existingFile)
|
||||
{
|
||||
if (existingFile->IsInBundle())
|
||||
*existingFile = *localFile;
|
||||
else
|
||||
{
|
||||
ASSERT_EQUAL(localFile.get(), existingFile.get(), ());
|
||||
}
|
||||
}
|
||||
else
|
||||
m_localFiles[countryId].push_front(localFile);
|
||||
}
|
||||
@@ -1025,10 +998,8 @@ string Storage::GetFileDownloadPath(CountryId const & countryId, MapFileType typ
|
||||
bool Storage::CheckFailedCountries(CountriesVec const & countries) const
|
||||
{
|
||||
for (auto const & country : countries)
|
||||
{
|
||||
if (m_failedCountries.count(country))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1045,27 +1016,26 @@ void Storage::RunCountriesCheckAsync()
|
||||
LOG(LDEBUG, ("Try download", COUNTRIES_FILE, "for", dataVersion));
|
||||
|
||||
m_downloader->DownloadAsString(downloader::GetFileDownloadUrl(COUNTRIES_FILE, dataVersion),
|
||||
[this, dataVersion](std::string const & buffer)
|
||||
[this, dataVersion](std::string const & buffer)
|
||||
{
|
||||
LOG(LDEBUG, (COUNTRIES_FILE, "downloaded"));
|
||||
|
||||
std::shared_ptr<Storage> storage(new Storage(7 /* dummy */));
|
||||
storage->m_currentVersion =
|
||||
LoadCountriesFromBuffer(buffer, storage->m_countries, storage->m_affiliations, storage->m_countryNameSynonyms,
|
||||
storage->m_mwmTopCityGeoIds, storage->m_mwmTopCountryGeoIds);
|
||||
if (storage->m_currentVersion > 0)
|
||||
{
|
||||
LOG(LDEBUG, (COUNTRIES_FILE, "downloaded"));
|
||||
LOG(LDEBUG, ("Apply new version", storage->m_currentVersion, dataVersion));
|
||||
ASSERT_EQUAL(storage->m_currentVersion, dataVersion, ());
|
||||
|
||||
std::shared_ptr<Storage> storage(new Storage(7 /* dummy */));
|
||||
storage->m_currentVersion = LoadCountriesFromBuffer(buffer, storage->m_countries, storage->m_affiliations, storage->m_countryNameSynonyms,
|
||||
storage->m_mwmTopCityGeoIds, storage->m_mwmTopCountryGeoIds);
|
||||
if (storage->m_currentVersion > 0)
|
||||
{
|
||||
LOG(LDEBUG, ("Apply new version", storage->m_currentVersion, dataVersion));
|
||||
ASSERT_EQUAL(storage->m_currentVersion, dataVersion, ());
|
||||
/// @todo Or use simple but reliable strategy: download new file and ask to restart the app?
|
||||
GetPlatform().RunTask(Platform::Thread::Gui,
|
||||
[this, storage, buffer = std::move(buffer)]() { ApplyCountries(buffer, *storage); });
|
||||
}
|
||||
|
||||
/// @todo Or use simple but reliable strategy: download new file and ask to restart the app?
|
||||
GetPlatform().RunTask(Platform::Thread::Gui, [this, storage, buffer = std::move(buffer)]()
|
||||
{
|
||||
ApplyCountries(buffer, *storage);
|
||||
});
|
||||
}
|
||||
|
||||
return false;
|
||||
}, true /* force reset */);
|
||||
return false;
|
||||
}, true /* force reset */);
|
||||
|
||||
// True when new download was requested.
|
||||
return true;
|
||||
@@ -1137,14 +1107,14 @@ void Storage::ApplyCountries(std::string const & countriesBuffer, Storage & stor
|
||||
/// @todo The best way is to restart the app after ApplyCountries.
|
||||
// Do not to update this information containers to avoid possible races.
|
||||
// Affiliations, synonyms, etc can be updated with the app update.
|
||||
//m_affiliations = std::move(storage.m_affiliations);
|
||||
//m_countryNameSynonyms = std::move(storage.m_countryNameSynonyms);
|
||||
//m_mwmTopCityGeoIds = std::move(storage.m_mwmTopCityGeoIds);
|
||||
//m_mwmTopCountryGeoIds = std::move(storage.m_mwmTopCountryGeoIds);
|
||||
// m_affiliations = std::move(storage.m_affiliations);
|
||||
// m_countryNameSynonyms = std::move(storage.m_countryNameSynonyms);
|
||||
// m_mwmTopCityGeoIds = std::move(storage.m_mwmTopCityGeoIds);
|
||||
// m_mwmTopCountryGeoIds = std::move(storage.m_mwmTopCountryGeoIds);
|
||||
|
||||
LOG(LDEBUG, ("Version", m_currentVersion, "is applied"));
|
||||
|
||||
//LoadDiffScheme();
|
||||
// LoadDiffScheme();
|
||||
|
||||
/// @todo Start World and WorldCoasts download ?!
|
||||
}
|
||||
@@ -1219,8 +1189,8 @@ void Storage::GetChildrenInGroups(CountryId const & parent, CountriesVec & downl
|
||||
}
|
||||
|
||||
vector<pair<CountryId, NodeStatus>> disputedTerritoriesAndStatus;
|
||||
StatusAndError const childStatus = GetNodeStatusInfo(childNode, disputedTerritoriesAndStatus,
|
||||
true /* isDisputedTerritoriesCounted */);
|
||||
StatusAndError const childStatus =
|
||||
GetNodeStatusInfo(childNode, disputedTerritoriesAndStatus, true /* isDisputedTerritoriesCounted */);
|
||||
|
||||
ASSERT_NOT_EQUAL(childStatus.status, NodeStatus::Undefined, ());
|
||||
for (auto const & disputed : disputedTerritoriesAndStatus)
|
||||
@@ -1230,10 +1200,8 @@ void Storage::GetChildrenInGroups(CountryId const & parent, CountriesVec & downl
|
||||
{
|
||||
availChildren.push_back(childValue);
|
||||
for (auto const & disputed : disputedTerritoriesAndStatus)
|
||||
{
|
||||
if (disputed.second != NodeStatus::NotDownloaded)
|
||||
disputedTerritoriesWithoutSiblings.push_back(disputed.first);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1243,8 +1211,7 @@ void Storage::GetChildrenInGroups(CountryId const & parent, CountriesVec & downl
|
||||
}
|
||||
});
|
||||
|
||||
CountriesVec uniqueDisputed(disputedTerritoriesWithoutSiblings.begin(),
|
||||
disputedTerritoriesWithoutSiblings.end());
|
||||
CountriesVec uniqueDisputed(disputedTerritoriesWithoutSiblings.begin(), disputedTerritoriesWithoutSiblings.end());
|
||||
base::SortUnique(uniqueDisputed);
|
||||
|
||||
for (auto const & countryId : uniqueDisputed)
|
||||
@@ -1253,8 +1220,7 @@ void Storage::GetChildrenInGroups(CountryId const & parent, CountriesVec & downl
|
||||
// |parent|
|
||||
// is equal to the number of disputed territories with out downloaded sibling
|
||||
// with |countryId| in subtree with root == |parent|.
|
||||
if (count(disputedTerritoriesWithoutSiblings.begin(), disputedTerritoriesWithoutSiblings.end(),
|
||||
countryId) ==
|
||||
if (count(disputedTerritoriesWithoutSiblings.begin(), disputedTerritoriesWithoutSiblings.end(), countryId) ==
|
||||
count(allDisputedTerritories.begin(), allDisputedTerritories.end(), countryId))
|
||||
{
|
||||
// |countryId| is downloaded without any other map in its group.
|
||||
@@ -1282,17 +1248,17 @@ bool Storage::IsAllowedToEditVersion(CountryId const & countryId) const
|
||||
auto const status = CountryStatusEx(countryId);
|
||||
switch (status)
|
||||
{
|
||||
case Status::OnDisk: return true;
|
||||
case Status::OnDiskOutOfDate:
|
||||
{
|
||||
auto const localFile = GetLatestLocalFile(countryId);
|
||||
ASSERT(localFile, ("Local file shouldn't be nullptr."));
|
||||
auto const currentVersionTime = base::YYMMDDToSecondsSinceEpoch(static_cast<uint32_t>(m_currentVersion));
|
||||
auto const localVersionTime = base::YYMMDDToSecondsSinceEpoch(static_cast<uint32_t>(localFile->GetVersion()));
|
||||
return currentVersionTime - localVersionTime < kMaxSecondsTillLastVersionUpdate &&
|
||||
base::SecondsSinceEpoch() - localVersionTime < kMaxSecondsTillNoEdits;
|
||||
}
|
||||
default: return false;
|
||||
case Status::OnDisk: return true;
|
||||
case Status::OnDiskOutOfDate:
|
||||
{
|
||||
auto const localFile = GetLatestLocalFile(countryId);
|
||||
ASSERT(localFile, ("Local file shouldn't be nullptr."));
|
||||
auto const currentVersionTime = base::YYMMDDToSecondsSinceEpoch(static_cast<uint32_t>(m_currentVersion));
|
||||
auto const localVersionTime = base::YYMMDDToSecondsSinceEpoch(static_cast<uint32_t>(localFile->GetVersion()));
|
||||
return currentVersionTime - localVersionTime < kMaxSecondsTillLastVersionUpdate &&
|
||||
base::SecondsSinceEpoch() - localVersionTime < kMaxSecondsTillNoEdits;
|
||||
}
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1321,15 +1287,12 @@ void Storage::DownloadNode(CountryId const & countryId, bool isUpdate /* = false
|
||||
if (GetNodeStatus(*node).status == NodeStatus::OnDisk)
|
||||
return;
|
||||
|
||||
auto downloadAction = [this, isUpdate](CountryTree::Node const & descendantNode) {
|
||||
if (descendantNode.ChildrenCount() == 0 &&
|
||||
GetNodeStatus(descendantNode).status != NodeStatus::OnDisk)
|
||||
auto downloadAction = [this, isUpdate](CountryTree::Node const & descendantNode)
|
||||
{
|
||||
if (descendantNode.ChildrenCount() == 0 && GetNodeStatus(descendantNode).status != NodeStatus::OnDisk)
|
||||
{
|
||||
auto const countryId = descendantNode.Value().Name();
|
||||
auto const fileType =
|
||||
isUpdate && m_diffsDataSource->HasDiffFor(countryId)
|
||||
? MapFileType::Diff
|
||||
: MapFileType::Map;
|
||||
auto const fileType = isUpdate && m_diffsDataSource->HasDiffFor(countryId) ? MapFileType::Diff : MapFileType::Map;
|
||||
|
||||
DownloadCountry(countryId, fileType);
|
||||
}
|
||||
@@ -1418,8 +1381,7 @@ void Storage::ApplyDiff(CountryId const & countryId, function<void(bool isSucces
|
||||
if (IsDiffApplyingInProgressToCountry(countryId))
|
||||
return;
|
||||
|
||||
auto const diffLocalFile = PreparePlaceForCountryFiles(m_currentVersion, m_dataDir,
|
||||
GetCountryFile(countryId));
|
||||
auto const diffLocalFile = PreparePlaceForCountryFiles(m_currentVersion, m_dataDir, GetCountryFile(countryId));
|
||||
uint64_t version;
|
||||
if (!diffLocalFile || !m_diffsDataSource->VersionFor(countryId, version))
|
||||
{
|
||||
@@ -1427,8 +1389,7 @@ void Storage::ApplyDiff(CountryId const & countryId, function<void(bool isSucces
|
||||
return;
|
||||
}
|
||||
|
||||
auto const emplaceResult =
|
||||
m_diffsBeingApplied.emplace(countryId, std::make_unique<base::Cancellable>());
|
||||
auto const emplaceResult = m_diffsBeingApplied.emplace(countryId, std::make_unique<base::Cancellable>());
|
||||
CHECK_EQUAL(emplaceResult.second, true, ());
|
||||
|
||||
NotifyStatusChangedForHierarchy(countryId);
|
||||
@@ -1439,48 +1400,46 @@ void Storage::ApplyDiff(CountryId const & countryId, function<void(bool isSucces
|
||||
params.m_oldMwmFile = GetLocalFile(countryId, version);
|
||||
|
||||
LocalFilePtr & diffFile = params.m_diffFile;
|
||||
diffs::ApplyDiff(
|
||||
std::move(params), *emplaceResult.first->second,
|
||||
[this, fn, countryId, diffFile](DiffApplicationResult result)
|
||||
{
|
||||
CHECK_THREAD_CHECKER(m_threadChecker, ());
|
||||
if (result == DiffApplicationResult::Ok && m_integrityValidationEnabled &&
|
||||
!diffFile->ValidateIntegrity())
|
||||
{
|
||||
GetPlatform().RunTask(Platform::Thread::File,
|
||||
[path = diffFile->GetPath(MapFileType::Map)] { base::DeleteFileX(path); });
|
||||
result = DiffApplicationResult::Failed;
|
||||
}
|
||||
diffs::ApplyDiff(std::move(params), *emplaceResult.first->second,
|
||||
[this, fn, countryId, diffFile](DiffApplicationResult result)
|
||||
{
|
||||
CHECK_THREAD_CHECKER(m_threadChecker, ());
|
||||
if (result == DiffApplicationResult::Ok && m_integrityValidationEnabled && !diffFile->ValidateIntegrity())
|
||||
{
|
||||
GetPlatform().RunTask(Platform::Thread::File,
|
||||
[path = diffFile->GetPath(MapFileType::Map)] { base::DeleteFileX(path); });
|
||||
result = DiffApplicationResult::Failed;
|
||||
}
|
||||
|
||||
if (m_diffsBeingApplied[countryId]->IsCancelled() && result == DiffApplicationResult::Ok)
|
||||
result = DiffApplicationResult::Cancelled;
|
||||
if (m_diffsBeingApplied[countryId]->IsCancelled() && result == DiffApplicationResult::Ok)
|
||||
result = DiffApplicationResult::Cancelled;
|
||||
|
||||
LOG(LINFO, ("Diff application result for", countryId, ":", result));
|
||||
LOG(LINFO, ("Diff application result for", countryId, ":", result));
|
||||
|
||||
m_diffsBeingApplied.erase(countryId);
|
||||
switch (result)
|
||||
{
|
||||
case DiffApplicationResult::Ok:
|
||||
{
|
||||
RegisterCountryFiles(diffFile);
|
||||
m_diffsDataSource->MarkAsApplied(countryId);
|
||||
fn(true);
|
||||
break;
|
||||
}
|
||||
case DiffApplicationResult::Cancelled:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case DiffApplicationResult::Failed:
|
||||
{
|
||||
m_diffsDataSource->RemoveDiffForCountry(countryId);
|
||||
fn(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
m_diffsBeingApplied.erase(countryId);
|
||||
switch (result)
|
||||
{
|
||||
case DiffApplicationResult::Ok:
|
||||
{
|
||||
RegisterCountryFiles(diffFile);
|
||||
m_diffsDataSource->MarkAsApplied(countryId);
|
||||
fn(true);
|
||||
break;
|
||||
}
|
||||
case DiffApplicationResult::Cancelled:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case DiffApplicationResult::Failed:
|
||||
{
|
||||
m_diffsDataSource->RemoveDiffForCountry(countryId);
|
||||
fn(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
OnFinishDownloading();
|
||||
});
|
||||
OnFinishDownloading();
|
||||
});
|
||||
}
|
||||
|
||||
void Storage::SetMapSchemeForCountriesWithAbsentDiffs(IsDiffAbsentForCountry const & isAbsent)
|
||||
@@ -1543,7 +1502,8 @@ void Storage::OnFinishDownloading()
|
||||
|
||||
m_justDownloaded.clear();
|
||||
|
||||
m_downloadingPolicy->ScheduleRetry(m_failedCountries, [this](CountriesSet const & needReload) {
|
||||
m_downloadingPolicy->ScheduleRetry(m_failedCountries, [this](CountriesSet const & needReload)
|
||||
{
|
||||
for (auto const & country : needReload)
|
||||
{
|
||||
NodeStatuses status;
|
||||
@@ -1558,10 +1518,7 @@ void Storage::OnDiffStatusReceived(diffs::NameDiffInfoMap && diffs)
|
||||
{
|
||||
m_diffsDataSource->SetDiffInfo(std::move(diffs));
|
||||
|
||||
SetMapSchemeForCountriesWithAbsentDiffs([this] (auto const & id)
|
||||
{
|
||||
return !m_diffsDataSource->HasDiffFor(id);
|
||||
});
|
||||
SetMapSchemeForCountriesWithAbsentDiffs([this](auto const & id) { return !m_diffsDataSource->HasDiffFor(id); });
|
||||
|
||||
if (m_diffsDataSource->GetStatus() == diffs::Status::NotAvailable)
|
||||
return;
|
||||
@@ -1596,9 +1553,9 @@ StatusAndError Storage::GetNodeStatusInfo(CountryTree::Node const & node,
|
||||
NodeStatus result = NodeStatus::NotDownloaded;
|
||||
bool allOnDisk = true;
|
||||
|
||||
auto groupStatusCalculator = [&](CountryTree::Node const & nodeInSubtree) {
|
||||
StatusAndError const statusAndError =
|
||||
ParseStatus(CountryStatusEx(nodeInSubtree.Value().Name()));
|
||||
auto groupStatusCalculator = [&](CountryTree::Node const & nodeInSubtree)
|
||||
{
|
||||
StatusAndError const statusAndError = ParseStatus(CountryStatusEx(nodeInSubtree.Value().Name()));
|
||||
|
||||
if (IsDisputed(nodeInSubtree) && isDisputedTerritoriesCounted)
|
||||
{
|
||||
@@ -1645,8 +1602,7 @@ void Storage::GetNodeAttrs(CountryId const & countryId, NodeAttrs & nodeAttrs) c
|
||||
nodeAttrs.m_status = statusAndErr.status;
|
||||
nodeAttrs.m_error = statusAndErr.error;
|
||||
nodeAttrs.m_nodeLocalName = m_countryNameGetter(countryId);
|
||||
nodeAttrs.m_nodeLocalDescription =
|
||||
m_countryNameGetter.Get(countryId + LOCALIZATION_DESCRIPTION_SUFFIX);
|
||||
nodeAttrs.m_nodeLocalDescription = m_countryNameGetter.Get(countryId + LOCALIZATION_DESCRIPTION_SUFFIX);
|
||||
|
||||
// Progress.
|
||||
if (nodeAttrs.m_status == NodeStatus::OnDisk)
|
||||
@@ -1659,8 +1615,7 @@ void Storage::GetNodeAttrs(CountryId const & countryId, NodeAttrs & nodeAttrs) c
|
||||
else
|
||||
{
|
||||
CountriesVec subtree;
|
||||
node->ForEachInSubtree(
|
||||
[&subtree](CountryTree::Node const & d) { subtree.push_back(d.Value().Name()); });
|
||||
node->ForEachInSubtree([&subtree](CountryTree::Node const & d) { subtree.push_back(d.Value().Name()); });
|
||||
|
||||
nodeAttrs.m_downloadingProgress = CalculateProgress(subtree);
|
||||
}
|
||||
@@ -1680,8 +1635,8 @@ void Storage::GetNodeAttrs(CountryId const & countryId, NodeAttrs & nodeAttrs) c
|
||||
// Downloading mwm information.
|
||||
StatusAndError const statusAndErr = GetNodeStatus(d);
|
||||
ASSERT_NOT_EQUAL(statusAndErr.status, NodeStatus::Undefined, ());
|
||||
if (statusAndErr.status != NodeStatus::NotDownloaded &&
|
||||
statusAndErr.status != NodeStatus::Partly && d.ChildrenCount() == 0)
|
||||
if (statusAndErr.status != NodeStatus::NotDownloaded && statusAndErr.status != NodeStatus::Partly &&
|
||||
d.ChildrenCount() == 0)
|
||||
{
|
||||
nodeAttrs.m_downloadingMwmCounter += 1;
|
||||
nodeAttrs.m_downloadingMwmSize += d.Value().GetSubtreeMwmSizeBytes();
|
||||
@@ -1713,11 +1668,11 @@ void Storage::GetNodeAttrs(CountryId const & countryId, NodeAttrs & nodeAttrs) c
|
||||
}
|
||||
// Parents country.
|
||||
nodeAttrs.m_topmostParentInfo.clear();
|
||||
ForEachAncestorExceptForTheRoot(
|
||||
nodes, [&](CountryId const & ancestorId, CountryTree::Node const & node) {
|
||||
if (node.Value().GetParent() == GetRootId())
|
||||
nodeAttrs.m_topmostParentInfo.push_back({ancestorId, m_countryNameGetter(ancestorId)});
|
||||
});
|
||||
ForEachAncestorExceptForTheRoot(nodes, [&](CountryId const & ancestorId, CountryTree::Node const & node)
|
||||
{
|
||||
if (node.Value().GetParent() == GetRootId())
|
||||
nodeAttrs.m_topmostParentInfo.push_back({ancestorId, m_countryNameGetter(ancestorId)});
|
||||
});
|
||||
}
|
||||
|
||||
void Storage::GetNodeStatuses(CountryId const & countryId, NodeStatuses & nodeStatuses) const
|
||||
@@ -1797,7 +1752,8 @@ void Storage::CancelDownloadNode(CountryId const & countryId)
|
||||
|
||||
auto const setQueue = GetQueuedCountries(m_downloader->GetQueue());
|
||||
|
||||
ForEachInSubtree(countryId, [&](CountryId const & descendantId, bool /* groupNode */) {
|
||||
ForEachInSubtree(countryId, [&](CountryId const & descendantId, bool /* groupNode */)
|
||||
{
|
||||
auto needNotify = false;
|
||||
if (setQueue.count(descendantId) != 0)
|
||||
needNotify = DeleteCountryFilesFromDownloader(descendantId);
|
||||
@@ -1814,7 +1770,8 @@ void Storage::CancelDownloadNode(CountryId const & countryId)
|
||||
|
||||
void Storage::RetryDownloadNode(CountryId const & countryId)
|
||||
{
|
||||
ForEachInSubtree(countryId, [this](CountryId const & descendantId, bool groupNode) {
|
||||
ForEachInSubtree(countryId, [this](CountryId const & descendantId, bool groupNode)
|
||||
{
|
||||
if (!groupNode && m_failedCountries.count(descendantId) != 0)
|
||||
{
|
||||
bool const isUpdateRequest = m_diffsDataSource->HasDiffFor(descendantId);
|
||||
@@ -1906,7 +1863,8 @@ void Storage::GetQueuedChildren(CountryId const & parent, CountriesVec & queuedC
|
||||
}
|
||||
|
||||
queuedChildren.clear();
|
||||
node->ForEachChild([&queuedChildren, this](CountryTree::Node const & child) {
|
||||
node->ForEachChild([&queuedChildren, this](CountryTree::Node const & child)
|
||||
{
|
||||
NodeStatus status = GetNodeStatus(child).status;
|
||||
ASSERT_NOT_EQUAL(status, NodeStatus::Undefined, ());
|
||||
if (status == NodeStatus::Downloading || status == NodeStatus::InQueue)
|
||||
@@ -1938,13 +1896,12 @@ void Storage::GetGroupNodePathToRoot(CountryId const & groupNode, CountriesVec &
|
||||
return;
|
||||
}
|
||||
|
||||
ForEachAncestorExceptForTheRoot(
|
||||
nodes, [&path](CountryId const & id, CountryTree::Node const &) { path.push_back(id); });
|
||||
ForEachAncestorExceptForTheRoot(nodes,
|
||||
[&path](CountryId const & id, CountryTree::Node const &) { path.push_back(id); });
|
||||
path.push_back(m_countries.GetRoot().Value().Name());
|
||||
}
|
||||
|
||||
void Storage::GetTopmostNodesFor(CountryId const & countryId, CountriesVec & nodes,
|
||||
size_t level) const
|
||||
void Storage::GetTopmostNodesFor(CountryId const & countryId, CountriesVec & nodes, size_t level) const
|
||||
{
|
||||
nodes.clear();
|
||||
|
||||
@@ -1962,8 +1919,7 @@ void Storage::GetTopmostNodesFor(CountryId const & countryId, CountriesVec & nod
|
||||
nodes[i] = countryId;
|
||||
CountriesVec path;
|
||||
ForEachAncestorExceptForTheRoot(
|
||||
{treeNodes[i]},
|
||||
[&path](CountryId const & id, CountryTree::Node const &) { path.emplace_back(id); });
|
||||
{treeNodes[i]}, [&path](CountryId const & id, CountryTree::Node const &) { path.emplace_back(id); });
|
||||
if (!path.empty() && level < path.size())
|
||||
nodes[i] = path[path.size() - 1 - level];
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
namespace storage_tests
|
||||
{
|
||||
struct UnitClass_StorageTest_DeleteCountry;
|
||||
} // storage_tests
|
||||
} // namespace storage_tests
|
||||
|
||||
namespace storage
|
||||
{
|
||||
@@ -47,9 +47,17 @@ struct CountryIdAndName
|
||||
/// It's applicable for expandable and not expandable node id.
|
||||
struct NodeAttrs
|
||||
{
|
||||
NodeAttrs() : m_mwmCounter(0), m_localMwmCounter(0), m_downloadingMwmCounter(0),
|
||||
m_mwmSize(0), m_localMwmSize(0), m_downloadingMwmSize(0),
|
||||
m_status(NodeStatus::Undefined), m_error(NodeErrorCode::NoError), m_present(false) {}
|
||||
NodeAttrs()
|
||||
: m_mwmCounter(0)
|
||||
, m_localMwmCounter(0)
|
||||
, m_downloadingMwmCounter(0)
|
||||
, m_mwmSize(0)
|
||||
, m_localMwmSize(0)
|
||||
, m_downloadingMwmSize(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)
|
||||
/// belonging to the node. If the node isn't expandable |m_mwmCounter| == 1.
|
||||
@@ -259,32 +267,28 @@ private:
|
||||
void LoadCountriesFile(std::string const & pathToCountriesFile);
|
||||
|
||||
void ReportProgress(CountryId const & countryId, downloader::Progress const & p);
|
||||
void ReportProgressForHierarchy(CountryId const & countryId,
|
||||
downloader::Progress const & leafProgress);
|
||||
void ReportProgressForHierarchy(CountryId const & countryId, downloader::Progress const & leafProgress);
|
||||
|
||||
// QueuedCountry::Subscriber overrides:
|
||||
void OnCountryInQueue(QueuedCountry const & queuedCountry) override;
|
||||
void OnStartDownloading(QueuedCountry const & queuedCountry) override;
|
||||
/// Called on the main thread by MapFilesDownloader when
|
||||
/// downloading of a map file succeeds/fails.
|
||||
void OnDownloadFinished(QueuedCountry const & queuedCountry,
|
||||
downloader::DownloadStatus status) override;
|
||||
void OnDownloadFinished(QueuedCountry const & queuedCountry, downloader::DownloadStatus status) override;
|
||||
|
||||
/// Periodically called on the main thread by MapFilesDownloader
|
||||
/// during the downloading process.
|
||||
void OnDownloadProgress(QueuedCountry const & queuedCountry,
|
||||
downloader::Progress const & progress) override;
|
||||
void OnDownloadProgress(QueuedCountry const & queuedCountry, downloader::Progress const & progress) override;
|
||||
|
||||
void RegisterDownloadedFiles(CountryId const & countryId, MapFileType type);
|
||||
|
||||
void OnMapDownloadFinished(CountryId const & countryId, downloader::DownloadStatus status,
|
||||
MapFileType type);
|
||||
void OnMapDownloadFinished(CountryId const & countryId, downloader::DownloadStatus status, MapFileType type);
|
||||
|
||||
/// Dummy ctor for private use only.
|
||||
explicit Storage(int);
|
||||
|
||||
public:
|
||||
ThreadChecker const & GetThreadChecker() const {return m_threadChecker;}
|
||||
ThreadChecker const & GetThreadChecker() const { return m_threadChecker; }
|
||||
|
||||
/// \brief Storage will create its directories in Writable Directory
|
||||
/// (gotten with platform::WritableDir) by default.
|
||||
@@ -296,8 +300,7 @@ public:
|
||||
/// * create a instance of Storage with a special countries.txt and |dataDir|
|
||||
/// * download some maps to WritableDir/|dataDir|
|
||||
/// * destroy the instance of Storage and move the downloaded maps to proper place
|
||||
Storage(std::string const & pathToCountriesFile = COUNTRIES_FILE,
|
||||
std::string const & dataDir = std::string());
|
||||
Storage(std::string const & pathToCountriesFile = COUNTRIES_FILE, std::string const & dataDir = std::string());
|
||||
|
||||
/// \brief This constructor should be used for testing only.
|
||||
Storage(std::string const & referenceCountriesTxtJsonForTesting,
|
||||
@@ -337,8 +340,8 @@ public:
|
||||
/// which have been written in coutries.txt or cournties_migrate.txt.
|
||||
/// It means the method does not put to its params neither custom maps generated by user
|
||||
/// nor World.mwm and WorldCoasts.mwm.
|
||||
void GetChildrenInGroups(CountryId const & parent, CountriesVec & downloadedChildren,
|
||||
CountriesVec & availChildren, bool keepAvailableChildren = false) const;
|
||||
void GetChildrenInGroups(CountryId const & parent, CountriesVec & downloadedChildren, CountriesVec & availChildren,
|
||||
bool keepAvailableChildren = false) const;
|
||||
/// \brief Fills |queuedChildren| with children of |parent| if they (or thier childen) are in |m_queue|.
|
||||
/// \note For group node children if one of child's ancestor has status
|
||||
/// NodeStatus::Downloading or NodeStatus::InQueue the child is considered as a queued child
|
||||
@@ -354,8 +357,7 @@ public:
|
||||
/// \param level is distance from top level except root.
|
||||
/// For disputed territories all possible owners will be added.
|
||||
/// Puts |countryId| to |nodes| when |level| is greater than the level of |countryId|.
|
||||
void GetTopmostNodesFor(CountryId const & countryId, CountriesVec & nodes,
|
||||
size_t level = 0) const;
|
||||
void GetTopmostNodesFor(CountryId const & countryId, CountriesVec & nodes, size_t level = 0) const;
|
||||
|
||||
/// \brief Returns topmost country id prior root id or |countryId| itself, if it's already
|
||||
/// a topmost node or disputed territory id if |countryId| is a disputed territory or belongs to
|
||||
@@ -392,10 +394,7 @@ public:
|
||||
/// \note This method works quicklier than GetNodeAttrs().
|
||||
void GetNodeStatuses(CountryId const & countryId, NodeStatuses & nodeStatuses) const;
|
||||
|
||||
std::string GetNodeLocalName(CountryId const & countryId) const
|
||||
{
|
||||
return m_countryNameGetter(countryId);
|
||||
}
|
||||
std::string GetNodeLocalName(CountryId const & countryId) const { return m_countryNameGetter(countryId); }
|
||||
|
||||
/// \brief Downloads/update one node (expandable or not) by countryId.
|
||||
/// If node is expandable downloads/update all children (grandchildren) by the node
|
||||
@@ -471,7 +470,7 @@ public:
|
||||
|
||||
/// \returns real (not fake) local maps contained in countries.txt.
|
||||
/// So this method does not return custom user local maps and World and WorldCoasts country id.
|
||||
//void GetLocalRealMaps(CountriesVec & localMaps) const;
|
||||
// void GetLocalRealMaps(CountriesVec & localMaps) const;
|
||||
|
||||
/// Do we have downloaded countries
|
||||
bool HaveDownloadedCountries() const;
|
||||
@@ -485,7 +484,8 @@ public:
|
||||
/// Used in Android to get absent Worlds files to download.
|
||||
/// @param[out] res Out vector, empty if all files are present some or error occured.
|
||||
/// @return WorldStatus:
|
||||
enum class WorldStatus {
|
||||
enum class WorldStatus
|
||||
{
|
||||
READY = 0, ///< Ready to download or all files are present if \a res is empty
|
||||
WAS_MOVED, ///< All World files are present and one or more files was moved, \a res is empty.
|
||||
ERROR_CREATE_FOLDER, ///< Error when creating folder
|
||||
@@ -523,10 +523,7 @@ public:
|
||||
{
|
||||
return localFile.GetCountryName();
|
||||
}
|
||||
CountryId const & FindCountryIdByFile(std::string const & name) const
|
||||
{
|
||||
return name;
|
||||
}
|
||||
CountryId const & FindCountryIdByFile(std::string const & name) const { return name; }
|
||||
/// @}
|
||||
|
||||
// Returns true iff |countryId| exists as a node in the tree.
|
||||
@@ -563,7 +560,7 @@ public:
|
||||
bool IsDownloadInProgress() const;
|
||||
|
||||
/// @param[out] res Populated with oudated countries.
|
||||
//void GetOutdatedCountries(std::vector<Country const *> & countries) const;
|
||||
// void GetOutdatedCountries(std::vector<Country const *> & countries) const;
|
||||
|
||||
/// Sets and gets locale, which is used to get localized counries names
|
||||
void SetLocale(std::string const & locale) { m_countryNameGetter.SetLocale(locale); }
|
||||
@@ -577,7 +574,7 @@ public:
|
||||
void SetLocaleForTesting(std::string const & jsonBuffer, std::string const & locale);
|
||||
|
||||
/// Returns true if the diff scheme is available and all local outdated maps can be updated via diffs.
|
||||
//bool IsPossibleToAutoupdate() const;
|
||||
// bool IsPossibleToAutoupdate() const;
|
||||
|
||||
void SetStartDownloadingCallback(StartDownloadingCallback const & cb);
|
||||
|
||||
@@ -630,10 +627,9 @@ private:
|
||||
|
||||
/// Returns status for a node (group node or not).
|
||||
/// Fills |disputedTeritories| with all disputed teritories in subtree with the root == |node|.
|
||||
StatusAndError GetNodeStatusInfo(
|
||||
CountryTree::Node const & node,
|
||||
std::vector<std::pair<CountryId, NodeStatus>> & disputedTeritories,
|
||||
bool isDisputedTerritoriesCounted) const;
|
||||
StatusAndError GetNodeStatusInfo(CountryTree::Node const & node,
|
||||
std::vector<std::pair<CountryId, NodeStatus>> & disputedTeritories,
|
||||
bool isDisputedTerritoriesCounted) const;
|
||||
|
||||
void NotifyStatusChanged(CountryId const & countryId);
|
||||
void NotifyStatusChangedForHierarchy(CountryId const & countryId);
|
||||
@@ -654,7 +650,7 @@ private:
|
||||
|
||||
void OnMapDownloadFailed(CountryId const & countryId);
|
||||
|
||||
//void LoadDiffScheme();
|
||||
// void LoadDiffScheme();
|
||||
void ApplyDiff(CountryId const & countryId, std::function<void(bool isSuccess)> const & fn);
|
||||
|
||||
using IsDiffAbsentForCountry = std::function<bool(CountryId const & id)>;
|
||||
@@ -677,7 +673,8 @@ void Storage::ForEachInSubtree(CountryId const & root, ToDo && toDo) const
|
||||
ASSERT(false, ("CountryId =", root, "not found in m_countries."));
|
||||
return;
|
||||
}
|
||||
rootNode->ForEachInSubtree([&toDo](CountryTree::Node const & node) {
|
||||
rootNode->ForEachInSubtree([&toDo](CountryTree::Node const & node)
|
||||
{
|
||||
Country const & value = node.Value();
|
||||
toDo(value.Name(), value.GetSubtreeMwmCounter() != 1 /* groupNode. */);
|
||||
});
|
||||
@@ -712,7 +709,8 @@ void Storage::ForEachAncestorExceptForTheRoot(CountryTree::NodesBufferT const &
|
||||
// may be more than one. It means |childId| is present in the country tree more than once.
|
||||
for (auto const & node : nodes)
|
||||
{
|
||||
node->ForEachAncestorExceptForTheRoot([&](CountryTree::Node const & node) {
|
||||
node->ForEachAncestorExceptForTheRoot([&](CountryTree::Node const & node)
|
||||
{
|
||||
CountryId const ancestorId = node.Value().Name();
|
||||
if (visitedAncestors.find(&node) != visitedAncestors.end())
|
||||
return; // The node was visited before because countryId is present in the tree more
|
||||
|
||||
@@ -11,32 +11,25 @@ namespace storage
|
||||
{
|
||||
storage::CountryId const kInvalidCountryId;
|
||||
|
||||
bool IsCountryIdValid(CountryId const & countryId) { return countryId != kInvalidCountryId; }
|
||||
bool IsCountryIdValid(CountryId const & countryId)
|
||||
{
|
||||
return countryId != kInvalidCountryId;
|
||||
}
|
||||
|
||||
string DebugPrint(Status status)
|
||||
{
|
||||
switch (status)
|
||||
{
|
||||
case Status::Undefined:
|
||||
return "EUndefined"s;
|
||||
case Status::OnDisk:
|
||||
return "OnDisk"s;
|
||||
case Status::NotDownloaded:
|
||||
return "NotDownloaded"s;
|
||||
case Status::DownloadFailed:
|
||||
return "DownloadFailed"s;
|
||||
case Status::Downloading:
|
||||
return "Downloading"s;
|
||||
case Status::Applying:
|
||||
return "Applying"s;
|
||||
case Status::InQueue:
|
||||
return "InQueue"s;
|
||||
case Status::UnknownError:
|
||||
return "Unknown"s;
|
||||
case Status::OnDiskOutOfDate:
|
||||
return "OnDiskOutOfDate"s;
|
||||
case Status::OutOfMemFailed:
|
||||
return "OutOfMemFailed"s;
|
||||
case Status::Undefined: return "EUndefined"s;
|
||||
case Status::OnDisk: return "OnDisk"s;
|
||||
case Status::NotDownloaded: return "NotDownloaded"s;
|
||||
case Status::DownloadFailed: return "DownloadFailed"s;
|
||||
case Status::Downloading: return "Downloading"s;
|
||||
case Status::Applying: return "Applying"s;
|
||||
case Status::InQueue: return "InQueue"s;
|
||||
case Status::UnknownError: return "Unknown"s;
|
||||
case Status::OnDiskOutOfDate: return "OnDiskOutOfDate"s;
|
||||
case Status::OutOfMemFailed: return "OutOfMemFailed"s;
|
||||
}
|
||||
UNREACHABLE();
|
||||
}
|
||||
@@ -45,24 +38,15 @@ string DebugPrint(NodeStatus status)
|
||||
{
|
||||
switch (status)
|
||||
{
|
||||
case NodeStatus::Undefined:
|
||||
return "Undefined"s;
|
||||
case NodeStatus::Error:
|
||||
return "Error"s;
|
||||
case NodeStatus::OnDisk:
|
||||
return "OnDisk"s;
|
||||
case NodeStatus::NotDownloaded:
|
||||
return "NotDownloaded"s;
|
||||
case NodeStatus::Downloading:
|
||||
return "Downloading"s;
|
||||
case NodeStatus::Applying:
|
||||
return "Applying"s;
|
||||
case NodeStatus::InQueue:
|
||||
return "InQueue"s;
|
||||
case NodeStatus::OnDiskOutOfDate:
|
||||
return "OnDiskOutOfDate"s;
|
||||
case NodeStatus::Partly:
|
||||
return "Partly"s;
|
||||
case NodeStatus::Undefined: return "Undefined"s;
|
||||
case NodeStatus::Error: return "Error"s;
|
||||
case NodeStatus::OnDisk: return "OnDisk"s;
|
||||
case NodeStatus::NotDownloaded: return "NotDownloaded"s;
|
||||
case NodeStatus::Downloading: return "Downloading"s;
|
||||
case NodeStatus::Applying: return "Applying"s;
|
||||
case NodeStatus::InQueue: return "InQueue"s;
|
||||
case NodeStatus::OnDiskOutOfDate: return "OnDiskOutOfDate"s;
|
||||
case NodeStatus::Partly: return "Partly"s;
|
||||
}
|
||||
UNREACHABLE();
|
||||
}
|
||||
@@ -71,14 +55,10 @@ string DebugPrint(NodeErrorCode status)
|
||||
{
|
||||
switch (status)
|
||||
{
|
||||
case NodeErrorCode::NoError:
|
||||
return "NoError"s;
|
||||
case NodeErrorCode::UnknownError:
|
||||
return "UnknownError"s;
|
||||
case NodeErrorCode::OutOfMemFailed:
|
||||
return "OutOfMemFailed"s;
|
||||
case NodeErrorCode::NoInetConnection:
|
||||
return "NoInetConnection"s;
|
||||
case NodeErrorCode::NoError: return "NoError"s;
|
||||
case NodeErrorCode::UnknownError: return "UnknownError"s;
|
||||
case NodeErrorCode::OutOfMemFailed: return "OutOfMemFailed"s;
|
||||
case NodeErrorCode::NoInetConnection: return "NoInetConnection"s;
|
||||
}
|
||||
UNREACHABLE();
|
||||
}
|
||||
@@ -87,26 +67,16 @@ StatusAndError ParseStatus(Status innerStatus)
|
||||
{
|
||||
switch (innerStatus)
|
||||
{
|
||||
case Status::Undefined:
|
||||
return StatusAndError(NodeStatus::Undefined, NodeErrorCode::NoError);
|
||||
case Status::OnDisk:
|
||||
return StatusAndError(NodeStatus::OnDisk, NodeErrorCode::NoError);
|
||||
case Status::NotDownloaded:
|
||||
return StatusAndError(NodeStatus::NotDownloaded, NodeErrorCode::NoError);
|
||||
case Status::DownloadFailed:
|
||||
return StatusAndError(NodeStatus::Error, NodeErrorCode::NoInetConnection);
|
||||
case Status::Downloading:
|
||||
return StatusAndError(NodeStatus::Downloading, NodeErrorCode::NoError);
|
||||
case Status::Applying:
|
||||
return StatusAndError(NodeStatus::Applying, NodeErrorCode::NoError);
|
||||
case Status::InQueue:
|
||||
return StatusAndError(NodeStatus::InQueue, NodeErrorCode::NoError);
|
||||
case Status::UnknownError:
|
||||
return StatusAndError(NodeStatus::Error, NodeErrorCode::UnknownError);
|
||||
case Status::OnDiskOutOfDate:
|
||||
return StatusAndError(NodeStatus::OnDiskOutOfDate, NodeErrorCode::NoError);
|
||||
case Status::OutOfMemFailed:
|
||||
return StatusAndError(NodeStatus::Error, NodeErrorCode::OutOfMemFailed);
|
||||
case Status::Undefined: return StatusAndError(NodeStatus::Undefined, NodeErrorCode::NoError);
|
||||
case Status::OnDisk: return StatusAndError(NodeStatus::OnDisk, NodeErrorCode::NoError);
|
||||
case Status::NotDownloaded: return StatusAndError(NodeStatus::NotDownloaded, NodeErrorCode::NoError);
|
||||
case Status::DownloadFailed: return StatusAndError(NodeStatus::Error, NodeErrorCode::NoInetConnection);
|
||||
case Status::Downloading: return StatusAndError(NodeStatus::Downloading, NodeErrorCode::NoError);
|
||||
case Status::Applying: return StatusAndError(NodeStatus::Applying, NodeErrorCode::NoError);
|
||||
case Status::InQueue: return StatusAndError(NodeStatus::InQueue, NodeErrorCode::NoError);
|
||||
case Status::UnknownError: return StatusAndError(NodeStatus::Error, NodeErrorCode::UnknownError);
|
||||
case Status::OnDiskOutOfDate: return StatusAndError(NodeStatus::OnDiskOutOfDate, NodeErrorCode::NoError);
|
||||
case Status::OutOfMemFailed: return StatusAndError(NodeStatus::Error, NodeErrorCode::OutOfMemFailed);
|
||||
}
|
||||
UNREACHABLE();
|
||||
}
|
||||
@@ -114,8 +84,7 @@ StatusAndError ParseStatus(Status innerStatus)
|
||||
string DebugPrint(StatusAndError statusAndError)
|
||||
{
|
||||
ostringstream out;
|
||||
out << "StatusAndError[" << DebugPrint(statusAndError.status)
|
||||
<< ", " << DebugPrint(statusAndError.error) << "]";
|
||||
out << "StatusAndError[" << DebugPrint(statusAndError.status) << ", " << DebugPrint(statusAndError.error) << "]";
|
||||
return out.str();
|
||||
}
|
||||
} // namespace storage
|
||||
|
||||
@@ -29,7 +29,7 @@ using CountryNameSynonyms = std::unordered_map<std::string, CountryId>;
|
||||
using MwmTopCityGeoIds = std::unordered_map<CountryId, base::GeoObjectId>;
|
||||
using MwmTopCountryGeoIds = std::unordered_map<CountryId, std::vector<base::GeoObjectId>>;
|
||||
|
||||
extern const storage::CountryId kInvalidCountryId;
|
||||
extern storage::CountryId const kInvalidCountryId;
|
||||
|
||||
// @TODO(bykoianko) Check in country tree if the countryId is valid.
|
||||
bool IsCountryIdValid(CountryId const & countryId);
|
||||
@@ -77,22 +77,16 @@ std::string DebugPrint(NodeErrorCode status);
|
||||
|
||||
struct StatusAndError
|
||||
{
|
||||
StatusAndError(NodeStatus nodeStatus, NodeErrorCode nodeError)
|
||||
: status(nodeStatus), error(nodeError)
|
||||
{
|
||||
}
|
||||
StatusAndError(NodeStatus nodeStatus, NodeErrorCode nodeError) : status(nodeStatus), error(nodeError) {}
|
||||
|
||||
bool operator==(StatusAndError const & other) const
|
||||
{
|
||||
return other.status == status && other.error == error;
|
||||
}
|
||||
bool operator==(StatusAndError const & other) const { return other.status == status && other.error == error; }
|
||||
|
||||
NodeStatus status;
|
||||
NodeErrorCode error;
|
||||
};
|
||||
std::string DebugPrint(StatusAndError statusAndError);
|
||||
};
|
||||
std::string DebugPrint(StatusAndError statusAndError);
|
||||
|
||||
StatusAndError ParseStatus(Status innerStatus);
|
||||
StatusAndError ParseStatus(Status innerStatus);
|
||||
} // namespace storage
|
||||
|
||||
using DownloadFn = std::function<void(storage::CountryId const &)>;
|
||||
|
||||
@@ -9,8 +9,7 @@
|
||||
|
||||
namespace storage
|
||||
{
|
||||
bool IsPointCoveredByDownloadedMaps(m2::PointD const & position,
|
||||
Storage const & storage,
|
||||
bool IsPointCoveredByDownloadedMaps(m2::PointD const & position, Storage const & storage,
|
||||
CountryInfoGetter const & countryInfoGetter)
|
||||
{
|
||||
return storage.IsNodeDownloaded(countryInfoGetter.GetRegionCountryId(position));
|
||||
@@ -18,16 +17,14 @@ bool IsPointCoveredByDownloadedMaps(m2::PointD const & position,
|
||||
|
||||
bool IsDownloadFailed(Status status)
|
||||
{
|
||||
return status == Status::DownloadFailed || status == Status::OutOfMemFailed ||
|
||||
status == Status::UnknownError;
|
||||
return status == Status::DownloadFailed || status == Status::OutOfMemFailed || status == Status::UnknownError;
|
||||
}
|
||||
|
||||
bool IsEnoughSpaceForDownload(MwmSize mwmSize)
|
||||
{
|
||||
// Additional size which is necessary to have on flash card to download file of mwmSize bytes.
|
||||
MwmSize constexpr kExtraSizeBytes = 10 * 1024 * 1024;
|
||||
return GetPlatform().GetWritableStorageStatus(mwmSize + kExtraSizeBytes) ==
|
||||
Platform::TStorageStatus::STORAGE_OK;
|
||||
return GetPlatform().GetWritableStorageStatus(mwmSize + kExtraSizeBytes) == Platform::TStorageStatus::STORAGE_OK;
|
||||
}
|
||||
|
||||
bool IsEnoughSpaceForDownload(CountryId const & countryId, Storage const & storage)
|
||||
@@ -51,8 +48,8 @@ bool IsEnoughSpaceForUpdate(CountryId const & countryId, Storage const & storage
|
||||
// - final size difference between old and new MWMs = m_sizeDifference
|
||||
|
||||
[[maybe_unused]] MwmSize const diff = updateInfo.m_sizeDifference > 0 ? updateInfo.m_sizeDifference : 0;
|
||||
// return IsEnoughSpaceForDownload(std::max(diff, updateInfo.m_totalDownloadSizeInBytes) +
|
||||
// updateInfo.m_maxFileSizeInBytes);
|
||||
// return IsEnoughSpaceForDownload(std::max(diff, updateInfo.m_totalDownloadSizeInBytes) +
|
||||
// updateInfo.m_maxFileSizeInBytes);
|
||||
|
||||
// 2. For the current "download and replace" strategy:
|
||||
// - Android and Desktop has 1 simultaneous download
|
||||
@@ -68,8 +65,8 @@ m2::RectD CalcLimitRect(CountryId const & countryId, Storage const & storage,
|
||||
CountryInfoGetter const & countryInfoGetter)
|
||||
{
|
||||
m2::RectD boundingBox;
|
||||
auto const accumulator = [&countryInfoGetter, &boundingBox](CountryId const & descendantId,
|
||||
bool groupNode) {
|
||||
auto const accumulator = [&countryInfoGetter, &boundingBox](CountryId const & descendantId, bool groupNode)
|
||||
{
|
||||
if (!groupNode)
|
||||
boundingBox.Add(countryInfoGetter.GetLimitRectForLeaf(descendantId));
|
||||
};
|
||||
@@ -80,12 +77,11 @@ m2::RectD CalcLimitRect(CountryId const & countryId, Storage const & storage,
|
||||
return boundingBox;
|
||||
}
|
||||
|
||||
MwmSize GetRemoteSize(diffs::DiffsDataSource const & diffsDataSource,
|
||||
platform::CountryFile const & file)
|
||||
MwmSize GetRemoteSize(diffs::DiffsDataSource const & diffsDataSource, platform::CountryFile const & file)
|
||||
{
|
||||
uint64_t size;
|
||||
if (diffsDataSource.SizeFor(file.GetName(), size))
|
||||
return size;
|
||||
return file.GetRemoteSize();
|
||||
}
|
||||
} // namespace storage
|
||||
} // namespace storage
|
||||
|
||||
@@ -31,6 +31,5 @@ bool IsEnoughSpaceForUpdate(CountryId const & countryId, Storage const & storage
|
||||
m2::RectD CalcLimitRect(CountryId const & countryId, Storage const & storage,
|
||||
CountryInfoGetter const & countryInfoGetter);
|
||||
|
||||
MwmSize GetRemoteSize(diffs::DiffsDataSource const & diffsDataSource,
|
||||
platform::CountryFile const & file);
|
||||
MwmSize GetRemoteSize(diffs::DiffsDataSource const & diffsDataSource, platform::CountryFile const & file);
|
||||
} // namespace storage
|
||||
|
||||
@@ -15,7 +15,8 @@ using namespace storage;
|
||||
void InitStorage(Storage & storage, Storage::UpdateCallback const & didDownload,
|
||||
Storage::ProgressFunction const & progress)
|
||||
{
|
||||
auto const changeCountryFunction = [&](CountryId const & /* countryId */) {
|
||||
auto const changeCountryFunction = [&](CountryId const & /* countryId */)
|
||||
{
|
||||
if (!storage.IsDownloadInProgress())
|
||||
{
|
||||
// End wait for downloading complete.
|
||||
@@ -34,7 +35,7 @@ UNIT_TEST(DownloadingTests_CalcOverallProgress)
|
||||
WritableDirChanger writableDirChanger(storage::kMapTestDir);
|
||||
|
||||
// A bunch of small islands.
|
||||
CountriesVec const kTestCountries = { "Kiribati", "Tokelau", "Niue", "Palau", "Pitcairn Islands" };
|
||||
CountriesVec const kTestCountries = {"Kiribati", "Tokelau", "Niue", "Palau", "Pitcairn Islands"};
|
||||
|
||||
Storage s;
|
||||
|
||||
@@ -44,13 +45,12 @@ UNIT_TEST(DownloadingTests_CalcOverallProgress)
|
||||
TEST_EQUAL(baseProgress.m_bytesDownloaded, 0, ());
|
||||
TEST_EQUAL(baseProgress.m_bytesTotal, 0, ());
|
||||
|
||||
for (auto const &country : kTestCountries)
|
||||
{
|
||||
for (auto const & country : kTestCountries)
|
||||
baseProgress.m_bytesTotal += s.CountrySizeInBytes(country).second;
|
||||
}
|
||||
|
||||
auto progressChanged = [&s, &kTestCountries, &baseProgress](CountryId const & id,
|
||||
downloader::Progress const & /* progress */) {
|
||||
auto progressChanged =
|
||||
[&s, &kTestCountries, &baseProgress](CountryId const & id, downloader::Progress const & /* progress */)
|
||||
{
|
||||
auto const currentProgress = s.GetOverallProgress(kTestCountries);
|
||||
LOG_SHORT(LINFO, (id, "downloading progress:", currentProgress));
|
||||
|
||||
|
||||
@@ -15,10 +15,8 @@ double constexpr kStepInMercator = 1;
|
||||
|
||||
struct PointAndCountry
|
||||
{
|
||||
PointAndCountry(m2::PointD && pt, storage::CountryId && country)
|
||||
: m_pt(std::move(pt)), m_country(std::move(country))
|
||||
{
|
||||
}
|
||||
PointAndCountry(m2::PointD && pt, storage::CountryId && country) : m_pt(std::move(pt)), m_country(std::move(country))
|
||||
{}
|
||||
|
||||
m2::PointD m_pt;
|
||||
storage::CountryId m_country;
|
||||
@@ -44,8 +42,6 @@ UNIT_CLASS_TEST(CountryInfoReader, LightweightMatching)
|
||||
LOG(LINFO, ("The dataset is generated. Dataset size:", dataset.size()));
|
||||
|
||||
for (auto const & sample : dataset)
|
||||
{
|
||||
TEST_EQUAL(GetRegionCountryId(sample.m_pt), sample.m_country, (sample.m_pt));
|
||||
}
|
||||
}
|
||||
} // namespace lightweight_matching_tests
|
||||
|
||||
@@ -30,7 +30,7 @@ int GetLevelCount(Storage & storage, CountryId const & countryId)
|
||||
level = std::max(level, GetLevelCount(storage, child));
|
||||
return 1 + level;
|
||||
}
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
UNIT_TEST(SmallMwms_3levels_Test)
|
||||
{
|
||||
@@ -42,13 +42,7 @@ UNIT_TEST(SmallMwms_3levels_Test)
|
||||
/// RunOnGui callbacks, so delete Framework also in RunOnGui.
|
||||
auto * frm = new Framework(FrameworkParams(false /* m_enableDiffs */));
|
||||
|
||||
SCOPE_GUARD(deleteFramework, [frm]()
|
||||
{
|
||||
GetPlatform().RunTask(Platform::Thread::Gui, [frm]()
|
||||
{
|
||||
delete frm;
|
||||
});
|
||||
});
|
||||
SCOPE_GUARD(deleteFramework, [frm]() { GetPlatform().RunTask(Platform::Thread::Gui, [frm]() { delete frm; }); });
|
||||
|
||||
auto & storage = frm->GetStorage();
|
||||
std::string const version = strings::to_string(storage.GetCurrentDataVersion());
|
||||
@@ -60,7 +54,8 @@ UNIT_TEST(SmallMwms_3levels_Test)
|
||||
|
||||
auto onProgressFn = [&](CountryId const & countryId, downloader::Progress const & /* progress */) {};
|
||||
|
||||
auto onChangeCountryFn = [&](CountryId const & countryId) {
|
||||
auto onChangeCountryFn = [&](CountryId const & countryId)
|
||||
{
|
||||
if (!storage.IsDownloadInProgress())
|
||||
testing::StopEventLoop();
|
||||
};
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
#include "base/thread.hpp"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <functional>
|
||||
#include <exception>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
using namespace platform;
|
||||
@@ -29,7 +29,7 @@ using namespace std;
|
||||
using namespace std::placeholders;
|
||||
|
||||
// Uncomment to enable the test that requires network and downloads an mwm several times.
|
||||
//#define TEST_INTEGRITY
|
||||
// #define TEST_INTEGRITY
|
||||
#ifndef TEST_INTEGRITY_ITERATIONS
|
||||
#define TEST_INTEGRITY_ITERATIONS 5
|
||||
#endif
|
||||
@@ -40,7 +40,8 @@ using Runner = Platform::ThreadRunner;
|
||||
|
||||
string const kCountryId = "Trinidad and Tobago";
|
||||
|
||||
class InterruptException : public exception {};
|
||||
class InterruptException : public exception
|
||||
{};
|
||||
|
||||
void Update(CountryId const &, storage::LocalFilePtr const localCountryFile)
|
||||
{
|
||||
@@ -63,7 +64,7 @@ void InitStorage(Storage & storage, Storage::ProgressFunction const & onProgress
|
||||
storage.SetDownloadingServersForTesting({kTestWebServer});
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
UNIT_TEST(SmallMwms_ReDownloadExistedMWMIgnored_Test)
|
||||
{
|
||||
@@ -90,7 +91,8 @@ UNIT_CLASS_TEST(Runner, SmallMwms_InterruptDownloadResumeDownload_Test)
|
||||
{
|
||||
Storage storage;
|
||||
|
||||
auto const onProgressFn = [](CountryId const & countryId, downloader::Progress const & /* progress */) {
|
||||
auto const onProgressFn = [](CountryId const & countryId, downloader::Progress const & /* progress */)
|
||||
{
|
||||
TEST_EQUAL(countryId, kCountryId, ());
|
||||
// Interrupt download
|
||||
testing::StopEventLoop();
|
||||
@@ -116,30 +118,25 @@ UNIT_CLASS_TEST(Runner, SmallMwms_InterruptDownloadResumeDownload_Test)
|
||||
|
||||
bool onProgressIsCalled = false;
|
||||
NodeAttrs onProgressAttrs;
|
||||
auto const onProgressFn =
|
||||
[&](CountryId const & countryId, downloader::Progress const & /* progress */)
|
||||
{
|
||||
TEST_EQUAL(countryId, kCountryId, ());
|
||||
auto const onProgressFn = [&](CountryId const & countryId, downloader::Progress const & /* progress */)
|
||||
{
|
||||
TEST_EQUAL(countryId, kCountryId, ());
|
||||
|
||||
if (onProgressIsCalled)
|
||||
return;
|
||||
if (onProgressIsCalled)
|
||||
return;
|
||||
|
||||
onProgressIsCalled = true;
|
||||
storage.GetNodeAttrs(kCountryId, onProgressAttrs);
|
||||
testing::StopEventLoop();
|
||||
};
|
||||
onProgressIsCalled = true;
|
||||
storage.GetNodeAttrs(kCountryId, onProgressAttrs);
|
||||
testing::StopEventLoop();
|
||||
};
|
||||
|
||||
InitStorage(storage, onProgressFn);
|
||||
storage.Init([](CountryId const &, storage::LocalFilePtr const localCountryFile)
|
||||
{
|
||||
TEST_EQUAL(localCountryFile->GetCountryName(), kCountryId, ());
|
||||
{
|
||||
TEST_EQUAL(localCountryFile->GetCountryName(), kCountryId, ());
|
||||
|
||||
testing::StopEventLoop();
|
||||
},
|
||||
[](CountryId const &, storage::LocalFilePtr const)
|
||||
{
|
||||
return false;
|
||||
});
|
||||
testing::StopEventLoop();
|
||||
}, [](CountryId const &, storage::LocalFilePtr const) { return false; });
|
||||
|
||||
testing::RunEventLoop();
|
||||
|
||||
@@ -191,7 +188,8 @@ UNIT_CLASS_TEST(Runner, DownloadIntegrity_Test)
|
||||
|
||||
Storage storage(COUNTRIES_FILE);
|
||||
|
||||
auto onProgressFn = [i, j](CountryId const & countryId, LocalAndRemoteSize const & mapSize) {
|
||||
auto onProgressFn = [i, j](CountryId const & countryId, LocalAndRemoteSize const & mapSize)
|
||||
{
|
||||
TEST_EQUAL(countryId, kCountryId, ());
|
||||
auto progress = static_cast<double>(mapSize.first) / mapSize.second;
|
||||
auto interruptionProgress =
|
||||
|
||||
@@ -24,7 +24,7 @@ using namespace std;
|
||||
using namespace storage;
|
||||
|
||||
CountryId const kGroupCountryId = "Venezuela";
|
||||
CountriesSet const kLeafCountriesIds = { "Venezuela_North", "Venezuela_South" };
|
||||
CountriesSet const kLeafCountriesIds = {"Venezuela_North", "Venezuela_South"};
|
||||
|
||||
string GetMwmFilePath(string const & version, CountryId const & countryId)
|
||||
{
|
||||
@@ -33,9 +33,8 @@ string GetMwmFilePath(string const & version, CountryId const & countryId)
|
||||
|
||||
string GetMwmDownloadingFilePath(string const & version, CountryId const & countryId)
|
||||
{
|
||||
return base::JoinPath(
|
||||
GetPlatform().WritableDir(), version,
|
||||
countryId + DATA_FILE_EXTENSION READY_FILE_EXTENSION DOWNLOADING_FILE_EXTENSION);
|
||||
return base::JoinPath(GetPlatform().WritableDir(), version,
|
||||
countryId + DATA_FILE_EXTENSION READY_FILE_EXTENSION DOWNLOADING_FILE_EXTENSION);
|
||||
}
|
||||
|
||||
string GetMwmResumeFilePath(string const & version, CountryId const & countryId)
|
||||
@@ -55,13 +54,12 @@ void DownloadGroup(Storage & storage, bool oneByOne)
|
||||
// All nodes in subtree (including the root) for the group node.
|
||||
storage.GetChildren(kGroupCountryId, children);
|
||||
CountriesSet subTree;
|
||||
storage.ForEachInSubtree(kGroupCountryId,
|
||||
[&subTree](CountryId const & descendantId, bool /* groupNode */) {
|
||||
subTree.insert(descendantId);
|
||||
});
|
||||
storage.ForEachInSubtree(kGroupCountryId, [&subTree](CountryId const & descendantId, bool /* groupNode */)
|
||||
{ subTree.insert(descendantId); });
|
||||
|
||||
CountriesSet changed;
|
||||
auto onChangeCountryFn = [&](CountryId const & countryId) {
|
||||
auto onChangeCountryFn = [&](CountryId const & countryId)
|
||||
{
|
||||
TEST(subTree.find(countryId) != subTree.end(), (countryId));
|
||||
changed.insert(countryId);
|
||||
if (!storage.IsDownloadInProgress())
|
||||
@@ -72,12 +70,13 @@ void DownloadGroup(Storage & storage, bool oneByOne)
|
||||
};
|
||||
|
||||
CountriesSet downloadedChecker;
|
||||
auto onProgressFn = [&](CountryId const & countryId, downloader::Progress const & progress) {
|
||||
auto onProgressFn = [&](CountryId const & countryId, downloader::Progress const & progress)
|
||||
{
|
||||
TEST(subTree.find(countryId) != subTree.end(), ());
|
||||
if (progress.m_bytesDownloaded == progress.m_bytesTotal)
|
||||
{
|
||||
auto const res = downloadedChecker.insert(countryId);
|
||||
TEST_EQUAL(res.second, true, ()); // Every child is downloaded only once.
|
||||
TEST_EQUAL(res.second, true, ()); // Every child is downloaded only once.
|
||||
}
|
||||
};
|
||||
|
||||
@@ -124,14 +123,10 @@ void DownloadGroup(Storage & storage, bool oneByOne)
|
||||
|
||||
// Download the group.
|
||||
if (oneByOne)
|
||||
{
|
||||
for (auto const & countryId : children)
|
||||
storage.DownloadNode(countryId);
|
||||
}
|
||||
else
|
||||
{
|
||||
storage.DownloadNode(kGroupCountryId);
|
||||
}
|
||||
// Wait for downloading of all children.
|
||||
testing::RunEventLoop();
|
||||
|
||||
@@ -169,8 +164,7 @@ void DownloadGroup(Storage & storage, bool oneByOne)
|
||||
|
||||
// Check all group children are downloaded.
|
||||
storage.GetChildrenInGroups(kGroupCountryId, downloaded, available);
|
||||
TEST_EQUAL(CountriesSet(children.begin(), children.end()),
|
||||
CountriesSet(downloaded.begin(), downloaded.end()), ());
|
||||
TEST_EQUAL(CountriesSet(children.begin(), children.end()), CountriesSet(downloaded.begin(), downloaded.end()), ());
|
||||
|
||||
storage.Unsubscribe(subsrcibtionId);
|
||||
}
|
||||
@@ -205,14 +199,10 @@ void DeleteGroup(Storage & storage, bool oneByOne)
|
||||
|
||||
// Delete the group
|
||||
if (oneByOne)
|
||||
{
|
||||
for (auto const & countryId : children)
|
||||
storage.DeleteNode(countryId);
|
||||
}
|
||||
else
|
||||
{
|
||||
storage.DeleteNode(kGroupCountryId);
|
||||
}
|
||||
|
||||
// Check state for the group node is set to NotDownloaded and NoError.
|
||||
NodeAttrs attrs;
|
||||
@@ -251,7 +241,8 @@ void TestDownloadDelete(bool downloadOneByOne, bool deleteOneByOne)
|
||||
Storage storage;
|
||||
string const version = strings::to_string(storage.GetCurrentDataVersion());
|
||||
|
||||
auto onUpdatedFn = [&](CountryId const &, storage::LocalFilePtr const localCountryFile) {
|
||||
auto onUpdatedFn = [&](CountryId const &, storage::LocalFilePtr const localCountryFile)
|
||||
{
|
||||
CountryId const countryId = localCountryFile->GetCountryName();
|
||||
TEST(kLeafCountriesIds.find(countryId) != kLeafCountriesIds.end(), ());
|
||||
};
|
||||
@@ -291,4 +282,4 @@ UNIT_TEST(SmallMwms_GroupDownloadDelete_Test4)
|
||||
{
|
||||
TestDownloadDelete(true, true);
|
||||
}
|
||||
} // namespace storage_group_download_tests
|
||||
} // namespace storage_group_download_tests
|
||||
|
||||
@@ -43,22 +43,21 @@ string const GetMwmFullPath(string const & countryId, string const & version)
|
||||
|
||||
string const GetDownloadingFullPath(string const & countryId, string const & version)
|
||||
{
|
||||
return base::JoinPath(
|
||||
GetPlatform().WritableDir(), version,
|
||||
kCountryId + DATA_FILE_EXTENSION READY_FILE_EXTENSION DOWNLOADING_FILE_EXTENSION);
|
||||
return base::JoinPath(GetPlatform().WritableDir(), version,
|
||||
kCountryId + DATA_FILE_EXTENSION READY_FILE_EXTENSION DOWNLOADING_FILE_EXTENSION);
|
||||
}
|
||||
|
||||
string const GetResumeFullPath(string const & countryId, string const & version)
|
||||
{
|
||||
return base::JoinPath(
|
||||
GetPlatform().WritableDir(), version,
|
||||
kCountryId + DATA_FILE_EXTENSION READY_FILE_EXTENSION RESUME_FILE_EXTENSION);
|
||||
return base::JoinPath(GetPlatform().WritableDir(), version,
|
||||
kCountryId + DATA_FILE_EXTENSION READY_FILE_EXTENSION RESUME_FILE_EXTENSION);
|
||||
}
|
||||
|
||||
void InitStorage(Storage & storage, Storage::UpdateCallback const & didDownload,
|
||||
Storage::ProgressFunction const & progress)
|
||||
{
|
||||
auto const changeCountryFunction = [&](CountryId const & /* countryId */) {
|
||||
auto const changeCountryFunction = [&](CountryId const & /* countryId */)
|
||||
{
|
||||
if (!storage.IsDownloadInProgress())
|
||||
{
|
||||
// End wait for downloading complete.
|
||||
@@ -76,11 +75,10 @@ class StorageHttpTest
|
||||
{
|
||||
public:
|
||||
StorageHttpTest()
|
||||
: m_writableDirChanger(kMapTestDir),
|
||||
m_version(strings::to_string(m_storage.GetCurrentDataVersion())),
|
||||
m_cleanupVersionDir(m_version)
|
||||
{
|
||||
}
|
||||
: m_writableDirChanger(kMapTestDir)
|
||||
, m_version(strings::to_string(m_storage.GetCurrentDataVersion()))
|
||||
, m_cleanupVersionDir(m_version)
|
||||
{}
|
||||
|
||||
protected:
|
||||
WritableDirChanger const m_writableDirChanger;
|
||||
@@ -91,15 +89,13 @@ protected:
|
||||
|
||||
UNIT_CLASS_TEST(StorageHttpTest, StorageDownloadNodeAndDeleteNode)
|
||||
{
|
||||
auto const progressFunction = [this](CountryId const & countryId,
|
||||
downloader::Progress const & progress) {
|
||||
auto const progressFunction = [this](CountryId const & countryId, downloader::Progress const & progress)
|
||||
{
|
||||
NodeAttrs nodeAttrs;
|
||||
m_storage.GetNodeAttrs(countryId, nodeAttrs);
|
||||
|
||||
TEST_EQUAL(progress.m_bytesDownloaded,
|
||||
nodeAttrs.m_downloadingProgress.m_bytesDownloaded, (countryId));
|
||||
TEST_EQUAL(progress.m_bytesTotal,
|
||||
nodeAttrs.m_downloadingProgress.m_bytesTotal, (countryId));
|
||||
TEST_EQUAL(progress.m_bytesDownloaded, nodeAttrs.m_downloadingProgress.m_bytesDownloaded, (countryId));
|
||||
TEST_EQUAL(progress.m_bytesTotal, nodeAttrs.m_downloadingProgress.m_bytesTotal, (countryId));
|
||||
TEST_EQUAL(countryId, kCountryId, (countryId));
|
||||
};
|
||||
|
||||
@@ -132,15 +128,13 @@ UNIT_CLASS_TEST(StorageHttpTest, StorageDownloadNodeAndDeleteNode)
|
||||
|
||||
UNIT_CLASS_TEST(StorageHttpTest, StorageDownloadAndDeleteDisputedNode)
|
||||
{
|
||||
auto const progressFunction = [this](CountryId const & countryId,
|
||||
downloader::Progress const & progress) {
|
||||
auto const progressFunction = [this](CountryId const & countryId, downloader::Progress const & progress)
|
||||
{
|
||||
NodeAttrs nodeAttrs;
|
||||
m_storage.GetNodeAttrs(countryId, nodeAttrs);
|
||||
|
||||
TEST_EQUAL(progress.m_bytesDownloaded,
|
||||
nodeAttrs.m_downloadingProgress.m_bytesDownloaded, (countryId));
|
||||
TEST_EQUAL(progress.m_bytesTotal,
|
||||
nodeAttrs.m_downloadingProgress.m_bytesTotal, (countryId));
|
||||
TEST_EQUAL(progress.m_bytesDownloaded, nodeAttrs.m_downloadingProgress.m_bytesDownloaded, (countryId));
|
||||
TEST_EQUAL(progress.m_bytesTotal, nodeAttrs.m_downloadingProgress.m_bytesTotal, (countryId));
|
||||
};
|
||||
|
||||
InitStorage(m_storage, UpdateWithoutChecks, progressFunction);
|
||||
@@ -168,8 +162,7 @@ UNIT_CLASS_TEST(StorageHttpTest, StorageDownloadAndDeleteDisputedNode)
|
||||
CountriesVec availChildren;
|
||||
m_storage.GetChildrenInGroups(m_storage.GetRootId(), downloadedChildren, availChildren);
|
||||
|
||||
CountriesVec const expectedDownloadedChildren = {"Argentina", kDisputedCountryId2,
|
||||
kDisputedCountryId1};
|
||||
CountriesVec const expectedDownloadedChildren = {"Argentina", kDisputedCountryId2, kDisputedCountryId1};
|
||||
TEST_EQUAL(downloadedChildren, expectedDownloadedChildren, ());
|
||||
TEST_EQUAL(availChildren.size(), 223, ());
|
||||
|
||||
|
||||
@@ -30,24 +30,21 @@ static FrameworkParams const kFrameworkParams(false /* m_enableDiffs */);
|
||||
string const kCountriesTxtFile = COUNTRIES_FILE;
|
||||
|
||||
string const kMwmVersion1 = "190830";
|
||||
//size_t const kCountriesTxtFileSize1 = 420632;
|
||||
// size_t const kCountriesTxtFileSize1 = 420632;
|
||||
|
||||
string const kMwmVersion2 = "190910";
|
||||
//size_t const kCountriesTxtFileSize2 = 420634;
|
||||
// size_t const kCountriesTxtFileSize2 = 420634;
|
||||
|
||||
string const kGroupCountryId = "Belarus";
|
||||
|
||||
bool DownloadFile(string const & url,
|
||||
string const & filePath,
|
||||
size_t fileSize)
|
||||
bool DownloadFile(string const & url, string const & filePath, size_t fileSize)
|
||||
{
|
||||
using namespace downloader;
|
||||
|
||||
DownloadStatus httpStatus;
|
||||
bool finished = false;
|
||||
|
||||
unique_ptr<HttpRequest> request(HttpRequest::GetFile({url}, filePath, fileSize,
|
||||
[&](HttpRequest & request)
|
||||
unique_ptr<HttpRequest> request(HttpRequest::GetFile({url}, filePath, fileSize, [&](HttpRequest & request)
|
||||
{
|
||||
DownloadStatus const s = request.GetStatus();
|
||||
if (s != DownloadStatus::InProgress)
|
||||
|
||||
@@ -9,6 +9,6 @@
|
||||
UNIT_TEST(CalculateWorldSHA)
|
||||
{
|
||||
auto const path = GetPlatform().ResourcesDir();
|
||||
for (char const * country : { WORLD_FILE_NAME, WORLD_COASTS_FILE_NAME })
|
||||
for (char const * country : {WORLD_FILE_NAME, WORLD_COASTS_FILE_NAME})
|
||||
LOG(LINFO, (country, coding::SHA1::CalculateBase64(path + country + DATA_FILE_EXTENSION)));
|
||||
}
|
||||
|
||||
@@ -45,7 +45,8 @@ class RandomPointGenerator
|
||||
{
|
||||
public:
|
||||
explicit RandomPointGenerator(mt19937 & randomEngine, vector<m2::RegionD> const & regions)
|
||||
: m_randomEngine(randomEngine), m_regions(regions)
|
||||
: m_randomEngine(randomEngine)
|
||||
, m_regions(regions)
|
||||
{
|
||||
CHECK(!m_regions.empty(), ());
|
||||
vector<double> areas(m_regions.size());
|
||||
@@ -102,36 +103,28 @@ UNIT_TEST(CountryInfoGetter_GetRegionsCountryIdByRect_Smoke)
|
||||
|
||||
// Single mwm.
|
||||
m2::PointD const halfSize = m2::PointD(0.1, 0.1);
|
||||
auto const countries =
|
||||
getter->GetRegionsCountryIdByRect(m2::RectD(p - halfSize, p + halfSize), false /* rough */);
|
||||
auto const countries = getter->GetRegionsCountryIdByRect(m2::RectD(p - halfSize, p + halfSize), false /* rough */);
|
||||
TEST_EQUAL(countries, vector<storage::CountryId>{"Russia_Bryansk Oblast"}, ());
|
||||
|
||||
// Several countries.
|
||||
m2::PointD const halfSize2 = m2::PointD(0.5, 0.5);
|
||||
auto const countries2 =
|
||||
getter->GetRegionsCountryIdByRect(m2::RectD(p - halfSize2, p + halfSize2), false /* rough */);
|
||||
auto const expected = vector<storage::CountryId>{
|
||||
"Belarus_Homiel Region", "Russia_Bryansk Oblast", "Ukraine_Chernihiv Oblast"};
|
||||
auto const countries2 = getter->GetRegionsCountryIdByRect(m2::RectD(p - halfSize2, p + halfSize2), false /* rough */);
|
||||
auto const expected =
|
||||
vector<storage::CountryId>{"Belarus_Homiel Region", "Russia_Bryansk Oblast", "Ukraine_Chernihiv Oblast"};
|
||||
TEST_EQUAL(countries2, expected, ());
|
||||
|
||||
// No one found.
|
||||
auto const countries3 =
|
||||
getter->GetRegionsCountryIdByRect(m2::RectD(-halfSize, halfSize), false /* rough */);
|
||||
auto const countries3 = getter->GetRegionsCountryIdByRect(m2::RectD(-halfSize, halfSize), false /* rough */);
|
||||
TEST_EQUAL(countries3, vector<storage::CountryId>{}, ());
|
||||
|
||||
// Inside mwm (rough).
|
||||
auto const countries4 =
|
||||
getter->GetRegionsCountryIdByRect(m2::RectD(p - halfSize, p + halfSize), true /* rough */);
|
||||
auto const countries4 = getter->GetRegionsCountryIdByRect(m2::RectD(p - halfSize, p + halfSize), true /* rough */);
|
||||
TEST_EQUAL(countries, vector<storage::CountryId>{"Russia_Bryansk Oblast"}, ());
|
||||
|
||||
// Several countries (rough).
|
||||
auto const countries5 =
|
||||
getter->GetRegionsCountryIdByRect(m2::RectD(p - halfSize2, p + halfSize2), true /* rough */);
|
||||
auto const expected2 = vector<storage::CountryId>{"Belarus_Homiel Region",
|
||||
"Belarus_Maglieu Region",
|
||||
"Russia_Bryansk Oblast",
|
||||
"Ukraine_Chernihiv Oblast",
|
||||
"US_Alaska"};
|
||||
auto const countries5 = getter->GetRegionsCountryIdByRect(m2::RectD(p - halfSize2, p + halfSize2), true /* rough */);
|
||||
auto const expected2 = vector<storage::CountryId>{"Belarus_Homiel Region", "Belarus_Maglieu Region",
|
||||
"Russia_Bryansk Oblast", "Ukraine_Chernihiv Oblast", "US_Alaska"};
|
||||
TEST_EQUAL(countries5, expected2, ());
|
||||
}
|
||||
|
||||
@@ -180,8 +173,7 @@ UNIT_TEST(CountryInfoGetter_HitsOnLongLine)
|
||||
CountriesVec results;
|
||||
getter->GetRegionsCountryId(mercator::FromLatLon(62.2507, -102.0753), results);
|
||||
TEST_EQUAL(results.size(), 2, ());
|
||||
TEST(find(results.begin(), results.end(), "Canada_Northwest Territories_East") != results.end(),
|
||||
());
|
||||
TEST(find(results.begin(), results.end(), "Canada_Northwest Territories_East") != results.end(), ());
|
||||
TEST(find(results.begin(), results.end(), "Canada_Nunavut_South") != results.end(), ());
|
||||
}
|
||||
|
||||
@@ -191,8 +183,7 @@ UNIT_TEST(CountryInfoGetter_HitsInTheMiddleOfNowhere)
|
||||
CountriesVec results;
|
||||
getter->GetRegionsCountryId(mercator::FromLatLon(62.2900, -103.9423), results);
|
||||
TEST_EQUAL(results.size(), 1, ());
|
||||
TEST(find(results.begin(), results.end(), "Canada_Northwest Territories_East") != results.end(),
|
||||
());
|
||||
TEST(find(results.begin(), results.end(), "Canada_Northwest Territories_East") != results.end(), ());
|
||||
}
|
||||
|
||||
UNIT_TEST(CountryInfoGetter_BorderRelations)
|
||||
@@ -200,11 +191,9 @@ UNIT_TEST(CountryInfoGetter_BorderRelations)
|
||||
auto const getter = CreateCountryInfoGetter();
|
||||
|
||||
ms::LatLon labels[] = {
|
||||
{42.4318876, -8.6431592}, {42.6075172, -8.4714942},
|
||||
{42.3436415, -7.8674242}, {42.1968459, -7.6114105},
|
||||
{43.0118437, -7.5565749}, {43.0462247, -7.4739921},
|
||||
{43.3709703, -8.3959425}, {43.0565609, -8.5296941},
|
||||
{27.0006968, 49.6532161},
|
||||
{42.4318876, -8.6431592}, {42.6075172, -8.4714942}, {42.3436415, -7.8674242},
|
||||
{42.1968459, -7.6114105}, {43.0118437, -7.5565749}, {43.0462247, -7.4739921},
|
||||
{43.3709703, -8.3959425}, {43.0565609, -8.5296941}, {27.0006968, 49.6532161},
|
||||
};
|
||||
|
||||
for (auto const & ll : labels)
|
||||
@@ -221,8 +210,8 @@ UNIT_TEST(CountryInfoGetter_GetLimitRectForLeafSingleMwm)
|
||||
Storage storage;
|
||||
|
||||
m2::RectD const boundingBox = getter->GetLimitRectForLeaf("Angola");
|
||||
m2::RectD const expectedBoundingBox = {9.205259 /* minX */, -18.34456 /* minY */,
|
||||
24.08212 /* maxX */, -4.393187 /* maxY */};
|
||||
m2::RectD const expectedBoundingBox = {9.205259 /* minX */, -18.34456 /* minY */, 24.08212 /* maxX */,
|
||||
-4.393187 /* maxY */};
|
||||
|
||||
TEST(AlmostEqualAbs(boundingBox, expectedBoundingBox, kRectCompareEpsilon), ());
|
||||
}
|
||||
@@ -263,10 +252,7 @@ UNIT_TEST(CountryInfoGetter_Countries_And_Polygons)
|
||||
|
||||
// Set is used here because disputed territories may occur as leaves several times.
|
||||
set<CountryId> storageLeaves;
|
||||
storage.ForEachCountry([&](Country const & country)
|
||||
{
|
||||
storageLeaves.insert(country.Name());
|
||||
});
|
||||
storage.ForEachCountry([&](Country const & country) { storageLeaves.insert(country.Name()); });
|
||||
|
||||
TEST_EQUAL(countries.size(), storageLeaves.size(), ());
|
||||
|
||||
@@ -312,10 +298,8 @@ BENCHMARK_TEST(CountryInfoGetter_RegionsByRect)
|
||||
|
||||
size_t totalPoints = 0;
|
||||
for (auto const & regs : allRegions)
|
||||
{
|
||||
for (auto const & reg : regs)
|
||||
totalPoints += reg.Size();
|
||||
}
|
||||
LOG(LINFO, ("Total points:", totalPoints));
|
||||
|
||||
{
|
||||
@@ -379,8 +363,7 @@ BENCHMARK_TEST(CountryInfoGetter_RegionsByRect)
|
||||
longest = countryId;
|
||||
}
|
||||
|
||||
LOG(LINFO, ("Slowest country for CountryInfoGetter (random point)", longest,
|
||||
avgTimeByCountry[longest]));
|
||||
LOG(LINFO, ("Slowest country for CountryInfoGetter (random point)", longest, avgTimeByCountry[longest]));
|
||||
}
|
||||
|
||||
{
|
||||
@@ -420,8 +403,7 @@ BENCHMARK_TEST(CountryInfoGetter_RegionsByRect)
|
||||
if (longest.empty() || avgTimeByCountry[longest] < avgTimeByCountry[countryId])
|
||||
longest = countryId;
|
||||
}
|
||||
LOG(LINFO, ("Slowest country for CountryInfoGetter (point on a random side)", longest,
|
||||
avgTimeByCountry[longest]));
|
||||
LOG(LINFO, ("Slowest country for CountryInfoGetter (point on a random side)", longest, avgTimeByCountry[longest]));
|
||||
}
|
||||
}
|
||||
} // namespace country_info_getter_tests
|
||||
} // namespace country_info_getter_tests
|
||||
|
||||
@@ -11,9 +11,7 @@ namespace downloader_tests
|
||||
|
||||
class DownloaderStub : public storage::MapFilesDownloaderWithPing
|
||||
{
|
||||
virtual void Download(storage::QueuedCountry && queuedCountry)
|
||||
{
|
||||
}
|
||||
virtual void Download(storage::QueuedCountry && queuedCountry) {}
|
||||
};
|
||||
|
||||
UNIT_TEST(GetMetaConfig)
|
||||
@@ -32,4 +30,4 @@ UNIT_TEST(GetMetaConfig)
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace downloader_tests
|
||||
} // namespace downloader_tests
|
||||
|
||||
@@ -13,13 +13,15 @@ namespace storage
|
||||
{
|
||||
int64_t const FakeMapFilesDownloader::kBlockSize;
|
||||
|
||||
FakeMapFilesDownloader::FakeMapFilesDownloader(TaskRunner & taskRunner)
|
||||
: m_timestamp(0), m_taskRunner(taskRunner)
|
||||
FakeMapFilesDownloader::FakeMapFilesDownloader(TaskRunner & taskRunner) : m_timestamp(0), m_taskRunner(taskRunner)
|
||||
{
|
||||
SetServersList({"http://test-url/"});
|
||||
}
|
||||
|
||||
FakeMapFilesDownloader::~FakeMapFilesDownloader() { CHECK_THREAD_CHECKER(m_checker, ()); }
|
||||
FakeMapFilesDownloader::~FakeMapFilesDownloader()
|
||||
{
|
||||
CHECK_THREAD_CHECKER(m_checker, ());
|
||||
}
|
||||
|
||||
void FakeMapFilesDownloader::Download(QueuedCountry && queuedCountry)
|
||||
{
|
||||
|
||||
@@ -45,8 +45,7 @@ private:
|
||||
|
||||
void Download();
|
||||
void DownloadNextChunk(uint64_t requestId);
|
||||
void OnFileDownloaded(QueuedCountry const & queuedCountry,
|
||||
downloader::DownloadStatus const & status);
|
||||
void OnFileDownloaded(QueuedCountry const & queuedCountry, downloader::DownloadStatus const & status);
|
||||
|
||||
downloader::Progress m_progress;
|
||||
|
||||
|
||||
@@ -10,4 +10,4 @@ class CountryInfoGetter;
|
||||
|
||||
std::unique_ptr<CountryInfoGetter> CreateCountryInfoGetter();
|
||||
|
||||
} // namespace storage
|
||||
} // namespace storage
|
||||
|
||||
@@ -71,8 +71,7 @@ public:
|
||||
class SometimesFailingDownloadingPolicy : public DownloadingPolicy
|
||||
{
|
||||
public:
|
||||
explicit SometimesFailingDownloadingPolicy(vector<uint64_t> const & failedRequests)
|
||||
: m_failedRequests(failedRequests)
|
||||
explicit SometimesFailingDownloadingPolicy(vector<uint64_t> const & failedRequests) : m_failedRequests(failedRequests)
|
||||
{
|
||||
std::sort(m_failedRequests.begin(), m_failedRequests.end());
|
||||
}
|
||||
@@ -91,7 +90,8 @@ private:
|
||||
|
||||
string const kCountriesTxt = string(R"({
|
||||
"id": "Countries",
|
||||
"v": )" + strings::to_string(version::FOR_TESTING_MWM1) + R"(,
|
||||
"v": )" + strings::to_string(version::FOR_TESTING_MWM1) +
|
||||
R"(,
|
||||
"g": [
|
||||
{
|
||||
"id": "Abkhazia",
|
||||
@@ -235,9 +235,8 @@ public:
|
||||
, m_currStatus(0)
|
||||
, m_transitionList(transitionList)
|
||||
{
|
||||
m_slot = m_storage.Subscribe(
|
||||
bind(&CountryDownloaderChecker::OnCountryStatusChanged, this, _1),
|
||||
bind(&CountryDownloaderChecker::OnCountryDownloadingProgress, this, _1, _2));
|
||||
m_slot = m_storage.Subscribe(bind(&CountryDownloaderChecker::OnCountryStatusChanged, this, _1),
|
||||
bind(&CountryDownloaderChecker::OnCountryDownloadingProgress, this, _1, _2));
|
||||
TEST(storage.IsLeaf(countryId), (m_countryFile));
|
||||
TEST(!m_transitionList.empty(), (m_countryFile));
|
||||
}
|
||||
@@ -263,35 +262,32 @@ protected:
|
||||
return;
|
||||
|
||||
Status const nexStatus = m_storage.CountryStatusEx(m_countryId);
|
||||
LOG(LINFO, (m_countryFile, "status transition: from", m_transitionList[m_currStatus], "to",
|
||||
nexStatus));
|
||||
LOG(LINFO, (m_countryFile, "status transition: from", m_transitionList[m_currStatus], "to", nexStatus));
|
||||
TEST_LESS(m_currStatus + 1, m_transitionList.size(), (m_countryFile));
|
||||
TEST_EQUAL(nexStatus, m_transitionList[m_currStatus + 1], (m_countryFile));
|
||||
++m_currStatus;
|
||||
if (m_transitionList[m_currStatus] == Status::Downloading ||
|
||||
m_transitionList[m_currStatus] == Status::InQueue)
|
||||
if (m_transitionList[m_currStatus] == Status::Downloading || m_transitionList[m_currStatus] == Status::InQueue)
|
||||
{
|
||||
LocalAndRemoteSize localAndRemoteSize = m_storage.CountrySizeInBytes(m_countryId);
|
||||
m_totalBytesToDownload = localAndRemoteSize.second;
|
||||
}
|
||||
}
|
||||
|
||||
virtual void OnCountryDownloadingProgress(CountryId const & countryId,
|
||||
downloader::Progress const & progress)
|
||||
virtual void OnCountryDownloadingProgress(CountryId const & countryId, downloader::Progress const & progress)
|
||||
{
|
||||
if (countryId != m_countryId)
|
||||
return;
|
||||
|
||||
LOG(LINFO, (m_countryFile, "downloading progress:", progress));
|
||||
|
||||
TEST_GREATER(progress.m_bytesDownloaded, static_cast<
|
||||
decltype(progress.m_bytesDownloaded)>(m_bytesDownloaded), (m_countryFile));
|
||||
TEST_GREATER(progress.m_bytesDownloaded, static_cast<decltype(progress.m_bytesDownloaded)>(m_bytesDownloaded),
|
||||
(m_countryFile));
|
||||
m_bytesDownloaded = progress.m_bytesDownloaded;
|
||||
TEST_LESS_OR_EQUAL(m_bytesDownloaded, m_totalBytesToDownload, (m_countryFile));
|
||||
|
||||
LocalAndRemoteSize localAndRemoteSize = m_storage.CountrySizeInBytes(m_countryId);
|
||||
TEST_EQUAL(static_cast<decltype(localAndRemoteSize.second)>(m_totalBytesToDownload),
|
||||
localAndRemoteSize.second, (m_countryFile));
|
||||
TEST_EQUAL(static_cast<decltype(localAndRemoteSize.second)>(m_totalBytesToDownload), localAndRemoteSize.second,
|
||||
(m_countryFile));
|
||||
}
|
||||
|
||||
Storage & m_storage;
|
||||
@@ -309,27 +305,22 @@ protected:
|
||||
class CancelDownloadingWhenAlmostDoneChecker : public CountryDownloaderChecker
|
||||
{
|
||||
public:
|
||||
CancelDownloadingWhenAlmostDoneChecker(Storage & storage, CountryId const & countryId,
|
||||
TaskRunner & runner)
|
||||
CancelDownloadingWhenAlmostDoneChecker(Storage & storage, CountryId const & countryId, TaskRunner & runner)
|
||||
: CountryDownloaderChecker(
|
||||
storage, countryId, MapFileType::Map,
|
||||
vector<Status>{Status::NotDownloaded, Status::InQueue, Status::Downloading, Status::NotDownloaded})
|
||||
, m_runner(runner)
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
protected:
|
||||
// CountryDownloaderChecker overrides:
|
||||
void OnCountryDownloadingProgress(CountryId const & countryId,
|
||||
downloader::Progress const & progress) override
|
||||
void OnCountryDownloadingProgress(CountryId const & countryId, downloader::Progress const & progress) override
|
||||
{
|
||||
CountryDownloaderChecker::OnCountryDownloadingProgress(countryId, progress);
|
||||
|
||||
// Cancel downloading when almost done.
|
||||
if (progress.m_bytesDownloaded + 2 * FakeMapFilesDownloader::kBlockSize >= progress.m_bytesTotal)
|
||||
{
|
||||
m_runner.PostTask([&]() { m_storage.CancelDownloadNode(m_countryId); });
|
||||
}
|
||||
}
|
||||
|
||||
TaskRunner & m_runner;
|
||||
@@ -337,8 +328,8 @@ protected:
|
||||
|
||||
// Checks following state transitions:
|
||||
// NotDownloaded -> Downloading -> OnDisk.
|
||||
unique_ptr<CountryDownloaderChecker> AbsentCountryDownloaderChecker(
|
||||
Storage & storage, CountryId const & countryId, MapFileType type)
|
||||
unique_ptr<CountryDownloaderChecker> AbsentCountryDownloaderChecker(Storage & storage, CountryId const & countryId,
|
||||
MapFileType type)
|
||||
{
|
||||
return make_unique<CountryDownloaderChecker>(
|
||||
storage, countryId, type,
|
||||
@@ -347,8 +338,8 @@ unique_ptr<CountryDownloaderChecker> AbsentCountryDownloaderChecker(
|
||||
|
||||
// Checks following state transitions:
|
||||
// NotDownloaded -> Downloading -> NotDownloaded.
|
||||
unique_ptr<CountryDownloaderChecker> CancelledCountryDownloaderChecker(
|
||||
Storage & storage, CountryId const & countryId, MapFileType type)
|
||||
unique_ptr<CountryDownloaderChecker> CancelledCountryDownloaderChecker(Storage & storage, CountryId const & countryId,
|
||||
MapFileType type)
|
||||
{
|
||||
return make_unique<CountryDownloaderChecker>(
|
||||
storage, countryId, type,
|
||||
@@ -359,11 +350,13 @@ class CountryStatusChecker
|
||||
{
|
||||
public:
|
||||
CountryStatusChecker(Storage & storage, CountryId const & countryId, Status status)
|
||||
: m_storage(storage), m_countryId(countryId), m_status(status), m_triggered(false)
|
||||
: m_storage(storage)
|
||||
, m_countryId(countryId)
|
||||
, m_status(status)
|
||||
, m_triggered(false)
|
||||
{
|
||||
m_slot = m_storage.Subscribe(
|
||||
std::bind(&CountryStatusChecker::OnCountryStatusChanged, this, _1),
|
||||
std::bind(&CountryStatusChecker::OnCountryDownloadingProgress, this, _1, _2));
|
||||
m_slot = m_storage.Subscribe(std::bind(&CountryStatusChecker::OnCountryStatusChanged, this, _1),
|
||||
std::bind(&CountryStatusChecker::OnCountryDownloadingProgress, this, _1, _2));
|
||||
}
|
||||
|
||||
~CountryStatusChecker()
|
||||
@@ -383,8 +376,7 @@ private:
|
||||
m_triggered = true;
|
||||
}
|
||||
|
||||
void OnCountryDownloadingProgress(CountryId const & /* countryId */,
|
||||
downloader::Progress const & /* progress */)
|
||||
void OnCountryDownloadingProgress(CountryId const & /* countryId */, downloader::Progress const & /* progress */)
|
||||
{
|
||||
TEST(false, ("Unexpected country downloading progress."));
|
||||
}
|
||||
@@ -400,7 +392,9 @@ class FailedDownloadingWaiter
|
||||
{
|
||||
public:
|
||||
FailedDownloadingWaiter(Storage & storage, CountryId const & countryId)
|
||||
: m_storage(storage), m_countryId(countryId), m_finished(false)
|
||||
: m_storage(storage)
|
||||
, m_countryId(countryId)
|
||||
, m_finished(false)
|
||||
{
|
||||
m_slot = m_storage.Subscribe(std::bind(&FailedDownloadingWaiter::OnStatusChanged, this, _1),
|
||||
std::bind(&FailedDownloadingWaiter::OnProgress, this, _1, _2));
|
||||
@@ -415,10 +409,7 @@ public:
|
||||
void Wait()
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(m_mu);
|
||||
m_cv.wait(lock, [this]()
|
||||
{
|
||||
return m_finished;
|
||||
});
|
||||
m_cv.wait(lock, [this]() { return m_finished; });
|
||||
}
|
||||
|
||||
void OnStatusChanged(CountryId const & countryId)
|
||||
@@ -454,8 +445,7 @@ void OnCountryDownloaded(CountryId const & countryId, LocalFilePtr const localFi
|
||||
|
||||
LocalFilePtr CreateDummyMapFile(CountryFile const & countryFile, int64_t version, uint64_t size)
|
||||
{
|
||||
LocalFilePtr localFile =
|
||||
PreparePlaceForCountryFiles(version, string() /* dataDir */, countryFile);
|
||||
LocalFilePtr localFile = PreparePlaceForCountryFiles(version, string() /* dataDir */, countryFile);
|
||||
TEST(localFile.get(), ("Can't prepare place for", countryFile, "(version", version, ")"));
|
||||
{
|
||||
string const zeroes(size, '\0');
|
||||
@@ -468,8 +458,7 @@ LocalFilePtr CreateDummyMapFile(CountryFile const & countryFile, int64_t version
|
||||
return localFile;
|
||||
}
|
||||
|
||||
void InitStorage(Storage & storage, TaskRunner & runner,
|
||||
Storage::UpdateCallback const & update = &OnCountryDownloaded)
|
||||
void InitStorage(Storage & storage, TaskRunner & runner, Storage::UpdateCallback const & update = &OnCountryDownloaded)
|
||||
{
|
||||
storage.Clear();
|
||||
storage.Init(update, [](CountryId const &, LocalFilePtr const) { return false; });
|
||||
@@ -495,7 +484,8 @@ UNIT_TEST(StorageTest_ParseIndexFile)
|
||||
Storage storage;
|
||||
|
||||
TEST_EQUAL(storage.ParseIndexAndGetDataVersion(R"([ { "21010101" : 210317 } ])"), 210317, ());
|
||||
TEST_EQUAL(storage.ParseIndexAndGetDataVersion(R"([ { "21010101" : 210317 }, { "21041001" : 210409 } ])"), 210409, ());
|
||||
TEST_EQUAL(storage.ParseIndexAndGetDataVersion(R"([ { "21010101" : 210317 }, { "21041001" : 210409 } ])"), 210409,
|
||||
());
|
||||
|
||||
// Invalid jsons
|
||||
TEST_EQUAL(storage.ParseIndexAndGetDataVersion(R"([ { "21010101" : 210317 })"), 0, ());
|
||||
@@ -523,8 +513,7 @@ UNIT_CLASS_TEST(StorageTest, CountryDownloading)
|
||||
storage.DeleteCountry(azerbaijanCountryId, MapFileType::Map);
|
||||
|
||||
{
|
||||
SCOPE_GUARD(cleanupCountryFiles,
|
||||
bind(&Storage::DeleteCountry, &storage, azerbaijanCountryId, MapFileType::Map));
|
||||
SCOPE_GUARD(cleanupCountryFiles, bind(&Storage::DeleteCountry, &storage, azerbaijanCountryId, MapFileType::Map));
|
||||
unique_ptr<CountryDownloaderChecker> checker =
|
||||
AbsentCountryDownloaderChecker(storage, azerbaijanCountryId, MapFileType::Map);
|
||||
checker->StartDownload();
|
||||
@@ -532,8 +521,7 @@ UNIT_CLASS_TEST(StorageTest, CountryDownloading)
|
||||
}
|
||||
|
||||
{
|
||||
SCOPE_GUARD(cleanupCountryFiles,
|
||||
bind(&Storage::DeleteCountry, &storage, azerbaijanCountryId, MapFileType::Map));
|
||||
SCOPE_GUARD(cleanupCountryFiles, bind(&Storage::DeleteCountry, &storage, azerbaijanCountryId, MapFileType::Map));
|
||||
unique_ptr<CountryDownloaderChecker> checker =
|
||||
AbsentCountryDownloaderChecker(storage, azerbaijanCountryId, MapFileType::Map);
|
||||
checker->StartDownload();
|
||||
@@ -619,8 +607,7 @@ UNIT_CLASS_TEST(StorageTest, CancelDownloadingWhenAlmostDone)
|
||||
UNIT_CLASS_TEST(StorageTest, DeleteCountry)
|
||||
{
|
||||
tests_support::ScopedFile map("Wonderland.mwm", ScopedFile::Mode::Create);
|
||||
LocalCountryFile file = LocalCountryFile::MakeForTesting("Wonderland",
|
||||
version::FOR_TESTING_MWM1);
|
||||
LocalCountryFile file = LocalCountryFile::MakeForTesting("Wonderland", version::FOR_TESTING_MWM1);
|
||||
TEST(file.OnDisk(MapFileType::Map), ());
|
||||
|
||||
CountryIndexes::PreparePlaceOnDisk(file);
|
||||
@@ -656,7 +643,8 @@ UNIT_TEST(StorageTest_FailedDownloading)
|
||||
// To prevent interference from other tests and on other tests it's
|
||||
// better to remove temprorary downloader files.
|
||||
DeleteDownloaderFilesForCountry(storage.GetCurrentDataVersion(), countryFile);
|
||||
SCOPE_GUARD(cleanup, [&]() {
|
||||
SCOPE_GUARD(cleanup, [&]()
|
||||
{
|
||||
DeleteDownloaderFilesForCountry(storage.GetCurrentDataVersion(), countryFile);
|
||||
// Failed country is added into the "retry later" list, and fails next test.
|
||||
storage.Clear();
|
||||
@@ -669,7 +657,8 @@ UNIT_TEST(StorageTest_FailedDownloading)
|
||||
}
|
||||
|
||||
// File wasn't downloaded, but temprorary downloader files must exist.
|
||||
string const downloadPath = GetFileDownloadPath(storage.GetCurrentDataVersion(), countryFile.GetName(), MapFileType::Map);
|
||||
string const downloadPath =
|
||||
GetFileDownloadPath(storage.GetCurrentDataVersion(), countryFile.GetName(), MapFileType::Map);
|
||||
TEST(!Platform::IsFileExistsByFullPath(downloadPath), ());
|
||||
TEST(Platform::IsFileExistsByFullPath(downloadPath + DOWNLOADING_FILE_EXTENSION), ());
|
||||
TEST(Platform::IsFileExistsByFullPath(downloadPath + RESUME_FILE_EXTENSION), ());
|
||||
@@ -704,9 +693,11 @@ UNIT_TEST(StorageTest_GetRootId)
|
||||
{
|
||||
Storage storage(string(R"({
|
||||
"id": "Countries",
|
||||
"v": )" + strings::to_string(version::FOR_TESTING_MWM1) + R"(,
|
||||
"v": )" +
|
||||
strings::to_string(version::FOR_TESTING_MWM1) + R"(,
|
||||
"g": []
|
||||
})"), make_unique<TestMapFilesDownloader>());
|
||||
})"),
|
||||
make_unique<TestMapFilesDownloader>());
|
||||
|
||||
// The name of the root is the same for courntries.txt version 1 and version 2.
|
||||
TEST_EQUAL(storage.GetRootId(), COUNTRIES_ROOT, ());
|
||||
@@ -755,8 +746,7 @@ UNIT_TEST(StorageTest_GetAffiliations)
|
||||
|
||||
UNIT_TEST(StorageTest_HasCountryId)
|
||||
{
|
||||
CountriesVec middleEarthCountryIdVec = {"Arnor", "Mordor", "Rhovanion", "Rhun",
|
||||
"Gondor", "Eriador", "Rohan"};
|
||||
CountriesVec middleEarthCountryIdVec = {"Arnor", "Mordor", "Rhovanion", "Rhun", "Gondor", "Eriador", "Rohan"};
|
||||
sort(middleEarthCountryIdVec.begin(), middleEarthCountryIdVec.end());
|
||||
}
|
||||
|
||||
@@ -772,19 +762,16 @@ UNIT_CLASS_TEST(StorageTest, DownloadedMap)
|
||||
|
||||
SCOPE_GUARD(cleanupAlgeriaCentral,
|
||||
bind(&Storage::DeleteCountry, &storage, algeriaCentralCountryId, MapFileType::Map));
|
||||
SCOPE_GUARD(cleanupAlgeriaCoast,
|
||||
bind(&Storage::DeleteCountry, &storage, algeriaCoastCountryId, MapFileType::Map));
|
||||
SCOPE_GUARD(cleanupAlgeriaCoast, bind(&Storage::DeleteCountry, &storage, algeriaCoastCountryId, MapFileType::Map));
|
||||
|
||||
{
|
||||
auto algeriaCentralChecker = make_unique<CountryDownloaderChecker>(
|
||||
storage, algeriaCentralCountryId, MapFileType::Map,
|
||||
vector<Status>{Status::NotDownloaded, Status::InQueue, Status::Downloading,
|
||||
Status::OnDisk});
|
||||
vector<Status>{Status::NotDownloaded, Status::InQueue, Status::Downloading, Status::OnDisk});
|
||||
|
||||
auto algeriaCoastChecker = make_unique<CountryDownloaderChecker>(
|
||||
storage, algeriaCoastCountryId, MapFileType::Map,
|
||||
vector<Status>{Status::NotDownloaded, Status::InQueue, Status::Downloading,
|
||||
Status::OnDisk});
|
||||
vector<Status>{Status::NotDownloaded, Status::InQueue, Status::Downloading, Status::OnDisk});
|
||||
|
||||
algeriaCentralChecker->StartDownload();
|
||||
algeriaCoastChecker->StartDownload();
|
||||
@@ -792,9 +779,9 @@ UNIT_CLASS_TEST(StorageTest, DownloadedMap)
|
||||
}
|
||||
|
||||
// Storage::GetLocalRealMaps() test.
|
||||
// CountriesVec localRealMaps;
|
||||
// storage.GetLocalRealMaps(localRealMaps);
|
||||
// TEST_EQUAL(localRealMaps.size(), 4, ());
|
||||
// CountriesVec localRealMaps;
|
||||
// storage.GetLocalRealMaps(localRealMaps);
|
||||
// TEST_EQUAL(localRealMaps.size(), 4, ());
|
||||
|
||||
TEST(storage.IsNodeDownloaded("Algeria_Central"), ());
|
||||
TEST(storage.IsNodeDownloaded("Algeria_Coast"), ());
|
||||
@@ -812,24 +799,22 @@ UNIT_CLASS_TEST(StorageTest, DownloadedMap)
|
||||
TEST_EQUAL(available.size(), 223, ());
|
||||
|
||||
CountriesVec downloadedWithKeep, availableWithKeep;
|
||||
storage.GetChildrenInGroups(rootCountryId, downloadedWithKeep,
|
||||
availableWithKeep, true /* keepAvailableChildren*/);
|
||||
storage.GetChildrenInGroups(rootCountryId, downloadedWithKeep, availableWithKeep, true /* keepAvailableChildren*/);
|
||||
TEST_EQUAL(downloadedWithKeep.size(), 1, (downloadedWithKeep));
|
||||
TEST_EQUAL(availableWithKeep.size(), 224, ());
|
||||
|
||||
storage.GetChildrenInGroups("Algeria", downloaded, available);
|
||||
TEST_EQUAL(downloaded.size(), 2, (downloaded));
|
||||
|
||||
storage.GetChildrenInGroups("Algeria", downloadedWithKeep,
|
||||
availableWithKeep, true /* keepAvailableChildren*/);
|
||||
storage.GetChildrenInGroups("Algeria", downloadedWithKeep, availableWithKeep, true /* keepAvailableChildren*/);
|
||||
TEST_EQUAL(downloadedWithKeep.size(), 2, (downloadedWithKeep));
|
||||
TEST_EQUAL(availableWithKeep.size(), 2, (availableWithKeep));
|
||||
|
||||
storage.GetChildrenInGroups("Algeria_Central", downloaded, available);
|
||||
TEST(downloaded.empty(), ());
|
||||
|
||||
storage.GetChildrenInGroups("Algeria_Central", downloadedWithKeep,
|
||||
availableWithKeep, true /* keepAvailableChildren*/);
|
||||
storage.GetChildrenInGroups("Algeria_Central", downloadedWithKeep, availableWithKeep,
|
||||
true /* keepAvailableChildren*/);
|
||||
TEST_EQUAL(downloadedWithKeep.size(), 0, (downloadedWithKeep));
|
||||
TEST_EQUAL(availableWithKeep.size(), 0, (availableWithKeep));
|
||||
|
||||
@@ -839,8 +824,7 @@ UNIT_CLASS_TEST(StorageTest, DownloadedMap)
|
||||
storage.GetChildrenInGroups(rootCountryId, downloaded, available);
|
||||
TEST_EQUAL(downloaded.size(), 1, (downloaded));
|
||||
|
||||
storage.GetChildrenInGroups("Algeria", downloadedWithKeep,
|
||||
availableWithKeep, true /* keepAvailableChildren*/);
|
||||
storage.GetChildrenInGroups("Algeria", downloadedWithKeep, availableWithKeep, true /* keepAvailableChildren*/);
|
||||
TEST_EQUAL(downloadedWithKeep.size(), 1, (downloadedWithKeep));
|
||||
TEST_EQUAL(availableWithKeep.size(), 2, (availableWithKeep));
|
||||
|
||||
@@ -873,8 +857,7 @@ UNIT_CLASS_TEST(StorageTest, IsPointCoveredByDownloadedMaps)
|
||||
TEST(!storage::IsPointCoveredByDownloadedMaps(montevideoUruguay, storage, *countryInfoGetter), ());
|
||||
|
||||
{
|
||||
SCOPE_GUARD(cleanupCountryFiles,
|
||||
bind(&Storage::DeleteCountry, &storage, uruguayId, MapFileType::Map));
|
||||
SCOPE_GUARD(cleanupCountryFiles, bind(&Storage::DeleteCountry, &storage, uruguayId, MapFileType::Map));
|
||||
auto const checker = AbsentCountryDownloaderChecker(storage, uruguayId, MapFileType::Map);
|
||||
checker->StartDownload();
|
||||
runner.Run();
|
||||
@@ -948,7 +931,7 @@ UNIT_TEST(StorageTest_GetNodeAttrsSingleMwm)
|
||||
storage.GetNodeAttrs("Algeria", nodeAttrs);
|
||||
TEST_EQUAL(nodeAttrs.m_mwmCounter, 2, ());
|
||||
TEST_EQUAL(nodeAttrs.m_mwmSize, 90878678, ());
|
||||
TEST_EQUAL(nodeAttrs.m_status, NodeStatus::NotDownloaded, ()); // It's a status of expandable node.
|
||||
TEST_EQUAL(nodeAttrs.m_status, NodeStatus::NotDownloaded, ()); // It's a status of expandable node.
|
||||
TEST_EQUAL(nodeAttrs.m_error, NodeErrorCode::NoError, ());
|
||||
TEST_EQUAL(nodeAttrs.m_parentInfo.size(), 1, ());
|
||||
TEST_EQUAL(nodeAttrs.m_parentInfo[0].m_id, COUNTRIES_ROOT, ());
|
||||
@@ -1063,19 +1046,16 @@ UNIT_TEST(StorageTest_GetUpdateInfoSingleMwm)
|
||||
storage.GetUpdateInfo(storage.GetRootId(), updateInfo);
|
||||
TEST_EQUAL(updateInfo.m_numberOfMwmFilesToUpdate, 2, ());
|
||||
TEST_EQUAL(updateInfo.m_totalDownloadSizeInBytes, 1050, ());
|
||||
TEST_EQUAL(updateInfo.m_sizeDifference,
|
||||
(1000 + 50) - static_cast<int64_t>((country1Size + country2Size)), ());
|
||||
TEST_EQUAL(updateInfo.m_sizeDifference, (1000 + 50) - static_cast<int64_t>((country1Size + country2Size)), ());
|
||||
}
|
||||
#endif // defined(OMIM_OS_DESKTOP)
|
||||
|
||||
UNIT_TEST(StorageTest_ParseStatus)
|
||||
{
|
||||
TEST_EQUAL(StatusAndError(NodeStatus::Undefined, NodeErrorCode::NoError),
|
||||
ParseStatus(Status::Undefined), ());
|
||||
TEST_EQUAL(StatusAndError(NodeStatus::Error, NodeErrorCode::NoInetConnection),
|
||||
ParseStatus(Status::DownloadFailed), ());
|
||||
TEST_EQUAL(StatusAndError(NodeStatus::Downloading, NodeErrorCode::NoError),
|
||||
ParseStatus(Status::Downloading), ());
|
||||
TEST_EQUAL(StatusAndError(NodeStatus::Undefined, NodeErrorCode::NoError), ParseStatus(Status::Undefined), ());
|
||||
TEST_EQUAL(StatusAndError(NodeStatus::Error, NodeErrorCode::NoInetConnection), ParseStatus(Status::DownloadFailed),
|
||||
());
|
||||
TEST_EQUAL(StatusAndError(NodeStatus::Downloading, NodeErrorCode::NoError), ParseStatus(Status::Downloading), ());
|
||||
}
|
||||
|
||||
UNIT_TEST(StorageTest_ForEachInSubtree)
|
||||
@@ -1083,7 +1063,8 @@ UNIT_TEST(StorageTest_ForEachInSubtree)
|
||||
Storage storage(kCountriesTxt, make_unique<TestMapFilesDownloader>());
|
||||
|
||||
CountriesVec leafVec;
|
||||
auto const forEach = [&leafVec](CountryId const & descendantId, bool groupNode) {
|
||||
auto const forEach = [&leafVec](CountryId const & descendantId, bool groupNode)
|
||||
{
|
||||
if (!groupNode)
|
||||
leafVec.push_back(descendantId);
|
||||
};
|
||||
@@ -1107,24 +1088,21 @@ UNIT_TEST(StorageTest_ForEachAncestorExceptForTheRoot)
|
||||
Storage storage(kCountriesTxt, make_unique<TestMapFilesDownloader>());
|
||||
|
||||
// Two parent case.
|
||||
auto const forEachParentDisputableTerritory = [](CountryId const & parentId,
|
||||
CountryTree::Node const & parentNode) {
|
||||
auto const forEachParentDisputableTerritory = [](CountryId const & parentId, CountryTree::Node const & parentNode)
|
||||
{
|
||||
CountriesVec descendants;
|
||||
parentNode.ForEachDescendant([&descendants](CountryTree::Node const & container) {
|
||||
descendants.push_back(container.Value().Name());
|
||||
});
|
||||
parentNode.ForEachDescendant([&descendants](CountryTree::Node const & container)
|
||||
{ descendants.push_back(container.Value().Name()); });
|
||||
|
||||
if (parentId == "Country1")
|
||||
{
|
||||
CountriesVec const expectedDescendants = {"Disputable Territory",
|
||||
"Indisputable Territory Of Country1"};
|
||||
CountriesVec const expectedDescendants = {"Disputable Territory", "Indisputable Territory Of Country1"};
|
||||
TEST_EQUAL(descendants, expectedDescendants, ());
|
||||
return;
|
||||
}
|
||||
if (parentId == "Country2")
|
||||
{
|
||||
CountriesVec const expectedDescendants = {"Indisputable Territory Of Country2",
|
||||
"Disputable Territory"};
|
||||
CountriesVec const expectedDescendants = {"Indisputable Territory Of Country2", "Disputable Territory"};
|
||||
TEST_EQUAL(descendants, expectedDescendants, ());
|
||||
return;
|
||||
}
|
||||
@@ -1133,24 +1111,21 @@ UNIT_TEST(StorageTest_ForEachAncestorExceptForTheRoot)
|
||||
storage.ForEachAncestorExceptForTheRoot("Disputable Territory", forEachParentDisputableTerritory);
|
||||
|
||||
// One parent case.
|
||||
auto const forEachParentIndisputableTerritory = [](CountryId const & parentId,
|
||||
CountryTree::Node const & parentNode) {
|
||||
auto const forEachParentIndisputableTerritory = [](CountryId const & parentId, CountryTree::Node const & parentNode)
|
||||
{
|
||||
CountriesVec descendants;
|
||||
parentNode.ForEachDescendant([&descendants](CountryTree::Node const & container) {
|
||||
descendants.push_back(container.Value().Name());
|
||||
});
|
||||
parentNode.ForEachDescendant([&descendants](CountryTree::Node const & container)
|
||||
{ descendants.push_back(container.Value().Name()); });
|
||||
|
||||
if (parentId == "Country1")
|
||||
{
|
||||
CountriesVec const expectedDescendants = {"Disputable Territory",
|
||||
"Indisputable Territory Of Country1"};
|
||||
CountriesVec const expectedDescendants = {"Disputable Territory", "Indisputable Territory Of Country1"};
|
||||
TEST_EQUAL(descendants, expectedDescendants, ());
|
||||
return;
|
||||
}
|
||||
TEST(false, ());
|
||||
};
|
||||
storage.ForEachAncestorExceptForTheRoot("Indisputable Territory Of Country1",
|
||||
forEachParentIndisputableTerritory);
|
||||
storage.ForEachAncestorExceptForTheRoot("Indisputable Territory Of Country1", forEachParentIndisputableTerritory);
|
||||
}
|
||||
|
||||
UNIT_CLASS_TEST(StorageTest, CalcLimitRect)
|
||||
@@ -1159,8 +1134,8 @@ UNIT_CLASS_TEST(StorageTest, CalcLimitRect)
|
||||
ASSERT(countryInfoGetter, ());
|
||||
|
||||
m2::RectD const boundingBox = storage::CalcLimitRect("Algeria", storage, *countryInfoGetter);
|
||||
m2::RectD const expectedBoundingBox = {-8.6689 /* minX */, 19.32443 /* minY */,
|
||||
11.99734 /* maxX */, 45.23 /* maxY */};
|
||||
m2::RectD const expectedBoundingBox = {-8.6689 /* minX */, 19.32443 /* minY */, 11.99734 /* maxX */,
|
||||
45.23 /* maxY */};
|
||||
|
||||
static double constexpr kEpsilon = 1e-2;
|
||||
TEST(AlmostEqualAbs(boundingBox, expectedBoundingBox, kEpsilon), ());
|
||||
@@ -1168,8 +1143,7 @@ UNIT_CLASS_TEST(StorageTest, CalcLimitRect)
|
||||
|
||||
UNIT_TEST(StorageTest_CountriesNamesTest)
|
||||
{
|
||||
string const kRuJson =
|
||||
string(R"json({
|
||||
string const kRuJson = string(R"json({
|
||||
"Countries":"Весь мир",
|
||||
"Abkhazia":"Абхазия",
|
||||
"Algeria":"Алжир",
|
||||
@@ -1182,8 +1156,7 @@ UNIT_TEST(StorageTest_CountriesNamesTest)
|
||||
"Indisputable Territory Of Country2":"Бесспорная территория страны 2"
|
||||
})json");
|
||||
|
||||
string const kFrJson =
|
||||
string(R"json({
|
||||
string const kFrJson = string(R"json({
|
||||
"Countries":"Des pays",
|
||||
"Abkhazia":"Abkhazie",
|
||||
"Algeria":"Algérie",
|
||||
@@ -1244,8 +1217,7 @@ UNIT_TEST(StorageTest_CountriesNamesTest)
|
||||
TEST_EQUAL(nodeAttrs.m_parentInfo.size(), 2, ());
|
||||
TEST_EQUAL(nodeAttrs.m_parentInfo[0].m_localName, "Страна 1", ());
|
||||
TEST_EQUAL(nodeAttrs.m_parentInfo[1].m_localName, "Страна 2", ());
|
||||
vector<CountryIdAndName> const expectedTopmostParentsRu = {{"Country1", "Страна 1"},
|
||||
{"Country2", "Страна 2"}};
|
||||
vector<CountryIdAndName> const expectedTopmostParentsRu = {{"Country1", "Страна 1"}, {"Country2", "Страна 2"}};
|
||||
TEST(nodeAttrs.m_topmostParentInfo == expectedTopmostParentsRu, ());
|
||||
|
||||
// set french locale
|
||||
@@ -1297,8 +1269,7 @@ UNIT_TEST(StorageTest_CountriesNamesTest)
|
||||
TEST_EQUAL(nodeAttrs.m_parentInfo.size(), 2, ());
|
||||
TEST_EQUAL(nodeAttrs.m_parentInfo[0].m_localName, "Pays 1", ());
|
||||
TEST_EQUAL(nodeAttrs.m_parentInfo[1].m_localName, "Pays 2", ());
|
||||
vector<CountryIdAndName> const expectedTopmostParentsFr = {{"Country1", "Pays 1"},
|
||||
{"Country2", "Pays 2"}};
|
||||
vector<CountryIdAndName> const expectedTopmostParentsFr = {{"Country1", "Pays 1"}, {"Country2", "Pays 2"}};
|
||||
TEST(nodeAttrs.m_topmostParentInfo == expectedTopmostParentsFr, ());
|
||||
}
|
||||
|
||||
@@ -1453,10 +1424,7 @@ UNIT_TEST(StorageTest_FalsePolicy)
|
||||
// To prevent interference with other tests and on other tests it's
|
||||
// better to remove temporary downloader files.
|
||||
DeleteDownloaderFilesForCountry(storage.GetCurrentDataVersion(), countryFile);
|
||||
SCOPE_GUARD(cleanup, [&]() {
|
||||
DeleteDownloaderFilesForCountry(storage.GetCurrentDataVersion(),
|
||||
countryFile);
|
||||
});
|
||||
SCOPE_GUARD(cleanup, [&]() { DeleteDownloaderFilesForCountry(storage.GetCurrentDataVersion(), countryFile); });
|
||||
|
||||
{
|
||||
FailedDownloadingWaiter waiter(storage, countryId);
|
||||
@@ -1470,7 +1438,7 @@ UNIT_CLASS_TEST(StorageTest, MultipleMaps)
|
||||
// network policy sometimes changes, therefore some countries won't
|
||||
// be downloaded.
|
||||
|
||||
vector<uint64_t> const failedRequests {{5, 10, 21}};
|
||||
vector<uint64_t> const failedRequests{{5, 10, 21}};
|
||||
TEST(is_sorted(failedRequests.begin(), failedRequests.end()), ());
|
||||
|
||||
SometimesFailingDownloadingPolicy policy(failedRequests);
|
||||
@@ -1482,7 +1450,8 @@ UNIT_CLASS_TEST(StorageTest, MultipleMaps)
|
||||
storage.GetChildren(nodeId, children);
|
||||
vector<bool> downloaded(children.size());
|
||||
|
||||
auto const onStatusChange = [&](CountryId const & id) {
|
||||
auto const onStatusChange = [&](CountryId const & id)
|
||||
{
|
||||
auto const status = storage.CountryStatusEx(id);
|
||||
if (status != Status::OnDisk)
|
||||
return;
|
||||
@@ -1494,8 +1463,7 @@ UNIT_CLASS_TEST(StorageTest, MultipleMaps)
|
||||
downloaded[distance(children.cbegin(), it)] = true;
|
||||
};
|
||||
|
||||
auto const onProgress = [&](CountryId const & /* countryId */,
|
||||
downloader::Progress const & /* progress */) {};
|
||||
auto const onProgress = [&](CountryId const & /* countryId */, downloader::Progress const & /* progress */) {};
|
||||
|
||||
auto const slot = storage.Subscribe(onStatusChange, onProgress);
|
||||
SCOPE_GUARD(cleanup, [&]() { storage.Unsubscribe(slot); });
|
||||
|
||||
@@ -4,7 +4,10 @@
|
||||
|
||||
namespace storage
|
||||
{
|
||||
TaskRunner::~TaskRunner() { CHECK(m_checker.CalledOnOriginalThread(), ()); }
|
||||
TaskRunner::~TaskRunner()
|
||||
{
|
||||
CHECK(m_checker.CalledOnOriginalThread(), ());
|
||||
}
|
||||
|
||||
void TaskRunner::Run()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user