1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_serviceworkerupdatejob_h
8 #define mozilla_dom_serviceworkerupdatejob_h
10 #include "ServiceWorkerJob.h"
11 #include "ServiceWorkerRegistration.h"
13 #include "nsIRequest.h"
15 namespace mozilla::dom
{
17 namespace serviceWorkerScriptCache
{
18 enum class OnFailure
: uint8_t;
19 } // namespace serviceWorkerScriptCache
21 class ServiceWorkerManager
;
22 class ServiceWorkerRegistrationInfo
;
24 // A job class that performs the Update and Install algorithms from the
25 // service worker spec. This class is designed to be inherited and customized
26 // as a different job type. This is necessary because the register job
27 // performs largely the same operations as the update job, but has a few
28 // different starting steps.
29 class ServiceWorkerUpdateJob
: public ServiceWorkerJob
{
31 // Construct an update job to be used only for updates.
32 ServiceWorkerUpdateJob(nsIPrincipal
* aPrincipal
, const nsACString
& aScope
,
33 nsCString aScriptSpec
,
34 ServiceWorkerUpdateViaCache aUpdateViaCache
);
36 already_AddRefed
<ServiceWorkerRegistrationInfo
> GetRegistration() const;
39 // Construct an update job that is overriden as another job type.
40 ServiceWorkerUpdateJob(Type aType
, nsIPrincipal
* aPrincipal
,
41 const nsACString
& aScope
, nsCString aScriptSpec
,
42 ServiceWorkerUpdateViaCache aUpdateViaCache
);
44 virtual ~ServiceWorkerUpdateJob();
46 // FailUpdateJob() must be called if an update job needs Finish() with
48 void FailUpdateJob(ErrorResult
& aRv
);
50 void FailUpdateJob(nsresult aRv
);
52 // The entry point when the update job is being used directly. Job
53 // types overriding this class should override this method to
54 // customize behavior.
55 virtual void AsyncExecute() override
;
57 // Set the registration to be operated on by Update() or to be immediately
58 // returned as a result of the job. This must be called before Update().
59 void SetRegistration(ServiceWorkerRegistrationInfo
* aRegistration
);
61 // Execute the bulk of the update job logic using the registration defined
62 // by a previous SetRegistration() call. This can be called by the overriden
63 // AsyncExecute() to complete the job. The Update() method will always call
64 // Finish(). This method corresponds to the spec Update algorithm.
67 ServiceWorkerUpdateViaCache
GetUpdateViaCache() const;
70 class CompareCallback
;
71 class ContinueUpdateRunnable
;
72 class ContinueInstallRunnable
;
74 // Utility method called after a script is loaded and compared to
75 // our current cached script.
76 void ComparisonResult(nsresult aStatus
, bool aInCacheAndEqual
,
77 serviceWorkerScriptCache::OnFailure aOnFailure
,
78 const nsAString
& aNewCacheName
,
79 const nsACString
& aMaxScope
, nsLoadFlags aLoadFlags
);
81 // Utility method called after evaluating the worker script.
82 void ContinueUpdateAfterScriptEval(bool aScriptEvaluationResult
);
84 // Utility method corresponding to the spec Install algorithm.
87 // Utility method called after the install event is handled.
88 void ContinueAfterInstallEvent(bool aInstallEventSuccess
);
90 RefPtr
<ServiceWorkerRegistrationInfo
> mRegistration
;
91 ServiceWorkerUpdateViaCache mUpdateViaCache
;
92 serviceWorkerScriptCache::OnFailure mOnFailure
;
95 } // namespace mozilla::dom
97 #endif // mozilla_dom_serviceworkerupdatejob_h