Fixed processing of the mwm deregistered notification.

This commit is contained in:
Daria Volvenkova 2018-07-16 17:27:56 +03:00 committed by Vlad Mihaylenko
parent 260d119a03
commit 1376bec5f3
9 changed files with 52 additions and 20 deletions

View file

@ -31,6 +31,12 @@ MwmInfo::MwmTypeT MwmInfo::GetType() const
return COASTS;
}
bool MwmSet::MwmId::IsDeregistered(platform::LocalCountryFile const & deregisteredCountryFile) const
{
return m_info && m_info->GetStatus() == MwmInfo::STATUS_DEREGISTERED &&
m_info->GetLocalFile() == deregisteredCountryFile;
}
string DebugPrint(MwmSet::MwmId const & id)
{
ostringstream ss;

View file

@ -119,6 +119,8 @@ public:
void Reset() { m_info.reset(); }
bool IsAlive() const { return (m_info && m_info->GetStatus() != MwmInfo::STATUS_DEREGISTERED); }
bool IsDeregistered(platform::LocalCountryFile const & deregisteredCountryFile) const;
shared_ptr<MwmInfo> & GetInfo() { return m_info; }
shared_ptr<MwmInfo> const & GetInfo() const { return m_info; }

View file

@ -606,13 +606,8 @@ bool Framework::OnCountryFileDelete(storage::TCountryId const & countryId, stora
if (localFile)
{
rect = m_infoGetter->GetLimitRectForLeaf(countryId);
auto const mwmId = m_model.GetDataSource().GetMwmIdByCountryFile(localFile->GetCountryFile());
m_model.DeregisterMap(platform::CountryFile(countryId));
deferredDelete = true;
// Notify managers in case of mwm deletion.
m_localAdsManager.OnMwmDeregistered(mwmId);
m_transitManager.OnMwmDeregistered(mwmId);
m_trafficManager.OnMwmDeregistered(mwmId);
}
InvalidateRect(rect);
@ -622,20 +617,15 @@ bool Framework::OnCountryFileDelete(storage::TCountryId const & countryId, stora
void Framework::OnMapDeregistered(platform::LocalCountryFile const & localFile)
{
m_localAdsManager.OnMwmDeregistered(localFile);
m_transitManager.OnMwmDeregistered(localFile);
m_trafficManager.OnMwmDeregistered(localFile);
auto action = [this, localFile]
{
m_storage.DeleteCustomCountryVersion(localFile);
};
auto const mwmId = m_model.GetDataSource().GetMwmIdByCountryFile(localFile.GetCountryFile());
if (mwmId.GetInfo())
{
// Notify managers in case of mwm updating.
m_localAdsManager.OnMwmDeregistered(mwmId);
m_transitManager.OnMwmDeregistered(mwmId);
m_trafficManager.OnMwmDeregistered(mwmId);
}
// Call action on thread in which the framework was created
// For more information look at comment for Observer class in mwm_set.hpp
if (m_storage.GetThreadChecker().CalledOnOriginalThread())

View file

@ -505,8 +505,22 @@ void LocalAdsManager::OnDownloadCountry(std::string const & countryName)
});
}
void LocalAdsManager::OnMwmDeregistered(MwmSet::MwmId const & mwmId)
void LocalAdsManager::OnMwmDeregistered(platform::LocalCountryFile const & countryFile)
{
MwmSet::MwmId mwmId;
{
std::lock_guard<std::mutex> lock(m_featuresCacheMutex);
for (auto const & cachedMwm : m_featuresCache)
{
if (cachedMwm.first.m_mwmId.IsDeregistered(countryFile))
{
mwmId = cachedMwm.first.m_mwmId;
break;
}
}
}
if (!mwmId.GetInfo())
return;
GetPlatform().RunTask(Platform::Thread::File, [this, mwmId]
{
ProcessRequests({std::make_pair(mwmId, RequestType::Delete)});

View file

@ -52,7 +52,7 @@ public:
void UpdateViewport(ScreenBase const & screen);
void OnDownloadCountry(std::string const & countryName);
void OnMwmDeregistered(MwmSet::MwmId const & mwmId);
void OnMwmDeregistered(platform::LocalCountryFile const & countryFile);
void Invalidate();

View file

@ -140,13 +140,24 @@ void TrafficManager::SetCurrentDataVersion(int64_t dataVersion)
m_currentDataVersion = dataVersion;
}
void TrafficManager::OnMwmDeregistered(MwmSet::MwmId const & mwmId)
void TrafficManager::OnMwmDeregistered(platform::LocalCountryFile const & countryFile)
{
if (!IsEnabled())
return;
{
lock_guard<mutex> lock(m_mutex);
MwmSet::MwmId mwmId;
for (auto const & cacheEntry : m_mwmCache)
{
if (cacheEntry.first.IsDeregistered(countryFile))
{
mwmId = cacheEntry.first;
break;
}
}
ClearCache(mwmId);
}
}

View file

@ -76,7 +76,7 @@ public:
void OnDestroyGLContext();
void OnRecoverGLContext();
void OnMwmDeregistered(MwmSet::MwmId const & mwmId);
void OnMwmDeregistered(platform::LocalCountryFile const & countryFile);
void OnEnterForeground();
void OnEnterBackground();

View file

@ -308,8 +308,17 @@ void TransitReadManager::ClearCache(MwmSet::MwmId const & mwmId)
m_drapeEngine.SafeCall(&df::DrapeEngine::ClearTransitSchemeCache, mwmId);
}
void TransitReadManager::OnMwmDeregistered(MwmSet::MwmId const & mwmId)
void TransitReadManager::OnMwmDeregistered(platform::LocalCountryFile const & countryFile)
{
MwmSet::MwmId mwmId;
for (auto const & cacheEntry : m_mwmCache)
{
if (cacheEntry.first.IsDeregistered(countryFile))
{
mwmId = cacheEntry.first;
break;
}
}
ClearCache(mwmId);
}

View file

@ -104,7 +104,7 @@ public:
void EnableTransitSchemeMode(bool enable);
void BlockTransitSchemeMode(bool isBlocked);
void UpdateViewport(ScreenBase const & screen);
void OnMwmDeregistered(MwmSet::MwmId const & mwmId);
void OnMwmDeregistered(platform::LocalCountryFile const & countryFile);
void Invalidate();
private: