OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/push_messaging/push_messaging_notification_manager.h" | 5 #include "chrome/browser/push_messaging/push_messaging_notification_manager.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <bitset> | 9 #include <bitset> |
10 | 10 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 const GURL& origin, | 97 const GURL& origin, |
98 int64_t service_worker_registration_id, | 98 int64_t service_worker_registration_id, |
99 const base::Closure& message_handled_closure) { | 99 const base::Closure& message_handled_closure) { |
100 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 100 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
101 // TODO(johnme): Relax this heuristic slightly. | 101 // TODO(johnme): Relax this heuristic slightly. |
102 scoped_refptr<PlatformNotificationContext> notification_context = | 102 scoped_refptr<PlatformNotificationContext> notification_context = |
103 GetStoragePartition(profile_, origin)->GetPlatformNotificationContext(); | 103 GetStoragePartition(profile_, origin)->GetPlatformNotificationContext(); |
104 | 104 |
105 BrowserThread::PostTask( | 105 BrowserThread::PostTask( |
106 BrowserThread::IO, FROM_HERE, | 106 BrowserThread::IO, FROM_HERE, |
107 base::Bind( | 107 base::BindOnce( |
108 &PlatformNotificationContext:: | 108 &PlatformNotificationContext:: |
109 ReadAllNotificationDataForServiceWorkerRegistration, | 109 ReadAllNotificationDataForServiceWorkerRegistration, |
110 notification_context, origin, service_worker_registration_id, | 110 notification_context, origin, service_worker_registration_id, |
111 base::Bind(&PushMessagingNotificationManager:: | 111 base::Bind(&PushMessagingNotificationManager:: |
112 DidGetNotificationsFromDatabaseIOProxy, | 112 DidGetNotificationsFromDatabaseIOProxy, |
113 weak_factory_.GetWeakPtr(), origin, | 113 weak_factory_.GetWeakPtr(), origin, |
114 service_worker_registration_id, message_handled_closure))); | 114 service_worker_registration_id, message_handled_closure))); |
115 } | 115 } |
116 | 116 |
117 // static | 117 // static |
118 void PushMessagingNotificationManager::DidGetNotificationsFromDatabaseIOProxy( | 118 void PushMessagingNotificationManager::DidGetNotificationsFromDatabaseIOProxy( |
119 const base::WeakPtr<PushMessagingNotificationManager>& ui_weak_ptr, | 119 const base::WeakPtr<PushMessagingNotificationManager>& ui_weak_ptr, |
120 const GURL& origin, | 120 const GURL& origin, |
121 int64_t service_worker_registration_id, | 121 int64_t service_worker_registration_id, |
122 const base::Closure& message_handled_closure, | 122 const base::Closure& message_handled_closure, |
123 bool success, | 123 bool success, |
124 const std::vector<NotificationDatabaseData>& data) { | 124 const std::vector<NotificationDatabaseData>& data) { |
125 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 125 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
126 BrowserThread::PostTask( | 126 BrowserThread::PostTask( |
127 BrowserThread::UI, FROM_HERE, | 127 BrowserThread::UI, FROM_HERE, |
128 base::Bind( | 128 base::BindOnce( |
129 &PushMessagingNotificationManager::DidGetNotificationsFromDatabase, | 129 &PushMessagingNotificationManager::DidGetNotificationsFromDatabase, |
130 ui_weak_ptr, origin, service_worker_registration_id, | 130 ui_weak_ptr, origin, service_worker_registration_id, |
131 message_handled_closure, success, data)); | 131 message_handled_closure, success, data)); |
132 } | 132 } |
133 | 133 |
134 void PushMessagingNotificationManager::DidGetNotificationsFromDatabase( | 134 void PushMessagingNotificationManager::DidGetNotificationsFromDatabase( |
135 const GURL& origin, | 135 const GURL& origin, |
136 int64_t service_worker_registration_id, | 136 int64_t service_worker_registration_id, |
137 const base::Closure& message_handled_closure, | 137 const base::Closure& message_handled_closure, |
138 bool success, | 138 bool success, |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 | 269 |
270 // The site failed to show a notification when one was needed, and they don't | 270 // The site failed to show a notification when one was needed, and they don't |
271 // have enough budget to cover the cost of suppressing, so we will show a | 271 // have enough budget to cover the cost of suppressing, so we will show a |
272 // generic notification. | 272 // generic notification. |
273 NotificationDatabaseData database_data = | 273 NotificationDatabaseData database_data = |
274 CreateDatabaseData(origin, service_worker_registration_id); | 274 CreateDatabaseData(origin, service_worker_registration_id); |
275 scoped_refptr<PlatformNotificationContext> notification_context = | 275 scoped_refptr<PlatformNotificationContext> notification_context = |
276 GetStoragePartition(profile_, origin)->GetPlatformNotificationContext(); | 276 GetStoragePartition(profile_, origin)->GetPlatformNotificationContext(); |
277 BrowserThread::PostTask( | 277 BrowserThread::PostTask( |
278 BrowserThread::IO, FROM_HERE, | 278 BrowserThread::IO, FROM_HERE, |
279 base::Bind(&PlatformNotificationContext::WriteNotificationData, | 279 base::BindOnce(&PlatformNotificationContext::WriteNotificationData, |
280 notification_context, origin, database_data, | 280 notification_context, origin, database_data, |
281 base::Bind(&PushMessagingNotificationManager:: | 281 base::Bind(&PushMessagingNotificationManager:: |
282 DidWriteNotificationDataIOProxy, | 282 DidWriteNotificationDataIOProxy, |
283 weak_factory_.GetWeakPtr(), origin, | 283 weak_factory_.GetWeakPtr(), origin, |
284 database_data.notification_data, | 284 database_data.notification_data, |
285 message_handled_closure))); | 285 message_handled_closure))); |
286 } | 286 } |
287 | 287 |
288 // static | 288 // static |
289 void PushMessagingNotificationManager::DidWriteNotificationDataIOProxy( | 289 void PushMessagingNotificationManager::DidWriteNotificationDataIOProxy( |
290 const base::WeakPtr<PushMessagingNotificationManager>& ui_weak_ptr, | 290 const base::WeakPtr<PushMessagingNotificationManager>& ui_weak_ptr, |
291 const GURL& origin, | 291 const GURL& origin, |
292 const PlatformNotificationData& notification_data, | 292 const PlatformNotificationData& notification_data, |
293 const base::Closure& message_handled_closure, | 293 const base::Closure& message_handled_closure, |
294 bool success, | 294 bool success, |
295 const std::string& notification_id) { | 295 const std::string& notification_id) { |
296 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 296 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
297 BrowserThread::PostTask( | 297 BrowserThread::PostTask( |
298 BrowserThread::UI, FROM_HERE, | 298 BrowserThread::UI, FROM_HERE, |
299 base::Bind(&PushMessagingNotificationManager::DidWriteNotificationData, | 299 base::BindOnce( |
300 ui_weak_ptr, origin, notification_data, | 300 &PushMessagingNotificationManager::DidWriteNotificationData, |
301 message_handled_closure, success, notification_id)); | 301 ui_weak_ptr, origin, notification_data, message_handled_closure, |
| 302 success, notification_id)); |
302 } | 303 } |
303 | 304 |
304 void PushMessagingNotificationManager::DidWriteNotificationData( | 305 void PushMessagingNotificationManager::DidWriteNotificationData( |
305 const GURL& origin, | 306 const GURL& origin, |
306 const PlatformNotificationData& notification_data, | 307 const PlatformNotificationData& notification_data, |
307 const base::Closure& message_handled_closure, | 308 const base::Closure& message_handled_closure, |
308 bool success, | 309 bool success, |
309 const std::string& notification_id) { | 310 const std::string& notification_id) { |
310 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 311 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
311 if (!success) { | 312 if (!success) { |
312 DLOG(ERROR) << "Writing forced notification to database should not fail"; | 313 DLOG(ERROR) << "Writing forced notification to database should not fail"; |
313 message_handled_closure.Run(); | 314 message_handled_closure.Run(); |
314 return; | 315 return; |
315 } | 316 } |
316 | 317 |
317 // Do not pass service worker scope. The origin will be used instead of the | 318 // Do not pass service worker scope. The origin will be used instead of the |
318 // service worker scope to determine whether a notification should be | 319 // service worker scope to determine whether a notification should be |
319 // attributed to a WebAPK on Android. This is OK because this code path is hit | 320 // attributed to a WebAPK on Android. This is OK because this code path is hit |
320 // rarely. | 321 // rarely. |
321 PlatformNotificationServiceImpl::GetInstance()->DisplayPersistentNotification( | 322 PlatformNotificationServiceImpl::GetInstance()->DisplayPersistentNotification( |
322 profile_, notification_id, GURL() /* service_worker_scope */, origin, | 323 profile_, notification_id, GURL() /* service_worker_scope */, origin, |
323 notification_data, NotificationResources()); | 324 notification_data, NotificationResources()); |
324 | 325 |
325 message_handled_closure.Run(); | 326 message_handled_closure.Run(); |
326 } | 327 } |
OLD | NEW |