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

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

Issue 1579413004: Move push event dispatching out of ServiceWorkerVersion. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Have a simplified combined StartRequest/DispatchEvent/FinishRequest method 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.h
diff --git a/content/browser/service_worker/service_worker_version.h b/content/browser/service_worker/service_worker_version.h
index 2b7009d48d6e57f74dcb814e85136822c1270c88..6372237a1bd0748d3eae3c3ac9871b950ac5cc86 100644
--- a/content/browser/service_worker/service_worker_version.h
+++ b/content/browser/service_worker/service_worker_version.h
@@ -226,6 +226,17 @@ class CONTENT_EXPORT ServiceWorkerVersion
const IPC::Message& message,
const ResponseCallbackType& callback);
+ // Combines StartRequest and DispatchEvent, and automatically calls
+ // FinishRequest before passing a response to the response callback.
+ // ResponseMessage must have a int request_id and
+ // blink::WebServiceWorkerEventResult.
+ template <typename EventMessage,
+ typename ResponseMessage,
+ typename... EventArgs>
+ int DispatchSimpleEvent(ServiceWorkerMetrics::EventType event_type,
+ const StatusCallback& callback,
+ EventArgs... event_args);
+
// Sends a message event to the associated embedded worker.
void DispatchMessageEvent(
const base::string16& message,
@@ -272,14 +283,6 @@ class CONTENT_EXPORT ServiceWorkerVersion
const PlatformNotificationData& notification_data,
int action_index);
- // Sends push event to the associated embedded worker and asynchronously calls
- // |callback| when it errors out or it gets a response from the worker to
- // notify completion.
- //
- // This must be called when the status() is ACTIVATED.
- void DispatchPushEvent(const StatusCallback& callback,
- const std::string& data);
-
// Sends a cross origin message event to the associated embedded worker and
// asynchronously calls |callback| when the message was sent (or failed to
// sent).
@@ -406,7 +409,6 @@ class CONTENT_EXPORT ServiceWorkerVersion
REQUEST_INSTALL,
REQUEST_FETCH,
REQUEST_NOTIFICATION_CLICK,
- REQUEST_PUSH,
REQUEST_CUSTOM,
NUM_REQUEST_TYPES
};
@@ -568,8 +570,6 @@ class CONTENT_EXPORT ServiceWorkerVersion
ServiceWorkerFetchEventResult result,
const ServiceWorkerResponse& response);
void OnNotificationClickEventFinished(int request_id);
- void OnPushEventFinished(int request_id,
- blink::WebServiceWorkerEventResult result);
void OnOpenWindow(int request_id, GURL url);
void OnOpenWindowFinished(int request_id,
ServiceWorkerStatusCode status,
@@ -679,6 +679,19 @@ class CONTENT_EXPORT ServiceWorkerVersion
// event ended).
void OnBeginEvent();
+ void ResponseCallbackWrapper(const StatusCallback& callback,
+ int request_id,
+ blink::WebServiceWorkerEventResult result) {
+ // TODO(mek): trace?
+ if (!FinishRequest(request_id))
+ NOTREACHED() << "Should only receive one reply per event";
+
+ ServiceWorkerStatusCode status = SERVICE_WORKER_OK;
+ if (result == blink::WebServiceWorkerEventResultRejected)
+ status = SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED;
+ callback.Run(status);
+ }
+
const int64_t version_id_;
const int64_t registration_id_;
const GURL script_url_;
@@ -698,7 +711,6 @@ class CONTENT_EXPORT ServiceWorkerVersion
IDMap<PendingRequest<FetchCallback>, IDMapOwnPointer> fetch_requests_;
IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer>
notification_click_requests_;
- IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> push_requests_;
IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> custom_requests_;
// Stores all open connections to mojo services. Maps the service name to
@@ -810,6 +822,21 @@ void ServiceWorkerVersion::DispatchEvent(int request_id,
}
}
+template <typename EventMessage,
+ typename ResponseMessage,
+ typename... EventArgs>
+int ServiceWorkerVersion::DispatchSimpleEvent(
+ ServiceWorkerMetrics::EventType event_type,
+ const StatusCallback& callback,
+ EventArgs... event_args) {
+ int request_id = StartRequest(event_type, callback);
+ DispatchEvent<ResponseMessage>(
+ request_id, EventMessage(request_id, event_args...),
+ base::Bind(&ServiceWorkerVersion::ResponseCallbackWrapper, this,
+ callback));
+ return request_id;
+}
+
template <typename ResponseMessage, typename CallbackType>
bool ServiceWorkerVersion::EventResponseHandler<ResponseMessage, CallbackType>::
OnMessageReceived(const IPC::Message& message) {
@@ -820,6 +847,7 @@ bool ServiceWorkerVersion::EventResponseHandler<ResponseMessage, CallbackType>::
if (!result || received_request_id != request_id_)
return false;
+ CallbackType protect(callback_);
// Essentially same code as what IPC_MESSAGE_FORWARD expands to.
void* param = nullptr;
if (!ResponseMessage::Dispatch(&message, &callback_, this, param,

Powered by Google App Engine
This is Rietveld 408576698