| 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/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 12 #include "chrome/browser/notifications/desktop_notification_profile_util.h" | 13 #include "chrome/browser/notifications/desktop_notification_profile_util.h" |
| 13 #include "chrome/browser/notifications/notification_object_proxy.h" | 14 #include "chrome/browser/notifications/notification_object_proxy.h" |
| 14 #include "chrome/browser/notifications/notification_ui_manager.h" | 15 #include "chrome/browser/notifications/notification_ui_manager.h" |
| 15 #include "chrome/browser/notifications/persistent_notification_delegate.h" | 16 #include "chrome/browser/notifications/persistent_notification_delegate.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/profiles/profile_io_data.h" | 18 #include "chrome/browser/profiles/profile_io_data.h" |
| 18 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
| 19 #include "components/content_settings/core/browser/host_content_settings_map.h" | 20 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 20 #include "components/content_settings/core/common/content_settings.h" | 21 #include "components/content_settings/core/common/content_settings.h" |
| 21 #include "components/url_formatter/url_formatter.h" | 22 #include "components/url_formatter/url_formatter.h" |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 Notification notification = CreateNotificationFromData( | 232 Notification notification = CreateNotificationFromData( |
| 232 profile, origin, icon, notification_data, proxy); | 233 profile, origin, icon, notification_data, proxy); |
| 233 | 234 |
| 234 GetNotificationUIManager()->Add(notification, profile); | 235 GetNotificationUIManager()->Add(notification, profile); |
| 235 if (cancel_callback) | 236 if (cancel_callback) |
| 236 *cancel_callback = | 237 *cancel_callback = |
| 237 base::Bind(&CancelNotification, | 238 base::Bind(&CancelNotification, |
| 238 notification.delegate_id(), | 239 notification.delegate_id(), |
| 239 NotificationUIManager::GetProfileID(profile)); | 240 NotificationUIManager::GetProfileID(profile)); |
| 240 | 241 |
| 241 profile->GetHostContentSettingsMap()->UpdateLastUsage( | 242 HostContentSettingsMapFactory::GetForProfile(profile)->UpdateLastUsage( |
| 242 origin, origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 243 origin, origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
| 243 } | 244 } |
| 244 | 245 |
| 245 void PlatformNotificationServiceImpl::DisplayPersistentNotification( | 246 void PlatformNotificationServiceImpl::DisplayPersistentNotification( |
| 246 BrowserContext* browser_context, | 247 BrowserContext* browser_context, |
| 247 int64_t persistent_notification_id, | 248 int64_t persistent_notification_id, |
| 248 const GURL& origin, | 249 const GURL& origin, |
| 249 const SkBitmap& icon, | 250 const SkBitmap& icon, |
| 250 const content::PlatformNotificationData& notification_data) { | 251 const content::PlatformNotificationData& notification_data) { |
| 251 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 252 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 252 | 253 |
| 253 Profile* profile = Profile::FromBrowserContext(browser_context); | 254 Profile* profile = Profile::FromBrowserContext(browser_context); |
| 254 DCHECK(profile); | 255 DCHECK(profile); |
| 255 | 256 |
| 256 PersistentNotificationDelegate* delegate = new PersistentNotificationDelegate( | 257 PersistentNotificationDelegate* delegate = new PersistentNotificationDelegate( |
| 257 browser_context, persistent_notification_id, origin); | 258 browser_context, persistent_notification_id, origin); |
| 258 | 259 |
| 259 Notification notification = CreateNotificationFromData( | 260 Notification notification = CreateNotificationFromData( |
| 260 profile, origin, icon, notification_data, delegate); | 261 profile, origin, icon, notification_data, delegate); |
| 261 | 262 |
| 262 // TODO(peter): Remove this mapping when we have reliable id generation for | 263 // TODO(peter): Remove this mapping when we have reliable id generation for |
| 263 // the message_center::Notification objects. | 264 // the message_center::Notification objects. |
| 264 persistent_notifications_[persistent_notification_id] = notification.id(); | 265 persistent_notifications_[persistent_notification_id] = notification.id(); |
| 265 | 266 |
| 266 GetNotificationUIManager()->Add(notification, profile); | 267 GetNotificationUIManager()->Add(notification, profile); |
| 267 | 268 |
| 268 profile->GetHostContentSettingsMap()->UpdateLastUsage( | 269 HostContentSettingsMapFactory::GetForProfile(profile)->UpdateLastUsage( |
| 269 origin, origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 270 origin, origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
| 270 } | 271 } |
| 271 | 272 |
| 272 void PlatformNotificationServiceImpl::ClosePersistentNotification( | 273 void PlatformNotificationServiceImpl::ClosePersistentNotification( |
| 273 BrowserContext* browser_context, | 274 BrowserContext* browser_context, |
| 274 int64_t persistent_notification_id) { | 275 int64_t persistent_notification_id) { |
| 275 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 276 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 276 | 277 |
| 277 Profile* profile = Profile::FromBrowserContext(browser_context); | 278 Profile* profile = Profile::FromBrowserContext(browser_context); |
| 278 DCHECK(profile); | 279 DCHECK(profile); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 extensions::ExtensionRegistry::Get(profile)->GetExtensionById( | 381 extensions::ExtensionRegistry::Get(profile)->GetExtensionById( |
| 381 origin.host(), extensions::ExtensionRegistry::EVERYTHING); | 382 origin.host(), extensions::ExtensionRegistry::EVERYTHING); |
| 382 DCHECK(extension); | 383 DCHECK(extension); |
| 383 | 384 |
| 384 return base::UTF8ToUTF16(extension->name()); | 385 return base::UTF8ToUTF16(extension->name()); |
| 385 } | 386 } |
| 386 #endif | 387 #endif |
| 387 | 388 |
| 388 return base::string16(); | 389 return base::string16(); |
| 389 } | 390 } |
| OLD | NEW |