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

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

Issue 1799413002: ServiceWorker: Release a reference when it fails to dispatch ExtendableMessageEvent (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@move_dispatch_extendable_message_event
Patch Set: fix build failures Created 4 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
Index: content/browser/service_worker/service_worker_dispatcher_host.cc
diff --git a/content/browser/service_worker/service_worker_dispatcher_host.cc b/content/browser/service_worker/service_worker_dispatcher_host.cc
index d75ab4a7f43c96132b6cb4654468c9d8f916b183..ac43969dad588784ca19462889775a473e6d6e77 100644
--- a/content/browser/service_worker/service_worker_dispatcher_host.cc
+++ b/content/browser/service_worker/service_worker_dispatcher_host.cc
@@ -701,6 +701,19 @@ void ServiceWorkerDispatcherHost::OnPostMessageToWorker(
return;
}
+ DispatchExtendableMessageEvent(
+ make_scoped_refptr(handle->version()), message, source_origin,
+ sent_message_ports, sender_provider_host,
+ base::Bind(&ServiceWorkerUtils::NoOpStatusCallback));
+}
+
+void ServiceWorkerDispatcherHost::DispatchExtendableMessageEvent(
+ scoped_refptr<ServiceWorkerVersion> worker,
+ const base::string16& message,
+ const url::Origin& source_origin,
+ const std::vector<TransferredMessagePort>& sent_message_ports,
+ ServiceWorkerProviderHost* sender_provider_host,
+ const StatusCallback& callback) {
for (const TransferredMessagePort& port : sent_message_ports)
MessagePortService::GetInstance()->HoldMessages(port.id);
@@ -710,20 +723,17 @@ void ServiceWorkerDispatcherHost::OnPostMessageToWorker(
case SERVICE_WORKER_PROVIDER_FOR_SHARED_WORKER:
service_worker_client_utils::GetClient(
sender_provider_host,
- base::Bind(
- &ServiceWorkerDispatcherHost::DispatchExtendableMessageEvent<
- ServiceWorkerClientInfo>,
- this, make_scoped_refptr(handle->version()), message,
- source_origin, sent_message_ports));
+ base::Bind(&ServiceWorkerDispatcherHost::
+ DispatchExtendableMessageEventInternal<
+ ServiceWorkerClientInfo>,
+ this, worker, message, source_origin, sent_message_ports,
+ callback));
break;
case SERVICE_WORKER_PROVIDER_FOR_CONTROLLER:
- // TODO(nhiroki): Decrement a reference to ServiceWorkerHandle if starting
- // worker fails (http://crbug.com/543198).
RunSoon(base::Bind(
- &ServiceWorkerDispatcherHost::DispatchExtendableMessageEvent<
+ &ServiceWorkerDispatcherHost::DispatchExtendableMessageEventInternal<
ServiceWorkerObjectInfo>,
- this, make_scoped_refptr(handle->version()), message, source_origin,
- sent_message_ports,
+ this, worker, message, source_origin, sent_message_ports, callback,
sender_provider_host->GetOrCreateServiceWorkerHandle(
sender_provider_host->running_hosted_version())));
break;
@@ -866,15 +876,16 @@ void ServiceWorkerDispatcherHost::OnSetHostedVersionId(int provider_id,
}
template <typename SourceInfo>
-void ServiceWorkerDispatcherHost::DispatchExtendableMessageEvent(
+void ServiceWorkerDispatcherHost::DispatchExtendableMessageEventInternal(
scoped_refptr<ServiceWorkerVersion> worker,
const base::string16& message,
const url::Origin& source_origin,
const std::vector<TransferredMessagePort>& sent_message_ports,
+ const StatusCallback& callback,
const SourceInfo& source_info) {
if (!source_info.IsValid()) {
- DidFailToDispatchExtendableMessageEvent(sent_message_ports,
- SERVICE_WORKER_ERROR_FAILED);
+ DidFailToDispatchExtendableMessageEvent<SourceInfo>(
+ sent_message_ports, source_info, callback, SERVICE_WORKER_ERROR_FAILED);
return;
}
worker->RunAfterStartWorker(
@@ -882,10 +893,11 @@ void ServiceWorkerDispatcherHost::DispatchExtendableMessageEvent(
base::Bind(&ServiceWorkerDispatcherHost::
DispatchExtendableMessageEventAfterStartWorker,
this, worker, message, source_origin, sent_message_ports,
- ExtendableMessageEventSource(source_info)),
+ ExtendableMessageEventSource(source_info), callback),
base::Bind(
- &ServiceWorkerDispatcherHost::DidFailToDispatchExtendableMessageEvent,
- this, sent_message_ports));
+ &ServiceWorkerDispatcherHost::DidFailToDispatchExtendableMessageEvent<
+ SourceInfo>,
+ this, sent_message_ports, source_info, callback));
}
void ServiceWorkerDispatcherHost::
@@ -894,10 +906,10 @@ void ServiceWorkerDispatcherHost::
const base::string16& message,
const url::Origin& source_origin,
const std::vector<TransferredMessagePort>& sent_message_ports,
- const ExtendableMessageEventSource& source) {
+ const ExtendableMessageEventSource& source,
+ const StatusCallback& callback) {
int request_id =
- worker->StartRequest(ServiceWorkerMetrics::EventType::MESSAGE,
- base::Bind(&ServiceWorkerUtils::NoOpStatusCallback));
+ worker->StartRequest(ServiceWorkerMetrics::EventType::MESSAGE, callback);
MessagePortMessageFilter* filter =
worker->embedded_worker()->message_port_message_filter();
@@ -924,12 +936,33 @@ void ServiceWorkerDispatcherHost::
request_id, ServiceWorkerMsg_ExtendableMessageEvent(request_id, params));
}
+template <typename SourceInfo>
void ServiceWorkerDispatcherHost::DidFailToDispatchExtendableMessageEvent(
const std::vector<TransferredMessagePort>& sent_message_ports,
+ const SourceInfo& source_info,
+ const StatusCallback& callback,
ServiceWorkerStatusCode status) {
// Transfering the message ports failed, so destroy the ports.
for (const TransferredMessagePort& port : sent_message_ports)
MessagePortService::GetInstance()->ClosePort(port.id);
+ if (source_info.IsValid())
+ ReleaseSourceInfo(source_info);
+ callback.Run(status);
+}
+
+void ServiceWorkerDispatcherHost::ReleaseSourceInfo(
+ const ServiceWorkerClientInfo& source_info) {
+ // ServiceWorkerClientInfo is just a snapshot of the client. There is no need
+ // to do anything for it.
+}
+
+void ServiceWorkerDispatcherHost::ReleaseSourceInfo(
+ const ServiceWorkerObjectInfo& source_info) {
+ ServiceWorkerHandle* handle = handles_.Lookup(source_info.handle_id);
+ DCHECK(handle);
+ handle->DecrementRefCount();
+ if (handle->HasNoRefCount())
+ handles_.Remove(source_info.handle_id);
}
ServiceWorkerRegistrationHandle*

Powered by Google App Engine
This is Rietveld 408576698