OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_delegate.h" | 5 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_delegate.h" |
6 | 6 |
| 7 |
| 8 #include "base/metrics/histogram.h" |
7 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h" | 9 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h" |
8 #include "chrome/browser/notifications/sync_notifier/synced_notification.h" | 10 #include "chrome/browser/notifications/sync_notifier/synced_notification.h" |
9 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
10 #include "chrome/browser/ui/browser_finder.h" | 12 #include "chrome/browser/ui/browser_finder.h" |
11 #include "content/public/browser/page_navigator.h" | 13 #include "content/public/browser/page_navigator.h" |
| 14 #include "content/public/browser/user_metrics.h" |
12 | 15 |
13 namespace notifier { | 16 namespace notifier { |
14 ChromeNotifierDelegate::ChromeNotifierDelegate( | 17 ChromeNotifierDelegate::ChromeNotifierDelegate( |
15 const std::string& notification_id, | 18 const std::string& notification_id, |
16 ChromeNotifierService* notifier) | 19 ChromeNotifierService* notifier) |
17 : notification_id_(notification_id), chrome_notifier_(notifier) {} | 20 : notification_id_(notification_id), chrome_notifier_(notifier) {} |
18 | 21 |
19 ChromeNotifierDelegate::~ChromeNotifierDelegate() {} | 22 ChromeNotifierDelegate::~ChromeNotifierDelegate() {} |
20 | 23 |
21 std::string ChromeNotifierDelegate::id() const { | 24 std::string ChromeNotifierDelegate::id() const { |
22 return notification_id_; | 25 return notification_id_; |
23 } | 26 } |
24 | 27 |
25 content::RenderViewHost* ChromeNotifierDelegate::GetRenderViewHost() const { | 28 content::RenderViewHost* ChromeNotifierDelegate::GetRenderViewHost() const { |
26 return NULL; | 29 return NULL; |
27 } | 30 } |
28 | 31 |
| 32 void ChromeNotifierDelegate::CollectAction(SyncedNotificationActionType type) { |
| 33 DCHECK(!notification_id_.empty()); |
| 34 |
| 35 UMA_HISTOGRAM_ENUMERATION("SyncedNotifications.Actions", |
| 36 type, |
| 37 SYNCED_NOTIFICATION_ACTION_COUNT); |
| 38 } |
| 39 |
| 40 |
29 // TODO(petewil) Add the ability to do URL actions also. | 41 // TODO(petewil) Add the ability to do URL actions also. |
30 void ChromeNotifierDelegate::Click() { | 42 void ChromeNotifierDelegate::Click() { |
31 SyncedNotification* notification = | 43 SyncedNotification* notification = |
32 chrome_notifier_->FindNotificationById(notification_id_); | 44 chrome_notifier_->FindNotificationById(notification_id_); |
33 if (notification == NULL) | 45 if (notification == NULL) |
34 return; | 46 return; |
35 | 47 |
36 GURL destination = notification->GetDefaultDestinationUrl(); | 48 GURL destination = notification->GetDefaultDestinationUrl(); |
37 NavigateToUrl(destination); | 49 NavigateToUrl(destination); |
38 chrome_notifier_->MarkNotificationAsRead(notification_id_); | 50 chrome_notifier_->MarkNotificationAsRead(notification_id_); |
| 51 |
| 52 // Record the action in UMA statistics. |
| 53 CollectAction(SYNCED_NOTIFICATION_ACTION_CLICK); |
39 } | 54 } |
40 | 55 |
41 // TODO(petewil) Add the ability to do URL actions also. | 56 // TODO(petewil) Add the ability to do URL actions also. |
42 void ChromeNotifierDelegate::ButtonClick(int button_index) { | 57 void ChromeNotifierDelegate::ButtonClick(int button_index) { |
43 SyncedNotification* notification = | 58 SyncedNotification* notification = |
44 chrome_notifier_->FindNotificationById(notification_id_); | 59 chrome_notifier_->FindNotificationById(notification_id_); |
45 if (notification) { | 60 if (notification) { |
46 GURL destination = notification->GetButtonUrl(button_index); | 61 GURL destination = notification->GetButtonUrl(button_index); |
47 NavigateToUrl(destination); | 62 NavigateToUrl(destination); |
48 chrome_notifier_->MarkNotificationAsRead(notification_id_); | 63 chrome_notifier_->MarkNotificationAsRead(notification_id_); |
49 } | 64 } |
| 65 |
| 66 // Now record the UMA statistics for this action. |
| 67 CollectAction(SYNCED_NOTIFICATION_ACTION_BUTTON_CLICK); |
50 } | 68 } |
51 | 69 |
52 void ChromeNotifierDelegate::NavigateToUrl(const GURL& destination) const { | 70 void ChromeNotifierDelegate::NavigateToUrl(const GURL& destination) const { |
53 if (!destination.is_valid()) | 71 if (!destination.is_valid()) |
54 return; | 72 return; |
55 | 73 |
56 content::OpenURLParams openParams(destination, content::Referrer(), | 74 content::OpenURLParams openParams(destination, content::Referrer(), |
57 NEW_FOREGROUND_TAB, | 75 NEW_FOREGROUND_TAB, |
58 content::PAGE_TRANSITION_LINK, false); | 76 content::PAGE_TRANSITION_LINK, false); |
59 Browser* browser = chrome::FindLastActiveWithProfile( | 77 Browser* browser = chrome::FindLastActiveWithProfile( |
60 chrome_notifier_->profile(), | 78 chrome_notifier_->profile(), |
61 chrome::GetActiveDesktop()); | 79 chrome::GetActiveDesktop()); |
62 // Navigate to the URL in a new tab. | 80 // Navigate to the URL in a new tab. |
63 if (browser != NULL) | 81 if (browser != NULL) |
64 browser->OpenURL(openParams); | 82 browser->OpenURL(openParams); |
65 | 83 |
66 } | 84 } |
67 | 85 |
68 void ChromeNotifierDelegate::Close(bool by_user) { | 86 void ChromeNotifierDelegate::Close(bool by_user) { |
69 if (by_user) | 87 if (by_user) |
70 chrome_notifier_->MarkNotificationAsRead(notification_id_); | 88 chrome_notifier_->MarkNotificationAsRead(notification_id_); |
| 89 |
| 90 CollectAction(by_user ? |
| 91 SYNCED_NOTIFICATION_ACTION_CLOSE_BY_USER : |
| 92 SYNCED_NOTIFICATION_ACTION_CLOSE_BY_SYSTEM); |
71 } | 93 } |
72 | 94 |
73 } // namespace notifier | 95 } // namespace notifier |
OLD | NEW |