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

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

Issue 264123002: Google Now Message Center Stats (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Histogram Update Created 6 years, 7 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 | Annotate | Revision Log
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/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 const int kNotificationsMaxCount = 10;
Ilya Sherman 2014/05/06 00:33:39 As I mentioned before, if you're worried that 10 m
19 }
20
21 GoogleNowNotificationStatsCollector::GoogleNowNotificationStatsCollector(
22 message_center::MessageCenter* message_center)
23 : message_center_(message_center) {
24 message_center_->AddObserver(this);
25 }
26
27 GoogleNowNotificationStatsCollector::~GoogleNowNotificationStatsCollector() {
28 message_center_->RemoveObserver(this);
29 }
30
31 void GoogleNowNotificationStatsCollector::OnNotificationPoppedUp(
32 const std::string& notification_id) {
33 if (IsNotificationIdForGoogleNow(notification_id)) {
34 content::RecordAction(
35 base::UserMetricsAction(
36 "GoogleNow.MessageCenter.NotificationPoppedUp"));
37 }
38 }
39
40 void GoogleNowNotificationStatsCollector::OnCenterVisibilityChanged(
41 message_center::Visibility visibility) {
42 if (visibility == message_center::VISIBILITY_MESSAGE_CENTER) {
43 UMA_HISTOGRAM_SPARSE_SLOWLY(
44 "GoogleNow.MessageCenter.Displayed.NotificationsVisible",
45 std::min(CountVisibleGoogleNowNotifications(), kNotificationsMaxCount));
46 }
47 }
48
49 bool GoogleNowNotificationStatsCollector::IsNotificationIdForGoogleNow(
50 const std::string& notification_id) {
51 bool isGoogleNowNotification = false;
52 const Notification* const notification =
53 g_browser_process->notification_ui_manager()->FindById(notification_id);
54 if (notification) {
55 isGoogleNowNotification =
56 (notification->notifier_id().id == kChromeNowExtensionID);
57 }
58 return isGoogleNowNotification;
59 }
60
61 int GoogleNowNotificationStatsCollector::CountVisibleGoogleNowNotifications() {
62 typedef message_center::NotificationList::Notifications Notifications;
63 const Notifications visible_notifications =
64 message_center_->GetVisibleNotifications();
65 int google_now_notification_count = 0;
66 for (Notifications::iterator iter = visible_notifications.begin();
67 iter != visible_notifications.end();
68 ++iter) {
69 if ((*iter)->notifier_id().id == kChromeNowExtensionID)
70 google_now_notification_count++;
71 }
72 return google_now_notification_count;
73 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698