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 "base/bind.h"
12 #include "content/browser/service_worker/service_worker_register_job.h"
13 #include "content/browser/service_worker/service_worker_registration_status.h"
14 #include "content/browser/service_worker/service_worker_storage.h"
15 #include "content/common/content_export.h"
20 class ServiceWorkerRegistration;
22 // This class manages all in-flight jobs. Any asynchronous
23 // operations are run through instances of ServiceWorkerRegisterJob.
24 class CONTENT_EXPORT ServiceWorkerJobCoordinator {
26 explicit ServiceWorkerJobCoordinator(ServiceWorkerStorage* storage);
27 ~ServiceWorkerJobCoordinator();
29 void Register(const GURL& pattern,
30 const GURL& script_url,
31 const ServiceWorkerRegisterJob::RegistrationCallback& callback);
35 const ServiceWorkerRegisterJob::UnregistrationCallback& callback);
37 // Jobs are removed whenever they are finished or canceled.
38 void FinishJob(const GURL& pattern, ServiceWorkerRegisterJob* job);
41 friend class ServiceWorkerRegisterJob;
48 void Push(scoped_ptr<ServiceWorkerRegisterJob> job,
49 const ServiceWorkerRegisterJob::RegistrationCallback& callback);
51 void Pop(ServiceWorkerRegisterJob* job);
53 bool empty() { return jobs_.empty(); }
56 std::deque<ServiceWorkerRegisterJob*> jobs_;
59 typedef std::map<GURL, JobQueue> RegistrationJobMap;
61 // Called at ServiceWorkerRegisterJob completion.
62 void UnregisterComplete(
63 const ServiceWorkerRegisterJob::UnregistrationCallback& callback,
64 ServiceWorkerStatusCode status,
65 const scoped_refptr<ServiceWorkerRegistration>& registration);
67 // The ServiceWorkerStorage object should always outlive this
68 ServiceWorkerStorage* storage_;
69 base::WeakPtrFactory<ServiceWorkerJobCoordinator> weak_factory_;
71 RegistrationJobMap jobs_;
73 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerJobCoordinator);
76 } // namespace content
78 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_JOB_COORDINATOR_H_