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

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: 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 }
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(
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
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++) {
Ilya Sherman 2014/05/05 21:37:59 ++iter
robliao 2014/05/05 22:39:28 Done.
68 if ((*iter)->notifier_id().id == kChromeNowExtensionID)
69 google_now_notification_count++;
70 }
71 return google_now_notification_count;
72 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698