Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2046)

Unified Diff: chrome/browser/notifications/platform_notification_service_impl.cc

Issue 784383002: Support persistent notifications in the PlatformNotificationServiceImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@n-chrome-base
Patch Set: adds browser tests Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/notifications/platform_notification_service_impl.cc
diff --git a/chrome/browser/notifications/platform_notification_service_impl.cc b/chrome/browser/notifications/platform_notification_service_impl.cc
index 991acdc7c21b6892e91291d5184bd228d852f2ad..bf4861992efede1d8010bb81039b12a4f67cd5ce 100644
--- a/chrome/browser/notifications/platform_notification_service_impl.cc
+++ b/chrome/browser/notifications/platform_notification_service_impl.cc
@@ -6,15 +6,16 @@
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/browser_process.h"
-#include "chrome/browser/notifications/notification.h"
#include "chrome/browser/notifications/notification_object_proxy.h"
#include "chrome/browser/notifications/notification_ui_manager.h"
+#include "chrome/browser/notifications/persistent_notification_delegate.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_io_data.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/content_settings/core/common/content_settings.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/desktop_notification_delegate.h"
+#include "content/public/browser/notification_event_dispatcher.h"
#include "content/public/common/show_desktop_notification_params.h"
#include "ui/message_center/notifier_settings.h"
@@ -51,12 +52,30 @@ PlatformNotificationServiceImpl::PlatformNotificationServiceImpl()
PlatformNotificationServiceImpl::~PlatformNotificationServiceImpl() {}
+void PlatformNotificationServiceImpl::OnPersistentNotificationClick(
+ content::BrowserContext* browser_context,
+ int64 service_worker_registration_id,
+ const std::string& notification_id,
+ const content::ShowDesktopNotificationHostMsgParams& params,
+ const base::Callback<void(content::PersistentNotificationStatus)>&
+ callback) const {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ content::NotificationEventDispatcher::GetInstance()
+ ->DispatchNotificationClickEvent(
+ browser_context,
+ params.origin,
+ service_worker_registration_id,
+ notification_id,
+ params,
+ callback);
+}
+
blink::WebNotificationPermission
PlatformNotificationServiceImpl::CheckPermission(
content::ResourceContext* resource_context,
const GURL& origin,
int render_process_id) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
#if defined(ENABLE_EXTENSIONS)
@@ -100,31 +119,20 @@ void PlatformNotificationServiceImpl::DisplayNotification(
scoped_ptr<content::DesktopNotificationDelegate> delegate,
int render_process_id,
base::Closure* cancel_callback) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
Profile* profile = Profile::FromBrowserContext(browser_context);
DCHECK(profile);
NotificationObjectProxy* proxy = new NotificationObjectProxy(delegate.Pass());
- base::string16 display_source = DisplayNameForOriginInProcessId(
- profile, params.origin, render_process_id);
-
- // TODO(peter): Icons for Web Notifications are currently always requested for
- // 1x scale, whereas the displays on which they can be displayed can have a
- // different pixel density. Be smarter about this when the API gets updated
- // with a way for developers to specify images of different resolutions.
- Notification notification(params.origin, params.title, params.body,
- gfx::Image::CreateFrom1xBitmap(params.icon),
- display_source, params.replace_id, proxy);
-
- // Web Notifications do not timeout.
- notification.set_never_timeout(true);
+ Notification notification = CreateNotificationFromData(
+ profile, params, proxy, render_process_id);
GetNotificationUIManager()->Add(notification, profile);
if (cancel_callback)
*cancel_callback =
base::Bind(&CancelNotification,
- proxy->id(),
+ notification.delegate_id(),
NotificationUIManager::GetProfileID(profile));
profile->GetHostContentSettingsMap()->UpdateLastUsage(
@@ -136,13 +144,55 @@ void PlatformNotificationServiceImpl::DisplayPersistentNotification(
int64 service_worker_registration_id,
const content::ShowDesktopNotificationHostMsgParams& params,
int render_process_id) {
- NOTIMPLEMENTED();
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+
+ Profile* profile = Profile::FromBrowserContext(browser_context);
+ DCHECK(profile);
+
+ PersistentNotificationDelegate* delegate = new PersistentNotificationDelegate(
+ browser_context, service_worker_registration_id, params);
+
+ Notification notification = CreateNotificationFromData(
+ profile, params, delegate, render_process_id);
+
+ GetNotificationUIManager()->Add(notification, profile);
+
+ profile->GetHostContentSettingsMap()->UpdateLastUsage(
+ params.origin, params.origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
}
void PlatformNotificationServiceImpl::ClosePersistentNotification(
content::BrowserContext* browser_context,
const std::string& persistent_notification_id) {
- NOTIMPLEMENTED();
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+
+ Profile* profile = Profile::FromBrowserContext(browser_context);
+ DCHECK(profile);
+
+ GetNotificationUIManager()->CancelById(
+ persistent_notification_id, NotificationUIManager::GetProfileID(profile));
+}
+
+Notification PlatformNotificationServiceImpl::CreateNotificationFromData(
+ Profile* profile,
+ const content::ShowDesktopNotificationHostMsgParams& params,
+ NotificationDelegate* delegate,
+ int render_process_id) const {
+ base::string16 display_source = DisplayNameForOriginInProcessId(
+ profile, params.origin, render_process_id);
+
+ // TODO(peter): Icons for Web Notifications are currently always requested for
+ // 1x scale, whereas the displays on which they can be displayed can have a
+ // different pixel density. Be smarter about this when the API gets updated
+ // with a way for developers to specify images of different resolutions.
+ Notification notification(params.origin, params.title, params.body,
+ gfx::Image::CreateFrom1xBitmap(params.icon),
+ display_source, params.replace_id, delegate);
+
+ // Web Notifications do not timeout.
+ notification.set_never_timeout(true);
+
+ return notification;
}
NotificationUIManager*
@@ -159,7 +209,7 @@ void PlatformNotificationServiceImpl::SetNotificationUIManagerForTesting(
}
base::string16 PlatformNotificationServiceImpl::DisplayNameForOriginInProcessId(
- Profile* profile, const GURL& origin, int process_id) {
+ Profile* profile, const GURL& origin, int process_id) const {
#if defined(ENABLE_EXTENSIONS)
// If the source is an extension, lookup the display name.
if (origin.SchemeIs(extensions::kExtensionScheme)) {

Powered by Google App Engine
This is Rietveld 408576698