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 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h" | 7 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h" |
8 #include "chrome/browser/notifications/sync_notifier/synced_notification.h" | 8 #include "chrome/browser/notifications/sync_notifier/synced_notification.h" |
9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
10 #include "chrome/browser/ui/browser_finder.h" | 10 #include "chrome/browser/ui/browser_finder.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 // TODO(petewil) Add the ability to do URL actions also. | 29 // TODO(petewil) Add the ability to do URL actions also. |
30 void ChromeNotifierDelegate::Click() { | 30 void ChromeNotifierDelegate::Click() { |
31 SyncedNotification* notification = | 31 SyncedNotification* notification = |
32 chrome_notifier_->FindNotificationById(notification_id_); | 32 chrome_notifier_->FindNotificationById(notification_id_); |
33 if (notification == NULL) | 33 if (notification == NULL) |
34 return; | 34 return; |
35 | 35 |
36 GURL destination = notification->GetDefaultDestinationUrl(); | 36 GURL destination = notification->GetDefaultDestinationUrl(); |
37 NavigateToUrl(destination); | 37 NavigateToUrl(destination); |
38 chrome_notifier_->MarkNotificationAsRead(notification_id_); | 38 chrome_notifier_->MarkNotificationAsRead(notification_id_); |
| 39 |
| 40 // Record the action in UMA statistics. |
| 41 StatsCollection::iterator iter = stats_.find(notification_id_); |
| 42 if (iter == stats_.end()) |
| 43 return; |
| 44 SyncedNotificationStats& notification_stat = iter->second; |
| 45 |
| 46 notification_stat.CollectAction(SYNCED_NOTIFICATION_ACTION_CLICK); |
39 } | 47 } |
40 | 48 |
41 // TODO(petewil) Add the ability to do URL actions also. | 49 // TODO(petewil) Add the ability to do URL actions also. |
42 void ChromeNotifierDelegate::ButtonClick(int button_index) { | 50 void ChromeNotifierDelegate::ButtonClick(int button_index) { |
43 SyncedNotification* notification = | 51 SyncedNotification* notification = |
44 chrome_notifier_->FindNotificationById(notification_id_); | 52 chrome_notifier_->FindNotificationById(notification_id_); |
45 if (notification) { | 53 if (notification) { |
46 GURL destination = notification->GetButtonUrl(button_index); | 54 GURL destination = notification->GetButtonUrl(button_index); |
47 NavigateToUrl(destination); | 55 NavigateToUrl(destination); |
48 chrome_notifier_->MarkNotificationAsRead(notification_id_); | 56 chrome_notifier_->MarkNotificationAsRead(notification_id_); |
49 } | 57 } |
| 58 |
| 59 // Now record the UMA statistics for this action. |
| 60 StatsCollection::iterator iter = stats_.find(notification_id_); |
| 61 if (iter == stats_.end()) |
| 62 return; |
| 63 SyncedNotificationStats& notification_stat = iter->second; |
| 64 |
| 65 notification_stat.CollectAction(SYNCED_NOTIFICATION_ACTION_CLICK); |
50 } | 66 } |
51 | 67 |
52 void ChromeNotifierDelegate::NavigateToUrl(const GURL& destination) const { | 68 void ChromeNotifierDelegate::NavigateToUrl(const GURL& destination) const { |
53 if (!destination.is_valid()) | 69 if (!destination.is_valid()) |
54 return; | 70 return; |
55 | 71 |
56 content::OpenURLParams openParams(destination, content::Referrer(), | 72 content::OpenURLParams openParams(destination, content::Referrer(), |
57 NEW_FOREGROUND_TAB, | 73 NEW_FOREGROUND_TAB, |
58 content::PAGE_TRANSITION_LINK, false); | 74 content::PAGE_TRANSITION_LINK, false); |
59 Browser* browser = chrome::FindLastActiveWithProfile( | 75 Browser* browser = chrome::FindLastActiveWithProfile( |
60 chrome_notifier_->profile(), | 76 chrome_notifier_->profile(), |
61 chrome::GetActiveDesktop()); | 77 chrome::GetActiveDesktop()); |
62 // Navigate to the URL in a new tab. | 78 // Navigate to the URL in a new tab. |
63 if (browser != NULL) | 79 if (browser != NULL) |
64 browser->OpenURL(openParams); | 80 browser->OpenURL(openParams); |
65 | 81 |
66 } | 82 } |
67 | 83 |
68 void ChromeNotifierDelegate::Close(bool by_user) { | 84 void ChromeNotifierDelegate::Close(bool by_user) { |
69 if (by_user) | 85 if (by_user) |
70 chrome_notifier_->MarkNotificationAsRead(notification_id_); | 86 chrome_notifier_->MarkNotificationAsRead(notification_id_); |
| 87 |
| 88 StatsCollection::iterator iter = stats_.find(notification_id_); |
| 89 if (iter == stats_.end()) |
| 90 return; |
| 91 SyncedNotificationStats& notification_stat = iter->second; |
| 92 notification_stat.CollectAction(by_user ? |
| 93 SYNCED_NOTIFICATION_ACTION_CLOSE_BY_USER : |
| 94 SYNCED_NOTIFICATION_ACTION_CLOSE_BY_SYSTEM); |
| 95 notification_stat.RecordAggregateStats(); |
| 96 stats_.erase(notification_id_); |
| 97 |
71 } | 98 } |
72 | 99 |
73 } // namespace notifier | 100 } // namespace notifier |
OLD | NEW |