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

Side by Side Diff: content/browser/push_messaging/push_messaging_router.cc

Issue 1636483002: Update the PushEvent to have a nullable PushMessageData (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "content/browser/push_messaging/push_messaging_router.h" 5 #include "content/browser/push_messaging/push_messaging_router.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "content/browser/service_worker/service_worker_context_wrapper.h" 10 #include "content/browser/service_worker/service_worker_context_wrapper.h"
(...skipping 16 matching lines...) Expand all
27 base::Bind(deliver_message_callback, delivery_status)); 27 base::Bind(deliver_message_callback, delivery_status));
28 } 28 }
29 29
30 } // namespace 30 } // namespace
31 31
32 // static 32 // static
33 void PushMessagingRouter::DeliverMessage( 33 void PushMessagingRouter::DeliverMessage(
34 BrowserContext* browser_context, 34 BrowserContext* browser_context,
35 const GURL& origin, 35 const GURL& origin,
36 int64_t service_worker_registration_id, 36 int64_t service_worker_registration_id,
37 const std::string& data, 37 const content::PushEventPayload& payload,
38 const DeliverMessageCallback& deliver_message_callback) { 38 const DeliverMessageCallback& deliver_message_callback) {
39 DCHECK_CURRENTLY_ON(BrowserThread::UI); 39 DCHECK_CURRENTLY_ON(BrowserThread::UI);
40 StoragePartition* partition = 40 StoragePartition* partition =
41 BrowserContext::GetStoragePartitionForSite(browser_context, origin); 41 BrowserContext::GetStoragePartitionForSite(browser_context, origin);
42 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context = 42 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context =
43 static_cast<ServiceWorkerContextWrapper*>( 43 static_cast<ServiceWorkerContextWrapper*>(
44 partition->GetServiceWorkerContext()); 44 partition->GetServiceWorkerContext());
45 BrowserThread::PostTask( 45 BrowserThread::PostTask(
46 BrowserThread::IO, FROM_HERE, 46 BrowserThread::IO, FROM_HERE,
47 base::Bind(&PushMessagingRouter::FindServiceWorkerRegistration, origin, 47 base::Bind(&PushMessagingRouter::FindServiceWorkerRegistration, origin,
48 service_worker_registration_id, data, deliver_message_callback, 48 service_worker_registration_id, payload,
49 service_worker_context)); 49 deliver_message_callback, service_worker_context));
50 } 50 }
51 51
52 // static 52 // static
53 void PushMessagingRouter::FindServiceWorkerRegistration( 53 void PushMessagingRouter::FindServiceWorkerRegistration(
54 const GURL& origin, 54 const GURL& origin,
55 int64_t service_worker_registration_id, 55 int64_t service_worker_registration_id,
56 const std::string& data, 56 const content::PushEventPayload& payload,
57 const DeliverMessageCallback& deliver_message_callback, 57 const DeliverMessageCallback& deliver_message_callback,
58 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context) { 58 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context) {
59 DCHECK_CURRENTLY_ON(BrowserThread::IO); 59 DCHECK_CURRENTLY_ON(BrowserThread::IO);
60 // Try to acquire the registration from storage. If it's already live we'll 60 // Try to acquire the registration from storage. If it's already live we'll
61 // receive it right away. If not, it will be revived from storage. 61 // receive it right away. If not, it will be revived from storage.
62 service_worker_context->FindReadyRegistrationForId( 62 service_worker_context->FindReadyRegistrationForId(
63 service_worker_registration_id, origin, 63 service_worker_registration_id, origin,
64 base::Bind(&PushMessagingRouter::FindServiceWorkerRegistrationCallback, 64 base::Bind(&PushMessagingRouter::FindServiceWorkerRegistrationCallback,
65 data, deliver_message_callback)); 65 payload, deliver_message_callback));
66 } 66 }
67 67
68 // static 68 // static
69 void PushMessagingRouter::FindServiceWorkerRegistrationCallback( 69 void PushMessagingRouter::FindServiceWorkerRegistrationCallback(
70 const std::string& data, 70 const content::PushEventPayload& payload,
71 const DeliverMessageCallback& deliver_message_callback, 71 const DeliverMessageCallback& deliver_message_callback,
72 ServiceWorkerStatusCode service_worker_status, 72 ServiceWorkerStatusCode service_worker_status,
73 const scoped_refptr<ServiceWorkerRegistration>& 73 const scoped_refptr<ServiceWorkerRegistration>&
74 service_worker_registration) { 74 service_worker_registration) {
75 DCHECK_CURRENTLY_ON(BrowserThread::IO); 75 DCHECK_CURRENTLY_ON(BrowserThread::IO);
76 // TODO(mvanouwerkerk): UMA logging. 76 // TODO(mvanouwerkerk): UMA logging.
77 if (service_worker_status != SERVICE_WORKER_OK) { 77 if (service_worker_status != SERVICE_WORKER_OK) {
78 RunDeliverCallback(deliver_message_callback, 78 RunDeliverCallback(deliver_message_callback,
79 PUSH_DELIVERY_STATUS_NO_SERVICE_WORKER); 79 PUSH_DELIVERY_STATUS_NO_SERVICE_WORKER);
80 return; 80 return;
81 } 81 }
82 82
83 ServiceWorkerVersion* version = service_worker_registration->active_version(); 83 ServiceWorkerVersion* version = service_worker_registration->active_version();
84 DCHECK(version); 84 DCHECK(version);
85 85
86 // Hold on to the service worker registration in the callback to keep it 86 // Hold on to the service worker registration in the callback to keep it
87 // alive until the callback dies. Otherwise the registration could be 87 // alive until the callback dies. Otherwise the registration could be
88 // released when this method returns - before the event is delivered to the 88 // released when this method returns - before the event is delivered to the
89 // service worker. 89 // service worker.
90 base::Callback<void(ServiceWorkerStatusCode)> dispatch_event_callback = 90 base::Callback<void(ServiceWorkerStatusCode)> dispatch_event_callback =
91 base::Bind(&PushMessagingRouter::DeliverMessageEnd, 91 base::Bind(&PushMessagingRouter::DeliverMessageEnd,
92 deliver_message_callback, service_worker_registration); 92 deliver_message_callback, service_worker_registration);
93 93
94 version->DispatchPushEvent(dispatch_event_callback, data); 94 version->DispatchPushEvent(dispatch_event_callback, payload);
95 } 95 }
96 96
97 // static 97 // static
98 void PushMessagingRouter::DeliverMessageEnd( 98 void PushMessagingRouter::DeliverMessageEnd(
99 const DeliverMessageCallback& deliver_message_callback, 99 const DeliverMessageCallback& deliver_message_callback,
100 const scoped_refptr<ServiceWorkerRegistration>& service_worker_registration, 100 const scoped_refptr<ServiceWorkerRegistration>& service_worker_registration,
101 ServiceWorkerStatusCode service_worker_status) { 101 ServiceWorkerStatusCode service_worker_status) {
102 DCHECK_CURRENTLY_ON(BrowserThread::IO); 102 DCHECK_CURRENTLY_ON(BrowserThread::IO);
103 // TODO(mvanouwerkerk): UMA logging. 103 // TODO(mvanouwerkerk): UMA logging.
104 PushDeliveryStatus delivery_status = 104 PushDeliveryStatus delivery_status =
(...skipping 27 matching lines...) Expand all
132 case SERVICE_WORKER_ERROR_MAX_VALUE: 132 case SERVICE_WORKER_ERROR_MAX_VALUE:
133 NOTREACHED() << "Got unexpected error code: " << service_worker_status 133 NOTREACHED() << "Got unexpected error code: " << service_worker_status
134 << " " << ServiceWorkerStatusToString(service_worker_status); 134 << " " << ServiceWorkerStatusToString(service_worker_status);
135 delivery_status = PUSH_DELIVERY_STATUS_SERVICE_WORKER_ERROR; 135 delivery_status = PUSH_DELIVERY_STATUS_SERVICE_WORKER_ERROR;
136 break; 136 break;
137 } 137 }
138 RunDeliverCallback(deliver_message_callback, delivery_status); 138 RunDeliverCallback(deliver_message_callback, delivery_status);
139 } 139 }
140 140
141 } // namespace content 141 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698