ServiceWorkerProxy.h (1621B)
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_ServiceWorkerProxy_h 8 #define moz_dom_ServiceWorkerProxy_h 9 10 #include "ServiceWorkerDescriptor.h" 11 #include "nsProxyRelease.h" 12 13 namespace mozilla::dom { 14 15 class PostMessageSource; 16 class ServiceWorkerCloneData; 17 class ServiceWorkerInfo; 18 class ServiceWorkerParent; 19 20 class ServiceWorkerProxy final { 21 // Background thread only 22 RefPtr<ServiceWorkerParent> mActor; 23 24 // Written on background thread and read on main thread 25 nsCOMPtr<nsISerialEventTarget> mEventTarget; 26 27 // Main thread only 28 ServiceWorkerDescriptor mDescriptor; 29 nsMainThreadPtrHandle<ServiceWorkerInfo> mInfo; 30 31 ~ServiceWorkerProxy(); 32 33 // Background thread methods 34 void MaybeShutdownOnBGThread(); 35 36 void SetStateOnBGThread(ServiceWorkerState aState); 37 38 // Main thread methods 39 void InitOnMainThread(); 40 41 void MaybeShutdownOnMainThread(); 42 43 void StopListeningOnMainThread(); 44 45 public: 46 explicit ServiceWorkerProxy(const ServiceWorkerDescriptor& aDescriptor); 47 48 void Init(ServiceWorkerParent* aActor); 49 50 void RevokeActor(ServiceWorkerParent* aActor); 51 52 void PostMessage(RefPtr<ServiceWorkerCloneData>&& aData, 53 const PostMessageSource& aSource); 54 55 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ServiceWorkerProxy); 56 }; 57 58 } // namespace mozilla::dom 59 60 #endif // moz_dom_ServiceWorkerProxy_h