Review fixes.

This commit is contained in:
Vladimir Byko-Ianko 2016-12-09 13:38:03 +03:00
parent 5a89f88c03
commit f7c94e03a9
2 changed files with 19 additions and 18 deletions

View file

@ -35,7 +35,7 @@ TrafficManager::CacheEntry::CacheEntry()
TrafficManager::CacheEntry::CacheEntry(time_point<steady_clock> const & requestTime)
: m_isLoaded(false)
, m_dataSize(0)
, m_lastSeenTime(requestTime)
, m_lastActiveTime(requestTime)
, m_lastRequestTime(requestTime)
, m_retriesCount(0)
, m_isWaitingForResponse(true)
@ -206,13 +206,14 @@ void TrafficManager::UpdateMyPosition(MyPosition const & myPosition)
{
// Side of square around |myPosition|. Every mwm which is covered by the square
// will get traffic info.
double const kSquareSideM = 5000;
double const kSquareSideM = 5000.0;
m_currentPosition = {myPosition, true /* initialized */};
if (!IsEnabled() || IsInvalidState())
return;
m2::RectD const rect = MercatorBounds::RectByCenterXYAndSizeInMeters(myPosition.m_position, kSquareSideM);
m2::RectD const rect = MercatorBounds::RectByCenterXYAndSizeInMeters(myPosition.m_position,
kSquareSideM / 2.0);
// Request traffic.
UpdateActiveMwms(rect, m_lastRoutingMwmsByRect, m_activeRoutingMwms);
@ -301,7 +302,7 @@ void TrafficManager::RequestTrafficData(MwmSet::MwmId const & mwmId, bool force)
it->second.m_lastRequestTime = currentTime;
}
if (!force)
it->second.m_lastSeenTime = currentTime;
it->second.m_lastActiveTime = currentTime;
}
if (needRequesting)
@ -403,13 +404,13 @@ void TrafficManager::CheckCacheSize()
// Calculating number of different active mwms.
set<MwmSet::MwmId> activeMwms;
UniteActiveMwms(activeMwms);
size_t const activeMwmsSize = m_activeDrapeMwms.size();
size_t const activeMwmsSize = activeMwms.size();
if (m_currentCacheSizeBytes > m_maxCacheSizeBytes && m_mwmCache.size() > activeMwmsSize)
{
std::multimap<time_point<steady_clock>, MwmSet::MwmId> seenTimings;
for (auto const & mwmInfo : m_mwmCache)
seenTimings.insert(make_pair(mwmInfo.second.m_lastSeenTime, mwmInfo.first));
seenTimings.insert(make_pair(mwmInfo.second.m_lastActiveTime, mwmInfo.first));
auto itSeen = seenTimings.begin();
while (m_currentCacheSizeBytes > m_maxCacheSizeBytes &&

View file

@ -79,16 +79,6 @@ public:
void OnRecoverGLContext();
void OnMwmDelete(MwmSet::MwmId const & mwmId);
private:
void ThreadRoutine();
bool WaitForRequest(vector<MwmSet::MwmId> & mwms);
void OnTrafficDataResponse(traffic::TrafficInfo && info);
void OnTrafficRequestFailed(traffic::TrafficInfo && info);
void UpdateActiveMwms(m2::RectD const & rect, vector<MwmSet::MwmId> & lastMwmsByRect,
set<MwmSet::MwmId> & activeMwms);
private:
struct CacheEntry
{
@ -98,7 +88,7 @@ private:
bool m_isLoaded;
size_t m_dataSize;
time_point<steady_clock> m_lastSeenTime;
time_point<steady_clock> m_lastActiveTime;
time_point<steady_clock> m_lastRequestTime;
time_point<steady_clock> m_lastResponseTime;
@ -108,6 +98,16 @@ private:
traffic::TrafficInfo::Availability m_lastAvailability;
};
void ThreadRoutine();
bool WaitForRequest(vector<MwmSet::MwmId> & mwms);
void OnTrafficDataResponse(traffic::TrafficInfo && info);
void OnTrafficRequestFailed(traffic::TrafficInfo && info);
void UpdateActiveMwms(m2::RectD const & rect, vector<MwmSet::MwmId> & lastMwmsByRect,
set<MwmSet::MwmId> & activeMwms);
// This is a group of methods that haven't their own synchronization inside.
void RequestTrafficData();
void RequestTrafficData(MwmSet::MwmId const & mwmId, bool force);
@ -129,7 +129,7 @@ private:
{
set<MwmSet::MwmId> activeMwms;
UniteActiveMwms(activeMwms);
for (MwmSet::MwmId const & mwmId : activeMwms)
for (auto const & mwmId : activeMwms)
f(mwmId);
}