| 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
|
| index 9e1473d6ae279bdf2171f2a56113e687ac7f494e..099cc4ff6b653147b62c39c7c1d6d82fd675194a 100644
|
| --- a/content/browser/service_worker/service_worker_job_coordinator.cc
|
| +++ b/content/browser/service_worker/service_worker_job_coordinator.cc
|
| @@ -4,10 +4,38 @@
|
|
|
| #include "content/browser/service_worker/service_worker_job_coordinator.h"
|
|
|
| +#include "base/stl_util.h"
|
| #include "content/browser/service_worker/service_worker_registration.h"
|
|
|
| namespace content {
|
|
|
| +ServiceWorkerJobCoordinator::JobQueue::JobQueue() {}
|
| +
|
| +ServiceWorkerJobCoordinator::JobQueue::~JobQueue() {
|
| + STLDeleteElements(&jobs_);
|
| +}
|
| +
|
| +void ServiceWorkerJobCoordinator::JobQueue::Push(
|
| + scoped_ptr<ServiceWorkerRegisterJob> job,
|
| + const ServiceWorkerRegisterJob::RegistrationCallback& callback) {
|
| + if (jobs_.empty()) {
|
| + job->Start();
|
| + jobs_.push_back(job.release());
|
| + } else if (!job->Equals(jobs_.back())) {
|
| + jobs_.push_back(job.release());
|
| + }
|
| +
|
| + DCHECK(!jobs_.empty());
|
| + jobs_.back()->AddCallback(callback);
|
| +}
|
| +
|
| +void ServiceWorkerJobCoordinator::JobQueue::Pop(ServiceWorkerRegisterJob* job) {
|
| + DCHECK(job == jobs_.front());
|
| + jobs_.pop_front();
|
| + if (!jobs_.empty())
|
| + jobs_.front()->Start();
|
| +}
|
| +
|
| ServiceWorkerJobCoordinator::ServiceWorkerJobCoordinator(
|
| ServiceWorkerStorage* storage)
|
| : storage_(storage), weak_factory_(this) {}
|
| @@ -18,55 +46,46 @@ void ServiceWorkerJobCoordinator::Register(
|
| const GURL& pattern,
|
| const GURL& script_url,
|
| const ServiceWorkerRegisterJob::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());
|
| + scoped_ptr<ServiceWorkerRegisterJob> job = make_scoped_ptr(
|
| + new ServiceWorkerRegisterJob(storage_,
|
| + this,
|
| + pattern,
|
| + script_url,
|
| + ServiceWorkerRegisterJob::REGISTER));
|
| + jobs_[pattern].Push(job.Pass(), callback);
|
| }
|
|
|
| void ServiceWorkerJobCoordinator::Unregister(
|
| const GURL& pattern,
|
| const ServiceWorkerRegisterJob::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);
|
| - return;
|
| - }
|
| - }
|
| - NOTREACHED() << "Deleting non-existent job. ";
|
| + scoped_ptr<ServiceWorkerRegisterJob> job = make_scoped_ptr(
|
| + new ServiceWorkerRegisterJob(storage_,
|
| + this,
|
| + pattern,
|
| + GURL(),
|
| + ServiceWorkerRegisterJob::UNREGISTER));
|
| + jobs_[pattern]
|
| + .Push(job.Pass(),
|
| + base::Bind(&ServiceWorkerJobCoordinator::UnregisterComplete,
|
| + weak_factory_.GetWeakPtr(),
|
| + callback));
|
| }
|
|
|
| -void ServiceWorkerJobCoordinator::RegisterComplete(
|
| - const ServiceWorkerRegisterJob::RegistrationCallback& callback,
|
| - ServiceWorkerRegisterJob* job,
|
| - ServiceWorkerRegistrationStatus status,
|
| - ServiceWorkerRegistration* registration) {
|
| - callback.Run(status, registration);
|
| - EraseJob(job);
|
| +void ServiceWorkerJobCoordinator::FinishJob(const GURL& pattern,
|
| + ServiceWorkerRegisterJob* job) {
|
| + RegistrationJobMap::iterator pending_jobs = jobs_.find(pattern);
|
| + DCHECK(pending_jobs != jobs_.end()) << "Deleting non-existent job.";
|
| + pending_jobs->second.Pop(job);
|
| + if (pending_jobs->second.empty())
|
| + jobs_.erase(pending_jobs);
|
| }
|
|
|
| void ServiceWorkerJobCoordinator::UnregisterComplete(
|
| const ServiceWorkerRegisterJob::UnregistrationCallback& callback,
|
| - ServiceWorkerRegisterJob* job,
|
| ServiceWorkerRegistrationStatus status,
|
| - ServiceWorkerRegistration* previous_registration) {
|
| + const scoped_refptr<ServiceWorkerRegistration>& previous_registration) {
|
| callback.Run(status);
|
| - EraseJob(job);
|
| }
|
|
|
| } // namespace content
|
|
|