OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/notifications/message_center_stats_collector.h" | |
6 | |
7 #include <string> | |
8 | |
9 #include "base/metrics/histogram.h" | |
10 #include "content/public/browser/user_metrics.h" | |
11 #include "ui/message_center/message_center.h" | |
12 | |
13 MessageCenterStatsCollector::NotificationStats::NotificationStats() {} | |
14 | |
15 MessageCenterStatsCollector::NotificationStats::NotificationStats( | |
16 const std::string& id) : id_(id) { | |
17 for (size_t i = 0; i < NOTIFICATION_ACTION_COUNT; i++) { | |
18 actions_[i] = false; | |
19 } | |
20 } | |
21 | |
22 MessageCenterStatsCollector::NotificationStats::~NotificationStats() {} | |
23 | |
24 void MessageCenterStatsCollector::NotificationStats::CollectAction( | |
25 NotificationActionType type) { | |
26 DCHECK(!id_.empty()); | |
27 | |
28 UMA_HISTOGRAM_ENUMERATION("Notifications.RawActions", | |
29 type, | |
30 NOTIFICATION_ACTION_COUNT); | |
31 actions_[type] = true; | |
32 } | |
33 | |
34 void MessageCenterStatsCollector::NotificationStats::RecordAggregateStats() { | |
35 DCHECK(!id_.empty()); | |
36 | |
37 for (size_t i = 0; i < NOTIFICATION_ACTION_COUNT; i++) { | |
Ilya Sherman
2013/09/21 05:43:29
nit: ++i;
| |
38 if (!actions_[i]) | |
39 continue; | |
40 UMA_HISTOGRAM_ENUMERATION("Notifications.PerNotificationActions", | |
41 i, | |
Ilya Sherman
2013/09/21 05:43:29
Should this be actions_[i]?
| |
42 NOTIFICATION_ACTION_COUNT); | |
43 } | |
44 } | |
45 | |
46 MessageCenterStatsCollector::MessageCenterStatsCollector( | |
47 message_center::MessageCenter* message_center) | |
48 : message_center_(message_center) { | |
49 message_center_->AddObserver(this); | |
50 } | |
51 | |
52 MessageCenterStatsCollector::~MessageCenterStatsCollector() { | |
53 message_center_->RemoveObserver(this); | |
54 } | |
55 | |
56 void MessageCenterStatsCollector::OnNotificationAdded( | |
57 const std::string& notification_id) { | |
58 stats_[notification_id] = NotificationStats(notification_id); | |
59 | |
60 StatsCollection::iterator iter = stats_.find(notification_id); | |
61 DCHECK(iter != stats_.end()); | |
62 | |
63 stats_[notification_id].CollectAction(NOTIFICATION_ACTION_ADD); | |
64 } | |
65 | |
66 void MessageCenterStatsCollector::OnNotificationRemoved( | |
67 const std::string& notification_id, bool by_user) { | |
68 StatsCollection::iterator iter = stats_.find(notification_id); | |
69 if (iter == stats_.end()) | |
70 return; | |
71 NotificationStats& notification_stat = iter->second; | |
72 notification_stat.CollectAction(by_user ? | |
73 NOTIFICATION_ACTION_CLOSE_BY_USER : | |
74 NOTIFICATION_ACTION_CLOSE_BY_SYSTEM); | |
75 notification_stat.RecordAggregateStats(); | |
Jun Mukai
2013/09/21 00:21:59
Is it okay to compute the aggregation only when a
| |
76 stats_.erase(notification_id); | |
77 } | |
78 | |
79 void MessageCenterStatsCollector::OnNotificationUpdated( | |
80 const std::string& notification_id) { | |
81 StatsCollection::iterator iter = stats_.find(notification_id); | |
82 if (iter == stats_.end()) | |
83 return; | |
84 NotificationStats& notification_stat = iter->second; | |
85 | |
86 notification_stat.CollectAction(NOTIFICATION_ACTION_UPDATE); | |
87 } | |
88 | |
89 void MessageCenterStatsCollector::OnNotificationClicked( | |
90 const std::string& notification_id) { | |
91 StatsCollection::iterator iter = stats_.find(notification_id); | |
92 if (iter == stats_.end()) | |
93 return; | |
94 NotificationStats& notification_stat = iter->second; | |
95 | |
96 notification_stat.CollectAction(NOTIFICATION_ACTION_CLICK); | |
97 } | |
98 | |
99 void MessageCenterStatsCollector::OnNotificationButtonClicked( | |
100 const std::string& notification_id, | |
101 int button_index) { | |
102 StatsCollection::iterator iter = stats_.find(notification_id); | |
103 if (iter == stats_.end()) | |
104 return; | |
105 NotificationStats& notification_stat = iter->second; | |
106 | |
107 notification_stat.CollectAction(NOTIFICATION_ACTION_BUTTON_CLICK); | |
108 } | |
109 | |
110 void MessageCenterStatsCollector::OnNotificationDisplayed( | |
111 const std::string& notification_id) { | |
112 StatsCollection::iterator iter = stats_.find(notification_id); | |
113 if (iter == stats_.end()) | |
114 return; | |
115 NotificationStats& notification_stat = iter->second; | |
116 | |
117 notification_stat.CollectAction(NOTIFICATION_ACTION_DISPLAY); | |
118 } | |
119 | |
120 void MessageCenterStatsCollector::OnCenterVisibilityChanged( | |
121 message_center::Visibility visibility) { | |
122 switch (visibility) { | |
123 case message_center::VISIBILITY_TRANSIENT: | |
124 break; | |
125 case message_center::VISIBILITY_MESSAGE_CENTER: | |
126 content::RecordAction( | |
127 content::UserMetricsAction("Notifications.ShowMessageCenter")); | |
128 break; | |
129 case message_center::VISIBILITY_SETTINGS: | |
130 content::RecordAction( | |
131 content::UserMetricsAction("Notifications.ShowSettings")); | |
132 break; | |
133 } | |
134 } | |
135 | |
136 void MessageCenterStatsCollector::OnQuietModeChanged(bool in_quiet_mode) { | |
137 } | |
138 | |
OLD | NEW |