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

Unified Diff: content/browser/notifications/notification_event_dispatcher_impl.cc

Issue 1026853002: Integrate the notification database with the normal code path. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@n-db-ConfirmShow
Patch Set: Created 5 years, 8 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: content/browser/notifications/notification_event_dispatcher_impl.cc
diff --git a/content/browser/notifications/notification_event_dispatcher_impl.cc b/content/browser/notifications/notification_event_dispatcher_impl.cc
index a9cdd2e383709e14b6ae7ae5cee5e95afc1aa141..9f08158ec1f06564ff66952643a46c96a421792d 100644
--- a/content/browser/notifications/notification_event_dispatcher_impl.cc
+++ b/content/browser/notifications/notification_event_dispatcher_impl.cc
@@ -5,11 +5,14 @@
#include "content/browser/notifications/notification_event_dispatcher_impl.h"
#include "base/callback.h"
+#include "base/strings/string_number_conversions.h"
+#include "content/browser/notifications/platform_notification_context_impl.h"
#include "content/browser/service_worker/service_worker_context_wrapper.h"
#include "content/browser/service_worker/service_worker_registration.h"
#include "content/browser/service_worker/service_worker_storage.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/notification_database_data.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/common/platform_notification_data.h"
@@ -61,8 +64,7 @@ void NotificationClickEventFinished(
// Dispatches the notificationclick on |service_worker_registration| if the
// registration was available. Must be called on the IO thread.
void DispatchNotificationClickEventOnRegistration(
- const std::string& notification_id,
- const PlatformNotificationData& notification_data,
+ const NotificationDatabaseData& notification_database_data,
const NotificationClickDispatchCompleteCallback& dispatch_complete_callback,
ServiceWorkerStatusCode service_worker_status,
const scoped_refptr<ServiceWorkerRegistration>&
@@ -73,10 +75,17 @@ void DispatchNotificationClickEventOnRegistration(
base::Bind(&NotificationClickEventFinished,
dispatch_complete_callback,
service_worker_registration);
- service_worker_registration->active_version()
- ->DispatchNotificationClickEvent(dispatch_event_callback,
- notification_id,
- notification_data);
+
+ // TODO(peter): Pass the persistent notification id as an int64_t rather
+ // than as a string. This depends on the Blink API being updated.
+ std::string persistent_notification_id_string =
+ base::Int64ToString(notification_database_data.notification_id);
+
+ service_worker_registration->active_version()->
+ DispatchNotificationClickEvent(
+ dispatch_event_callback,
+ persistent_notification_id_string,
+ notification_database_data.notification_data);
return;
}
@@ -115,21 +124,44 @@ void DispatchNotificationClickEventOnRegistration(
// |service_worker_registration_id|. Must be called on the IO thread.
void FindServiceWorkerRegistration(
const GURL& origin,
- int64 service_worker_registration_id,
- const std::string& notification_id,
- const PlatformNotificationData& notification_data,
const NotificationClickDispatchCompleteCallback& dispatch_complete_callback,
- scoped_refptr<ServiceWorkerContextWrapper> service_worker_context) {
+ scoped_refptr<ServiceWorkerContextWrapper> service_worker_context,
+ bool success,
+ const NotificationDatabaseData& notification_database_data) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ if (!success) {
+ BrowserThread::PostTask(
+ BrowserThread::UI,
+ FROM_HERE,
+ base::Bind(dispatch_complete_callback,
+ PERSISTENT_NOTIFICATION_STATUS_DATABASE_ERROR));
+ return;
+ }
+
service_worker_context->context()->storage()->FindRegistrationForId(
- service_worker_registration_id,
+ notification_database_data.service_worker_registration_id,
origin,
base::Bind(&DispatchNotificationClickEventOnRegistration,
- notification_id,
- notification_data,
+ notification_database_data,
dispatch_complete_callback));
}
+// Reads the data associated with the |persistent_notification_id| belonging to
+// |origin| from the notification context.
+void ReadNotificationDatabaseData(
+ int64_t persistent_notification_id,
+ const GURL& origin,
+ const NotificationClickDispatchCompleteCallback& dispatch_complete_callback,
+ scoped_refptr<ServiceWorkerContextWrapper> service_worker_context,
+ scoped_refptr<PlatformNotificationContextImpl> notification_context) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ notification_context->ReadNotificationData(
+ persistent_notification_id,
+ origin,
+ base::Bind(&FindServiceWorkerRegistration,
+ origin, dispatch_complete_callback, service_worker_context));
+}
+
} // namespace
// static
@@ -149,29 +181,33 @@ NotificationEventDispatcherImpl::~NotificationEventDispatcherImpl() {}
void NotificationEventDispatcherImpl::DispatchNotificationClickEvent(
BrowserContext* browser_context,
+ int64_t persistent_notification_id,
const GURL& origin,
- int64 service_worker_registration_id,
- const std::string& notification_id,
- const PlatformNotificationData& notification_data,
const NotificationClickDispatchCompleteCallback&
dispatch_complete_callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ DCHECK_GT(persistent_notification_id, 0);
+ DCHECK(origin.is_valid());
StoragePartition* partition =
BrowserContext::GetStoragePartitionForSite(browser_context, origin);
+
scoped_refptr<ServiceWorkerContextWrapper> service_worker_context =
static_cast<ServiceWorkerContextWrapper*>(
partition->GetServiceWorkerContext());
+ scoped_refptr<PlatformNotificationContextImpl> notification_context =
+ static_cast<PlatformNotificationContextImpl*>(
+ partition->GetPlatformNotificationContext());
+
BrowserThread::PostTask(
BrowserThread::IO,
FROM_HERE,
- base::Bind(&FindServiceWorkerRegistration,
+ base::Bind(&ReadNotificationDatabaseData,
+ persistent_notification_id,
origin,
- service_worker_registration_id,
- notification_id,
- notification_data,
dispatch_complete_callback,
- service_worker_context));
+ service_worker_context,
+ notification_context));
}
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698