OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/platform_notification_service_impl.h" | 5 #include "chrome/browser/notifications/platform_notification_service_impl.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/metrics/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
| 9 #include "base/metrics/user_metrics_action.h" |
9 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
10 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
11 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 13 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
13 #include "chrome/browser/notifications/desktop_notification_profile_util.h" | 14 #include "chrome/browser/notifications/desktop_notification_profile_util.h" |
14 #include "chrome/browser/notifications/notification_object_proxy.h" | 15 #include "chrome/browser/notifications/notification_object_proxy.h" |
15 #include "chrome/browser/notifications/notification_ui_manager.h" | 16 #include "chrome/browser/notifications/notification_ui_manager.h" |
16 #include "chrome/browser/notifications/persistent_notification_delegate.h" | 17 #include "chrome/browser/notifications/persistent_notification_delegate.h" |
17 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/profiles/profile_io_data.h" | 19 #include "chrome/browser/profiles/profile_io_data.h" |
19 #include "chrome/browser/ui/browser.h" | 20 #include "chrome/browser/ui/browser.h" |
20 #include "chrome/browser/ui/chrome_pages.h" | 21 #include "chrome/browser/ui/chrome_pages.h" |
21 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" | 22 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" |
22 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
23 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
24 #include "chrome/grit/generated_resources.h" | 25 #include "chrome/grit/generated_resources.h" |
25 #include "components/content_settings/core/browser/host_content_settings_map.h" | 26 #include "components/content_settings/core/browser/host_content_settings_map.h" |
26 #include "components/content_settings/core/common/content_settings.h" | 27 #include "components/content_settings/core/common/content_settings.h" |
27 #include "components/content_settings/core/common/content_settings_types.h" | 28 #include "components/content_settings/core/common/content_settings_types.h" |
28 #include "components/url_formatter/url_formatter.h" | 29 #include "components/url_formatter/url_formatter.h" |
29 #include "content/public/browser/browser_thread.h" | 30 #include "content/public/browser/browser_thread.h" |
30 #include "content/public/browser/desktop_notification_delegate.h" | 31 #include "content/public/browser/desktop_notification_delegate.h" |
31 #include "content/public/browser/notification_event_dispatcher.h" | 32 #include "content/public/browser/notification_event_dispatcher.h" |
32 #include "content/public/browser/platform_notification_context.h" | 33 #include "content/public/browser/platform_notification_context.h" |
33 #include "content/public/browser/storage_partition.h" | 34 #include "content/public/browser/storage_partition.h" |
| 35 #include "content/public/browser/user_metrics.h" |
34 #include "content/public/common/platform_notification_data.h" | 36 #include "content/public/common/platform_notification_data.h" |
35 #include "ui/base/l10n/l10n_util.h" | 37 #include "ui/base/l10n/l10n_util.h" |
36 #include "ui/base/resource/resource_bundle.h" | 38 #include "ui/base/resource/resource_bundle.h" |
37 #include "ui/message_center/notifier_settings.h" | 39 #include "ui/message_center/notifier_settings.h" |
38 #include "ui/resources/grit/ui_resources.h" | 40 #include "ui/resources/grit/ui_resources.h" |
39 #include "url/url_constants.h" | 41 #include "url/url_constants.h" |
40 | 42 |
41 #if defined(ENABLE_EXTENSIONS) | 43 #if defined(ENABLE_EXTENSIONS) |
42 #include "chrome/browser/notifications/notifier_state_tracker.h" | 44 #include "chrome/browser/notifications/notifier_state_tracker.h" |
43 #include "chrome/browser/notifications/notifier_state_tracker_factory.h" | 45 #include "chrome/browser/notifications/notifier_state_tracker_factory.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 : notification_ui_manager_for_tests_(nullptr) {} | 94 : notification_ui_manager_for_tests_(nullptr) {} |
93 | 95 |
94 PlatformNotificationServiceImpl::~PlatformNotificationServiceImpl() {} | 96 PlatformNotificationServiceImpl::~PlatformNotificationServiceImpl() {} |
95 | 97 |
96 void PlatformNotificationServiceImpl::OnPersistentNotificationClick( | 98 void PlatformNotificationServiceImpl::OnPersistentNotificationClick( |
97 BrowserContext* browser_context, | 99 BrowserContext* browser_context, |
98 int64_t persistent_notification_id, | 100 int64_t persistent_notification_id, |
99 const GURL& origin, | 101 const GURL& origin, |
100 int action_index) const { | 102 int action_index) const { |
101 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 103 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 104 content::RecordAction( |
| 105 base::UserMetricsAction("Notifications.Persistent.Clicked")); |
| 106 |
102 content::NotificationEventDispatcher::GetInstance() | 107 content::NotificationEventDispatcher::GetInstance() |
103 ->DispatchNotificationClickEvent( | 108 ->DispatchNotificationClickEvent( |
104 browser_context, | 109 browser_context, |
105 persistent_notification_id, | 110 persistent_notification_id, |
106 origin, | 111 origin, |
107 action_index, | 112 action_index, |
108 base::Bind(&OnEventDispatchComplete)); | 113 base::Bind(&OnEventDispatchComplete)); |
109 } | 114 } |
110 | 115 |
111 void PlatformNotificationServiceImpl::OnPersistentNotificationClose( | 116 void PlatformNotificationServiceImpl::OnPersistentNotificationClose( |
112 BrowserContext* browser_context, | 117 BrowserContext* browser_context, |
113 int64_t persistent_notification_id, | 118 int64_t persistent_notification_id, |
114 const GURL& origin) const { | 119 const GURL& origin) const { |
115 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 120 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 121 content::RecordAction( |
| 122 base::UserMetricsAction("Notifications.Persistent.Closed")); |
| 123 |
116 PlatformNotificationContext* context = | 124 PlatformNotificationContext* context = |
117 BrowserContext::GetStoragePartitionForSite(browser_context, origin) | 125 BrowserContext::GetStoragePartitionForSite(browser_context, origin) |
118 ->GetPlatformNotificationContext(); | 126 ->GetPlatformNotificationContext(); |
119 | 127 |
120 BrowserThread::PostTask( | 128 BrowserThread::PostTask( |
121 BrowserThread::IO, | 129 BrowserThread::IO, |
122 FROM_HERE, | 130 FROM_HERE, |
123 base::Bind(&PlatformNotificationContext::DeleteNotificationData, | 131 base::Bind(&PlatformNotificationContext::DeleteNotificationData, |
124 context, | 132 context, |
125 persistent_notification_id, | 133 persistent_notification_id, |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 settings_button_index); | 280 settings_button_index); |
273 | 281 |
274 Notification notification = CreateNotificationFromData( | 282 Notification notification = CreateNotificationFromData( |
275 profile, origin, icon, notification_data, delegate); | 283 profile, origin, icon, notification_data, delegate); |
276 | 284 |
277 // TODO(peter): Remove this mapping when we have reliable id generation for | 285 // TODO(peter): Remove this mapping when we have reliable id generation for |
278 // the message_center::Notification objects. | 286 // the message_center::Notification objects. |
279 persistent_notifications_[persistent_notification_id] = notification.id(); | 287 persistent_notifications_[persistent_notification_id] = notification.id(); |
280 | 288 |
281 GetNotificationUIManager()->Add(notification, profile); | 289 GetNotificationUIManager()->Add(notification, profile); |
| 290 content::RecordAction( |
| 291 base::UserMetricsAction("Notifications.Persistent.Shown")); |
282 | 292 |
283 HostContentSettingsMapFactory::GetForProfile(profile)->UpdateLastUsage( | 293 HostContentSettingsMapFactory::GetForProfile(profile)->UpdateLastUsage( |
284 origin, origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 294 origin, origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
285 } | 295 } |
286 | 296 |
287 void PlatformNotificationServiceImpl::ClosePersistentNotification( | 297 void PlatformNotificationServiceImpl::ClosePersistentNotification( |
288 BrowserContext* browser_context, | 298 BrowserContext* browser_context, |
289 int64_t persistent_notification_id) { | 299 int64_t persistent_notification_id) { |
290 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 300 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
291 | 301 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 extensions::ExtensionRegistry::Get(profile)->GetExtensionById( | 436 extensions::ExtensionRegistry::Get(profile)->GetExtensionById( |
427 origin.host(), extensions::ExtensionRegistry::EVERYTHING); | 437 origin.host(), extensions::ExtensionRegistry::EVERYTHING); |
428 DCHECK(extension); | 438 DCHECK(extension); |
429 | 439 |
430 return base::UTF8ToUTF16(extension->name()); | 440 return base::UTF8ToUTF16(extension->name()); |
431 } | 441 } |
432 #endif | 442 #endif |
433 | 443 |
434 return base::string16(); | 444 return base::string16(); |
435 } | 445 } |
OLD | NEW |