Skip to content

Commit

Permalink
Bug 1653011 - Simplify and make WeakPtr<Derived> usable and compact. …
Browse files Browse the repository at this point in the history
…r=froydnj,sg,geckoview-reviewers,jgilbert,kvark,snorp

Having two classes in the inheritance chain inherit from SupportsWeakPtr
now won't compile, but you can use WeakPtr<Derived> when any base class
inherits from SupportsWeakPtr.

Differential Revision: https://phabricator.services.mozilla.com/D83674
  • Loading branch information
emilio committed Jul 23, 2020
1 parent 37c68db commit ff61891
Show file tree
Hide file tree
Showing 63 changed files with 135 additions and 330 deletions.
2 changes: 0 additions & 2 deletions docshell/base/BrowsingContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -513,8 +513,6 @@ class BrowsingContext : public nsILoadContext, public nsWrapperCache {

Nullable<WindowProxyHolder> GetWindow();

MOZ_DECLARE_WEAKREFERENCE_TYPENAME(BrowsingContext)

NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(BrowsingContext)
NS_DECL_NSILOADCONTEXT
Expand Down
3 changes: 1 addition & 2 deletions docshell/base/nsDocShell.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class nsDocShell final : public nsDocLoader,
public nsILoadContext,
public nsINetworkInterceptController,
public nsIDeprecationWarner,
public mozilla::SupportsWeakPtr<nsDocShell> {
public mozilla::SupportsWeakPtr {
public:
enum InternalLoad : uint32_t {
INTERNAL_LOAD_FLAGS_NONE = 0x0,
Expand Down Expand Up @@ -179,7 +179,6 @@ class nsDocShell final : public nsDocLoader,
nsWeakPtr mWeakPtr;
};

MOZ_DECLARE_WEAKREFERENCE_TYPENAME(nsDocShell)
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsDocShell, nsDocLoader)
NS_DECL_NSIDOCSHELL
Expand Down
4 changes: 1 addition & 3 deletions dom/base/Document.h
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ class Document : public nsINode,
public nsIApplicationCacheContainer,
public nsStubMutationObserver,
public DispatcherTrait,
public SupportsWeakPtr<Document> {
public SupportsWeakPtr {
friend class DocumentOrShadowRoot;

protected:
Expand All @@ -494,8 +494,6 @@ class Document : public nsINode,
*/
static void Shutdown();

MOZ_DECLARE_WEAKREFERENCE_TYPENAME(Document)

NS_DECLARE_STATIC_IID_ACCESSOR(NS_IDOCUMENT_IID)

NS_DECL_CYCLE_COLLECTING_ISUPPORTS
Expand Down
6 changes: 2 additions & 4 deletions dom/base/PlacesWeakCallbackWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@
namespace mozilla {
namespace dom {

class PlacesWeakCallbackWrapper final
: public nsWrapperCache,
public SupportsWeakPtr<PlacesWeakCallbackWrapper> {
class PlacesWeakCallbackWrapper final : public nsWrapperCache,
public SupportsWeakPtr {
public:
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(PlacesWeakCallbackWrapper)
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(PlacesWeakCallbackWrapper)
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(PlacesWeakCallbackWrapper)

Expand Down
4 changes: 1 addition & 3 deletions dom/base/Selection.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ namespace dom {
// is never deleted before its Selections.
class Selection final : public nsSupportsWeakReference,
public nsWrapperCache,
public SupportsWeakPtr<Selection> {
public SupportsWeakPtr {
protected:
virtual ~Selection();

Expand All @@ -67,8 +67,6 @@ class Selection final : public nsSupportsWeakReference,
explicit Selection(SelectionType aSelectionType,
nsFrameSelection* aFrameSelection);

MOZ_DECLARE_WEAKREFERENCE_TYPENAME(Selection)

NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Selection)

Expand Down
2 changes: 2 additions & 0 deletions dom/base/nsRange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,8 @@ void nsRange::RegisterSelection(Selection& aSelection) {
RegisterClosestCommonInclusiveAncestor(commonAncestor);
}

Selection* nsRange::GetSelection() const { return mSelection; }

void nsRange::UnregisterSelection() {
mSelection = nullptr;

Expand Down
2 changes: 1 addition & 1 deletion dom/base/nsRange.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class nsRange final : public mozilla::dom::AbstractRange,
/**
* Returns pointer to a Selection if the range is associated with a Selection.
*/
mozilla::dom::Selection* GetSelection() const { return mSelection; }
mozilla::dom::Selection* GetSelection() const;

/**
* Return true if this range was generated.
Expand Down
11 changes: 3 additions & 8 deletions dom/canvas/ClientWebGLContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ class WebGLProgramJS final : public nsWrapperCache, public webgl::ObjectJS {

class WebGLQueryJS final : public nsWrapperCache,
public webgl::ObjectJS,
public SupportsWeakPtr<WebGLQueryJS> {
public SupportsWeakPtr {
friend class ClientWebGLContext;
friend class webgl::AvailabilityRunnable;

Expand All @@ -402,7 +402,6 @@ class WebGLQueryJS final : public nsWrapperCache,
public:
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLQueryJS)
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLQueryJS)
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(WebGLQueryJS)

explicit WebGLQueryJS(const ClientWebGLContext& webgl)
: webgl::ObjectJS(webgl) {}
Expand Down Expand Up @@ -492,7 +491,7 @@ class WebGLShaderJS final : public nsWrapperCache, public webgl::ObjectJS {

class WebGLSyncJS final : public nsWrapperCache,
public webgl::ObjectJS,
public SupportsWeakPtr<WebGLSyncJS> {
public SupportsWeakPtr {
friend class ClientWebGLContext;
friend class webgl::AvailabilityRunnable;

Expand All @@ -502,7 +501,6 @@ class WebGLSyncJS final : public nsWrapperCache,
public:
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLSyncJS)
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLSyncJS)
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(WebGLSyncJS)

explicit WebGLSyncJS(const ClientWebGLContext& webgl)
: webgl::ObjectJS(webgl) {}
Expand Down Expand Up @@ -705,15 +703,12 @@ struct TexImageSourceAdapter final : public TexImageSource {
*/
class ClientWebGLContext final : public nsICanvasRenderingContextInternal,
public nsWrapperCache,
public SupportsWeakPtr<ClientWebGLContext> {
public SupportsWeakPtr {
friend class webgl::AvailabilityRunnable;
friend class webgl::ObjectJS;
friend class webgl::ProgramKeepAlive;
friend class webgl::ShaderKeepAlive;

public:
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(ClientWebGLContext)

// ----------------------------- Lifetime and DOM ---------------------------
public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
Expand Down
4 changes: 1 addition & 3 deletions dom/canvas/HostWebGLContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ struct LockedOutstandingContexts final {
* nsICanvasRenderingContextInternal DOM class. That is the
* ClientWebGLContext.
*/
class HostWebGLContext final : public SupportsWeakPtr<HostWebGLContext> {
class HostWebGLContext final : public SupportsWeakPtr {
friend class WebGLContext;
friend class WebGLMemoryTracker;

Expand All @@ -77,8 +77,6 @@ class HostWebGLContext final : public SupportsWeakPtr<HostWebGLContext> {
}

public:
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(HostWebGLContext)

struct RemotingData final {
dom::WebGLParent& mParent;
UniquePtr<HostWebGLCommandSinkP> mCommandSinkP;
Expand Down
6 changes: 2 additions & 4 deletions dom/canvas/IpdlQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,13 +305,12 @@ class SyncConsumerActor : public AsyncConsumerActor<Derived> {
};

template <typename _Actor>
class IpdlProducer final : public SupportsWeakPtr<IpdlProducer<_Actor>> {
class IpdlProducer final : public SupportsWeakPtr {
nsTArray<uint8_t> mSerializedData;
WeakPtr<_Actor> mActor;
uint64_t mId;

public:
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(IpdlProducer<_Actor>)
using Actor = _Actor;
using SelfType = IpdlProducer<Actor>;

Expand Down Expand Up @@ -443,9 +442,8 @@ class IpdlProducer final : public SupportsWeakPtr<IpdlProducer<_Actor>> {
};

template <typename _Actor>
class IpdlConsumer final : public SupportsWeakPtr<IpdlConsumer<_Actor>> {
class IpdlConsumer final : public SupportsWeakPtr {
public:
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(IpdlConsumer<_Actor>)
using Actor = _Actor;
using SelfType = IpdlConsumer<Actor>;

Expand Down
4 changes: 1 addition & 3 deletions dom/canvas/ProducerConsumerQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class PcqConsumer;
* }
* Implementations of abstract methods will typically just forward to IProtocol.
*/
class PcqActor : public SupportsWeakPtr<PcqActor> {
class PcqActor : public SupportsWeakPtr {
// The IProtocol part of `this`.
IProtocol* mProtocol;

Expand Down Expand Up @@ -82,8 +82,6 @@ class PcqActor : public SupportsWeakPtr<PcqActor> {
}

public:
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(PcqActor)

Shmem::SharedMemory* LookupSharedMemory(int32_t aId) {
return mProtocol->LookupSharedMemory(aId);
}
Expand Down
5 changes: 1 addition & 4 deletions dom/canvas/WebGLChild.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,12 @@ struct FlushedCmdInfo final {
size_t flushedCmdBytes = 0;
};

class WebGLChild final : public PWebGLChild,
public SupportsWeakPtr<WebGLChild> {
class WebGLChild final : public PWebGLChild, public SupportsWeakPtr {
const WeakPtr<ClientWebGLContext> mContext;
webgl::RaiiShmem mPendingCmdsShmem;
size_t mPendingCmdsPos = 0;
FlushedCmdInfo mFlushedCmdInfo;

public:
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(WebGLChild)
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(WebGLChild, override);
using OtherSideActor = WebGLParent;

Expand Down
4 changes: 1 addition & 3 deletions dom/canvas/WebGLContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ struct BufferAndIndex final {

////////////////////////////////////////////////////////////////////////////////

class WebGLContext : public VRefCounted, public SupportsWeakPtr<WebGLContext> {
class WebGLContext : public VRefCounted, public SupportsWeakPtr {
friend class ScopedDrawCallWrapper;
friend class ScopedDrawWithTransformFeedback;
friend class ScopedFakeVertexAttrib0;
Expand Down Expand Up @@ -319,8 +319,6 @@ class WebGLContext : public VRefCounted, public SupportsWeakPtr<WebGLContext> {
mutable FuncScope* mFuncScope = nullptr;

public:
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(WebGLContext)

static RefPtr<WebGLContext> Create(HostWebGLContext&,
const webgl::InitContextDesc&,
webgl::InitContextResult* out);
Expand Down
5 changes: 1 addition & 4 deletions dom/canvas/WebGLContextLossHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,11 @@
namespace mozilla {
class WebGLContext;

class WebGLContextLossHandler final
: public SupportsWeakPtr<WebGLContextLossHandler> {
class WebGLContextLossHandler final : public SupportsWeakPtr {
RefPtr<Runnable> mRunnable;
Atomic<bool> mTimerIsScheduled;

public:
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(WebGLContextLossHandler)

explicit WebGLContextLossHandler(WebGLContext* webgl);
~WebGLContextLossHandler();

Expand Down
3 changes: 1 addition & 2 deletions dom/canvas/WebGLFramebuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,10 @@ class WebGLFBAttachPoint final {
};

class WebGLFramebuffer final : public WebGLContextBoundObject,
public SupportsWeakPtr<WebGLFramebuffer>,
public SupportsWeakPtr,
public CacheInvalidator {
public:
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(WebGLFramebuffer, override)
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(WebGLFramebuffer)

const GLuint mGLName;
bool mHasBeenBound = false;
Expand Down
3 changes: 1 addition & 2 deletions dom/canvas/WebGLParent.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ class SurfaceDescriptor;

namespace dom {

class WebGLParent : public PWebGLParent, public SupportsWeakPtr<WebGLParent> {
class WebGLParent : public PWebGLParent, public SupportsWeakPtr {
friend PWebGLParent;

public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(WebGLParent, override);
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(WebGLParent)
using OtherSideActor = WebGLChild;

mozilla::ipc::IPCResult RecvInitialize(
Expand Down
3 changes: 1 addition & 2 deletions dom/canvas/WebGLProgram.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,11 @@ struct LocationInfo final {
// -

struct LinkedProgramInfo final : public RefCounted<LinkedProgramInfo>,
public SupportsWeakPtr<LinkedProgramInfo>,
public SupportsWeakPtr,
public CacheInvalidator {
friend class mozilla::WebGLProgram;

MOZ_DECLARE_REFCOUNTED_TYPENAME(LinkedProgramInfo)
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(LinkedProgramInfo)

//////

Expand Down
9 changes: 3 additions & 6 deletions dom/geolocation/Geolocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,9 @@ using mozilla::Unused; // <snicker>
using namespace mozilla;
using namespace mozilla::dom;

class nsGeolocationRequest final
: public ContentPermissionRequestBase,
public nsIGeolocationUpdate,
public SupportsWeakPtr<nsGeolocationRequest> {
class nsGeolocationRequest final : public ContentPermissionRequestBase,
public nsIGeolocationUpdate,
public SupportsWeakPtr {
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIGEOLOCATIONUPDATE
Expand All @@ -86,8 +85,6 @@ class nsGeolocationRequest final
MOZ_CAN_RUN_SCRIPT NS_IMETHOD Cancel(void) override;
MOZ_CAN_RUN_SCRIPT NS_IMETHOD Allow(JS::HandleValue choices) override;

MOZ_DECLARE_WEAKREFERENCE_TYPENAME(nsGeolocationRequest)

void Shutdown();

// MOZ_CAN_RUN_SCRIPT_BOUNDARY is OK here because we're always called from a
Expand Down
9 changes: 2 additions & 7 deletions dom/html/HTMLCanvasElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,8 @@ class HTMLCanvasElementObserver final : public nsIObserver,
* will be given a copy of the just-painted canvas.
* All FrameCaptureListeners get the same copy.
*/
class FrameCaptureListener : public SupportsWeakPtr<FrameCaptureListener> {
class FrameCaptureListener : public SupportsWeakPtr {
public:
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(FrameCaptureListener)

FrameCaptureListener() : mFrameCaptureRequested(false) {}

/*
Expand Down Expand Up @@ -119,7 +117,7 @@ class FrameCaptureListener : public SupportsWeakPtr<FrameCaptureListener> {

class HTMLCanvasElement final : public nsGenericHTMLElement,
public CanvasRenderingContextHelper,
public SupportsWeakPtr<HTMLCanvasElement> {
public SupportsWeakPtr {
enum { DEFAULT_CANVAS_WIDTH = 300, DEFAULT_CANVAS_HEIGHT = 150 };

typedef layers::CanvasRenderer CanvasRenderer;
Expand All @@ -141,9 +139,6 @@ class HTMLCanvasElement final : public nsGenericHTMLElement,
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLCanvasElement,
nsGenericHTMLElement)

// WeakPtr
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(HTMLCanvasElement)

// WebIDL
uint32_t Height() {
return GetUnsignedIntAttr(nsGkAtoms::height, DEFAULT_CANVAS_HEIGHT);
Expand Down
3 changes: 1 addition & 2 deletions dom/html/HTMLMediaElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ enum class StreamCaptureBehavior : uint8_t {
class HTMLMediaElement : public nsGenericHTMLElement,
public MediaDecoderOwner,
public PrincipalChangeObserver<MediaStreamTrack>,
public SupportsWeakPtr<HTMLMediaElement>,
public SupportsWeakPtr,
public nsStubMutationObserver {
public:
typedef mozilla::TimeStamp TimeStamp;
Expand Down Expand Up @@ -134,7 +134,6 @@ class HTMLMediaElement : public nsGenericHTMLElement,
RefPtr<DOMMediaStream> mFinishWhenEndedAttrStream;
};

MOZ_DECLARE_WEAKREFERENCE_TYPENAME(HTMLMediaElement)
NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED

CORSMode GetCORSMode() { return mCORSMode; }
Expand Down
4 changes: 1 addition & 3 deletions dom/html/TextControlState.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,11 @@ class HTMLInputElement;

class RestoreSelectionState;

class TextControlState final : public SupportsWeakPtr<TextControlState> {
class TextControlState final : public SupportsWeakPtr {
public:
typedef dom::Element Element;
typedef dom::HTMLInputElement HTMLInputElement;

MOZ_DECLARE_WEAKREFERENCE_TYPENAME(TextControlState)

static TextControlState* Construct(TextControlElement* aOwningElement);

// Note that this does not run script actually because of `sHasShutDown`
Expand Down
4 changes: 1 addition & 3 deletions dom/ipc/ProcessHangMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,11 @@ class HangMonitoredProcess final : public nsIHangReport {
};

class HangMonitorParent : public PProcessHangMonitorParent,
public SupportsWeakPtr<HangMonitorParent> {
public SupportsWeakPtr {
public:
explicit HangMonitorParent(ProcessHangMonitor* aMonitor);
~HangMonitorParent() override;

MOZ_DECLARE_WEAKREFERENCE_TYPENAME(HangMonitorParent)

void Bind(Endpoint<PProcessHangMonitorParent>&& aEndpoint);

mozilla::ipc::IPCResult RecvHangEvidence(const HangData& aHangData) override;
Expand Down
Loading

0 comments on commit ff61891

Please sign in to comment.