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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_JOB_COORDINATOR_H_
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_JOB_COORDINATOR_H_
11 #include "content/browser/service_worker/service_worker_register_job.h"
12 #include "content/browser/service_worker/service_worker_unregister_job.h"
13 #include "content/common/content_export.h"
18 class EmbeddedWorkerRegistry;
19 class ServiceWorkerRegistration;
20 class ServiceWorkerStorage;
22 // This class manages all in-flight registration or unregistration jobs.
23 class CONTENT_EXPORT ServiceWorkerJobCoordinator {
25 explicit ServiceWorkerJobCoordinator(
26 base::WeakPtr<ServiceWorkerContextCore> context);
27 ~ServiceWorkerJobCoordinator();
29 void Register(const GURL& pattern,
30 const GURL& script_url,
31 int source_process_id,
32 const ServiceWorkerRegisterJob::RegistrationCallback& callback);
36 const ServiceWorkerUnregisterJob::UnregistrationCallback& callback);
38 // Jobs are removed whenever they are finished or canceled.
39 void FinishJob(const GURL& pattern, ServiceWorkerRegisterJobBase* job);
47 // Adds a job to the queue. If an identical job is already in the queue, no
48 // new job is added. Returns the job in the queue, regardless of whether it
50 ServiceWorkerRegisterJobBase* Push(
51 scoped_ptr<ServiceWorkerRegisterJobBase> job);
53 // Removes a job from the queue.
54 void Pop(ServiceWorkerRegisterJobBase* job);
56 bool empty() { return jobs_.empty(); }
59 std::deque<ServiceWorkerRegisterJobBase*> jobs_;
62 typedef std::map<GURL, JobQueue> RegistrationJobMap;
64 // The ServiceWorkerContextCore object should always outlive the
65 // job coordinator, the core owns the coordinator.
66 base::WeakPtr<ServiceWorkerContextCore> context_;
67 RegistrationJobMap jobs_;
69 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerJobCoordinator);
72 } // namespace content
74 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_JOB_COORDINATOR_H_