From c50ccf8dba0683a55079bd585dccef30dd671d6c Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Wed, 30 Jul 2014 15:52:05 -0400 Subject: [PATCH] Bug 1044658 - 5/6 - remove asWeakPtr - r=froydnj --- content/base/src/nsDocument.cpp | 2 +- .../html/content/src/nsTextEditorState.cpp | 2 +- content/media/webaudio/AudioListener.cpp | 2 +- .../recognition/SpeechRecognition.cpp | 2 +- image/src/RasterImage.cpp | 4 ++-- image/src/RasterImage.h | 2 +- image/src/imgStatusTracker.cpp | 8 ++++---- ipc/glue/MessageChannel.cpp | 2 +- layout/base/nsDocumentViewer.cpp | 4 ++-- layout/base/nsPresContext.cpp | 2 +- mfbt/WeakPtr.h | 20 ++++--------------- mfbt/tests/TestWeakPtr.cpp | 10 +++++----- netwerk/sctp/datachannel/DataChannel.cpp | 2 +- uriloader/prefetch/nsOfflineCacheUpdate.cpp | 2 +- xpcom/base/nsMessageLoop.cpp | 2 +- 15 files changed, 27 insertions(+), 39 deletions(-) diff --git a/content/base/src/nsDocument.cpp b/content/base/src/nsDocument.cpp index c81e6c7ab9b1..4e147b33da62 100644 --- a/content/base/src/nsDocument.cpp +++ b/content/base/src/nsDocument.cpp @@ -4334,7 +4334,7 @@ void nsIDocument::SetContainer(nsDocShell* aContainer) { if (aContainer) { - mDocumentContainer = aContainer->asWeakPtr(); + mDocumentContainer = aContainer; } else { mDocumentContainer = WeakPtr(); } diff --git a/content/html/content/src/nsTextEditorState.cpp b/content/html/content/src/nsTextEditorState.cpp index 756a397f9c79..fcec80666a28 100644 --- a/content/html/content/src/nsTextEditorState.cpp +++ b/content/html/content/src/nsTextEditorState.cpp @@ -1042,7 +1042,7 @@ public: PrepareEditorEvent(nsTextEditorState &aState, nsIContent *aOwnerContent, const nsAString &aCurrentValue) - : mState(aState.asWeakPtr()) + : mState(&aState) , mOwnerContent(aOwnerContent) , mCurrentValue(aCurrentValue) { diff --git a/content/media/webaudio/AudioListener.cpp b/content/media/webaudio/AudioListener.cpp index a297f61b4ac7..e376c9d6da2c 100644 --- a/content/media/webaudio/AudioListener.cpp +++ b/content/media/webaudio/AudioListener.cpp @@ -72,7 +72,7 @@ AudioListener::SetOrientation(double aX, double aY, double aZ, void AudioListener::RegisterPannerNode(PannerNode* aPannerNode) { - mPanners.AppendElement(aPannerNode->asWeakPtr()); + mPanners.AppendElement(aPannerNode); // Let the panner node know about our parameters aPannerNode->SendThreeDPointParameterToStream(PannerNode::LISTENER_POSITION, mPosition); diff --git a/content/media/webspeech/recognition/SpeechRecognition.cpp b/content/media/webspeech/recognition/SpeechRecognition.cpp index fd147a444b33..d7b8e9150c91 100644 --- a/content/media/webspeech/recognition/SpeechRecognition.cpp +++ b/content/media/webspeech/recognition/SpeechRecognition.cpp @@ -700,7 +700,7 @@ SpeechRecognition::Start(const Optional>& aStream, Error mRecognitionService = do_GetService(speechRecognitionServiceCID.get(), &rv); NS_ENSURE_SUCCESS_VOID(rv); - rv = mRecognitionService->Initialize(this->asWeakPtr()); + rv = mRecognitionService->Initialize(this); NS_ENSURE_SUCCESS_VOID(rv); MediaStreamConstraints constraints; diff --git a/image/src/RasterImage.cpp b/image/src/RasterImage.cpp index 7ede9adbd146..6de6ce0afe2a 100644 --- a/image/src/RasterImage.cpp +++ b/image/src/RasterImage.cpp @@ -193,7 +193,7 @@ public: MOZ_ASSERT(!aSrcFrame->GetIsPaletted()); MOZ_ASSERT(aScale.width > 0 && aScale.height > 0); - weakImage = aImage->asWeakPtr(); + weakImage = aImage; srcRect = aSrcFrame->GetRect(); nsIntRect dstRect = srcRect; @@ -1041,7 +1041,7 @@ RasterImage::GetImageContainer(LayerManager* aManager, ImageContainer **_retval) // We only need to be careful about holding on to the image when it is // discardable by the OS. if (CanForciblyDiscardAndRedecode()) { - mImageContainerCache = mImageContainer->asWeakPtr(); + mImageContainerCache = mImageContainer; mImageContainer = nullptr; } diff --git a/image/src/RasterImage.h b/image/src/RasterImage.h index e16af7b2bbd4..7ef6ba224c24 100644 --- a/image/src/RasterImage.h +++ b/image/src/RasterImage.h @@ -813,7 +813,7 @@ class imgDecodeRequestor : public nsRunnable { public: imgDecodeRequestor(RasterImage &aContainer) { - mContainer = aContainer.asWeakPtr(); + mContainer = &aContainer; } NS_IMETHOD Run() { if (mContainer) diff --git a/image/src/imgStatusTracker.cpp b/image/src/imgStatusTracker.cpp index ceaa15235c82..cda73581c06b 100644 --- a/image/src/imgStatusTracker.cpp +++ b/image/src/imgStatusTracker.cpp @@ -24,7 +24,7 @@ class imgStatusTrackerObserver : public imgDecoderObserver { public: imgStatusTrackerObserver(imgStatusTracker* aTracker) - : mTracker(aTracker->asWeakPtr()) + : mTracker(aTracker) { MOZ_ASSERT(aTracker); } @@ -32,7 +32,7 @@ public: void SetTracker(imgStatusTracker* aTracker) { MOZ_ASSERT(aTracker); - mTracker = aTracker->asWeakPtr(); + mTracker = aTracker; } /** imgDecoderObserver methods **/ @@ -553,7 +553,7 @@ imgStatusTracker::SyncNotify(imgRequestProxy* proxy) } ProxyArray array; - array.AppendElement(proxy->asWeakPtr()); + array.AppendElement(proxy); SyncNotifyState(array, !!mImage, mState, r, mHadLastPart); } @@ -584,7 +584,7 @@ void imgStatusTracker::AddConsumer(imgRequestProxy* aConsumer) { MOZ_ASSERT(NS_IsMainThread()); - mConsumers.AppendElementUnlessExists(aConsumer->asWeakPtr()); + mConsumers.AppendElementUnlessExists(aConsumer); } // XXX - The last argument should go away. diff --git a/ipc/glue/MessageChannel.cpp b/ipc/glue/MessageChannel.cpp index bb01bcfcb31c..0455454b2d27 100644 --- a/ipc/glue/MessageChannel.cpp +++ b/ipc/glue/MessageChannel.cpp @@ -189,7 +189,7 @@ private: }; MessageChannel::MessageChannel(MessageListener *aListener) - : mListener(aListener->asWeakPtr()), + : mListener(aListener), mChannelState(ChannelClosed), mSide(UnknownSide), mLink(nullptr), diff --git a/layout/base/nsDocumentViewer.cpp b/layout/base/nsDocumentViewer.cpp index 4b1799537f84..204be23a885e 100644 --- a/layout/base/nsDocumentViewer.cpp +++ b/layout/base/nsDocumentViewer.cpp @@ -600,7 +600,7 @@ nsDocumentViewer::SyncParentSubDocMap() NS_IMETHODIMP nsDocumentViewer::SetContainer(nsIDocShell* aContainer) { - mContainer = static_cast(aContainer)->asWeakPtr(); + mContainer = static_cast(aContainer); if (mPresContext) { mPresContext->SetContainer(mContainer); } @@ -1537,7 +1537,7 @@ DetachContainerRecurse(nsIDocShell *aShell) nsCOMPtr presShell; viewer->GetPresShell(getter_AddRefs(presShell)); if (presShell) { - auto weakShell = static_cast(aShell)->asWeakPtr(); + auto weakShell = static_cast(aShell); presShell->SetForwardingContainer(weakShell); } } diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp index f645f8590926..05aad2c8971b 100644 --- a/layout/base/nsPresContext.cpp +++ b/layout/base/nsPresContext.cpp @@ -1516,7 +1516,7 @@ void nsPresContext::SetContainer(nsIDocShell* aDocShell) { if (aDocShell) { - mContainer = static_cast(aDocShell)->asWeakPtr(); + mContainer = static_cast(aDocShell); } else { mContainer = WeakPtr(); } diff --git a/mfbt/WeakPtr.h b/mfbt/WeakPtr.h index fa60f988cfb0..ebcb92506742 100644 --- a/mfbt/WeakPtr.h +++ b/mfbt/WeakPtr.h @@ -38,12 +38,12 @@ * * C* ptr = new C(); * - * // Get weak pointers to ptr. The first time asWeakPtr is called - * // a reference counted WeakReference object is created that + * // Get weak pointers to ptr. The first time a weak pointer + * // is obtained, a reference counted WeakReference object is created that * // can live beyond the lifetime of 'ptr'. The WeakReference * // object will be notified of 'ptr's destruction. - * WeakPtr weak = ptr->asWeakPtr(); - * WeakPtr other = ptr->asWeakPtr(); + * WeakPtr weak = ptr; + * WeakPtr other = ptr; * * // Test a weak pointer for validity before using it. * if (weak) { @@ -130,18 +130,6 @@ private: template class SupportsWeakPtr { -public: - - const T* asWeakPtr() const - { - return static_cast(this); - } - - T* asWeakPtr() - { - return static_cast(this); - } - protected: ~SupportsWeakPtr() { diff --git a/mfbt/tests/TestWeakPtr.cpp b/mfbt/tests/TestWeakPtr.cpp index cece96897efe..21a0db5dc85d 100644 --- a/mfbt/tests/TestWeakPtr.cpp +++ b/mfbt/tests/TestWeakPtr.cpp @@ -27,8 +27,8 @@ Example() // a reference counted WeakReference object is created that // can live beyond the lifetime of 'ptr'. The WeakReference // object will be notified of 'ptr's destruction. - WeakPtr weak = ptr->asWeakPtr(); - WeakPtr other = ptr->asWeakPtr(); + WeakPtr weak = ptr; + WeakPtr other = ptr; // Test a weak pointer for validity before using it. if (weak) { @@ -59,11 +59,11 @@ main() A* a2 = new A; a->mData = 5; - WeakPtr ptr = a->asWeakPtr(); + WeakPtr ptr = a; { - WeakPtr ptr2 = a->asWeakPtr(); + WeakPtr ptr2 = a; MOZ_RELEASE_ASSERT(ptr->mData == 5); - WeakPtr ptr3 = a->asWeakPtr(); + WeakPtr ptr3 = a; MOZ_RELEASE_ASSERT(ptr->mData == 5); } diff --git a/netwerk/sctp/datachannel/DataChannel.cpp b/netwerk/sctp/datachannel/DataChannel.cpp index 4551550508bb..76aa8e206279 100644 --- a/netwerk/sctp/datachannel/DataChannel.cpp +++ b/netwerk/sctp/datachannel/DataChannel.cpp @@ -200,7 +200,7 @@ DataChannelConnection::DataChannelConnection(DataConnectionListener *listener) : mState = CLOSED; mSocket = nullptr; mMasterSocket = nullptr; - mListener = listener->asWeakPtr(); + mListener = listener; mLocalPort = 0; mRemotePort = 0; mDeferTimeout = 10; diff --git a/uriloader/prefetch/nsOfflineCacheUpdate.cpp b/uriloader/prefetch/nsOfflineCacheUpdate.cpp index 7aafdcf4d09d..d881010d10cc 100644 --- a/uriloader/prefetch/nsOfflineCacheUpdate.cpp +++ b/uriloader/prefetch/nsOfflineCacheUpdate.cpp @@ -1985,7 +1985,7 @@ void nsOfflineCacheUpdate::SetOwner(nsOfflineCacheUpdateOwner *aOwner) { NS_ASSERTION(!mOwner, "Tried to set cache update owner twice."); - mOwner = aOwner->asWeakPtr(); + mOwner = aOwner; } bool diff --git a/xpcom/base/nsMessageLoop.cpp b/xpcom/base/nsMessageLoop.cpp index c7e9773489aa..a04ad8cfa819 100644 --- a/xpcom/base/nsMessageLoop.cpp +++ b/xpcom/base/nsMessageLoop.cpp @@ -121,7 +121,7 @@ MessageLoopIdleTask::Run() } MessageLoopTimerCallback::MessageLoopTimerCallback(MessageLoopIdleTask* aTask) - : mTask(aTask->asWeakPtr()) + : mTask(aTask) { }