Index: content/browser/service_worker/service_worker_register_job.cc |
diff --git a/content/browser/service_worker/service_worker_register_job.cc b/content/browser/service_worker/service_worker_register_job.cc |
index 3dcc80b05c60148e1f91989588d9f371b6a188a2..0013f619eeb9d3e740e8f1ceb64de5f6166af50e 100644 |
--- a/content/browser/service_worker/service_worker_register_job.cc |
+++ b/content/browser/service_worker/service_worker_register_job.cc |
@@ -71,7 +71,7 @@ void ServiceWorkerRegisterJob::HandleExistingRegistrationAndContinue( |
if (status != SERVICE_WORKER_OK) { |
// Abort this registration job. |
- Complete(status); |
+ Complete(NULL, status); |
return; |
} |
@@ -87,41 +87,42 @@ void ServiceWorkerRegisterJob::HandleExistingRegistrationAndContinue( |
} |
// Reuse the existing registration. |
- registration_ = registration; |
- StartWorkerAndContinue(SERVICE_WORKER_OK); |
+ StartWorkerAndContinue(registration, SERVICE_WORKER_OK); |
} |
void ServiceWorkerRegisterJob::RegisterAndContinue( |
ServiceWorkerStatusCode status) { |
- DCHECK(!registration_); |
if (status != SERVICE_WORKER_OK) { |
// Abort this registration job. |
- Complete(status); |
+ Complete(NULL, status); |
return; |
} |
- registration_ = new ServiceWorkerRegistration( |
- pattern_, script_url_, context_->storage()->NewRegistrationId(), |
- context_); |
+ scoped_refptr<ServiceWorkerRegistration> registration = |
+ new ServiceWorkerRegistration(pattern_, |
+ script_url_, |
+ context_->storage()->NewRegistrationId(), |
+ context_); |
context_->storage()->StoreRegistration( |
- registration_.get(), |
+ registration.get(), |
base::Bind(&ServiceWorkerRegisterJob::StartWorkerAndContinue, |
- weak_factory_.GetWeakPtr())); |
+ weak_factory_.GetWeakPtr(), |
+ registration)); |
} |
void ServiceWorkerRegisterJob::StartWorkerAndContinue( |
+ ServiceWorkerRegistration* registration, |
ServiceWorkerStatusCode status) { |
// TODO(falken): Handle the case where status is an error code. |
- DCHECK(registration_); |
- if (registration_->active_version()) { |
+ if (registration->active_version()) { |
// We have an active version, so we can complete immediately, even |
// if the service worker isn't running. |
- Complete(SERVICE_WORKER_OK); |
+ Complete(registration, SERVICE_WORKER_OK); |
return; |
} |
pending_version_ = new ServiceWorkerVersion( |
- registration_, context_->storage()->NewVersionId(), context_); |
+ registration, context_->storage()->NewVersionId(), context_); |
for (std::vector<int>::const_iterator it = pending_process_ids_.begin(); |
it != pending_process_ids_.end(); |
++it) |
@@ -132,19 +133,21 @@ void ServiceWorkerRegisterJob::StartWorkerAndContinue( |
// dispatched. The job will continue to run even though the main |
// callback has executed. |
pending_version_->StartWorker(base::Bind(&ServiceWorkerRegisterJob::Complete, |
- weak_factory_.GetWeakPtr())); |
+ weak_factory_.GetWeakPtr(), |
+ make_scoped_refptr(registration))); |
// TODO(falken): Don't set the active version until just before |
// the activate event is dispatched. |
pending_version_->SetStatus(ServiceWorkerVersion::ACTIVE); |
- registration_->set_active_version(pending_version_); |
+ registration->set_active_version(pending_version_); |
} |
-void ServiceWorkerRegisterJob::Complete(ServiceWorkerStatusCode status) { |
+void ServiceWorkerRegisterJob::Complete(ServiceWorkerRegistration* registration, |
+ ServiceWorkerStatusCode status) { |
for (std::vector<RegistrationCallback>::iterator it = callbacks_.begin(); |
it != callbacks_.end(); |
++it) { |
- it->Run(status, status == SERVICE_WORKER_OK ? registration_ : NULL); |
+ it->Run(status, status == SERVICE_WORKER_OK ? registration : NULL); |
} |
context_->job_coordinator()->FinishJob(pattern_, this); |
} |