Update mojo surfaces bindings and mojo/cc/ glue
[chromium-blink-merge.git] / chrome / browser / notifications / message_center_stats_collector.cc
blob82e3e96bbc285543f83595e4bde4c6dc91f8e16b
1 // Copyright 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.
5 #include "chrome/browser/notifications/message_center_stats_collector.h"
7 #include <string>
9 #include "base/metrics/histogram.h"
10 #include "content/public/browser/user_metrics.h"
11 #include "ui/message_center/message_center.h"
13 MessageCenterStatsCollector::NotificationStats::NotificationStats() {}
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;
22 MessageCenterStatsCollector::NotificationStats::~NotificationStats() {}
24 void MessageCenterStatsCollector::NotificationStats::CollectAction(
25 NotificationActionType type) {
26 DCHECK(!id_.empty());
28 UMA_HISTOGRAM_ENUMERATION("Notifications.Actions",
29 type,
30 NOTIFICATION_ACTION_COUNT);
31 actions_[type] = true;
34 void MessageCenterStatsCollector::NotificationStats::RecordAggregateStats() {
35 DCHECK(!id_.empty());
37 for (size_t i = 0; i < NOTIFICATION_ACTION_COUNT; i++) {
38 if (!actions_[i])
39 continue;
40 UMA_HISTOGRAM_ENUMERATION("Notifications.PerNotificationActions",
42 NOTIFICATION_ACTION_COUNT);
46 MessageCenterStatsCollector::MessageCenterStatsCollector(
47 message_center::MessageCenter* message_center)
48 : message_center_(message_center) {
49 message_center_->AddObserver(this);
52 MessageCenterStatsCollector::~MessageCenterStatsCollector() {
53 message_center_->RemoveObserver(this);
56 void MessageCenterStatsCollector::OnNotificationAdded(
57 const std::string& notification_id) {
58 stats_[notification_id] = NotificationStats(notification_id);
60 StatsCollection::iterator iter = stats_.find(notification_id);
61 DCHECK(iter != stats_.end());
63 stats_[notification_id].CollectAction(NOTIFICATION_ACTION_ADD);
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();
76 stats_.erase(notification_id);
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;
86 notification_stat.CollectAction(NOTIFICATION_ACTION_UPDATE);
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;
96 notification_stat.CollectAction(NOTIFICATION_ACTION_CLICK);
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;
107 notification_stat.CollectAction(NOTIFICATION_ACTION_BUTTON_CLICK);
110 void MessageCenterStatsCollector::OnNotificationDisplayed(
111 const std::string& notification_id,
112 const message_center::DisplaySource source) {
113 StatsCollection::iterator iter = stats_.find(notification_id);
114 if (iter == stats_.end())
115 return;
116 NotificationStats& notification_stat = iter->second;
118 notification_stat.CollectAction(NOTIFICATION_ACTION_DISPLAY);
121 void MessageCenterStatsCollector::OnCenterVisibilityChanged(
122 message_center::Visibility visibility) {
123 switch (visibility) {
124 case message_center::VISIBILITY_TRANSIENT:
125 break;
126 case message_center::VISIBILITY_MESSAGE_CENTER:
127 content::RecordAction(
128 base::UserMetricsAction("Notifications.ShowMessageCenter"));
129 break;
130 case message_center::VISIBILITY_SETTINGS:
131 content::RecordAction(
132 base::UserMetricsAction("Notifications.ShowSettings"));
133 break;
137 void MessageCenterStatsCollector::OnQuietModeChanged(bool in_quiet_mode) {
138 if (in_quiet_mode) {
139 content::RecordAction(
140 base::UserMetricsAction("Notifications.Mute"));
141 } else {
142 content::RecordAction(
143 base::UserMetricsAction("Notifications.Unmute"));