Source code

Revision control

Other Tools

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/. */
6
7
#ifndef mozilla_dom_serviceworkerupdatejob_h
8
#define mozilla_dom_serviceworkerupdatejob_h
9
10
#include "ServiceWorkerJob.h"
11
#include "ServiceWorkerRegistration.h"
12
13
namespace mozilla {
14
namespace dom {
15
16
namespace serviceWorkerScriptCache {
17
enum class OnFailure : uint8_t;
18
} // namespace serviceWorkerScriptCache
19
20
class ServiceWorkerManager;
21
class ServiceWorkerRegistrationInfo;
22
23
// A job class that performs the Update and Install algorithms from the
24
// service worker spec. This class is designed to be inherited and customized
25
// as a different job type. This is necessary because the register job
26
// performs largely the same operations as the update job, but has a few
27
// different starting steps.
28
class ServiceWorkerUpdateJob : public ServiceWorkerJob {
29
public:
30
// Construct an update job to be used only for updates.
31
ServiceWorkerUpdateJob(nsIPrincipal* aPrincipal, const nsACString& aScope,
32
const nsACString& aScriptSpec,
33
ServiceWorkerUpdateViaCache aUpdateViaCache);
34
35
already_AddRefed<ServiceWorkerRegistrationInfo> GetRegistration() const;
36
37
protected:
38
// Construct an update job that is overriden as another job type.
39
ServiceWorkerUpdateJob(Type aType, nsIPrincipal* aPrincipal,
40
const nsACString& aScope,
41
const nsACString& aScriptSpec,
42
ServiceWorkerUpdateViaCache aUpdateViaCache);
43
44
virtual ~ServiceWorkerUpdateJob();
45
46
// FailUpdateJob() must be called if an update job needs Finish() with
47
// an error.
48
void FailUpdateJob(ErrorResult& aRv);
49
50
void FailUpdateJob(nsresult aRv);
51
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;
56
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);
60
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.
65
void Update();
66
67
ServiceWorkerUpdateViaCache GetUpdateViaCache() const;
68
69
private:
70
class CompareCallback;
71
class ContinueUpdateRunnable;
72
class ContinueInstallRunnable;
73
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);
80
81
// Utility method called after evaluating the worker script.
82
void ContinueUpdateAfterScriptEval(bool aScriptEvaluationResult);
83
84
// Utility method corresponding to the spec Install algorithm.
85
void Install();
86
87
// Utility method called after the install event is handled.
88
void ContinueAfterInstallEvent(bool aInstallEventSuccess);
89
90
RefPtr<ServiceWorkerRegistrationInfo> mRegistration;
91
ServiceWorkerUpdateViaCache mUpdateViaCache;
92
serviceWorkerScriptCache::OnFailure mOnFailure;
93
};
94
95
} // namespace dom
96
} // namespace mozilla
97
98
#endif // mozilla_dom_serviceworkerupdatejob_h