forked from organicmaps/organicmaps
[storage] new way for abort diff scheme is added. It is needed for working with downloaders without direct access into internal queues.
This commit is contained in:
parent
d6e22a8375
commit
3126ebe7da
7 changed files with 23 additions and 22 deletions
|
@ -37,7 +37,7 @@ CountryId const & Queue::GetFirstId() const
|
|||
return m_queue.front().GetCountryId();
|
||||
}
|
||||
|
||||
QueuedCountry & Queue::GetFirstCountry()
|
||||
QueuedCountry const & Queue::GetFirstCountry() const
|
||||
{
|
||||
CHECK(!m_queue.empty(), ());
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ public:
|
|||
void ForEachCountry(ForEachCountryMutable const & fn);
|
||||
|
||||
CountryId const & GetFirstId() const;
|
||||
QueuedCountry & GetFirstCountry();
|
||||
QueuedCountry const & GetFirstCountry() const;
|
||||
void PopFront();
|
||||
|
||||
void Append(QueuedCountry && country)
|
||||
|
|
|
@ -57,9 +57,7 @@ void HttpMapFilesDownloader::Download()
|
|||
{
|
||||
CHECK_THREAD_CHECKER(m_checker, ());
|
||||
|
||||
auto & queuedCountry = m_queue.GetFirstCountry();
|
||||
|
||||
queuedCountry.ClarifyDownloadingType();
|
||||
auto const & queuedCountry = m_queue.GetFirstCountry();
|
||||
|
||||
auto const urls = MakeUrlList(queuedCountry.GetRelativeUrl());
|
||||
auto const path = queuedCountry.GetFileDownloadPath();
|
||||
|
|
|
@ -92,19 +92,6 @@ uint64_t QueuedCountry::GetDownloadSize() const
|
|||
return GetRemoteSize(*m_diffsDataSource, m_countryFile);
|
||||
}
|
||||
|
||||
void QueuedCountry::ClarifyDownloadingType()
|
||||
{
|
||||
if (m_fileType != MapFileType::Diff)
|
||||
return;
|
||||
|
||||
using diffs::Status;
|
||||
auto const status = m_diffsDataSource->GetStatus();
|
||||
if (status == Status::NotAvailable || !m_diffsDataSource->HasDiffFor(m_countryId))
|
||||
{
|
||||
m_fileType = MapFileType::Map;
|
||||
}
|
||||
}
|
||||
|
||||
void QueuedCountry::OnCountryInQueue() const
|
||||
{
|
||||
if (m_subscriber != nullptr)
|
||||
|
|
|
@ -50,8 +50,6 @@ public:
|
|||
std::string GetFileDownloadPath() const;
|
||||
uint64_t GetDownloadSize() const;
|
||||
|
||||
void ClarifyDownloadingType();
|
||||
|
||||
void OnCountryInQueue() const;
|
||||
void OnStartDownloading() const;
|
||||
void OnDownloadProgress(downloader::Progress const & progress) const;
|
||||
|
|
|
@ -812,7 +812,7 @@ void Storage::OnMapDownloadFinished(CountryId const & countryId, DownloadStatus
|
|||
{
|
||||
if (status == DownloadStatus::FileNotFound && type == MapFileType::Diff)
|
||||
{
|
||||
m_diffsDataSource->AbortDiffScheme();
|
||||
AbortDiffScheme();
|
||||
NotifyStatusChanged(GetRootId());
|
||||
}
|
||||
|
||||
|
@ -1223,7 +1223,7 @@ void Storage::LoadDiffScheme()
|
|||
|
||||
if (localMapsInfo.m_localMaps.empty())
|
||||
{
|
||||
m_diffsDataSource->AbortDiffScheme();
|
||||
AbortDiffScheme();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1307,6 +1307,23 @@ void Storage::ApplyDiff(CountryId const & countryId, function<void(bool isSucces
|
|||
});
|
||||
}
|
||||
|
||||
void Storage::AbortDiffScheme()
|
||||
{
|
||||
std::vector<CountryId> countriesToReplace;
|
||||
m_downloader->GetQueue().ForEachCountry([&countriesToReplace](QueuedCountry const & queuedCountry)
|
||||
{
|
||||
if (queuedCountry.GetFileType() == MapFileType::Diff)
|
||||
countriesToReplace.push_back(queuedCountry.GetCountryId());
|
||||
});
|
||||
|
||||
for (auto const & countryId : countriesToReplace)
|
||||
{
|
||||
DeleteCountryFilesFromDownloader(countryId);
|
||||
DownloadCountry(countryId, MapFileType::Map);
|
||||
}
|
||||
m_diffsDataSource->AbortDiffScheme();
|
||||
}
|
||||
|
||||
bool Storage::IsPossibleToAutoupdate() const
|
||||
{
|
||||
CHECK_THREAD_CHECKER(m_threadChecker, ());
|
||||
|
|
|
@ -650,6 +650,7 @@ private:
|
|||
|
||||
void LoadDiffScheme();
|
||||
void ApplyDiff(CountryId const & countryId, std::function<void(bool isSuccess)> const & fn);
|
||||
void AbortDiffScheme();
|
||||
|
||||
// Should be called once on startup, downloading process should be suspended until this method
|
||||
// was not called. Do not call this method manually.
|
||||
|
|
Loading…
Add table
Reference in a new issue