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 moz_dom_ServiceWorkerRegistrationProxy_h
8
#define moz_dom_ServiceWorkerRegistrationProxy_h
9
10
#include "mozilla/dom/PServiceWorkerRegistrationParent.h"
11
#include "nsProxyRelease.h"
12
#include "ServiceWorkerRegistrationDescriptor.h"
13
#include "ServiceWorkerRegistrationListener.h"
14
#include "ServiceWorkerUtils.h"
15
16
namespace mozilla {
17
namespace dom {
18
19
class ServiceWorkerRegistrationInfo;
20
class ServiceWorkerRegistrationParent;
21
22
class ServiceWorkerRegistrationProxy final
23
: public ServiceWorkerRegistrationListener {
24
// Background thread only
25
ServiceWorkerRegistrationParent* mActor;
26
27
// Written on background thread and read on main thread
28
nsCOMPtr<nsISerialEventTarget> mEventTarget;
29
30
// Main thread only
31
ServiceWorkerRegistrationDescriptor mDescriptor;
32
nsMainThreadPtrHandle<ServiceWorkerRegistrationInfo> mReg;
33
34
~ServiceWorkerRegistrationProxy();
35
36
// Background thread methods
37
void MaybeShutdownOnBGThread();
38
39
void UpdateStateOnBGThread(
40
const ServiceWorkerRegistrationDescriptor& aDescriptor);
41
42
void FireUpdateFoundOnBGThread();
43
44
// Main thread methods
45
void InitOnMainThread();
46
47
void MaybeShutdownOnMainThread();
48
49
void StopListeningOnMainThread();
50
51
// The timer callback to perform the delayed update
52
class DelayedUpdate;
53
RefPtr<DelayedUpdate> mDelayedUpdate;
54
55
// ServiceWorkerRegistrationListener interface
56
void UpdateState(
57
const ServiceWorkerRegistrationDescriptor& aDescriptor) override;
58
59
void FireUpdateFound() override;
60
61
void RegistrationCleared() override;
62
63
void GetScope(nsAString& aScope) const override;
64
65
bool MatchesDescriptor(
66
const ServiceWorkerRegistrationDescriptor& aDescriptor) override;
67
68
public:
69
explicit ServiceWorkerRegistrationProxy(
70
const ServiceWorkerRegistrationDescriptor& aDescriptor);
71
72
void Init(ServiceWorkerRegistrationParent* aActor);
73
74
void RevokeActor(ServiceWorkerRegistrationParent* aActor);
75
76
RefPtr<GenericPromise> Unregister();
77
78
RefPtr<ServiceWorkerRegistrationPromise> Update();
79
80
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ServiceWorkerRegistrationProxy,
81
override);
82
};
83
84
} // namespace dom
85
} // namespace mozilla
86
87
#endif // moz_dom_ServiceWorkerRegistrationProxy_h