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_UNREGISTER_JOB_H_
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_UNREGISTER_JOB_H_
10 #include "base/memory/weak_ptr.h"
11 #include "content/browser/service_worker/service_worker_register_job_base.h"
12 #include "content/common/service_worker/service_worker_status_code.h"
17 class EmbeddedWorkerRegistry
;
18 class ServiceWorkerContextCore
;
19 class ServiceWorkerJobCoordinator
;
20 class ServiceWorkerRegistration
;
21 class ServiceWorkerStorage
;
23 // Handles the unregistration of a Service Worker.
25 // The unregistration process is primarily cleanup, removing everything that was
26 // created during the registration process, including the
27 // ServiceWorkerRegistration itself.
28 class ServiceWorkerUnregisterJob
: public ServiceWorkerRegisterJobBase
{
30 typedef base::Callback
<void(int64 registration_id
,
31 ServiceWorkerStatusCode status
)>
32 UnregistrationCallback
;
34 ServiceWorkerUnregisterJob(base::WeakPtr
<ServiceWorkerContextCore
> context
,
36 ~ServiceWorkerUnregisterJob() override
;
38 // Registers a callback to be called when the job completes (whether
39 // successfully or not). Multiple callbacks may be registered.
40 void AddCallback(const UnregistrationCallback
& callback
);
42 // ServiceWorkerRegisterJobBase implementation:
43 void Start() override
;
44 void Abort() override
;
45 bool Equals(ServiceWorkerRegisterJobBase
* job
) const override
;
46 RegistrationJobType
GetType() const override
;
49 void OnRegistrationFound(
50 ServiceWorkerStatusCode status
,
51 const scoped_refptr
<ServiceWorkerRegistration
>& registration
);
52 void Complete(int64 registration_id
, ServiceWorkerStatusCode status
);
53 void CompleteInternal(int64 registration_id
, ServiceWorkerStatusCode status
);
54 void ResolvePromise(int64 registration_id
, ServiceWorkerStatusCode status
);
56 base::WeakPtr
<ServiceWorkerContextCore
> context_
;
58 std::vector
<UnregistrationCallback
> callbacks_
;
59 bool is_promise_resolved_
;
60 base::WeakPtrFactory
<ServiceWorkerUnregisterJob
> weak_factory_
;
62 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerUnregisterJob
);
64 } // namespace content
66 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_UNREGISTER_JOB_H_