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

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

Issue 2093953002: Introduce a new API to handle native notification clicks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: initial review 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/notifications/nonpersistent_notification_handler.cc
diff --git a/chrome/browser/notifications/nonpersistent_notification_handler.cc b/chrome/browser/notifications/nonpersistent_notification_handler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a859e5437b6a4a266fe82996a7e45b5e5302ded2
--- /dev/null
+++ b/chrome/browser/notifications/nonpersistent_notification_handler.cc
@@ -0,0 +1,48 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/notifications/nonpersistent_notification_handler.h"
+
+#include "chrome/browser/notifications/notification_delegate.h"
+#include "chrome/browser/notifications/platform_notification_service_impl.h"
+
+NonPersistentNotificationHandler::NonPersistentNotificationHandler() {}
+NonPersistentNotificationHandler::~NonPersistentNotificationHandler() {}
+
+void NonPersistentNotificationHandler::Close(Profile* profile,
+ const std::string& origin,
+ const std::string& notification_id,
+ bool by_user) {
+ if (notifications_.find(notification_id) != notifications_.end()) {
+ notifications_[notification_id]->Close(by_user);
+ notifications_.erase(notification_id);
+ }
Peter Beverloo 2016/07/05 14:25:34 nit (avoids multiple lookups - elsewhere too): au
Miguel Garcia 2016/07/05 17:12:52 But unordered_map does not allow lookups by iterat
+}
+
+void NonPersistentNotificationHandler::Click(Profile* profile,
+ const std::string& origin,
+ const std::string& notification_id,
+ int action_index) {
+ // Buttons not supported for non persistent notifications.
+ DCHECK(action_index = -1);
Peter Beverloo 2016/07/05 14:25:34 This is not doing what you want it to do :) DCHEC
Miguel Garcia 2016/07/05 17:12:52 changed ;)
+ if (notifications_.find(notification_id) != notifications_.end()) {
+ notifications_[notification_id]->Click();
+ }
+}
+
+void NonPersistentNotificationHandler::Settings(Profile* profile) {
+ NotificationCommon::OpenNotificationSettings(profile);
+}
+
+void NonPersistentNotificationHandler::RegisterNotification(
+ const std::string& notification_id,
+ NotificationDelegate* delegate) {
+ DCHECK_EQ(notifications_.count(notification_id), 0u);
+ notifications_[notification_id] =
+ scoped_refptr<NotificationDelegate>(delegate);
+}
+
+NotificationCommon::Type NonPersistentNotificationHandler::NotificationType() {
+ return NotificationCommon::NONPERSISTENT;
+}

Powered by Google App Engine
This is Rietveld 408576698