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

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

Issue 1116693002: [NOT FOR REVIEW] Significantly simplify the PlatformNotificationService //content API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
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_message_filter.cc
diff --git a/content/browser/notifications/notification_message_filter.cc b/content/browser/notifications/notification_message_filter.cc
index 622fd1e66a22f0950957732a95542ddbc02aa0a3..20c0955e7d6e13534a6c0f8fdfadb2cee5fe10ab 100644
--- a/content/browser/notifications/notification_message_filter.cc
+++ b/content/browser/notifications/notification_message_filter.cc
@@ -5,7 +5,11 @@
#include "content/browser/notifications/notification_message_filter.h"
#include "base/callback.h"
+#include "base/guid.h"
+#include "base/hash.h"
+#include "base/strings/utf_string_conversions.h"
#include "content/browser/notifications/page_notification_delegate.h"
+#include "content/browser/notifications/persistent_notification_delegate.h"
#include "content/browser/notifications/platform_notification_context_impl.h"
#include "content/common/platform_notification_messages.h"
#include "content/public/browser/browser_context.h"
@@ -16,19 +20,24 @@
#include "content/public/browser/platform_notification_service.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/common/content_client.h"
+#include "ui/message_center/notification.h"
+
+using message_center::Notification;
+using message_center::NotificationDelegate;
namespace content {
NotificationMessageFilter::NotificationMessageFilter(
- int process_id,
+ int render_process_id,
PlatformNotificationContextImpl* notification_context,
ResourceContext* resource_context,
BrowserContext* browser_context)
: BrowserMessageFilter(PlatformNotificationMsgStart),
- process_id_(process_id),
+ render_process_id_(render_process_id),
notification_context_(notification_context),
resource_context_(resource_context),
browser_context_(browser_context),
+ notification_id_generator_(browser_context, render_process_id),
weak_factory_io_(this) {}
NotificationMessageFilter::~NotificationMessageFilter() {}
@@ -79,34 +88,41 @@ void NotificationMessageFilter::OnCheckNotificationPermission(
}
void NotificationMessageFilter::OnShowPlatformNotification(
- int notification_id,
+ int non_persistent_notification_id,
const GURL& origin,
const SkBitmap& icon,
const PlatformNotificationData& notification_data) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
- if (!RenderProcessHost::FromID(process_id_))
+ if (!RenderProcessHost::FromID(render_process_id_))
return;
- scoped_ptr<DesktopNotificationDelegate> delegate(
- new PageNotificationDelegate(process_id_, notification_id));
+ scoped_refptr<NotificationDelegate> delegate =
+ new PageNotificationDelegate(render_process_id_,
+ non_persistent_notification_id);
+
+ std::string notification_id =
+ notification_id_generator_.GenerateForNonPersistentNotification(
+ origin,
+ notification_data.tag,
+ non_persistent_notification_id);
+
+ message_center::Notification notification(
+ message_center::NOTIFICATION_TYPE_SIMPLE,
+ notification_id,
+ notification_data.title,
+ notification_data.body,
+ gfx::Image::CreateFrom1xBitmap(icon),
+ base::UTF8ToUTF16(origin.GetOrigin().spec()),
+ message_center::NotifierId(origin),
+ message_center::RichNotificationData(),
+ delegate.get());
PlatformNotificationService* service =
GetContentClient()->browser()->GetPlatformNotificationService();
DCHECK(service);
- if (!VerifyNotificationPermissionGranted(service, origin))
- return;
-
- base::Closure close_closure;
- service->DisplayNotification(browser_context_,
- origin,
- icon,
- notification_data,
- delegate.Pass(),
- &close_closure);
-
- if (!close_closure.is_null())
- close_closures_[notification_id] = close_closure;
+ if (VerifyNotificationPermissionGranted(service, origin))
+ service->DisplayNotification(browser_context_, notification);
}
void NotificationMessageFilter::OnShowPersistentNotification(
@@ -127,8 +143,6 @@ void NotificationMessageFilter::OnShowPersistentNotification(
database_data.service_worker_registration_id = service_worker_registration_id;
database_data.notification_data = notification_data;
- // TODO(peter): Significantly reduce the amount of information we need to
- // retain outside of the database for displaying notifications.
notification_context_->WriteNotificationData(
origin,
database_data,
@@ -150,20 +164,40 @@ void NotificationMessageFilter::DidWritePersistentNotificationData(
DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (success) {
+ scoped_refptr<NotificationDelegate> delegate =
+ new PersistentNotificationDelegate(browser_context_, origin,
+ persistent_notification_id);
+
+ std::string notification_id =
+ notification_id_generator_.GenerateForPersistentNotification(
+ origin,
+ notification_data.tag,
+ persistent_notification_id);
+
+ message_center::Notification notification(
+ message_center::NOTIFICATION_TYPE_SIMPLE,
+ notification_id,
+ notification_data.title,
+ notification_data.body,
+ gfx::Image::CreateFrom1xBitmap(icon),
+ base::UTF8ToUTF16(origin.GetOrigin().spec()),
+ message_center::NotifierId(origin),
+ message_center::RichNotificationData(),
+ delegate.get());
+
PlatformNotificationService* service =
GetContentClient()->browser()->GetPlatformNotificationService();
DCHECK(service);
- BrowserThread::PostTask(
- BrowserThread::UI,
- FROM_HERE,
- base::Bind(&PlatformNotificationService::DisplayPersistentNotification,
- base::Unretained(service), // The service is a singleton.
- browser_context_,
- persistent_notification_id,
- origin,
- icon,
- notification_data));
+ //if (VerifyNotificationPermissionGranted(service, origin)) {
+ BrowserThread::PostTask(
+ BrowserThread::UI,
+ FROM_HERE,
+ base::Bind(&PlatformNotificationService::DisplayNotification,
+ base::Unretained(service), // The service is a singleton.
+ browser_context_,
+ notification));
+ //}
}
Send(new PlatformNotificationMsg_DidShowPersistent(request_id, success));
@@ -216,20 +250,34 @@ void NotificationMessageFilter::DidGetNotifications(
}
void NotificationMessageFilter::OnClosePlatformNotification(
- int notification_id) {
+ /* const GURL& origin, */
+ /* const std::string& tag, */
+ int non_persistent_notification_id) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
- if (!RenderProcessHost::FromID(process_id_))
+ if (!RenderProcessHost::FromID(render_process_id_))
return;
- if (!close_closures_.count(notification_id))
- return;
+ // TODO(peter): Have the renderer inform us of those.
+ GURL origin("http://127.0.0.1:8000");
+ std::string tag = "";
- close_closures_[notification_id].Run();
- close_closures_.erase(notification_id);
+ std::string notification_id =
+ notification_id_generator_.GenerateForNonPersistentNotification(
+ origin,
+ tag,
+ non_persistent_notification_id);
+
+ PlatformNotificationService* service =
+ GetContentClient()->browser()->GetPlatformNotificationService();
+ DCHECK(service);
+
+ if (VerifyNotificationPermissionGranted(service, origin))
+ service->CloseNotification(browser_context_, notification_id);
}
void NotificationMessageFilter::OnClosePersistentNotification(
const GURL& origin,
+ /* const std::string& tag, */
int64_t persistent_notification_id) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (GetPermissionForOriginOnIO(origin) !=
@@ -238,19 +286,28 @@ void NotificationMessageFilter::OnClosePersistentNotification(
return;
}
+ // TODO(peter): Have the renderer inform us of this.
+ std::string tag = "";
+
PlatformNotificationService* service =
GetContentClient()->browser()->GetPlatformNotificationService();
DCHECK(service);
+ std::string notification_id =
+ notification_id_generator_.GenerateForPersistentNotification(
+ origin,
+ tag,
+ persistent_notification_id);
+
// There's no point in waiting until the database data has been removed before
// closing the notification presented to the user. Post that task immediately.
BrowserThread::PostTask(
BrowserThread::UI,
FROM_HERE,
- base::Bind(&PlatformNotificationService::ClosePersistentNotification,
+ base::Bind(&PlatformNotificationService::CloseNotification,
base::Unretained(service), // The service is a singleton.
browser_context_,
- persistent_notification_id));
+ notification_id));
notification_context_->DeleteNotificationData(
persistent_notification_id,
@@ -279,7 +336,7 @@ NotificationMessageFilter::GetPermissionForOriginOnIO(
return service->CheckPermissionOnIOThread(resource_context_,
origin,
- process_id_);
+ render_process_id_);
}
bool NotificationMessageFilter::VerifyNotificationPermissionGranted(
@@ -290,7 +347,7 @@ bool NotificationMessageFilter::VerifyNotificationPermissionGranted(
blink::WebNotificationPermission permission =
service->CheckPermissionOnUIThread(browser_context_,
origin,
- process_id_);
+ render_process_id_);
if (permission == blink::WebNotificationPermissionAllowed)
return true;

Powered by Google App Engine
This is Rietveld 408576698