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

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

Issue 2569993002: [ServiceWorker] Mojofy PushEvent of Service Worker. (Closed)
Patch Set: Created 4 years 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 "base/metrics/histogram_macros.h"
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 const scoped_refptr<ServiceWorkerRegistration>& service_worker_registration, 116 const scoped_refptr<ServiceWorkerRegistration>& service_worker_registration,
117 const PushEventPayload& payload, 117 const PushEventPayload& payload,
118 const DeliverMessageCallback& deliver_message_callback) { 118 const DeliverMessageCallback& deliver_message_callback) {
119 DCHECK_CURRENTLY_ON(BrowserThread::IO); 119 DCHECK_CURRENTLY_ON(BrowserThread::IO);
120 int request_id = service_worker->StartRequestWithCustomTimeout( 120 int request_id = service_worker->StartRequestWithCustomTimeout(
121 ServiceWorkerMetrics::EventType::PUSH, 121 ServiceWorkerMetrics::EventType::PUSH,
122 base::Bind(&PushMessagingRouter::DeliverMessageEnd, 122 base::Bind(&PushMessagingRouter::DeliverMessageEnd,
123 deliver_message_callback, service_worker_registration), 123 deliver_message_callback, service_worker_registration),
124 base::TimeDelta::FromSeconds(kPushMessageTimeoutSeconds), 124 base::TimeDelta::FromSeconds(kPushMessageTimeoutSeconds),
125 ServiceWorkerVersion::KILL_ON_TIMEOUT); 125 ServiceWorkerVersion::KILL_ON_TIMEOUT);
126 service_worker->DispatchSimpleEvent<ServiceWorkerHostMsg_PushEventFinished>( 126
127 request_id, ServiceWorkerMsg_PushEvent(request_id, payload)); 127 // |event_dispatcher| is owned by |service_worker|, once |service_worker|
128 // got destroyed, the bound function will never be called, so it is safe to
129 // use
shimazu 2016/12/14 04:42:34 nit: please fix indent
xiaofengzhang 2016/12/15 01:30:49 Acknowledged.
130 // base::Unretained() here.
131 service_worker->event_dispatcher()->DispatchPushEvent(
132 payload, base::Bind(&ServiceWorkerVersion::OnSimpleEventFinished,
133 base::Unretained(service_worker.get()), request_id));
Peter Beverloo 2016/12/13 13:31:32 Instead of using base::Unretained(), just pass |se
leonhsl(Using Gerrit) 2016/12/14 03:29:18 I have one question which I'm not so sure: This wa
xiaofengzhang 2016/12/15 01:30:48 I re-submit and pass |service_worker| directly, bu
xiaofengzhang 2016/12/16 01:34:48 Any comments on Leon's question: "I have one quest
128 } 134 }
129 135
130 // static 136 // static
131 void PushMessagingRouter::DeliverMessageEnd( 137 void PushMessagingRouter::DeliverMessageEnd(
132 const DeliverMessageCallback& deliver_message_callback, 138 const DeliverMessageCallback& deliver_message_callback,
133 const scoped_refptr<ServiceWorkerRegistration>& service_worker_registration, 139 const scoped_refptr<ServiceWorkerRegistration>& service_worker_registration,
134 ServiceWorkerStatusCode service_worker_status) { 140 ServiceWorkerStatusCode service_worker_status) {
135 DCHECK_CURRENTLY_ON(BrowserThread::IO); 141 DCHECK_CURRENTLY_ON(BrowserThread::IO);
136 UMA_HISTOGRAM_ENUMERATION("PushMessaging.DeliveryStatus.ServiceWorkerEvent", 142 UMA_HISTOGRAM_ENUMERATION("PushMessaging.DeliveryStatus.ServiceWorkerEvent",
137 service_worker_status, 143 service_worker_status,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 case SERVICE_WORKER_ERROR_MAX_VALUE: 175 case SERVICE_WORKER_ERROR_MAX_VALUE:
170 NOTREACHED() << "Got unexpected error code: " << service_worker_status 176 NOTREACHED() << "Got unexpected error code: " << service_worker_status
171 << " " << ServiceWorkerStatusToString(service_worker_status); 177 << " " << ServiceWorkerStatusToString(service_worker_status);
172 delivery_status = PUSH_DELIVERY_STATUS_SERVICE_WORKER_ERROR; 178 delivery_status = PUSH_DELIVERY_STATUS_SERVICE_WORKER_ERROR;
173 break; 179 break;
174 } 180 }
175 RunDeliverCallback(deliver_message_callback, delivery_status); 181 RunDeliverCallback(deliver_message_callback, delivery_status);
176 } 182 }
177 183
178 } // namespace content 184 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698