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

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

Issue 2151993002: [WebAPKs] Plumb service worker scope to notifications (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge branch 'master' into notification_scope Created 4 years, 5 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
11 #include "base/metrics/histogram_macros.h" 11 #include "base/metrics/histogram_macros.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/budget_service/background_budget_service.h" 14 #include "chrome/browser/budget_service/background_budget_service.h"
15 #include "chrome/browser/budget_service/background_budget_service_factory.h" 15 #include "chrome/browser/budget_service/background_budget_service_factory.h"
16 #include "chrome/browser/engagement/site_engagement_service.h" 16 #include "chrome/browser/engagement/site_engagement_service.h"
17 #include "chrome/browser/notifications/platform_notification_service_impl.h" 17 #include "chrome/browser/notifications/platform_notification_service_impl.h"
18 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/push_messaging/push_messaging_constants.h" 19 #include "chrome/browser/push_messaging/push_messaging_constants.h"
20 #include "chrome/common/features.h" 20 #include "chrome/common/features.h"
21 #include "chrome/grit/generated_resources.h" 21 #include "chrome/grit/generated_resources.h"
22 #include "components/rappor/rappor_utils.h" 22 #include "components/rappor/rappor_utils.h"
23 #include "components/url_formatter/elide_url.h" 23 #include "components/url_formatter/elide_url.h"
24 #include "content/browser/service_worker/service_worker_context_wrapper.h"
24 #include "content/public/browser/browser_context.h" 25 #include "content/public/browser/browser_context.h"
25 #include "content/public/browser/browser_thread.h" 26 #include "content/public/browser/browser_thread.h"
26 #include "content/public/browser/platform_notification_context.h" 27 #include "content/public/browser/platform_notification_context.h"
27 #include "content/public/browser/push_messaging_service.h" 28 #include "content/public/browser/push_messaging_service.h"
28 #include "content/public/browser/render_frame_host.h" 29 #include "content/public/browser/render_frame_host.h"
29 #include "content/public/browser/storage_partition.h" 30 #include "content/public/browser/storage_partition.h"
30 #include "content/public/browser/web_contents.h" 31 #include "content/public/browser/web_contents.h"
31 #include "content/public/common/notification_resources.h" 32 #include "content/public/common/notification_resources.h"
32 #include "content/public/common/url_constants.h" 33 #include "content/public/common/url_constants.h"
33 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" 34 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 CreateDatabaseData(origin, service_worker_registration_id); 312 CreateDatabaseData(origin, service_worker_registration_id);
312 scoped_refptr<PlatformNotificationContext> notification_context = 313 scoped_refptr<PlatformNotificationContext> notification_context =
313 GetStoragePartition(profile_, origin)->GetPlatformNotificationContext(); 314 GetStoragePartition(profile_, origin)->GetPlatformNotificationContext();
314 BrowserThread::PostTask( 315 BrowserThread::PostTask(
315 BrowserThread::IO, FROM_HERE, 316 BrowserThread::IO, FROM_HERE,
316 base::Bind(&PlatformNotificationContext::WriteNotificationData, 317 base::Bind(&PlatformNotificationContext::WriteNotificationData,
317 notification_context, origin, database_data, 318 notification_context, origin, database_data,
318 base::Bind(&PushMessagingNotificationManager:: 319 base::Bind(&PushMessagingNotificationManager::
319 DidWriteNotificationDataIOProxy, 320 DidWriteNotificationDataIOProxy,
320 weak_factory_.GetWeakPtr(), origin, 321 weak_factory_.GetWeakPtr(), origin,
322 service_worker_registration_id,
321 database_data.notification_data, 323 database_data.notification_data,
322 message_handled_closure))); 324 message_handled_closure)));
323 } 325 }
324 326
325 // static 327 // static
326 void PushMessagingNotificationManager::DidWriteNotificationDataIOProxy( 328 void PushMessagingNotificationManager::DidWriteNotificationDataIOProxy(
327 const base::WeakPtr<PushMessagingNotificationManager>& ui_weak_ptr, 329 const base::WeakPtr<PushMessagingNotificationManager>& ui_weak_ptr,
328 const GURL& origin, 330 const GURL& origin,
331 int service_worker_registration_id,
329 const PlatformNotificationData& notification_data, 332 const PlatformNotificationData& notification_data,
330 const base::Closure& message_handled_closure, 333 const base::Closure& message_handled_closure,
331 bool success, 334 bool success,
332 int64_t persistent_notification_id) { 335 int64_t persistent_notification_id) {
333 DCHECK_CURRENTLY_ON(BrowserThread::IO); 336 DCHECK_CURRENTLY_ON(BrowserThread::IO);
334 BrowserThread::PostTask( 337 BrowserThread::PostTask(
335 BrowserThread::UI, FROM_HERE, 338 BrowserThread::UI, FROM_HERE,
336 base::Bind(&PushMessagingNotificationManager::DidWriteNotificationData, 339 base::Bind(&PushMessagingNotificationManager::DidWriteNotificationData,
337 ui_weak_ptr, origin, notification_data, 340 ui_weak_ptr, origin, service_worker_registration_id,
338 message_handled_closure, success, persistent_notification_id)); 341 notification_data, message_handled_closure, success,
342 persistent_notification_id));
339 } 343 }
340 344
341 void PushMessagingNotificationManager::DidWriteNotificationData( 345 void PushMessagingNotificationManager::DidWriteNotificationData(
342 const GURL& origin, 346 const GURL& origin,
347 int service_worker_registration_id,
343 const PlatformNotificationData& notification_data, 348 const PlatformNotificationData& notification_data,
344 const base::Closure& message_handled_closure, 349 const base::Closure& message_handled_closure,
345 bool success, 350 bool success,
346 int64_t persistent_notification_id) { 351 int64_t persistent_notification_id) {
347 DCHECK_CURRENTLY_ON(BrowserThread::UI); 352 DCHECK_CURRENTLY_ON(BrowserThread::UI);
348 if (!success) { 353 if (!success) {
349 DLOG(ERROR) << "Writing forced notification to database should not fail"; 354 DLOG(ERROR) << "Writing forced notification to database should not fail";
350 message_handled_closure.Run(); 355 message_handled_closure.Run();
351 return; 356 return;
352 } 357 }
353 358
359 // Get the service worker scope.
Peter Beverloo 2016/07/15 13:40:11 The //content API does not allow us to do this (se
360 scoped_refptr<content::ServiceWorkerContextWrapper> service_worker_context =
361 static_cast<content::ServiceWorkerContextWrapper*>(
362 GetStoragePartition(profile_, origin)->GetServiceWorkerContext());
363 BrowserThread::PostTask(
364 BrowserThread::IO, FROM_HERE,
365 base::Bind(
366 &content::ServiceWorkerContextWrapper::FindReadyRegistrationForId,
pkotwicz 2016/07/14 19:32:50 Is it safe to call FindReadyRegistrationForId()? T
367 service_worker_context, service_worker_registration_id, origin,
368 base::Bind(&PushMessagingNotificationManager::
369 FindServiceWorkerRegistrationCallbackIOProxy,
370 weak_factory_.GetWeakPtr(), origin, notification_data,
371 message_handled_closure, persistent_notification_id)));
372 }
373
374 // static
375 void PushMessagingNotificationManager::
376 FindServiceWorkerRegistrationCallbackIOProxy(
377 const base::WeakPtr<PushMessagingNotificationManager>& ui_weak_ptr,
378 const GURL& origin,
379 const content::PlatformNotificationData& notification_data,
380 const base::Closure& message_handled_closure,
381 int64_t persistent_notification_id,
382 content::ServiceWorkerStatusCode service_worker_status,
383 const scoped_refptr<content::ServiceWorkerRegistration>& registration) {
384 DCHECK_CURRENTLY_ON(BrowserThread::IO);
385 BrowserThread::PostTask(
386 BrowserThread::UI, FROM_HERE,
387 base::Bind(&PushMessagingNotificationManager::
388 FindServiceWorkerRegistrationCallback,
389 ui_weak_ptr, origin, notification_data,
390 message_handled_closure, persistent_notification_id,
391 service_worker_status, registration));
392 }
393
394 void PushMessagingNotificationManager::FindServiceWorkerRegistrationCallback(
395 const GURL& origin,
396 const content::PlatformNotificationData& notification_data,
397 const base::Closure& message_handled_closure,
398 int64_t persistent_notification_id,
399 content::ServiceWorkerStatusCode service_worker_status,
400 const scoped_refptr<content::ServiceWorkerRegistration>& registration) {
401 DCHECK_CURRENTLY_ON(BrowserThread::UI);
354 PlatformNotificationServiceImpl::GetInstance()->DisplayPersistentNotification( 402 PlatformNotificationServiceImpl::GetInstance()->DisplayPersistentNotification(
355 profile_, persistent_notification_id, origin, notification_data, 403 profile_, persistent_notification_id, registration->pattern(), origin,
356 NotificationResources()); 404 notification_data, NotificationResources());
357 405
358 message_handled_closure.Run(); 406 message_handled_closure.Run();
359 } 407 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698