[new downloader] Review fixes.

This commit is contained in:
Vladimir Byko-Ianko 2016-02-04 16:02:57 +03:00 committed by Sergey Yershov
parent aee56b879d
commit fd9fa541f6
12 changed files with 76 additions and 51 deletions

View file

@ -228,7 +228,7 @@ bool SearchPanel::TryMigrate(QString const & str)
}
};
auto progressChanged = [](storage::TCountryId const & id, storage::LocalAndRemoteSizeT const & sz)
auto progressChanged = [](storage::TCountryId const & id, storage::TLocalAndRemoteSize const & sz)
{
LOG(LINFO, (id, "downloading progress:", sz));
};

View file

@ -157,7 +157,7 @@ namespace qt
{
QColor rowColor;
QString statusString;
LocalAndRemoteSizeT size(0, 0);
TLocalAndRemoteSize size(0, 0);
MapOptions const options = MapOptions::MapWithCarRouting;

View file

@ -291,18 +291,18 @@ bool Storage::IsCoutryIdInCountryTree(TCountryId const & countryId) const
return m_countries.Find(Country(countryId)) != nullptr;
}
LocalAndRemoteSizeT Storage::CountrySizeInBytes(TCountryId const & countryId, MapOptions opt) const
TLocalAndRemoteSize Storage::CountrySizeInBytes(TCountryId const & countryId, MapOptions opt) const
{
QueuedCountry const * queuedCountry = FindCountryInQueue(countryId);
TLocalFilePtr localFile = GetLatestLocalFile(countryId);
CountryFile const & countryFile = GetCountryFile(countryId);
if (queuedCountry == nullptr)
{
return LocalAndRemoteSizeT(GetLocalSize(localFile, opt),
return TLocalAndRemoteSize(GetLocalSize(localFile, opt),
GetRemoteSize(countryFile, opt, GetCurrentDataVersion()));
}
LocalAndRemoteSizeT sizes(0, GetRemoteSize(countryFile, opt, GetCurrentDataVersion()));
TLocalAndRemoteSize sizes(0, GetRemoteSize(countryFile, opt, GetCurrentDataVersion()));
if (!m_downloader->IsIdle() && IsCountryFirstInQueue(countryId))
{
sizes.first = m_downloader->GetDownloadingProgress().first +
@ -1130,9 +1130,9 @@ void Storage::GetNodeAttrs(TCountryId const & countryId, NodeAttrs & nodeAttrs)
Country const & nodeValue = node->Value();
nodeAttrs.m_mwmCounter = nodeValue.GetSubtreeMwmCounter();
nodeAttrs.m_mwmSize = nodeValue.GetSubtreeMwmSizeBytes();
TStatusAndError statusAndErr = ParseStatus(NodeStatus(*node));
nodeAttrs.m_status = statusAndErr.first;
nodeAttrs.m_error = statusAndErr.second;
StatusAndError statusAndErr = ParseStatus(NodeStatus(*node));
nodeAttrs.m_status = statusAndErr.status;
nodeAttrs.m_error = statusAndErr.error;
// @TODO(bykoianko) NodeAttrs::m_nodeLocalName should be in local language.
nodeAttrs.m_nodeLocalName = countryId;
}

View file

@ -23,7 +23,7 @@ struct NodeAttrs
{
NodeAttrs() : m_mwmCounter(0), m_localMwmCounter(0), m_mwmSize(0), m_localMwmSize(0),
m_downloadingMwmSize(0), m_downloadingProgress(0),
m_status(TNodeStatus::Undefined), m_error(TErrNodeStatus::NoError) {}
m_status(TNodeStatus::Undefined), m_error(TNodeErrorCode::NoError) {}
/// If the node is expandable (a big country) |m_mwmCounter| is number of mwm files (leaves)
/// belongs to the node. If the node isn't expandable |m_mapsDownloaded| == 1.
uint32_t m_mwmCounter;
@ -64,7 +64,7 @@ struct NodeAttrs
uint8_t m_downloadingProgress;
TNodeStatus m_status;
TErrNodeStatus m_error;
TNodeErrorCode m_error;
};
/// This class is used for downloading, updating and deleting maps.
@ -74,7 +74,7 @@ public:
struct StatusCallback;
using TUpdate = function<void(platform::LocalCountryFile const &)>;
using TChangeCountryFunction = function<void(TCountryId const &)>;
using TProgressFunction = function<void(TCountryId const &, LocalAndRemoteSizeT const &)>;
using TProgressFunction = function<void(TCountryId const &, TLocalAndRemoteSize const &)>;
private:
/// We support only one simultaneous request at the moment
@ -349,7 +349,7 @@ public:
string const & CountryName(TCountryId const & countryId) const;
bool IsCoutryIdInCountryTree(TCountryId const & countryId) const;
LocalAndRemoteSizeT CountrySizeInBytes(TCountryId const & countryId, MapOptions opt) const;
TLocalAndRemoteSize CountrySizeInBytes(TCountryId const & countryId, MapOptions opt) const;
platform::CountryFile const & GetCountryFile(TCountryId const & countryId) const;
TLocalFilePtr GetLatestLocalFile(platform::CountryFile const & countryFile) const;
TLocalFilePtr GetLatestLocalFile(TCountryId const & countryId) const;

View file

@ -1,5 +1,7 @@
#include "storage/storage_defines.hpp"
#include "std/sstream.hpp"
namespace storage
{
string DebugPrint(TStatus status)
@ -52,45 +54,53 @@ string DebugPrint(TNodeStatus status)
}
}
string DebugPrint(TErrNodeStatus status)
string DebugPrint(TNodeErrorCode status)
{
switch (status)
{
case TErrNodeStatus::NoError:
case TNodeErrorCode::NoError:
return string("NoError");
case TErrNodeStatus::UnknownError:
case TNodeErrorCode::UnknownError:
return string("UnknownError");
case TErrNodeStatus::OutOfMemFailed:
case TNodeErrorCode::OutOfMemFailed:
return string("OutOfMemFailed");
case TErrNodeStatus::NoInetConnection:
case TNodeErrorCode::NoInetConnection:
return string("NoInetConnection");
}
}
TStatusAndError ParseStatus(TStatus innerStatus)
StatusAndError ParseStatus(TStatus innerStatus)
{
switch (innerStatus)
{
case TStatus::EUndefined:
return TStatusAndError(TNodeStatus::Undefined, TErrNodeStatus::NoError);
return StatusAndError(TNodeStatus::Undefined, TNodeErrorCode::NoError);
case TStatus::EOnDisk:
return TStatusAndError(TNodeStatus::OnDisk, TErrNodeStatus::NoError);
return StatusAndError(TNodeStatus::OnDisk, TNodeErrorCode::NoError);
case TStatus::ENotDownloaded:
return TStatusAndError(TNodeStatus::NotDownloaded, TErrNodeStatus::NoError);
return StatusAndError(TNodeStatus::NotDownloaded, TNodeErrorCode::NoError);
case TStatus::EDownloadFailed:
return TStatusAndError(TNodeStatus::Error, TErrNodeStatus::NoInetConnection);
return StatusAndError(TNodeStatus::Error, TNodeErrorCode::NoInetConnection);
case TStatus::EDownloading:
return TStatusAndError(TNodeStatus::Downloading, TErrNodeStatus::NoError);
return StatusAndError(TNodeStatus::Downloading, TNodeErrorCode::NoError);
case TStatus::EInQueue:
return TStatusAndError(TNodeStatus::InQueue, TErrNodeStatus::NoError);
return StatusAndError(TNodeStatus::InQueue, TNodeErrorCode::NoError);
case TStatus::EUnknown:
return TStatusAndError(TNodeStatus::Error, TErrNodeStatus::UnknownError);
return StatusAndError(TNodeStatus::Error, TNodeErrorCode::UnknownError);
case TStatus::EOnDiskOutOfDate:
return TStatusAndError(TNodeStatus::OnDiskOutOfDate, TErrNodeStatus::NoError);
return StatusAndError(TNodeStatus::OnDiskOutOfDate, TNodeErrorCode::NoError);
case TStatus::EOutOfMemFailed:
return TStatusAndError(TNodeStatus::Error, TErrNodeStatus::OutOfMemFailed);
return StatusAndError(TNodeStatus::Error, TNodeErrorCode::OutOfMemFailed);
case TStatus::EMixed:
return TStatusAndError(TNodeStatus::Mixed, TErrNodeStatus::NoError);
return StatusAndError(TNodeStatus::Mixed, TNodeErrorCode::NoError);
}
}
string DebugPrint(StatusAndError statusAndError)
{
ostringstream out;
out << "StatusAndError[" << DebugPrint(statusAndError.status)
<< ", " << DebugPrint(statusAndError.error) << "]";
return out.str();
}
} // namespace storage

