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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
11 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
12 #include "base/strings/nullable_string16.h" | 12 #include "base/strings/nullable_string16.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
15 #include "chrome/browser/notifications/message_center_display_service.h" | 15 #include "chrome/browser/notifications/message_center_display_service.h" |
16 #include "chrome/browser/notifications/non_persistent_notification_handler.h" | 16 #include "chrome/browser/notifications/non_persistent_notification_handler.h" |
17 #include "chrome/browser/notifications/notification.h" | 17 #include "chrome/browser/notifications/notification.h" |
18 #include "chrome/browser/notifications/notification_delegate.h" | 18 #include "chrome/browser/notifications/notification_delegate.h" |
19 #include "chrome/browser/notifications/notification_handler.h" | 19 #include "chrome/browser/notifications/notification_handler.h" |
20 #include "chrome/browser/notifications/notification_platform_bridge.h" | 20 #include "chrome/browser/notifications/notification_platform_bridge.h" |
21 #include "chrome/browser/notifications/persistent_notification_handler.h" | 21 #include "chrome/browser/notifications/persistent_notification_handler.h" |
22 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
23 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
| 24 #include "content/public/browser/notification_event_dispatcher.h" |
24 #include "extensions/features/features.h" | 25 #include "extensions/features/features.h" |
25 | 26 |
26 #if BUILDFLAG(ENABLE_EXTENSIONS) | 27 #if BUILDFLAG(ENABLE_EXTENSIONS) |
27 #include "chrome/browser/extensions/api/notifications/extension_notification_han
dler.h" | 28 #include "chrome/browser/extensions/api/notifications/extension_notification_han
dler.h" |
28 #endif | 29 #endif |
29 | 30 |
30 namespace { | 31 namespace { |
31 | 32 |
32 std::string GetProfileId(Profile* profile) { | 33 std::string GetProfileId(Profile* profile) { |
33 #if defined(OS_WIN) | 34 #if defined(OS_WIN) |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 } | 87 } |
87 | 88 |
88 void NativeNotificationDisplayService::Display( | 89 void NativeNotificationDisplayService::Display( |
89 NotificationCommon::Type notification_type, | 90 NotificationCommon::Type notification_type, |
90 const std::string& notification_id, | 91 const std::string& notification_id, |
91 const Notification& notification) { | 92 const Notification& notification) { |
92 if (notification_bridge_ready_) { | 93 if (notification_bridge_ready_) { |
93 notification_bridge_->Display(notification_type, notification_id, | 94 notification_bridge_->Display(notification_type, notification_id, |
94 GetProfileId(profile_), | 95 GetProfileId(profile_), |
95 profile_->IsOffTheRecord(), notification); | 96 profile_->IsOffTheRecord(), notification); |
96 notification.delegate()->Display(); | 97 // Unlike all other notifications non persistent notifications require |
97 NotificationHandler* handler = GetNotificationHandler(notification_type); | 98 // an event after the notification has been displayed. |
98 handler->RegisterNotification(notification_id, notification.delegate()); | 99 // TODO(miguelg) create an OnShow notification handler instead. |
| 100 if (notification_type == NotificationCommon::NON_PERSISTENT) { |
| 101 content::NotificationEventDispatcher::GetInstance() |
| 102 ->DispatchNonPersistentShowEvent(notification_id); |
| 103 } |
99 } else if (message_center_display_service_) { | 104 } else if (message_center_display_service_) { |
100 message_center_display_service_->Display(notification_type, notification_id, | 105 message_center_display_service_->Display(notification_type, notification_id, |
101 notification); | 106 notification); |
102 } else { | 107 } else { |
103 actions_.push(base::BindOnce(&NativeNotificationDisplayService::Display, | 108 actions_.push(base::BindOnce(&NativeNotificationDisplayService::Display, |
104 weak_factory_.GetWeakPtr(), notification_type, | 109 weak_factory_.GetWeakPtr(), notification_type, |
105 notification_id, notification)); | 110 notification_id, notification)); |
106 } | 111 } |
107 } | 112 } |
108 | 113 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 notification_handlers_.erase(notification_type); | 181 notification_handlers_.erase(notification_type); |
177 } | 182 } |
178 | 183 |
179 NotificationHandler* NativeNotificationDisplayService::GetNotificationHandler( | 184 NotificationHandler* NativeNotificationDisplayService::GetNotificationHandler( |
180 NotificationCommon::Type notification_type) { | 185 NotificationCommon::Type notification_type) { |
181 DCHECK(notification_handlers_.find(notification_type) != | 186 DCHECK(notification_handlers_.find(notification_type) != |
182 notification_handlers_.end()) | 187 notification_handlers_.end()) |
183 << notification_type << " is not registered."; | 188 << notification_type << " is not registered."; |
184 return notification_handlers_[notification_type].get(); | 189 return notification_handlers_[notification_type].get(); |
185 } | 190 } |
OLD | NEW |