Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/notifications/notification_display_service.h" | |
| 6 | |
| 7 #include "base/memory/ptr_util.h" | |
| 8 #include "base/strings/nullable_string16.h" | |
| 9 #include "chrome/browser/notifications/non_persistent_notification_handler.h" | |
| 10 #include "chrome/browser/notifications/notification_common.h" | |
| 11 #include "chrome/browser/notifications/persistent_notification_handler.h" | |
| 12 #include "extensions/features/features.h" | |
| 13 | |
| 14 #if BUILDFLAG(ENABLE_EXTENSIONS) | |
| 15 #include "chrome/browser/extensions/api/notifications/extension_notification_han dler.h" | |
| 16 #endif | |
| 17 | |
| 18 NotificationDisplayService::NotificationDisplayService(Profile* profile) | |
| 19 : profile_(profile) { | |
| 20 AddNotificationHandler(NotificationCommon::NON_PERSISTENT, | |
| 21 base::MakeUnique<NonPersistentNotificationHandler>()); | |
| 22 AddNotificationHandler(NotificationCommon::PERSISTENT, | |
| 23 base::MakeUnique<PersistentNotificationHandler>()); | |
| 24 #if BUILDFLAG(ENABLE_EXTENSIONS) | |
| 25 AddNotificationHandler( | |
| 26 NotificationCommon::EXTENSION, | |
| 27 base::MakeUnique<extensions::ExtensionNotificationHandler>()); | |
| 28 #endif | |
| 29 } | |
| 30 | |
| 31 NotificationDisplayService::~NotificationDisplayService() = default; | |
| 32 | |
| 33 void NotificationDisplayService::AddNotificationHandler( | |
| 34 NotificationCommon::Type notification_type, | |
| 35 std::unique_ptr<NotificationHandler> handler) { | |
| 36 DCHECK(handler); | |
| 37 DCHECK_EQ(notification_handlers_.count(notification_type), 0u); | |
| 38 notification_handlers_[notification_type] = std::move(handler); | |
| 39 } | |
| 40 | |
| 41 NotificationHandler* NotificationDisplayService::GetNotificationHandler( | |
| 42 NotificationCommon::Type notification_type) { | |
| 43 DCHECK(notification_handlers_.find(notification_type) != | |
| 44 notification_handlers_.end()) | |
| 45 << notification_type << " is not registered."; | |
| 46 return notification_handlers_[notification_type].get(); | |
| 47 } | |
| 48 | |
| 49 void NotificationDisplayService::ProcessNotificationOperation( | |
| 50 NotificationCommon::Operation operation, | |
| 51 NotificationCommon::Type notification_type, | |
| 52 const std::string& origin, | |
| 53 const std::string& notification_id, | |
| 54 int action_index, | |
| 55 const base::NullableString16& reply) { | |
| 56 NotificationHandler* handler = GetNotificationHandler(notification_type); | |
| 57 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
| |
| 58 switch (operation) { | |
| 59 case NotificationCommon::CLICK: | |
| 60 handler->OnClick(profile_, origin, notification_id, action_index, reply); | |
| 61 break; | |
| 62 case NotificationCommon::CLOSE: | |
| 63 handler->OnClose(profile_, origin, notification_id, true /* by_user */); | |
| 64 break; | |
| 65 case NotificationCommon::SETTINGS: | |
| 66 handler->OpenSettings(profile_); | |
| 67 break; | |
| 68 } | |
| 69 } | |
| OLD | NEW |