View file

@ -38,19 +38,33 @@ namespace storage
};
string DebugPrint(TNodeStatus status);
enum class TErrNodeStatus
enum class TNodeErrorCode
{
NoError,
UnknownError, /**< Downloading failed because of unknown error. */
OutOfMemFailed, /**< Downloading failed because it's not enough memory */
NoInetConnection, /**< Downloading failed because internet connection was interrupted */
};
string DebugPrint(TErrNodeStatus status);
string DebugPrint(TNodeErrorCode status);
using TStatusAndError = pair<TNodeStatus, TErrNodeStatus>;
using LocalAndRemoteSizeT = pair<uint64_t, uint64_t>;
struct StatusAndError
{
StatusAndError(TNodeStatus nodeStatus, TNodeErrorCode nodeError) :
status(nodeStatus), error(nodeError) {}
TStatusAndError ParseStatus(TStatus innerStatus);
bool operator==(StatusAndError const & other)
{
return other.status == status && other.error == error;
}
TNodeStatus status;
TNodeErrorCode error;
};
string DebugPrint(StatusAndError statusAndError);
using TLocalAndRemoteSize = pair<uint64_t, uint64_t>;
StatusAndError ParseStatus(TStatus innerStatus);
} // namespace storage
using TDownloadFn = function<void (storage::TCountryId const &)>;

