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

Side by Side Diff: content/browser/notifications/notification_message_filter.cc

Issue 2888303004: Minimize the delegate dependencies for non persistent notifications. (Closed)
Patch Set: review 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "content/browser/notifications/notification_message_filter.h" 5 #include "content/browser/notifications/notification_message_filter.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/feature_list.h" 11 #include "base/feature_list.h"
12 #include "content/browser/bad_message.h" 12 #include "content/browser/bad_message.h"
13 #include "content/browser/notifications/notification_event_dispatcher_impl.h"
13 #include "content/browser/notifications/notification_id_generator.h" 14 #include "content/browser/notifications/notification_id_generator.h"
14 #include "content/browser/notifications/page_notification_delegate.h" 15 #include "content/browser/notifications/page_notification_delegate.h"
15 #include "content/browser/notifications/platform_notification_context_impl.h" 16 #include "content/browser/notifications/platform_notification_context_impl.h"
16 #include "content/browser/service_worker/service_worker_context_wrapper.h" 17 #include "content/browser/service_worker/service_worker_context_wrapper.h"
17 #include "content/common/platform_notification_messages.h" 18 #include "content/common/platform_notification_messages.h"
18 #include "content/public/browser/browser_context.h" 19 #include "content/public/browser/browser_context.h"
19 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
20 #include "content/public/browser/content_browser_client.h" 21 #include "content/public/browser/content_browser_client.h"
21 #include "content/public/browser/desktop_notification_delegate.h" 22 #include "content/public/browser/desktop_notification_delegate.h"
22 #include "content/public/browser/notification_database_data.h" 23 #include "content/public/browser/notification_database_data.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 } // namespace 84 } // namespace
84 85
85 NotificationMessageFilter::NotificationMessageFilter( 86 NotificationMessageFilter::NotificationMessageFilter(
86 int process_id, 87 int process_id,
87 PlatformNotificationContextImpl* notification_context, 88 PlatformNotificationContextImpl* notification_context,
88 ResourceContext* resource_context, 89 ResourceContext* resource_context,
89 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context, 90 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context,
90 BrowserContext* browser_context) 91 BrowserContext* browser_context)
91 : BrowserMessageFilter(PlatformNotificationMsgStart), 92 : BrowserMessageFilter(PlatformNotificationMsgStart),
92 process_id_(process_id), 93 process_id_(process_id),
94 non_persistent__notification_shown_(false),
93 notification_context_(notification_context), 95 notification_context_(notification_context),
94 resource_context_(resource_context), 96 resource_context_(resource_context),
95 service_worker_context_(service_worker_context), 97 service_worker_context_(service_worker_context),
96 browser_context_(browser_context), 98 browser_context_(browser_context),
97 weak_factory_io_(this) {} 99 weak_factory_io_(this) {}
98 100
99 NotificationMessageFilter::~NotificationMessageFilter() {} 101 NotificationMessageFilter::~NotificationMessageFilter() = default;
100 102
101 void NotificationMessageFilter::DidCloseNotification( 103 void NotificationMessageFilter::DidCloseNotification(
102 const std::string& notification_id) { 104 const std::string& notification_id) {
103 DCHECK_CURRENTLY_ON(BrowserThread::UI); 105 DCHECK_CURRENTLY_ON(BrowserThread::UI);
104 close_closures_.erase(notification_id); 106 close_closures_.erase(notification_id);
105 } 107 }
106 108
107 void NotificationMessageFilter::OnDestruct() const { 109 void NotificationMessageFilter::OnDestruct() const {
110 if (non_persistent__notification_shown_) {
111 NotificationEventDispatcherImpl* event_dispatcher =
112 content::NotificationEventDispatcherImpl::GetInstance();
113 DCHECK(event_dispatcher);
114 event_dispatcher->RendererGone(process_id_);
115 }
108 BrowserThread::DeleteOnIOThread::Destruct(this); 116 BrowserThread::DeleteOnIOThread::Destruct(this);
109 } 117 }
110 118
111 bool NotificationMessageFilter::OnMessageReceived(const IPC::Message& message) { 119 bool NotificationMessageFilter::OnMessageReceived(const IPC::Message& message) {
112 bool handled = true; 120 bool handled = true;
113 IPC_BEGIN_MESSAGE_MAP(NotificationMessageFilter, message) 121 IPC_BEGIN_MESSAGE_MAP(NotificationMessageFilter, message)
114 IPC_MESSAGE_HANDLER(PlatformNotificationHostMsg_Show, 122 IPC_MESSAGE_HANDLER(PlatformNotificationHostMsg_Show,
115 OnShowPlatformNotification) 123 OnShowPlatformNotification)
116 IPC_MESSAGE_HANDLER(PlatformNotificationHostMsg_ShowPersistent, 124 IPC_MESSAGE_HANDLER(PlatformNotificationHostMsg_ShowPersistent,
117 OnShowPersistentNotification) 125 OnShowPersistentNotification)
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 DCHECK(service); 162 DCHECK(service);
155 163
156 if (!VerifyNotificationPermissionGranted(service, origin)) 164 if (!VerifyNotificationPermissionGranted(service, origin))
157 return; 165 return;
158 166
159 std::string notification_id = 167 std::string notification_id =
160 GetNotificationIdGenerator()->GenerateForNonPersistentNotification( 168 GetNotificationIdGenerator()->GenerateForNonPersistentNotification(
161 origin, notification_data.tag, non_persistent_notification_id, 169 origin, notification_data.tag, non_persistent_notification_id,
162 process_id_); 170 process_id_);
163 171
172 NotificationEventDispatcherImpl* event_dispatcher =
173 content::NotificationEventDispatcherImpl::GetInstance();
174 non_persistent__notification_shown_ = true;
175 event_dispatcher->RegisterNonPersistentNotification(
176 notification_id, process_id_, non_persistent_notification_id);
177
164 std::unique_ptr<DesktopNotificationDelegate> delegate( 178 std::unique_ptr<DesktopNotificationDelegate> delegate(
165 new PageNotificationDelegate(process_id_, non_persistent_notification_id, 179 new PageNotificationDelegate(process_id_, non_persistent_notification_id,
166 notification_id)); 180 notification_id));
167 181
168 base::Closure close_closure; 182 base::Closure close_closure;
169 service->DisplayNotification(browser_context_, notification_id, origin, 183 service->DisplayNotification(browser_context_, notification_id, origin,
170 SanitizeNotificationData(notification_data), 184 SanitizeNotificationData(notification_data),
171 notification_resources, std::move(delegate), 185 notification_resources, std::move(delegate),
172 &close_closure); 186 &close_closure);
173 187
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 bad_message::ReceivedBadMessage(this, bad_message::NMF_NO_PERMISSION_VERIFY); 404 bad_message::ReceivedBadMessage(this, bad_message::NMF_NO_PERMISSION_VERIFY);
391 return false; 405 return false;
392 } 406 }
393 407
394 NotificationIdGenerator* NotificationMessageFilter::GetNotificationIdGenerator() 408 NotificationIdGenerator* NotificationMessageFilter::GetNotificationIdGenerator()
395 const { 409 const {
396 return notification_context_->notification_id_generator(); 410 return notification_context_->notification_id_generator();
397 } 411 }
398 412
399 } // namespace content 413 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/notifications/notification_message_filter.h ('k') | content/public/browser/notification_event_dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698