Chromium Code Reviews| 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 |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..7d92e9397082f77f37610d5110b05660405ddda8 |
| --- /dev/null |
| +++ b/content/browser/service_worker/service_worker_register_job.cc |
| @@ -0,0 +1,80 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/browser/service_worker/service_worker_register_job.h" |
| + |
| +#include "content/browser/service_worker/service_worker_registration.h" |
| +#include "content/public/browser/browser_thread.h" |
| +#include "url/gurl.h" |
| + |
| +namespace content { |
| + |
| +ServiceWorkerRegisterJob::ServiceWorkerRegisterJob( |
| + const base::WeakPtr<ServiceWorkerStorage>& storage, |
| + const RegistrationCompleteCallback& callback) |
| + : storage_(storage), callback_(callback), weak_factory_(this) {} |
| +ServiceWorkerRegisterJob::~ServiceWorkerRegisterJob() {} |
| + |
| +void ServiceWorkerRegisterJob::StartRegister(const GURL& pattern, |
| + const GURL& script_url) { |
| + storage_->FindRegistrationForPattern( |
| + pattern, |
| + base::Bind( |
| + &ServiceWorkerRegisterJob::UnregisterPatternAndContinue, |
| + weak_factory_.GetWeakPtr(), |
| + pattern, |
| + script_url, |
| + base::Bind(&ServiceWorkerRegisterJob::RegisterPatternAndContinue, |
| + weak_factory_.GetWeakPtr(), |
| + pattern, |
| + script_url, |
| + base::Bind(&ServiceWorkerRegisterJob::RegisterComplete, |
| + weak_factory_.GetWeakPtr())))); |
|
kinuko
2013/11/25 08:17:10
In this way of chaining when something very bad ha
alecflett
2013/11/26 00:19:14
yes - though if we add the status field like you s
kinuko
2013/11/26 08:02:00
Ok, with status code we can short-cut, which may n
|
| +} |
| + |
| +void ServiceWorkerRegisterJob::StartUnregister(const GURL& pattern) { |
| + storage_->FindRegistrationForPattern( |
| + pattern, |
| + base::Bind(&ServiceWorkerRegisterJob::UnregisterPatternAndContinue, |
| + weak_factory_.GetWeakPtr(), |
| + pattern, |
| + GURL(), |
| + base::Bind(&ServiceWorkerRegisterJob::UnregisterComplete, |
| + weak_factory_.GetWeakPtr()))); |
| +} |
| + |
| +void ServiceWorkerRegisterJob::UnregisterComplete() { |
| + callback_.Run(this, NULL); |
| +} |
| +void ServiceWorkerRegisterJob::RegisterComplete( |
| + const scoped_refptr<ServiceWorkerRegistration>& registration) { |
| + callback_.Run(this, registration.get()); |
| +} |
| + |
| +void ServiceWorkerRegisterJob::RegisterPatternAndContinue( |
| + const GURL& pattern, |
| + const GURL& script_url, |
| + const ServiceWorkerStorage::ResponseCallback callback) { |
| + if (storage_) { |
|
kinuko
2013/11/25 08:17:10
storage_ owns this job, so technically this should
alecflett
2013/11/26 00:19:14
Well this allows storage_ to go away in the middle
kinuko
2013/11/26 08:02:00
But storage class does own this Job instance via S
|
| + scoped_refptr<ServiceWorkerRegistration> registration = |
| + storage_->RegisterInternal(pattern, script_url); |
| + BrowserThread::PostTask( |
| + BrowserThread::IO, FROM_HERE, base::Bind(callback, registration)); |
| + } |
| +} |
| + |
| +void ServiceWorkerRegisterJob::UnregisterPatternAndContinue( |
| + const GURL& pattern, |
| + const GURL& new_script_url, |
| + const base::Closure& callback, |
| + const scoped_refptr<ServiceWorkerRegistration>& previous_registration) { |
| + if (previous_registration && |
| + (new_script_url.is_empty() || |
| + previous_registration->script_url() != new_script_url)) { |
| + storage_->UnregisterInternal(pattern); |
| + } |
| + BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, callback); |
| +} |
| + |
| +} // namespace content |