diff options
author | peter <peter@chromium.org> | 2015-03-28 16:15:02 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-03-28 23:15:45 +0000 |
commit | 1bca63ecfb185e669d10ece2920d8b4d56dba925 (patch) | |
tree | 2c0e4a6beadfaa9b6cdeb06b5f5d5f4f96404fa1 | |
parent | e5fc8e4937c6902cf25248fb88faca0cd0245c7b (diff) | |
download | chromium_src-1bca63ecfb185e669d10ece2920d8b4d56dba925.zip chromium_src-1bca63ecfb185e669d10ece2920d8b4d56dba925.tar.gz chromium_src-1bca63ecfb185e669d10ece2920d8b4d56dba925.tar.bz2 |
Have the browser process confirm creation of a persistent notification.
There are two reasons why this is going to be important:
(1) With a database in the display path, there are failure cases.
(2) After the SWR.showNotification() promise resolves, the developer
should be able to assume it's included in SWR.getNotifications().
The browser process confirming display of the notification enables these
cases to be implemented reliably.
BUG=447628
Review URL: https://codereview.chromium.org/1021293002
Cr-Commit-Position: refs/heads/master@{#322711}
5 files changed, 48 insertions, 5 deletions
diff --git a/content/browser/notifications/notification_message_filter.cc b/content/browser/notifications/notification_message_filter.cc index 99e13c0..f1aa17a 100644 --- a/content/browser/notifications/notification_message_filter.cc +++ b/content/browser/notifications/notification_message_filter.cc @@ -111,6 +111,7 @@ void NotificationMessageFilter::OnShowPlatformNotification( } void NotificationMessageFilter::OnShowPersistentNotification( + int request_id, int64 service_worker_registration_id, const GURL& origin, const SkBitmap& icon, @@ -129,6 +130,11 @@ void NotificationMessageFilter::OnShowPersistentNotification( service->DisplayPersistentNotification(browser_context_, service_worker_registration_id, origin, icon, notification_data); + + // TODO(peter): Confirm display of the persistent notification after the + // data has been stored using the |notification_context_|. + Send(new PlatformNotificationMsg_DidShowPersistent(request_id, + true /* success */)); } void NotificationMessageFilter::OnGetNotifications( diff --git a/content/browser/notifications/notification_message_filter.h b/content/browser/notifications/notification_message_filter.h index 75b0895..9499a133 100644 --- a/content/browser/notifications/notification_message_filter.h +++ b/content/browser/notifications/notification_message_filter.h @@ -51,6 +51,7 @@ class NotificationMessageFilter : public BrowserMessageFilter { const SkBitmap& icon, const PlatformNotificationData& notification_data); void OnShowPersistentNotification( + int request_id, int64 service_worker_registration_id, const GURL& origin, const SkBitmap& icon, diff --git a/content/child/notifications/notification_manager.cc b/content/child/notifications/notification_manager.cc index f1dec82..6f5e8fe 100644 --- a/content/child/notifications/notification_manager.cc +++ b/content/child/notifications/notification_manager.cc @@ -198,6 +198,8 @@ bool NotificationManager::OnMessageReceived(const IPC::Message& message) { bool handled = true; IPC_BEGIN_MESSAGE_MAP(NotificationManager, message) IPC_MESSAGE_HANDLER(PlatformNotificationMsg_DidShow, OnDidShow); + IPC_MESSAGE_HANDLER(PlatformNotificationMsg_DidShowPersistent, + OnDidShowPersistent) IPC_MESSAGE_HANDLER(PlatformNotificationMsg_DidClose, OnDidClose); IPC_MESSAGE_HANDLER(PlatformNotificationMsg_DidClick, OnDidClick); IPC_MESSAGE_HANDLER(PlatformNotificationMsg_DidGetNotifications, @@ -216,6 +218,22 @@ void NotificationManager::OnDidShow(int notification_id) { iter->second->dispatchShowEvent(); } +void NotificationManager::OnDidShowPersistent(int request_id, bool success) { + blink::WebNotificationShowCallbacks* callbacks = + pending_show_notification_requests_.Lookup(request_id); + DCHECK(callbacks); + + if (!callbacks) + return; + + if (success) + callbacks->onSuccess(); + else + callbacks->onError(); + + pending_show_notification_requests_.Remove(request_id); +} + void NotificationManager::OnDidClose(int notification_id) { const auto& iter = active_page_notifications_.find(notification_id); if (iter == active_page_notifications_.end()) @@ -284,16 +302,21 @@ void NotificationManager::DisplayPersistentNotification( int64 service_worker_registration_id, scoped_ptr<blink::WebNotificationShowCallbacks> callbacks, const SkBitmap& icon) { + // TODO(peter): GenerateNotificationId is more of a request id. Consider + // renaming the method in the NotificationDispatcher if this makes sense. + int request_id = + notification_dispatcher_->GenerateNotificationId(CurrentWorkerId()); + + pending_show_notification_requests_.AddWithID(callbacks.release(), + request_id); + thread_safe_sender_->Send( new PlatformNotificationHostMsg_ShowPersistent( + request_id, service_worker_registration_id, GURL(origin.string()), icon, ToPlatformNotificationData(notification_data))); - - // There currently isn't a case in which the promise would be rejected per - // our implementation, so always resolve it here. - callbacks->onSuccess(); } } // namespace content diff --git a/content/child/notifications/notification_manager.h b/content/child/notifications/notification_manager.h index ae9a1ec..7624198 100644 --- a/content/child/notifications/notification_manager.h +++ b/content/child/notifications/notification_manager.h @@ -73,6 +73,7 @@ class NotificationManager : public blink::WebNotificationManager, // IPC message handlers. void OnDidShow(int notification_id); + void OnDidShowPersistent(int request_id, bool success); void OnDidClose(int notification_id); void OnDidClick(int notification_id); void OnDidGetNotifications( @@ -111,6 +112,10 @@ class NotificationManager : public blink::WebNotificationManager, IDMap<blink::WebNotificationGetCallbacks, IDMapOwnPointer> pending_get_notification_requests_; + // Tracks pending requests for displaying persistent notifications. + IDMap<blink::WebNotificationShowCallbacks, IDMapOwnPointer> + pending_show_notification_requests_; + // Map to store the delegate associated with a notification request Id. std::map<int, blink::WebNotificationDelegate*> active_page_notifications_; diff --git a/content/common/platform_notification_messages.h b/content/common/platform_notification_messages.h index eef981f..3ed9b2f 100644 --- a/content/common/platform_notification_messages.h +++ b/content/common/platform_notification_messages.h @@ -59,6 +59,13 @@ IPC_MESSAGE_CONTROL1(PlatformNotificationMsg_DidClose, IPC_MESSAGE_CONTROL1(PlatformNotificationMsg_DidClick, int /* notification_id */) +// Reply to PlatformNotificationHostMsg_ShowPersistent indicating that a +// persistent notification has been shown on the platform (if |success| is +// true), or that an unspecified error occurred. +IPC_MESSAGE_CONTROL2(PlatformNotificationMsg_DidShowPersistent, + int /* request_id */, + bool /* success */) + // Reply to PlatformNotificationHostMsg_GetNotifications sharing a vector of // available notifications per the request's constraints. IPC_MESSAGE_CONTROL2(PlatformNotificationMsg_DidGetNotifications, @@ -74,7 +81,8 @@ IPC_MESSAGE_CONTROL4(PlatformNotificationHostMsg_Show, SkBitmap /* icon */, content::PlatformNotificationData /* notification_data */) -IPC_MESSAGE_CONTROL4(PlatformNotificationHostMsg_ShowPersistent, +IPC_MESSAGE_CONTROL5(PlatformNotificationHostMsg_ShowPersistent, + int /* request_id */, int64_t /* service_worker_registration_id */, GURL /* origin */, SkBitmap /* icon */, |