diff options
author | r.kuznetsov <r.kuznetsov@corp.mail.ru> | 2018-08-15 16:20:37 +0300 |
---|---|---|
committer | Daria Volvenkova <d.volvenkova@corp.mail.ru> | 2018-08-17 15:26:10 +0300 |
commit | 515abeed2a658d13864d15c80463f53845738912 (patch) | |
tree | 8f1b718ba312ed47a60cbc64f34d9f4b2f31a8cc /local_ads | |
parent | 93d41ed31836c9302b4589e1f7c0521e748c87ef (diff) |
[Core] Added subscription
Diffstat (limited to 'local_ads')
-rw-r--r-- | local_ads/statistics.cpp | 14 | ||||
-rw-r--r-- | local_ads/statistics.hpp | 3 |
2 files changed, 17 insertions, 0 deletions
diff --git a/local_ads/statistics.cpp b/local_ads/statistics.cpp index 41ce9d9ae6..4c7e5f8599 100644 --- a/local_ads/statistics.cpp +++ b/local_ads/statistics.cpp @@ -245,6 +245,7 @@ Statistics::Statistics() void Statistics::Startup() { + m_isEnabled = true; GetPlatform().RunTask(Platform::Thread::File, [this] { IndexMetadata(); @@ -254,15 +255,25 @@ void Statistics::Startup() void Statistics::RegisterEvent(Event && event) { + if (!m_isEnabled) + return; + RegisterEvents({std::move(event)}); } void Statistics::RegisterEvents(std::list<Event> && events) { + if (!m_isEnabled) + return; GetPlatform().RunTask(Platform::Thread::File, std::bind(&Statistics::ProcessEvents, this, std::move(events))); } +void Statistics::SetEnabled(bool isEnabled) +{ + m_isEnabled = isEnabled; +} + std::list<Event> Statistics::WriteEvents(std::list<Event> & events, std::string & fileNameToRebuild) { try @@ -379,6 +390,9 @@ void Statistics::ProcessEvents(std::list<Event> & events) void Statistics::SendToServer() { + if (!m_isEnabled) + return; + if (CanUpload()) { for (auto it = m_metadataCache.begin(); it != m_metadataCache.end(); ++it) diff --git a/local_ads/statistics.hpp b/local_ads/statistics.hpp index 3b8d20068e..2fc8dcc9c4 100644 --- a/local_ads/statistics.hpp +++ b/local_ads/statistics.hpp @@ -4,6 +4,7 @@ #include "base/thread.hpp" +#include <atomic> #include <chrono> #include <condition_variable> #include <functional> @@ -36,6 +37,7 @@ public: void Startup(); void RegisterEvent(Event && event); void RegisterEvents(std::list<Event> && events); + void SetEnabled(bool isEnabled); std::list<Event> WriteEventsForTesting(std::list<Event> const & events, std::string & fileNameToRebuild); @@ -67,6 +69,7 @@ private: void SendFileWithMetadata(MetadataKey && metadataKey, Metadata && metadata); std::string const m_userId; + bool m_isEnabled = false; std::map<MetadataKey, Metadata> m_metadataCache; }; } // namespace local_ads |