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

Unified Diff: chrome/browser/push_messaging/push_messaging_notification_manager.cc

Issue 2151993002: [WebAPKs] Plumb service worker scope to notifications (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge branch 'master' into notification_scope Created 4 years, 5 months 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/push_messaging/push_messaging_notification_manager.cc
diff --git a/chrome/browser/push_messaging/push_messaging_notification_manager.cc b/chrome/browser/push_messaging/push_messaging_notification_manager.cc
index e80db64effe85f8adc5f90611d4f98bd21dda374..c9bc017ed3c1a7b7196da4a8702c383097dacf32 100644
--- a/chrome/browser/push_messaging/push_messaging_notification_manager.cc
+++ b/chrome/browser/push_messaging/push_messaging_notification_manager.cc
@@ -21,6 +21,7 @@
#include "chrome/grit/generated_resources.h"
#include "components/rappor/rappor_utils.h"
#include "components/url_formatter/elide_url.h"
+#include "content/browser/service_worker/service_worker_context_wrapper.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/platform_notification_context.h"
@@ -318,6 +319,7 @@ void PushMessagingNotificationManager::CheckForMissedNotification(
base::Bind(&PushMessagingNotificationManager::
DidWriteNotificationDataIOProxy,
weak_factory_.GetWeakPtr(), origin,
+ service_worker_registration_id,
database_data.notification_data,
message_handled_closure)));
}
@@ -326,6 +328,7 @@ void PushMessagingNotificationManager::CheckForMissedNotification(
void PushMessagingNotificationManager::DidWriteNotificationDataIOProxy(
const base::WeakPtr<PushMessagingNotificationManager>& ui_weak_ptr,
const GURL& origin,
+ int service_worker_registration_id,
const PlatformNotificationData& notification_data,
const base::Closure& message_handled_closure,
bool success,
@@ -334,12 +337,14 @@ void PushMessagingNotificationManager::DidWriteNotificationDataIOProxy(
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(&PushMessagingNotificationManager::DidWriteNotificationData,
- ui_weak_ptr, origin, notification_data,
- message_handled_closure, success, persistent_notification_id));
+ ui_weak_ptr, origin, service_worker_registration_id,
+ notification_data, message_handled_closure, success,
+ persistent_notification_id));
}
void PushMessagingNotificationManager::DidWriteNotificationData(
const GURL& origin,
+ int service_worker_registration_id,
const PlatformNotificationData& notification_data,
const base::Closure& message_handled_closure,
bool success,
@@ -351,9 +356,52 @@ void PushMessagingNotificationManager::DidWriteNotificationData(
return;
}
+ // Get the service worker scope.
Peter Beverloo 2016/07/15 13:40:11 The //content API does not allow us to do this (se
+ scoped_refptr<content::ServiceWorkerContextWrapper> service_worker_context =
+ static_cast<content::ServiceWorkerContextWrapper*>(
+ GetStoragePartition(profile_, origin)->GetServiceWorkerContext());
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(
+ &content::ServiceWorkerContextWrapper::FindReadyRegistrationForId,
pkotwicz 2016/07/14 19:32:50 Is it safe to call FindReadyRegistrationForId()? T
+ service_worker_context, service_worker_registration_id, origin,
+ base::Bind(&PushMessagingNotificationManager::
+ FindServiceWorkerRegistrationCallbackIOProxy,
+ weak_factory_.GetWeakPtr(), origin, notification_data,
+ message_handled_closure, persistent_notification_id)));
+}
+
+// static
+void PushMessagingNotificationManager::
+ FindServiceWorkerRegistrationCallbackIOProxy(
+ const base::WeakPtr<PushMessagingNotificationManager>& ui_weak_ptr,
+ const GURL& origin,
+ const content::PlatformNotificationData& notification_data,
+ const base::Closure& message_handled_closure,
+ int64_t persistent_notification_id,
+ content::ServiceWorkerStatusCode service_worker_status,
+ const scoped_refptr<content::ServiceWorkerRegistration>& registration) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&PushMessagingNotificationManager::
+ FindServiceWorkerRegistrationCallback,
+ ui_weak_ptr, origin, notification_data,
+ message_handled_closure, persistent_notification_id,
+ service_worker_status, registration));
+}
+
+void PushMessagingNotificationManager::FindServiceWorkerRegistrationCallback(
+ const GURL& origin,
+ const content::PlatformNotificationData& notification_data,
+ const base::Closure& message_handled_closure,
+ int64_t persistent_notification_id,
+ content::ServiceWorkerStatusCode service_worker_status,
+ const scoped_refptr<content::ServiceWorkerRegistration>& registration) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
PlatformNotificationServiceImpl::GetInstance()->DisplayPersistentNotification(
- profile_, persistent_notification_id, origin, notification_data,
- NotificationResources());
+ profile_, persistent_notification_id, registration->pattern(), origin,
+ notification_data, NotificationResources());
message_handled_closure.Run();
}

Powered by Google App Engine
This is Rietveld 408576698