Backed out changesets ddbac34527fe and fa82f32d0c39 (bug 991812) for B2G bustage.
authorRyan VanderMeulen <ryanvm@gmail.com>
Mon, 14 Apr 2014 16:16:18 -0400
changeset 196901 376496720a0e662039298fcfdde08ff911e23695
parent 196900 23528b4efd67c53b46ceaac02c377bb6443487ce
child 196902 16f349eeb65c46fc4614c4aabd2e7cf5d75fa443
push id3624
push userasasaki@mozilla.com
push dateMon, 09 Jun 2014 21:49:01 +0000
treeherdermozilla-beta@b1a5da15899a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs991812
milestone31.0a1
backs outddbac34527fefbc05afbdf735141184cca07ea10
fa82f32d0c397317d19c92a60538b4562f8bed0f
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Backed out changesets ddbac34527fe and fa82f32d0c39 (bug 991812) for B2G bustage. CLOSED TREE
content/media/MediaTaskQueue.h
content/media/fmp4/PlatformDecoderModule.h
content/media/fmp4/wmf/MFTDecoder.h
dom/bluetooth/BluetoothProfileController.h
dom/camera/CameraControlImpl.h
dom/camera/ICameraControl.h
dom/devicestorage/DeviceStorage.h
dom/devicestorage/DeviceStorageFileDescriptor.h
dom/devicestorage/DeviceStorageRequestChild.h
dom/devicestorage/nsDeviceStorage.cpp
dom/devicestorage/nsDeviceStorage.h
dom/interfaces/devicestorage/nsIDOMDeviceStorage.idl
dom/system/gonk/AutoMounter.cpp
dom/system/gonk/Volume.h
dom/system/gonk/VolumeCommand.h
dom/system/gonk/VolumeManager.h
dom/system/gonk/VolumeServiceIOThread.h
gfx/layers/Compositor.h
gfx/layers/Effects.h
gfx/layers/client/CompositableClient.h
gfx/layers/client/SimpleTextureClientPool.h
gfx/layers/client/TextureClient.cpp
gfx/layers/client/TextureClientPool.h
gfx/layers/client/TiledContentClient.h
gfx/layers/composite/AsyncCompositionManager.h
gfx/layers/composite/CompositableHost.h
gfx/layers/composite/TextRenderer.h
gfx/layers/composite/TextureHost.h
gfx/layers/ipc/LayerTransactionChild.h
gfx/layers/opengl/CompositorOGL.h
gfx/src/FilterSupport.cpp
hal/gonk/GonkHal.cpp
hal/gonk/GonkSwitch.cpp
image/src/SurfaceCache.cpp
ipc/netd/Netd.h
ipc/unixsocket/UnixSocket.h
layout/base/FrameLayerBuilder.h
security/manager/ssl/src/SharedCertVerifier.h
xpcom/threads/BackgroundHangMonitor.cpp
--- a/content/media/MediaTaskQueue.h
+++ b/content/media/MediaTaskQueue.h
@@ -18,23 +18,21 @@ namespace mozilla {
 
 class SharedThreadPool;
 
 // Abstracts executing runnables in order in a thread pool. The runnables
 // dispatched to the MediaTaskQueue will be executed in the order in which
 // they're received, and are guaranteed to not be executed concurrently.
 // They may be executed on different threads, and a memory barrier is used
 // to make this threadsafe for objects that aren't already threadsafe.
-class MediaTaskQueue MOZ_FINAL {
-  ~MediaTaskQueue();
-
+class MediaTaskQueue : public AtomicRefCounted<MediaTaskQueue> {
 public:
-  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MediaTaskQueue)
-
+  MOZ_DECLARE_REFCOUNTED_TYPENAME(MediaTaskQueue)
   MediaTaskQueue(TemporaryRef<SharedThreadPool> aPool);
+  ~MediaTaskQueue();
 
   nsresult Dispatch(nsIRunnable* aRunnable);
 
   // Removes all pending tasks from the task queue, and blocks until
   // the currently running task (if any) finishes.
   void Flush();
 
   // Blocks until all tasks finish executing, then shuts down the task queue
--- a/content/media/fmp4/PlatformDecoderModule.h
+++ b/content/media/fmp4/PlatformDecoderModule.h
@@ -138,23 +138,21 @@ public:
 //
 // All functions must be threadsafe, and be able to be called on an
 // arbitrary thread.
 //
 // Decoding is done asynchronously. Any async work can be done on the
 // MediaTaskQueue passed into the PlatformDecoderModules's Create*Decoder()
 // function. This may not be necessary for platforms with async APIs
 // for decoding.
-class MediaDataDecoder {
-protected:
+class MediaDataDecoder : public AtomicRefCounted<MediaDataDecoder> {
+public:
+  MOZ_DECLARE_REFCOUNTED_TYPENAME(MediaDataDecoder)
   virtual ~MediaDataDecoder() {};
 
-public:
-  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MediaDataDecoder)
-
   // Initialize the decoder. The decoder should be ready to decode after
   // this returns. The decoder should do any initialization here, rather
   // than in its constructor or PlatformDecoderModule::Create*Decoder(),
   // so that if the MP4Reader needs to shutdown during initialization,
   // it can call Shutdown() to cancel this operation. Any initialization
   // that requires blocking the calling thread in this function *must*
   // be done here so that it can be canceled by calling Shutdown()!
   virtual nsresult Init() = 0;
--- a/content/media/fmp4/wmf/MFTDecoder.h
+++ b/content/media/fmp4/wmf/MFTDecoder.h
@@ -9,23 +9,21 @@
 
 #include "WMF.h"
 #include "mozilla/RefPtr.h"
 #include "mozilla/ReentrantMonitor.h"
 #include "nsIThread.h"
 
 namespace mozilla {
 
-class MFTDecoder MOZ_FINAL {
-  ~MFTDecoder();
-
+class MFTDecoder : public AtomicRefCounted<MFTDecoder> {
 public:
-  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MFTDecoder)
-
+  MOZ_DECLARE_REFCOUNTED_TYPENAME(MTFDecoder)
   MFTDecoder();
+  ~MFTDecoder();
 
   // Creates the MFT. First thing to do as part of setup.
   //
   // Params:
   //  - aMFTClsID the clsid used by CoCreateInstance to instantiate the
   //    decoder MFT.
   HRESULT Create(const GUID& aMFTClsID);
 
--- a/dom/bluetooth/BluetoothProfileController.h
+++ b/dom/bluetooth/BluetoothProfileController.h
@@ -3,17 +3,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_bluetooth_bluetoothprofilecontroller_h__
 #define mozilla_dom_bluetooth_bluetoothprofilecontroller_h__
 
 #include "BluetoothUuid.h"
-#include "nsISupportsImpl.h"
+#include "mozilla/RefPtr.h"
 #include "nsAutoPtr.h"
 #include "nsITimer.h"
 
 BEGIN_BLUETOOTH_NAMESPACE
 
 /*
  * Class of Device(CoD): 32-bit unsigned integer
  *
@@ -52,22 +52,20 @@ BEGIN_BLUETOOTH_NAMESPACE
 
 // Pointing device: sub-field of minor device class (Bit 7)
 #define IS_POINTING_DEVICE(cod)      ((GET_MINOR_DEVICE_CLASS(cod) & 0x20) >> 5)
 
 class BluetoothProfileManagerBase;
 class BluetoothReplyRunnable;
 typedef void (*BluetoothProfileControllerCallback)();
 
-class BluetoothProfileController MOZ_FINAL
+class BluetoothProfileController : public RefCounted<BluetoothProfileController>
 {
-  ~BluetoothProfileController();
-
 public:
-  NS_INLINE_DECL_REFCOUNTING(BluetoothProfileController)
+  MOZ_DECLARE_REFCOUNTED_TYPENAME(BluetoothProfileController)
   /**
    * @param aConnect:       If it's a connect request, the value should be set
    *                        to true. For disconnect request, set it to false.
    * @param aDeviceAddress: The address of remote device.
    * @param aRunnable:      Once the controller has done, the runnable will be
    *                        replied. When all connection/disconnection attemps
    *                        have failed, an error is fired. In other words,
    *                        reply a success if any attemp successes.
@@ -80,16 +78,17 @@ public:
    *                        aCod or disconnect all connected profiles.
    */
   BluetoothProfileController(bool aConnect,
                              const nsAString& aDeviceAddress,
                              BluetoothReplyRunnable* aRunnable,
                              BluetoothProfileControllerCallback aCallback,
                              uint16_t aServiceUuid,
                              uint32_t aCod = 0);
+  ~BluetoothProfileController();
 
   /**
    * The controller starts connecting/disconnecting profiles one by one
    * according to the order in array mProfiles.
    */
   void StartSession();
 
   /**
--- a/dom/camera/CameraControlImpl.h
+++ b/dom/camera/CameraControlImpl.h
@@ -14,16 +14,18 @@
 #include "AutoRwLock.h"
 #include "nsIDOMDeviceStorage.h"
 #include "ICameraControl.h"
 #include "CameraCommon.h"
 #include "DeviceStorage.h"
 #include "DeviceStorageFileDescriptor.h"
 #include "CameraControlListener.h"
 
+class DeviceStorageFileDescriptor;
+
 namespace mozilla {
 
 namespace layers {
   class Image;
 }
 
 class RecorderProfileManager;
 
--- a/dom/camera/ICameraControl.h
+++ b/dom/camera/ICameraControl.h
@@ -5,17 +5,17 @@
 #ifndef DOM_CAMERA_ICAMERACONTROL_H
 #define DOM_CAMERA_ICAMERACONTROL_H
 
 #include "nsCOMPtr.h"
 #include "nsString.h"
 #include "nsAutoPtr.h"
 #include "nsISupportsImpl.h"
 
-struct DeviceStorageFileDescriptor;
+class DeviceStorageFileDescriptor;
 
 class nsIFile;
 
 namespace mozilla {
 
 class CameraControlListener;
 class RecorderProfileManager;
 
--- a/dom/devicestorage/DeviceStorage.h
+++ b/dom/devicestorage/DeviceStorage.h
@@ -316,17 +316,23 @@ private:
   bool mIsWatchingFile;
   bool mAllowedToWatchFile;
 
   nsresult Notify(const char* aReason, class DeviceStorageFile* aFile);
 
   friend class WatchFileEvent;
   friend class DeviceStorageRequest;
 
-  static mozilla::StaticAutoPtr<nsTArray<nsString>> sVolumeNameCache;
+  class VolumeNameCache : public mozilla::RefCounted<VolumeNameCache>
+  {
+  public:
+    MOZ_DECLARE_REFCOUNTED_TYPENAME(VolumeNameCache)
+    nsTArray<nsString>  mVolumeNames;
+  };
+  static mozilla::StaticRefPtr<VolumeNameCache> sVolumeNameCache;
 
 #ifdef MOZ_WIDGET_GONK
   nsString mLastStatus;
   void DispatchMountChangeEvent(nsAString& aVolumeStatus);
 #endif
 
   // nsIDOMDeviceStorage.type
   enum {
--- a/dom/devicestorage/DeviceStorageFileDescriptor.h
+++ b/dom/devicestorage/DeviceStorageFileDescriptor.h
@@ -4,16 +4,18 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef DeviceStorageFileDescriptor_h
 #define DeviceStorageFileDescriptor_h
 
 #include "mozilla/ipc/FileDescriptor.h"
 
-struct DeviceStorageFileDescriptor MOZ_FINAL
+class DeviceStorageFileDescriptor MOZ_FINAL
+  : public mozilla::RefCounted<DeviceStorageFileDescriptor>
 {
-  NS_INLINE_DECL_REFCOUNTING(DeviceStorageFileDescriptor)
+public:
+  MOZ_DECLARE_REFCOUNTED_TYPENAME(DeviceStorageFileDescriptor)
   nsRefPtr<DeviceStorageFile> mDSFile;
   mozilla::ipc::FileDescriptor mFileDescriptor;
 };
 
 #endif
--- a/dom/devicestorage/DeviceStorageRequestChild.h
+++ b/dom/devicestorage/DeviceStorageRequestChild.h
@@ -4,17 +4,17 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_devicestorage_DeviceStorageRequestChild_h
 #define mozilla_dom_devicestorage_DeviceStorageRequestChild_h
 
 #include "mozilla/dom/devicestorage/PDeviceStorageRequestChild.h"
 
 class DeviceStorageFile;
-struct DeviceStorageFileDescriptor;
+class DeviceStorageFileDescriptor;
 
 namespace mozilla {
 namespace dom {
 
 class DOMRequest;
 
 namespace devicestorage {
 
--- a/dom/devicestorage/nsDeviceStorage.cpp
+++ b/dom/devicestorage/nsDeviceStorage.cpp
@@ -110,26 +110,25 @@ DeviceStorageUsedSpaceCache::CreateOrGet
 
   MOZ_ASSERT(NS_IsMainThread());
 
   sDeviceStorageUsedSpaceCache = new DeviceStorageUsedSpaceCache();
   ClearOnShutdown(&sDeviceStorageUsedSpaceCache);
   return sDeviceStorageUsedSpaceCache;
 }
 
-already_AddRefed<DeviceStorageUsedSpaceCache::CacheEntry>
+TemporaryRef<DeviceStorageUsedSpaceCache::CacheEntry>
 DeviceStorageUsedSpaceCache::GetCacheEntry(const nsAString& aStorageName)
 {
-  nsTArray<nsRefPtr<CacheEntry>>::size_type numEntries = mCacheEntries.Length();
-  nsTArray<nsRefPtr<CacheEntry>>::index_type i;
+  nsTArray<RefPtr<CacheEntry> >::size_type numEntries = mCacheEntries.Length();
+  nsTArray<RefPtr<CacheEntry> >::index_type i;
   for (i = 0; i < numEntries; i++) {
-    nsRefPtr<CacheEntry>& cacheEntry = mCacheEntries[i];
+    RefPtr<CacheEntry> cacheEntry = mCacheEntries[i];
     if (cacheEntry->mStorageName.Equals(aStorageName)) {
-      nsRefPtr<CacheEntry> addRefedCacheEntry = cacheEntry;
-      return addRefedCacheEntry.forget();
+      return cacheEntry;
     }
   }
   return nullptr;
 }
 
 static int64_t
 GetFreeBytes(const nsAString& aStorageName)
 {
@@ -145,17 +144,17 @@ GetFreeBytes(const nsAString& aStorageNa
 
 nsresult
 DeviceStorageUsedSpaceCache::AccumUsedSizes(const nsAString& aStorageName,
                                             uint64_t* aPicturesSoFar,
                                             uint64_t* aVideosSoFar,
                                             uint64_t* aMusicSoFar,
                                             uint64_t* aTotalSoFar)
 {
-  nsRefPtr<CacheEntry> cacheEntry = GetCacheEntry(aStorageName);
+  RefPtr<CacheEntry> cacheEntry = GetCacheEntry(aStorageName);
   if (!cacheEntry || cacheEntry->mDirty) {
     return NS_ERROR_NOT_AVAILABLE;
   }
   int64_t freeBytes = GetFreeBytes(cacheEntry->mStorageName);
   if (freeBytes != cacheEntry->mFreeBytes) {
     // Free space changed, so our cached results are no longer valid.
     return NS_ERROR_NOT_AVAILABLE;
   }
@@ -170,35 +169,35 @@ DeviceStorageUsedSpaceCache::AccumUsedSi
 
 void
 DeviceStorageUsedSpaceCache::SetUsedSizes(const nsAString& aStorageName,
                                           uint64_t aPictureSize,
                                           uint64_t aVideosSize,
                                           uint64_t aMusicSize,
                                           uint64_t aTotalUsedSize)
 {
-  nsRefPtr<CacheEntry> cacheEntry = GetCacheEntry(aStorageName);
+  RefPtr<CacheEntry> cacheEntry = GetCacheEntry(aStorageName);
   if (!cacheEntry) {
     cacheEntry = new CacheEntry;
     cacheEntry->mStorageName = aStorageName;
     mCacheEntries.AppendElement(cacheEntry);
   }
   cacheEntry->mFreeBytes = GetFreeBytes(cacheEntry->mStorageName);
 
   cacheEntry->mPicturesUsedSize = aPictureSize;
   cacheEntry->mVideosUsedSize = aVideosSize;
   cacheEntry->mMusicUsedSize = aMusicSize;
   cacheEntry->mTotalUsedSize = aTotalUsedSize;
   cacheEntry->mDirty = false;
 }
 
-class GlobalDirs
+class GlobalDirs : public RefCounted<GlobalDirs>
 {
 public:
-  NS_INLINE_DECL_REFCOUNTING(GlobalDirs)
+  MOZ_DECLARE_REFCOUNTED_TYPENAME(GlobalDirs)
 #if !defined(MOZ_WIDGET_GONK)
   nsCOMPtr<nsIFile> pictures;
   nsCOMPtr<nsIFile> videos;
   nsCOMPtr<nsIFile> music;
   nsCOMPtr<nsIFile> sdcard;
 #endif
   nsCOMPtr<nsIFile> apps;
   nsCOMPtr<nsIFile> crashes;
@@ -3175,25 +3174,26 @@ nsDOMDeviceStorage::Shutdown()
     UnregisterForSDCardChanges(this);
   }
 
   nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
   obs->RemoveObserver(this, "file-watcher-update");
   obs->RemoveObserver(this, "disk-space-watcher");
 }
 
-StaticAutoPtr<nsTArray<nsString>> nsDOMDeviceStorage::sVolumeNameCache;
+StaticRefPtr<nsDOMDeviceStorage::VolumeNameCache>
+  nsDOMDeviceStorage::sVolumeNameCache;
 
 // static
 void
 nsDOMDeviceStorage::GetOrderedVolumeNames(
   nsDOMDeviceStorage::VolumeNameArray &aVolumeNames)
 {
-  if (sVolumeNameCache && sVolumeNameCache->Length() > 0) {
-    aVolumeNames.AppendElements(*sVolumeNameCache);
+  if (sVolumeNameCache && sVolumeNameCache->mVolumeNames.Length() > 0) {
+    aVolumeNames.AppendElements(sVolumeNameCache->mVolumeNames);
     return;
   }
 #ifdef MOZ_WIDGET_GONK
   nsCOMPtr<nsIVolumeService> vs = do_GetService(NS_VOLUMESERVICE_CONTRACTID);
   if (vs) {
     vs->GetVolumeNames(aVolumeNames);
 
     // If the volume sdcard exists, then we want it to be first.
@@ -3204,18 +3204,18 @@ nsDOMDeviceStorage::GetOrderedVolumeName
       aVolumeNames.RemoveElementAt(sdcardIndex);
       aVolumeNames.InsertElementAt(0, NS_LITERAL_STRING("sdcard"));
     }
   }
 #endif
   if (aVolumeNames.IsEmpty()) {
     aVolumeNames.AppendElement(EmptyString());
   }
-  sVolumeNameCache = new nsTArray<nsString>;
-  sVolumeNameCache->AppendElements(aVolumeNames);
+  sVolumeNameCache = new VolumeNameCache;
+  sVolumeNameCache->mVolumeNames.AppendElements(aVolumeNames);
 }
 
 // static
 void
 nsDOMDeviceStorage::CreateDeviceStorageFor(nsPIDOMWindow* aWin,
                                            const nsAString &aType,
                                            nsDOMDeviceStorage** aStore)
 {
--- a/dom/devicestorage/nsDeviceStorage.h
+++ b/dom/devicestorage/nsDeviceStorage.h
@@ -24,16 +24,17 @@ class nsPIDOMWindow;
 #include "nsWeakPtr.h"
 #include "nsIDOMEventListener.h"
 #include "nsIObserver.h"
 #include "nsIStringBundle.h"
 #include "mozilla/Mutex.h"
 #include "prtime.h"
 #include "DeviceStorage.h"
 #include "mozilla/dom/devicestorage/DeviceStorageRequestChild.h"
+#include "mozilla/RefPtr.h"
 #include "mozilla/StaticPtr.h"
 
 namespace mozilla {
 class ErrorResult;
 } // namespace mozilla
 
 #define POST_ERROR_EVENT_FILE_EXISTS                 "NoModificationAllowedError"
 #define POST_ERROR_EVENT_FILE_DOES_NOT_EXIST         "NotFoundError"
@@ -74,17 +75,17 @@ public:
                          const nsAString& aStorageName)
         : mCache(aCache)
         , mStorageName(aStorageName) {}
 
       ~InvalidateRunnable() {}
 
       NS_IMETHOD Run() MOZ_OVERRIDE
       {
-        nsRefPtr<DeviceStorageUsedSpaceCache::CacheEntry> cacheEntry;
+        mozilla::RefPtr<DeviceStorageUsedSpaceCache::CacheEntry> cacheEntry;
         cacheEntry = mCache->GetCacheEntry(mStorageName);
         if (cacheEntry) {
           cacheEntry->mDirty = true;
         }
         return NS_OK;
       }
     private:
       DeviceStorageUsedSpaceCache* mCache;
@@ -114,31 +115,31 @@ public:
 
   void SetUsedSizes(const nsAString& aStorageName,
                     uint64_t aPictureSize, uint64_t aVideosSize,
                     uint64_t aMusicSize, uint64_t aTotalSize);
 
 private:
   friend class InvalidateRunnable;
 
-  struct CacheEntry
+  class CacheEntry : public mozilla::RefCounted<CacheEntry> 
   {
-    NS_INLINE_DECL_REFCOUNTING(DeviceStorageUsedSpaceCache::CacheEntry)
-
+  public:
+    MOZ_DECLARE_REFCOUNTED_TYPENAME(DeviceStorageUsedSpaceCache::CacheEntry)
     bool mDirty;
     nsString mStorageName;
     int64_t  mFreeBytes;
     uint64_t mPicturesUsedSize;
     uint64_t mVideosUsedSize;
     uint64_t mMusicUsedSize;
     uint64_t mTotalUsedSize;
   };
-  already_AddRefed<CacheEntry> GetCacheEntry(const nsAString& aStorageName);
+  mozilla::TemporaryRef<CacheEntry> GetCacheEntry(const nsAString& aStorageName);
 
-  nsTArray<nsRefPtr<CacheEntry>> mCacheEntries;
+  nsTArray<mozilla::RefPtr<CacheEntry> > mCacheEntries;
 
   nsCOMPtr<nsIThread> mIOThread;
 
   static mozilla::StaticAutoPtr<DeviceStorageUsedSpaceCache> sDeviceStorageUsedSpaceCache;
 };
 
 class DeviceStorageTypeChecker MOZ_FINAL
 {
--- a/dom/interfaces/devicestorage/nsIDOMDeviceStorage.idl
+++ b/dom/interfaces/devicestorage/nsIDOMDeviceStorage.idl
@@ -7,17 +7,17 @@
 interface nsIDOMBlob;
 interface nsIDOMDOMRequest;
 interface nsIDOMDOMCursor;
 interface nsIDOMDeviceStorageChangeEvent;
 interface nsIDOMEventListener;
 interface nsIFile;
 
 %{C++
-struct DeviceStorageFileDescriptor;
+class DeviceStorageFileDescriptor;
 %}
 [ptr] native DeviceStorageFdPtr(DeviceStorageFileDescriptor);
 
 [scriptable, uuid(8b724547-3c78-4244-969a-f00a1f4ae0c3), builtinclass]
 interface nsIDOMDeviceStorage : nsIDOMEventTarget
 {
     [implicit_jscontext] attribute jsval onchange;
     nsIDOMDOMRequest add(in nsIDOMBlob aBlob);
--- a/dom/system/gonk/AutoMounter.cpp
+++ b/dom/system/gonk/AutoMounter.cpp
@@ -158,34 +158,34 @@ protected:
 private:
     const static int kMaxErrorCount = 3; // Max number of errors before we give up
 
     int   mErrorCount;
 };
 
 /***************************************************************************/
 
-class AutoMounter
+class AutoMounter : public RefCounted<AutoMounter>
 {
 public:
-  NS_INLINE_DECL_REFCOUNTING(AutoMounter)
+  MOZ_DECLARE_REFCOUNTED_TYPENAME(AutoMounter)
 
-  typedef nsTArray<nsRefPtr<Volume>> VolumeArray;
+  typedef nsTArray<RefPtr<Volume> > VolumeArray;
 
   AutoMounter()
     : mResponseCallback(new AutoMounterResponseCallback),
       mMode(AUTOMOUNTER_DISABLE)
   {
     VolumeManager::RegisterStateObserver(&mVolumeManagerStateObserver);
     Volume::RegisterObserver(&mVolumeEventObserver);
 
     VolumeManager::VolumeArray::size_type numVolumes = VolumeManager::NumVolumes();
     VolumeManager::VolumeArray::index_type i;
     for (i = 0; i < numVolumes; i++) {
-      nsRefPtr<Volume> vol = VolumeManager::GetVolume(i);
+      RefPtr<Volume> vol = VolumeManager::GetVolume(i);
       if (vol) {
         vol->RegisterObserver(&mVolumeEventObserver);
         // We need to pick up the intial value of the
         // ums.volume.NAME.enabled setting.
         AutoMounterSetting::CheckVolumeSettings(vol->Name());
       }
     }
 
@@ -193,17 +193,17 @@ public:
     UpdateState();
   }
 
   ~AutoMounter()
   {
     VolumeManager::VolumeArray::size_type numVolumes = VolumeManager::NumVolumes();
     VolumeManager::VolumeArray::index_type volIndex;
     for (volIndex = 0; volIndex < numVolumes; volIndex++) {
-      nsRefPtr<Volume> vol = VolumeManager::GetVolume(volIndex);
+      RefPtr<Volume> vol = VolumeManager::GetVolume(volIndex);
       if (vol) {
         vol->UnregisterObserver(&mVolumeEventObserver);
       }
     }
     Volume::UnregisterObserver(&mVolumeEventObserver);
     VolumeManager::UnregisterStateObserver(&mVolumeManagerStateObserver);
   }
 
@@ -247,67 +247,67 @@ public:
       mMode = aMode;
       DBG("Calling UpdateState due to mode set to %d", mMode);
       UpdateState();
     }
   }
 
   void SetSharingMode(const nsACString& aVolumeName, bool aAllowSharing)
   {
-    nsRefPtr<Volume> vol = VolumeManager::FindVolumeByName(aVolumeName);
+    RefPtr<Volume> vol = VolumeManager::FindVolumeByName(aVolumeName);
     if (!vol) {
       return;
     }
     if (vol->IsSharingEnabled() == aAllowSharing) {
       return;
     }
     vol->SetUnmountRequested(false);
     vol->SetMountRequested(false);
     vol->SetSharingEnabled(aAllowSharing);
     DBG("Calling UpdateState due to volume %s shareing set to %d",
         vol->NameStr(), (int)aAllowSharing);
     UpdateState();
   }
 
   void FormatVolume(const nsACString& aVolumeName)
   {
-    nsRefPtr<Volume> vol = VolumeManager::FindVolumeByName(aVolumeName);
+    RefPtr<Volume> vol = VolumeManager::FindVolumeByName(aVolumeName);
     if (!vol) {
       return;
     }
     if (vol->IsFormatRequested()) {
       return;
     }
     vol->SetUnmountRequested(false);
     vol->SetMountRequested(false);
     vol->SetFormatRequested(true);
     DBG("Calling UpdateState due to volume %s formatting set to %d",
         vol->NameStr(), (int)vol->IsFormatRequested());
     UpdateState();
   }
 
   void MountVolume(const nsACString& aVolumeName)
   {
-    nsRefPtr<Volume> vol = VolumeManager::FindVolumeByName(aVolumeName);
+    RefPtr<Volume> vol = VolumeManager::FindVolumeByName(aVolumeName);
     if (!vol) {
       return;
     }
     vol->SetUnmountRequested(false);
     if (vol->IsMountRequested() || vol->mState == nsIVolume::STATE_MOUNTED) {
       return;
     }
     vol->SetMountRequested(true);
     DBG("Calling UpdateState due to volume %s mounting set to %d",
         vol->NameStr(), (int)vol->IsMountRequested());
     UpdateState();
   }
 
   void UnmountVolume(const nsACString& aVolumeName)
   {
-    nsRefPtr<Volume> vol = VolumeManager::FindVolumeByName(aVolumeName);
+    RefPtr<Volume> vol = VolumeManager::FindVolumeByName(aVolumeName);
     if (!vol) {
       return;
     }
     if (vol->IsUnmountRequested()) {
       return;
     }
     vol->SetMountRequested(false);
     vol->SetUnmountRequested(true);
@@ -444,17 +444,17 @@ AutoMounter::UpdateState()
   LOG("UpdateState: umsAvail:%d umsEnabled:%d mode:%d usbCablePluggedIn:%d tryToShare:%d",
       umsAvail, umsEnabled, mMode, usbCablePluggedIn, tryToShare);
 
   bool filesOpen = false;
   static unsigned filesOpenDelayCount = 0;
   VolumeArray::index_type volIndex;
   VolumeArray::size_type  numVolumes = VolumeManager::NumVolumes();
   for (volIndex = 0; volIndex < numVolumes; volIndex++) {
-    nsRefPtr<Volume>  vol = VolumeManager::GetVolume(volIndex);
+    RefPtr<Volume>  vol = VolumeManager::GetVolume(volIndex);
     Volume::STATE   volState = vol->State();
 
     if (vol->State() == nsIVolume::STATE_MOUNTED) {
       LOG("UpdateState: Volume %s is %s and %s @ %s gen %d locked %d sharing %c",
           vol->NameStr(), vol->StateStr(),
           vol->MediaPresent() ? "inserted" : "missing",
           vol->MountPoint().get(), vol->MountGeneration(),
           (int)vol->IsMountLocked(),
@@ -687,31 +687,31 @@ UsbCableEventIOThread()
 *
 *   Public API
 *
 *   Since the AutoMounter runs in IO Thread context, we need to switch
 *   to IOThread context before we can do anything.
 *
 **************************************************************************/
 
-class UsbCableObserver MOZ_FINAL : public SwitchObserver
+class UsbCableObserver : public SwitchObserver,
+                         public RefCounted<UsbCableObserver>
 {
+public:
+  MOZ_DECLARE_REFCOUNTED_TYPENAME(UsbCableObserver)
+  UsbCableObserver()
+  {
+    RegisterSwitchObserver(SWITCH_USB, this);
+  }
+
   ~UsbCableObserver()
   {
     UnregisterSwitchObserver(SWITCH_USB, this);
   }
 
-public:
-  NS_INLINE_DECL_REFCOUNTING(UsbCableObserver)
-
-  UsbCableObserver()
-  {
-    RegisterSwitchObserver(SWITCH_USB, this);
-  }
-
   virtual void Notify(const SwitchEvent& aEvent)
   {
     DBG("UsbCable switch device: %d state: %s\n",
         aEvent.device(), SwitchStateStr(aEvent));
     XRE_GetIOMessageLoop()->PostTask(
         FROM_HERE,
         NewRunnableFunction(UsbCableEventIOThread));
   }
--- a/dom/system/gonk/Volume.h
+++ b/dom/system/gonk/Volume.h
@@ -4,36 +4,35 @@
 
 #ifndef mozilla_system_volume_h__
 #define mozilla_system_volume_h__
 
 #include "VolumeCommand.h"
 #include "nsIVolume.h"
 #include "nsString.h"
 #include "mozilla/Observer.h"
-#include "nsISupportsImpl.h"
+#include "mozilla/RefPtr.h"
 #include "nsWhitespaceTokenizer.h"
 
 namespace mozilla {
 namespace system {
 
 /***************************************************************************
 *
 *   There is an instance of the Volume class for each volume reported
 *   from vold.
 *
 *   Each volume originates from the /system/etv/vold.fstab file.
 *
 ***************************************************************************/
 
-class Volume MOZ_FINAL
+class Volume : public RefCounted<Volume>
 {
 public:
-  NS_INLINE_DECL_REFCOUNTING(Volume)
-
+  MOZ_DECLARE_REFCOUNTED_TYPENAME(Volume)
   Volume(const nsCSubstring& aVolumeName);
 
   typedef long STATE; // States are now defined in nsIVolume.idl
 
   static const char* StateStr(STATE aState) { return NS_VolumeStateStr(aState); }
   const char* StateStr() const  { return StateStr(mState); }
   STATE State() const           { return mState; }
 
--- a/dom/system/gonk/VolumeCommand.h
+++ b/dom/system/gonk/VolumeCommand.h
@@ -1,17 +1,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_system_volumecommand_h__
 #define mozilla_system_volumecommand_h__
 
 #include "nsString.h"
-#include "nsISupportsImpl.h"
 #include "mozilla/RefPtr.h"
 #include <algorithm>
 #include <vold/ResponseCode.h>
 
 namespace mozilla {
 namespace system {
 
 class Volume;
@@ -28,26 +27,25 @@ class VolumeCommand;
 *   The responses from vold are all of the form:
 *
 *     <ResponseCode> <String>
 *
 *   Valid Response codes can be found in the vold/ResponseCode.h header.
 *
 ***************************************************************************/
 
-class VolumeResponseCallback
+class VolumeResponseCallback : public RefCounted<VolumeResponseCallback>
 {
-protected:
-  virtual ~VolumeResponseCallback() {}
-
 public:
-  NS_INLINE_DECL_REFCOUNTED(VolumeResponseCallback)
+  MOZ_DECLARE_REFCOUNTED_TYPENAME(VolumeResponseCallback)
   VolumeResponseCallback()
     : mResponseCode(0), mPending(false) {}
 
+  virtual ~VolumeResponseCallback() {}
+
   bool Done() const
   {
     // Response codes from the 200, 400, and 500 series all indicated that
     // the command has completed.
 
     return (mResponseCode >= ResponseCode::CommandOkay)
         && (mResponseCode < ResponseCode::UnsolicitedInformational);
   }
@@ -103,38 +101,36 @@ private:
 *   Commands sent to vold need an explicit null character so we add one
 *   to the command to ensure that it's included in the length.
 *
 *   All of these commands are asynchronous in nature, and the
 *   ResponseReceived callback will be called when a response is available.
 *
 ***************************************************************************/
 
-class VolumeCommand
+class VolumeCommand : public RefCounted<VolumeCommand>
 {
-protected:
-  virtual ~VolumeCommand() {}
-
 public:
-  NS_INLINE_DECL_REFCOUNTED(VolumeCommand)
-
+  MOZ_DECLARE_REFCOUNTED_TYPENAME(VolumeCommand)
   VolumeCommand(VolumeResponseCallback* aCallback)
     : mBytesConsumed(0),
       mCallback(aCallback)
   {
     SetCmd(NS_LITERAL_CSTRING(""));
   }
 
   VolumeCommand(const nsACString& aCommand, VolumeResponseCallback* aCallback)
     : mBytesConsumed(0),
       mCallback(aCallback)
   {
     SetCmd(aCommand);
   }
 
+  virtual ~VolumeCommand() {}
+
   void SetCmd(const nsACString& aCommand)
   {
     mCmd.Truncate();
 #if ANDROID_VERSION >= 17
     // JB requires a sequence number at the beginning of messages.
     // It doesn't matter what we use, so we use 0.
     mCmd = "0 ";
 #endif
--- a/dom/system/gonk/VolumeManager.h
+++ b/dom/system/gonk/VolumeManager.h
@@ -6,17 +6,17 @@
 #define mozilla_system_volumemanager_h__
 
 #include <vector>
 #include <queue>
 
 #include "base/message_loop.h"
 #include "mozilla/FileUtils.h"
 #include "mozilla/Observer.h"
-#include "nsISupportsImpl.h"
+#include "mozilla/RefPtr.h"
 #include "nsString.h"
 #include "nsTArray.h"
 
 #include "Volume.h"
 #include "VolumeCommand.h"
 
 namespace mozilla {
 namespace system {
@@ -68,26 +68,26 @@ namespace system {
 *   There is also a command line tool called vdc, which can be used to send
 *   the above commands to vold.
 *
 *   Currently, only the volume list, share/unshare, and mount/unmount
 *   commands are being used.
 *
 ***************************************************************************/
 
-class VolumeManager MOZ_FINAL : public MessageLoopForIO::LineWatcher
+class VolumeManager : public MessageLoopForIO::LineWatcher,
+                      public RefCounted<VolumeManager>
 {
-  virtual ~VolumeManager();
+public:
+  MOZ_DECLARE_REFCOUNTED_TYPENAME(VolumeManager)
 
-public:
-  NS_INLINE_DECL_REFCOUNTING(VolumeManager)
-
-  typedef nsTArray<RefPtr<Volume>> VolumeArray;
+  typedef nsTArray<RefPtr<Volume> > VolumeArray;
 
   VolumeManager();
+  virtual ~VolumeManager();
 
   //-----------------------------------------------------------------------
   //
   // State related methods.
   //
   // The VolumeManager starts off in the STARTING state. Once a connection
   // is established with vold, it asks for a list of volumes, and once the
   // volume list has been received, then the VolumeManager enters the
--- a/dom/system/gonk/VolumeServiceIOThread.h
+++ b/dom/system/gonk/VolumeServiceIOThread.h
@@ -14,25 +14,24 @@ namespace system {
 
 class nsVolumeService;
 
 /***************************************************************************
 * The nsVolumeServiceIOThread is a companion class to the nsVolumeService
 * class, but whose methods are called from IOThread.
 */
 class VolumeServiceIOThread : public VolumeManager::StateObserver,
-                              public Volume::EventObserver
+                              public Volume::EventObserver,
+                              public RefCounted<VolumeServiceIOThread>
 {
+public:
+  MOZ_DECLARE_REFCOUNTED_TYPENAME(VolumeServiceIOThread)
+  VolumeServiceIOThread(nsVolumeService* aVolumeService);
   ~VolumeServiceIOThread();
 
-public:
-  NS_INLINE_DECL_REFCOUNTING(VolumeServiceIOThread)
-
-  VolumeServiceIOThread(nsVolumeService* aVolumeService);
-
 private:
   void  UpdateAllVolumes();
 
   virtual void Notify(const VolumeManager::StateChangedEvent& aEvent);
   virtual void Notify(Volume* const & aVolume);
 
   RefPtr<nsVolumeService>   mVolumeService;
 };
--- a/gfx/layers/Compositor.h
+++ b/gfx/layers/Compositor.h
@@ -132,22 +132,28 @@ enum SurfaceInitMode
 {
   INIT_MODE_NONE,
   INIT_MODE_CLEAR
 };
 
 /**
  * A base class for a platform-dependent helper for use by TextureHost.
  */
-class CompositorBackendSpecificData
+class CompositorBackendSpecificData : public RefCounted<CompositorBackendSpecificData>
 {
-  NS_INLINE_DECL_REFCOUNTING(CompositorBackendSpecificData)
-
-protected:
-  virtual ~CompositorBackendSpecificData() {}
+public:
+  MOZ_DECLARE_REFCOUNTED_TYPENAME(CompositorBackendSpecificData)
+  CompositorBackendSpecificData()
+  {
+    MOZ_COUNT_CTOR(CompositorBackendSpecificData);
+  }
+  virtual ~CompositorBackendSpecificData()
+  {
+    MOZ_COUNT_DTOR(CompositorBackendSpecificData);
+  }
 };
 
 /**
  * Common interface for compositor backends.
  *
  * Compositor provides a cross-platform interface to a set of operations for
  * compositing quads. Compositor knows nothing about the layer tree. It must be
  * told everything about each composited quad - contents, location, transform,
@@ -184,30 +190,31 @@ protected:
  *
  * By default, the compositor will render to the screen, to render to a target,
  * call SetTargetContext or SetRenderTarget, the latter with a target created
  * by CreateRenderTarget or CreateRenderTargetFromSource.
  *
  * The target and viewport methods can be called before any DrawQuad call and
  * affect any subsequent DrawQuad calls.
  */
-class Compositor
+class Compositor : public RefCounted<Compositor>
 {
-protected:
-  virtual ~Compositor() {}
-
 public:
-  NS_INLINE_DECL_REFCOUNTING(Compositor)
-
+  MOZ_DECLARE_REFCOUNTED_TYPENAME(Compositor)
   Compositor(PCompositorParent* aParent = nullptr)
     : mCompositorID(0)
     , mDiagnosticTypes(DIAGNOSTIC_NONE)
     , mParent(aParent)
     , mScreenRotation(ROTATION_0)
   {
+    MOZ_COUNT_CTOR(Compositor);
+  }
+  virtual ~Compositor()
+  {
+    MOZ_COUNT_DTOR(Compositor);
   }
 
   virtual TemporaryRef<DataTextureSource> CreateDataTextureSource(TextureFlags aFlags = 0) = 0;
   virtual bool Initialize() = 0;
   virtual void Destroy() = 0;
 
   /**
    * Return true if the effect type is supported.
--- a/gfx/layers/Effects.h
+++ b/gfx/layers/Effects.h
@@ -32,28 +32,25 @@ namespace layers {
  * - any way in which rendering can be changed, e.g., applying a mask layer.
  *
  * During the rendering process, an effect chain is created by the layer being
  * rendered and the primary effect is added by the compositable host. Secondary
  * effects may be added by the layer or compositable. The effect chain is passed
  * to the compositor by the compositable host as a parameter to DrawQuad.
  */
 
-struct Effect
+struct Effect : public RefCounted<Effect>
 {
-  NS_INLINE_DECL_REFCOUNTING(Effect)
-
+  MOZ_DECLARE_REFCOUNTED_TYPENAME(Effect)
   Effect(EffectTypes aType) : mType(aType) {}
 
   EffectTypes mType;
 
-  virtual void PrintInfo(nsACString& aTo, const char* aPrefix) = 0;
-
-protected:
   virtual ~Effect() {}
+  virtual void PrintInfo(nsACString& aTo, const char* aPrefix) =0;
 };
 
 // Render from a texture
 struct TexturedEffect : public Effect
 {
   TexturedEffect(EffectTypes aType,
                  TextureSource *aTexture,
                  bool aPremultiplied,
--- a/gfx/layers/client/CompositableClient.h
+++ b/gfx/layers/client/CompositableClient.h
@@ -63,25 +63,23 @@ class TextureClientData;
  * by this layer forwarder (the matching uses a global map on the compositor side,
  * see CompositableMap in ImageBridgeParent.cpp)
  *
  * Subclasses: Thebes layers use ContentClients, ImageLayers use ImageClients,
  * Canvas layers use CanvasClients (but ImageHosts). We have a different subclass
  * where we have a different way of interfacing with the textures - in terms of
  * drawing into the compositable and/or passing its contents to the compostior.
  */
-class CompositableClient
+class CompositableClient : public AtomicRefCounted<CompositableClient>
 {
-protected:
-  virtual ~CompositableClient();
+public:
+  MOZ_DECLARE_REFCOUNTED_TYPENAME(CompositableClient)
+  CompositableClient(CompositableForwarder* aForwarder, TextureFlags aFlags = 0);
 
-public:
-  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(CompositableClient)
-
-  CompositableClient(CompositableForwarder* aForwarder, TextureFlags aFlags = 0);
+  virtual ~CompositableClient();
 
   virtual TextureInfo GetTextureInfo() const = 0;
 
   LayersBackend GetCompositorBackendType() const;
 
   TemporaryRef<BufferTextureClient>
   CreateBufferTextureClient(gfx::SurfaceFormat aFormat,
                             TextureFlags aFlags = TEXTURE_FLAGS_DEFAULT,
--- a/gfx/layers/client/SimpleTextureClientPool.h
+++ b/gfx/layers/client/SimpleTextureClientPool.h
@@ -14,31 +14,31 @@
 #include <stack>
 #include <list>
 
 namespace mozilla {
 namespace layers {
 
 class ISurfaceAllocator;
 
-class SimpleTextureClientPool
+class SimpleTextureClientPool : public RefCounted<SimpleTextureClientPool>
 {
+public:
+  MOZ_DECLARE_REFCOUNTED_TYPENAME(SimpleTextureClientPool)
+
+  SimpleTextureClientPool(gfx::SurfaceFormat aFormat, gfx::IntSize aSize,
+                          ISurfaceAllocator *aAllocator);
+
   ~SimpleTextureClientPool()
   {
     for (auto it = mOutstandingTextureClients.begin(); it != mOutstandingTextureClients.end(); ++it) {
       (*it)->ClearRecycleCallback();
     }
   }
 
-public:
-  NS_INLINE_DECL_REFCOUNTING(SimpleTextureClientPool)
-
-  SimpleTextureClientPool(gfx::SurfaceFormat aFormat, gfx::IntSize aSize,
-                          ISurfaceAllocator *aAllocator);
-
   /**
    * If a TextureClient is AutoRecycled, when the last reference is
    * released this object will be automatically return to the pool as
    * soon as the compositor informs us it is done with it.
    */
   TemporaryRef<TextureClient> GetTextureClient(bool aAutoRecycle = false);
   TemporaryRef<TextureClient> GetTextureClientWithAutoRecycle() { return GetTextureClient(true); }
 
--- a/gfx/layers/client/TextureClient.cpp
+++ b/gfx/layers/client/TextureClient.cpp
@@ -70,27 +70,33 @@ namespace layers {
  * TextureChild is used to synchronize a texture client and its corresponding
  * TextureHost if needed (a TextureClient that is not shared with the compositor
  * does not have a TextureChild)
  *
  * During the deallocation phase, a TextureChild may hold its recently destroyed
  * TextureClient's data until the compositor side confirmed that it is safe to
  * deallocte or recycle the it.
  */
-class TextureChild MOZ_FINAL : public PTextureChild
+class TextureChild : public PTextureChild
+                   , public AtomicRefCounted<TextureChild>
 {
 public:
-  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(TextureChild)
-
+  MOZ_DECLARE_REFCOUNTED_TYPENAME(TextureChild)
   TextureChild()
   : mForwarder(nullptr)
   , mTextureData(nullptr)
   , mTextureClient(nullptr)
   , mIPCOpen(false)
   {
+    MOZ_COUNT_CTOR(TextureChild);
+  }
+
+  ~TextureChild()
+  {
+    MOZ_COUNT_DTOR(TextureChild);
   }
 
   bool Recv__delete__() MOZ_OVERRIDE;
 
   bool RecvCompositorRecycle(const MaybeFenceHandle& aFence)
   {
     RECYCLE_LOG("Receive recycle %p (%p)\n", mTextureClient, mWaitForRecycle.get());
     if (aFence.type() != aFence.Tnull_t) {
--- a/gfx/layers/client/TextureClientPool.h
+++ b/gfx/layers/client/TextureClientPool.h
@@ -13,25 +13,23 @@
 #include "nsITimer.h"
 #include <stack>
 
 namespace mozilla {
 namespace layers {
 
 class ISurfaceAllocator;
 
-class TextureClientPool MOZ_FINAL
+class TextureClientPool : public RefCounted<TextureClientPool>
 {
-  ~TextureClientPool();
-
 public:
-  NS_INLINE_DECL_REFCOUNTING(TextureClientPool)
-
+  MOZ_DECLARE_REFCOUNTED_TYPENAME(TextureClientPool)
   TextureClientPool(gfx::SurfaceFormat aFormat, gfx::IntSize aSize,
                     ISurfaceAllocator *aAllocator);
+  ~TextureClientPool();
 
   /**
    * Gets an allocated TextureClient of size and format that are determined
    * by the initialisation parameters given to the pool. This will either be
    * a cached client that was returned to the pool, or a newly allocated
    * client if one isn't available.
    *
    * All clients retrieved by this method should be returned using the return
--- a/gfx/layers/client/TiledContentClient.h
+++ b/gfx/layers/client/TiledContentClient.h
@@ -42,23 +42,21 @@ namespace mozilla {
 namespace layers {
 
 class BasicTileDescriptor;
 class ClientTiledThebesLayer;
 class ClientLayerManager;
 
 
 // A class to help implement copy-on-write semantics for shared tiles.
-class gfxSharedReadLock {
-protected:
+class gfxSharedReadLock : public AtomicRefCounted<gfxSharedReadLock> {
+public:
+  MOZ_DECLARE_REFCOUNTED_TYPENAME(gfxSharedReadLock)
   virtual ~gfxSharedReadLock() {}
 
-public:
-  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(gfxSharedReadLock)
-
   virtual int32_t ReadLock() = 0;
   virtual int32_t ReadUnlock() = 0;
   virtual int32_t GetReadCount() = 0;
   virtual bool IsValid() const = 0;
 
   enum gfxSharedReadLockType {
     TYPE_MEMORY,
     TYPE_SHMEM
--- a/gfx/layers/composite/AsyncCompositionManager.h
+++ b/gfx/layers/composite/AsyncCompositionManager.h
@@ -56,31 +56,32 @@ struct ViewTransform {
 /**
  * Manage async composition effects. This class is only used with OMTC and only
  * lives on the compositor thread. It is a layer on top of the layer manager
  * (LayerManagerComposite) which deals with elements of composition which are
  * usually dealt with by dom or layout when main thread rendering, but which can
  * short circuit that stuff to directly affect layers as they are composited,
  * for example, off-main thread animation, async video, async pan/zoom.
  */
-class AsyncCompositionManager MOZ_FINAL
+class AsyncCompositionManager MOZ_FINAL : public RefCounted<AsyncCompositionManager>
 {
   friend class AutoResolveRefLayers;
 public:
-  NS_INLINE_DECL_REFCOUNTING(AsyncCompositionManager)
-
+  MOZ_DECLARE_REFCOUNTED_TYPENAME(AsyncCompositionManager)
   AsyncCompositionManager(LayerManagerComposite* aManager)
     : mLayerManager(aManager)
     , mIsFirstPaint(false)
     , mLayersUpdated(false)
     , mReadyForCompose(true)
   {
+    MOZ_COUNT_CTOR(AsyncCompositionManager);
   }
   ~AsyncCompositionManager()
   {
+    MOZ_COUNT_DTOR(AsyncCompositionManager);
   }
 
   /**
    * This forces the is-first-paint flag to true. This is intended to
    * be called by the widget code when it loses its viewport information
    * (or for whatever reason wants to refresh the viewport information).
    * The information refresh happens because the compositor will call
    * SetFirstPaintViewport on the next frame of composition.
--- a/gfx/layers/composite/CompositableHost.h
+++ b/gfx/layers/composite/CompositableHost.h
@@ -51,28 +51,28 @@ class Compositor;
 class ISurfaceAllocator;
 class ThebesBufferData;
 class TiledLayerComposer;
 struct EffectChain;
 
 /**
  * A base class for doing CompositableHost and platform dependent task on TextureHost.
  */
-class CompositableBackendSpecificData
+class CompositableBackendSpecificData : public RefCounted<CompositableBackendSpecificData>
 {
-protected:
-  virtual ~CompositableBackendSpecificData() { }
-
 public:
-  NS_INLINE_DECL_REFCOUNTING(CompositableBackendSpecificData)
-
+  MOZ_DECLARE_REFCOUNTED_TYPENAME(CompositableBackendSpecificData)
   CompositableBackendSpecificData()
   {
+    MOZ_COUNT_CTOR(CompositableBackendSpecificData);
   }
-
+  virtual ~CompositableBackendSpecificData()
+  {
+    MOZ_COUNT_DTOR(CompositableBackendSpecificData);
+  }
   virtual void SetCompositor(Compositor* aCompositor) {}
   virtual void ClearData()
   {
     mCurrentReleaseFenceTexture = nullptr;
     ClearPendingReleaseFenceTextureList();
   }
 
   /**
@@ -119,25 +119,24 @@ protected:
  * the layers transaction to update the Compositbale's textures from the
  * content side. The actual update (and any syncronous upload) is done by the
  * TextureHost, but it is coordinated by the CompositableHost.
  *
  * Composite is called by the owning layer when it is composited. CompositableHost
  * will use its TextureHost(s) and call Compositor::DrawQuad to do the actual
  * rendering.
  */
-class CompositableHost
+class CompositableHost : public RefCounted<CompositableHost>
 {
-protected:
+public:
+  MOZ_DECLARE_REFCOUNTED_TYPENAME(CompositableHost)
+  CompositableHost(const TextureInfo& aTextureInfo);
+
   virtual ~CompositableHost();
 
-public:
-  NS_INLINE_DECL_REFCOUNTING(CompositableHost)
-  CompositableHost(const TextureInfo& aTextureInfo);
-
   static TemporaryRef<CompositableHost> Create(const TextureInfo& aTextureInfo);
 
   virtual CompositableType GetType() = 0;
 
   virtual CompositableBackendSpecificData* GetCompositableBackendSpecificData()
   {
     return mBackendData;
   }
--- a/gfx/layers/composite/TextRenderer.h
+++ b/gfx/layers/composite/TextRenderer.h
@@ -2,29 +2,27 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef GFX_TextRenderer_H
 #define GFX_TextRenderer_H
 
 #include "mozilla/gfx/2D.h"
-#include "nsISupportsImpl.h"
 #include <string>
 
 namespace mozilla {
 namespace layers {
 
 class Compositor;
 
-class TextRenderer
+class TextRenderer : public RefCounted<TextRenderer>
 {
 public:
-  NS_INLINE_DECL_REFCOUNTING(TextRenderer)
-
+  MOZ_DECLARE_REFCOUNTED_TYPENAME(TextRenderer)
   TextRenderer(Compositor *aCompositor)
     : mCompositor(aCompositor)
   {
   }
 
   ~TextRenderer();
 
   void RenderText(const std::string& aText, const gfx::IntPoint& aOrigin,
--- a/gfx/layers/composite/TextureHost.h
+++ b/gfx/layers/composite/TextureHost.h
@@ -75,26 +75,23 @@ public:
  * TextureSource is the interface for texture objects that can be composited
  * by a given compositor backend. Since the drawing APIs are different
  * between backends, the TextureSource interface is split into different
  * interfaces (TextureSourceOGL, etc.), and TextureSource mostly provide
  * access to these interfaces.
  *
  * This class is used on the compositor side.
  */
-class TextureSource
+class TextureSource : public RefCounted<TextureSource>
 {
-protected:
+public:
+  MOZ_DECLARE_REFCOUNTED_TYPENAME(TextureSource)
+  TextureSource();
   virtual ~TextureSource();
 
-public:
-  NS_INLINE_DECL_REFCOUNTING(TextureSource)
-
-  TextureSource();
-
   /**
    * Return the size of the texture in texels.
    * If this is a tile iterator, GetSize must return the size of the current tile.
    */
   virtual gfx::IntSize GetSize() const = 0;
 
   /**
    * Return the pixel format of this texture
--- a/gfx/layers/ipc/LayerTransactionChild.h
+++ b/gfx/layers/ipc/LayerTransactionChild.h
@@ -18,35 +18,38 @@ namespace mozilla {
 
 namespace layout {
 class RenderFrameChild;
 }
 
 namespace layers {
 
 class LayerTransactionChild : public PLayerTransactionChild
+                            , public AtomicRefCounted<LayerTransactionChild>
 {
 public:
-  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(LayerTransactionChild)
+  MOZ_DECLARE_REFCOUNTED_TYPENAME(LayerTransactionChild)
   /**
    * Clean this up, finishing with Send__delete__().
    *
    * It is expected (checked with an assert) that all shadow layers
    * created by this have already been destroyed and
    * Send__delete__()d by the time this method is called.
    */
   void Destroy();
 
   bool IPCOpen() const { return mIPCOpen; }
 
 protected:
   LayerTransactionChild()
     : mIPCOpen(false)
   {}
   ~LayerTransactionChild() { }
+  friend class AtomicRefCounted<LayerTransactionChild>;
+  friend class detail::RefCounted<LayerTransactionChild, detail::AtomicRefCount>;
 
   virtual PGrallocBufferChild*
   AllocPGrallocBufferChild(const IntSize&,
                            const uint32_t&, const uint32_t&,
                            MaybeMagicGrallocBufferHandle*) MOZ_OVERRIDE;
   virtual bool
   DeallocPGrallocBufferChild(PGrallocBufferChild* actor) MOZ_OVERRIDE;
 
--- a/gfx/layers/opengl/CompositorOGL.h
+++ b/gfx/layers/opengl/CompositorOGL.h
@@ -59,24 +59,23 @@ struct EffectChain;
  * Interface for pools of temporary gl textures for the compositor.
  * The textures are fully owned by the pool, so the latter is responsible
  * calling fDeleteTextures accordingly.
  * Users of GetTexture receive a texture that is only valid for the duration
  * of the current frame.
  * This is primarily intended for direct texturing APIs that need to attach
  * shared objects (such as an EGLImage) to a gl texture.
  */
-class CompositorTexturePoolOGL
+class CompositorTexturePoolOGL : public RefCounted<CompositorTexturePoolOGL>
 {
-protected:
+public:
+  MOZ_DECLARE_REFCOUNTED_TYPENAME(CompositorTexturePoolOGL)
+
   virtual ~CompositorTexturePoolOGL() {}
 
-public:
-  NS_INLINE_DECL_REFCOUNTING(CompositorTexturePoolOGL)
-
   virtual void Clear() = 0;
 
   virtual GLuint GetTexture(GLenum aTarget, GLenum aEnum) = 0;
 
   virtual void EndFrame() = 0;
 };
 
 /**
--- a/gfx/src/FilterSupport.cpp
+++ b/gfx/src/FilterSupport.cpp
@@ -225,20 +225,20 @@ namespace FilterWrappers {
 // A class that wraps a FilterNode and handles conversion between different
 // color models. Create FilterCachedColorModels with your original filter and
 // the color model that this filter outputs in natively, and then call
 // ->ForColorModel(colorModel) in order to get a FilterNode which outputs to
 // the specified colorModel.
 // Internally, this is achieved by wrapping the original FilterNode with
 // conversion FilterNodes. These filter nodes are cached in such a way that no
 // repeated or back-and-forth conversions happen.
-class FilterCachedColorModels
+class FilterCachedColorModels : public RefCounted<FilterCachedColorModels>
 {
 public:
-  NS_INLINE_DECL_REFCOUNTING(FilterCachedColorModels)
+  MOZ_DECLARE_REFCOUNTED_TYPENAME(FilterCachedColorModels)
   // aFilter can be null. In that case, ForColorModel will return a non-null
   // completely transparent filter for all color models.
   FilterCachedColorModels(DrawTarget* aDT,
                           FilterNode* aFilter,
                           ColorModel aOriginalColorModel);
 
   // Get a FilterNode for the specified color model, guaranteed to be non-null.
   TemporaryRef<FilterNode> ForColorModel(ColorModel aColorModel);
--- a/hal/gonk/GonkHal.cpp
+++ b/hal/gonk/GonkHal.cpp
@@ -289,21 +289,21 @@ public:
 
     hal::NotifyBatteryChange(info);
     return NS_OK;
   }
 };
 
 } // anonymous namespace
 
-class BatteryObserver : public IUeventObserver
+class BatteryObserver : public IUeventObserver,
+                        public RefCounted<BatteryObserver>
 {
 public:
-  NS_INLINE_DECL_REFCOUNTING(BatteryObserver)
-
+  MOZ_DECLARE_REFCOUNTED_TYPENAME(BatteryObserver)
   BatteryObserver()
     :mUpdater(new BatteryUpdater())
   {
   }
 
   virtual void Notify(const NetlinkEvent &aEvent)
   {
     // this will run on IO thread
--- a/hal/gonk/GonkSwitch.cpp
+++ b/hal/gonk/GonkSwitch.cpp
@@ -46,21 +46,20 @@ namespace hal_impl {
  *  change@/devices/virtual/switch/usb_configuration
  *    ACTION=change
  *    DEVPATH=/devices/virtual/switch/usb_configuration
  *    SUBSYSTEM=switch
  *    SWITCH_NAME=usb_configuration
  *    SWITCH_STATE=0
  *    SEQNUM=5038
  */
-class SwitchHandler
+class SwitchHandler : public RefCounted<SwitchHandler>
 {
 public:
-  NS_INLINE_DECL_REFCOUNTING(SwitchHandler)
-
+  MOZ_DECLARE_REFCOUNTED_TYPENAME(SwitchHandler)
   SwitchHandler(const char* aDevPath, SwitchDevice aDevice)
     : mDevPath(aDevPath),
       mState(SWITCH_STATE_UNKNOWN),
       mDevice(aDevice)
   {
     GetInitialState();
   }
 
@@ -226,30 +225,31 @@ public:
   {
     NotifySwitchChange(mEvent);
     return NS_OK;
   }
 private:
   SwitchEvent mEvent;
 };
 
-class SwitchEventObserver MOZ_FINAL : public IUeventObserver
+class SwitchEventObserver : public IUeventObserver,
+                            public RefCounted<SwitchEventObserver>
 {
+public:
+  MOZ_DECLARE_REFCOUNTED_TYPENAME(SwitchEventObserver)
+  SwitchEventObserver() : mEnableCount(0)
+  {
+    Init();
+  }
+
   ~SwitchEventObserver()
   {
     mHandler.Clear();
   }
 
-public:
-  NS_INLINE_DECL_REFCOUNTING(SwitchEventObserver)
-  SwitchEventObserver() : mEnableCount(0)
-  {
-    Init();
-  }
-
   int GetEnableCount()
   {
     return mEnableCount;
   }
 
   void EnableSwitch(SwitchDevice aDevice)
   {
     mEventInfo[aDevice].mEnabled = true;
--- a/image/src/SurfaceCache.cpp
+++ b/image/src/SurfaceCache.cpp
@@ -105,21 +105,20 @@ private:
   CachedSurface* mSurface;
   Cost           mCost;
 };
 
 /*
  * A CachedSurface associates a surface with a key that uniquely identifies that
  * surface.
  */
-class CachedSurface
+class CachedSurface : public RefCounted<CachedSurface>
 {
 public:
-  NS_INLINE_DECL_REFCOUNTING(CachedSurface)
-
+  MOZ_DECLARE_REFCOUNTED_TYPENAME(CachedSurface)
   CachedSurface(DrawTarget*       aTarget,
                 const IntSize     aTargetSize,
                 const Cost        aCost,
                 const ImageKey    aImageKey,
                 const SurfaceKey& aSurfaceKey)
     : mTarget(aTarget)
     , mTargetSize(aTargetSize)
     , mCost(aCost)
@@ -152,21 +151,20 @@ private:
 };
 
 /*
  * An ImageSurfaceCache is a per-image surface cache. For correctness we must be
  * able to remove all surfaces associated with an image when the image is
  * destroyed or invalidated. Since this will happen frequently, it makes sense
  * to make it cheap by storing the surfaces for each image separately.
  */
-class ImageSurfaceCache
+class ImageSurfaceCache : public RefCounted<ImageSurfaceCache>
 {
 public:
-  NS_INLINE_DECL_REFCOUNTING(ImageSurfaceCache)
-
+  MOZ_DECLARE_REFCOUNTED_TYPENAME(ImageSurfaceCache)
   typedef nsRefPtrHashtable<nsGenericHashKey<SurfaceKey>, CachedSurface> SurfaceTable;
 
   bool IsEmpty() const { return mSurfaces.Count() == 0; }
   
   void Insert(const SurfaceKey& aKey, CachedSurface* aSurface)
   {
     MOZ_ASSERT(aSurface, "Should have a surface");
     mSurfaces.Put(aKey, aSurface);
--- a/ipc/netd/Netd.h
+++ b/ipc/netd/Netd.h
@@ -1,16 +1,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_system_netd_h__
 #define mozilla_system_netd_h__
 
-#include "nsISupportsImpl.h"
+#include "mozilla/RefPtr.h"
 #include "nsAutoPtr.h"
 #include "base/message_loop.h"
 #include "mozilla/FileUtils.h"
 
 #define MAX_COMMAND_SIZE  4096
 
 namespace mozilla {
 namespace ipc {
@@ -21,41 +21,38 @@ namespace ipc {
 struct NetdCommand
 {
   uint8_t mData[MAX_COMMAND_SIZE];
 
   // Number of octets in mData.
   size_t mSize;
 };
 
-class NetdConsumer
+class NetdConsumer : public mozilla::RefCounted<NetdConsumer>
 {
-protected:
+public:
+  MOZ_DECLARE_REFCOUNTED_TYPENAME(NetdConsumer)
   virtual ~NetdConsumer() { }
-
-public:
-  NS_INLINE_DECL_REFCOUNTING(NetdConsumer)
-
   virtual void MessageReceived(NetdCommand* aMessage) = 0;
 };
 
 class NetdWriteTask : public Task
 {
   virtual void Run();
 };
 
-class NetdClient : public MessageLoopForIO::LineWatcher
+class NetdClient : public MessageLoopForIO::LineWatcher,
+                   public RefCounted<NetdClient>
 {
-  virtual ~NetdClient();
-
 public:
-  NS_INLINE_DECL_REFCOUNTING(NetdClient)
+  MOZ_DECLARE_REFCOUNTED_TYPENAME(NetdClient)
   typedef std::queue<NetdCommand*> NetdCommandQueue;
 
   NetdClient();
+  virtual ~NetdClient();
   static void Start();
   static void SendNetdCommandIOThread(NetdCommand* aMessage);
 
 private:
   void WriteNetdCommand();
   virtual void OnError();
   virtual void OnLineRead(int aFd, nsDependentCSubstring& aMessage);
   virtual void OnFileCanWriteWithoutBlocking(int aFd);
--- a/ipc/unixsocket/UnixSocket.h
+++ b/ipc/unixsocket/UnixSocket.h
@@ -130,25 +130,23 @@ public:
 
 enum SocketConnectionStatus {
   SOCKET_DISCONNECTED = 0,
   SOCKET_LISTENING = 1,
   SOCKET_CONNECTING = 2,
   SOCKET_CONNECTED = 3
 };
 
-class UnixSocketConsumer
+class UnixSocketConsumer : public AtomicRefCounted<UnixSocketConsumer>
 {
-protected:
-  virtual ~UnixSocketConsumer();
+public:
+  MOZ_DECLARE_REFCOUNTED_TYPENAME(UnixSocketConsumer)
+  UnixSocketConsumer();
 
-public:
-  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(UnixSocketConsumer)
-
-  UnixSocketConsumer();
+  virtual ~UnixSocketConsumer();
 
   SocketConnectionStatus GetConnectionStatus() const
   {
     MOZ_ASSERT(NS_IsMainThread());
     return mConnectionStatus;
   }
 
   int GetSuggestedConnectDelayMs() const
--- a/layout/base/FrameLayerBuilder.h
+++ b/layout/base/FrameLayerBuilder.h
@@ -41,20 +41,19 @@ enum LayerState {
   // when the layer has rounded rect clips.
   LAYER_ACTIVE_FORCE,
   // Special layer that is metadata only.
   LAYER_ACTIVE_EMPTY,
   // Inactive style layer for rendering SVG effects.
   LAYER_SVG_EFFECTS
 };
 
-class RefCountedRegion {
+class RefCountedRegion : public RefCounted<RefCountedRegion> {
 public:
-  NS_INLINE_DECL_REFCOUNTING(RefCountedRegion)
-
+  MOZ_DECLARE_REFCOUNTED_TYPENAME(RefCountedRegion)
   RefCountedRegion() : mIsInfinite(false) {}
   nsRegion mRegion;
   bool mIsInfinite;
 };
 
 struct ContainerLayerParameters {
   ContainerLayerParameters() :
     mXScale(1), mYScale(1), mAncestorClipRect(nullptr),
--- a/security/manager/ssl/src/SharedCertVerifier.h
+++ b/security/manager/ssl/src/SharedCertVerifier.h
@@ -6,34 +6,32 @@
 #define mozilla_psm__SharedCertVerifier_h
 
 #include "certt.h"
 #include "CertVerifier.h"
 #include "mozilla/RefPtr.h"
 
 namespace mozilla { namespace psm {
 
-class SharedCertVerifier : public mozilla::psm::CertVerifier
+class SharedCertVerifier : public mozilla::psm::CertVerifier,
+                           public mozilla::AtomicRefCounted<SharedCertVerifier>
 {
-protected:
-  ~SharedCertVerifier();
-
 public:
-  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SharedCertVerifier)
-
+  MOZ_DECLARE_REFCOUNTED_TYPENAME(SharedCertVerifier)
   SharedCertVerifier(implementation_config ic,
 #ifndef NSS_NO_LIBPKIX
                      missing_cert_download_config ac, crl_download_config cdc,
 #endif
                      ocsp_download_config odc, ocsp_strict_config osc,
                      ocsp_get_config ogc)
     : mozilla::psm::CertVerifier(ic,
 #ifndef NSS_NO_LIBPKIX
                                  ac, cdc,
 #endif
                                  odc, osc, ogc)
   {
   }
+  ~SharedCertVerifier();
 };
 
 } } // namespace mozilla::psm
 
 #endif // mozilla_psm__SharedCertVerifier_h
--- a/xpcom/threads/BackgroundHangMonitor.cpp
+++ b/xpcom/threads/BackgroundHangMonitor.cpp
@@ -23,17 +23,17 @@
 #include <algorithm>
 
 namespace mozilla {
 
 /**
  * BackgroundHangManager is the global object that
  * manages all instances of BackgroundHangThread.
  */
-class BackgroundHangManager
+class BackgroundHangManager : public AtomicRefCounted<BackgroundHangManager>
 {
 private:
   // Background hang monitor thread function
   static void MonitorThread(void* aData)
   {
     PR_SetCurrentThreadName("BgHangManager");
 
 #ifdef MOZ_NUWA_PROCESS
@@ -57,17 +57,17 @@ private:
   // Stop hang monitoring
   bool mShutdown;
 
   BackgroundHangManager(const BackgroundHangManager&);
   BackgroundHangManager& operator=(const BackgroundHangManager&);
   void RunMonitorThread();
 
 public:
-  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(BackgroundHangManager)
+  MOZ_DECLARE_REFCOUNTED_TYPENAME(BackgroundHangManager)
   static StaticRefPtr<BackgroundHangManager> sInstance;
 
   // Lock for access to members of this class
   Monitor mLock;
   // Current time as seen by hang monitors
   PRIntervalTime mIntervalNow;
   // List of BackgroundHangThread instances associated with each thread
   LinkedList<BackgroundHangThread> mHangThreads;