Merge pull request #2465 from bykoianko/master-downloading-counter-and-amount

[new downloader] Adding downloading size and downloading counter.
This commit is contained in:
igrechuhin 2016-03-24 09:53:20 +03:00
commit 887f142029
3 changed files with 34 additions and 2 deletions

View file

@ -1273,11 +1273,21 @@ void Storage::GetNodeAttrs(TCountryId const & countryId, NodeAttrs & nodeAttrs)
CalculateProgress(downloadingMwm, subtree, downloadingMwmProgress, setQueue);
}
// Local mwm information.
// Local mwm information and information about downloading mwms.
nodeAttrs.m_localMwmCounter = 0;
nodeAttrs.m_localMwmSize = 0;
nodeAttrs.m_downloadingMwmCounter = 0;
nodeAttrs.m_downloadingMwmSize = 0;
node->ForEachInSubtree([this, &nodeAttrs](TCountryTreeNode const & d)
{
// Downloading mwm information.
if (nodeAttrs.m_status != NodeStatus::NotDownloaded && d.ChildrenCount() == 0)
{
nodeAttrs.m_downloadingMwmCounter += 1;
nodeAttrs.m_downloadingMwmSize += d.Value().GetSubtreeMwmSizeBytes();
}
// Local mwm information.
Storage::TLocalFilePtr const localFile =
GetLatestLocalFile(d.Value().Name());
if (localFile == nullptr)

View file

@ -32,7 +32,8 @@ struct CountryIdAndName
/// It's applicable for expandable and not expandable node id.
struct NodeAttrs
{
NodeAttrs() : m_mwmCounter(0), m_localMwmCounter(0), m_mwmSize(0), m_localMwmSize(0),
NodeAttrs() : m_mwmCounter(0), m_localMwmCounter(0), m_downloadingMwmCounter(0),
m_mwmSize(0), m_localMwmSize(0), m_downloadingMwmSize(0),
m_downloadingProgress(make_pair(0, 0)),
m_status(NodeStatus::Undefined), m_error(NodeErrorCode::NoError), m_present(false) {}
@ -44,6 +45,11 @@ struct NodeAttrs
/// Number of mwms belonging to the node which have been downloaded.
uint32_t m_localMwmCounter;
/// Number of leaves of the node which have been downloaded
/// plus which is in progress of downloading (zero or one)
/// plus which are staying in queue.
uint32_t m_downloadingMwmCounter;
/// If it's not an expandable node, |m_mwmSize| is size of one mwm according to countries.txt.
/// Otherwise |m_mwmSize| is the sum of all mwm file sizes which belong to the group
/// according to countries.txt.
@ -54,6 +60,12 @@ struct NodeAttrs
/// have been downloaded.
size_t m_localMwmSize;
/// Size of leaves of the node which have been downloaded
/// plus which is in progress of downloading (zero or one)
/// plus which are staying in queue.
/// \note The size of leaves is the size is written in countries.txt.
size_t m_downloadingMwmSize;
/// The name of the node in a local language. That means the language dependent on
/// a device locale.
string m_nodeLocalName;

View file

@ -1272,6 +1272,8 @@ UNIT_TEST(StorageTest_GetNodeAttrsSingleMwm)
TEST_EQUAL(nodeAttrs.m_downloadingProgress.second, 0, ());
TEST_EQUAL(nodeAttrs.m_localMwmCounter, 0, ());
TEST_EQUAL(nodeAttrs.m_localMwmSize, 0, ());
TEST_EQUAL(nodeAttrs.m_downloadingMwmCounter, 0, ());
TEST_EQUAL(nodeAttrs.m_localMwmSize, 0, ());
TEST(!nodeAttrs.m_present, ());
storage.GetNodeAttrs("Algeria", nodeAttrs);
@ -1285,6 +1287,8 @@ UNIT_TEST(StorageTest_GetNodeAttrsSingleMwm)
TEST_EQUAL(nodeAttrs.m_downloadingProgress.second, 0, ());
TEST_EQUAL(nodeAttrs.m_localMwmCounter, 0, ());
TEST_EQUAL(nodeAttrs.m_localMwmSize, 0, ());
TEST_EQUAL(nodeAttrs.m_downloadingMwmCounter, 0, ());
TEST_EQUAL(nodeAttrs.m_localMwmSize, 0, ());
TEST(!nodeAttrs.m_present, ());
storage.GetNodeAttrs("Algeria_Coast", nodeAttrs);
@ -1298,6 +1302,8 @@ UNIT_TEST(StorageTest_GetNodeAttrsSingleMwm)
TEST_EQUAL(nodeAttrs.m_downloadingProgress.second, 0, ());
TEST_EQUAL(nodeAttrs.m_localMwmCounter, 0, ());
TEST_EQUAL(nodeAttrs.m_localMwmSize, 0, ());
TEST_EQUAL(nodeAttrs.m_downloadingMwmCounter, 0, ());
TEST_EQUAL(nodeAttrs.m_localMwmSize, 0, ());
TEST(!nodeAttrs.m_present, ());
storage.GetNodeAttrs("South Korea_South", nodeAttrs);
@ -1311,6 +1317,8 @@ UNIT_TEST(StorageTest_GetNodeAttrsSingleMwm)
TEST_EQUAL(nodeAttrs.m_downloadingProgress.second, 0, ());
TEST_EQUAL(nodeAttrs.m_localMwmCounter, 0, ());
TEST_EQUAL(nodeAttrs.m_localMwmSize, 0, ());
TEST_EQUAL(nodeAttrs.m_downloadingMwmCounter, 0, ());
TEST_EQUAL(nodeAttrs.m_localMwmSize, 0, ());
TEST(!nodeAttrs.m_present, ());
storage.GetNodeAttrs("Disputable Territory", nodeAttrs);
@ -1326,6 +1334,8 @@ UNIT_TEST(StorageTest_GetNodeAttrsSingleMwm)
TEST_EQUAL(nodeAttrs.m_downloadingProgress.second, 0, ());
TEST_EQUAL(nodeAttrs.m_localMwmCounter, 0, ());
TEST_EQUAL(nodeAttrs.m_localMwmSize, 0, ());
TEST_EQUAL(nodeAttrs.m_downloadingMwmCounter, 0, ());
TEST_EQUAL(nodeAttrs.m_localMwmSize, 0, ());
TEST(!nodeAttrs.m_present, ());
}