OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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/google_now_notification_stats_collector.h
" |
| 6 |
| 7 #include <string> |
| 8 |
| 9 #include "base/metrics/sparse_histogram.h" |
| 10 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/notifications/notification.h" |
| 12 #include "chrome/browser/notifications/notification_ui_manager.h" |
| 13 #include "content/public/browser/user_metrics.h" |
| 14 #include "ui/message_center/notification.h" |
| 15 |
| 16 namespace { |
| 17 const char kChromeNowExtensionID[] = "pafkbggdmjlpgkdkcbjmhmfcdpncadgh"; |
| 18 } |
| 19 |
| 20 GoogleNowNotificationStatsCollector::GoogleNowNotificationStatsCollector( |
| 21 message_center::MessageCenter* message_center) |
| 22 : message_center_(message_center) { |
| 23 message_center_->AddObserver(this); |
| 24 } |
| 25 |
| 26 GoogleNowNotificationStatsCollector::~GoogleNowNotificationStatsCollector() { |
| 27 message_center_->RemoveObserver(this); |
| 28 } |
| 29 |
| 30 void GoogleNowNotificationStatsCollector::OnNotificationPoppedUp( |
| 31 const std::string& notification_id) { |
| 32 if (IsNotificationIdForGoogleNow(notification_id)) { |
| 33 content::RecordAction( |
| 34 base::UserMetricsAction( |
| 35 "GoogleNow.MessageCenter.NotificationPoppedUp")); |
| 36 } |
| 37 } |
| 38 |
| 39 void GoogleNowNotificationStatsCollector::OnCenterVisibilityChanged( |
| 40 message_center::Visibility visibility) { |
| 41 if (visibility == message_center::VISIBILITY_MESSAGE_CENTER) { |
| 42 UMA_HISTOGRAM_SPARSE_SLOWLY( |
| 43 "GoogleNow.MessageCenter.Displayed.NotificationsVisible", |
| 44 CountVisibleGoogleNowNotifications()); |
| 45 } |
| 46 } |
| 47 |
| 48 bool GoogleNowNotificationStatsCollector::IsNotificationIdForGoogleNow( |
| 49 const std::string& notification_id) { |
| 50 bool isGoogleNowNotification = false; |
| 51 const Notification* const notification = |
| 52 g_browser_process->notification_ui_manager()->FindById(notification_id); |
| 53 if (notification) { |
| 54 isGoogleNowNotification = |
| 55 (notification->notifier_id().id == kChromeNowExtensionID); |
| 56 } |
| 57 return isGoogleNowNotification; |
| 58 } |
| 59 |
| 60 int GoogleNowNotificationStatsCollector::CountVisibleGoogleNowNotifications() { |
| 61 typedef message_center::NotificationList::Notifications Notifications; |
| 62 const Notifications visible_notifications = |
| 63 message_center_->GetVisibleNotifications(); |
| 64 int google_now_notification_count = 0; |
| 65 for (Notifications::iterator iter = visible_notifications.begin(); |
| 66 iter != visible_notifications.end(); |
| 67 ++iter) { |
| 68 if ((*iter)->notifier_id().id == kChromeNowExtensionID) |
| 69 google_now_notification_count++; |
| 70 } |
| 71 return google_now_notification_count; |
| 72 } |
OLD | NEW |