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

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: 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 4dd4cb348ee776748791e255cadf972d3bea5f09..1d9d9ecd2a1bb6ef0994f976ca22028563a0da36 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,25 +876,27 @@ 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(
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::
@@ -893,10 +905,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();
@@ -923,12 +935,35 @@ 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);
+ callback.Run(status);
+}
+
+template <>
void ServiceWorkerDispatcherHost::DidFailToDispatchExtendableMessageEvent(
falken 2016/03/17 05:10:49 I'm kind of confused why there are two ServiceWork
nhiroki 2016/03/17 06:05:30 "typename SourceInfo" is resolved to ServiceWorker
nhiroki 2016/03/17 06:33:28 FYI: I tried to use overloaded functions instead o
const std::vector<TransferredMessagePort>& sent_message_ports,
+ const ServiceWorkerObjectInfo& 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()) {
+ ServiceWorkerHandle* handle = handles_.Lookup(source_info.handle_id);
+ DCHECK(handle);
+ handle->DecrementRefCount();
+ if (handle->HasNoRefCount())
+ handles_.Remove(source_info.handle_id);
+ }
+ callback.Run(status);
}
ServiceWorkerRegistrationHandle*

Powered by Google App Engine
This is Rietveld 408576698