Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / chrome / browser / notifications / message_center_stats_collector.h
blobf5808d077a1a9268bbc27100c7b3bffe6411ba77
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 #ifndef CHROME_BROWSER_NOTIFICATIONS_MESSAGE_CENTER_STATS_COLLECTOR_H_
6 #define CHROME_BROWSER_NOTIFICATIONS_MESSAGE_CENTER_STATS_COLLECTOR_H_
8 #include <set>
9 #include <string>
11 #include "ui/message_center/message_center.h"
12 #include "ui/message_center/message_center_observer.h"
13 #include "ui/message_center/message_center_types.h"
15 namespace message_center {
16 class MessageCenter;
19 // MessageCenterStatsCollector sends both raw and per-notification statistics
20 // to the UMA servers, if the user has opted in. It observes the message center
21 // to gather its data.
22 class MessageCenterStatsCollector
23 : public message_center::MessageCenterObserver {
24 public:
25 enum NotificationActionType {
26 NOTIFICATION_ACTION_UNKNOWN,
27 NOTIFICATION_ACTION_ADD,
28 NOTIFICATION_ACTION_UPDATE,
29 NOTIFICATION_ACTION_CLICK,
30 NOTIFICATION_ACTION_BUTTON_CLICK,
31 NOTIFICATION_ACTION_DISPLAY,
32 NOTIFICATION_ACTION_CLOSE_BY_USER,
33 NOTIFICATION_ACTION_CLOSE_BY_SYSTEM,
34 // NOTE: Add new action types only immediately above this line. Also,
35 // make sure the enum list in tools/histogram/histograms.xml is
36 // updated with any change in here.
37 NOTIFICATION_ACTION_COUNT
40 explicit MessageCenterStatsCollector(
41 message_center::MessageCenter* message_center);
42 ~MessageCenterStatsCollector() override;
44 private:
45 // Represents the aggregate stats for each notification.
46 class NotificationStats {
47 public:
48 // Default constructor for map.
49 NotificationStats();
51 explicit NotificationStats(const std::string& id);
52 virtual ~NotificationStats();
54 // Called when we get an action from the message center.
55 void CollectAction(NotificationActionType type);
57 // Sends aggregate data to UMA.
58 void RecordAggregateStats();
60 private:
61 std::string id_;
62 bool actions_[NOTIFICATION_ACTION_COUNT];
65 // MessageCenterObserver
66 void OnNotificationAdded(const std::string& notification_id) override;
67 void OnNotificationRemoved(const std::string& notification_id,
68 bool by_user) override;
69 void OnNotificationUpdated(const std::string& notification_id) override;
70 void OnNotificationClicked(const std::string& notification_id) override;
71 void OnNotificationButtonClicked(const std::string& notification_id,
72 int button_index) override;
73 void OnNotificationDisplayed(
74 const std::string& notification_id,
75 const message_center::DisplaySource source) override;
76 void OnCenterVisibilityChanged(
77 message_center::Visibility visibility) override;
78 void OnQuietModeChanged(bool in_quiet_mode) override;
80 // Weak, global.
81 message_center::MessageCenter* message_center_;
83 typedef std::map<std::string,NotificationStats> StatsCollection;
84 StatsCollection stats_;
86 DISALLOW_COPY_AND_ASSIGN(MessageCenterStatsCollector);
89 #endif // CHROME_BROWSER_NOTIFICATIONS_MESSAGE_CENTER_STATS_COLLECTOR_H_