Index: content/browser/service_worker/service_worker_unregister_job.cc |
diff --git a/content/browser/service_worker/service_worker_unregister_job.cc b/content/browser/service_worker/service_worker_unregister_job.cc |
index 6797b0b5b79a87d8e827f958793185b1a2dc0752..f52c7eabd6481e15e3a1f1c34bfd74ca5e3df22f 100644 |
--- a/content/browser/service_worker/service_worker_unregister_job.cc |
+++ b/content/browser/service_worker/service_worker_unregister_job.cc |
@@ -4,10 +4,13 @@ |
#include "content/browser/service_worker/service_worker_unregister_job.h" |
+#include "base/memory/weak_ptr.h" |
#include "content/browser/service_worker/service_worker_context_core.h" |
#include "content/browser/service_worker/service_worker_job_coordinator.h" |
#include "content/browser/service_worker/service_worker_registration.h" |
#include "content/browser/service_worker/service_worker_storage.h" |
+#include "content/browser/service_worker/service_worker_utils.h" |
+#include "content/browser/service_worker/service_worker_version.h" |
namespace content { |
@@ -18,7 +21,9 @@ ServiceWorkerUnregisterJob::ServiceWorkerUnregisterJob( |
const GURL& pattern) |
: context_(context), |
pattern_(pattern), |
- weak_factory_(this) {} |
+ is_promise_resolved_(false), |
+ weak_factory_(this) { |
+} |
ServiceWorkerUnregisterJob::~ServiceWorkerUnregisterJob() {} |
@@ -62,23 +67,40 @@ void ServiceWorkerUnregisterJob::OnRegistrationFound( |
return; |
} |
- DCHECK(registration); |
- DeleteRegistration(registration); |
-} |
+ if (registration->is_uninstalling()) { |
+ Complete(SERVICE_WORKER_OK); |
+ return; |
+ } |
-void ServiceWorkerUnregisterJob::DeleteRegistration( |
- const scoped_refptr<ServiceWorkerRegistration>& registration) { |
- // TODO: Also doom installing version. |
- if (registration->waiting_version()) |
+ // "6. Set registration.uninstalling to true." |
+ registration->set_uninstalling(true); |
+ |
+ // TODO: "7. If registration.updatePromise is not null..." |
+ |
+ // "8. If registration.installingWorker is not null, then: |
+ if (registration->installing_version()) { |
+ // 1. Terminate registration.installingWorker. |
+ // 2. Run the [[UpdateState]] algorithm passing |
+ // registration.installingWorker and 'redundant' as the arguments. |
+ registration->installing_version()->Doom(); |
+ // 3. Set registration.installingWorker to null. |
+ registration->UnsetVersion(registration->installing_version()); |
+ } |
+ |
+ // "9. If registration.waitingWorker is not null, then: |
+ if (registration->waiting_version()) { |
+ // "1. Run the [[UpdateState]] algorithm passing registration.waitingWorker |
+ // and 'redundant' as the arguments." |
registration->waiting_version()->Doom(); |
- if (registration->active_version()) |
- registration->active_version()->Doom(); |
+ // "2. Set registration.waitingWorker to null." |
+ registration->UnsetVersion(registration->waiting_version()); |
+ } |
- context_->storage()->DeleteRegistration( |
- registration->id(), |
- registration->script_url().GetOrigin(), |
- base::Bind(&ServiceWorkerUnregisterJob::Complete, |
- weak_factory_.GetWeakPtr())); |
+ // "10. Resolve promise." |
+ ResolvePromise(SERVICE_WORKER_OK); |
+ |
+ registration->StartUninstall(); |
+ Complete(SERVICE_WORKER_OK); |
} |
void ServiceWorkerUnregisterJob::Complete(ServiceWorkerStatusCode status) { |
@@ -88,6 +110,14 @@ void ServiceWorkerUnregisterJob::Complete(ServiceWorkerStatusCode status) { |
void ServiceWorkerUnregisterJob::CompleteInternal( |
ServiceWorkerStatusCode status) { |
+ if (!is_promise_resolved_) |
+ ResolvePromise(status); |
+} |
+ |
+void ServiceWorkerUnregisterJob::ResolvePromise( |
+ ServiceWorkerStatusCode status) { |
+ DCHECK(!is_promise_resolved_); |
+ is_promise_resolved_ = true; |
for (std::vector<UnregistrationCallback>::iterator it = callbacks_.begin(); |
it != callbacks_.end(); |
++it) { |