Chromium Code Reviews| Index: content/browser/service_worker/service_worker_job_coordinator.cc |
| diff --git a/content/browser/service_worker/service_worker_job_coordinator.cc b/content/browser/service_worker/service_worker_job_coordinator.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..be49971cab782c10a1572c9c2b6771c8a9001adc |
| --- /dev/null |
| +++ b/content/browser/service_worker/service_worker_job_coordinator.cc |
| @@ -0,0 +1,73 @@ |
| +// 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_job_coordinator.h" |
| + |
| +#include "content/browser/service_worker/service_worker_register_job.h" |
| +#include "content/browser/service_worker/service_worker_registration.h" |
| + |
| +namespace content { |
| + |
| +ServiceWorkerJobCoordinator::ServiceWorkerJobCoordinator( |
| + const base::WeakPtr<ServiceWorkerStorage>& storage) |
| + : storage_(storage), weak_factory_(this) {} |
| + |
| +ServiceWorkerJobCoordinator::~ServiceWorkerJobCoordinator() {} |
| + |
| +void ServiceWorkerJobCoordinator::Register( |
| + const GURL& pattern, |
| + const GURL& script_url, |
| + const RegistrationCallback& callback) { |
| + scoped_ptr<ServiceWorkerRegisterJob> job(new ServiceWorkerRegisterJob( |
| + storage_, |
| + base::Bind(&ServiceWorkerJobCoordinator::RegisterComplete, |
| + weak_factory_.GetWeakPtr(), |
| + callback))); |
| + job->StartRegister(pattern, script_url); |
| + registration_jobs_.push_back(job.release()); |
| +} |
| + |
| +void ServiceWorkerJobCoordinator::Unregister( |
| + const GURL& pattern, |
| + const UnregistrationCallback& callback) { |
| + scoped_ptr<ServiceWorkerRegisterJob> job(new ServiceWorkerRegisterJob( |
| + storage_, |
| + base::Bind(&ServiceWorkerJobCoordinator::UnregisterComplete, |
| + weak_factory_.GetWeakPtr(), |
| + callback))); |
| + job->StartUnregister(pattern); |
| + registration_jobs_.push_back(job.release()); |
| +} |
| + |
| +void ServiceWorkerJobCoordinator::EraseJob(ServiceWorkerRegisterJob* job) { |
| + ScopedVector<ServiceWorkerRegisterJob>::iterator job_position = |
| + registration_jobs_.begin(); |
| + for (; job_position != registration_jobs_.end(); ++job_position) { |
| + if (*job_position == job) { |
| + registration_jobs_.erase(job_position); |
|
kinuko
2013/12/18 05:43:35
Keeping this as vector (scoped_vector) while we'll
alecflett
2014/01/06 21:47:12
Agreed. This array is going to get cleaned up in m
|
| + return; |
| + } |
| + } |
| + NOTREACHED() << "Deleting non-existent job. "; |
| +} |
| + |
| +void ServiceWorkerJobCoordinator::UnregisterComplete( |
| + const UnregistrationCallback& callback, |
| + ServiceWorkerRegisterJob* job, |
| + ServiceWorkerRegistrationStatus status, |
| + ServiceWorkerRegistration* previous_registration) { |
| + callback.Run(status); |
| + EraseJob(job); |
| +} |
| + |
| +void ServiceWorkerJobCoordinator::RegisterComplete( |
| + const RegistrationCallback& callback, |
| + ServiceWorkerRegisterJob* job, |
| + ServiceWorkerRegistrationStatus status, |
| + ServiceWorkerRegistration* registration) { |
| + callback.Run(status, registration); |
| + EraseJob(job); |
| +} |
| + |
| +} // namespace content |