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

Side by Side Diff: chrome/browser/push_messaging/push_messaging_notification_manager.cc

Issue 1149243005: Automatically close the default push notification when a real one appears. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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 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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 break; 136 break;
137 } 137 }
138 138
139 // Use the visible URL since that's the one the user is aware of (and it 139 // Use the visible URL since that's the one the user is aware of (and it
140 // doesn't matter whether the page loaded successfully). 140 // doesn't matter whether the page loaded successfully).
141 const GURL& active_url = active_web_contents->GetVisibleURL(); 141 const GURL& active_url = active_web_contents->GetVisibleURL();
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)
johnme 2015/06/02 13:43:52 Please don't remove this. The double closing brack
Peter Beverloo 2015/06/02 13:58:08 I'm having a very hard time accepting that reasoni
147 } 146 }
148 #else 147
148 // If more than two notifications are showing for this Service Worker, close
149 // the default notification if it happens to be part of this group.
150 if (notification_count >= 2) {
151 for (const auto& notification_database_data : data) {
152 if (notification_database_data.notification_data.tag !=
153 kPushMessagingForcedNotificationTag)
154 continue;
155
156 PlatformNotificationServiceImpl* platform_notification_service =
157 PlatformNotificationServiceImpl::GetInstance();
158
159 // First close the notification for the user's point of view, and then
160 // manually tell the service that the notification has been closed in
161 // order to avoid duplicating the thread-jump logic.
162 platform_notification_service->ClosePersistentNotification(
163 profile_, notification_database_data.notification_id);
164 platform_notification_service->OnPersistentNotificationClose(
165 profile_, notification_database_data.notification_id,
166 notification_database_data.origin);
167
168 break;
169 }
149 } 170 }
150 #endif
151 171
152 // Don't track push messages that didn't show a notification but were exempt 172 // Don't track push messages that didn't show a notification but were exempt
153 // from needing to do so. 173 // from needing to do so.
154 if (notification_shown || notification_needed) { 174 if (notification_shown || notification_needed) {
155 content::ServiceWorkerContext* service_worker_context = 175 content::ServiceWorkerContext* service_worker_context =
156 content::BrowserContext::GetStoragePartitionForSite( 176 content::BrowserContext::GetStoragePartitionForSite(
157 profile_, requesting_origin)->GetServiceWorkerContext(); 177 profile_, requesting_origin)->GetServiceWorkerContext();
158 178
159 content::PushMessagingService::GetNotificationsShownByLastFewPushes( 179 content::PushMessagingService::GetNotificationsShownByLastFewPushes(
160 service_worker_context, service_worker_registration_id, 180 service_worker_context, service_worker_registration_id,
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 return; 314 return;
295 } 315 }
296 PlatformNotificationServiceImpl::GetInstance()->DisplayPersistentNotification( 316 PlatformNotificationServiceImpl::GetInstance()->DisplayPersistentNotification(
297 profile_, 317 profile_,
298 persistent_notification_id, 318 persistent_notification_id,
299 requesting_origin, 319 requesting_origin,
300 SkBitmap() /* icon */, 320 SkBitmap() /* icon */,
301 notification_data); 321 notification_data);
302 message_handled_closure.Run(); 322 message_handled_closure.Run();
303 } 323 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698