Bug 1617993 - Add CheckedUnsafePtr to some SharedWorker classes r=dom-workers-and-storage-reviewers,sg

Depends on D64302

Differential Revision: https://phabricator.services.mozilla.com/D64199

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Perry Jiang 2020-03-12 16:10:03 +00:00
parent 6223cfb160
commit 7a9d3317b1
4 changed files with 22 additions and 15 deletions

View File

@ -7,7 +7,9 @@
#ifndef mozilla_dom_SharedWorkerManager_h
#define mozilla_dom_SharedWorkerManager_h
#include "SharedWorkerParent.h"
#include "mozilla/dom/RemoteWorkerController.h"
#include "mozilla/dom/quota/CheckedUnsafePtr.h"
#include "nsISupportsImpl.h"
#include "nsTArray.h"
@ -20,12 +22,12 @@ class UniqueMessagePortId;
class RemoteWorkerData;
class SharedWorkerManager;
class SharedWorkerService;
class SharedWorkerParent;
// Main-thread only object that keeps a manager and the service alive.
// When the last SharedWorkerManagerHolder is released, the corresponding
// manager unregisters itself from the service and terminates the worker.
class SharedWorkerManagerHolder final {
class SharedWorkerManagerHolder final
: public SupportsCheckedUnsafePtr<CheckIf<DiagnosticAssertEnabled>> {
public:
NS_INLINE_DECL_REFCOUNTING(SharedWorkerManagerHolder);
@ -39,8 +41,8 @@ class SharedWorkerManagerHolder final {
private:
~SharedWorkerManagerHolder();
RefPtr<SharedWorkerManager> mManager;
RefPtr<SharedWorkerService> mService;
const RefPtr<SharedWorkerManager> mManager;
const RefPtr<SharedWorkerService> mService;
};
// Thread-safe wrapper for SharedWorkerManagerHolder.
@ -124,23 +126,23 @@ class SharedWorkerManager final : public RemoteWorkerObserver {
nsCOMPtr<nsIEventTarget> mPBackgroundEventTarget;
nsCOMPtr<nsIPrincipal> mLoadingPrincipal;
nsCString mDomain;
OriginAttributes mStoragePrincipalAttrs;
nsCOMPtr<nsIURI> mResolvedScriptURL;
nsString mName;
bool mIsSecureContext;
const nsCString mDomain;
const OriginAttributes mStoragePrincipalAttrs;
const nsCOMPtr<nsIURI> mResolvedScriptURL;
const nsString mName;
const bool mIsSecureContext;
bool mSuspended;
bool mFrozen;
// Raw pointers because SharedWorkerParent unregisters itself in
// ActorDestroy().
nsTArray<SharedWorkerParent*> mActors;
nsTArray<CheckedUnsafePtr<SharedWorkerParent>> mActors;
RefPtr<RemoteWorkerController> mRemoteWorkerController;
// Main-thread only. Raw Pointers because holders keep the manager alive and
// they unregister themselves in their DTOR.
nsTArray<SharedWorkerManagerHolder*> mHolders;
nsTArray<CheckedUnsafePtr<SharedWorkerManagerHolder>> mHolders;
};
} // namespace dom

View File

@ -8,6 +8,7 @@
#define mozilla_dom_dom_SharedWorkerParent_h
#include "mozilla/dom/PSharedWorkerParent.h"
#include "mozilla/dom/quota/CheckedUnsafePtr.h"
#include "mozilla/ipc/BackgroundUtils.h"
#include "nsISupportsImpl.h"
@ -18,7 +19,9 @@ class MessagePortIdentifier;
class RemoteWorkerData;
class SharedWorkerManagerWrapper;
class SharedWorkerParent final : public mozilla::dom::PSharedWorkerParent {
class SharedWorkerParent final
: public mozilla::dom::PSharedWorkerParent,
public SupportsCheckedUnsafePtr<CheckIf<DiagnosticAssertEnabled>> {
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SharedWorkerParent)

View File

@ -23,7 +23,7 @@ StaticMutex sSharedWorkerMutex;
// Raw pointer because SharedWorkerParent keeps this object alive, indirectly
// via SharedWorkerManagerHolder.
SharedWorkerService* MOZ_NON_OWNING_REF sSharedWorkerService;
CheckedUnsafePtr<SharedWorkerService> sSharedWorkerService;
class GetOrCreateWorkerManagerRunnable final : public Runnable {
public:
@ -119,7 +119,7 @@ already_AddRefed<SharedWorkerService> SharedWorkerService::GetOrCreate() {
StaticMutexAutoLock lock(sSharedWorkerMutex);
if (sSharedWorkerService) {
RefPtr<SharedWorkerService> instance = sSharedWorkerService;
RefPtr<SharedWorkerService> instance = sSharedWorkerService.get();
return instance.forget();
}

View File

@ -7,6 +7,7 @@
#ifndef mozilla_dom_SharedWorkerService_h
#define mozilla_dom_SharedWorkerService_h
#include "mozilla/dom/quota/CheckedUnsafePtr.h"
#include "nsISupportsImpl.h"
#include "nsTArray.h"
@ -24,7 +25,8 @@ class SharedWorkerManager;
class SharedWorkerParent;
class UniqueMessagePortId;
class SharedWorkerService final {
class SharedWorkerService final
: public SupportsCheckedUnsafePtr<CheckIf<DiagnosticAssertEnabled>> {
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SharedWorkerService);