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

Unified Diff: content/browser/service_worker/service_worker_version.cc

Issue 1619703002: Implement notificationclose event (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments 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 side-by-side diff with in-line comments
Download patch
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 25d33fa5194e9e5df0e1746007e83fabbfb584e9..394fe979fea242d8c78f4f0641727b4887e1cdfe 100644
--- a/content/browser/service_worker/service_worker_version.cc
+++ b/content/browser/service_worker/service_worker_version.cc
@@ -681,6 +681,34 @@ void ServiceWorkerVersion::DispatchNotificationClickEvent(
}
}
+void ServiceWorkerVersion::DispatchNotificationCloseEvent(
Peter Beverloo 2016/01/26 16:13:45 (I'm not really looking at this bit because Marijn
Nina 2016/01/27 18:48:58 Acknowledged.
+ 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, &notification_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();
@@ -1016,6 +1044,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,
@@ -1228,6 +1258,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(&notification_close_requests_, request_id);
+}
+
void ServiceWorkerVersion::OnOpenWindow(int request_id, GURL url) {
// Just abort if we are shutting down.
if (!context_)
@@ -1764,6 +1813,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();
}
@@ -1864,6 +1914,9 @@ bool ServiceWorkerVersion::MaybeTimeOutRequest(const RequestInfo& info) {
case REQUEST_NOTIFICATION_CLICK:
return RunIDMapCallback(&notification_click_requests_, info.id,
SERVICE_WORKER_ERROR_TIMEOUT);
+ case REQUEST_NOTIFICATION_CLOSE:
+ return RunIDMapCallback(&notification_close_requests_, info.id,
+ SERVICE_WORKER_ERROR_TIMEOUT);
case REQUEST_PUSH:
return RunIDMapCallback(&push_requests_, info.id,
SERVICE_WORKER_ERROR_TIMEOUT);

Powered by Google App Engine
This is Rietveld 408576698