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