| Index: content/browser/service_worker/service_worker_version.cc
|
| diff --git a/content/browser/service_worker/service_worker_version.cc b/content/browser/service_worker/service_worker_version.cc
|
| index b77ba3b06ec0ab61b2ac67e528e0bd38e8612d57..a553f893a5a786312ed2a2b4b37bb2a2f9118007 100644
|
| --- a/content/browser/service_worker/service_worker_version.cc
|
| +++ b/content/browser/service_worker/service_worker_version.cc
|
| @@ -656,6 +656,34 @@ void ServiceWorkerVersion::DispatchNotificationClickEvent(
|
| }
|
| }
|
|
|
| +void ServiceWorkerVersion::DispatchNotificationCloseEvent(
|
| + const StatusCallback& callback,
|
| + int64_t persistent_notification_id,
|
| + const PlatformNotificationData& notification_data) {
|
| + OnBeginEvent();
|
| + DCHECK_EQ(ACTIVATED, status()) << status();
|
| + if (running_status() != RUNNING) {
|
| + // Schedule calling this method after starting the worker.
|
| + StartWorker(base::Bind(
|
| + &RunTaskAfterStartWorker, weak_factory_.GetWeakPtr(), callback,
|
| + base::Bind(&self::DispatchNotificationCloseEvent,
|
| + weak_factory_.GetWeakPtr(), callback,
|
| + persistent_notification_id, notification_data)));
|
| + return;
|
| + }
|
| +
|
| + int request_id = AddRequest(
|
| + callback, ¬ification_close_requests_, REQUEST_NOTIFICATION_CLOSE,
|
| + ServiceWorkerMetrics::EventType::NOTIFICATION_CLOSE);
|
| + ServiceWorkerStatusCode status =
|
| + embedded_worker_->SendMessage(ServiceWorkerMsg_NotificationCloseEvent(
|
| + request_id, persistent_notification_id, notification_data));
|
| + if (status != SERVICE_WORKER_OK) {
|
| + notification_close_requests_.Remove(request_id);
|
| + RunSoon(base::Bind(callback, status));
|
| + }
|
| +}
|
| +
|
| void ServiceWorkerVersion::DispatchPushEvent(const StatusCallback& callback,
|
| const std::string& data) {
|
| OnBeginEvent();
|
| @@ -986,6 +1014,8 @@ bool ServiceWorkerVersion::OnMessageReceived(const IPC::Message& message) {
|
| OnNotificationClickEventFinished)
|
| IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PushEventFinished,
|
| OnPushEventFinished)
|
| + IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_NotificationCloseEventFinished,
|
| + OnNotificationCloseEventFinished)
|
| IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_OpenWindow,
|
| OnOpenWindow)
|
| IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SetCachedMetadata,
|
| @@ -1198,6 +1228,25 @@ void ServiceWorkerVersion::OnPushEventFinished(
|
| RemoveCallbackAndStopIfRedundant(&push_requests_, request_id);
|
| }
|
|
|
| +void ServiceWorkerVersion::OnNotificationCloseEventFinished(int request_id) {
|
| + TRACE_EVENT1("ServiceWorker",
|
| + "ServiceWorkerVersion::OnNotificationCloseEventFinished",
|
| + "Request id", request_id);
|
| + PendingRequest<StatusCallback>* request =
|
| + notification_close_requests_.Lookup(request_id);
|
| + if (!request) {
|
| + NOTREACHED() << "Got unexpected message: " << request_id;
|
| + return;
|
| + }
|
| +
|
| + ServiceWorkerMetrics::RecordEventDuration(
|
| + request->event_type, base::TimeTicks::Now() - request->start_time);
|
| +
|
| + scoped_refptr<ServiceWorkerVersion> protect(this);
|
| + request->callback.Run(SERVICE_WORKER_OK);
|
| + RemoveCallbackAndStopIfRedundant(¬ification_close_requests_, request_id);
|
| +}
|
| +
|
| void ServiceWorkerVersion::OnOpenWindow(int request_id, GURL url) {
|
| // Just abort if we are shutting down.
|
| if (!context_)
|
| @@ -1734,6 +1783,7 @@ bool ServiceWorkerVersion::HasInflightRequests() const {
|
| return !activate_requests_.IsEmpty() || !install_requests_.IsEmpty() ||
|
| !fetch_requests_.IsEmpty() ||
|
| !notification_click_requests_.IsEmpty() || !push_requests_.IsEmpty() ||
|
| + !notification_close_requests_.IsEmpty() ||
|
| !custom_requests_.IsEmpty() || !streaming_url_request_jobs_.empty();
|
| }
|
|
|
| @@ -1831,6 +1881,9 @@ bool ServiceWorkerVersion::MaybeTimeOutRequest(const RequestInfo& info) {
|
| case REQUEST_NOTIFICATION_CLICK:
|
| return RunIDMapCallback(¬ification_click_requests_, info.id,
|
| SERVICE_WORKER_ERROR_TIMEOUT);
|
| + case REQUEST_NOTIFICATION_CLOSE:
|
| + return RunIDMapCallback(¬ification_close_requests_, info.id,
|
| + SERVICE_WORKER_ERROR_TIMEOUT);
|
| case REQUEST_PUSH:
|
| return RunIDMapCallback(&push_requests_, info.id,
|
| SERVICE_WORKER_ERROR_TIMEOUT);
|
|
|