Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
authorSergey Magidovich <mgsergio@mapswithme.com>2016-06-14 11:41:45 +0300
committerVladimir Byko-Ianko <v.bykoianko@corp.mail.ru>2016-06-23 19:34:57 +0300
commit3b8eca0a261d838c8280297aa720b54124e1d127 (patch)
tree5c92ca84ec473b0f5e401c63bc32182881bdab95 /editor
parent18802c4c9e55a6ba3043a74d0f08ba101e873ce9 (diff)
Add force update of UserStats.
Diffstat (limited to 'editor')
-rw-r--r--editor/user_stats.cpp11
-rw-r--r--editor/user_stats.hpp6
2 files changed, 14 insertions, 3 deletions
diff --git a/editor/user_stats.cpp b/editor/user_stats.cpp
index 629f4543a9..4b0a9290e7 100644
--- a/editor/user_stats.cpp
+++ b/editor/user_stats.cpp
@@ -127,12 +127,14 @@ bool UserStatsLoader::Update(string const & userName)
return true;
}
-void UserStatsLoader::Update(string const & userName, TOnUpdateCallback fn)
+void UserStatsLoader::Update(string const & userName, UpdatePolicy const policy,
+ TOnUpdateCallback fn)
{
auto nothingToUpdate = false;
+ if (policy == UpdatePolicy::Lazy)
{
lock_guard<mutex> g(m_mutex);
- nothingToUpdate = m_userStats && m_userName == userName && m_userStats &&
+ nothingToUpdate = m_userStats && m_userName == userName &&
difftime(m_lastUpdate, time(nullptr)) < kSecondsInHour;
}
@@ -148,6 +150,11 @@ void UserStatsLoader::Update(string const & userName, TOnUpdateCallback fn)
}).detach();
}
+void UserStatsLoader::Update(string const & userName, TOnUpdateCallback fn)
+{
+ Update(userName, UpdatePolicy::Lazy, fn);
+}
+
void UserStatsLoader::DropStats(string const & userName)
{
lock_guard<mutex> g(m_mutex);
diff --git a/editor/user_stats.hpp b/editor/user_stats.hpp
index 200330ec23..4b71882736 100644
--- a/editor/user_stats.hpp
+++ b/editor/user_stats.hpp
@@ -39,13 +39,17 @@ class UserStatsLoader
public:
using TOnUpdateCallback = function<void()>;
+ enum class UpdatePolicy { Lazy, Force };
+
UserStatsLoader();
/// Synchronously sends request to the server. Updates stats and returns true on success.
bool Update(string const & userName);
- /// Launch the update process if stats are too old.
+ /// Launches the update process if stats are too old or if policy is UpdatePolicy::Force.
/// The process posts fn to a gui thread on success.
+ void Update(string const & userName, UpdatePolicy policy, TOnUpdateCallback fn);
+ /// Calls Update with UpdatePolicy::Lazy.
void Update(string const & userName, TOnUpdateCallback fn);
/// Resets internal state and removes records from settings.