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 <bitset> | 7 #include <bitset> |
8 | 8 |
9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 if (requesting_origin == active_url.GetOrigin()) { | 142 if (requesting_origin == active_url.GetOrigin()) { |
143 notification_needed = false; | 143 notification_needed = false; |
144 break; | 144 break; |
145 } | 145 } |
146 #if defined(OS_ANDROID) | 146 #if defined(OS_ANDROID) |
147 } | 147 } |
148 #else | 148 #else |
149 } | 149 } |
150 #endif | 150 #endif |
151 | 151 |
| 152 // If more than two notifications are showing for this Service Worker, close |
| 153 // the default notification if it happens to be part of this group. |
| 154 if (notification_count >= 2) { |
| 155 for (const auto& notification_database_data : data) { |
| 156 if (notification_database_data.notification_data.tag != |
| 157 kPushMessagingForcedNotificationTag) |
| 158 continue; |
| 159 |
| 160 PlatformNotificationServiceImpl* platform_notification_service = |
| 161 PlatformNotificationServiceImpl::GetInstance(); |
| 162 |
| 163 // First close the notification for the user's point of view, and then |
| 164 // manually tell the service that the notification has been closed in |
| 165 // order to avoid duplicating the thread-jump logic. |
| 166 platform_notification_service->ClosePersistentNotification( |
| 167 profile_, notification_database_data.notification_id); |
| 168 platform_notification_service->OnPersistentNotificationClose( |
| 169 profile_, notification_database_data.notification_id, |
| 170 notification_database_data.origin); |
| 171 |
| 172 break; |
| 173 } |
| 174 } |
| 175 |
152 // Don't track push messages that didn't show a notification but were exempt | 176 // Don't track push messages that didn't show a notification but were exempt |
153 // from needing to do so. | 177 // from needing to do so. |
154 if (notification_shown || notification_needed) { | 178 if (notification_shown || notification_needed) { |
155 content::ServiceWorkerContext* service_worker_context = | 179 content::ServiceWorkerContext* service_worker_context = |
156 content::BrowserContext::GetStoragePartitionForSite( | 180 content::BrowserContext::GetStoragePartitionForSite( |
157 profile_, requesting_origin)->GetServiceWorkerContext(); | 181 profile_, requesting_origin)->GetServiceWorkerContext(); |
158 | 182 |
159 content::PushMessagingService::GetNotificationsShownByLastFewPushes( | 183 content::PushMessagingService::GetNotificationsShownByLastFewPushes( |
160 service_worker_context, service_worker_registration_id, | 184 service_worker_context, service_worker_registration_id, |
161 base::Bind(&PushMessagingNotificationManager | 185 base::Bind(&PushMessagingNotificationManager |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 return; | 318 return; |
295 } | 319 } |
296 PlatformNotificationServiceImpl::GetInstance()->DisplayPersistentNotification( | 320 PlatformNotificationServiceImpl::GetInstance()->DisplayPersistentNotification( |
297 profile_, | 321 profile_, |
298 persistent_notification_id, | 322 persistent_notification_id, |
299 requesting_origin, | 323 requesting_origin, |
300 SkBitmap() /* icon */, | 324 SkBitmap() /* icon */, |
301 notification_data); | 325 notification_data); |
302 message_handled_closure.Run(); | 326 message_handled_closure.Run(); |
303 } | 327 } |
OLD | NEW |