[downloader] Added current data version to meta-server request.

Signed-off-by: Viktor Govako <viktor.govako@gmail.com>
This commit is contained in:
Viktor Govako 2021-08-31 21:09:09 +03:00 committed by Alexander Borsuk
parent 3c9f017bda
commit 757a861cd4
3 changed files with 13 additions and 4 deletions

View file

@ -147,15 +147,14 @@ std::vector<std::string> MapFilesDownloader::MakeUrlList(std::string const & rel
// static
MapFilesDownloader::ServersList MapFilesDownloader::LoadServersList()
{
auto constexpr kTimeoutInSeconds = 10.0;
std::string const metaServerUrl = GetPlatform().MetaServerUrl();
std::string httpResult;
if (!metaServerUrl.empty())
{
platform::HttpClient request(metaServerUrl);
request.SetTimeout(kTimeoutInSeconds);
request.SetRawHeader("X-OM-DataVersion", std::to_string(m_dataVersion));
request.SetTimeout(10.0); // timeout in seconds
request.RunHttpRequest(httpResult);
}

View file

@ -58,13 +58,14 @@ public:
void SetServersList(ServersList const & serversList);
void SetDownloadingPolicy(DownloadingPolicy * policy);
void SetDataVersion(int64_t version) { m_dataVersion = version; }
protected:
bool IsDownloadingAllowed() const;
std::vector<std::string> MakeUrlList(std::string const & relativeUrl);
// Synchronously loads list of servers by http client.
static ServersList LoadServersList();
ServersList LoadServersList();
private:
/**
@ -84,6 +85,8 @@ private:
std::unique_ptr<RequestT> m_fileRequest;
ServersList m_serversList;
int64_t m_dataVersion = 0;
/// Used as guard for m_serversList assign.
std::atomic_bool m_isServersListRequested = false;

View file

@ -134,6 +134,8 @@ Storage::Storage(string const & pathToCountriesFile /* = COUNTRIES_FILE */,
SetLocale(languages::GetCurrentTwine());
LoadCountriesFile(pathToCountriesFile);
CalcMaxMwmSizeBytes();
m_downloader->SetDataVersion(m_currentVersion);
}
Storage::Storage(string const & referenceCountriesTxtJsonForTesting,
@ -147,6 +149,8 @@ Storage::Storage(string const & referenceCountriesTxtJsonForTesting,
m_countryNameSynonyms, m_mwmTopCityGeoIds, m_mwmTopCountryGeoIds);
CHECK_LESS_OR_EQUAL(0, m_currentVersion, ("Can't load test countries file"));
CalcMaxMwmSizeBytes();
m_downloader->SetDataVersion(m_currentVersion);
}
void Storage::Init(UpdateCallback didDownload, DeleteCallback willDelete)
@ -814,6 +818,7 @@ void Storage::SetEnabledIntegrityValidationForTesting(bool enabled)
void Storage::SetCurrentDataVersionForTesting(int64_t currentVersion)
{
m_currentVersion = currentVersion;
m_downloader->SetDataVersion(m_currentVersion);
}
void Storage::SetDownloadingServersForTesting(vector<string> const & downloadingUrls)
@ -1028,6 +1033,8 @@ void Storage::ApplyCountries(std::string const & countriesBuffer, Storage & stor
}
m_currentVersion = storage.m_currentVersion;
m_downloader->SetDataVersion(m_currentVersion);
m_countries = std::move(storage.m_countries);
m_affiliations = std::move(storage.m_affiliations);
m_countryNameSynonyms = std::move(storage.m_countryNameSynonyms);