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

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

Issue 2917923004: Move handler processing to NotificationDisplayService
Patch Set: Created 3 years, 7 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/notification_display_service.cc
diff --git a/chrome/browser/notifications/notification_display_service.cc b/chrome/browser/notifications/notification_display_service.cc
new file mode 100644
index 0000000000000000000000000000000000000000..885b204c5224a7b472136616bb359885bff87d6a
--- /dev/null
+++ b/chrome/browser/notifications/notification_display_service.cc
@@ -0,0 +1,73 @@
+// Copyright 2017 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/notification_display_service.h"
+
+#include "base/memory/ptr_util.h"
+#include "base/strings/nullable_string16.h"
+#include "chrome/browser/notifications/non_persistent_notification_handler.h"
+#include "chrome/browser/notifications/notification_common.h"
+#include "chrome/browser/notifications/persistent_notification_handler.h"
+#include "extensions/features/features.h"
+
+#if BUILDFLAG(ENABLE_EXTENSIONS)
+#include "chrome/browser/extensions/api/notifications/extension_notification_handler.h"
+#endif
+
+NotificationDisplayService::NotificationDisplayService(Profile* profile)
+ : profile_(profile) {
+ AddNotificationHandler(NotificationCommon::NON_PERSISTENT,
+ base::MakeUnique<NonPersistentNotificationHandler>());
+ AddNotificationHandler(NotificationCommon::PERSISTENT,
+ base::MakeUnique<PersistentNotificationHandler>());
+#if BUILDFLAG(ENABLE_EXTENSIONS)
+ AddNotificationHandler(
+ NotificationCommon::EXTENSION,
+ base::MakeUnique<extensions::ExtensionNotificationHandler>());
+#endif
+}
+
+NotificationDisplayService::~NotificationDisplayService() = default;
+
+void NotificationDisplayService::AddNotificationHandler(
+ NotificationCommon::Type notification_type,
+ std::unique_ptr<NotificationHandler> handler) {
+ DCHECK(handler);
+ DCHECK_EQ(notification_handlers_.count(notification_type), 0u);
+ notification_handlers_[notification_type] = std::move(handler);
+}
+
+NotificationHandler* NotificationDisplayService::GetNotificationHandler(
+ NotificationCommon::Type notification_type) {
+ DCHECK(notification_handlers_.find(notification_type) !=
+ notification_handlers_.end())
+ << notification_type << " is not registered.";
+ return notification_handlers_[notification_type].get();
+}
+
+void NotificationDisplayService::ProcessNotificationOperation(
+ NotificationCommon::Operation operation,
+ NotificationCommon::Type notification_type,
+ const std::string& origin,
+ const std::string& notification_id,
+ int action_index,
+ const base::NullableString16& reply) {
+ NotificationHandler* handler = GetNotificationHandler(notification_type);
+ DCHECK(handler);
+ if (!handler) {
+ LOG(ERROR) << "Unable to find a handler for " << notification_type;
+ return;
+ }
+ switch (operation) {
+ case NotificationCommon::CLICK:
+ handler->OnClick(profile_, origin, notification_id, action_index, reply);
+ break;
+ case NotificationCommon::CLOSE:
+ handler->OnClose(profile_, origin, notification_id, true /* by_user */);
+ break;
+ case NotificationCommon::SETTINGS:
+ handler->OpenSettings(profile_);
+ break;
+ }
+}
« no previous file with comments | « chrome/browser/notifications/notification_display_service.h ('k') | chrome/browser/notifications/notification_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698