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

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

Issue 1619703002: Implement notificationclose event (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed test expectations and compile error Created 4 years, 10 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_event_dispatcher_impl.h" 5 #include "content/browser/notifications/notification_event_dispatcher_impl.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 #include "content/browser/notifications/platform_notification_context_impl.h" 9 #include "content/browser/notifications/platform_notification_context_impl.h"
10 #include "content/browser/service_worker/service_worker_context_wrapper.h" 10 #include "content/browser/service_worker/service_worker_context_wrapper.h"
11 #include "content/browser/service_worker/service_worker_registration.h" 11 #include "content/browser/service_worker/service_worker_registration.h"
12 #include "content/browser/service_worker/service_worker_storage.h" 12 #include "content/browser/service_worker/service_worker_storage.h"
13 #include "content/common/service_worker/service_worker_messages.h" 13 #include "content/common/service_worker/service_worker_messages.h"
14 #include "content/public/browser/browser_context.h" 14 #include "content/public/browser/browser_context.h"
15 #include "content/public/browser/browser_thread.h" 15 #include "content/public/browser/browser_thread.h"
16 #include "content/public/browser/notification_database_data.h"
17 #include "content/public/browser/storage_partition.h" 16 #include "content/public/browser/storage_partition.h"
18 #include "content/public/common/platform_notification_data.h" 17 #include "content/public/common/platform_notification_data.h"
19 18
20 namespace content { 19 namespace content {
21 namespace { 20 namespace {
22 21
23 using NotificationClickDispatchCompleteCallback = 22 using NotificationDispatchCompleteCallback =
24 NotificationEventDispatcher::NotificationClickDispatchCompleteCallback; 23 NotificationEventDispatcher::NotificationDispatchCompleteCallback;
24 using NotificationOperationCallback =
25 base::Callback<void(const ServiceWorkerRegistration*,
26 const NotificationDatabaseData&)>;
27 using NotificationOperationCallbackWithContext =
28 base::Callback<void(scoped_refptr<PlatformNotificationContext>,
29 const ServiceWorkerRegistration*,
30 const NotificationDatabaseData&)>;
25 31
26 // To be called when the notificationclick event has finished executing. Will 32 // To be called when a notification event has finished executing. Will post a
27 // post a task to call |dispatch_complete_callback| on the UI thread. 33 // task to call |dispatch_complete_callback| on the UI thread.
28 void NotificationClickEventFinished( 34 void NotificationEventFinished(
29 const NotificationClickDispatchCompleteCallback& dispatch_complete_callback, 35 const NotificationDispatchCompleteCallback& dispatch_complete_callback,
30 const scoped_refptr<ServiceWorkerRegistration>& service_worker_registration, 36 PersistentNotificationStatus status) {
31 ServiceWorkerStatusCode service_worker_status) {
32 DCHECK_CURRENTLY_ON(BrowserThread::IO); 37 DCHECK_CURRENTLY_ON(BrowserThread::IO);
33 38
39 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
40 base::Bind(dispatch_complete_callback, status));
41 }
42
43 // To be called when a notification event has finished with a
44 // ServiceWorkerStatusCode result. Will call NotificationEventFinished with a
45 // PersistentNotificationStatus derived from the service worker status.
46 void ServiceWorkerNotificationEventFinished(
47 const NotificationDispatchCompleteCallback& dispatch_complete_callback,
48 ServiceWorkerStatusCode service_worker_status) {
34 #if defined(OS_ANDROID) 49 #if defined(OS_ANDROID)
35 // This LOG(INFO) deliberately exists to help track down the cause of 50 // This LOG(INFO) deliberately exists to help track down the cause of
36 // https://crbug.com/534537, where notifications sometimes do not react to 51 // https://crbug.com/534537, where notifications sometimes do not react to
37 // the user clicking on them. It should be removed once that's fixed. 52 // the user clicking on them. It should be removed once that's fixed.
38 LOG(INFO) << "The notificationclick event has finished: " 53 LOG(INFO) << "The notification event has finished: " << service_worker_status;
39 << service_worker_status;
40 #endif 54 #endif
41 55
42 PersistentNotificationStatus status = PERSISTENT_NOTIFICATION_STATUS_SUCCESS; 56 PersistentNotificationStatus status = PERSISTENT_NOTIFICATION_STATUS_SUCCESS;
43 switch (service_worker_status) { 57 switch (service_worker_status) {
44 case SERVICE_WORKER_OK: 58 case SERVICE_WORKER_OK:
45 // Success status was initialized above. 59 // Success status was initialized above.
46 break; 60 break;
47 case SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED: 61 case SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED:
48 status = PERSISTENT_NOTIFICATION_STATUS_EVENT_WAITUNTIL_REJECTED; 62 status = PERSISTENT_NOTIFICATION_STATUS_EVENT_WAITUNTIL_REJECTED;
49 break; 63 break;
(...skipping 12 matching lines...) Expand all
62 case SERVICE_WORKER_ERROR_TIMEOUT: 76 case SERVICE_WORKER_ERROR_TIMEOUT:
63 case SERVICE_WORKER_ERROR_SCRIPT_EVALUATE_FAILED: 77 case SERVICE_WORKER_ERROR_SCRIPT_EVALUATE_FAILED:
64 case SERVICE_WORKER_ERROR_DISK_CACHE: 78 case SERVICE_WORKER_ERROR_DISK_CACHE:
65 case SERVICE_WORKER_ERROR_REDUNDANT: 79 case SERVICE_WORKER_ERROR_REDUNDANT:
66 case SERVICE_WORKER_ERROR_DISALLOWED: 80 case SERVICE_WORKER_ERROR_DISALLOWED:
67 case SERVICE_WORKER_ERROR_DISABLED_WORKER: 81 case SERVICE_WORKER_ERROR_DISABLED_WORKER:
68 case SERVICE_WORKER_ERROR_MAX_VALUE: 82 case SERVICE_WORKER_ERROR_MAX_VALUE:
69 status = PERSISTENT_NOTIFICATION_STATUS_SERVICE_WORKER_ERROR; 83 status = PERSISTENT_NOTIFICATION_STATUS_SERVICE_WORKER_ERROR;
70 break; 84 break;
71 } 85 }
72 86 NotificationEventFinished(dispatch_complete_callback, status);
73 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
74 base::Bind(dispatch_complete_callback, status));
75 } 87 }
76 88
77 // Dispatches the notificationclick event on |service_worker|. Most be called on 89 // Dispatches the given notification action event on
78 // the IO thread, and with the worker running. 90 // |service_worker_registration| if the registration was available. Must be
79 void DispatchNotificationClickEventOnWorker( 91 // called on the IO thread.
80 const scoped_refptr<ServiceWorkerVersion>& service_worker, 92 void DispatchNotificationEventOnRegistration(
81 const NotificationDatabaseData& notification_database_data, 93 const NotificationDatabaseData& notification_database_data,
82 int action_index, 94 const scoped_refptr<PlatformNotificationContext> notification_context,
Peter Beverloo 2016/02/03 00:00:21 const& (elsewhere too)
Nina 2016/02/03 12:15:13 Made scoped_refptrs const and passed by ref.
83 const ServiceWorkerVersion::StatusCallback& callback) { 95 const NotificationOperationCallback& dispatch_event_action,
84 DCHECK_CURRENTLY_ON(BrowserThread::IO); 96 const NotificationDispatchCompleteCallback& dispatch_error_callback,
85 int request_id = service_worker->StartRequest(
86 ServiceWorkerMetrics::EventType::NOTIFICATION_CLICK, callback);
87 service_worker->DispatchSimpleEvent<
88 ServiceWorkerHostMsg_NotificationClickEventFinished>(
89 request_id,
90 ServiceWorkerMsg_NotificationClickEvent(
91 request_id, notification_database_data.notification_id,
92 notification_database_data.notification_data, action_index));
93 }
94
95 // Dispatches the notificationclick on |service_worker_registration| if the
96 // registration was available. Must be called on the IO thread.
97 void DispatchNotificationClickEventOnRegistration(
98 const NotificationDatabaseData& notification_database_data,
99 int action_index,
100 const NotificationClickDispatchCompleteCallback& dispatch_complete_callback,
101 ServiceWorkerStatusCode service_worker_status, 97 ServiceWorkerStatusCode service_worker_status,
102 const scoped_refptr<ServiceWorkerRegistration>& 98 const scoped_refptr<ServiceWorkerRegistration>&
103 service_worker_registration) { 99 service_worker_registration) {
104 DCHECK_CURRENTLY_ON(BrowserThread::IO); 100 DCHECK_CURRENTLY_ON(BrowserThread::IO);
105 #if defined(OS_ANDROID) 101 #if defined(OS_ANDROID)
106 // This LOG(INFO) deliberately exists to help track down the cause of 102 // This LOG(INFO) deliberately exists to help track down the cause of
107 // https://crbug.com/534537, where notifications sometimes do not react to 103 // https://crbug.com/534537, where notifications sometimes do not react to
108 // the user clicking on them. It should be removed once that's fixed. 104 // the user clicking on them. It should be removed once that's fixed.
109 LOG(INFO) << "Trying to dispatch notification for SW with status: " 105 LOG(INFO) << "Trying to dispatch notification for SW with status: "
110 << service_worker_status << " action_index: " << action_index; 106 << service_worker_status;
111 #endif 107 #endif
112 if (service_worker_status == SERVICE_WORKER_OK) { 108 if (service_worker_status == SERVICE_WORKER_OK) {
113 ServiceWorkerVersion::StatusCallback dispatch_event_callback = 109 DCHECK(service_worker_registration->active_version());
114 base::Bind(&NotificationClickEventFinished, dispatch_complete_callback,
115 service_worker_registration);
116 110
117 DCHECK(service_worker_registration->active_version()); 111 dispatch_event_action.Run(service_worker_registration.get(),
118 service_worker_registration->active_version()->RunAfterStartWorker( 112 notification_database_data);
119 base::Bind(
120 &DispatchNotificationClickEventOnWorker,
121 make_scoped_refptr(service_worker_registration->active_version()),
122 notification_database_data, action_index, dispatch_event_callback),
123 dispatch_event_callback);
124 return; 113 return;
125 } 114 }
126 115
127 PersistentNotificationStatus status = PERSISTENT_NOTIFICATION_STATUS_SUCCESS; 116 PersistentNotificationStatus status = PERSISTENT_NOTIFICATION_STATUS_SUCCESS;
128 switch (service_worker_status) { 117 switch (service_worker_status) {
129 case SERVICE_WORKER_ERROR_NOT_FOUND: 118 case SERVICE_WORKER_ERROR_NOT_FOUND:
130 status = PERSISTENT_NOTIFICATION_STATUS_NO_SERVICE_WORKER; 119 status = PERSISTENT_NOTIFICATION_STATUS_NO_SERVICE_WORKER;
131 break; 120 break;
132 case SERVICE_WORKER_ERROR_FAILED: 121 case SERVICE_WORKER_ERROR_FAILED:
133 case SERVICE_WORKER_ERROR_ABORT: 122 case SERVICE_WORKER_ERROR_ABORT:
(...skipping 15 matching lines...) Expand all
149 case SERVICE_WORKER_ERROR_DISABLED_WORKER: 138 case SERVICE_WORKER_ERROR_DISABLED_WORKER:
150 case SERVICE_WORKER_ERROR_MAX_VALUE: 139 case SERVICE_WORKER_ERROR_MAX_VALUE:
151 status = PERSISTENT_NOTIFICATION_STATUS_SERVICE_WORKER_ERROR; 140 status = PERSISTENT_NOTIFICATION_STATUS_SERVICE_WORKER_ERROR;
152 break; 141 break;
153 case SERVICE_WORKER_OK: 142 case SERVICE_WORKER_OK:
154 NOTREACHED(); 143 NOTREACHED();
155 break; 144 break;
156 } 145 }
157 146
158 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 147 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
159 base::Bind(dispatch_complete_callback, status)); 148 base::Bind(dispatch_error_callback, status));
160 } 149 }
161 150
162 // Finds the ServiceWorkerRegistration associated with the |origin| and 151 // Finds the ServiceWorkerRegistration associated with the |origin| and
163 // |service_worker_registration_id|. Must be called on the IO thread. 152 // |service_worker_registration_id|. Must be called on the IO thread.
164 void FindServiceWorkerRegistration( 153 void FindServiceWorkerRegistration(
165 const GURL& origin, 154 const GURL& origin,
166 int action_index,
167 const NotificationClickDispatchCompleteCallback& dispatch_complete_callback,
168 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context, 155 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context,
156 scoped_refptr<PlatformNotificationContext> notification_context,
157 const NotificationOperationCallback& notification_action_callback,
158 const NotificationDispatchCompleteCallback& dispatch_error_callback,
169 bool success, 159 bool success,
170 const NotificationDatabaseData& notification_database_data) { 160 const NotificationDatabaseData& notification_database_data) {
171 DCHECK_CURRENTLY_ON(BrowserThread::IO); 161 DCHECK_CURRENTLY_ON(BrowserThread::IO);
172 162
173 #if defined(OS_ANDROID) 163 #if defined(OS_ANDROID)
174 // This LOG(INFO) deliberately exists to help track down the cause of 164 // This LOG(INFO) deliberately exists to help track down the cause of
175 // https://crbug.com/534537, where notifications sometimes do not react to 165 // https://crbug.com/534537, where notifications sometimes do not react to
176 // the user clicking on them. It should be removed once that's fixed. 166 // the user clicking on them. It should be removed once that's fixed.
177 LOG(INFO) << "Lookup for ServiceWoker Registration: success:" << success 167 LOG(INFO) << "Lookup for ServiceWoker Registration: success: " << success;
178 << " action_index: " << action_index;
179 #endif 168 #endif
180 if (!success) { 169 if (!success) {
181 BrowserThread::PostTask( 170 BrowserThread::PostTask(
182 BrowserThread::UI, FROM_HERE, 171 BrowserThread::UI, FROM_HERE,
183 base::Bind(dispatch_complete_callback, 172 base::Bind(dispatch_error_callback,
184 PERSISTENT_NOTIFICATION_STATUS_DATABASE_ERROR)); 173 PERSISTENT_NOTIFICATION_STATUS_DATABASE_ERROR));
185 return; 174 return;
186 } 175 }
187 176
188 service_worker_context->FindReadyRegistrationForId( 177 service_worker_context->FindReadyRegistrationForId(
189 notification_database_data.service_worker_registration_id, origin, 178 notification_database_data.service_worker_registration_id, origin,
190 base::Bind(&DispatchNotificationClickEventOnRegistration, 179 base::Bind(&DispatchNotificationEventOnRegistration,
191 notification_database_data, action_index, 180 notification_database_data, notification_context,
192 dispatch_complete_callback)); 181 notification_action_callback, dispatch_error_callback));
193 } 182 }
194 183
195 // Reads the data associated with the |persistent_notification_id| belonging to 184 // Reads the data associated with the |persistent_notification_id| belonging to
196 // |origin| from the notification context. 185 // |origin| from the notification context.
197 void ReadNotificationDatabaseData( 186 void ReadNotificationDatabaseData(
198 int64_t persistent_notification_id, 187 int64_t persistent_notification_id,
199 const GURL& origin, 188 const GURL& origin,
200 int action_index,
201 const NotificationClickDispatchCompleteCallback& dispatch_complete_callback,
202 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context, 189 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context,
203 scoped_refptr<PlatformNotificationContextImpl> notification_context) { 190 scoped_refptr<PlatformNotificationContext> notification_context,
191 const NotificationOperationCallback& notification_read_callback,
192 const NotificationDispatchCompleteCallback& dispatch_error_callback) {
204 DCHECK_CURRENTLY_ON(BrowserThread::IO); 193 DCHECK_CURRENTLY_ON(BrowserThread::IO);
205 notification_context->ReadNotificationData( 194 notification_context->ReadNotificationData(
206 persistent_notification_id, origin, 195 persistent_notification_id, origin,
207 base::Bind(&FindServiceWorkerRegistration, origin, action_index, 196 base::Bind(&FindServiceWorkerRegistration, origin, service_worker_context,
208 dispatch_complete_callback, service_worker_context)); 197 notification_context, notification_read_callback,
198 dispatch_error_callback));
209 } 199 }
210 200
211 } // namespace 201 // -----------------------------------------------------------------------------
212 202
213 // static 203 // Dispatches the notificationclick event on |service_worker|. Must be called on
214 NotificationEventDispatcher* NotificationEventDispatcher::GetInstance() { 204 // the IO thread, and with the worker running.
215 return NotificationEventDispatcherImpl::GetInstance(); 205 void DispatchNotificationClickEventOnWorker(
206 const scoped_refptr<ServiceWorkerVersion>& service_worker,
207 const NotificationDatabaseData& notification_database_data,
208 int action_index,
209 const ServiceWorkerVersion::StatusCallback& callback) {
210 DCHECK_CURRENTLY_ON(BrowserThread::IO);
211 int request_id = service_worker->StartRequest(
212 ServiceWorkerMetrics::EventType::NOTIFICATION_CLICK, callback);
213 service_worker->DispatchSimpleEvent<
214 ServiceWorkerHostMsg_NotificationClickEventFinished>(
215 request_id,
216 ServiceWorkerMsg_NotificationClickEvent(
217 request_id, notification_database_data.notification_id,
218 notification_database_data.notification_data, action_index));
216 } 219 }
217 220
218 NotificationEventDispatcherImpl* 221 // Dispatches the notification click event on the |service_worker_registration|.
219 NotificationEventDispatcherImpl::GetInstance() { 222 void DoDispatchNotificationClickEvent(
220 DCHECK_CURRENTLY_ON(BrowserThread::UI); 223 int action_index,
221 return base::Singleton<NotificationEventDispatcherImpl>::get(); 224 const NotificationDispatchCompleteCallback& dispatch_complete_callback,
225 const scoped_refptr<PlatformNotificationContext> notification_context,
226 const ServiceWorkerRegistration* service_worker_registration,
227 const NotificationDatabaseData& notification_database_data) {
228 ServiceWorkerVersion::StatusCallback status_callback = base::Bind(
229 &ServiceWorkerNotificationEventFinished, dispatch_complete_callback);
230 service_worker_registration->active_version()->RunAfterStartWorker(
231 base::Bind(
232 &DispatchNotificationClickEventOnWorker,
233 make_scoped_refptr(service_worker_registration->active_version()),
234 notification_database_data, action_index, status_callback),
235 status_callback);
222 } 236 }
223 237
224 NotificationEventDispatcherImpl::NotificationEventDispatcherImpl() {} 238 // -----------------------------------------------------------------------------
225 239
226 NotificationEventDispatcherImpl::~NotificationEventDispatcherImpl() {} 240 // Called when the notification data has been deleted to finish the notification
241 // close event.
242 void OnPersistentNotificationDataDeleted(
243 ServiceWorkerStatusCode service_worker_status,
244 const NotificationDispatchCompleteCallback& dispatch_complete_callback,
245 bool success) {
246 if (service_worker_status != SERVICE_WORKER_OK) {
247 ServiceWorkerNotificationEventFinished(dispatch_complete_callback,
248 service_worker_status);
249 return;
250 }
251 NotificationEventFinished(
252 dispatch_complete_callback,
253 success ? PERSISTENT_NOTIFICATION_STATUS_SUCCESS
254 : PERSISTENT_NOTIFICATION_STATUS_DATABASE_ERROR);
255 }
227 256
228 void NotificationEventDispatcherImpl::DispatchNotificationClickEvent( 257 // Called when the persistent notification close event has been handled
258 // to remove the notification from the database.
259 void DeleteNotificationDataFromDatabase(
260 const int64_t notification_id,
261 const GURL& origin,
262 scoped_refptr<PlatformNotificationContext> notification_context,
263 const NotificationDispatchCompleteCallback& dispatch_complete_callback,
264 ServiceWorkerStatusCode status_code) {
265 notification_context->DeleteNotificationData(
266 notification_id, origin,
267 base::Bind(&OnPersistentNotificationDataDeleted, status_code,
268 dispatch_complete_callback));
269 }
270
271 // Dispatches the notificationclose event on |service_worker|. Must be called on
272 // the IO thread, and with the worker running.
273 void DispatchNotificationCloseEventOnWorker(
274 const scoped_refptr<ServiceWorkerVersion>& service_worker,
275 const NotificationDatabaseData& notification_database_data,
276 const ServiceWorkerVersion::StatusCallback& callback) {
277 DCHECK_CURRENTLY_ON(BrowserThread::IO);
278 int request_id = service_worker->StartRequest(
279 ServiceWorkerMetrics::EventType::NOTIFICATION_CLOSE, callback);
280 service_worker->DispatchSimpleEvent<
281 ServiceWorkerHostMsg_NotificationCloseEventFinished>(
282 request_id, ServiceWorkerMsg_NotificationCloseEvent(
283 request_id, notification_database_data.notification_id,
284 notification_database_data.notification_data));
285 }
286
287 // Actually dispatches the notification close event on the service worker
288 // registration.
289 void DoDispatchNotificationCloseEvent(
290 bool by_user,
291 const NotificationDispatchCompleteCallback& dispatch_complete_callback,
292 scoped_refptr<PlatformNotificationContext> notification_context,
293 const ServiceWorkerRegistration* service_worker_registration,
294 const NotificationDatabaseData& notification_database_data) {
295 const ServiceWorkerVersion::StatusCallback dispatch_event_callback =
296 base::Bind(&DeleteNotificationDataFromDatabase,
297 notification_database_data.notification_id,
298 notification_database_data.origin, notification_context,
299 dispatch_complete_callback);
300 if (by_user) {
301 service_worker_registration->active_version()->RunAfterStartWorker(
302 base::Bind(
303 &DispatchNotificationCloseEventOnWorker,
304 make_scoped_refptr(service_worker_registration->active_version()),
305 notification_database_data, dispatch_event_callback),
306 dispatch_event_callback);
307 } else {
308 dispatch_event_callback.Run(ServiceWorkerStatusCode::SERVICE_WORKER_OK);
309 }
310 }
311
312 // Dispatches any notification event. The actual, specific event dispatch should
313 // be done by the |notification_action_callback|.
314 void DispatchNotificationEvent(
229 BrowserContext* browser_context, 315 BrowserContext* browser_context,
230 int64_t persistent_notification_id, 316 int64_t persistent_notification_id,
231 const GURL& origin, 317 const GURL& origin,
232 int action_index, 318 const NotificationOperationCallbackWithContext&
233 const NotificationClickDispatchCompleteCallback& 319 notification_action_callback,
234 dispatch_complete_callback) { 320 const NotificationDispatchCompleteCallback& notification_error_callback) {
235 DCHECK_CURRENTLY_ON(BrowserThread::UI); 321 DCHECK_CURRENTLY_ON(BrowserThread::UI);
236 DCHECK_GT(persistent_notification_id, 0); 322 DCHECK_GT(persistent_notification_id, 0);
237 DCHECK(origin.is_valid()); 323 DCHECK(origin.is_valid());
238 324
239 StoragePartition* partition = 325 StoragePartition* partition =
240 BrowserContext::GetStoragePartitionForSite(browser_context, origin); 326 BrowserContext::GetStoragePartitionForSite(browser_context, origin);
241 327
242 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context = 328 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context =
243 static_cast<ServiceWorkerContextWrapper*>( 329 static_cast<ServiceWorkerContextWrapper*>(
244 partition->GetServiceWorkerContext()); 330 partition->GetServiceWorkerContext());
245 scoped_refptr<PlatformNotificationContextImpl> notification_context = 331 scoped_refptr<PlatformNotificationContext> notification_context =
246 static_cast<PlatformNotificationContextImpl*>( 332 partition->GetPlatformNotificationContext();
247 partition->GetPlatformNotificationContext());
248 333
249 BrowserThread::PostTask( 334 BrowserThread::PostTask(
250 BrowserThread::IO, FROM_HERE, 335 BrowserThread::IO, FROM_HERE,
251 base::Bind(&ReadNotificationDatabaseData, persistent_notification_id, 336 base::Bind(&ReadNotificationDatabaseData, persistent_notification_id,
252 origin, action_index, dispatch_complete_callback, 337 origin, service_worker_context, notification_context,
253 service_worker_context, notification_context)); 338 base::Bind(notification_action_callback, notification_context),
339 notification_error_callback));
340 }
341
342 } // namespace
343
344 // static
345 NotificationEventDispatcher* NotificationEventDispatcher::GetInstance() {
346 return NotificationEventDispatcherImpl::GetInstance();
347 }
348
349 NotificationEventDispatcherImpl*
350 NotificationEventDispatcherImpl::GetInstance() {
351 DCHECK_CURRENTLY_ON(BrowserThread::UI);
352 return base::Singleton<NotificationEventDispatcherImpl>::get();
353 }
354
355 NotificationEventDispatcherImpl::NotificationEventDispatcherImpl() {}
356
357 NotificationEventDispatcherImpl::~NotificationEventDispatcherImpl() {}
358
359 void NotificationEventDispatcherImpl::DispatchNotificationClickEvent(
360 BrowserContext* browser_context,
361 int64_t persistent_notification_id,
362 const GURL& origin,
363 int action_index,
364 const NotificationDispatchCompleteCallback& dispatch_complete_callback) {
365 DispatchNotificationEvent(
366 browser_context, persistent_notification_id, origin,
367 base::Bind(&DoDispatchNotificationClickEvent, action_index,
368 dispatch_complete_callback),
369 dispatch_complete_callback);
370 }
371
372 void NotificationEventDispatcherImpl::DispatchNotificationCloseEvent(
373 BrowserContext* browser_context,
374 int64_t persistent_notification_id,
375 const GURL& origin,
376 bool by_user,
377 const NotificationDispatchCompleteCallback& dispatch_complete_callback) {
378 DispatchNotificationEvent(browser_context, persistent_notification_id, origin,
379 base::Bind(&DoDispatchNotificationCloseEvent,
380 by_user, dispatch_complete_callback),
381 dispatch_complete_callback);
254 } 382 }
255 383
256 } // namespace content 384 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698