Index: chrome/browser/notifications/google_now_notification_stats_collector.cc |
diff --git a/chrome/browser/notifications/google_now_notification_stats_collector.cc b/chrome/browser/notifications/google_now_notification_stats_collector.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8f6dfebda53aa88505cf6415823f53d90f79160b |
--- /dev/null |
+++ b/chrome/browser/notifications/google_now_notification_stats_collector.cc |
@@ -0,0 +1,72 @@ |
+// Copyright 2014 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/google_now_notification_stats_collector.h" |
+ |
+#include <string> |
+ |
+#include "base/metrics/sparse_histogram.h" |
+#include "chrome/browser/browser_process.h" |
+#include "chrome/browser/notifications/notification.h" |
+#include "chrome/browser/notifications/notification_ui_manager.h" |
+#include "content/public/browser/user_metrics.h" |
+#include "ui/message_center/notification.h" |
+ |
+namespace { |
+const char kChromeNowExtensionID[] = "pafkbggdmjlpgkdkcbjmhmfcdpncadgh"; |
+} |
+ |
+GoogleNowNotificationStatsCollector::GoogleNowNotificationStatsCollector( |
+ message_center::MessageCenter* message_center) |
+ : message_center_(message_center) { |
+ message_center_->AddObserver(this); |
+} |
+ |
+GoogleNowNotificationStatsCollector::~GoogleNowNotificationStatsCollector() { |
+ message_center_->RemoveObserver(this); |
+} |
+ |
+void GoogleNowNotificationStatsCollector::OnNotificationPoppedUp( |
+ const std::string& notification_id) { |
+ if (IsNotificationIdForGoogleNow(notification_id)) { |
+ content::RecordAction( |
+ base::UserMetricsAction( |
+ "GoogleNow.MessageCenter.NotificationPoppedUp")); |
+ } |
+} |
+ |
+void GoogleNowNotificationStatsCollector::OnCenterVisibilityChanged( |
+ message_center::Visibility visibility) { |
+ if (visibility == message_center::VISIBILITY_MESSAGE_CENTER) { |
+ UMA_HISTOGRAM_SPARSE_SLOWLY( |
Ilya Sherman
2014/05/05 21:37:59
I don't think you need a sparse histogram for this
robliao
2014/05/05 22:39:28
We want to avoid bucketing if at all possible. How
Ilya Sherman
2014/05/05 23:27:36
Why do you want to avoid bucketing? What sorts of
robliao
2014/05/05 23:33:55
We're interested in measuring the following specif
Ilya Sherman
2014/05/05 23:39:07
That sounds fine. Please implement that cap. If
robliao
2014/05/05 23:45:56
When crunching stats for review, yes.
To the orig
Ilya Sherman
2014/05/05 23:53:32
If you want linear buckets, you might as well keep
robliao
2014/05/06 00:06:15
We discovered that our sparse histograms on the UM
Ilya Sherman
2014/05/06 00:10:52
Yep, 'tis.
robliao
2014/05/06 00:17:33
Okay, so how does this sound then?
UMA_HISTOGRAM_S
Ilya Sherman
2014/05/06 00:18:15
Sounds fine.
robliao
2014/05/06 00:25:29
It's a done deal.
On 2014/05/06 00:18:15, Ilya She
|
+ "GoogleNow.MessageCenter.Displayed.NotificationsVisible", |
+ CountVisibleGoogleNowNotifications()); |
+ } |
+} |
+ |
+bool GoogleNowNotificationStatsCollector::IsNotificationIdForGoogleNow( |
+ const std::string& notification_id) { |
+ bool isGoogleNowNotification = false; |
+ const Notification* const notification = |
+ g_browser_process->notification_ui_manager()->FindById(notification_id); |
+ if (notification) { |
+ isGoogleNowNotification = |
+ (notification->notifier_id().id == kChromeNowExtensionID); |
+ } |
+ return isGoogleNowNotification; |
+} |
+ |
+int GoogleNowNotificationStatsCollector::CountVisibleGoogleNowNotifications() { |
+ typedef message_center::NotificationList::Notifications Notifications; |
+ const Notifications visible_notifications = |
+ message_center_->GetVisibleNotifications(); |
+ int google_now_notification_count = 0; |
+ for (Notifications::iterator iter = visible_notifications.begin(); |
+ iter != visible_notifications.end(); |
+ iter++) { |
Ilya Sherman
2014/05/05 21:37:59
++iter
robliao
2014/05/05 22:39:28
Done.
|
+ if ((*iter)->notifier_id().id == kChromeNowExtensionID) |
+ google_now_notification_count++; |
+ } |
+ return google_now_notification_count; |
+} |