| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/notifications/native_notification_display_service.h" | 5 #include "chrome/browser/notifications/native_notification_display_service.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/strings/nullable_string16.h" | 8 #include "base/strings/nullable_string16.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/notifications/non_persistent_notification_handler.h" | 10 #include "chrome/browser/notifications/non_persistent_notification_handler.h" |
| 11 #include "chrome/browser/notifications/notification.h" | 11 #include "chrome/browser/notifications/notification.h" |
| 12 #include "chrome/browser/notifications/notification_delegate.h" | 12 #include "chrome/browser/notifications/notification_delegate.h" |
| 13 #include "chrome/browser/notifications/notification_handler.h" | 13 #include "chrome/browser/notifications/notification_handler.h" |
| 14 #include "chrome/browser/notifications/notification_platform_bridge.h" | 14 #include "chrome/browser/notifications/notification_platform_bridge.h" |
| 15 #include "chrome/browser/notifications/persistent_notification_handler.h" | 15 #include "chrome/browser/notifications/persistent_notification_handler.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 18 #include "extensions/features/features.h" |
| 19 |
| 20 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 21 #include "chrome/browser/extensions/api/notifications/extension_notification_han
dler.h" |
| 22 #endif |
| 18 | 23 |
| 19 namespace { | 24 namespace { |
| 20 | 25 |
| 21 std::string GetProfileId(Profile* profile) { | 26 std::string GetProfileId(Profile* profile) { |
| 22 #if defined(OS_WIN) | 27 #if defined(OS_WIN) |
| 23 std::string profile_id = | 28 std::string profile_id = |
| 24 base::WideToUTF8(profile->GetPath().BaseName().value()); | 29 base::WideToUTF8(profile->GetPath().BaseName().value()); |
| 25 #elif defined(OS_POSIX) | 30 #elif defined(OS_POSIX) |
| 26 std::string profile_id = profile->GetPath().BaseName().value(); | 31 std::string profile_id = profile->GetPath().BaseName().value(); |
| 27 #endif | 32 #endif |
| 28 return profile_id; | 33 return profile_id; |
| 29 } | 34 } |
| 30 | 35 |
| 31 } // namespace | 36 } // namespace |
| 32 | 37 |
| 33 NativeNotificationDisplayService::NativeNotificationDisplayService( | 38 NativeNotificationDisplayService::NativeNotificationDisplayService( |
| 34 Profile* profile, | 39 Profile* profile, |
| 35 NotificationPlatformBridge* notification_bridge) | 40 NotificationPlatformBridge* notification_bridge) |
| 36 : profile_(profile), notification_bridge_(notification_bridge) { | 41 : profile_(profile), notification_bridge_(notification_bridge) { |
| 37 DCHECK(profile_); | 42 DCHECK(profile_); |
| 38 DCHECK(notification_bridge_); | 43 DCHECK(notification_bridge_); |
| 39 | 44 |
| 40 AddNotificationHandler(NotificationCommon::NON_PERSISTENT, | 45 AddNotificationHandler(NotificationCommon::NON_PERSISTENT, |
| 41 base::MakeUnique<NonPersistentNotificationHandler>()); | 46 base::MakeUnique<NonPersistentNotificationHandler>()); |
| 42 AddNotificationHandler(NotificationCommon::PERSISTENT, | 47 AddNotificationHandler(NotificationCommon::PERSISTENT, |
| 43 base::MakeUnique<PersistentNotificationHandler>()); | 48 base::MakeUnique<PersistentNotificationHandler>()); |
| 49 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 50 AddNotificationHandler(NotificationCommon::EXTENSION, |
| 51 base::MakeUnique<ExtensionNotificationHandler>()); |
| 52 #endif |
| 44 } | 53 } |
| 45 | 54 |
| 46 NativeNotificationDisplayService::~NativeNotificationDisplayService() {} | 55 NativeNotificationDisplayService::~NativeNotificationDisplayService() {} |
| 47 | 56 |
| 48 void NativeNotificationDisplayService::Display( | 57 void NativeNotificationDisplayService::Display( |
| 49 NotificationCommon::Type notification_type, | 58 NotificationCommon::Type notification_type, |
| 50 const std::string& notification_id, | 59 const std::string& notification_id, |
| 51 const Notification& notification) { | 60 const Notification& notification) { |
| 52 notification_bridge_->Display(notification_type, notification_id, | 61 notification_bridge_->Display(notification_type, notification_id, |
| 53 GetProfileId(profile_), | 62 GetProfileId(profile_), |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 notification_handlers_.erase(notification_type); | 120 notification_handlers_.erase(notification_type); |
| 112 } | 121 } |
| 113 | 122 |
| 114 NotificationHandler* NativeNotificationDisplayService::GetNotificationHandler( | 123 NotificationHandler* NativeNotificationDisplayService::GetNotificationHandler( |
| 115 NotificationCommon::Type notification_type) { | 124 NotificationCommon::Type notification_type) { |
| 116 DCHECK(notification_handlers_.find(notification_type) != | 125 DCHECK(notification_handlers_.find(notification_type) != |
| 117 notification_handlers_.end()) | 126 notification_handlers_.end()) |
| 118 << notification_type << " is not registered."; | 127 << notification_type << " is not registered."; |
| 119 return notification_handlers_[notification_type].get(); | 128 return notification_handlers_[notification_type].get(); |
| 120 } | 129 } |
| OLD | NEW |