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

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

Issue 2300093002: Make //content responsible for generating notification Ids (Closed)
Patch Set: Make //content responsible for generating notification Ids Created 4 years, 3 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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <bitset> 9 #include <bitset>
10 10
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 } 164 }
165 165
166 // If more than one notification is showing for this Service Worker, close 166 // If more than one notification is showing for this Service Worker, close
167 // the default notification if it happens to be part of this group. 167 // the default notification if it happens to be part of this group.
168 if (notification_count >= 2) { 168 if (notification_count >= 2) {
169 for (const auto& notification_database_data : data) { 169 for (const auto& notification_database_data : data) {
170 if (notification_database_data.notification_data.tag != 170 if (notification_database_data.notification_data.tag !=
171 kPushMessagingForcedNotificationTag) 171 kPushMessagingForcedNotificationTag)
172 continue; 172 continue;
173 173
174 scoped_refptr<PlatformNotificationContext> notification_context =
175 GetStoragePartition(profile_, origin)
176 ->GetPlatformNotificationContext();
177
178 const std::string notification_id =
179 notification_context->GenerateNotificationId(
180 origin, kPushMessagingForcedNotificationTag,
181 notification_database_data.notification_id);
182
174 PlatformNotificationServiceImpl* platform_notification_service = 183 PlatformNotificationServiceImpl* platform_notification_service =
175 PlatformNotificationServiceImpl::GetInstance(); 184 PlatformNotificationServiceImpl::GetInstance();
176 185
177 // First close the notification for the user's point of view, and then 186 // First close the notification for the user's point of view, and then
178 // manually tell the service that the notification has been closed in 187 // manually tell the service that the notification has been closed in
179 // order to avoid duplicating the thread-jump logic. 188 // order to avoid duplicating the thread-jump logic.
180 platform_notification_service->ClosePersistentNotification( 189 platform_notification_service->ClosePersistentNotification(
181 profile_, notification_database_data.notification_id); 190 profile_, notification_id);
182 platform_notification_service->OnPersistentNotificationClose( 191 platform_notification_service->OnPersistentNotificationClose(
183 profile_, notification_database_data.notification_id, 192 profile_, notification_id, notification_database_data.origin,
184 notification_database_data.origin, false /* by_user */); 193 false /* by_user */);
185 194
186 break; 195 break;
187 } 196 }
188 } 197 }
189 198
190 // Get the budget for the origin. 199 // Get the budget for the origin.
191 BudgetManager* manager = BudgetManagerFactory::GetForProfile(profile_); 200 BudgetManager* manager = BudgetManagerFactory::GetForProfile(profile_);
192 manager->GetBudget( 201 manager->GetBudget(
193 origin, 202 origin,
194 base::Bind(&PushMessagingNotificationManager::DidGetBudget, 203 base::Bind(&PushMessagingNotificationManager::DidGetBudget,
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 message_handled_closure))); 330 message_handled_closure)));
322 } 331 }
323 332
324 // static 333 // static
325 void PushMessagingNotificationManager::DidWriteNotificationDataIOProxy( 334 void PushMessagingNotificationManager::DidWriteNotificationDataIOProxy(
326 const base::WeakPtr<PushMessagingNotificationManager>& ui_weak_ptr, 335 const base::WeakPtr<PushMessagingNotificationManager>& ui_weak_ptr,
327 const GURL& origin, 336 const GURL& origin,
328 const PlatformNotificationData& notification_data, 337 const PlatformNotificationData& notification_data,
329 const base::Closure& message_handled_closure, 338 const base::Closure& message_handled_closure,
330 bool success, 339 bool success,
331 int64_t persistent_notification_id) { 340 const std::string& notification_id) {
332 DCHECK_CURRENTLY_ON(BrowserThread::IO); 341 DCHECK_CURRENTLY_ON(BrowserThread::IO);
333 BrowserThread::PostTask( 342 BrowserThread::PostTask(
334 BrowserThread::UI, FROM_HERE, 343 BrowserThread::UI, FROM_HERE,
335 base::Bind(&PushMessagingNotificationManager::DidWriteNotificationData, 344 base::Bind(&PushMessagingNotificationManager::DidWriteNotificationData,
336 ui_weak_ptr, origin, notification_data, 345 ui_weak_ptr, origin, notification_data,
337 message_handled_closure, success, persistent_notification_id)); 346 message_handled_closure, success, notification_id));
338 } 347 }
339 348
340 void PushMessagingNotificationManager::DidWriteNotificationData( 349 void PushMessagingNotificationManager::DidWriteNotificationData(
341 const GURL& origin, 350 const GURL& origin,
342 const PlatformNotificationData& notification_data, 351 const PlatformNotificationData& notification_data,
343 const base::Closure& message_handled_closure, 352 const base::Closure& message_handled_closure,
344 bool success, 353 bool success,
345 int64_t persistent_notification_id) { 354 const std::string& notification_id) {
346 DCHECK_CURRENTLY_ON(BrowserThread::UI); 355 DCHECK_CURRENTLY_ON(BrowserThread::UI);
347 if (!success) { 356 if (!success) {
348 DLOG(ERROR) << "Writing forced notification to database should not fail"; 357 DLOG(ERROR) << "Writing forced notification to database should not fail";
349 message_handled_closure.Run(); 358 message_handled_closure.Run();
350 return; 359 return;
351 } 360 }
352 361
353 // Do not pass service worker scope. The origin will be used instead of the 362 // Do not pass service worker scope. The origin will be used instead of the
354 // service worker scope to determine whether a notification should be 363 // service worker scope to determine whether a notification should be
355 // attributed to a WebAPK on Android. This is OK because this code path is hit 364 // attributed to a WebAPK on Android. This is OK because this code path is hit
356 // rarely. 365 // rarely.
357 PlatformNotificationServiceImpl::GetInstance()->DisplayPersistentNotification( 366 PlatformNotificationServiceImpl::GetInstance()->DisplayPersistentNotification(
358 profile_, persistent_notification_id, GURL() /* service_worker_scope */, 367 profile_, notification_id, GURL() /* service_worker_scope */, origin,
359 origin, notification_data, NotificationResources()); 368 notification_data, NotificationResources());
360 369
361 message_handled_closure.Run(); 370 message_handled_closure.Run();
362 } 371 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698