forked from mapsme/omim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheye.hpp
84 lines (68 loc) · 2.35 KB
/
eye.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#pragma once
#include "metrics/eye_info.hpp"
#include "base/atomic_shared_ptr.hpp"
#include "base/macros.hpp"
#include <chrono>
#include <string>
#include <vector>
namespace eye
{
class Subscriber
{
public:
virtual ~Subscriber() = default;
public:
virtual void OnTipClicked(Tip const & tip) {}
virtual void OnBookingFilterUsed(Time const & time) {}
virtual void OnBookmarksCatalogShown(Time const & time) {}
virtual void OnDiscoveryShown(Time const & time) {}
virtual void OnDiscoveryItemClicked(Discovery::Event event) {}
virtual void OnLayerShown(Layer const & layer) {}
virtual void OnMapObjectEvent(MapObject const & poi) {}
};
// Note This class IS thread-safe.
// All write operations are asynchronous and work on Platform::Thread::File thread.
// Read operations are synchronous and return shared pointer with constant copy of internal
// container.
class Eye
{
public:
friend class EyeForTesting;
using InfoType = base::AtomicSharedPtr<Info>::ValueType;
class Event
{
public:
static void TipClicked(Tip::Type type, Tip::Event event);
static void BookingFilterUsed();
static void BoomarksCatalogShown();
static void DiscoveryShown();
static void DiscoveryItemClicked(Discovery::Event event);
static void LayerShown(Layer::Type type);
static void MapObjectEvent(MapObject const & mapObject, MapObject::Event::Type type,
m2::PointD const & userPos);
};
static Eye & Instance();
InfoType GetInfo() const;
// Subscribe/Unsubscribe must be called from main thread only.
void Subscribe(Subscriber * subscriber);
void UnsubscribeAll();
static std::chrono::hours const & GetMapObjectEventsExpirePeriod();
void TrimExpired();
private:
Eye();
bool Save(InfoType const & info);
void TrimExpiredMapObjectEvents();
// Event processing:
void RegisterTipClick(Tip::Type type, Tip::Event event);
void UpdateBookingFilterUsedTime();
void UpdateBoomarksCatalogShownTime();
void UpdateDiscoveryShownTime();
void IncrementDiscoveryItem(Discovery::Event event);
void RegisterLayerShown(Layer::Type type);
void RegisterMapObjectEvent(MapObject const & mapObject, MapObject::Event::Type type,
m2::PointD const & userPos);
base::AtomicSharedPtr<Info> m_info;
std::vector<Subscriber *> m_subscribers;
DISALLOW_COPY_AND_MOVE(Eye);
};
} // namespace eye