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 bd34fabf1b4cd971d3d2c844db7ea84a57845de2..8f5146c09cd9d44f17a9e1c1ed65c5f9c9491f19 100644 |
--- a/content/browser/service_worker/service_worker_dispatcher_host.cc |
+++ b/content/browser/service_worker/service_worker_dispatcher_host.cc |
@@ -921,16 +921,20 @@ void ServiceWorkerDispatcherHost::DispatchExtendableMessageEvent( |
DispatchExtendableMessageEventInternal< |
ServiceWorkerClientInfo>, |
this, worker, message, source_origin, sent_message_ports, |
- callback)); |
+ callback, base::nullopt)); |
break; |
- case SERVICE_WORKER_PROVIDER_FOR_CONTROLLER: |
+ case SERVICE_WORKER_PROVIDER_FOR_CONTROLLER: { |
falken
2016/11/21 08:01:48
nit: maybe add some comment like "Clamp timeout to
Marijn Kruisselbrink
2016/12/01 19:54:30
Done
|
+ base::TimeDelta timeout = |
+ sender_provider_host->running_hosted_version()->remaining_timeout(); |
RunSoon(base::Bind( |
&ServiceWorkerDispatcherHost::DispatchExtendableMessageEventInternal< |
ServiceWorkerObjectInfo>, |
this, worker, message, source_origin, sent_message_ports, callback, |
+ base::make_optional(timeout), |
sender_provider_host->GetOrCreateServiceWorkerHandle( |
sender_provider_host->running_hosted_version()))); |
break; |
+ } |
case SERVICE_WORKER_PROVIDER_UNKNOWN: |
default: |
NOTREACHED() << sender_provider_host->provider_type(); |
@@ -1085,18 +1089,28 @@ void ServiceWorkerDispatcherHost::DispatchExtendableMessageEventInternal( |
const url::Origin& source_origin, |
const std::vector<int>& sent_message_ports, |
const StatusCallback& callback, |
+ const base::Optional<base::TimeDelta>& timeout, |
const SourceInfo& source_info) { |
if (!source_info.IsValid()) { |
DidFailToDispatchExtendableMessageEvent<SourceInfo>( |
sent_message_ports, source_info, callback, SERVICE_WORKER_ERROR_FAILED); |
return; |
} |
+ |
+ // If not enough time is left to actually process the event don't even |
+ // bother starting the worker and sending the event. |
+ if (timeout && *timeout < base::TimeDelta::FromMilliseconds(100)) { |
+ DidFailToDispatchExtendableMessageEvent<SourceInfo>( |
+ sent_message_ports, source_info, callback, SERVICE_WORKER_ERROR_FAILED); |
falken
2016/11/21 08:01:48
Hm, TIMEOUT seems like a better error code here, s
Marijn Kruisselbrink
2016/12/01 19:54:29
Good point, done.
|
+ return; |
+ } |
+ |
worker->RunAfterStartWorker( |
ServiceWorkerMetrics::EventType::MESSAGE, |
base::Bind(&ServiceWorkerDispatcherHost:: |
DispatchExtendableMessageEventAfterStartWorker, |
this, worker, message, source_origin, sent_message_ports, |
- ExtendableMessageEventSource(source_info), callback), |
+ ExtendableMessageEventSource(source_info), timeout, callback), |
base::Bind( |
&ServiceWorkerDispatcherHost::DidFailToDispatchExtendableMessageEvent< |
SourceInfo>, |
@@ -1110,9 +1124,17 @@ void ServiceWorkerDispatcherHost:: |
const url::Origin& source_origin, |
const std::vector<int>& sent_message_ports, |
const ExtendableMessageEventSource& source, |
+ const base::Optional<base::TimeDelta>& timeout, |
const StatusCallback& callback) { |
- int request_id = |
- worker->StartRequest(ServiceWorkerMetrics::EventType::MESSAGE, callback); |
+ int request_id; |
+ if (timeout) { |
+ request_id = worker->StartRequestWithCustomTimeout( |
+ ServiceWorkerMetrics::EventType::MESSAGE, callback, *timeout, |
+ ServiceWorkerVersion::CONTINUE_ON_TIMEOUT); |
+ } else { |
+ request_id = worker->StartRequest(ServiceWorkerMetrics::EventType::MESSAGE, |
+ callback); |
+ } |
MessagePortMessageFilter* filter = |
worker->embedded_worker()->message_port_message_filter(); |