Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(285)

Side by Side Diff: chrome/browser/notifications/native_notification_display_service.cc

Issue 2916383004: Revert of Minimize the delegate dependencies for non persistent notifications. (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
25 #include "extensions/features/features.h" 24 #include "extensions/features/features.h"
26 25
27 #if BUILDFLAG(ENABLE_EXTENSIONS) 26 #if BUILDFLAG(ENABLE_EXTENSIONS)
28 #include "chrome/browser/extensions/api/notifications/extension_notification_han dler.h" 27 #include "chrome/browser/extensions/api/notifications/extension_notification_han dler.h"
29 #endif 28 #endif
30 29
31 namespace { 30 namespace {
32 31
33 std::string GetProfileId(Profile* profile) { 32 std::string GetProfileId(Profile* profile) {
34 #if defined(OS_WIN) 33 #if defined(OS_WIN)
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 } 86 }
88 87
89 void NativeNotificationDisplayService::Display( 88 void NativeNotificationDisplayService::Display(
90 NotificationCommon::Type notification_type, 89 NotificationCommon::Type notification_type,
91 const std::string& notification_id, 90 const std::string& notification_id,
92 const Notification& notification) { 91 const Notification& notification) {
93 if (notification_bridge_ready_) { 92 if (notification_bridge_ready_) {
94 notification_bridge_->Display(notification_type, notification_id, 93 notification_bridge_->Display(notification_type, notification_id,
95 GetProfileId(profile_), 94 GetProfileId(profile_),
96 profile_->IsOffTheRecord(), notification); 95 profile_->IsOffTheRecord(), notification);
97 // Unlike all other notifications non persistent notifications require 96 notification.delegate()->Display();
98 // an event after the notification has been displayed. 97 NotificationHandler* handler = GetNotificationHandler(notification_type);
99 // TODO(miguelg) create an OnShow notification handler instead. 98 handler->RegisterNotification(notification_id, notification.delegate());
100 if (notification_type == NotificationCommon::NON_PERSISTENT) {
101 content::NotificationEventDispatcher::GetInstance()
102 ->DispatchNonPersistentShowEvent(notification_id);
103 }
104 } else if (message_center_display_service_) { 99 } else if (message_center_display_service_) {
105 message_center_display_service_->Display(notification_type, notification_id, 100 message_center_display_service_->Display(notification_type, notification_id,
106 notification); 101 notification);
107 } else { 102 } else {
108 actions_.push(base::BindOnce(&NativeNotificationDisplayService::Display, 103 actions_.push(base::BindOnce(&NativeNotificationDisplayService::Display,
109 weak_factory_.GetWeakPtr(), notification_type, 104 weak_factory_.GetWeakPtr(), notification_type,
110 notification_id, notification)); 105 notification_id, notification));
111 } 106 }
112 } 107 }
113 108
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 notification_handlers_.erase(notification_type); 176 notification_handlers_.erase(notification_type);
182 } 177 }
183 178
184 NotificationHandler* NativeNotificationDisplayService::GetNotificationHandler( 179 NotificationHandler* NativeNotificationDisplayService::GetNotificationHandler(
185 NotificationCommon::Type notification_type) { 180 NotificationCommon::Type notification_type) {
186 DCHECK(notification_handlers_.find(notification_type) != 181 DCHECK(notification_handlers_.find(notification_type) !=
187 notification_handlers_.end()) 182 notification_handlers_.end())
188 << notification_type << " is not registered."; 183 << notification_type << " is not registered.";
189 return notification_handlers_[notification_type].get(); 184 return notification_handlers_[notification_type].get();
190 } 185 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698