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

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

Issue 2361113002: Push API: Don't unsubscribe when finding Service Worker fails (Closed)
Patch Set: Created 4 years, 2 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 "base/metrics/histogram_macros.h"
10 #include "content/browser/service_worker/service_worker_context_wrapper.h" 11 #include "content/browser/service_worker/service_worker_context_wrapper.h"
11 #include "content/browser/service_worker/service_worker_registration.h" 12 #include "content/browser/service_worker/service_worker_registration.h"
12 #include "content/browser/service_worker/service_worker_storage.h" 13 #include "content/browser/service_worker/service_worker_storage.h"
13 #include "content/common/service_worker/service_worker_messages.h" 14 #include "content/common/service_worker/service_worker_messages.h"
14 #include "content/common/service_worker/service_worker_status_code.h" 15 #include "content/common/service_worker/service_worker_status_code.h"
15 #include "content/public/browser/browser_context.h" 16 #include "content/public/browser/browser_context.h"
16 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
17 #include "content/public/browser/storage_partition.h" 18 #include "content/public/browser/storage_partition.h"
18 #include "content/public/common/push_event_payload.h" 19 #include "content/public/common/push_event_payload.h"
19 20
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 payload, deliver_message_callback)); 69 payload, deliver_message_callback));
69 } 70 }
70 71
71 // static 72 // static
72 void PushMessagingRouter::FindServiceWorkerRegistrationCallback( 73 void PushMessagingRouter::FindServiceWorkerRegistrationCallback(
73 const PushEventPayload& payload, 74 const PushEventPayload& payload,
74 const DeliverMessageCallback& deliver_message_callback, 75 const DeliverMessageCallback& deliver_message_callback,
75 ServiceWorkerStatusCode service_worker_status, 76 ServiceWorkerStatusCode service_worker_status,
76 scoped_refptr<ServiceWorkerRegistration> service_worker_registration) { 77 scoped_refptr<ServiceWorkerRegistration> service_worker_registration) {
77 DCHECK_CURRENTLY_ON(BrowserThread::IO); 78 DCHECK_CURRENTLY_ON(BrowserThread::IO);
78 // TODO(mvanouwerkerk): UMA logging. 79 UMA_HISTOGRAM_ENUMERATION("PushMessaging.DeliveryStatus.FindServiceWorker",
80 service_worker_status,
81 SERVICE_WORKER_ERROR_MAX_VALUE);
82 if (service_worker_status == SERVICE_WORKER_ERROR_NOT_FOUND) {
83 RunDeliverCallback(deliver_message_callback,
84 PUSH_DELIVERY_STATUS_NO_SERVICE_WORKER);
85 return;
86 }
79 if (service_worker_status != SERVICE_WORKER_OK) { 87 if (service_worker_status != SERVICE_WORKER_OK) {
80 RunDeliverCallback(deliver_message_callback, 88 RunDeliverCallback(deliver_message_callback,
81 PUSH_DELIVERY_STATUS_NO_SERVICE_WORKER); 89 PUSH_DELIVERY_STATUS_SERVICE_WORKER_ERROR);
82 return; 90 return;
83 } 91 }
84 92
85 ServiceWorkerVersion* version = service_worker_registration->active_version(); 93 ServiceWorkerVersion* version = service_worker_registration->active_version();
86 DCHECK(version); 94 DCHECK(version);
87 95
88 // Hold on to the service worker registration in the callback to keep it 96 // Hold on to the service worker registration in the callback to keep it
89 // alive until the callback dies. Otherwise the registration could be 97 // alive until the callback dies. Otherwise the registration could be
90 // released when this method returns - before the event is delivered to the 98 // released when this method returns - before the event is delivered to the
91 // service worker. 99 // service worker.
(...skipping 20 matching lines...) Expand all
112 service_worker->DispatchSimpleEvent<ServiceWorkerHostMsg_PushEventFinished>( 120 service_worker->DispatchSimpleEvent<ServiceWorkerHostMsg_PushEventFinished>(
113 request_id, ServiceWorkerMsg_PushEvent(request_id, payload)); 121 request_id, ServiceWorkerMsg_PushEvent(request_id, payload));
114 } 122 }
115 123
116 // static 124 // static
117 void PushMessagingRouter::DeliverMessageEnd( 125 void PushMessagingRouter::DeliverMessageEnd(
118 const DeliverMessageCallback& deliver_message_callback, 126 const DeliverMessageCallback& deliver_message_callback,
119 const scoped_refptr<ServiceWorkerRegistration>& service_worker_registration, 127 const scoped_refptr<ServiceWorkerRegistration>& service_worker_registration,
120 ServiceWorkerStatusCode service_worker_status) { 128 ServiceWorkerStatusCode service_worker_status) {
121 DCHECK_CURRENTLY_ON(BrowserThread::IO); 129 DCHECK_CURRENTLY_ON(BrowserThread::IO);
122 // TODO(mvanouwerkerk): UMA logging. 130 UMA_HISTOGRAM_ENUMERATION("PushMessaging.DeliveryStatus.ServiceWorkerEvent",
131 service_worker_status,
132 SERVICE_WORKER_ERROR_MAX_VALUE);
123 PushDeliveryStatus delivery_status = 133 PushDeliveryStatus delivery_status =
124 PUSH_DELIVERY_STATUS_SERVICE_WORKER_ERROR; 134 PUSH_DELIVERY_STATUS_SERVICE_WORKER_ERROR;
125 switch (service_worker_status) { 135 switch (service_worker_status) {
126 case SERVICE_WORKER_OK: 136 case SERVICE_WORKER_OK:
127 delivery_status = PUSH_DELIVERY_STATUS_SUCCESS; 137 delivery_status = PUSH_DELIVERY_STATUS_SUCCESS;
128 break; 138 break;
129 case SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED: 139 case SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED:
130 delivery_status = PUSH_DELIVERY_STATUS_EVENT_WAITUNTIL_REJECTED; 140 delivery_status = PUSH_DELIVERY_STATUS_EVENT_WAITUNTIL_REJECTED;
131 break; 141 break;
132 case SERVICE_WORKER_ERROR_FAILED: 142 case SERVICE_WORKER_ERROR_FAILED:
(...skipping 18 matching lines...) Expand all
151 case SERVICE_WORKER_ERROR_MAX_VALUE: 161 case SERVICE_WORKER_ERROR_MAX_VALUE:
152 NOTREACHED() << "Got unexpected error code: " << service_worker_status 162 NOTREACHED() << "Got unexpected error code: " << service_worker_status
153 << " " << ServiceWorkerStatusToString(service_worker_status); 163 << " " << ServiceWorkerStatusToString(service_worker_status);
154 delivery_status = PUSH_DELIVERY_STATUS_SERVICE_WORKER_ERROR; 164 delivery_status = PUSH_DELIVERY_STATUS_SERVICE_WORKER_ERROR;
155 break; 165 break;
156 } 166 }
157 RunDeliverCallback(deliver_message_callback, delivery_status); 167 RunDeliverCallback(deliver_message_callback, delivery_status);
158 } 168 }
159 169
160 } // namespace content 170 } // namespace content
OLDNEW
« no previous file with comments | « chrome/browser/push_messaging/push_messaging_browsertest.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698