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

Unified Diff: content/renderer/service_worker/service_worker_context_client.cc

Issue 2824193002: Enable use_once_callback for //content/common/*.mojom (Closed)
Patch Set: push_messaging fix Created 3 years, 8 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/renderer/service_worker/service_worker_context_client.cc
diff --git a/content/renderer/service_worker/service_worker_context_client.cc b/content/renderer/service_worker/service_worker_context_client.cc
index dd792b32d59d2b9374983ce4364ff83092949818..b95ed56ad7dc72b68c0f27522057176f32e652fb 100644
--- a/content/renderer/service_worker/service_worker_context_client.cc
+++ b/content/renderer/service_worker/service_worker_context_client.cc
@@ -231,7 +231,8 @@ void ToWebServiceWorkerResponse(const ServiceWorkerResponse& response,
template <typename T>
void AbortPendingEventCallbacks(T& callbacks) {
for (typename T::iterator it(&callbacks); !it.IsAtEnd(); it.Advance()) {
- it.GetCurrentValue()->Run(SERVICE_WORKER_ERROR_ABORT, base::Time::Now());
+ std::move(*it.GetCurrentValue())
+ .Run(SERVICE_WORKER_ERROR_ABORT, base::Time::Now());
}
}
@@ -249,25 +250,25 @@ struct ServiceWorkerContextClient::WorkerContextData {
using SkipWaitingCallbacksMap =
IDMap<std::unique_ptr<blink::WebServiceWorkerSkipWaitingCallbacks>>;
using ActivateEventCallbacksMap =
- IDMap<std::unique_ptr<const DispatchActivateEventCallback>>;
+ IDMap<std::unique_ptr<DispatchActivateEventCallback>>;
using BackgroundFetchAbortEventCallbacksMap =
- IDMap<std::unique_ptr<const DispatchBackgroundFetchAbortEventCallback>>;
+ IDMap<std::unique_ptr<DispatchBackgroundFetchAbortEventCallback>>;
using BackgroundFetchClickEventCallbacksMap =
- IDMap<std::unique_ptr<const DispatchBackgroundFetchClickEventCallback>>;
+ IDMap<std::unique_ptr<DispatchBackgroundFetchClickEventCallback>>;
using BackgroundFetchFailEventCallbacksMap =
- IDMap<std::unique_ptr<const DispatchBackgroundFetchFailEventCallback>>;
+ IDMap<std::unique_ptr<DispatchBackgroundFetchFailEventCallback>>;
using BackgroundFetchedEventCallbacksMap =
- IDMap<std::unique_ptr<const DispatchBackgroundFetchedEventCallback>>;
- using SyncEventCallbacksMap = IDMap<std::unique_ptr<const SyncCallback>>;
+ IDMap<std::unique_ptr<DispatchBackgroundFetchedEventCallback>>;
+ using SyncEventCallbacksMap = IDMap<std::unique_ptr<SyncCallback>>;
using NotificationClickEventCallbacksMap =
- IDMap<std::unique_ptr<const DispatchNotificationClickEventCallback>>;
+ IDMap<std::unique_ptr<DispatchNotificationClickEventCallback>>;
using NotificationCloseEventCallbacksMap =
- IDMap<std::unique_ptr<const DispatchNotificationCloseEventCallback>>;
+ IDMap<std::unique_ptr<DispatchNotificationCloseEventCallback>>;
using PushEventCallbacksMap =
- IDMap<std::unique_ptr<const DispatchPushEventCallback>>;
- using FetchEventCallbacksMap = IDMap<std::unique_ptr<const FetchCallback>>;
+ IDMap<std::unique_ptr<DispatchPushEventCallback>>;
+ using FetchEventCallbacksMap = IDMap<std::unique_ptr<FetchCallback>>;
using ExtendableMessageEventCallbacksMap =
- IDMap<std::unique_ptr<const DispatchExtendableMessageEventCallback>>;
+ IDMap<std::unique_ptr<DispatchExtendableMessageEventCallback>>;
using NavigationPreloadRequestsMap = IDMap<
std::unique_ptr<ServiceWorkerContextClient::NavigationPreloadRequest>>;
@@ -318,8 +319,7 @@ struct ServiceWorkerContextClient::WorkerContextData {
payment_response_callbacks;
// Pending callbacks for Payment Request Events.
- std::map<int /* payment_request_id */,
- const DispatchPaymentRequestEventCallback>
+ std::map<int /* payment_request_id */, DispatchPaymentRequestEventCallback>
payment_request_event_callbacks;
// Pending callbacks for Notification Click Events.
@@ -398,7 +398,7 @@ class ServiceWorkerContextClient::NavigationPreloadRequest final
void OnUploadProgress(int64_t current_position,
int64_t total_size,
- const base::Closure& ack_callback) override {
+ OnUploadProgressCallback ack_callback) override {
NOTREACHED();
}
@@ -795,11 +795,12 @@ void ServiceWorkerContextClient::DidHandleActivateEvent(
int request_id,
blink::WebServiceWorkerEventResult result,
double event_dispatch_time) {
- const DispatchActivateEventCallback* callback =
+ DispatchActivateEventCallback* callback =
context_->activate_event_callbacks.Lookup(request_id);
DCHECK(callback);
- callback->Run(EventResultToStatus(result),
- base::Time::FromDoubleT(event_dispatch_time));
+ DCHECK(*callback);
+ std::move(*callback).Run(EventResultToStatus(result),
+ base::Time::FromDoubleT(event_dispatch_time));
context_->activate_event_callbacks.Remove(request_id);
}
@@ -807,11 +808,12 @@ void ServiceWorkerContextClient::DidHandleBackgroundFetchAbortEvent(
int request_id,
blink::WebServiceWorkerEventResult result,
double event_dispatch_time) {
- const DispatchBackgroundFetchAbortEventCallback* callback =
+ DispatchBackgroundFetchAbortEventCallback* callback =
context_->background_fetch_abort_event_callbacks.Lookup(request_id);
DCHECK(callback);
- callback->Run(EventResultToStatus(result),
- base::Time::FromDoubleT(event_dispatch_time));
+ DCHECK(*callback);
+ std::move(*callback).Run(EventResultToStatus(result),
+ base::Time::FromDoubleT(event_dispatch_time));
context_->background_fetch_abort_event_callbacks.Remove(request_id);
}
@@ -819,11 +821,12 @@ void ServiceWorkerContextClient::DidHandleBackgroundFetchClickEvent(
int request_id,
blink::WebServiceWorkerEventResult result,
double event_dispatch_time) {
- const DispatchBackgroundFetchClickEventCallback* callback =
+ DispatchBackgroundFetchClickEventCallback* callback =
context_->background_fetch_click_event_callbacks.Lookup(request_id);
DCHECK(callback);
- callback->Run(EventResultToStatus(result),
- base::Time::FromDoubleT(event_dispatch_time));
+ DCHECK(*callback);
+ std::move(*callback).Run(EventResultToStatus(result),
+ base::Time::FromDoubleT(event_dispatch_time));
context_->background_fetch_click_event_callbacks.Remove(request_id);
}
@@ -831,11 +834,12 @@ void ServiceWorkerContextClient::DidHandleBackgroundFetchFailEvent(
int request_id,
blink::WebServiceWorkerEventResult result,
double event_dispatch_time) {
- const DispatchBackgroundFetchFailEventCallback* callback =
+ DispatchBackgroundFetchFailEventCallback* callback =
context_->background_fetch_fail_event_callbacks.Lookup(request_id);
DCHECK(callback);
- callback->Run(EventResultToStatus(result),
- base::Time::FromDoubleT(event_dispatch_time));
+ DCHECK(*callback);
+ std::move(*callback).Run(EventResultToStatus(result),
+ base::Time::FromDoubleT(event_dispatch_time));
context_->background_fetch_fail_event_callbacks.Remove(request_id);
}
@@ -843,11 +847,12 @@ void ServiceWorkerContextClient::DidHandleBackgroundFetchedEvent(
int request_id,
blink::WebServiceWorkerEventResult result,
double event_dispatch_time) {
- const DispatchBackgroundFetchedEventCallback* callback =
+ DispatchBackgroundFetchedEventCallback* callback =
context_->background_fetched_event_callbacks.Lookup(request_id);
DCHECK(callback);
- callback->Run(EventResultToStatus(result),
- base::Time::FromDoubleT(event_dispatch_time));
+ DCHECK(*callback);
+ std::move(*callback).Run(EventResultToStatus(result),
+ base::Time::FromDoubleT(event_dispatch_time));
context_->background_fetched_event_callbacks.Remove(request_id);
}
@@ -855,11 +860,12 @@ void ServiceWorkerContextClient::DidHandleExtendableMessageEvent(
int request_id,
blink::WebServiceWorkerEventResult result,
double event_dispatch_time) {
- const DispatchExtendableMessageEventCallback* callback =
+ DispatchExtendableMessageEventCallback* callback =
context_->message_event_callbacks.Lookup(request_id);
DCHECK(callback);
- callback->Run(EventResultToStatus(result),
- base::Time::FromDoubleT(event_dispatch_time));
+ DCHECK(*callback);
+ std::move(*callback).Run(EventResultToStatus(result),
+ base::Time::FromDoubleT(event_dispatch_time));
context_->message_event_callbacks.Remove(request_id);
}
@@ -896,11 +902,12 @@ void ServiceWorkerContextClient::DidHandleFetchEvent(
int fetch_event_id,
blink::WebServiceWorkerEventResult result,
double event_dispatch_time) {
- const FetchCallback* callback =
+ FetchCallback* callback =
context_->fetch_event_callbacks.Lookup(fetch_event_id);
DCHECK(callback);
- callback->Run(EventResultToStatus(result),
- base::Time::FromDoubleT(event_dispatch_time));
+ DCHECK(*callback);
+ std::move(*callback).Run(EventResultToStatus(result),
+ base::Time::FromDoubleT(event_dispatch_time));
context_->fetch_event_callbacks.Remove(fetch_event_id);
}
@@ -908,12 +915,12 @@ void ServiceWorkerContextClient::DidHandleNotificationClickEvent(
int request_id,
blink::WebServiceWorkerEventResult result,
double event_dispatch_time) {
- const DispatchNotificationClickEventCallback* callback =
+ DispatchNotificationClickEventCallback* callback =
context_->notification_click_event_callbacks.Lookup(request_id);
DCHECK(callback);
-
- callback->Run(EventResultToStatus(result),
- base::Time::FromDoubleT(event_dispatch_time));
+ DCHECK(*callback);
+ std::move(*callback).Run(EventResultToStatus(result),
+ base::Time::FromDoubleT(event_dispatch_time));
context_->notification_click_event_callbacks.Remove(request_id);
}
@@ -922,12 +929,12 @@ void ServiceWorkerContextClient::DidHandleNotificationCloseEvent(
int request_id,
blink::WebServiceWorkerEventResult result,
double event_dispatch_time) {
- const DispatchNotificationCloseEventCallback* callback =
+ DispatchNotificationCloseEventCallback* callback =
context_->notification_close_event_callbacks.Lookup(request_id);
DCHECK(callback);
-
- callback->Run(EventResultToStatus(result),
- base::Time::FromDoubleT(event_dispatch_time));
+ DCHECK(*callback);
+ std::move(*callback).Run(EventResultToStatus(result),
+ base::Time::FromDoubleT(event_dispatch_time));
context_->notification_close_event_callbacks.Remove(request_id);
}
@@ -936,11 +943,12 @@ void ServiceWorkerContextClient::DidHandlePushEvent(
int request_id,
blink::WebServiceWorkerEventResult result,
double event_dispatch_time) {
- const DispatchPushEventCallback* callback =
+ DispatchPushEventCallback* callback =
context_->push_event_callbacks.Lookup(request_id);
DCHECK(callback);
- callback->Run(EventResultToStatus(result),
- base::Time::FromDoubleT(event_dispatch_time));
+ DCHECK(*callback);
+ std::move(*callback).Run(EventResultToStatus(result),
+ base::Time::FromDoubleT(event_dispatch_time));
context_->push_event_callbacks.Remove(request_id);
}
@@ -948,11 +956,11 @@ void ServiceWorkerContextClient::DidHandleSyncEvent(
int request_id,
blink::WebServiceWorkerEventResult result,
double event_dispatch_time) {
- const SyncCallback* callback =
- context_->sync_event_callbacks.Lookup(request_id);
+ SyncCallback* callback = context_->sync_event_callbacks.Lookup(request_id);
DCHECK(callback);
- callback->Run(EventResultToStatus(result),
- base::Time::FromDoubleT(event_dispatch_time));
+ DCHECK(*callback);
+ std::move(*callback).Run(EventResultToStatus(result),
+ base::Time::FromDoubleT(event_dispatch_time));
context_->sync_event_callbacks.Remove(request_id);
}
@@ -974,10 +982,10 @@ void ServiceWorkerContextClient::DidHandlePaymentRequestEvent(
int payment_request_id,
blink::WebServiceWorkerEventResult result,
double event_dispatch_time) {
- const DispatchPaymentRequestEventCallback& callback =
- context_->payment_request_event_callbacks[payment_request_id];
- callback.Run(EventResultToStatus(result),
- base::Time::FromDoubleT(event_dispatch_time));
+ DispatchPaymentRequestEventCallback callback =
+ std::move(context_->payment_request_event_callbacks[payment_request_id]);
+ std::move(callback).Run(EventResultToStatus(result),
+ base::Time::FromDoubleT(event_dispatch_time));
context_->payment_request_event_callbacks.erase(payment_request_id);
}
@@ -1064,11 +1072,11 @@ void ServiceWorkerContextClient::RegisterForeignFetchScopes(
void ServiceWorkerContextClient::DispatchSyncEvent(
const std::string& tag,
blink::mojom::BackgroundSyncEventLastChance last_chance,
- const DispatchSyncEventCallback& callback) {
+ DispatchSyncEventCallback callback) {
TRACE_EVENT0("ServiceWorker",
"ServiceWorkerContextClient::DispatchSyncEvent");
int request_id = context_->sync_event_callbacks.Add(
- base::MakeUnique<SyncCallback>(callback));
+ base::MakeUnique<SyncCallback>(std::move(callback)));
// TODO(shimazu): Use typemap when this is moved to blink-side.
blink::WebServiceWorkerContextProxy::LastChanceOption web_last_chance =
@@ -1085,13 +1093,13 @@ void ServiceWorkerContextClient::DispatchPaymentRequestEvent(
int payment_request_id,
payments::mojom::PaymentAppRequestPtr app_request,
payments::mojom::PaymentAppResponseCallbackPtr response_callback,
- const DispatchPaymentRequestEventCallback& callback) {
+ DispatchPaymentRequestEventCallback callback) {
TRACE_EVENT0("ServiceWorker",
"ServiceWorkerContextClient::DispatchPaymentRequestEvent");
context_->payment_response_callbacks.insert(
std::make_pair(payment_request_id, std::move(response_callback)));
context_->payment_request_event_callbacks.insert(
- std::make_pair(payment_request_id, callback));
+ std::make_pair(payment_request_id, std::move(callback)));
blink::WebPaymentAppRequest webAppRequest =
mojo::ConvertTo<blink::WebPaymentAppRequest>(std::move(app_request));
@@ -1128,21 +1136,22 @@ void ServiceWorkerContextClient::SetRegistrationInServiceWorkerGlobalScope(
}
void ServiceWorkerContextClient::DispatchActivateEvent(
- const DispatchActivateEventCallback& callback) {
+ DispatchActivateEventCallback callback) {
TRACE_EVENT0("ServiceWorker",
"ServiceWorkerContextClient::DispatchActivateEvent");
int request_id = context_->activate_event_callbacks.Add(
- base::MakeUnique<DispatchActivateEventCallback>(callback));
+ base::MakeUnique<DispatchActivateEventCallback>(std::move(callback)));
proxy_->DispatchActivateEvent(request_id);
}
void ServiceWorkerContextClient::DispatchBackgroundFetchAbortEvent(
const std::string& tag,
- const DispatchBackgroundFetchAbortEventCallback& callback) {
+ DispatchBackgroundFetchAbortEventCallback callback) {
TRACE_EVENT0("ServiceWorker",
"ServiceWorkerContextClient::DispatchBackgroundFetchAbortEvent");
int request_id = context_->background_fetch_abort_event_callbacks.Add(
- base::MakeUnique<DispatchBackgroundFetchAbortEventCallback>(callback));
+ base::MakeUnique<DispatchBackgroundFetchAbortEventCallback>(
+ std::move(callback)));
proxy_->DispatchBackgroundFetchAbortEvent(request_id,
blink::WebString::FromUTF8(tag));
@@ -1151,11 +1160,12 @@ void ServiceWorkerContextClient::DispatchBackgroundFetchAbortEvent(
void ServiceWorkerContextClient::DispatchBackgroundFetchClickEvent(
const std::string& tag,
mojom::BackgroundFetchState state,
- const DispatchBackgroundFetchClickEventCallback& callback) {
+ DispatchBackgroundFetchClickEventCallback callback) {
TRACE_EVENT0("ServiceWorker",
"ServiceWorkerContextClient::DispatchBackgroundFetchClickEvent");
int request_id = context_->background_fetch_click_event_callbacks.Add(
- base::MakeUnique<DispatchBackgroundFetchClickEventCallback>(callback));
+ base::MakeUnique<DispatchBackgroundFetchClickEventCallback>(
+ std::move(callback)));
// TODO(peter): Use typemap when this is moved to blink-side.
blink::WebServiceWorkerContextProxy::BackgroundFetchState web_state =
@@ -1169,11 +1179,12 @@ void ServiceWorkerContextClient::DispatchBackgroundFetchClickEvent(
void ServiceWorkerContextClient::DispatchBackgroundFetchFailEvent(
const std::string& tag,
const std::vector<BackgroundFetchSettledFetch>& fetches,
- const DispatchBackgroundFetchFailEventCallback& callback) {
+ DispatchBackgroundFetchFailEventCallback callback) {
TRACE_EVENT0("ServiceWorker",
"ServiceWorkerContextClient::DispatchBackgroundFetchFailEvent");
int request_id = context_->background_fetch_fail_event_callbacks.Add(
- base::MakeUnique<DispatchBackgroundFetchFailEventCallback>(callback));
+ base::MakeUnique<DispatchBackgroundFetchFailEventCallback>(
+ std::move(callback)));
blink::WebVector<blink::WebBackgroundFetchSettledFetch> web_fetches(
fetches.size());
@@ -1189,11 +1200,12 @@ void ServiceWorkerContextClient::DispatchBackgroundFetchFailEvent(
void ServiceWorkerContextClient::DispatchBackgroundFetchedEvent(
const std::string& tag,
const std::vector<BackgroundFetchSettledFetch>& fetches,
- const DispatchBackgroundFetchedEventCallback& callback) {
+ DispatchBackgroundFetchedEventCallback callback) {
TRACE_EVENT0("ServiceWorker",
"ServiceWorkerContextClient::DispatchBackgroundFetchedEvent");
int request_id = context_->background_fetched_event_callbacks.Add(
- base::MakeUnique<DispatchBackgroundFetchedEventCallback>(callback));
+ base::MakeUnique<DispatchBackgroundFetchedEventCallback>(
+ std::move(callback)));
blink::WebVector<blink::WebBackgroundFetchSettledFetch> web_fetches(
fetches.size());
@@ -1208,11 +1220,12 @@ void ServiceWorkerContextClient::DispatchBackgroundFetchedEvent(
void ServiceWorkerContextClient::DispatchExtendableMessageEvent(
mojom::ExtendableMessageEventPtr event,
- const DispatchExtendableMessageEventCallback& callback) {
+ DispatchExtendableMessageEventCallback callback) {
TRACE_EVENT0("ServiceWorker",
"ServiceWorkerContextClient::DispatchExtendableMessageEvent");
int request_id = context_->message_event_callbacks.Add(
- base::MakeUnique<DispatchExtendableMessageEventCallback>(callback));
+ base::MakeUnique<DispatchExtendableMessageEventCallback>(
+ std::move(callback)));
blink::WebMessagePortChannelArray ports =
WebMessagePortChannelImpl::CreateFromMessagePipeHandles(
@@ -1251,7 +1264,7 @@ void ServiceWorkerContextClient::DispatchFetchEvent(
int fetch_event_id,
const ServiceWorkerFetchRequest& request,
mojom::FetchEventPreloadHandlePtr preload_handle,
- const DispatchFetchEventCallback& callback) {
+ DispatchFetchEventCallback callback) {
std::unique_ptr<NavigationPreloadRequest> preload_request =
preload_handle
? base::MakeUnique<NavigationPreloadRequest>(
@@ -1261,7 +1274,7 @@ void ServiceWorkerContextClient::DispatchFetchEvent(
TRACE_EVENT0("ServiceWorker",
"ServiceWorkerContextClient::DispatchFetchEvent");
context_->fetch_event_callbacks.AddWithID(
- base::MakeUnique<FetchCallback>(callback), fetch_event_id);
+ base::MakeUnique<FetchCallback>(std::move(callback)), fetch_event_id);
if (preload_request) {
context_->preload_requests.AddWithID(std::move(preload_request),
fetch_event_id);
@@ -1283,12 +1296,13 @@ void ServiceWorkerContextClient::DispatchNotificationClickEvent(
const PlatformNotificationData& notification_data,
int action_index,
const base::Optional<base::string16>& reply,
- const DispatchNotificationClickEventCallback& callback) {
+ DispatchNotificationClickEventCallback callback) {
TRACE_EVENT0("ServiceWorker",
"ServiceWorkerContextClient::DispatchNotificationClickEvent");
int request_id = context_->notification_click_event_callbacks.Add(
- base::MakeUnique<DispatchNotificationClickEventCallback>(callback));
+ base::MakeUnique<DispatchNotificationClickEventCallback>(
+ std::move(callback)));
blink::WebString web_reply;
if (reply)
@@ -1302,12 +1316,13 @@ void ServiceWorkerContextClient::DispatchNotificationClickEvent(
void ServiceWorkerContextClient::DispatchNotificationCloseEvent(
const std::string& notification_id,
const PlatformNotificationData& notification_data,
- const DispatchNotificationCloseEventCallback& callback) {
+ DispatchNotificationCloseEventCallback callback) {
TRACE_EVENT0("ServiceWorker",
"ServiceWorkerContextClient::DispatchNotificationCloseEvent");
int request_id = context_->notification_close_event_callbacks.Add(
- base::MakeUnique<DispatchNotificationCloseEventCallback>(callback));
+ base::MakeUnique<DispatchNotificationCloseEventCallback>(
+ std::move(callback)));
proxy_->DispatchNotificationCloseEvent(
request_id, blink::WebString::FromUTF8(notification_id),
@@ -1316,11 +1331,11 @@ void ServiceWorkerContextClient::DispatchNotificationCloseEvent(
void ServiceWorkerContextClient::DispatchPushEvent(
const PushEventPayload& payload,
- const DispatchPushEventCallback& callback) {
+ DispatchPushEventCallback callback) {
TRACE_EVENT0("ServiceWorker",
"ServiceWorkerContextClient::DispatchPushEvent");
int request_id = context_->push_event_callbacks.Add(
- base::MakeUnique<DispatchPushEventCallback>(callback));
+ base::MakeUnique<DispatchPushEventCallback>(std::move(callback)));
// Only set data to be a valid string if the payload had decrypted data.
blink::WebString data;
@@ -1513,8 +1528,8 @@ void ServiceWorkerContextClient::OnClaimClientsError(
context_->claim_clients_callbacks.Remove(request_id);
}
-void ServiceWorkerContextClient::Ping(const PingCallback& callback) {
- callback.Run();
+void ServiceWorkerContextClient::Ping(PingCallback callback) {
+ std::move(callback).Run();
}
void ServiceWorkerContextClient::OnNavigationPreloadResponse(

Powered by Google App Engine
This is Rietveld 408576698