Chromium Code Reviews| 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 if (notification_type == NotificationCommon::NON_PERSISTENT) { |
|
Peter Beverloo
2017/06/01 17:56:27
This is where OnShow() could be fired. (Or maybe i
Miguel Garcia
2017/06/02 12:37:13
Yeah makes sense, I will add it to the next patch.
| |
| 100 content::NotificationEventDispatcher::GetInstance() | |
| 101 ->DispatchNonPersistentShowEvent(notification_id); | |
| 102 } | |
| 99 } else if (message_center_display_service_) { | 103 } else if (message_center_display_service_) { |
| 100 message_center_display_service_->Display(notification_type, notification_id, | 104 message_center_display_service_->Display(notification_type, notification_id, |
| 101 notification); | 105 notification); |
| 102 } else { | 106 } else { |
| 103 actions_.push(base::BindOnce(&NativeNotificationDisplayService::Display, | 107 actions_.push(base::BindOnce(&NativeNotificationDisplayService::Display, |
| 104 weak_factory_.GetWeakPtr(), notification_type, | 108 weak_factory_.GetWeakPtr(), notification_type, |
| 105 notification_id, notification)); | 109 notification_id, notification)); |
| 106 } | 110 } |
| 107 } | 111 } |
| 108 | 112 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 176 notification_handlers_.erase(notification_type); | 180 notification_handlers_.erase(notification_type); |
| 177 } | 181 } |
| 178 | 182 |
| 179 NotificationHandler* NativeNotificationDisplayService::GetNotificationHandler( | 183 NotificationHandler* NativeNotificationDisplayService::GetNotificationHandler( |
| 180 NotificationCommon::Type notification_type) { | 184 NotificationCommon::Type notification_type) { |
| 181 DCHECK(notification_handlers_.find(notification_type) != | 185 DCHECK(notification_handlers_.find(notification_type) != |
| 182 notification_handlers_.end()) | 186 notification_handlers_.end()) |
| 183 << notification_type << " is not registered."; | 187 << notification_type << " is not registered."; |
| 184 return notification_handlers_[notification_type].get(); | 188 return notification_handlers_[notification_type].get(); |
| 185 } | 189 } |
| OLD | NEW |