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

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

Issue 2756723003: Avoid using the method pointer to Callback::Run in ServiceWorkerVersion (Closed)
Patch Set: rebase Created 3 years, 9 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 8e2b42104c655f7928c825f52aa1059c31fd9fe6..66516d17981a8071134e2deb87865f40c7a594b1 100644
--- a/content/browser/service_worker/service_worker_version.h
+++ b/content/browser/service_worker/service_worker_version.h
@@ -571,8 +571,14 @@ class CONTENT_EXPORT ServiceWorkerVersion
// with same arguments as the IPC message.
// Additionally only calls the callback for messages with a specific request
// id, which must be the first argument of the IPC message.
- template <typename ResponseMessage, typename CallbackType>
- class EventResponseHandler : public EmbeddedWorkerInstance::Listener {
+ template <typename ResponseMessage,
+ typename CallbackType,
+ typename Signature = typename CallbackType::RunType>
+ class EventResponseHandler;
+
+ template <typename ResponseMessage, typename CallbackType, typename... Args>
+ class EventResponseHandler<ResponseMessage, CallbackType, void(Args...)>
+ : public EmbeddedWorkerInstance::Listener {
public:
EventResponseHandler(const base::WeakPtr<EmbeddedWorkerInstance>& worker,
int request_id,
@@ -587,6 +593,10 @@ class CONTENT_EXPORT ServiceWorkerVersion
bool OnMessageReceived(const IPC::Message& message) override;
private:
+ void RunCallback(Args... args) {
+ callback_.Run(std::forward<Args>(args)...);
+ }
+
base::WeakPtr<EmbeddedWorkerInstance> const worker_;
const int request_id_;
const CallbackType callback_;
@@ -895,9 +905,11 @@ void ServiceWorkerVersion::RegisterSimpleRequest(int request_id) {
base::Bind(&ServiceWorkerVersion::OnSimpleEventResponse, this));
}
-template <typename ResponseMessage, typename CallbackType>
-bool ServiceWorkerVersion::EventResponseHandler<ResponseMessage, CallbackType>::
- OnMessageReceived(const IPC::Message& message) {
+template <typename ResponseMessage, typename CallbackType, typename... Args>
+bool ServiceWorkerVersion::EventResponseHandler<
+ ResponseMessage,
+ CallbackType,
+ void(Args...)>::OnMessageReceived(const IPC::Message& message) {
if (message.type() != ResponseMessage::ID)
return false;
int received_request_id;
@@ -908,8 +920,8 @@ bool ServiceWorkerVersion::EventResponseHandler<ResponseMessage, CallbackType>::
CallbackType protect(callback_);
// Essentially same code as what IPC_MESSAGE_FORWARD expands to.
void* param = nullptr;
- if (!ResponseMessage::Dispatch(&message, &callback_, this, param,
- &CallbackType::Run))
+ if (!ResponseMessage::Dispatch(&message, this, this, param,
+ &EventResponseHandler::RunCallback))
message.set_dispatch_error();
// At this point |this| can have been deleted, so don't do anything other
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698