| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/service_worker/service_worker_unregister_job.h" | 5 #include "content/browser/service_worker/service_worker_unregister_job.h" |
| 6 | 6 |
| 7 #include "base/memory/weak_ptr.h" | 7 #include "base/memory/weak_ptr.h" |
| 8 #include "content/browser/service_worker/service_worker_context_core.h" | 8 #include "content/browser/service_worker/service_worker_context_core.h" |
| 9 #include "content/browser/service_worker/service_worker_job_coordinator.h" | 9 #include "content/browser/service_worker/service_worker_job_coordinator.h" |
| 10 #include "content/browser/service_worker/service_worker_registration.h" | 10 #include "content/browser/service_worker/service_worker_registration.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 } | 33 } |
| 34 | 34 |
| 35 void ServiceWorkerUnregisterJob::Start() { | 35 void ServiceWorkerUnregisterJob::Start() { |
| 36 context_->storage()->FindRegistrationForPattern( | 36 context_->storage()->FindRegistrationForPattern( |
| 37 pattern_, | 37 pattern_, |
| 38 base::Bind(&ServiceWorkerUnregisterJob::OnRegistrationFound, | 38 base::Bind(&ServiceWorkerUnregisterJob::OnRegistrationFound, |
| 39 weak_factory_.GetWeakPtr())); | 39 weak_factory_.GetWeakPtr())); |
| 40 } | 40 } |
| 41 | 41 |
| 42 void ServiceWorkerUnregisterJob::Abort() { | 42 void ServiceWorkerUnregisterJob::Abort() { |
| 43 CompleteInternal(SERVICE_WORKER_ERROR_ABORT); | 43 CompleteInternal(kInvalidServiceWorkerRegistrationId, |
| 44 SERVICE_WORKER_ERROR_ABORT); |
| 44 } | 45 } |
| 45 | 46 |
| 46 bool ServiceWorkerUnregisterJob::Equals(ServiceWorkerRegisterJobBase* job) { | 47 bool ServiceWorkerUnregisterJob::Equals(ServiceWorkerRegisterJobBase* job) { |
| 47 if (job->GetType() != GetType()) | 48 if (job->GetType() != GetType()) |
| 48 return false; | 49 return false; |
| 49 return static_cast<ServiceWorkerUnregisterJob*>(job)->pattern_ == pattern_; | 50 return static_cast<ServiceWorkerUnregisterJob*>(job)->pattern_ == pattern_; |
| 50 } | 51 } |
| 51 | 52 |
| 52 RegistrationJobType ServiceWorkerUnregisterJob::GetType() { | 53 RegistrationJobType ServiceWorkerUnregisterJob::GetType() { |
| 53 return UNREGISTRATION_JOB; | 54 return UNREGISTRATION_JOB; |
| 54 } | 55 } |
| 55 | 56 |
| 56 void ServiceWorkerUnregisterJob::OnRegistrationFound( | 57 void ServiceWorkerUnregisterJob::OnRegistrationFound( |
| 57 ServiceWorkerStatusCode status, | 58 ServiceWorkerStatusCode status, |
| 58 const scoped_refptr<ServiceWorkerRegistration>& registration) { | 59 const scoped_refptr<ServiceWorkerRegistration>& registration) { |
| 59 if (status == SERVICE_WORKER_ERROR_NOT_FOUND) { | 60 if (status == SERVICE_WORKER_ERROR_NOT_FOUND) { |
| 60 DCHECK(!registration.get()); | 61 DCHECK(!registration.get()); |
| 61 Complete(SERVICE_WORKER_ERROR_NOT_FOUND); | 62 Complete(kInvalidServiceWorkerRegistrationId, |
| 63 SERVICE_WORKER_ERROR_NOT_FOUND); |
| 62 return; | 64 return; |
| 63 } | 65 } |
| 64 | 66 |
| 65 if (status != SERVICE_WORKER_OK || registration->is_uninstalling()) { | 67 if (status != SERVICE_WORKER_OK || registration->is_uninstalling()) { |
| 66 Complete(status); | 68 Complete(kInvalidServiceWorkerRegistrationId, status); |
| 67 return; | 69 return; |
| 68 } | 70 } |
| 69 | 71 |
| 70 // TODO: "7. If registration.updatePromise is not null..." | 72 // TODO: "7. If registration.updatePromise is not null..." |
| 71 | 73 |
| 72 // "8. Resolve promise." | 74 // "8. Resolve promise." |
| 73 ResolvePromise(SERVICE_WORKER_OK); | 75 ResolvePromise(registration->id(), SERVICE_WORKER_OK); |
| 74 | 76 |
| 75 registration->ClearWhenReady(); | 77 registration->ClearWhenReady(); |
| 76 | 78 |
| 77 Complete(SERVICE_WORKER_OK); | 79 Complete(registration->id(), SERVICE_WORKER_OK); |
| 78 } | 80 } |
| 79 | 81 |
| 80 void ServiceWorkerUnregisterJob::Complete(ServiceWorkerStatusCode status) { | 82 void ServiceWorkerUnregisterJob::Complete(int64 registration_id, |
| 81 CompleteInternal(status); | 83 ServiceWorkerStatusCode status) { |
| 84 CompleteInternal(registration_id, status); |
| 82 context_->job_coordinator()->FinishJob(pattern_, this); | 85 context_->job_coordinator()->FinishJob(pattern_, this); |
| 83 } | 86 } |
| 84 | 87 |
| 85 void ServiceWorkerUnregisterJob::CompleteInternal( | 88 void ServiceWorkerUnregisterJob::CompleteInternal( |
| 89 int64 registration_id, |
| 86 ServiceWorkerStatusCode status) { | 90 ServiceWorkerStatusCode status) { |
| 87 if (!is_promise_resolved_) | 91 if (!is_promise_resolved_) |
| 88 ResolvePromise(status); | 92 ResolvePromise(registration_id, status); |
| 89 } | 93 } |
| 90 | 94 |
| 91 void ServiceWorkerUnregisterJob::ResolvePromise( | 95 void ServiceWorkerUnregisterJob::ResolvePromise( |
| 96 int64 registration_id, |
| 92 ServiceWorkerStatusCode status) { | 97 ServiceWorkerStatusCode status) { |
| 93 DCHECK(!is_promise_resolved_); | 98 DCHECK(!is_promise_resolved_); |
| 94 is_promise_resolved_ = true; | 99 is_promise_resolved_ = true; |
| 95 for (std::vector<UnregistrationCallback>::iterator it = callbacks_.begin(); | 100 for (std::vector<UnregistrationCallback>::iterator it = callbacks_.begin(); |
| 96 it != callbacks_.end(); | 101 it != callbacks_.end(); |
| 97 ++it) { | 102 ++it) { |
| 98 it->Run(status); | 103 it->Run(registration_id, status); |
| 99 } | 104 } |
| 100 } | 105 } |
| 101 | 106 |
| 102 } // namespace content | 107 } // namespace content |
| OLD | NEW |