View file

@ -69,7 +69,7 @@ UNIT_TEST(StorageMigrationTests)
}
};
auto progressChanged = [](TCountryId const & id, LocalAndRemoteSizeT const & sz)
auto progressChanged = [](TCountryId const & id, TLocalAndRemoteSize const & sz)
{
LOG_SHORT(LINFO, (id, "downloading progress:", sz));
};

View file

@ -67,7 +67,7 @@ UNIT_TEST(SmallMwms_InterruptDownloadResumeDownload_Test)
Storage storage(COUNTRIES_MIGRATE_FILE);
TEST(version::IsSingleMwm(storage.GetCurrentDataVersion()), ());
auto onProgressFn = [](TCountryId const & countryId, LocalAndRemoteSizeT const & mapSize)
auto onProgressFn = [](TCountryId const & countryId, TLocalAndRemoteSize const & mapSize)
{
TEST_EQUAL(countryId, kCountryId, ());
// Interrupt download
@ -90,7 +90,7 @@ UNIT_TEST(SmallMwms_InterruptDownloadResumeDownload_Test)
Storage storage(COUNTRIES_MIGRATE_FILE);
auto onProgressFn = [](TCountryId const & countryId, LocalAndRemoteSizeT const & mapSize)
auto onProgressFn = [](TCountryId const & countryId, TLocalAndRemoteSize const & mapSize)
{
TEST_EQUAL(countryId, kCountryId, ());
};

View file

@ -79,7 +79,7 @@ void DownloadGroup(Storage & storage, bool oneByOne)
};
TCountriesSet downloaded;
auto onProgressFn = [&](TCountryId const & countryId, LocalAndRemoteSizeT const & mapSize)
auto onProgressFn = [&](TCountryId const & countryId, TLocalAndRemoteSize const & mapSize)
{
TEST(children.find(countryId) != children.end(), ());
if (mapSize.first == mapSize.second)

View file

@ -30,7 +30,7 @@ string const kMapTestDir = "map-tests";
string const kTestWebServer = "http://new-search.mapswithme.com/";
void ProgressFunction(TCountryId const & countryId, LocalAndRemoteSizeT const & mapSize)
void ProgressFunction(TCountryId const & countryId, TLocalAndRemoteSize const & mapSize)
{
TEST_EQUAL(countryId, kCountryId, ());
}

View file

@ -84,7 +84,7 @@ UNIT_TEST(SmallMwms_Update_Test)
Platform & platform = GetPlatform();
auto onProgressFn = [&](TCountryId const & countryId, LocalAndRemoteSizeT const & mapSize) {};
auto onProgressFn = [&](TCountryId const & countryId, TLocalAndRemoteSize const & mapSize) {};
// Download countries.txt for version 1
TEST(DownloadFile(GetCountriesTxtWebUrl(kMwmVersion1), GetCountriesTxtFilePath(), kCountriesTxtFileSize1), ());

View file

@ -193,13 +193,13 @@ protected:
++m_currStatus;
if (m_transitionList[m_currStatus] == TStatus::EDownloading)
{
LocalAndRemoteSizeT localAndRemoteSize = m_storage.CountrySizeInBytes(m_countryId, m_files);
TLocalAndRemoteSize localAndRemoteSize = m_storage.CountrySizeInBytes(m_countryId, m_files);
m_totalBytesToDownload = localAndRemoteSize.second;
}
}
virtual void OnCountryDownloadingProgress(TCountryId const & countryId,
LocalAndRemoteSizeT const & progress)
TLocalAndRemoteSize const & progress)
{
if (countryId != m_countryId)
return;
@ -210,7 +210,7 @@ protected:
m_bytesDownloaded = progress.first;
TEST_LESS_OR_EQUAL(m_bytesDownloaded, m_totalBytesToDownload, (m_countryFile));
LocalAndRemoteSizeT localAndRemoteSize = m_storage.CountrySizeInBytes(m_countryId, m_files);
TLocalAndRemoteSize localAndRemoteSize = m_storage.CountrySizeInBytes(m_countryId, m_files);
TEST_EQUAL(m_totalBytesToDownload, localAndRemoteSize.second, (m_countryFile));
}
@ -241,7 +241,7 @@ public:
protected:
// CountryDownloaderChecker overrides:
void OnCountryDownloadingProgress(TCountryId const & countryId,
LocalAndRemoteSizeT const & progress) override
TLocalAndRemoteSize const & progress) override
{
CountryDownloaderChecker::OnCountryDownloadingProgress(countryId, progress);
@ -331,7 +331,7 @@ private:
}
void OnCountryDownloadingProgress(TCountryId const & /* countryId */,
LocalAndRemoteSizeT const & /* progress */)
TLocalAndRemoteSize const & /* progress */)
{
TEST(false, ("Unexpected country downloading progress."));
}
@ -382,7 +382,7 @@ public:
QCoreApplication::exit();
}
void OnProgress(TCountryId const & /* countryId */, LocalAndRemoteSizeT const & /* progress */) {}
void OnProgress(TCountryId const & /* countryId */, TLocalAndRemoteSize const & /* progress */) {}
private:
Storage & m_storage;
@ -1167,27 +1167,28 @@ UNIT_TEST(StorageTest_GetNodeAttrsSingleMwm)
TEST_EQUAL(nodeAttrs.m_mwmCounter, 1, ());
TEST_EQUAL(nodeAttrs.m_mwmSize, 4689718, ());
TEST_EQUAL(nodeAttrs.m_status, TNodeStatus::NotDownloaded, ());
TEST_EQUAL(nodeAttrs.m_error, TErrNodeStatus::NoError, ());
TEST_EQUAL(nodeAttrs.m_error, TNodeErrorCode::NoError, ());
storage.GetNodeAttrs("Algeria", nodeAttrs);
TEST_EQUAL(nodeAttrs.m_mwmCounter, 2, ());
TEST_EQUAL(nodeAttrs.m_mwmSize, 90878678, ());
TEST_EQUAL(nodeAttrs.m_status, TNodeStatus::NotDownloaded, ());
TEST_EQUAL(nodeAttrs.m_error, TErrNodeStatus::NoError, ());
TEST_EQUAL(nodeAttrs.m_error, TNodeErrorCode::NoError, ());
storage.GetNodeAttrs("South Korea_South", nodeAttrs);
TEST_EQUAL(nodeAttrs.m_mwmCounter, 1, ());
TEST_EQUAL(nodeAttrs.m_mwmSize, 48394664, ());
TEST_EQUAL(nodeAttrs.m_status, TNodeStatus::NotDownloaded, ());
TEST_EQUAL(nodeAttrs.m_error, TErrNodeStatus::NoError, ());
TEST_EQUAL(nodeAttrs.m_error, TNodeErrorCode::NoError, ());
}
UNIT_TEST(StorageTest_ParseStatus)
{
TEST_EQUAL(TStatusAndError(TNodeStatus::Undefined, TErrNodeStatus::NoError),
TEST_EQUAL(StatusAndError(TNodeStatus::Undefined, TNodeErrorCode::NoError),
ParseStatus(TStatus::EUndefined), ());
TEST_EQUAL(TStatusAndError(TNodeStatus::Error, TErrNodeStatus::NoInetConnection),
TEST_EQUAL(StatusAndError(TNodeStatus::Error, TNodeErrorCode::NoInetConnection),
ParseStatus(TStatus::EDownloadFailed), ());
TEST_EQUAL(TStatusAndError(TNodeStatus::Downloading, TErrNodeStatus::NoError),
TEST_EQUAL(StatusAndError(TNodeStatus::Downloading, TNodeErrorCode::NoError),
ParseStatus(TStatus::EDownloading), ());
}
} // namespace storage