Merge autoland to mozilla-central. a=merge
[gecko.git] / dom / serviceworkers / ServiceWorkerRegistrationProxy.h
blob4253d2f259705799cbc818be11de2b8a188c7d26
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 moz_dom_ServiceWorkerRegistrationProxy_h
8 #define moz_dom_ServiceWorkerRegistrationProxy_h
10 #include "mozilla/dom/PServiceWorkerRegistrationParent.h"
11 #include "nsProxyRelease.h"
12 #include "ServiceWorkerRegistrationDescriptor.h"
13 #include "ServiceWorkerRegistrationListener.h"
14 #include "ServiceWorkerUtils.h"
16 namespace mozilla::dom {
18 class ServiceWorkerRegistrationInfo;
19 class ServiceWorkerRegistrationParent;
21 class ServiceWorkerRegistrationProxy final
22 : public ServiceWorkerRegistrationListener {
23 // Background thread only
24 RefPtr<ServiceWorkerRegistrationParent> mActor;
26 // Written on background thread and read on main thread
27 nsCOMPtr<nsISerialEventTarget> mEventTarget;
29 // Main thread only
30 ServiceWorkerRegistrationDescriptor mDescriptor;
31 nsMainThreadPtrHandle<ServiceWorkerRegistrationInfo> mReg;
33 ~ServiceWorkerRegistrationProxy();
35 // Background thread methods
36 void MaybeShutdownOnBGThread();
38 void UpdateStateOnBGThread(
39 const ServiceWorkerRegistrationDescriptor& aDescriptor);
41 void FireUpdateFoundOnBGThread();
43 // Main thread methods
44 void InitOnMainThread();
46 void MaybeShutdownOnMainThread();
48 void StopListeningOnMainThread();
50 // The timer callback to perform the delayed update
51 class DelayedUpdate;
52 RefPtr<DelayedUpdate> mDelayedUpdate;
54 // ServiceWorkerRegistrationListener interface
55 void UpdateState(
56 const ServiceWorkerRegistrationDescriptor& aDescriptor) override;
58 void FireUpdateFound() override;
60 void RegistrationCleared() override;
62 void GetScope(nsAString& aScope) const override;
64 bool MatchesDescriptor(
65 const ServiceWorkerRegistrationDescriptor& aDescriptor) override;
67 public:
68 explicit ServiceWorkerRegistrationProxy(
69 const ServiceWorkerRegistrationDescriptor& aDescriptor);
71 void Init(ServiceWorkerRegistrationParent* aActor);
73 void RevokeActor(ServiceWorkerRegistrationParent* aActor);
75 RefPtr<GenericPromise> Unregister();
77 RefPtr<ServiceWorkerRegistrationPromise> Update(
78 const nsACString& aNewestWorkerScriptUrl);
80 RefPtr<GenericPromise> SetNavigationPreloadEnabled(const bool& aEnabled);
82 RefPtr<GenericPromise> SetNavigationPreloadHeader(const nsACString& aHeader);
84 RefPtr<NavigationPreloadStatePromise> GetNavigationPreloadState();
86 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ServiceWorkerRegistrationProxy,
87 override);
90 } // namespace mozilla::dom
92 #endif // moz_dom_ServiceWorkerRegistrationProxy_h