Bug 1037691 - Fix instances where refcounted classes expose a public destructor. r=ehsan,bent,mayhemer,jrmuizel
authorBenoit Girard <b56girard@gmail.com>
Tue, 15 Jul 2014 11:37:45 -0400
changeset 194226 91a4d189f5d75a231be157f9be994b3b4b13f062
parent 194225 4530801b5e4603b50f14fc556395280f8ed748cf
child 194227 164c1eef200a181b02bb38759734b4720907177c
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersehsan, bent, mayhemer, jrmuizel
bugs1037691
milestone33.0a1
Bug 1037691 - Fix instances where refcounted classes expose a public destructor. r=ehsan,bent,mayhemer,jrmuizel
content/base/src/nsAttrValueInlines.h
content/base/src/nsDocument.cpp
content/media/AudioNodeExternalInputStream.h
content/media/AudioNodeStream.h
content/media/BufferMediaResource.h
content/media/FileBlockCache.h
content/media/MediaDataDecodedListener.h
content/media/MediaResource.cpp
content/media/mediasource/SourceBufferResource.h
content/media/ogg/OggReader.h
content/media/raw/RawReader.h
content/media/wave/WaveReader.h
content/media/webm/WebMReader.h
content/xul/templates/src/nsRuleNetwork.h
dom/archivereader/ArchiveEvent.h
dom/archivereader/ArchiveRequest.cpp
dom/archivereader/ArchiveZipEvent.h
dom/asmjscache/AsmJSCache.cpp
dom/base/nsGlobalWindow.cpp
dom/camera/DOMCameraControlListener.cpp
dom/promise/Promise.cpp
dom/src/storage/DOMStorageCache.h
gfx/layers/CopyableCanvasLayer.h
gfx/layers/basic/BasicColorLayer.cpp
gfx/layers/basic/BasicCompositor.h
gfx/layers/basic/BasicContainerLayer.h
gfx/layers/basic/BasicImageLayer.cpp
gfx/layers/basic/BasicLayers.h
gfx/layers/basic/BasicLayersImpl.h
gfx/layers/basic/BasicThebesLayer.h
gfx/layers/client/ClientCanvasLayer.h
gfx/layers/client/ClientColorLayer.cpp
gfx/layers/client/ClientContainerLayer.h
gfx/layers/client/ClientImageLayer.cpp
gfx/layers/client/ClientLayerManager.h
gfx/layers/client/ClientThebesLayer.h
gfx/layers/client/ClientTiledThebesLayer.h
gfx/layers/client/CompositableClient.h
gfx/layers/client/SimpleTiledContentClient.h
gfx/layers/client/TextureClient.h
gfx/layers/client/TiledContentClient.h
gfx/layers/composite/CanvasLayerComposite.h
gfx/layers/composite/ColorLayerComposite.h
gfx/layers/composite/ContainerLayerComposite.h
gfx/layers/composite/ImageLayerComposite.h
gfx/layers/composite/TextureHost.h
gfx/layers/composite/ThebesLayerComposite.h
gfx/layers/composite/TiledContentHost.h
gfx/layers/ipc/AsyncTransactionTracker.h
gfx/layers/ipc/LayerTransactionParent.h
gfx/layers/ipc/SharedPlanarYCbCrImage.h
gfx/layers/ipc/SharedRGBImage.h
gfx/layers/opengl/CompositorOGL.h
gfx/thebes/gfxBaseSharedMemorySurface.h
gfx/thebes/gfxReusableImageSurfaceWrapper.h
gfx/thebes/gfxReusableSharedImageSurfaceWrapper.h
ipc/glue/BackgroundChildImpl.cpp
ipc/glue/BackgroundParentImpl.cpp
layout/base/MaskLayerImageCache.cpp
layout/base/MaskLayerImageCache.h
layout/forms/nsComboboxControlFrame.cpp
netwerk/cache2/CacheEntry.h
netwerk/cache2/CacheFile.cpp
netwerk/cache2/CacheFileChunk.cpp
netwerk/cache2/CacheFileIOManager.cpp
netwerk/protocol/ftp/nsFtpConnectionThread.cpp
parser/html/nsHtml5OwningUTF16Buffer.h
rdf/base/src/nsInMemoryDataSource.cpp
widget/xpwidgets/nsBaseWidget.cpp
--- a/content/base/src/nsAttrValueInlines.h
+++ b/content/base/src/nsAttrValueInlines.h
@@ -4,16 +4,26 @@
 
 #ifndef nsAttrValueInlines_h__
 #define nsAttrValueInlines_h__
 
 #include <stdint.h>
 
 #include "nsAttrValue.h"
 
+struct MiscContainer;
+
+namespace mozilla {
+template<>
+struct HasDangerousPublicDestructor<MiscContainer>
+{
+  static const bool value = true;
+};
+}
+
 struct MiscContainer
 {
   typedef nsAttrValue::ValueType ValueType;
 
   ValueType mType;
   // mStringBits points to either nsIAtom* or nsStringBuffer* and is used when
   // mType isn't mCSSStyleRule.
   // Note eStringBase and eAtomBase is used also to handle the type of
@@ -88,17 +98,16 @@ struct MiscContainer
     MOZ_ASSERT(IsRefCounted());
     return --mValue.mRefCount;
   }
 
   void Cache();
   void Evict();
 };
 
