| Index: content/browser/service_worker/service_worker_registration.cc
|
| diff --git a/content/browser/service_worker/service_worker_registration.cc b/content/browser/service_worker/service_worker_registration.cc
|
| index cfd1e5e6e0d9554e6d069da150e3b52d4c66c3bd..64aba5869f0024fc4314cdf04caf3a4e94f402f4 100644
|
| --- a/content/browser/service_worker/service_worker_registration.cc
|
| +++ b/content/browser/service_worker/service_worker_registration.cc
|
| @@ -182,11 +182,8 @@ void ServiceWorkerRegistration::UnsetVersionInternal(
|
| void ServiceWorkerRegistration::ActivateWaitingVersionWhenReady() {
|
| DCHECK(waiting_version());
|
| should_activate_when_ready_ = true;
|
| -
|
| - if (!active_version() || !active_version()->HasControllee() ||
|
| - waiting_version()->skip_waiting()) {
|
| + if (IsReadyToActivate())
|
| ActivateWaitingVersion(false);
|
| - }
|
| }
|
|
|
| void ServiceWorkerRegistration::ClaimClients() {
|
| @@ -253,8 +250,27 @@ void ServiceWorkerRegistration::OnNoControllees(ServiceWorkerVersion* version) {
|
| DCHECK_EQ(active_version(), version);
|
| if (is_uninstalling_)
|
| Clear();
|
| - else if (should_activate_when_ready_)
|
| - ActivateWaitingVersion(true);
|
| + else if (IsReadyToActivate())
|
| + ActivateWaitingVersion(true /* delay */);
|
| +}
|
| +
|
| +void ServiceWorkerRegistration::OnNoInflightRequests(
|
| + ServiceWorkerVersion* version) {
|
| + if (!context_)
|
| + return;
|
| + DCHECK_EQ(active_version(), version);
|
| + if (IsReadyToActivate())
|
| + ActivateWaitingVersion(false /* delay */);
|
| +}
|
| +
|
| +bool ServiceWorkerRegistration::IsReadyToActivate() const {
|
| + if (!should_activate_when_ready_)
|
| + return false;
|
| +
|
| + const ServiceWorkerVersion* active = active_version();
|
| + return !(active &&
|
| + (active->HasInflightRequests() ||
|
| + (active->HasControllee() && !waiting_version()->skip_waiting())));
|
| }
|
|
|
| void ServiceWorkerRegistration::ActivateWaitingVersion(bool delay) {
|
| @@ -271,8 +287,11 @@ void ServiceWorkerRegistration::ActivateWaitingVersion(bool delay) {
|
|
|
| // "5. If exitingWorker is not null,
|
| if (exiting_version.get()) {
|
| - // TODO(michaeln): should wait for events to be complete
|
| + // TODO(falken): Update the quoted spec comments once
|
| + // https://github.com/slightlyoff/ServiceWorker/issues/916 is codified in
|
| + // the spec.
|
| // "1. Wait for exitingWorker to finish handling any in-progress requests."
|
| + // This is already handled by IsReadyToActivate().
|
| // "2. Terminate exitingWorker."
|
| exiting_version->StopWorker(
|
| base::Bind(&ServiceWorkerUtils::NoOpStatusCallback));
|
|
|