Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(234)

Side by Side Diff: chrome/browser/notifications/google_now_notification_stats_collector.cc

Issue 2727103002: Remove GoogleNowNotification stats collector (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/histogram_macros.h"
10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/notifications/extension_welcome_notification.h"
12 #include "chrome/browser/notifications/notification.h"
13 #include "chrome/browser/notifications/notification_ui_manager.h"
14 #include "content/public/browser/user_metrics.h"
15 #include "ui/message_center/notification.h"
16
17 namespace {
18 const int kNotificationsMaxCount = 20;
19 }
20
21 // TODO(dewittj) remove the dependency on the MessageCenter because this
22 // violates layering.
23 GoogleNowNotificationStatsCollector::GoogleNowNotificationStatsCollector(
24 message_center::MessageCenter* message_center)
25 : message_center_(message_center) {
26 message_center_->AddObserver(this);
27 }
28
29 GoogleNowNotificationStatsCollector::~GoogleNowNotificationStatsCollector() {
30 message_center_->RemoveObserver(this);
31 }
32
33 void GoogleNowNotificationStatsCollector::OnNotificationDisplayed(
34 const std::string& notification_id,
35 const message_center::DisplaySource source) {
36 if ((source == message_center::DISPLAY_SOURCE_POPUP) &&
37 IsVisibleNotificationIdForGoogleNow(notification_id)) {
38 content::RecordAction(
39 base::UserMetricsAction(
40 "GoogleNow.MessageCenter.NotificationPoppedUp"));
41 }
42 }
43
44 void GoogleNowNotificationStatsCollector::OnCenterVisibilityChanged(
45 message_center::Visibility visibility) {
46 if (visibility == message_center::VISIBILITY_MESSAGE_CENTER) {
47 UMA_HISTOGRAM_SPARSE_SLOWLY(
48 "GoogleNow.MessageCenter.Displayed.NotificationsVisible",
49 std::min(CountVisibleGoogleNowNotifications(), kNotificationsMaxCount));
50 }
51 }
52
53 bool GoogleNowNotificationStatsCollector::IsVisibleNotificationIdForGoogleNow(
54 const std::string& notification_id) {
55 bool isGoogleNowNotification = false;
56 const message_center::Notification* const notification =
57 message_center::MessageCenter::Get()->FindVisibleNotificationById(
58 notification_id);
59 if (notification) {
60 isGoogleNowNotification =
61 ((notification->notifier_id().type ==
62 message_center::NotifierId::APPLICATION) &&
63 (notification->notifier_id().id ==
64 ExtensionWelcomeNotification::kChromeNowExtensionID));
65 }
66 return isGoogleNowNotification;
67 }
68
69 int GoogleNowNotificationStatsCollector::CountVisibleGoogleNowNotifications() {
70 typedef message_center::NotificationList::Notifications Notifications;
71 const Notifications visible_notifications =
72 message_center_->GetVisibleNotifications();
73 int google_now_notification_count = 0;
74 for (Notifications::iterator iter = visible_notifications.begin();
75 iter != visible_notifications.end();
76 ++iter) {
77 if ((*iter)->notifier_id().id ==
78 ExtensionWelcomeNotification::kChromeNowExtensionID)
79 google_now_notification_count++;
80 }
81 return google_now_notification_count;
82 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698