Chromium Code Reviews| 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..a14b3d7bc3f298cf3b540fbe916284546b1a8e9e |
| --- /dev/null |
| +++ b/chrome/browser/notifications/notification_display_service.cc |
| @@ -0,0 +1,69 @@ |
| +// 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); |
| + CHECK(handler); |
|
Peter Beverloo
2017/06/01 11:32:45
Random thought: should we crash the browser if we
Miguel Garcia
2017/06/02 15:02:55
Ok moved it to a DCHECK with nice LOG(ERROR) + re
|
| + 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; |
| + } |
| +} |