-
 /**
  * Implementation of inline methods
  */
 
 inline int32_t
 nsAttrValue::GetIntegerValue() const
 {
   NS_PRECONDITION(Type() == eInteger, "wrong type");
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -1458,21 +1458,23 @@ class nsIDocument::SelectorCacheKeyDelet
 {
 public:
   explicit SelectorCacheKeyDeleter(SelectorCacheKey* aToDelete)
     : mSelector(aToDelete)
   {
     MOZ_COUNT_CTOR(SelectorCacheKeyDeleter);
   }
 
+protected:
   ~SelectorCacheKeyDeleter()
   {
     MOZ_COUNT_DTOR(SelectorCacheKeyDeleter);
   }
 
+public:
   NS_IMETHOD Run()
   {
     return NS_OK;
   }
 
 private:
   nsAutoPtr<SelectorCacheKey> mSelector;
 };
--- a/content/media/AudioNodeExternalInputStream.h
+++ b/content/media/AudioNodeExternalInputStream.h
@@ -19,18 +19,20 @@ namespace mozilla {
  * This is a MediaStream implementation that acts for a Web Audio node but
  * unlike other AudioNodeStreams, supports any kind of MediaStream as an
  * input --- handling any number of audio tracks, resampling them from whatever
  * sample rate they're using, and handling blocking of the input MediaStream.
  */
 class AudioNodeExternalInputStream : public AudioNodeStream {
 public:
   AudioNodeExternalInputStream(AudioNodeEngine* aEngine, TrackRate aSampleRate);
+protected:
   ~AudioNodeExternalInputStream();
 
+public:
   virtual void ProcessInput(GraphTime aFrom, GraphTime aTo, uint32_t aFlags) MOZ_OVERRIDE;
 
 private:
   // For storing pointers and data about input tracks, like the last TrackTick which
   // was read, and the associated speex resampler.
   struct TrackMapEntry {
     ~TrackMapEntry();
 
--- a/content/media/AudioNodeStream.h
+++ b/content/media/AudioNodeStream.h
@@ -60,18 +60,21 @@ public:
   {
     MOZ_ASSERT(NS_IsMainThread());
     mChannelCountMode = ChannelCountMode::Max;
     mChannelInterpretation = ChannelInterpretation::Speakers;
     // AudioNodes are always producing data
     mHasCurrentData = true;
     MOZ_COUNT_CTOR(AudioNodeStream);
   }
+
+protected:
   ~AudioNodeStream();
 
+public:
   // Control API
   /**
    * Sets a parameter that's a time relative to some stream's played time.
    * This time is converted to a time relative to this stream when it's set.
    */
   void SetStreamTimeParameter(uint32_t aIndex, AudioContext* aContext,
                               double aStreamTime);
   void SetDoubleParameter(uint32_t aIndex, double aValue);
--- a/content/media/BufferMediaResource.h
+++ b/content/media/BufferMediaResource.h
@@ -28,21 +28,23 @@ public:
     mLength(aLength),
     mOffset(0),
     mPrincipal(aPrincipal),
     mContentType(aContentType)
   {
     MOZ_COUNT_CTOR(BufferMediaResource);
   }
 
+protected:
   virtual ~BufferMediaResource()
   {
     MOZ_COUNT_DTOR(BufferMediaResource);
   }
 
+private:
   virtual nsresult Close() { return NS_OK; }
   virtual void Suspend(bool aCloseImmediately) {}
   virtual void Resume() {}
   // Get the current principal for the channel
   virtual already_AddRefed<nsIPrincipal> GetCurrentPrincipal()
   {
     nsCOMPtr<nsIPrincipal> principal = mPrincipal;
     return principal.forget();
--- a/content/media/FileBlockCache.h
+++ b/content/media/FileBlockCache.h
@@ -51,18 +51,20 @@ namespace mozilla {
 class FileBlockCache : public nsRunnable {
 public:
   enum {
     BLOCK_SIZE = MediaCacheStream::BLOCK_SIZE
   };
 
   FileBlockCache();
 
+protected:
   ~FileBlockCache();
 
+public:
   // Assumes ownership of aFD.
   nsresult Open(PRFileDesc* aFD);
 
   // Closes writer, shuts down thread.
   void Close();
 
   // Can be called on any thread. This defers to a non-main thread.
   nsresult WriteBlock(uint32_t aBlockIndex, const uint8_t* aData);
--- a/content/media/MediaDataDecodedListener.h
+++ b/content/media/MediaDataDecodedListener.h
@@ -99,20 +99,22 @@ private:
   class DeliverAudioTask : public nsRunnable {
   public:
     DeliverAudioTask(AudioData* aSample, Target* aTarget)
       : mSample(aSample)
       , mTarget(aTarget)
     {
       MOZ_COUNT_CTOR(DeliverAudioTask);
     }
+  protected:
     ~DeliverAudioTask()
     {
       MOZ_COUNT_DTOR(DeliverAudioTask);
     }
+  public:
     NS_METHOD Run() {
       mTarget->OnAudioDecoded(mSample.forget());
       return NS_OK;
     }
   private:
     nsAutoPtr<AudioData> mSample;
     RefPtr<Target> mTarget;
   };
@@ -120,20 +122,22 @@ private:
   class DeliverVideoTask : public nsRunnable {
   public:
     DeliverVideoTask(VideoData* aSample, Target* aTarget)
       : mSample(aSample)
       , mTarget(aTarget)
     {
       MOZ_COUNT_CTOR(DeliverVideoTask);
     }
+  protected:
     ~DeliverVideoTask()
     {
       MOZ_COUNT_DTOR(DeliverVideoTask);
     }
+  public:
     NS_METHOD Run() {
       mTarget->OnVideoDecoded(mSample.forget());
       return NS_OK;
     }
   private:
     nsAutoPtr<VideoData> mSample;
     RefPtr<Target> mTarget;
   };
--- a/content/media/MediaResource.cpp
+++ b/content/media/MediaResource.cpp
@@ -1634,21 +1634,23 @@ public:
                              int64_t aOffset)
     : mDecoder(aDecoder),
       mNumBytes(aNumBytes),
       mOffset(aOffset)
   {
     MOZ_COUNT_CTOR(DispatchBytesConsumedEvent);
   }
 
+protected:
   ~DispatchBytesConsumedEvent()
   {
     MOZ_COUNT_DTOR(DispatchBytesConsumedEvent);
   }
 
+public:
   NS_IMETHOD Run() {
     mDecoder->NotifyBytesConsumed(mNumBytes, mOffset);
     // Drop ref to decoder on main thread, just in case this reference
     // ends up being the last owning reference somehow.
     mDecoder = nullptr;
     return NS_OK;
   }
 
--- a/content/media/mediasource/SourceBufferResource.h
+++ b/content/media/mediasource/SourceBufferResource.h
@@ -187,18 +187,20 @@ private:
     // Logical offset into the resource of the first element
     // in the queue.
     uint64_t mOffset;
   };
 
 public:
   SourceBufferResource(nsIPrincipal* aPrincipal,
                        const nsACString& aType);
+protected:
   ~SourceBufferResource();
 
+public:
   virtual nsresult Close() MOZ_OVERRIDE;
   virtual void Suspend(bool aCloseImmediately) MOZ_OVERRIDE {}
   virtual void Resume() MOZ_OVERRIDE {}
 
   virtual already_AddRefed<nsIPrincipal> GetCurrentPrincipal() MOZ_OVERRIDE
   {
     return nsCOMPtr<nsIPrincipal>(mPrincipal).forget();
   }
--- a/content/media/ogg/OggReader.h
+++ b/content/media/ogg/OggReader.h
@@ -44,18 +44,21 @@ class OggCodecStore
     // Protects the |mCodecStates| and the |mKnownStreams| members.
     Monitor mMonitor;
 };
 
 class OggReader : public MediaDecoderReader
 {
 public:
   OggReader(AbstractMediaDecoder* aDecoder);
+
+protected:
   ~OggReader();
 
+public:
   virtual nsresult Init(MediaDecoderReader* aCloneDonor);
   virtual nsresult ResetDecode();
   virtual bool DecodeAudioData();
 
   // If the Theora granulepos has not been captured, it may read several packets
   // until one with a granulepos has been captured, to ensure that all packets
   // read have valid time info.
   virtual bool DecodeVideoFrame(bool &aKeyframeSkip,
--- a/content/media/raw/RawReader.h
+++ b/content/media/raw/RawReader.h
@@ -10,18 +10,21 @@
 #include "RawStructs.h"
 
 namespace mozilla {
 
 class RawReader : public MediaDecoderReader
 {
 public:
   RawReader(AbstractMediaDecoder* aDecoder);
+
+protected:
   ~RawReader();
 
+public:
   virtual nsresult Init(MediaDecoderReader* aCloneDonor);
   virtual nsresult ResetDecode();
   virtual bool DecodeAudioData();
 
   virtual bool DecodeVideoFrame(bool &aKeyframeSkip,
                                   int64_t aTimeThreshold);
 
   virtual bool HasAudio()
--- a/content/media/wave/WaveReader.h
+++ b/content/media/wave/WaveReader.h
@@ -16,18 +16,21 @@ class TimeRanges;
 }
 
 namespace mozilla {
 
 class WaveReader : public MediaDecoderReader
 {
 public:
   WaveReader(AbstractMediaDecoder* aDecoder);
+
+protected:
   ~WaveReader();
 
+public:
   virtual nsresult Init(MediaDecoderReader* aCloneDonor);
   virtual bool DecodeAudioData();
   virtual bool DecodeVideoFrame(bool &aKeyframeSkip,
                                   int64_t aTimeThreshold);
 
   virtual bool HasAudio()
   {
     return true;
--- a/content/media/webm/WebMReader.h
+++ b/content/media/webm/WebMReader.h
@@ -100,18 +100,21 @@ class WebMPacketQueue : private nsDeque 
     }
   }
 };
 
 class WebMReader : public MediaDecoderReader
 {
 public:
   WebMReader(AbstractMediaDecoder* aDecoder);
+
+protected:
   ~WebMReader();
 
+public:
   virtual nsresult Init(MediaDecoderReader* aCloneDonor);
   virtual nsresult ResetDecode();
   virtual bool DecodeAudioData();
 
   // If the Theora granulepos has not been captured, it may read several packets
   // until one with a granulepos has been captured, to ensure that all packets
   // read have valid time info.  
   virtual bool DecodeVideoFrame(bool &aKeyframeSkip,
--- a/content/xul/templates/src/nsRuleNetwork.h
+++ b/content/xul/templates/src/nsRuleNetwork.h
@@ -81,21 +81,23 @@ public:
     class ConstIterator;
     friend class ConstIterator;
 
 protected:
     class List {
     public:
         List() { MOZ_COUNT_CTOR(MemoryElementSet::List); }
 
+    protected:
         ~List() {
             MOZ_COUNT_DTOR(MemoryElementSet::List);
             delete mElement;
             NS_IF_RELEASE(mNext); }
 
+    public:
         int32_t AddRef() { return ++mRefCnt; }
 
         int32_t Release() {
             int32_t refcnt = --mRefCnt;
             if (refcnt == 0) delete this;
             return refcnt; }
 
         MemoryElement* mElement;
@@ -226,20 +228,23 @@ public:
     friend class ConstIterator;
 
 protected:
     class List {
     public:
         List(const nsAssignment &aAssignment) : mAssignment(aAssignment) {
             MOZ_COUNT_CTOR(nsAssignmentSet::List); }
 
+    protected:
         ~List() {
             MOZ_COUNT_DTOR(nsAssignmentSet::List);
             NS_IF_RELEASE(mNext); }
 
+    public:
+
         int32_t AddRef() { return ++mRefCnt; }
 
         int32_t Release() {
             int32_t refcnt = --mRefCnt;
             if (refcnt == 0) delete this;
             return refcnt; }
 
         nsAssignment mAssignment;
--- a/dom/archivereader/ArchiveEvent.h
+++ b/dom/archivereader/ArchiveEvent.h
@@ -51,18 +51,20 @@ protected:
  */
 class ArchiveReaderEvent : public nsRunnable
 {
 public:
   NS_DECL_NSIRUNNABLE
 
   ArchiveReaderEvent(ArchiveReader* aArchiveReader);
 
+protected:
   virtual ~ArchiveReaderEvent();
 
+public:
   // This must be implemented
   virtual nsresult Exec() = 0;
 
 protected:
   nsresult GetType(nsCString& aExt,
                    nsCString& aMimeType);
 
   nsresult RunShare(nsresult aStatus);
--- a/dom/archivereader/ArchiveRequest.cpp
+++ b/dom/archivereader/ArchiveRequest.cpp
@@ -24,16 +24,17 @@ public:
   NS_DECL_NSIRUNNABLE
 
   ArchiveRequestEvent(ArchiveRequest* request)
   : mRequest(request)
   {
     MOZ_COUNT_CTOR(ArchiveRequestEvent);
   }
 
+protected:
   ~ArchiveRequestEvent()
   {
     MOZ_COUNT_DTOR(ArchiveRequestEvent);
   }
 
 private: //data
   nsRefPtr<ArchiveRequest> mRequest;
 };
--- a/dom/archivereader/ArchiveZipEvent.h
+++ b/dom/archivereader/ArchiveZipEvent.h
@@ -19,18 +19,20 @@ BEGIN_ARCHIVEREADER_NAMESPACE
  * ArchiveZipItem - ArchiveItem for ArchiveReaderZipEvent
  */
 class ArchiveZipItem : public ArchiveItem
 {
 public:
   ArchiveZipItem(const char* aFilename,
                  const ZipCentral& aCentralStruct,
                  const nsACString& aEncoding);
+protected:
   virtual ~ArchiveZipItem();
 
+public:
   nsresult GetFilename(nsString& aFilename) MOZ_OVERRIDE;
 
   // From zipItem to DOMFile:
   virtual nsIDOMFile* File(ArchiveReader* aArchiveReader) MOZ_OVERRIDE;
 
 public: // for the event
   static uint32_t StrToInt32(const uint8_t* aStr);
   static uint16_t StrToInt16(const uint8_t* aStr);
--- a/dom/asmjscache/AsmJSCache.cpp
+++ b/dom/asmjscache/AsmJSCache.cpp
@@ -1111,16 +1111,17 @@ public:
   : MainProcessRunnable(aPrincipal, aOpenMode, aWriteParams),
     mReadParams(aReadParams)
   {
     MOZ_ASSERT(IsMainProcess());
     MOZ_ASSERT(!NS_IsMainThread());
     MOZ_COUNT_CTOR(SingleProcessRunnable);
   }
 
+protected:
   ~SingleProcessRunnable()
   {
     MOZ_COUNT_DTOR(SingleProcessRunnable);
   }
 
 private:
   void
   OnOpenMetadataForRead(const Metadata& aMetadata) MOZ_OVERRIDE
@@ -1365,16 +1366,17 @@ public:
     mActorDestroyed(false),
     mState(eInitial)
   {
     MOZ_ASSERT(!IsMainProcess());
     MOZ_ASSERT(!NS_IsMainThread());
     MOZ_COUNT_CTOR(ChildProcessRunnable);
   }
 
+protected:
   ~ChildProcessRunnable()
   {
     MOZ_ASSERT(mState == eFinished);
     MOZ_ASSERT(mActorDestroyed);
     MOZ_COUNT_DTOR(ChildProcessRunnable);
   }
 
 private:
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -7834,22 +7834,24 @@ class PostMessageEvent : public nsRunnab
     : mSource(aSource),
       mCallerOrigin(aCallerOrigin),
       mTargetWindow(aTargetWindow),
       mProvidedPrincipal(aProvidedPrincipal),
       mTrustedCaller(aTrustedCaller)
     {
       MOZ_COUNT_CTOR(PostMessageEvent);
     }
-    
+
+protected:
     ~PostMessageEvent()
     {
       MOZ_COUNT_DTOR(PostMessageEvent);
     }
 
+public:
     JSAutoStructuredCloneBuffer& Buffer()
     {
       return mBuffer;
     }
 
     bool StoreISupports(nsISupports* aSupports)
     {
       mSupportsArray.AppendElement(aSupports);
--- a/dom/camera/DOMCameraControlListener.cpp
+++ b/dom/camera/DOMCameraControlListener.cpp
@@ -31,21 +31,24 @@ DOMCameraControlListener::~DOMCameraCont
 class DOMCameraControlListener::DOMCallback : public nsRunnable
 {
 public:
   DOMCallback(nsMainThreadPtrHandle<nsDOMCameraControl> aDOMCameraControl)
     : mDOMCameraControl(aDOMCameraControl)
   {
     MOZ_COUNT_CTOR(DOMCameraControlListener::DOMCallback);
   }
+
+protected:
   virtual ~DOMCallback()
   {
     MOZ_COUNT_DTOR(DOMCameraControlListener::DOMCallback);
   }
 
+public:
   virtual void RunCallback(nsDOMCameraControl* aDOMCameraControl) = 0;
 
   NS_IMETHOD
   Run() MOZ_OVERRIDE
   {
     MOZ_ASSERT(NS_IsMainThread());
 
     nsRefPtr<nsDOMCameraControl> camera = mDOMCameraControl.get();
--- a/dom/promise/Promise.cpp
+++ b/dom/promise/Promise.cpp
@@ -38,21 +38,23 @@ class PromiseTask MOZ_FINAL : public nsR
 public:
   PromiseTask(Promise* aPromise)
     : mPromise(aPromise)
   {
     MOZ_ASSERT(aPromise);
     MOZ_COUNT_CTOR(PromiseTask);
   }
 
+protected:
   ~PromiseTask()
   {
     MOZ_COUNT_DTOR(PromiseTask);
   }
 
+public:
   NS_IMETHOD Run()
   {
     mPromise->mTaskPending = false;
     mPromise->RunTask();
     return NS_OK;
   }
 
 private:
@@ -65,21 +67,23 @@ public:
   WorkerPromiseTask(WorkerPrivate* aWorkerPrivate, Promise* aPromise)
     : WorkerSameThreadRunnable(aWorkerPrivate)
     , mPromise(aPromise)
   {
     MOZ_ASSERT(aPromise);
     MOZ_COUNT_CTOR(WorkerPromiseTask);
   }
 
+protected:
   ~WorkerPromiseTask()
   {
     MOZ_COUNT_DTOR(WorkerPromiseTask);
   }
 
+public:
   bool
   WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate)
   {
     mPromise->mTaskPending = false;
     mPromise->RunTask();
     return true;
   }
 
--- a/dom/src/storage/DOMStorageCache.h
+++ b/dom/src/storage/DOMStorageCache.h
@@ -65,18 +65,21 @@ protected:
 // private and session-only cookie modes.  It is also responsible for
 // persisting data changes using the database, works as a write-back cache.
 class DOMStorageCache : public DOMStorageCacheBridge
 {
 public:
   NS_IMETHOD_(void) Release(void);
 
   DOMStorageCache(const nsACString* aScope);
+
+protected:
   virtual ~DOMStorageCache();
 
+public:
   void Init(DOMStorageManager* aManager, bool aPersistent, nsIPrincipal* aPrincipal,
             const nsACString& aQuotaScope);
 
   // Copies all data from the other storage.
   void CloneFrom(const DOMStorageCache* aThat);
 
   // Starts async preload of this cache if it persistent and not loaded.
   void Preload();
--- a/gfx/layers/CopyableCanvasLayer.h
+++ b/gfx/layers/CopyableCanvasLayer.h
@@ -32,18 +32,21 @@ class CanvasClientWebGL;
 /**
  * A shared CanvasLayer implementation that supports copying
  * its contents into a gfxASurface using UpdateSurface.
  */
 class CopyableCanvasLayer : public CanvasLayer
 {
 public:
   CopyableCanvasLayer(LayerManager* aLayerManager, void *aImplData);
+
+protected:
   virtual ~CopyableCanvasLayer();
 
+public:
   virtual void Initialize(const Data& aData);
 
   virtual bool IsDataValid(const Data& aData);
 
   bool IsGLLayer() { return !!mGLContext; }
 
 protected:
   void UpdateTarget(gfx::DrawTarget* aDestTarget = nullptr);
--- a/gfx/layers/basic/BasicColorLayer.cpp
+++ b/gfx/layers/basic/BasicColorLayer.cpp
@@ -27,21 +27,24 @@ namespace layers {
 class BasicColorLayer : public ColorLayer, public BasicImplData {
 public:
   BasicColorLayer(BasicLayerManager* aLayerManager) :
     ColorLayer(aLayerManager,
                static_cast<BasicImplData*>(MOZ_THIS_IN_INITIALIZER_LIST()))
   {
     MOZ_COUNT_CTOR(BasicColorLayer);
   }
+
+protected:
   virtual ~BasicColorLayer()
   {
     MOZ_COUNT_DTOR(BasicColorLayer);
   }
 
+public:
   virtual void SetVisibleRegion(const nsIntRegion& aRegion)
   {
     NS_ASSERTION(BasicManager()->InConstruction(),
                  "Can only set properties in construction phase");
     ColorLayer::SetVisibleRegion(aRegion);
   }
 
   virtual void Paint(DrawTarget* aDT,
--- a/gfx/layers/basic/BasicCompositor.h
+++ b/gfx/layers/basic/BasicCompositor.h
@@ -37,19 +37,20 @@ public:
   gfx::IntSize mSize;
 };
 
 class BasicCompositor : public Compositor
 {
 public:
   BasicCompositor(nsIWidget *aWidget);
 
+protected:
   virtual ~BasicCompositor();
 
-
+public:
   virtual bool Initialize() MOZ_OVERRIDE { return true; };
 
   virtual void Destroy() MOZ_OVERRIDE;
 
   virtual TextureFactoryIdentifier GetTextureFactoryIdentifier() MOZ_OVERRIDE
   {
     return TextureFactoryIdentifier(LayersBackend::LAYERS_BASIC,
                                     XRE_GetProcessType(),
--- a/gfx/layers/basic/BasicContainerLayer.h
+++ b/gfx/layers/basic/BasicContainerLayer.h
@@ -21,18 +21,20 @@ class BasicContainerLayer : public Conta
 public:
   BasicContainerLayer(BasicLayerManager* aManager) :
     ContainerLayer(aManager,
                    static_cast<BasicImplData*>(MOZ_THIS_IN_INITIALIZER_LIST()))
   {
     MOZ_COUNT_CTOR(BasicContainerLayer);
     mSupportsComponentAlphaChildren = true;
   }
+protected:
   virtual ~BasicContainerLayer();
 
+public:
   virtual void SetVisibleRegion(const nsIntRegion& aRegion)
   {
     NS_ASSERTION(BasicManager()->InConstruction(),
                  "Can only set properties in construction phase");
     ContainerLayer::SetVisibleRegion(aRegion);
   }
   virtual bool InsertAfter(Layer* aChild, Layer* aAfter)
   {
--- a/gfx/layers/basic/BasicImageLayer.cpp
+++ b/gfx/layers/basic/BasicImageLayer.cpp
@@ -27,21 +27,23 @@ class BasicImageLayer : public ImageLaye
 public:
   BasicImageLayer(BasicLayerManager* aLayerManager) :
     ImageLayer(aLayerManager,
                static_cast<BasicImplData*>(MOZ_THIS_IN_INITIALIZER_LIST())),
     mSize(-1, -1)
   {
     MOZ_COUNT_CTOR(BasicImageLayer);
   }
+protected:
   virtual ~BasicImageLayer()
   {
     MOZ_COUNT_DTOR(BasicImageLayer);
   }
 
+public:
   virtual void SetVisibleRegion(const nsIntRegion& aRegion)
   {
     NS_ASSERTION(BasicManager()->InConstruction(),
                  "Can only set properties in construction phase");
     ImageLayer::SetVisibleRegion(aRegion);
   }
 
   virtual void Paint(DrawTarget* aDT,
--- a/gfx/layers/basic/BasicLayers.h
+++ b/gfx/layers/basic/BasicLayers.h
@@ -68,18 +68,21 @@ public:
    * to the passed-in context if there is no widget and no default
    * target context.
    * 
    * This does not keep a strong reference to the widget, so the caller
    * must ensure that the widget outlives the layer manager or call
    * ClearWidget before the widget dies.
    */
   BasicLayerManager(nsIWidget* aWidget);
+
+protected:
   virtual ~BasicLayerManager();
 
+public:
   /**
    * Set the default target context that will be used when BeginTransaction
    * is called. This can only be called outside a transaction.
    * 
    * aDoubleBuffering can request double-buffering for drawing to the
    * default target. When BUFFERED, the layer manager avoids blitting
    * temporary results to aContext and then overpainting them with final
    * results, by using a temporary buffer when necessary. In BUFFERED
--- a/gfx/layers/basic/BasicLayersImpl.h
+++ b/gfx/layers/basic/BasicLayersImpl.h
@@ -50,21 +50,24 @@ class BasicReadbackLayer : public Readba
 {
 public:
   BasicReadbackLayer(BasicLayerManager* aLayerManager) :
     ReadbackLayer(aLayerManager,
                   static_cast<BasicImplData*>(MOZ_THIS_IN_INITIALIZER_LIST()))
   {
     MOZ_COUNT_CTOR(BasicReadbackLayer);
   }
+
+protected:
   virtual ~BasicReadbackLayer()
   {
     MOZ_COUNT_DTOR(BasicReadbackLayer);
   }
 
+public:
   virtual void SetVisibleRegion(const nsIntRegion& aRegion)
   {
     NS_ASSERTION(BasicManager()->InConstruction(),
                  "Can only set properties in construction phase");
     ReadbackLayer::SetVisibleRegion(aRegion);
   }
 
 protected:
--- a/gfx/layers/basic/BasicThebesLayer.h
+++ b/gfx/layers/basic/BasicThebesLayer.h
@@ -32,21 +32,24 @@ public:
 
   BasicThebesLayer(BasicLayerManager* aLayerManager) :
     ThebesLayer(aLayerManager,
                 static_cast<BasicImplData*>(MOZ_THIS_IN_INITIALIZER_LIST())),
     mContentClient(nullptr)
   {
     MOZ_COUNT_CTOR(BasicThebesLayer);
   }
+
+protected:
   virtual ~BasicThebesLayer()
   {
     MOZ_COUNT_DTOR(BasicThebesLayer);
   }
 
+public:
   virtual void SetVisibleRegion(const nsIntRegion& aRegion)
   {
     NS_ASSERTION(BasicManager()->InConstruction(),
                  "Can only set properties in construction phase");
     ThebesLayer::SetVisibleRegion(aRegion);
   }
   virtual void InvalidateRegion(const nsIntRegion& aRegion)
   {
--- a/gfx/layers/client/ClientCanvasLayer.h
+++ b/gfx/layers/client/ClientCanvasLayer.h
@@ -39,18 +39,21 @@ public:
   ClientCanvasLayer(ClientLayerManager* aLayerManager) :
     CopyableCanvasLayer(aLayerManager,
                         static_cast<ClientLayer*>(MOZ_THIS_IN_INITIALIZER_LIST()))
     , mTextureSurface(nullptr)
     , mFactory(nullptr)
   {
     MOZ_COUNT_CTOR(ClientCanvasLayer);
   }
+
+protected:
   virtual ~ClientCanvasLayer();
 
+public:
   virtual void SetVisibleRegion(const nsIntRegion& aRegion)
   {
     NS_ASSERTION(ClientManager()->InConstruction(),
                  "Can only set properties in construction phase");
     CanvasLayer::SetVisibleRegion(aRegion);
   }
 
   virtual void Initialize(const Data& aData);
--- a/gfx/layers/client/ClientColorLayer.cpp
+++ b/gfx/layers/client/ClientColorLayer.cpp
@@ -22,21 +22,24 @@ class ClientColorLayer : public ColorLay
                          public ClientLayer {
 public:
   ClientColorLayer(ClientLayerManager* aLayerManager) :
     ColorLayer(aLayerManager,
                static_cast<ClientLayer*>(MOZ_THIS_IN_INITIALIZER_LIST()))
   {
     MOZ_COUNT_CTOR(ClientColorLayer);
   }
+
+protected:
   virtual ~ClientColorLayer()
   {
     MOZ_COUNT_DTOR(ClientColorLayer);
   }
 
+public:
   virtual void SetVisibleRegion(const nsIntRegion& aRegion)
   {
     NS_ASSERTION(ClientManager()->InConstruction(),
                  "Can only set properties in construction phase");
     ColorLayer::SetVisibleRegion(aRegion);
   }
 
   virtual void RenderLayer()
--- a/gfx/layers/client/ClientContainerLayer.h
+++ b/gfx/layers/client/ClientContainerLayer.h
@@ -27,25 +27,28 @@ class ClientContainerLayer : public Cont
 public:
   ClientContainerLayer(ClientLayerManager* aManager) :
     ContainerLayer(aManager,
                    static_cast<ClientLayer*>(MOZ_THIS_IN_INITIALIZER_LIST()))
   {
     MOZ_COUNT_CTOR(ClientContainerLayer);
     mSupportsComponentAlphaChildren = true;
   }
+
+protected:
   virtual ~ClientContainerLayer()
   {
     while (mFirstChild) {
       ContainerLayer::RemoveChild(mFirstChild);
     }
 
     MOZ_COUNT_DTOR(ClientContainerLayer);
   }
 
+public:
   virtual void RenderLayer()
   {
     if (GetMaskLayer()) {
       ToClientLayer(GetMaskLayer())->RenderLayer();
     }
     
     DefaultComputeSupportsComponentAlphaChildren();
 
@@ -143,21 +146,24 @@ class ClientRefLayer : public RefLayer,
                        public ClientLayer {
 public:
   ClientRefLayer(ClientLayerManager* aManager) :
     RefLayer(aManager,
              static_cast<ClientLayer*>(MOZ_THIS_IN_INITIALIZER_LIST()))
   {
     MOZ_COUNT_CTOR(ClientRefLayer);
   }
+
+protected:
   virtual ~ClientRefLayer()
   {
     MOZ_COUNT_DTOR(ClientRefLayer);
   }
 
+public:
   virtual Layer* AsLayer() { return this; }
   virtual ShadowableLayer* AsShadowableLayer() { return this; }
 
   virtual void Disconnect()
   {
     ClientLayer::Disconnect();
   }
 
--- a/gfx/layers/client/ClientImageLayer.cpp
+++ b/gfx/layers/client/ClientImageLayer.cpp
@@ -28,22 +28,24 @@ class ClientImageLayer : public ImageLay
 public:
   ClientImageLayer(ClientLayerManager* aLayerManager)
     : ImageLayer(aLayerManager,
                  static_cast<ClientLayer*>(MOZ_THIS_IN_INITIALIZER_LIST()))
     , mImageClientTypeContainer(CompositableType::BUFFER_UNKNOWN)
   {
     MOZ_COUNT_CTOR(ClientImageLayer);
   }
+
+protected:
   virtual ~ClientImageLayer()
   {
     DestroyBackBuffer();
     MOZ_COUNT_DTOR(ClientImageLayer);
   }
-  
+
   virtual void SetContainer(ImageContainer* aContainer) MOZ_OVERRIDE
   {
     ImageLayer::SetContainer(aContainer);
     mImageClientTypeContainer = CompositableType::BUFFER_UNKNOWN;
   }
 
   virtual void SetVisibleRegion(const nsIntRegion& aRegion)
   {
--- a/gfx/layers/client/ClientLayerManager.h
+++ b/gfx/layers/client/ClientLayerManager.h
@@ -39,18 +39,21 @@ class TextureClientPool;
 class SimpleTextureClientPool;
 
 class ClientLayerManager : public LayerManager
 {
   typedef nsTArray<nsRefPtr<Layer> > LayerRefArray;
 
 public:
   ClientLayerManager(nsIWidget* aWidget);
+
+protected:
   virtual ~ClientLayerManager();
 
+public:
   virtual ShadowLayerForwarder* AsShadowForwarder()
   {
     return mForwarder;
   }
 
   virtual ClientLayerManager* AsClientLayerManager()
   {
     return this;
--- a/gfx/layers/client/ClientThebesLayer.h
+++ b/gfx/layers/client/ClientThebesLayer.h
@@ -37,25 +37,28 @@ public:
                     LayerManager::ThebesLayerCreationHint aCreationHint = LayerManager::NONE) :
     ThebesLayer(aLayerManager,
                 static_cast<ClientLayer*>(MOZ_THIS_IN_INITIALIZER_LIST()),
                 aCreationHint),
     mContentClient(nullptr)
   {
     MOZ_COUNT_CTOR(ClientThebesLayer);
   }
+
+protected:
   virtual ~ClientThebesLayer()
   {
     if (mContentClient) {
       mContentClient->OnDetach();
       mContentClient = nullptr;
     }
     MOZ_COUNT_DTOR(ClientThebesLayer);
   }
 
+public:
   virtual void SetVisibleRegion(const nsIntRegion& aRegion)
   {
     NS_ASSERTION(ClientManager()->InConstruction(),
                  "Can only set properties in construction phase");
     ThebesLayer::SetVisibleRegion(aRegion);
   }
   virtual void InvalidateRegion(const nsIntRegion& aRegion)
   {
--- a/gfx/layers/client/ClientTiledThebesLayer.h
+++ b/gfx/layers/client/ClientTiledThebesLayer.h
@@ -38,18 +38,21 @@ class SpecificLayerAttributes;
 class ClientTiledThebesLayer : public ThebesLayer,
                                public ClientLayer
 {
   typedef ThebesLayer Base;
 
 public:
   ClientTiledThebesLayer(ClientLayerManager* const aManager,
                          ClientLayerManager::ThebesLayerCreationHint aCreationHint = LayerManager::NONE);
+
+protected:
   ~ClientTiledThebesLayer();
 
+public:
   // Override name to distinguish it from ClientThebesLayer in layer dumps
   virtual const char* Name() const { return "TiledThebesLayer"; }
 
   // Thebes Layer
   virtual Layer* AsLayer() { return this; }
   virtual void InvalidateRegion(const nsIntRegion& aRegion) {
     mInvalidRegion.Or(mInvalidRegion, aRegion);
     mValidRegion.Sub(mValidRegion, aRegion);
--- a/gfx/layers/client/CompositableClient.h
+++ b/gfx/layers/client/CompositableClient.h
@@ -34,22 +34,24 @@ class PCompositableChild;
  */
 class RemoveTextureFromCompositableTracker : public AsyncTransactionTracker {
 public:
   RemoveTextureFromCompositableTracker()
   {
     MOZ_COUNT_CTOR(RemoveTextureFromCompositableTracker);
   }
 
+protected:
   ~RemoveTextureFromCompositableTracker()
   {
     MOZ_COUNT_DTOR(RemoveTextureFromCompositableTracker);
     ReleaseTextureClient();
   }
 
+public:
   virtual void Complete() MOZ_OVERRIDE
   {
     ReleaseTextureClient();
   }
 
   virtual void Cancel() MOZ_OVERRIDE
   {
     ReleaseTextureClient();
--- a/gfx/layers/client/SimpleTiledContentClient.h
+++ b/gfx/layers/client/SimpleTiledContentClient.h
@@ -135,16 +135,17 @@ private:
 class SimpleTiledContentClient : public CompositableClient
 {
   friend class SimpleClientTiledThebesLayer;
 
 public:
   SimpleTiledContentClient(SimpleClientTiledThebesLayer* aThebesLayer,
                            ClientLayerManager* aManager);
 
+private:
   ~SimpleTiledContentClient();
 
   virtual TextureInfo GetTextureInfo() const MOZ_OVERRIDE
   {
     return TextureInfo(CompositableType::BUFFER_SIMPLE_TILED);
   }
 
   void UseTiledLayerBuffer();
@@ -156,18 +157,20 @@ private:
 class SimpleClientTiledThebesLayer : public ThebesLayer,
                                      public ClientLayer
 {
   typedef ThebesLayer Base;
 
 public:
   SimpleClientTiledThebesLayer(ClientLayerManager* const aManager,
                                ClientLayerManager::ThebesLayerCreationHint aCreationHint = LayerManager::NONE);
+protected:
   ~SimpleClientTiledThebesLayer();
 
+public:
   // Thebes Layer
   virtual Layer* AsLayer() { return this; }
   virtual void InvalidateRegion(const nsIntRegion& aRegion) {
     mInvalidRegion.Or(mInvalidRegion, aRegion);
     mValidRegion.Sub(mValidRegion, aRegion);
   }
 
   // Shadow methods
--- a/gfx/layers/client/TextureClient.h
+++ b/gfx/layers/client/TextureClient.h
@@ -495,18 +495,20 @@ protected:
  * the corresponding texture on the host side is ShmemTextureHost.
  */
 class ShmemTextureClient : public BufferTextureClient
 {
 public:
   ShmemTextureClient(ISurfaceAllocator* aAllocator, gfx::SurfaceFormat aFormat,
                      gfx::BackendType aBackend, TextureFlags aFlags);
 
+protected:
   ~ShmemTextureClient();
 
+public:
   virtual bool ToSurfaceDescriptor(SurfaceDescriptor& aDescriptor) MOZ_OVERRIDE;
 
   virtual bool Allocate(uint32_t aSize) MOZ_OVERRIDE;
 
   virtual uint8_t* GetBuffer() const MOZ_OVERRIDE;
 
   virtual size_t GetBufferSize() const MOZ_OVERRIDE;
 
@@ -527,18 +529,20 @@ protected:
  * Can obviously not be used in a cross process setup.
  */
 class MemoryTextureClient : public BufferTextureClient
 {
 public:
   MemoryTextureClient(ISurfaceAllocator* aAllocator, gfx::SurfaceFormat aFormat,
                       gfx::BackendType aBackend, TextureFlags aFlags);
 
+protected:
   ~MemoryTextureClient();
 
+public:
   virtual bool ToSurfaceDescriptor(SurfaceDescriptor& aDescriptor) MOZ_OVERRIDE;
 
   virtual bool Allocate(uint32_t aSize) MOZ_OVERRIDE;
 
   virtual uint8_t* GetBuffer() const MOZ_OVERRIDE { return mBuffer; }
 
   virtual size_t GetBufferSize() const MOZ_OVERRIDE { return mBufSize; }
 
@@ -554,18 +558,20 @@ protected:
 /**
  * A TextureClient implementation to share SurfaceStream.
  */
 class StreamTextureClient : public TextureClient
 {
 public:
   StreamTextureClient(TextureFlags aFlags);
 
+protected:
   ~StreamTextureClient();
 
+public:
   virtual bool IsAllocated() const MOZ_OVERRIDE;
 
   virtual bool Lock(OpenMode mode) MOZ_OVERRIDE;
 
   virtual void Unlock() MOZ_OVERRIDE;
 
   virtual bool IsLocked() const MOZ_OVERRIDE { return mIsLocked; }
 
--- a/gfx/layers/client/TiledContentClient.h
+++ b/gfx/layers/client/TiledContentClient.h
@@ -67,18 +67,20 @@ public:
 protected:
   NS_DECL_OWNINGTHREAD
 };
 
 class gfxMemorySharedReadLock : public gfxSharedReadLock {
 public:
   gfxMemorySharedReadLock();
 
+protected:
   ~gfxMemorySharedReadLock();
 
+public:
   virtual int32_t ReadLock() MOZ_OVERRIDE;
 
   virtual int32_t ReadUnlock() MOZ_OVERRIDE;
 
   virtual int32_t GetReadCount() MOZ_OVERRIDE;
 
   virtual gfxSharedReadLockType GetType() MOZ_OVERRIDE { return TYPE_MEMORY; }
 
@@ -92,18 +94,20 @@ class gfxShmSharedReadLock : public gfxS
 private:
   struct ShmReadLockInfo {
     int32_t readCount;
   };
 
 public:
   gfxShmSharedReadLock(ISurfaceAllocator* aAllocator);
 
+protected:
   ~gfxShmSharedReadLock();
 
+public:
   virtual int32_t ReadLock() MOZ_OVERRIDE;
 
   virtual int32_t ReadUnlock() MOZ_OVERRIDE;
 
   virtual int32_t GetReadCount() MOZ_OVERRIDE;
 
   virtual bool IsValid() const MOZ_OVERRIDE { return mAllocSuccess; };
 
@@ -460,24 +464,26 @@ class TiledContentClient : public Compos
   // own valid region, resolution, etc. Then we could have a much cleaner
   // interface and tidy up BasicTiledThebesLayer::PaintThebes (bug 862547).
   friend class ClientTiledThebesLayer;
 
 public:
   TiledContentClient(ClientTiledThebesLayer* aThebesLayer,
                      ClientLayerManager* aManager);
 
+protected:
   ~TiledContentClient()
   {
     MOZ_COUNT_DTOR(TiledContentClient);
 
     mTiledBuffer.Release();
     mLowPrecisionTiledBuffer.Release();
   }
 
+public:
   virtual TextureInfo GetTextureInfo() const MOZ_OVERRIDE
   {
     return TextureInfo(CompositableType::BUFFER_TILED);
   }
 
   virtual void ClearCachedResources() MOZ_OVERRIDE;
 
   enum TiledBufferType {
--- a/gfx/layers/composite/CanvasLayerComposite.h
+++ b/gfx/layers/composite/CanvasLayerComposite.h
@@ -25,18 +25,20 @@ class CompositableHost;
 class ImageHost;
 
 class CanvasLayerComposite : public CanvasLayer,
                              public LayerComposite
 {
 public:
   CanvasLayerComposite(LayerManagerComposite* aManager);
 
+protected:
   virtual ~CanvasLayerComposite();
 
+public:
   // CanvasLayer impl
   virtual void Initialize(const Data& aData) MOZ_OVERRIDE
   {
     NS_RUNTIMEABORT("Incompatibe surface type");
   }
 
   virtual LayerRenderState GetRenderState() MOZ_OVERRIDE;
 
--- a/gfx/layers/composite/ColorLayerComposite.h
+++ b/gfx/layers/composite/ColorLayerComposite.h
@@ -25,22 +25,25 @@ class ColorLayerComposite : public Color
 public:
   ColorLayerComposite(LayerManagerComposite *aManager)
     : ColorLayer(aManager, nullptr)
     , LayerComposite(aManager)
   {
     MOZ_COUNT_CTOR(ColorLayerComposite);
     mImplData = static_cast<LayerComposite*>(this);
   }
+
+protected:
   ~ColorLayerComposite()
   {
     MOZ_COUNT_DTOR(ColorLayerComposite);
     Destroy();
   }
 
+public:
   // LayerComposite Implementation
   virtual Layer* GetLayer() MOZ_OVERRIDE { return this; }
 
   virtual void Destroy() MOZ_OVERRIDE { mDestroyed = true; }
 
   virtual void RenderLayer(const nsIntRect& aClipRect) MOZ_OVERRIDE;
   virtual void CleanupResources() MOZ_OVERRIDE {};
 
--- a/gfx/layers/composite/ContainerLayerComposite.h
+++ b/gfx/layers/composite/ContainerLayerComposite.h
@@ -23,18 +23,20 @@ class ContainerLayerComposite : public C
 {
   template<class ContainerT>
   friend void ContainerRender(ContainerT* aContainer,
                               LayerManagerComposite* aManager,
                               const nsIntRect& aClipRect);
 public:
   ContainerLayerComposite(LayerManagerComposite *aManager);
 
+protected:
   ~ContainerLayerComposite();
 
+public:
   // LayerComposite Implementation
   virtual Layer* GetLayer() MOZ_OVERRIDE { return this; }
 
   virtual void Destroy() MOZ_OVERRIDE;
 
   LayerComposite* GetFirstChildComposite();
 
   virtual void RenderLayer(const nsIntRect& aClipRect) MOZ_OVERRIDE;
@@ -58,18 +60,21 @@ class RefLayerComposite : public RefLaye
                           public LayerComposite
 {
   template<class ContainerT>
   friend void ContainerRender(ContainerT* aContainer,
                               LayerManagerComposite* aManager,
                               const nsIntRect& aClipRect);
 public:
   RefLayerComposite(LayerManagerComposite *aManager);
+
+protected:
   ~RefLayerComposite();
 
+public:
   /** LayerOGL implementation */
   Layer* GetLayer() MOZ_OVERRIDE { return this; }
 
   void Destroy() MOZ_OVERRIDE;
 
   LayerComposite* GetFirstChildComposite();
 
   virtual void RenderLayer(const nsIntRect& aClipRect) MOZ_OVERRIDE;
--- a/gfx/layers/composite/ImageLayerComposite.h
+++ b/gfx/layers/composite/ImageLayerComposite.h
@@ -28,18 +28,20 @@ class Layer;
 class ImageLayerComposite : public ImageLayer,
                             public LayerComposite
 {
   typedef gl::TextureImage TextureImage;
 
 public:
   ImageLayerComposite(LayerManagerComposite* aManager);
 
+protected:
   virtual ~ImageLayerComposite();
 
+public:
   virtual LayerRenderState GetRenderState() MOZ_OVERRIDE;
 
   virtual void Disconnect() MOZ_OVERRIDE;
 
   virtual bool SetCompositableHost(CompositableHost* aHost) MOZ_OVERRIDE;
 
   virtual Layer* GetLayer() MOZ_OVERRIDE;
 
--- a/gfx/layers/composite/TextureHost.h
+++ b/gfx/layers/composite/TextureHost.h
@@ -143,21 +143,23 @@ protected:
  */
 class NewTextureSource : public TextureSource
 {
 public:
   NewTextureSource()
   {
     MOZ_COUNT_CTOR(NewTextureSource);
   }
+protected:
   virtual ~NewTextureSource()
   {
     MOZ_COUNT_DTOR(NewTextureSource);
   }
 
+public:
   /**
    * Should be overridden in order to deallocate the data that is associated
    * with the rendering backend, such as GL textures.
    */
   virtual void DeallocateDeviceData() = 0;
 
   virtual void SetCompositor(Compositor* aCompositor) {}
 
@@ -280,18 +282,20 @@ class TextureHost
    * Must only be called by Release().
    */
   void Finalize();
 
   friend class AtomicRefCountedWithFinalize<TextureHost>;
 public:
   TextureHost(TextureFlags aFlags);
 
+protected:
   virtual ~TextureHost();
 
+public:
   /**
    * Factory method.
    */
   static TemporaryRef<TextureHost> Create(const SurfaceDescriptor& aDesc,
                                           ISurfaceAllocator* aDeallocator,
                                           TextureFlags aFlags);
 
   /**
@@ -543,18 +547,20 @@ protected:
 class ShmemTextureHost : public BufferTextureHost
 {
 public:
   ShmemTextureHost(const mozilla::ipc::Shmem& aShmem,
                    gfx::SurfaceFormat aFormat,
                    ISurfaceAllocator* aDeallocator,
                    TextureFlags aFlags);
 
+protected:
   ~ShmemTextureHost();
 
+public:
   virtual void DeallocateSharedData() MOZ_OVERRIDE;
 
   virtual void ForgetSharedData() MOZ_OVERRIDE;
 
   virtual uint8_t* GetBuffer() MOZ_OVERRIDE;
 
   virtual size_t GetBufferSize() MOZ_OVERRIDE;
 
@@ -575,18 +581,20 @@ protected:
  */
 class MemoryTextureHost : public BufferTextureHost
 {
 public:
   MemoryTextureHost(uint8_t* aBuffer,
                     gfx::SurfaceFormat aFormat,
                     TextureFlags aFlags);
 
+protected:
   ~MemoryTextureHost();
 
+public:
   virtual void DeallocateSharedData() MOZ_OVERRIDE;
 
   virtual void ForgetSharedData() MOZ_OVERRIDE;
 
   virtual uint8_t* GetBuffer() MOZ_OVERRIDE;
 
   virtual size_t GetBufferSize() MOZ_OVERRIDE;
 
--- a/gfx/layers/composite/ThebesLayerComposite.h
+++ b/gfx/layers/composite/ThebesLayerComposite.h
@@ -33,18 +33,21 @@ class CompositableHost;
 class ContentHost;
 class TiledLayerComposer;
 
 class ThebesLayerComposite : public ThebesLayer,
                              public LayerComposite
 {
 public:
   ThebesLayerComposite(LayerManagerComposite *aManager);
+
+protected:
   virtual ~ThebesLayerComposite();
 
+public:
   virtual void Disconnect() MOZ_OVERRIDE;
 
   virtual LayerRenderState GetRenderState() MOZ_OVERRIDE;
 
   CompositableHost* GetCompositableHost() MOZ_OVERRIDE;
 
   virtual void Destroy() MOZ_OVERRIDE;
 
--- a/gfx/layers/composite/TiledContentHost.h
+++ b/gfx/layers/composite/TiledContentHost.h
@@ -181,18 +181,20 @@ private:
  * is similar to Composite for non-tiled ContentHosts.
  */
 class TiledContentHost : public ContentHost,
                          public TiledLayerComposer
 {
 public:
   TiledContentHost(const TextureInfo& aTextureInfo);
 
+protected:
   ~TiledContentHost();
 
+public:
   virtual LayerRenderState GetRenderState() MOZ_OVERRIDE
   {
     return LayerRenderState();
   }
 
 
   virtual bool UpdateThebes(const ThebesBufferData& aData,
                             const nsIntRegion& aUpdated,
--- a/gfx/layers/ipc/AsyncTransactionTracker.h
+++ b/gfx/layers/ipc/AsyncTransactionTracker.h
@@ -191,21 +191,23 @@ protected:
 class FenceDeliveryTracker : public AsyncTransactionTracker {
 public:
   FenceDeliveryTracker(FenceHandle& aFenceHandle)
     : mFenceHandle(aFenceHandle)
   {
     MOZ_COUNT_CTOR(FenceDeliveryTracker);
   }
 
+protected:
   ~FenceDeliveryTracker()
   {
     MOZ_COUNT_DTOR(FenceDeliveryTracker);
   }
 
+public:
   virtual void Complete() MOZ_OVERRIDE
   {
     mFenceHandle = FenceHandle();
   }
 
   virtual void Cancel() MOZ_OVERRIDE
   {
     mFenceHandle = FenceHandle();
--- a/gfx/layers/ipc/LayerTransactionParent.h
+++ b/gfx/layers/ipc/LayerTransactionParent.h
@@ -45,18 +45,21 @@ class LayerTransactionParent : public PL
   typedef InfallibleTArray<EditReply> EditReplyArray;
   typedef InfallibleTArray<AsyncChildMessageData> AsyncChildMessageArray;
 
 public:
   LayerTransactionParent(LayerManagerComposite* aManager,
                          ShadowLayersManager* aLayersManager,
                          uint64_t aId,
                          ProcessId aOtherProcess);
+
+protected:
   ~LayerTransactionParent();
 
+public:
   void Destroy();
 
   LayerManagerComposite* layer_manager() const { return mLayerManager; }
 
   uint64_t GetId() const { return mId; }
   Layer* GetRoot() const { return mRoot; }
 
   // ISurfaceAllocator
--- a/gfx/layers/ipc/SharedPlanarYCbCrImage.h
+++ b/gfx/layers/ipc/SharedPlanarYCbCrImage.h
@@ -24,18 +24,21 @@ class ISurfaceAllocator;
 class SurfaceDescriptor;
 class TextureClient;
 
 class SharedPlanarYCbCrImage : public PlanarYCbCrImage
                              , public ISharedImage
 {
 public:
   SharedPlanarYCbCrImage(ImageClient* aCompositable);
+
+protected:
   ~SharedPlanarYCbCrImage();
 
+public:
   virtual ISharedImage* AsSharedImage() MOZ_OVERRIDE { return this; }
   virtual TextureClient* GetTextureClient(CompositableClient* aClient) MOZ_OVERRIDE;
   virtual uint8_t* GetBuffer() MOZ_OVERRIDE;
 
   virtual TemporaryRef<gfx::SourceSurface> GetAsSourceSurface() MOZ_OVERRIDE;
   virtual void SetData(const PlanarYCbCrData& aData) MOZ_OVERRIDE;
   virtual void SetDataNoCopy(const Data &aData) MOZ_OVERRIDE;
 
--- a/gfx/layers/ipc/SharedRGBImage.h
+++ b/gfx/layers/ipc/SharedRGBImage.h
@@ -36,18 +36,21 @@ already_AddRefed<Image> CreateSharedRGBI
  * Stores RGB data in shared memory
  * It is assumed that the image width and stride are equal
  */
 class SharedRGBImage : public Image
                      , public ISharedImage
 {
 public:
   SharedRGBImage(ImageClient* aCompositable);
+
+protected:
   ~SharedRGBImage();
 
+public:
   virtual ISharedImage* AsSharedImage() MOZ_OVERRIDE { return this; }
 
   virtual TextureClient* GetTextureClient(CompositableClient* aClient) MOZ_OVERRIDE;
 
   virtual uint8_t* GetBuffer() MOZ_OVERRIDE;
 
   gfx::IntSize GetSize();
 
--- a/gfx/layers/opengl/CompositorOGL.h
+++ b/gfx/layers/opengl/CompositorOGL.h
@@ -161,18 +161,20 @@ class CompositorOGL MOZ_FINAL : public C
 
   friend class GLManagerCompositor;
 
   std::map<ShaderConfigOGL, ShaderProgramOGL*> mPrograms;
 public:
   CompositorOGL(nsIWidget *aWidget, int aSurfaceWidth = -1, int aSurfaceHeight = -1,
                 bool aUseExternalSurfaceSize = false);
 
+protected:
   virtual ~CompositorOGL();
 
+public:
   virtual TemporaryRef<DataTextureSource>
   CreateDataTextureSource(TextureFlags aFlags = TextureFlags::NO_FLAGS) MOZ_OVERRIDE;
 
   virtual bool Initialize() MOZ_OVERRIDE;
 
   virtual void Destroy() MOZ_OVERRIDE;
 
   virtual TextureFactoryIdentifier GetTextureFactoryIdentifier() MOZ_OVERRIDE
--- a/gfx/thebes/gfxBaseSharedMemorySurface.h
+++ b/gfx/thebes/gfxBaseSharedMemorySurface.h
@@ -33,22 +33,23 @@ GetShmInfoPtr(const mozilla::ipc::Shmem&
 extern const cairo_user_data_key_t SHM_KEY;
 
 template <typename Base, typename Sub>
 class gfxBaseSharedMemorySurface : public Base {
     typedef mozilla::ipc::SharedMemory SharedMemory;
     typedef mozilla::ipc::Shmem Shmem;
     friend class gfxReusableSharedImageSurfaceWrapper;
 
-public:
+protected:
     virtual ~gfxBaseSharedMemorySurface()
     {
         MOZ_COUNT_DTOR(gfxBaseSharedMemorySurface);
     }
 
+public:
     /**
      * Return a new gfxSharedImageSurface around a shmem segment newly
      * allocated by this function.  |aAllocator| is the object used to
      * allocate the new shmem segment.  Null is returned if creating
      * the surface failed.
      *
      * NB: the *caller* is responsible for freeing the Shmem allocated
      * by this function.
--- a/gfx/thebes/gfxReusableImageSurfaceWrapper.h
+++ b/gfx/thebes/gfxReusableImageSurfaceWrapper.h
@@ -11,18 +11,20 @@ class gfxImageSurface;
 
 /**
  * A cross-thread capable implementation of gfxReusableSurfaceWrapper based
  * on gfxImageSurface.
  */
 class gfxReusableImageSurfaceWrapper : public gfxReusableSurfaceWrapper {
 public:
   gfxReusableImageSurfaceWrapper(gfxImageSurface* aSurface);
+protected:
   ~gfxReusableImageSurfaceWrapper();
 
+public:
   const unsigned char* GetReadOnlyData() const MOZ_OVERRIDE;
   gfxImageFormat Format() MOZ_OVERRIDE;
   gfxReusableSurfaceWrapper* GetWritable(gfxImageSurface** aSurface) MOZ_OVERRIDE;
   void ReadLock() MOZ_OVERRIDE;
   void ReadUnlock() MOZ_OVERRIDE;
 
   Type GetType()
   {
--- a/gfx/thebes/gfxReusableSharedImageSurfaceWrapper.h
+++ b/gfx/thebes/gfxReusableSharedImageSurfaceWrapper.h
@@ -22,18 +22,20 @@ class ISurfaceAllocator;
 /**
  * A cross-process capable implementation of gfxReusableSurfaceWrapper based
  * on gfxSharedImageSurface.
  */
 class gfxReusableSharedImageSurfaceWrapper : public gfxReusableSurfaceWrapper {
 public:
   gfxReusableSharedImageSurfaceWrapper(mozilla::layers::ISurfaceAllocator* aAllocator,
                                        gfxSharedImageSurface* aSurface);
+protected:
   ~gfxReusableSharedImageSurfaceWrapper();
 
+public:
   const unsigned char* GetReadOnlyData() const MOZ_OVERRIDE;
   gfxImageFormat Format() MOZ_OVERRIDE;
   gfxReusableSurfaceWrapper* GetWritable(gfxImageSurface** aSurface) MOZ_OVERRIDE;
   void ReadLock() MOZ_OVERRIDE;
   void ReadUnlock() MOZ_OVERRIDE;
 
   Type GetType()
   {
--- a/ipc/glue/BackgroundChildImpl.cpp
+++ b/ipc/glue/BackgroundChildImpl.cpp
@@ -13,24 +13,26 @@ class TestChild MOZ_FINAL : public mozil
 {
   friend class mozilla::ipc::BackgroundChildImpl;
 
   nsCString mTestArg;
 
   TestChild(const nsCString& aTestArg)
   : mTestArg(aTestArg)
   {
-    MOZ_COUNT_CTOR(mozilla::ipc::BackgroundTestChild);
+    MOZ_COUNT_CTOR(TestChild);
   }
 
+protected:
   ~TestChild()
   {
-    MOZ_COUNT_DTOR(mozilla::ipc::BackgroundTestChild);
+    MOZ_COUNT_DTOR(TestChild);
   }
 
+public:
   virtual bool
   Recv__delete__(const nsCString& aTestArg) MOZ_OVERRIDE;
 };
 
 } // anonymous namespace
 
 namespace mozilla {
 namespace ipc {
--- a/ipc/glue/BackgroundParentImpl.cpp
+++ b/ipc/glue/BackgroundParentImpl.cpp
@@ -28,24 +28,26 @@ AssertIsOnMainThread()
 }
 
 class TestParent MOZ_FINAL : public mozilla::ipc::PBackgroundTestParent
 {
   friend class mozilla::ipc::BackgroundParentImpl;
 
   TestParent()
   {
-    MOZ_COUNT_CTOR(mozilla::ipc::BackgroundTestParent);
+    MOZ_COUNT_CTOR(TestParent);
   }
 
+protected:
   ~TestParent()
   {
-    MOZ_COUNT_DTOR(mozilla::ipc::BackgroundTestParent);
+    MOZ_COUNT_DTOR(TestParent);
   }
 
+public:
   virtual void
   ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE;
 };
 
 } // anonymous namespace
 
 namespace mozilla {
 namespace ipc {
--- a/layout/base/MaskLayerImageCache.cpp
+++ b/layout/base/MaskLayerImageCache.cpp
@@ -52,9 +52,36 @@ MaskLayerImageCache::FindImageFor(const 
 
 void
 MaskLayerImageCache::PutImage(const MaskLayerImageKey* aKey, ImageContainer* aContainer)
 {
   MaskLayerImageEntry* entry = mMaskImageContainers.PutEntry(*aKey);
   entry->mContainer = aContainer;
 }
 
+// This case is particularly 'clever' because it uses AddRef/Release to track the use
+// not to release the object.
+template<>
+struct HasDangerousPublicDestructor<MaskLayerImageCache::MaskLayerImageKey>
+{
+  static const bool value = true;
+};
+
+MaskLayerImageCache::MaskLayerImageKey::MaskLayerImageKey()
+  : mLayerCount(0)
+  , mRoundedClipRects()
+{
+  MOZ_COUNT_CTOR(MaskLayerImageKey);
 }
+
+MaskLayerImageCache::MaskLayerImageKey::MaskLayerImageKey(const MaskLayerImageKey& aKey)
+  : mLayerCount(aKey.mLayerCount)
+  , mRoundedClipRects(aKey.mRoundedClipRects)
+{
+  MOZ_COUNT_CTOR(MaskLayerImageKey);
+}
+
+MaskLayerImageCache::MaskLayerImageKey::~MaskLayerImageKey()
+{
+  MOZ_COUNT_DTOR(MaskLayerImageKey);
+}
+
+}
--- a/layout/base/MaskLayerImageCache.h
+++ b/layout/base/MaskLayerImageCache.h
@@ -126,33 +126,20 @@ public:
    * mLayerCount counts the number of mask layers which have a reference to
    * MaskLayerImageEntry::mContainer; it is maintained by MaskLayerUserData,
    * which keeps a reference to the key. There will usually be mLayerCount + 1
    * pointers to a key object (the +1 being from the hashtable entry), but this
    * invariant may be temporarily broken.
    */
   struct MaskLayerImageKey
   {
-    MaskLayerImageKey()
-      : mLayerCount(0)
-      , mRoundedClipRects()
-    {
-      MOZ_COUNT_CTOR(MaskLayerImageKey);
-    }
-    MaskLayerImageKey(const MaskLayerImageKey& aKey)
-      : mLayerCount(aKey.mLayerCount)
-      , mRoundedClipRects(aKey.mRoundedClipRects)
-    {
-      MOZ_COUNT_CTOR(MaskLayerImageKey);
-    }
+    MaskLayerImageKey();
+    MaskLayerImageKey(const MaskLayerImageKey& aKey);
 
-    ~MaskLayerImageKey()
-    {
-      MOZ_COUNT_DTOR(MaskLayerImageKey);
-    }
+    ~MaskLayerImageKey();
 
     void AddRef() const { ++mLayerCount; }
     void Release() const
     {
       NS_ASSERTION(mLayerCount > 0, "Inconsistent layer count");
       --mLayerCount;
     }
 
@@ -194,17 +181,18 @@ public:
 protected:
 
   class MaskLayerImageEntry : public PLDHashEntryHdr
   {
   public:
     typedef const MaskLayerImageKey& KeyType;
     typedef const MaskLayerImageKey* KeyTypePointer;
 
-    MaskLayerImageEntry(KeyTypePointer aKey) : mKey(aKey)
+    MaskLayerImageEntry(KeyTypePointer aKey)
+      : mKey(aKey)
     {
       MOZ_COUNT_CTOR(MaskLayerImageEntry);
     }
     MaskLayerImageEntry(const MaskLayerImageEntry& aOther)
       : mKey(aOther.mKey.get())
     {
       NS_ERROR("ALLOW_MEMMOVE == true, should never be called");
     }
@@ -242,12 +230,13 @@ protected:
   };
 
   nsTHashtable<MaskLayerImageEntry> mMaskImageContainers;
 
   // helper funtion for Sweep(), called for each entry in the hashtable
   static PLDHashOperator SweepFunc(MaskLayerImageEntry* aEntry, void* aUserArg);
 };
 
+
 }
 
 
 #endif
--- a/layout/forms/nsComboboxControlFrame.cpp
+++ b/layout/forms/nsComboboxControlFrame.cpp
@@ -364,21 +364,24 @@ class nsResizeDropdownAtFinalPosition
   : public nsIReflowCallback, public nsRunnable
 {
 public:
   nsResizeDropdownAtFinalPosition(nsComboboxControlFrame* aFrame)
     : mFrame(aFrame)
   {
     MOZ_COUNT_CTOR(nsResizeDropdownAtFinalPosition);
   }
+
+protected:
   ~nsResizeDropdownAtFinalPosition()
   {
     MOZ_COUNT_DTOR(nsResizeDropdownAtFinalPosition);
   }
 
+public:
   virtual bool ReflowFinished() MOZ_OVERRIDE
   {
     Run();
     NS_RELEASE_THIS();
     return false;
   }
 
   virtual void ReflowCallbackCanceled() MOZ_OVERRIDE
--- a/netwerk/cache2/CacheEntry.h
+++ b/netwerk/cache2/CacheEntry.h
@@ -15,16 +15,17 @@
 
 #include "nsCOMPtr.h"
 #include "nsRefPtrHashtable.h"
 #include "nsDataHashtable.h"
 #include "nsHashKeys.h"
 #include "nsString.h"
 #include "nsCOMArray.h"
 #include "nsThreadUtils.h"
+#include "mozilla/Attributes.h"
 #include "mozilla/Mutex.h"
 #include "mozilla/TimeStamp.h"
 
 static inline uint32_t
 PRTimeToSeconds(PRTime t_usec)
 {
   PRTime usec_per_sec = PR_USEC_PER_SEC;
   return uint32_t(t_usec /= usec_per_sec);
@@ -359,25 +360,26 @@ public:
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_FORWARD_NSICACHEENTRY(mEntry->)
 private:
   virtual ~CacheEntryHandle();
   nsRefPtr<CacheEntry> mEntry;
 };
 
 
-class CacheOutputCloseListener : public nsRunnable
+class CacheOutputCloseListener MOZ_FINAL : public nsRunnable
 {
 public:
   void OnOutputClosed();
-  virtual ~CacheOutputCloseListener();
 
 private:
   friend class CacheEntry;
 
+  virtual ~CacheOutputCloseListener();
+
   NS_DECL_NSIRUNNABLE
   CacheOutputCloseListener(CacheEntry* aEntry);
 
 private:
   nsRefPtr<CacheEntry> mEntry;
 };
 
 } // net
--- a/netwerk/cache2/CacheFile.cpp
+++ b/netwerk/cache2/CacheFile.cpp
@@ -36,23 +36,25 @@ public:
     , mRV(aResult)
     , mIsNew(aIsNew)
   {
     LOG(("NotifyCacheFileListenerEvent::NotifyCacheFileListenerEvent() "
          "[this=%p]", this));
     MOZ_COUNT_CTOR(NotifyCacheFileListenerEvent);
   }
 
+protected:
   ~NotifyCacheFileListenerEvent()
   {
     LOG(("NotifyCacheFileListenerEvent::~NotifyCacheFileListenerEvent() "
          "[this=%p]", this));
     MOZ_COUNT_DTOR(NotifyCacheFileListenerEvent);
   }
 
+public:
   NS_IMETHOD Run()
   {
     LOG(("NotifyCacheFileListenerEvent::Run() [this=%p]", this));
 
     mCallback->OnFileReady(mRV, mIsNew);
     return NS_OK;
   }
 
@@ -73,23 +75,25 @@ public:
     , mChunkIdx(aChunkIdx)
     , mChunk(aChunk)
   {
     LOG(("NotifyChunkListenerEvent::NotifyChunkListenerEvent() [this=%p]",
          this));
     MOZ_COUNT_CTOR(NotifyChunkListenerEvent);
   }
 
+protected:
   ~NotifyChunkListenerEvent()
   {
     LOG(("NotifyChunkListenerEvent::~NotifyChunkListenerEvent() [this=%p]",
          this));
     MOZ_COUNT_DTOR(NotifyChunkListenerEvent);
   }
 
+public:
   NS_IMETHOD Run()
   {
     LOG(("NotifyChunkListenerEvent::Run() [this=%p]", this));
 
     mCallback->OnChunkAvailable(mRV, mChunkIdx, mChunk);
     return NS_OK;
   }
 
--- a/netwerk/cache2/CacheFileChunk.cpp
+++ b/netwerk/cache2/CacheFileChunk.cpp
@@ -20,23 +20,25 @@ public:
     : mCallback(aCallback)
     , mChunk(aChunk)
   {
     LOG(("NotifyUpdateListenerEvent::NotifyUpdateListenerEvent() [this=%p]",
          this));
     MOZ_COUNT_CTOR(NotifyUpdateListenerEvent);
   }
 
+protected:
   ~NotifyUpdateListenerEvent()
   {
     LOG(("NotifyUpdateListenerEvent::~NotifyUpdateListenerEvent() [this=%p]",
          this));
     MOZ_COUNT_DTOR(NotifyUpdateListenerEvent);
   }
 
+public:
   NS_IMETHOD Run()
   {
     LOG(("NotifyUpdateListenerEvent::Run() [this=%p]", this));
 
     mCallback->OnChunkUpdated(mChunk);
     return NS_OK;
   }
 
--- a/netwerk/cache2/CacheFileIOManager.cpp
+++ b/netwerk/cache2/CacheFileIOManager.cpp
@@ -533,21 +533,23 @@ class ShutdownEvent : public nsRunnable 
 public:
   ShutdownEvent(mozilla::Mutex *aLock, mozilla::CondVar *aCondVar)
     : mLock(aLock)
     , mCondVar(aCondVar)
   {
     MOZ_COUNT_CTOR(ShutdownEvent);
   }
 
+protected:
   ~ShutdownEvent()
   {
     MOZ_COUNT_DTOR(ShutdownEvent);
   }
 
+public:
   NS_IMETHOD Run()
   {
     MutexAutoLock lock(*mLock);
 
     CacheFileIOManager::gInstance->ShutdownInternal();
 
     mCondVar->Notify();
     return NS_OK;
@@ -577,21 +579,23 @@ public:
     }
 
     mIOMan = CacheFileIOManager::gInstance;
 
     MOZ_EVENT_TRACER_NAME_OBJECT(static_cast<nsIRunnable*>(this), aKey.BeginReading());
     MOZ_EVENT_TRACER_WAIT(static_cast<nsIRunnable*>(this), "net::cache::open-background");
   }
 
+protected:
   ~OpenFileEvent()
   {
     MOZ_COUNT_DTOR(OpenFileEvent);
   }
 
+public:
   NS_IMETHOD Run()
   {
     if (mResultOnAnyThread || mTarget) {
       mRV = NS_OK;
 
       if (!(mFlags & CacheFileIOManager::SPECIAL_FILE)) {
         SHA1Sum sum;
         sum.update(mKey.BeginReading(), mKey.Length());
@@ -669,21 +673,23 @@ public:
     if (!aResultOnAnyThread) {
       mTarget = static_cast<nsIEventTarget*>(NS_GetCurrentThread());
     }
 
     MOZ_EVENT_TRACER_NAME_OBJECT(static_cast<nsIRunnable*>(this), aHandle->Key().get());
     MOZ_EVENT_TRACER_WAIT(static_cast<nsIRunnable*>(this), "net::cache::read-background");
   }
 
+protected:
   ~ReadEvent()
   {
     MOZ_COUNT_DTOR(ReadEvent);
   }
 
+public:
   NS_IMETHOD Run()
   {
     if (mResultOnAnyThread || mTarget) {
       MOZ_EVENT_TRACER_EXEC(static_cast<nsIRunnable*>(this), "net::cache::read-background");
       if (mHandle->IsClosed()) {
         mRV = NS_ERROR_NOT_INITIALIZED;
       } else {
         mRV = CacheFileIOManager::gInstance->ReadInternal(
@@ -734,25 +740,27 @@ public:
   {
     MOZ_COUNT_CTOR(WriteEvent);
     mTarget = static_cast<nsIEventTarget*>(NS_GetCurrentThread());
 
     MOZ_EVENT_TRACER_NAME_OBJECT(static_cast<nsIRunnable*>(this), aHandle->Key().get());
     MOZ_EVENT_TRACER_WAIT(static_cast<nsIRunnable*>(this), "net::cache::write-background");
   }
 
+protected:
   ~WriteEvent()
   {
     MOZ_COUNT_DTOR(WriteEvent);
 
     if (!mCallback && mBuf) {
       free(const_cast<char *>(mBuf));
     }
   }
 
+public:
   NS_IMETHOD Run()
   {
     if (mTarget) {
       MOZ_EVENT_TRACER_EXEC(static_cast<nsIRunnable*>(this), "net::cache::write-background");
       if (mHandle->IsClosed()) {
         mRV = NS_ERROR_NOT_INITIALIZED;
       } else {
         mRV = CacheFileIOManager::gInstance->WriteInternal(
@@ -798,21 +806,23 @@ public:
   {
     MOZ_COUNT_CTOR(DoomFileEvent);
     mTarget = static_cast<nsIEventTarget*>(NS_GetCurrentThread());
 
     MOZ_EVENT_TRACER_NAME_OBJECT(static_cast<nsIRunnable*>(this), aHandle->Key().get());
     MOZ_EVENT_TRACER_WAIT(static_cast<nsIRunnable*>(this), "net::cache::doom-background");
   }
 
+protected:
   ~DoomFileEvent()
   {
     MOZ_COUNT_DTOR(DoomFileEvent);
   }
 
+public:
   NS_IMETHOD Run()
   {
     if (mTarget) {
       MOZ_EVENT_TRACER_EXEC(static_cast<nsIRunnable*>(this), "net::cache::doom-background");
       if (mHandle->IsClosed()) {
         mRV = NS_ERROR_NOT_INITIALIZED;
       } else {
         mRV = CacheFileIOManager::gInstance->DoomFileInternal(mHandle);
@@ -853,21 +863,23 @@ public:
     sum.update(aKey.BeginReading(), aKey.Length());
     sum.finish(mHash);
 
     mTarget = static_cast<nsIEventTarget*>(NS_GetCurrentThread());
     mIOMan = CacheFileIOManager::gInstance;
     MOZ_ASSERT(mTarget);
   }
 
+protected:
   ~DoomFileByKeyEvent()
   {
     MOZ_COUNT_DTOR(DoomFileByKeyEvent);
   }
 
+public:
   NS_IMETHOD Run()
   {
     if (mTarget) {
       if (!mIOMan) {
         mRV = NS_ERROR_NOT_INITIALIZED;
       } else {
         mRV = mIOMan->DoomFileByKeyInternal(&mHash);
         mIOMan = nullptr;
@@ -895,21 +907,23 @@ protected:
 class ReleaseNSPRHandleEvent : public nsRunnable {
 public:
   ReleaseNSPRHandleEvent(CacheFileHandle *aHandle)
     : mHandle(aHandle)
   {
     MOZ_COUNT_CTOR(ReleaseNSPRHandleEvent);
   }
 
+protected:
   ~ReleaseNSPRHandleEvent()
   {
     MOZ_COUNT_DTOR(ReleaseNSPRHandleEvent);
   }
 
+public:
   NS_IMETHOD Run()
   {
     if (mHandle->mFD && !mHandle->IsClosed()) {
       CacheFileIOManager::gInstance->ReleaseNSPRHandleInternal(mHandle);
     }
 
     return NS_OK;
   }
@@ -927,21 +941,23 @@ public:
     , mEOFPos(aEOFPos)
     , mCallback(aCallback)
     , mRV(NS_ERROR_FAILURE)
   {
     MOZ_COUNT_CTOR(TruncateSeekSetEOFEvent);
     mTarget = static_cast<nsIEventTarget*>(NS_GetCurrentThread());
   }
 
+protected:
   ~TruncateSeekSetEOFEvent()
   {
     MOZ_COUNT_DTOR(TruncateSeekSetEOFEvent);
   }
 
+public:
   NS_IMETHOD Run()
   {
     if (mTarget) {
       if (mHandle->IsClosed()) {
         mRV = NS_ERROR_NOT_INITIALIZED;
       } else {
         mRV = CacheFileIOManager::gInstance->TruncateSeekSetEOFInternal(
           mHandle, mTruncatePos, mEOFPos);
@@ -975,21 +991,23 @@ public:
     , mNewName(aNewName)
     , mCallback(aCallback)
     , mRV(NS_ERROR_FAILURE)
   {
     MOZ_COUNT_CTOR(RenameFileEvent);
     mTarget = static_cast<nsIEventTarget*>(NS_GetCurrentThread());
   }
 
+protected:
   ~RenameFileEvent()
   {
     MOZ_COUNT_DTOR(RenameFileEvent);
   }
 
+public:
   NS_IMETHOD Run()
   {
     if (mTarget) {
       if (mHandle->IsClosed()) {
         mRV = NS_ERROR_NOT_INITIALIZED;
       } else {
         mRV = CacheFileIOManager::gInstance->RenameFileInternal(mHandle,
                                                                 mNewName);
@@ -1021,21 +1039,23 @@ public:
     : mHandle(aHandle)
     , mAppId(aAppId)
     , mAnonymous(aAnonymous)
     , mInBrowser(aInBrowser)
   {
     MOZ_COUNT_CTOR(InitIndexEntryEvent);
   }
 
+protected:
   ~InitIndexEntryEvent()
   {
     MOZ_COUNT_DTOR(InitIndexEntryEvent);
   }
 
+public:
   NS_IMETHOD Run()
   {
     if (mHandle->IsClosed() || mHandle->IsDoomed()) {
       return NS_OK;
     }
 
     CacheIndex::InitEntry(mHandle->Hash(), mAppId, mAnonymous, mInBrowser);
 
@@ -1070,21 +1090,23 @@ public:
       mFrecency = *aFrecency;
     }
     if (aExpirationTime) {
       mHasExpirationTime = true;
       mExpirationTime = *aExpirationTime;
     }
   }
 
+protected:
   ~UpdateIndexEntryEvent()
   {
     MOZ_COUNT_DTOR(UpdateIndexEntryEvent);
   }
 
+public:
   NS_IMETHOD Run()
   {
     if (mHandle->IsClosed() || mHandle->IsDoomed()) {
       return NS_OK;
     }
 
     CacheIndex::UpdateEntry(mHandle->Hash(),
                             mHasFrecency ? &mFrecency : nullptr,
--- a/netwerk/protocol/ftp/nsFtpConnectionThread.cpp
+++ b/netwerk/protocol/ftp/nsFtpConnectionThread.cpp
@@ -1946,20 +1946,22 @@ class nsFtpAsyncAlert : public nsRunnabl
 {
 public:
     nsFtpAsyncAlert(nsIPrompt *aPrompter, nsString aResponseMsg)
         : mPrompter(aPrompter)
         , mResponseMsg(aResponseMsg)
     {
         MOZ_COUNT_CTOR(nsFtpAsyncAlert);
     }
+protected:
     virtual ~nsFtpAsyncAlert()
     {
         MOZ_COUNT_DTOR(nsFtpAsyncAlert);
     }
+public:
     NS_IMETHOD Run()
     {
         if (mPrompter) {
             mPrompter->Alert(nullptr, mResponseMsg.get());
         }
         return NS_OK;
     }
 private:
--- a/parser/html/nsHtml5OwningUTF16Buffer.h
+++ b/parser/html/nsHtml5OwningUTF16Buffer.h
@@ -19,21 +19,23 @@ class nsHtml5OwningUTF16Buffer : public 
   public:
 
     /**
      * Constructor for a parser key placeholder. (No actual buffer.)
      * @param aKey a parser key
      */
     nsHtml5OwningUTF16Buffer(void* aKey);
 
+protected:
     /**
      * Takes care of releasing the owned buffer.
      */
     ~nsHtml5OwningUTF16Buffer();
 
+public:
     /**
      * The next buffer in a queue.
      */
     nsRefPtr<nsHtml5OwningUTF16Buffer> next;
 
     /**
      * A parser key.
      */
--- a/rdf/base/src/nsInMemoryDataSource.cpp
+++ b/rdf/base/src/nsInMemoryDataSource.cpp
@@ -84,18 +84,20 @@ public:
                            uint32_t aNumber, void* aArg);
 
     Assertion(nsIRDFResource* aSource,      // normal assertion
               nsIRDFResource* aProperty,
               nsIRDFNode* aTarget,
               bool aTruthValue);
     Assertion(nsIRDFResource* aSource);     // PLDHashTable assertion variant
 
+private:
     ~Assertion();
 
+public:
     void AddRef() {
         if (mRefCnt == UINT16_MAX) {
             NS_WARNING("refcount overflow, leaking Assertion");
             return;
         }
         ++mRefCnt;
     }
 
@@ -1312,17 +1314,17 @@ InMemoryDataSource::LockedUnassert(nsIRD
                     Entry* entry = reinterpret_cast<Entry*>(hdr);
                     entry->mNode = aProperty;
                     entry->mAssertions = next->mNext;
                 }
             }
             else {
                 // If this second-level hash empties out, clean it up.
                 if (!root->u.hash.mPropertyHash->entryCount) {
-                    delete root;
+                    root->Release();
                     SetForwardArcs(aSource, nullptr);
                 }
             }
         }
         else {
             prev->mNext = next->mNext;
         }
     }
@@ -1916,17 +1918,17 @@ InMemoryDataSource::SweepForwardArcsEntr
     if (as && (as->mHashEntry))
     {
         // Stuff in sub-hashes must be swept recursively (max depth: 1)
         PL_DHashTableEnumerate(as->u.hash.mPropertyHash,
                                SweepForwardArcsEntries, info);
 
         // If the sub-hash is now empty, clean it up.
         if (!as->u.hash.mPropertyHash->entryCount) {
-            delete as;
+            as->Release();
             result = PL_DHASH_REMOVE;
         }
 
         return result;
     }
 
     Assertion* prev = nullptr;
     while (as) {
--- a/widget/xpwidgets/nsBaseWidget.cpp
+++ b/widget/xpwidgets/nsBaseWidget.cpp
@@ -900,17 +900,17 @@ void nsBaseWidget::CreateCompositor(int 
     return;
   }
 
   // Initialize LayerScope on the main thread.
   LayerScope::Init();
 
   mCompositorParent = NewCompositorParent(aWidth, aHeight);
   MessageChannel *parentChannel = mCompositorParent->GetIPCChannel();
-  ClientLayerManager* lm = new ClientLayerManager(this);
+  nsRefPtr<ClientLayerManager> lm = new ClientLayerManager(this);
   MessageLoop *childMessageLoop = CompositorParent::CompositorLoop();
   mCompositorChild = new CompositorChild(lm);
   mCompositorChild->Open(parentChannel, childMessageLoop, ipc::ChildSide);
 
   TextureFactoryIdentifier textureFactoryIdentifier;
   PLayerTransactionChild* shadowManager = nullptr;
   nsTArray<LayersBackend> backendHints;
   GetPreferredCompositorBackends(backendHints);
@@ -923,26 +923,26 @@ void nsBaseWidget::CreateCompositor(int 
   if (!backendHints.IsEmpty()) {
     shadowManager = mCompositorChild->SendPLayerTransactionConstructor(
       backendHints, 0, &textureFactoryIdentifier, &success);
   }
 
   if (success) {
     ShadowLayerForwarder* lf = lm->AsShadowForwarder();
     if (!lf) {
-      delete lm;
+      lm = nullptr;
       mCompositorChild = nullptr;
       return;
     }
     lf->SetShadowManager(shadowManager);
     lf->IdentifyTextureHost(textureFactoryIdentifier);
     ImageBridgeChild::IdentifyCompositorTextureHost(textureFactoryIdentifier);
     WindowUsesOMTC();
 
-    mLayerManager = lm;
+    mLayerManager = lm.forget();
     return;
   }
 
   NS_WARNING("Failed to create an OMT compositor.");
   DestroyCompositor();
   // Compositor child had the only reference to LayerManager and will have
   // deallocated it when being freed.
 }