| 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/metrics/histogram_macros.h" | 7 #include "base/metrics/histogram_macros.h" |
| 8 #include "base/metrics/user_metrics_action.h" |
| 8 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/notifications/desktop_notification_profile_util.h" | 12 #include "chrome/browser/notifications/desktop_notification_profile_util.h" |
| 12 #include "chrome/browser/notifications/notification_object_proxy.h" | 13 #include "chrome/browser/notifications/notification_object_proxy.h" |
| 13 #include "chrome/browser/notifications/notification_ui_manager.h" | 14 #include "chrome/browser/notifications/notification_ui_manager.h" |
| 14 #include "chrome/browser/notifications/persistent_notification_delegate.h" | 15 #include "chrome/browser/notifications/persistent_notification_delegate.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/profiles/profile_io_data.h" | 17 #include "chrome/browser/profiles/profile_io_data.h" |
| 17 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
| 18 #include "components/content_settings/core/browser/host_content_settings_map.h" | 19 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 19 #include "components/content_settings/core/common/content_settings.h" | 20 #include "components/content_settings/core/common/content_settings.h" |
| 20 #include "components/url_formatter/url_formatter.h" | 21 #include "components/url_formatter/url_formatter.h" |
| 21 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
| 22 #include "content/public/browser/desktop_notification_delegate.h" | 23 #include "content/public/browser/desktop_notification_delegate.h" |
| 23 #include "content/public/browser/notification_event_dispatcher.h" | 24 #include "content/public/browser/notification_event_dispatcher.h" |
| 24 #include "content/public/browser/platform_notification_context.h" | 25 #include "content/public/browser/platform_notification_context.h" |
| 25 #include "content/public/browser/storage_partition.h" | 26 #include "content/public/browser/storage_partition.h" |
| 27 #include "content/public/browser/user_metrics.h" |
| 26 #include "content/public/common/platform_notification_data.h" | 28 #include "content/public/common/platform_notification_data.h" |
| 27 #include "ui/message_center/notifier_settings.h" | 29 #include "ui/message_center/notifier_settings.h" |
| 28 #include "url/url_constants.h" | 30 #include "url/url_constants.h" |
| 29 | 31 |
| 30 #if defined(ENABLE_EXTENSIONS) | 32 #if defined(ENABLE_EXTENSIONS) |
| 31 #include "chrome/browser/notifications/notifier_state_tracker.h" | 33 #include "chrome/browser/notifications/notifier_state_tracker.h" |
| 32 #include "chrome/browser/notifications/notifier_state_tracker_factory.h" | 34 #include "chrome/browser/notifications/notifier_state_tracker_factory.h" |
| 33 #include "extensions/browser/extension_registry.h" | 35 #include "extensions/browser/extension_registry.h" |
| 34 #include "extensions/browser/info_map.h" | 36 #include "extensions/browser/info_map.h" |
| 35 #include "extensions/common/constants.h" | 37 #include "extensions/common/constants.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 : notification_ui_manager_for_tests_(nullptr) {} | 83 : notification_ui_manager_for_tests_(nullptr) {} |
| 82 | 84 |
| 83 PlatformNotificationServiceImpl::~PlatformNotificationServiceImpl() {} | 85 PlatformNotificationServiceImpl::~PlatformNotificationServiceImpl() {} |
| 84 | 86 |
| 85 void PlatformNotificationServiceImpl::OnPersistentNotificationClick( | 87 void PlatformNotificationServiceImpl::OnPersistentNotificationClick( |
| 86 BrowserContext* browser_context, | 88 BrowserContext* browser_context, |
| 87 int64_t persistent_notification_id, | 89 int64_t persistent_notification_id, |
| 88 const GURL& origin, | 90 const GURL& origin, |
| 89 int action_index) const { | 91 int action_index) const { |
| 90 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 92 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 93 content::RecordAction( |
| 94 base::UserMetricsAction("Notifications.Persistent.Clicked")); |
| 95 |
| 91 content::NotificationEventDispatcher::GetInstance() | 96 content::NotificationEventDispatcher::GetInstance() |
| 92 ->DispatchNotificationClickEvent( | 97 ->DispatchNotificationClickEvent( |
| 93 browser_context, | 98 browser_context, |
| 94 persistent_notification_id, | 99 persistent_notification_id, |
| 95 origin, | 100 origin, |
| 96 action_index, | 101 action_index, |
| 97 base::Bind(&OnEventDispatchComplete)); | 102 base::Bind(&OnEventDispatchComplete)); |
| 98 } | 103 } |
| 99 | 104 |
| 100 void PlatformNotificationServiceImpl::OnPersistentNotificationClose( | 105 void PlatformNotificationServiceImpl::OnPersistentNotificationClose( |
| 101 BrowserContext* browser_context, | 106 BrowserContext* browser_context, |
| 102 int64_t persistent_notification_id, | 107 int64_t persistent_notification_id, |
| 103 const GURL& origin) const { | 108 const GURL& origin) const { |
| 104 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 109 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 110 content::RecordAction( |
| 111 base::UserMetricsAction("Notifications.Persistent.Closed")); |
| 112 |
| 105 PlatformNotificationContext* context = | 113 PlatformNotificationContext* context = |
| 106 BrowserContext::GetStoragePartitionForSite(browser_context, origin) | 114 BrowserContext::GetStoragePartitionForSite(browser_context, origin) |
| 107 ->GetPlatformNotificationContext(); | 115 ->GetPlatformNotificationContext(); |
| 108 | 116 |
| 109 BrowserThread::PostTask( | 117 BrowserThread::PostTask( |
| 110 BrowserThread::IO, | 118 BrowserThread::IO, |
| 111 FROM_HERE, | 119 FROM_HERE, |
| 112 base::Bind(&PlatformNotificationContext::DeleteNotificationData, | 120 base::Bind(&PlatformNotificationContext::DeleteNotificationData, |
| 113 context, | 121 context, |
| 114 persistent_notification_id, | 122 persistent_notification_id, |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 browser_context, persistent_notification_id, origin); | 263 browser_context, persistent_notification_id, origin); |
| 256 | 264 |
| 257 Notification notification = CreateNotificationFromData( | 265 Notification notification = CreateNotificationFromData( |
| 258 profile, origin, icon, notification_data, delegate); | 266 profile, origin, icon, notification_data, delegate); |
| 259 | 267 |
| 260 // TODO(peter): Remove this mapping when we have reliable id generation for | 268 // TODO(peter): Remove this mapping when we have reliable id generation for |
| 261 // the message_center::Notification objects. | 269 // the message_center::Notification objects. |
| 262 persistent_notifications_[persistent_notification_id] = notification.id(); | 270 persistent_notifications_[persistent_notification_id] = notification.id(); |
| 263 | 271 |
| 264 GetNotificationUIManager()->Add(notification, profile); | 272 GetNotificationUIManager()->Add(notification, profile); |
| 273 content::RecordAction( |
| 274 base::UserMetricsAction("Notifications.Persistent.Shown")); |
| 265 | 275 |
| 266 profile->GetHostContentSettingsMap()->UpdateLastUsage( | 276 profile->GetHostContentSettingsMap()->UpdateLastUsage( |
| 267 origin, origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 277 origin, origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
| 268 } | 278 } |
| 269 | 279 |
| 270 void PlatformNotificationServiceImpl::ClosePersistentNotification( | 280 void PlatformNotificationServiceImpl::ClosePersistentNotification( |
| 271 BrowserContext* browser_context, | 281 BrowserContext* browser_context, |
| 272 int64_t persistent_notification_id) { | 282 int64_t persistent_notification_id) { |
| 273 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 283 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 274 | 284 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 extensions::ExtensionRegistry::Get(profile)->GetExtensionById( | 382 extensions::ExtensionRegistry::Get(profile)->GetExtensionById( |
| 373 origin.host(), extensions::ExtensionRegistry::EVERYTHING); | 383 origin.host(), extensions::ExtensionRegistry::EVERYTHING); |
| 374 DCHECK(extension); | 384 DCHECK(extension); |
| 375 | 385 |
| 376 return base::UTF8ToUTF16(extension->name()); | 386 return base::UTF8ToUTF16(extension->name()); |
| 377 } | 387 } |
| 378 #endif | 388 #endif |
| 379 | 389 |
| 380 return base::string16(); | 390 return base::string16(); |
| 381 } | 391 } |
| OLD | NEW |