diff options
author | dewittj@chromium.org <dewittj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-24 03:31:13 +0000 |
---|---|---|
committer | dewittj@chromium.org <dewittj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-24 03:31:13 +0000 |
commit | 1aa5edf4eefd4e3a8eac2fe616a485f48e532882 (patch) | |
tree | c9628f632035196c16be77777c19286f3f7c3705 /chrome/browser/notifications | |
parent | cd63cb4e252a90f3b49bf910e88a97df173906a0 (diff) | |
download | chromium_src-1aa5edf4eefd4e3a8eac2fe616a485f48e532882.zip chromium_src-1aa5edf4eefd4e3a8eac2fe616a485f48e532882.tar.gz chromium_src-1aa5edf4eefd4e3a8eac2fe616a485f48e532882.tar.bz2 |
Stats collector for message center.
This uses histograms to capture detailed data about how notifications
are being interacted with by the user.
BUG=228974
Review URL: https://chromiumcodereview.appspot.com/23902057
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@224880 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/notifications')
4 files changed, 236 insertions, 15 deletions
diff --git a/chrome/browser/notifications/message_center_notification_manager.cc b/chrome/browser/notifications/message_center_notification_manager.cc index ccc9121..6ca049e 100644 --- a/chrome/browser/notifications/message_center_notification_manager.cc +++ b/chrome/browser/notifications/message_center_notification_manager.cc @@ -23,7 +23,6 @@ #include "chrome/common/extensions/extension_set.h" #include "chrome/common/pref_names.h" #include "content/public/browser/notification_service.h" -#include "content/public/browser/user_metrics.h" #include "content/public/browser/web_contents.h" #include "content/public/common/url_constants.h" #include "ui/gfx/image/image_skia.h" @@ -53,7 +52,8 @@ MessageCenterNotificationManager::MessageCenterNotificationManager( weak_factory_(this), #endif settings_provider_(settings_provider.Pass()), - system_observer_(this) { + system_observer_(this), + stats_collector_(message_center) { #if defined(OS_WIN) first_run_pref_.Init(prefs::kMessageCenterShowedFirstRunBalloon, local_state); #endif @@ -232,21 +232,10 @@ void MessageCenterNotificationManager::OnNotificationRemoved( void MessageCenterNotificationManager::OnCenterVisibilityChanged( message_center::Visibility visibility) { - switch (visibility) { - case message_center::VISIBILITY_TRANSIENT: #if defined(OS_WIN) - CheckFirstRunTimer(); + if (visibility == message_center::VISIBILITY_TRANSIENT) + CheckFirstRunTimer(); #endif - break; - case message_center::VISIBILITY_MESSAGE_CENTER: - content::RecordAction( - content::UserMetricsAction("Notifications.ShowMessageCenter")); - break; - case message_center::VISIBILITY_SETTINGS: - content::RecordAction( - content::UserMetricsAction("Notifications.ShowSettings")); - break; - } } void MessageCenterNotificationManager::OnNotificationUpdated( diff --git a/chrome/browser/notifications/message_center_notification_manager.h b/chrome/browser/notifications/message_center_notification_manager.h index 35094cc..c124570 100644 --- a/chrome/browser/notifications/message_center_notification_manager.h +++ b/chrome/browser/notifications/message_center_notification_manager.h @@ -14,6 +14,7 @@ #include "base/prefs/pref_member.h" #include "base/time/time.h" #include "base/timer/timer.h" +#include "chrome/browser/notifications/message_center_stats_collector.h" #include "chrome/browser/notifications/notification.h" #include "chrome/browser/notifications/notification_system_observer.h" #include "chrome/browser/notifications/notification_ui_manager.h" @@ -227,6 +228,9 @@ class MessageCenterNotificationManager NotificationSystemObserver system_observer_; + // Keeps track of all notification statistics for UMA purposes. + MessageCenterStatsCollector stats_collector_; + DISALLOW_COPY_AND_ASSIGN(MessageCenterNotificationManager); }; diff --git a/chrome/browser/notifications/message_center_stats_collector.cc b/chrome/browser/notifications/message_center_stats_collector.cc new file mode 100644 index 0000000..f0257a9 --- /dev/null +++ b/chrome/browser/notifications/message_center_stats_collector.cc @@ -0,0 +1,138 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/notifications/message_center_stats_collector.h" + +#include <string> + +#include "base/metrics/histogram.h" +#include "content/public/browser/user_metrics.h" +#include "ui/message_center/message_center.h" + +MessageCenterStatsCollector::NotificationStats::NotificationStats() {} + +MessageCenterStatsCollector::NotificationStats::NotificationStats( + const std::string& id) : id_(id) { + for (size_t i = 0; i < NOTIFICATION_ACTION_COUNT; i++) { + actions_[i] = false; + } +} + +MessageCenterStatsCollector::NotificationStats::~NotificationStats() {} + +void MessageCenterStatsCollector::NotificationStats::CollectAction( + NotificationActionType type) { + DCHECK(!id_.empty()); + + UMA_HISTOGRAM_ENUMERATION("Notifications.Actions", + type, + NOTIFICATION_ACTION_COUNT); + actions_[type] = true; +} + +void MessageCenterStatsCollector::NotificationStats::RecordAggregateStats() { + DCHECK(!id_.empty()); + + for (size_t i = 0; i < NOTIFICATION_ACTION_COUNT; i++) { + if (!actions_[i]) + continue; + UMA_HISTOGRAM_ENUMERATION("Notifications.PerNotificationActions", + i, + NOTIFICATION_ACTION_COUNT); + } +} + +MessageCenterStatsCollector::MessageCenterStatsCollector( + message_center::MessageCenter* message_center) + : message_center_(message_center) { + message_center_->AddObserver(this); +} + +MessageCenterStatsCollector::~MessageCenterStatsCollector() { + message_center_->RemoveObserver(this); +} + +void MessageCenterStatsCollector::OnNotificationAdded( + const std::string& notification_id) { + stats_[notification_id] = NotificationStats(notification_id); + + StatsCollection::iterator iter = stats_.find(notification_id); + DCHECK(iter != stats_.end()); + + stats_[notification_id].CollectAction(NOTIFICATION_ACTION_ADD); +} + +void MessageCenterStatsCollector::OnNotificationRemoved( + const std::string& notification_id, bool by_user) { + StatsCollection::iterator iter = stats_.find(notification_id); + if (iter == stats_.end()) + return; + NotificationStats& notification_stat = iter->second; + notification_stat.CollectAction(by_user ? + NOTIFICATION_ACTION_CLOSE_BY_USER : + NOTIFICATION_ACTION_CLOSE_BY_SYSTEM); + notification_stat.RecordAggregateStats(); + stats_.erase(notification_id); +} + +void MessageCenterStatsCollector::OnNotificationUpdated( + const std::string& notification_id) { + StatsCollection::iterator iter = stats_.find(notification_id); + if (iter == stats_.end()) + return; + NotificationStats& notification_stat = iter->second; + + notification_stat.CollectAction(NOTIFICATION_ACTION_UPDATE); +} + +void MessageCenterStatsCollector::OnNotificationClicked( + const std::string& notification_id) { + StatsCollection::iterator iter = stats_.find(notification_id); + if (iter == stats_.end()) + return; + NotificationStats& notification_stat = iter->second; + + notification_stat.CollectAction(NOTIFICATION_ACTION_CLICK); +} + +void MessageCenterStatsCollector::OnNotificationButtonClicked( + const std::string& notification_id, + int button_index) { + StatsCollection::iterator iter = stats_.find(notification_id); + if (iter == stats_.end()) + return; + NotificationStats& notification_stat = iter->second; + + notification_stat.CollectAction(NOTIFICATION_ACTION_BUTTON_CLICK); +} + +void MessageCenterStatsCollector::OnNotificationDisplayed( + const std::string& notification_id) { + StatsCollection::iterator iter = stats_.find(notification_id); + if (iter == stats_.end()) + return; + NotificationStats& notification_stat = iter->second; + + notification_stat.CollectAction(NOTIFICATION_ACTION_DISPLAY); +} + +void MessageCenterStatsCollector::OnCenterVisibilityChanged( + message_center::Visibility visibility) { + switch (visibility) { + case message_center::VISIBILITY_TRANSIENT: + break; + case message_center::VISIBILITY_MESSAGE_CENTER: + content::RecordAction( + content::UserMetricsAction("Notifications.ShowMessageCenter")); + break; + case message_center::VISIBILITY_SETTINGS: + content::RecordAction( + content::UserMetricsAction("Notifications.ShowSettings")); + break; + } +} + +void MessageCenterStatsCollector::OnQuietModeChanged(bool in_quiet_mode) { +} + diff --git a/chrome/browser/notifications/message_center_stats_collector.h b/chrome/browser/notifications/message_center_stats_collector.h new file mode 100644 index 0000000..463b7ed --- /dev/null +++ b/chrome/browser/notifications/message_center_stats_collector.h @@ -0,0 +1,90 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_NOTIFICATIONS_MESSAGE_CENTER_STATS_COLLECTOR_H_ +#define CHROME_BROWSER_NOTIFICATIONS_MESSAGE_CENTER_STATS_COLLECTOR_H_ + +#include <set> +#include <string> + +#include "ui/message_center/message_center.h" +#include "ui/message_center/message_center_observer.h" +#include "ui/message_center/message_center_types.h" + +namespace message_center { +class MessageCenter; +} + +// MessageCenterStatsCollector sends both raw and per-notification statistics +// to the UMA servers, if the user has opted in. It observes the message center +// to gather its data. +class MessageCenterStatsCollector + : public message_center::MessageCenterObserver { + public: + enum NotificationActionType { + NOTIFICATION_ACTION_UNKNOWN, + NOTIFICATION_ACTION_ADD, + NOTIFICATION_ACTION_UPDATE, + NOTIFICATION_ACTION_CLICK, + NOTIFICATION_ACTION_BUTTON_CLICK, + NOTIFICATION_ACTION_DISPLAY, + NOTIFICATION_ACTION_CLOSE_BY_USER, + NOTIFICATION_ACTION_CLOSE_BY_SYSTEM, + // NOTE: Add new action types only immediately above this line. Also, + // make sure the enum list in tools/histogram/histograms.xml is + // updated with any change in here. + NOTIFICATION_ACTION_COUNT + }; + + explicit MessageCenterStatsCollector( + message_center::MessageCenter* message_center); + virtual ~MessageCenterStatsCollector(); + + private: + // Represents the aggregate stats for each notification. + class NotificationStats { + public: + // Default constructor for map. + NotificationStats(); + + explicit NotificationStats(const std::string& id); + virtual ~NotificationStats(); + + // Called when we get an action from the message center. + void CollectAction(NotificationActionType type); + + // Sends aggregate data to UMA. + void RecordAggregateStats(); + + private: + std::string id_; + bool actions_[NOTIFICATION_ACTION_COUNT]; + }; + + // MessageCenterObserver + virtual void OnNotificationAdded(const std::string& notification_id) OVERRIDE; + virtual void OnNotificationRemoved(const std::string& notification_id, + bool by_user) OVERRIDE; + virtual void OnNotificationUpdated( + const std::string& notification_id) OVERRIDE; + virtual void OnNotificationClicked( + const std::string& notification_id) OVERRIDE; + virtual void OnNotificationButtonClicked(const std::string& notification_id, + int button_index) OVERRIDE; + virtual void OnNotificationDisplayed( + const std::string& notification_id) OVERRIDE; + virtual void OnCenterVisibilityChanged( + message_center::Visibility visibility) OVERRIDE; + virtual void OnQuietModeChanged(bool in_quiet_mode) OVERRIDE; + + // Weak, global. + message_center::MessageCenter* message_center_; + + typedef std::map<std::string,NotificationStats> StatsCollection; + StatsCollection stats_; + + DISALLOW_COPY_AND_ASSIGN(MessageCenterStatsCollector); +}; + +#endif // CHROME_BROWSER_NOTIFICATIONS_MESSAGE_CENTER_STATS_COLLECTOR_H_ |