Bug 884061 - Part 3f: Use NS_DECL_THREADSAFE_ISUPPORTS in dom/, r=smaug,dhylands.
authorJoshua Cranmer <Pidgeot18@gmail.com>
Thu, 18 Jul 2013 21:21:20 -0500
changeset 151889 8ba67ee6a81d06211c8516b6d3b12c16f584efb4
parent 151888 eb49396e9def51a527bbf267895af764949fb0db
child 151890 c073457f6b02d0e1d383f9897befe585fdbc2981
push id2859
push userakeybl@mozilla.com
push dateMon, 16 Sep 2013 19:14:59 +0000
treeherdermozilla-beta@87d3c51cd2bf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug, dhylands
bugs884061
milestone25.0a1
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
Bug 884061 - Part 3f: Use NS_DECL_THREADSAFE_ISUPPORTS in dom/, r=smaug,dhylands.
dom/base/nsDOMScriptObjectFactory.cpp
dom/base/nsDOMScriptObjectFactory.h
dom/devicestorage/DeviceStorage.h
dom/devicestorage/DeviceStorageRequestParent.cpp
dom/devicestorage/DeviceStorageRequestParent.h
dom/devicestorage/nsDeviceStorage.cpp
dom/file/ArchiveEvent.cpp
dom/file/ArchiveEvent.h
dom/file/ArchiveZipFile.cpp
dom/file/AsyncHelper.cpp
dom/file/AsyncHelper.h
dom/file/FileHelper.cpp
dom/file/FileHelper.h
dom/file/FileService.cpp
dom/file/FileService.h
dom/file/FileStreamWrappers.cpp
dom/file/FileStreamWrappers.h
dom/file/LockedFile.cpp
dom/file/LockedFile.h
dom/file/MemoryStreams.cpp
dom/file/MemoryStreams.h
dom/indexedDB/AsyncConnectionHelper.cpp
dom/indexedDB/AsyncConnectionHelper.h
dom/indexedDB/CheckPermissionsHelper.cpp
dom/indexedDB/CheckPermissionsHelper.h
dom/indexedDB/FileInfo.cpp
dom/indexedDB/FileInfo.h
dom/indexedDB/IDBTransaction.cpp
dom/indexedDB/IDBTransaction.h
dom/indexedDB/IndexedDatabaseManager.cpp
dom/indexedDB/OpenDatabaseHelper.cpp
dom/indexedDB/OpenDatabaseHelper.h
dom/indexedDB/TransactionThreadPool.cpp
dom/indexedDB/TransactionThreadPool.h
dom/ipc/Blob.cpp
dom/ipc/ContentParent.cpp
dom/ipc/ContentParent.h
dom/media/MediaManager.cpp
dom/media/MediaManager.h
dom/plugins/base/nsNPAPIPluginInstance.cpp
dom/plugins/base/nsNPAPIPluginInstance.h
dom/plugins/base/nsPluginDirServiceProvider.cpp
dom/plugins/base/nsPluginDirServiceProvider.h
dom/quota/CheckQuotaHelper.cpp
dom/quota/CheckQuotaHelper.h
dom/quota/QuotaManager.cpp
dom/quota/QuotaObject.cpp
dom/quota/QuotaObject.h
dom/src/geolocation/nsGeoPosition.cpp
dom/src/geolocation/nsGeoPosition.h
dom/src/geolocation/nsGeolocation.cpp
dom/src/geolocation/nsGeolocation.h
dom/src/jsurl/nsJSProtocolHandler.cpp
dom/src/storage/DOMStorageCache.cpp
dom/src/storage/DOMStorageCache.h
dom/src/storage/DOMStorageIPC.cpp
dom/src/storage/DOMStorageIPC.h
dom/system/gonk/AutoMounterSetting.cpp
dom/system/gonk/GonkGPSGeolocationProvider.cpp
dom/system/gonk/GonkGPSGeolocationProvider.h
dom/system/gonk/nsVolume.cpp
dom/system/gonk/nsVolume.h
dom/system/gonk/nsVolumeService.cpp
dom/system/gonk/nsVolumeService.h
dom/workers/ScriptLoader.cpp
dom/workers/WorkerPrivate.cpp
dom/workers/WorkerPrivate.h
dom/workers/XMLHttpRequest.cpp
--- a/dom/base/nsDOMScriptObjectFactory.cpp
+++ b/dom/base/nsDOMScriptObjectFactory.cpp
@@ -204,17 +204,17 @@ nsresult NS_GetScriptRuntimeByID(uint32_
 
   NS_ENSURE_TRUE(aScriptTypeID == nsIProgrammingLanguage::JAVASCRIPT,
                  NS_ERROR_FAILURE);
 
   return NS_GetJSRuntime(aLanguage);
 }
 
 
-NS_IMPL_THREADSAFE_ISUPPORTS1(nsDOMExceptionProvider, nsIExceptionProvider)
+NS_IMPL_ISUPPORTS1(nsDOMExceptionProvider, nsIExceptionProvider)
 
 NS_IMETHODIMP
 nsDOMExceptionProvider::GetException(nsresult result,
                                      nsIException *aDefaultException,
                                      nsIException **_retval)
 {
   if (!NS_IsMainThread()) {
     return NS_ERROR_NOT_IMPLEMENTED;
--- a/dom/base/nsDOMScriptObjectFactory.h
+++ b/dom/base/nsDOMScriptObjectFactory.h
@@ -46,11 +46,11 @@ public:
                                   uint32_t aScriptableFlags,
                                   bool aHasClassInterface,
                                   const nsCID *aConstructorCID) MOZ_OVERRIDE;
 };
 
 class nsDOMExceptionProvider MOZ_FINAL : public nsIExceptionProvider
 {
 public:
-  NS_DECL_ISUPPORTS
+  NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIEXCEPTIONPROVIDER
 };
--- a/dom/devicestorage/DeviceStorage.h
+++ b/dom/devicestorage/DeviceStorage.h
@@ -60,17 +60,17 @@ public:
 
   void SetPath(const nsAString& aPath);
   void SetEditable(bool aEditable);
 
   static already_AddRefed<DeviceStorageFile> CreateUnique(nsAString& aFileName,
                                                           uint32_t aFileType,
                                                           uint32_t aFileAttributes);
 
-  NS_DECL_ISUPPORTS
+  NS_DECL_THREADSAFE_ISUPPORTS
 
   bool IsAvailable();
   bool IsComposite();
   void GetCompositePath(nsAString& aCompositePath);
 
   // we want to make sure that the names of file can't reach
   // outside of the type of storage the user asked for.
   bool IsSafePath();
--- a/dom/devicestorage/DeviceStorageRequestParent.cpp
+++ b/dom/devicestorage/DeviceStorageRequestParent.cpp
@@ -245,18 +245,18 @@ DeviceStorageRequestParent::EnsureRequir
   return true;
 }
 
 DeviceStorageRequestParent::~DeviceStorageRequestParent()
 {
   MOZ_COUNT_DTOR(DeviceStorageRequestParent);
 }
 
-NS_IMPL_THREADSAFE_ADDREF(DeviceStorageRequestParent)
-NS_IMPL_THREADSAFE_RELEASE(DeviceStorageRequestParent)
+NS_IMPL_ADDREF(DeviceStorageRequestParent)
+NS_IMPL_RELEASE(DeviceStorageRequestParent)
 
 void
 DeviceStorageRequestParent::ActorDestroy(ActorDestroyReason)
 {
   MutexAutoLock lock(mMutex);
   mActorDestoryed = true;
   int32_t count = mRunnables.Length();
   for (int32_t index = 0; index < count; index++) {
--- a/dom/devicestorage/DeviceStorageRequestParent.h
+++ b/dom/devicestorage/DeviceStorageRequestParent.h
@@ -31,17 +31,18 @@ public:
   void Dispatch();
 
   virtual void ActorDestroy(ActorDestroyReason);
 
 protected:
   ~DeviceStorageRequestParent();
 
 private:
-  nsAutoRefCnt mRefCnt;
+  ThreadSafeAutoRefCnt mRefCnt;
+  NS_DECL_OWNINGTHREAD
   DeviceStorageParams mParams;
 
   class CancelableRunnable : public nsRunnable
   {
   public:
     CancelableRunnable(DeviceStorageRequestParent* aParent)
       : mParent(aParent)
     {
--- a/dom/devicestorage/nsDeviceStorage.cpp
+++ b/dom/devicestorage/nsDeviceStorage.cpp
@@ -1295,17 +1295,17 @@ DeviceStorageFile::GetStatusInternal(nsA
   if (volState == nsIVolume::STATE_MOUNTED) {
     aStatus.AssignLiteral("available");
   } else if (volState == nsIVolume::STATE_SHARED || volState == nsIVolume::STATE_SHAREDMNT) {
     aStatus.AssignLiteral("shared");
   }
 #endif
 }
 
-NS_IMPL_THREADSAFE_ISUPPORTS0(DeviceStorageFile)
+NS_IMPL_ISUPPORTS0(DeviceStorageFile)
 
 static void
 RegisterForSDCardChanges(nsIObserver* aObserver)
 {
 #ifdef MOZ_WIDGET_GONK
   nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
   obs->AddObserver(aObserver, NS_VOLUME_STATE_CHANGED, false);
 #endif
--- a/dom/file/ArchiveEvent.cpp
+++ b/dom/file/ArchiveEvent.cpp
@@ -7,17 +7,17 @@
 #include "ArchiveEvent.h"
 
 #include "nsContentUtils.h"
 #include "nsCExternalHandlerService.h"
 #include "nsProxyRelease.h"
 
 USING_FILE_NAMESPACE
 
-NS_IMPL_THREADSAFE_ISUPPORTS0(ArchiveItem)
+NS_IMPL_ISUPPORTS0(ArchiveItem)
 
 ArchiveItem::ArchiveItem()
 {
   MOZ_COUNT_CTOR(ArchiveItem);
 }
 
 ArchiveItem::~ArchiveItem()
 {
--- a/dom/file/ArchiveEvent.h
+++ b/dom/file/ArchiveEvent.h
@@ -19,17 +19,17 @@ BEGIN_FILE_NAMESPACE
 
 /**
  * This class contains all the info needed for a single item
  * It must contain the implementation of the File() method.
  */
 class ArchiveItem : public nsISupports
 {
 public:
-  NS_DECL_ISUPPORTS
+  NS_DECL_THREADSAFE_ISUPPORTS
 
   ArchiveItem();
   virtual ~ArchiveItem();
 
   // Getter/Setter for the type
   nsCString GetType();
   void SetType(const nsCString& aType);
 
--- a/dom/file/ArchiveZipFile.cpp
+++ b/dom/file/ArchiveZipFile.cpp
@@ -44,17 +44,17 @@ public:
   }
 
   virtual ~ArchiveInputStream()
   {
     MOZ_COUNT_DTOR(ArchiveInputStream);
     Close();
   }
 
-  NS_DECL_ISUPPORTS
+  NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIINPUTSTREAM
   NS_DECL_NSISEEKABLESTREAM
 
 private:
   nsresult Init();
 
 private: // data
   ZipCentral mCentral;
@@ -77,19 +77,19 @@ private: // data
     unsigned char input[ZIP_CHUNK];
     uint32_t sizeToBeRead;
     uint32_t cursor;
 
     bool compressed; // a zip file can contain stored or compressed files
   } mData;
 };
 
-NS_IMPL_THREADSAFE_ISUPPORTS2(ArchiveInputStream,
-                              nsIInputStream,
-                              nsISeekableStream)
+NS_IMPL_ISUPPORTS2(ArchiveInputStream,
+                   nsIInputStream,
+                   nsISeekableStream)
 
 nsresult
 ArchiveInputStream::Init()
 {
   nsresult rv;
 
   memset(&mZs, 0, sizeof(z_stream));
   int zerr = inflateInit2(&mZs, -MAX_WBITS);
--- a/dom/file/AsyncHelper.cpp
+++ b/dom/file/AsyncHelper.cpp
@@ -9,17 +9,17 @@
 #include "nsIRequestObserver.h"
 
 #include "nsNetUtil.h"
 
 #include "FileService.h"
 
 USING_FILE_NAMESPACE
 
-NS_IMPL_THREADSAFE_ISUPPORTS2(AsyncHelper, nsIRunnable, nsIRequest)
+NS_IMPL_ISUPPORTS2(AsyncHelper, nsIRunnable, nsIRequest)
 
 nsresult
 AsyncHelper::AsyncWork(nsIRequestObserver* aObserver, nsISupports* aCtxt)
 {
   nsresult rv;
 
   if (aObserver) {
     // build proxy for observer events
--- a/dom/file/AsyncHelper.h
+++ b/dom/file/AsyncHelper.h
@@ -20,17 +20,17 @@ BEGIN_FILE_NAMESPACE
  * Must be subclassed. The subclass must implement DoStreamWork.
  * Async operations that are not supported in necko (truncate, flush, etc.)
  * should use this helper. Call AsyncWork to invoke the operation.
  */
 class AsyncHelper : public nsIRunnable,
                     public nsIRequest
 {
 public:
-  NS_DECL_ISUPPORTS
+  NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIRUNNABLE
   NS_DECL_NSIREQUEST
 
   nsresult
   AsyncWork(nsIRequestObserver* aObserver, nsISupports* aCtxt);
 
 protected:
   AsyncHelper(nsISupports* aStream)
--- a/dom/file/FileHelper.cpp
+++ b/dom/file/FileHelper.cpp
@@ -36,17 +36,17 @@ FileHelper::FileHelper(LockedFile* aLock
 }
 
 FileHelper::~FileHelper()
 {
   NS_ASSERTION(!mFileStorage && !mLockedFile && !mFileRequest && !mListener &&
                !mRequest, "Should have cleared this!");
 }
 
-NS_IMPL_THREADSAFE_ISUPPORTS1(FileHelper, nsIRequestObserver)
+NS_IMPL_ISUPPORTS1(FileHelper, nsIRequestObserver)
 
 nsresult
 FileHelper::Enqueue()
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
 
   FileService* service = FileService::GetOrCreate();
   NS_ENSURE_TRUE(service, NS_ERROR_FAILURE);
--- a/dom/file/FileHelper.h
+++ b/dom/file/FileHelper.h
@@ -40,17 +40,17 @@ public:
  * success event. Call Enqueue to start the file operation.
  */
 class FileHelper : public nsIRequestObserver
 {
   friend class FileRequest;
   friend class FileOutputStreamWrapper;
 
 public:
-  NS_DECL_ISUPPORTS
+  NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIREQUESTOBSERVER
 
   nsresult
   Enqueue();
 
   nsresult
   AsyncRun(FileHelperListener* aListener);
 
--- a/dom/file/FileService.cpp
+++ b/dom/file/FileService.cpp
@@ -338,18 +338,18 @@ FileService::MaybeFireCallback(StoragesC
 }
 
 FileService::LockedFileQueue::LockedFileQueue(LockedFile* aLockedFile)
 : mLockedFile(aLockedFile)
 {
   NS_ASSERTION(aLockedFile, "Null pointer!");
 }
 
-NS_IMPL_THREADSAFE_ADDREF(FileService::LockedFileQueue)
-NS_IMPL_THREADSAFE_RELEASE(FileService::LockedFileQueue)
+NS_IMPL_ADDREF(FileService::LockedFileQueue)
+NS_IMPL_RELEASE(FileService::LockedFileQueue)
 
 nsresult
 FileService::LockedFileQueue::Enqueue(FileHelper* aFileHelper)
 {
   mQueue.AppendElement(aFileHelper);
 
   nsresult rv;
   if (mLockedFile->mRequestMode == LockedFile::PARALLEL) {
--- a/dom/file/FileService.h
+++ b/dom/file/FileService.h
@@ -83,17 +83,17 @@ private:
 
   private:
     inline
     LockedFileQueue(LockedFile* aLockedFile);
 
     nsresult
     ProcessQueue();
 
-    nsAutoRefCnt mRefCnt;
+    ThreadSafeAutoRefCnt mRefCnt;
     NS_DECL_OWNINGTHREAD
     nsRefPtr<LockedFile> mLockedFile;
     nsTArray<nsRefPtr<FileHelper> > mQueue;
     nsRefPtr<FileHelper> mCurrentHelper;
   };
 
   struct DelayedEnqueueInfo
   {
--- a/dom/file/FileStreamWrappers.cpp
+++ b/dom/file/FileStreamWrappers.cpp
@@ -14,17 +14,17 @@
 
 USING_FILE_NAMESPACE
 
 namespace {
 
 class ProgressRunnable MOZ_FINAL : public nsIRunnable
 {
 public:
-  NS_DECL_ISUPPORTS
+  NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIRUNNABLE
 
   ProgressRunnable(FileHelper* aFileHelper,
                    uint64_t aProgress,
                    uint64_t aProgressMax)
   : mFileHelper(aFileHelper),
     mProgress(aProgress),
     mProgressMax(aProgressMax)
@@ -35,31 +35,31 @@ private:
   nsRefPtr<FileHelper> mFileHelper;
   uint64_t mProgress;
   uint64_t mProgressMax;
 };
 
 class CloseRunnable MOZ_FINAL : public nsIRunnable
 {
 public:
-  NS_DECL_ISUPPORTS
+  NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIRUNNABLE
 
   CloseRunnable(FileHelper* aFileHelper)
   : mFileHelper(aFileHelper)
   { }
 
 private:
   nsRefPtr<FileHelper> mFileHelper;
 };
 
 class DestroyRunnable MOZ_FINAL : public nsIRunnable
 {
 public:
-  NS_DECL_ISUPPORTS
+  NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIRUNNABLE
 
   DestroyRunnable(FileHelper* aFileHelper)
   : mFileHelper(aFileHelper)
   { }
 
 private:
   nsRefPtr<FileHelper> mFileHelper;
@@ -96,17 +96,17 @@ FileStreamWrapper::~FileStreamWrapper()
       nsresult rv = NS_DispatchToMainThread(runnable, NS_DISPATCH_NORMAL);
       if (NS_FAILED(rv)) {
         NS_WARNING("Failed to dispatch to the main thread!");
       }
     }
   }
 }
 
-NS_IMPL_THREADSAFE_ISUPPORTS0(FileStreamWrapper)
+NS_IMPL_ISUPPORTS0(FileStreamWrapper)
 
 FileInputStreamWrapper::FileInputStreamWrapper(nsISupports* aFileStream,
                                                FileHelper* aFileHelper,
                                                uint64_t aOffset,
                                                uint64_t aLimit,
                                                uint32_t aFlags)
 : FileStreamWrapper(aFileStream, aFileHelper, aOffset, aLimit, aFlags)
 {
@@ -342,43 +342,43 @@ FileOutputStreamWrapper::WriteSegments(n
 
 NS_IMETHODIMP
 FileOutputStreamWrapper::IsNonBlocking(bool* _retval)
 {
   *_retval = false;
   return NS_OK;
 }
 
-NS_IMPL_THREADSAFE_ISUPPORTS1(ProgressRunnable, nsIRunnable)
+NS_IMPL_ISUPPORTS1(ProgressRunnable, nsIRunnable)
 
 NS_IMETHODIMP
 ProgressRunnable::Run()
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
 
   mFileHelper->OnStreamProgress(mProgress, mProgressMax);
   mFileHelper = nullptr;
 
   return NS_OK;
 }
 
-NS_IMPL_THREADSAFE_ISUPPORTS1(CloseRunnable, nsIRunnable)
+NS_IMPL_ISUPPORTS1(CloseRunnable, nsIRunnable)
 
 NS_IMETHODIMP
 CloseRunnable::Run()
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
 
   mFileHelper->OnStreamClose();
   mFileHelper = nullptr;
 
   return NS_OK;
 }
 
-NS_IMPL_THREADSAFE_ISUPPORTS1(DestroyRunnable, nsIRunnable)
+NS_IMPL_ISUPPORTS1(DestroyRunnable, nsIRunnable)
 
 NS_IMETHODIMP
 DestroyRunnable::Run()
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
 
   mFileHelper->OnStreamDestroy();
   mFileHelper = nullptr;
--- a/dom/file/FileStreamWrappers.h
+++ b/dom/file/FileStreamWrappers.h
@@ -14,17 +14,17 @@
 
 BEGIN_FILE_NAMESPACE
 
 class FileHelper;
 
 class FileStreamWrapper : public nsISupports
 {
 public:
-  NS_DECL_ISUPPORTS
+  NS_DECL_THREADSAFE_ISUPPORTS
 
   FileStreamWrapper(nsISupports* aFileStream,
                     FileHelper* aFileHelper,
                     uint64_t aOffset,
                     uint64_t aLimit,
                     uint32_t aFlags);
 
   virtual ~FileStreamWrapper();
--- a/dom/file/LockedFile.cpp
+++ b/dom/file/LockedFile.cpp
@@ -918,17 +918,17 @@ LockedFile::Finish()
 FinishHelper::FinishHelper(LockedFile* aLockedFile)
 : mLockedFile(aLockedFile),
   mAborted(aLockedFile->mAborted)
 {
   mParallelStreams.SwapElements(aLockedFile->mParallelStreams);
   mStream.swap(aLockedFile->mStream);
 }
 
-NS_IMPL_THREADSAFE_ISUPPORTS1(FinishHelper, nsIRunnable)
+NS_IMPL_ISUPPORTS1(FinishHelper, nsIRunnable)
 
 NS_IMETHODIMP
 FinishHelper::Run()
 {
   if (NS_IsMainThread()) {
     mLockedFile->mReadyState = LockedFile::DONE;
 
     FileService* service = FileService::Get();
--- a/dom/file/LockedFile.h
+++ b/dom/file/LockedFile.h
@@ -121,17 +121,17 @@ private:
   bool mCreating;
 };
 
 class FinishHelper MOZ_FINAL : public nsIRunnable
 {
   friend class LockedFile;
 
 public:
-  NS_DECL_ISUPPORTS
+  NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIRUNNABLE
 
 private:
   FinishHelper(LockedFile* aLockedFile);
   ~FinishHelper()
   { }
 
   nsRefPtr<LockedFile> mLockedFile;
--- a/dom/file/MemoryStreams.cpp
+++ b/dom/file/MemoryStreams.cpp
@@ -22,17 +22,17 @@ MemoryOutputStream::Create(uint64_t aSiz
 
   char* dummy;
   uint32_t length = stream->mData.GetMutableData(&dummy, aSize, fallible_t());
   NS_ENSURE_TRUE(length == aSize, nullptr);
 
   return stream.forget();
 }
 
-NS_IMPL_THREADSAFE_ISUPPORTS1(MemoryOutputStream, nsIOutputStream)
+NS_IMPL_ISUPPORTS1(MemoryOutputStream, nsIOutputStream)
 
 NS_IMETHODIMP
 MemoryOutputStream::Close()
 {
   mData.Truncate(mOffset);
   return NS_OK;
 }
 
--- a/dom/file/MemoryStreams.h
+++ b/dom/file/MemoryStreams.h
@@ -11,17 +11,17 @@
 
 #include "nsIOutputStream.h"
 
 BEGIN_FILE_NAMESPACE
 
 class MemoryOutputStream : public nsIOutputStream
 {
 public:
-  NS_DECL_ISUPPORTS
+  NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIOUTPUTSTREAM
 
   static already_AddRefed<MemoryOutputStream>
   Create(uint64_t aSize);
 
 
   const nsCString&
   Data() const
--- a/dom/indexedDB/AsyncConnectionHelper.cpp
+++ b/dom/indexedDB/AsyncConnectionHelper.cpp
@@ -180,18 +180,18 @@ AsyncConnectionHelper::~AsyncConnectionH
                         static_cast<nsIIDBTransaction*>(transaction));
       }
     }
   }
 
   NS_ASSERTION(!mOldProgressHandler, "Should not have anything here!");
 }
 
-NS_IMPL_THREADSAFE_ISUPPORTS2(AsyncConnectionHelper, nsIRunnable,
-                                                     mozIStorageProgressHandler)
+NS_IMPL_ISUPPORTS2(AsyncConnectionHelper, nsIRunnable,
+                   mozIStorageProgressHandler)
 
 NS_IMETHODIMP
 AsyncConnectionHelper::Run()
 {
   if (NS_IsMainThread()) {
     PROFILER_MAIN_THREAD_LABEL("IndexedDB", "AsyncConnectionHelper::Run");
 
     if (mTransaction &&
--- a/dom/indexedDB/AsyncConnectionHelper.h
+++ b/dom/indexedDB/AsyncConnectionHelper.h
@@ -85,17 +85,17 @@ protected:
 class AsyncConnectionHelper : public HelperBase,
                               public mozIStorageProgressHandler
 {
   friend class AutoSetCurrentTransaction;
 
 public:
   typedef ipc::ResponseValue ResponseValue;
 
-  NS_DECL_ISUPPORTS
+  NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIRUNNABLE
   NS_DECL_MOZISTORAGEPROGRESSHANDLER
 
   virtual nsresult Dispatch(nsIEventTarget* aDatabaseThread);
 
   // Only for transactions!
   nsresult DispatchToTransactionPool();
 
--- a/dom/indexedDB/CheckPermissionsHelper.cpp
+++ b/dom/indexedDB/CheckPermissionsHelper.cpp
@@ -86,19 +86,19 @@ GetIndexedDBPermissions(nsIDOMWindow* aW
                                                    &permission);
   NS_ENSURE_SUCCESS(rv, PERMISSION_DENIED);
 
   return permission;
 }
 
 } // anonymous namespace
 
-NS_IMPL_THREADSAFE_ISUPPORTS3(CheckPermissionsHelper, nsIRunnable,
-                                                      nsIInterfaceRequestor,
-                                                      nsIObserver)
+NS_IMPL_ISUPPORTS3(CheckPermissionsHelper, nsIRunnable,
+                   nsIInterfaceRequestor,
+                   nsIObserver)
 
 NS_IMETHODIMP
 CheckPermissionsHelper::Run()
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
 
   uint32_t permission = mHasPrompted ?
                         mPromptResult :
--- a/dom/indexedDB/CheckPermissionsHelper.h
+++ b/dom/indexedDB/CheckPermissionsHelper.h
@@ -19,17 +19,17 @@ class nsIThread;
 
 BEGIN_INDEXEDDB_NAMESPACE
 
 class CheckPermissionsHelper MOZ_FINAL : public nsIRunnable,
                                          public nsIInterfaceRequestor,
                                          public nsIObserver
 {
 public:
-  NS_DECL_ISUPPORTS
+  NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIRUNNABLE
   NS_DECL_NSIINTERFACEREQUESTOR
   NS_DECL_NSIOBSERVER
 
   CheckPermissionsHelper(OpenDatabaseHelper* aHelper,
                          nsIDOMWindow* aWindow,
                          bool aForDeletion)
   : mHelper(aHelper),
--- a/dom/indexedDB/FileInfo.cpp
+++ b/dom/indexedDB/FileInfo.cpp
@@ -60,18 +60,18 @@ FileInfo::GetReferences(int32_t* aRefCnt
   }
 
   if (aSliceRefCnt) {
     *aSliceRefCnt = mSliceRefCnt;
   }
 }
 
 void
-FileInfo::UpdateReferences(nsAutoRefCnt& aRefCount, int32_t aDelta,
-                           bool aClear)
+FileInfo::UpdateReferences(mozilla::ThreadSafeAutoRefCnt& aRefCount,
+                           int32_t aDelta, bool aClear)
 {
   if (IndexedDatabaseManager::IsClosed()) {
     NS_ERROR("Shouldn't be called after shutdown!");
     return;
   }
 
   bool needsCleanup;
   {
--- a/dom/indexedDB/FileInfo.h
+++ b/dom/indexedDB/FileInfo.h
@@ -30,27 +30,27 @@ public:
   { }
 
   static
   FileInfo* Create(FileManager* aFileManager, int64_t aId);
 
   void AddRef()
   {
     if (IndexedDatabaseManager::IsClosed()) {
-      NS_AtomicIncrementRefcnt(mRefCnt);
+      ++mRefCnt;
     }
     else {
       UpdateReferences(mRefCnt, 1);
     }
   }
 
   void Release()
   {
     if (IndexedDatabaseManager::IsClosed()) {
-      nsrefcnt count = NS_AtomicDecrementRefcnt(mRefCnt);
+      nsrefcnt count = --mRefCnt;
       if (count == 0) {
         mRefCnt = 1;
         delete this;
       }
     }
     else {
       UpdateReferences(mRefCnt, -1);
     }
@@ -77,23 +77,23 @@ public:
   FileManager* Manager() const
   {
     return mFileManager;
   }
 
   virtual int64_t Id() const = 0;
 
 private:
-  void UpdateReferences(nsAutoRefCnt& aRefCount, int32_t aDelta,
+  void UpdateReferences(ThreadSafeAutoRefCnt& aRefCount, int32_t aDelta,
                         bool aClear = false);
   void Cleanup();
 
-  nsAutoRefCnt mRefCnt;
-  nsAutoRefCnt mDBRefCnt;
-  nsAutoRefCnt mSliceRefCnt;
+  ThreadSafeAutoRefCnt mRefCnt;
+  ThreadSafeAutoRefCnt mDBRefCnt;
+  ThreadSafeAutoRefCnt mSliceRefCnt;
 
   nsRefPtr<FileManager> mFileManager;
 };
 
 #define FILEINFO_SUBCLASS(_bits)                                              \
 class FileInfo##_bits : public FileInfo                                       \
 {                                                                             \
 public:                                                                       \
--- a/dom/indexedDB/IDBTransaction.cpp
+++ b/dom/indexedDB/IDBTransaction.cpp
@@ -815,17 +815,17 @@ CommitHelper::CommitHelper(IDBTransactio
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
 }
 
 CommitHelper::~CommitHelper()
 {
 }
 
-NS_IMPL_THREADSAFE_ISUPPORTS1(CommitHelper, nsIRunnable)
+NS_IMPL_ISUPPORTS1(CommitHelper, nsIRunnable)
 
 NS_IMETHODIMP
 CommitHelper::Run()
 {
   if (NS_IsMainThread()) {
     PROFILER_MAIN_THREAD_LABEL("IndexedDB", "CommitHelper::Run");
 
     NS_ASSERTION(mDoomedObjects.IsEmpty(), "Didn't release doomed objects!");
@@ -1016,17 +1016,17 @@ CommitHelper::RevertAutoIncrementCounts(
 nsresult
 UpdateRefcountFunction::Init()
 {
   mFileInfoEntries.Init();
 
   return NS_OK;
 }
 
-NS_IMPL_THREADSAFE_ISUPPORTS1(UpdateRefcountFunction, mozIStorageFunction)
+NS_IMPL_ISUPPORTS1(UpdateRefcountFunction, mozIStorageFunction)
 
 NS_IMETHODIMP
 UpdateRefcountFunction::OnFunctionCall(mozIStorageValueArray* aValues,
                                        nsIVariant** _retval)
 {
   *_retval = nullptr;
 
   uint32_t numEntries;
--- a/dom/indexedDB/IDBTransaction.h
+++ b/dom/indexedDB/IDBTransaction.h
@@ -276,17 +276,17 @@ private:
 #ifdef DEBUG
   bool mFiredCompleteOrAbort;
 #endif
 };
 
 class CommitHelper MOZ_FINAL : public nsIRunnable
 {
 public:
-  NS_DECL_ISUPPORTS
+  NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIRUNNABLE
 
   CommitHelper(IDBTransaction* aTransaction,
                IDBTransactionListener* aListener,
                const nsTArray<nsRefPtr<IDBObjectStore> >& mUpdatedObjectStores);
   CommitHelper(IDBTransaction* aTransaction,
                nsresult aAbortCode);
   ~CommitHelper();
@@ -322,17 +322,17 @@ private:
   nsAutoTArray<nsRefPtr<IDBObjectStore>, 10> mAutoIncrementObjectStores;
 
   nsresult mAbortCode;
 };
 
 class UpdateRefcountFunction MOZ_FINAL : public mozIStorageFunction
 {
 public:
-  NS_DECL_ISUPPORTS
+  NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_MOZISTORAGEFUNCTION
 
   UpdateRefcountFunction(FileManager* aFileManager)
   : mFileManager(aFileManager)
   { }
 
   ~UpdateRefcountFunction()
   { }
--- a/dom/indexedDB/IndexedDatabaseManager.cpp
+++ b/dom/indexedDB/IndexedDatabaseManager.cpp
@@ -46,30 +46,30 @@ namespace {
 mozilla::StaticRefPtr<IndexedDatabaseManager> gInstance;
 
 int32_t gInitialized = 0;
 int32_t gClosed = 0;
 
 class AsyncDeleteFileRunnable MOZ_FINAL : public nsIRunnable
 {
 public:
-  NS_DECL_ISUPPORTS
+  NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIRUNNABLE
 
   AsyncDeleteFileRunnable(FileManager* aFileManager, int64_t aFileId);
 
 private:
   nsRefPtr<FileManager> mFileManager;
   int64_t mFileId;
 };
 
 class GetFileReferencesHelper MOZ_FINAL : public nsIRunnable
 {
 public:
-  NS_DECL_ISUPPORTS
+  NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIRUNNABLE
 
   GetFileReferencesHelper(const nsACString& aOrigin,
                           const nsAString& aDatabaseName,
                           int64_t aFileId)
   : mOrigin(aOrigin), mDatabaseName(aDatabaseName), mFileId(aFileId),
     mMutex(IndexedDatabaseManager::FileMutex()),
     mCondVar(mMutex, "GetFileReferencesHelper::mCondVar"),
@@ -606,18 +606,18 @@ IndexedDatabaseManager::Observe(nsISuppo
  }
 
 AsyncDeleteFileRunnable::AsyncDeleteFileRunnable(FileManager* aFileManager,
                                                  int64_t aFileId)
 : mFileManager(aFileManager), mFileId(aFileId)
 {
 }
 
-NS_IMPL_THREADSAFE_ISUPPORTS1(AsyncDeleteFileRunnable,
-                              nsIRunnable)
+NS_IMPL_ISUPPORTS1(AsyncDeleteFileRunnable,
+                   nsIRunnable)
 
 NS_IMETHODIMP
 AsyncDeleteFileRunnable::Run()
 {
   AssertIsOnIOThread();
 
   nsCOMPtr<nsIFile> directory = mFileManager->GetDirectory();
   NS_ENSURE_TRUE(directory, NS_ERROR_FAILURE);
@@ -678,18 +678,18 @@ GetFileReferencesHelper::DispatchAndRetu
   *aMemRefCnt = mMemRefCnt;
   *aDBRefCnt = mDBRefCnt;
   *aSliceRefCnt = mSliceRefCnt;
   *aResult = mResult;
 
   return NS_OK;
 }
 
-NS_IMPL_THREADSAFE_ISUPPORTS1(GetFileReferencesHelper,
-                              nsIRunnable)
+NS_IMPL_ISUPPORTS1(GetFileReferencesHelper,
+                   nsIRunnable)
 
 NS_IMETHODIMP
 GetFileReferencesHelper::Run()
 {
   AssertIsOnIOThread();
 
   IndexedDatabaseManager* mgr = IndexedDatabaseManager::Get();
   NS_ASSERTION(mgr, "This should never fail!");
--- a/dom/indexedDB/OpenDatabaseHelper.cpp
+++ b/dom/indexedDB/OpenDatabaseHelper.cpp
@@ -1675,17 +1675,17 @@ private:
   nsRefPtr<IDBOpenDBRequest> mRequest;
   nsTArray<nsCOMPtr<nsIOfflineStorage> > mWaitingDatabases;
   int64_t mOldVersion;
   int64_t mNewVersion;
 };
 
 } // anonymous namespace
 
-NS_IMPL_THREADSAFE_ISUPPORTS1(OpenDatabaseHelper, nsIRunnable)
+NS_IMPL_ISUPPORTS1(OpenDatabaseHelper, nsIRunnable)
 
 nsresult
 OpenDatabaseHelper::Init()
 {
   mDatabaseId = QuotaManager::GetStorageId(mASCIIOrigin, mName);
   NS_ENSURE_TRUE(mDatabaseId, NS_ERROR_FAILURE);
 
   return NS_OK;
--- a/dom/indexedDB/OpenDatabaseHelper.h
+++ b/dom/indexedDB/OpenDatabaseHelper.h
@@ -48,17 +48,17 @@ public:
       mLastIndexId(0), mState(eCreated), mResultCode(NS_OK),
       mLoadDBMetadata(false),
       mTrackingQuota(aPrivilege != mozilla::dom::quota::Chrome)
   {
     NS_ASSERTION(!aForDeletion || !aRequestedVersion,
                  "Can't be for deletion and request a version!");
   }
 
-  NS_DECL_ISUPPORTS
+  NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIRUNNABLE
 
   nsresult Init();
 
   nsresult Dispatch(nsIEventTarget* aDatabaseThread);
   nsresult RunImmediately();
 
   void SetError(nsresult rv)
--- a/dom/indexedDB/TransactionThreadPool.cpp
+++ b/dom/indexedDB/TransactionThreadPool.cpp
@@ -29,34 +29,34 @@ const uint32_t kIdleThreadTimeoutMs = 30
 TransactionThreadPool* gInstance = nullptr;
 bool gShutdown = false;
 
 #ifdef MOZ_ENABLE_PROFILER_SPS
 
 class TransactionThreadPoolListener : public nsIThreadPoolListener
 {
 public:
-  NS_DECL_ISUPPORTS
+  NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSITHREADPOOLLISTENER
 
 private:
   virtual ~TransactionThreadPoolListener()
   { }
 };
 
 #endif // MOZ_ENABLE_PROFILER_SPS
 
 } // anonymous namespace
 
 BEGIN_INDEXEDDB_NAMESPACE
 
 class FinishTransactionRunnable MOZ_FINAL : public nsIRunnable
 {
 public:
-  NS_DECL_ISUPPORTS
+  NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIRUNNABLE
 
   inline FinishTransactionRunnable(IDBTransaction* aTransaction,
                                    nsCOMPtr<nsIRunnable>& aFinishRunnable);
 
 private:
   IDBTransaction* mTransaction;
   nsCOMPtr<nsIRunnable> mFinishRunnable;
@@ -561,18 +561,17 @@ TransactionThreadPool::TransactionQueue:
   NS_ASSERTION(!mShouldFinish, "Finish called more than once!");
 
   mShouldFinish = true;
   mFinishRunnable = aFinishRunnable;
 
   mMonitor.Notify();
 }
 
-NS_IMPL_THREADSAFE_ISUPPORTS1(TransactionThreadPool::TransactionQueue,
-                              nsIRunnable)
+NS_IMPL_ISUPPORTS1(TransactionThreadPool::TransactionQueue, nsIRunnable)
 
 NS_IMETHODIMP
 TransactionThreadPool::TransactionQueue::Run()
 {
   NS_ASSERTION(!NS_IsMainThread(), "Wrong thread!");
   NS_ASSERTION(IndexedDatabaseManager::IsMainProcess(), "Wrong process!");
 
   PROFILER_LABEL("IndexedDB", "TransactionQueue::Run");
@@ -634,17 +633,17 @@ FinishTransactionRunnable::FinishTransac
                                          nsCOMPtr<nsIRunnable>& aFinishRunnable)
 : mTransaction(aTransaction)
 {
   NS_ASSERTION(!NS_IsMainThread(), "Wrong thread!");
   NS_ASSERTION(aTransaction, "Null pointer!");
   mFinishRunnable.swap(aFinishRunnable);
 }
 
-NS_IMPL_THREADSAFE_ISUPPORTS1(FinishTransactionRunnable, nsIRunnable)
+NS_IMPL_ISUPPORTS1(FinishTransactionRunnable, nsIRunnable)
 
 NS_IMETHODIMP
 FinishTransactionRunnable::Run()
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
 
   PROFILER_MAIN_THREAD_LABEL("IndexedDB", "FinishTransactionRunnable::Run");
 
@@ -660,18 +659,17 @@ FinishTransactionRunnable::Run()
     mFinishRunnable = nullptr;
   }
 
   return NS_OK;
 }
 
 #ifdef MOZ_ENABLE_PROFILER_SPS
 
-NS_IMPL_THREADSAFE_ISUPPORTS1(TransactionThreadPoolListener,
-                              nsIThreadPoolListener)
+NS_IMPL_ISUPPORTS1(TransactionThreadPoolListener, nsIThreadPoolListener)
 
 NS_IMETHODIMP
 TransactionThreadPoolListener::OnThreadCreated()
 {
   MOZ_ASSERT(!NS_IsMainThread());
   char aLocal;
   profiler_register_thread("IndexedDB Transaction", &aLocal);
   return NS_OK;
--- a/dom/indexedDB/TransactionThreadPool.h
+++ b/dom/indexedDB/TransactionThreadPool.h
@@ -54,17 +54,17 @@ public:
 
   // Returns true if there are running or pending transactions for aDatabase.
   bool HasTransactionsForDatabase(IDBDatabase* aDatabase);
 
 protected:
   class TransactionQueue MOZ_FINAL : public nsIRunnable
   {
   public:
-    NS_DECL_ISUPPORTS
+    NS_DECL_THREADSAFE_ISUPPORTS
     NS_DECL_NSIRUNNABLE
 
     TransactionQueue(IDBTransaction* aTransaction);
 
     void Unblock();
 
     void Dispatch(nsIRunnable* aRunnable);
 
--- a/dom/ipc/Blob.cpp
+++ b/dom/ipc/Blob.cpp
@@ -55,17 +55,17 @@ class RemoteInputStream : public nsIInpu
 {
   mozilla::Monitor mMonitor;
   nsCOMPtr<nsIDOMBlob> mSourceBlob;
   nsCOMPtr<nsIInputStream> mStream;
   nsCOMPtr<nsISeekableStream> mSeekableStream;
   ActorFlavorEnum mOrigin;
 
 public:
-  NS_DECL_ISUPPORTS
+  NS_DECL_THREADSAFE_ISUPPORTS
 
   RemoteInputStream(nsIDOMBlob* aSourceBlob, ActorFlavorEnum aOrigin)
   : mMonitor("RemoteInputStream.mMonitor"), mSourceBlob(aSourceBlob),
     mOrigin(aOrigin)
   {
     MOZ_ASSERT(NS_IsMainThread());
     MOZ_ASSERT(aSourceBlob);
   }
@@ -307,18 +307,18 @@ private:
     else {
       ReallyBlockAndWaitForStream();
     }
 
     return !!mSeekableStream;
   }
 };
 
-NS_IMPL_THREADSAFE_ADDREF(RemoteInputStream)
-NS_IMPL_THREADSAFE_RELEASE(RemoteInputStream)
+NS_IMPL_ADDREF(RemoteInputStream)
+NS_IMPL_RELEASE(RemoteInputStream)
 
 NS_INTERFACE_MAP_BEGIN(RemoteInputStream)
   NS_INTERFACE_MAP_ENTRY(nsIInputStream)
   NS_INTERFACE_MAP_ENTRY(nsIIPCSerializableInputStream)
   NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsISeekableStream, IsSeekableStream())
   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIInputStream)
   NS_INTERFACE_MAP_ENTRY(IPrivateRemoteInputStream)
 NS_INTERFACE_MAP_END
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -1567,20 +1567,20 @@ ContentParent::RecvRecordingDeviceEvents
     if (obs) {
         obs->NotifyObservers(nullptr, "recording-device-events", aRecordingStatus.get());
     } else {
         NS_WARNING("Could not get the Observer service for ContentParent::RecvRecordingDeviceEvents.");
     }
     return true;
 }
 
-NS_IMPL_THREADSAFE_ISUPPORTS3(ContentParent,
-                              nsIObserver,
-                              nsIThreadObserver,
-                              nsIDOMGeoPositionCallback)
+NS_IMPL_ISUPPORTS3(ContentParent,
+                   nsIObserver,
+                   nsIThreadObserver,
+                   nsIDOMGeoPositionCallback)
 
 NS_IMETHODIMP
 ContentParent::Observe(nsISupports* aSubject,
                        const char* aTopic,
                        const PRUnichar* aData)
 {
     if (!strcmp(aTopic, "xpcom-shutdown") && mSubprocess) {
         ShutDownProcess(/* closeWithError */ false);
--- a/dom/ipc/ContentParent.h
+++ b/dom/ipc/ContentParent.h
@@ -103,17 +103,17 @@ public:
      */
     static TabParent*
     CreateBrowserOrApp(const TabContext& aContext,
                        nsIDOMElement* aFrameElement);
 
     static void GetAll(nsTArray<ContentParent*>& aArray);
     static void GetAllEvenIfDead(nsTArray<ContentParent*>& aArray);
 
-    NS_DECL_ISUPPORTS
+    NS_DECL_THREADSAFE_ISUPPORTS
     NS_DECL_NSIOBSERVER
     NS_DECL_NSITHREADOBSERVER
     NS_DECL_NSIDOMGEOPOSITIONCALLBACK
 
     /**
      * MessageManagerCallback methods that we override.
      */
     virtual bool DoSendAsyncMessage(JSContext* aCx,
--- a/dom/media/MediaManager.cpp
+++ b/dom/media/MediaManager.cpp
@@ -225,17 +225,17 @@ public:
 protected:
   uint64_t mWindowID;
   nsRefPtr<GetUserMediaCallbackMediaStreamListener> mListener;
 };
 
 /**
  * nsIMediaDevice implementation.
  */
-NS_IMPL_THREADSAFE_ISUPPORTS1(MediaDevice, nsIMediaDevice)
+NS_IMPL_ISUPPORTS1(MediaDevice, nsIMediaDevice)
 
 NS_IMETHODIMP
 MediaDevice::GetName(nsAString& aName)
 {
   aName.Assign(mName);
   return NS_OK;
 }
 
@@ -888,17 +888,17 @@ MediaManager::MediaManager()
   }
   LOG(("%s: default prefs: %dx%d @%dfps (min %d)", __FUNCTION__,
        mPrefs.mWidth, mPrefs.mHeight, mPrefs.mFPS, mPrefs.mMinFPS));
 
   mActiveWindows.Init();
   mActiveCallbacks.Init();
 }
 
-NS_IMPL_THREADSAFE_ISUPPORTS2(MediaManager, nsIMediaManagerService, nsIObserver)
+NS_IMPL_ISUPPORTS2(MediaManager, nsIMediaManagerService, nsIObserver)
 
 /* static */ StaticRefPtr<MediaManager> MediaManager::sSingleton;
 
 // NOTE: never Dispatch(....,NS_DISPATCH_SYNC) to the MediaManager
 // thread from the MainThread, as we NS_DISPATCH_SYNC to MainThread
 // from MediaManager thread.
 /* static */  MediaManager*
 MediaManager::Get() {
--- a/dom/media/MediaManager.h
+++ b/dom/media/MediaManager.h
@@ -380,17 +380,17 @@ private:
 };
 
 typedef nsTArray<nsRefPtr<GetUserMediaCallbackMediaStreamListener> > StreamListeners;
 typedef nsClassHashtable<nsUint64HashKey, StreamListeners> WindowTable;
 
 class MediaDevice : public nsIMediaDevice
 {
 public:
-  NS_DECL_ISUPPORTS
+  NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIMEDIADEVICE
 
   MediaDevice(MediaEngineVideoSource* aSource) {
     mSource = aSource;
     mType.Assign(NS_LITERAL_STRING("video"));
     mSource->GetName(mName);
     mSource->GetUUID(mID);
   }
@@ -420,17 +420,17 @@ public:
   // thread from the MainThread, as we NS_DISPATCH_SYNC to MainThread
   // from MediaManager thread.
   static MediaManager* Get();
 
   static nsIThread* GetThread() {
     return Get()->mMediaThread;
   }
 
-  NS_DECL_ISUPPORTS
+  NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIOBSERVER
   NS_DECL_NSIMEDIAMANAGERSERVICE
 
   MediaEngine* GetBackend(uint64_t aWindowId = 0);
   StreamListeners *GetWindowListeners(uint64_t aWindowId) {
     NS_ASSERTION(NS_IsMainThread(), "Only access windowlist on main thread");
 
     return mActiveWindows.Get(aWindowId);
--- a/dom/plugins/base/nsNPAPIPluginInstance.cpp
+++ b/dom/plugins/base/nsNPAPIPluginInstance.cpp
@@ -157,17 +157,17 @@ static std::map<NPP, nsNPAPIPluginInstan
 #endif
 
 using namespace mozilla;
 using namespace mozilla::plugins::parent;
 using namespace mozilla::layers;
 
 static NS_DEFINE_IID(kIOutputStreamIID, NS_IOUTPUTSTREAM_IID);
 
-NS_IMPL_THREADSAFE_ISUPPORTS0(nsNPAPIPluginInstance)
+NS_IMPL_ISUPPORTS0(nsNPAPIPluginInstance)
 
 nsNPAPIPluginInstance::nsNPAPIPluginInstance()
   :
     mDrawingModel(kDefaultDrawingModel),
 #ifdef MOZ_WIDGET_ANDROID
     mANPDrawingModel(0),
     mFullScreenOrientation(dom::eScreenOrientation_LandscapePrimary),
     mWakeLocked(false),
--- a/dom/plugins/base/nsNPAPIPluginInstance.h
+++ b/dom/plugins/base/nsNPAPIPluginInstance.h
@@ -76,17 +76,17 @@ public:
 };
 
 class nsNPAPIPluginInstance : public nsISupports
 {
 private:
   typedef mozilla::PluginLibrary PluginLibrary;
 
 public:
-  NS_DECL_ISUPPORTS
+  NS_DECL_THREADSAFE_ISUPPORTS
 
   nsresult Initialize(nsNPAPIPlugin *aPlugin, nsPluginInstanceOwner* aOwner, const char* aMIMEType);
   nsresult Start();
   nsresult Stop();
   nsresult SetWindow(NPWindow* window);
   nsresult NewStreamFromPlugin(const char* type, const char* target, nsIOutputStream* *result);
   nsresult Print(NPPrint* platformPrint);
   nsresult HandleEvent(void* event, int16_t* result,
--- a/dom/plugins/base/nsPluginDirServiceProvider.cpp
+++ b/dom/plugins/base/nsPluginDirServiceProvider.cpp
@@ -172,18 +172,18 @@ nsPluginDirServiceProvider::nsPluginDirS
 nsPluginDirServiceProvider::~nsPluginDirServiceProvider()
 {
 }
 
 //*****************************************************************************
 // nsPluginDirServiceProvider::nsISupports
 //*****************************************************************************
 
-NS_IMPL_THREADSAFE_ISUPPORTS1(nsPluginDirServiceProvider,
-                              nsIDirectoryServiceProvider)
+NS_IMPL_ISUPPORTS1(nsPluginDirServiceProvider,
+                   nsIDirectoryServiceProvider)
 
 //*****************************************************************************
 // nsPluginDirServiceProvider::nsIDirectoryServiceProvider
 //*****************************************************************************
 
 NS_IMETHODIMP
 nsPluginDirServiceProvider::GetFile(const char *charProp, bool *persistant,
                                     nsIFile **_retval)
--- a/dom/plugins/base/nsPluginDirServiceProvider.h
+++ b/dom/plugins/base/nsPluginDirServiceProvider.h
@@ -24,17 +24,17 @@ class nsISimpleEnumerator;
 // class nsPluginDirServiceProvider
 //*****************************************************************************   
 
 class nsPluginDirServiceProvider : public nsIDirectoryServiceProvider
 {
 public:
    nsPluginDirServiceProvider();
    
-   NS_DECL_ISUPPORTS
+   NS_DECL_THREADSAFE_ISUPPORTS
    NS_DECL_NSIDIRECTORYSERVICEPROVIDER
 
 #ifdef XP_WIN
    static nsresult GetPLIDDirectories(nsISimpleEnumerator **aEnumerator);
 private:
    static nsresult GetPLIDDirectoriesWithRootKey(uint32_t aKey,
      nsCOMArray<nsIFile> &aDirs);
 #endif
--- a/dom/quota/CheckQuotaHelper.cpp
+++ b/dom/quota/CheckQuotaHelper.cpp
@@ -132,19 +132,19 @@ CheckQuotaHelper::GetQuotaPermission(nsI
   nsresult rv = pm->TestPermissionFromPrincipal(aPrincipal,
                                                 PERMISSION_INDEXEDDB_UNLIMITED,
                                                 &permission);
   NS_ENSURE_SUCCESS(rv, nsIPermissionManager::DENY_ACTION);
 
   return permission;
 }
 
-NS_IMPL_THREADSAFE_ISUPPORTS3(CheckQuotaHelper, nsIRunnable,
-                                                nsIInterfaceRequestor,
-                                                nsIObserver)
+NS_IMPL_ISUPPORTS3(CheckQuotaHelper, nsIRunnable,
+                   nsIInterfaceRequestor,
+                   nsIObserver)
 
 NS_IMETHODIMP
 CheckQuotaHelper::Run()
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
 
   nsresult rv = NS_OK;
 
--- a/dom/quota/CheckQuotaHelper.h
+++ b/dom/quota/CheckQuotaHelper.h
@@ -21,17 +21,17 @@ class nsPIDOMWindow;
 
 BEGIN_QUOTA_NAMESPACE
 
 class CheckQuotaHelper MOZ_FINAL : public nsIRunnable,
                                    public nsIInterfaceRequestor,
                                    public nsIObserver
 {
 public:
-  NS_DECL_ISUPPORTS
+  NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIRUNNABLE
   NS_DECL_NSIINTERFACEREQUESTOR
   NS_DECL_NSIOBSERVER
 
   CheckQuotaHelper(nsPIDOMWindow* aWindow,
                    mozilla::Mutex& aMutex);
 
   bool PromptAndReturnQuotaIsDisabled();
--- a/dom/quota/QuotaManager.cpp
+++ b/dom/quota/QuotaManager.cpp
@@ -119,17 +119,17 @@ class OriginClearRunnable MOZ_FINAL : pu
     // Running on the IO thread.
     IO,
 
     // Running on the main thread after all work is done.
     Complete
   };
 
 public:
-  NS_DECL_ISUPPORTS
+  NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIRUNNABLE
 
   // AcquireListener override
   virtual nsresult
   OnExclusiveAccessAcquired() MOZ_OVERRIDE;
 
   OriginClearRunnable(const OriginOrPatternString& aOriginOrPattern)
   : mOriginOrPattern(aOriginOrPattern),
@@ -191,17 +191,17 @@ class AsyncUsageRunnable MOZ_FINAL : pub
     // Running on the main thread after all work is done.
     Complete,
 
     // Running on the main thread after skipping the work
     Shortcut
   };
 
 public:
-  NS_DECL_ISUPPORTS
+  NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIRUNNABLE
   NS_DECL_NSIQUOTAREQUEST
 
   AsyncUsageRunnable(uint32_t aAppId,
                      bool aInMozBrowserOnly,
                      const OriginOrPatternString& aOrigin,
                      nsIURI* aURI,
                      nsIUsageCallback* aCallback);
@@ -273,17 +273,17 @@ public:
   {
     NS_ASSERTION(mOp, "Why don't we have a runnable?");
     NS_ASSERTION(mOp->mStorages.IsEmpty(), "We're here too early!");
     NS_ASSERTION(mOp->mListener,
                  "What are we supposed to do when we're done?");
     NS_ASSERTION(mCountdown, "Wrong countdown!");
   }
 
-  NS_DECL_ISUPPORTS
+  NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIRUNNABLE
 
   void
   AddRun()
   {
     mCountdown++;
   }
 
@@ -295,17 +295,17 @@ private:
 
 class WaitForLockedFilesToFinishRunnable MOZ_FINAL : public nsIRunnable
 {
 public:
   WaitForLockedFilesToFinishRunnable()
   : mBusy(true)
   { }
 
-  NS_DECL_ISUPPORTS
+  NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIRUNNABLE
 
   bool
   IsBusy() const
   {
     return mBusy;
   }
 
@@ -1894,17 +1894,17 @@ OriginClearRunnable::DeleteFiles(QuotaMa
     }
   }
 
   aQuotaManager->RemoveQuotaForPattern(mOriginOrPattern);
 
   aQuotaManager->OriginClearCompleted(mOriginOrPattern);
 }
 
-NS_IMPL_THREADSAFE_ISUPPORTS1(OriginClearRunnable, nsIRunnable)
+NS_IMPL_ISUPPORTS1(OriginClearRunnable, nsIRunnable)
 
 NS_IMETHODIMP
 OriginClearRunnable::Run()
 {
   PROFILER_LABEL("Quota", "OriginClearRunnable::Run");
 
   QuotaManager* quotaManager = QuotaManager::Get();
   NS_ASSERTION(quotaManager, "This should never fail!");
@@ -2138,19 +2138,19 @@ AsyncUsageRunnable::RunInternal()
       NS_ERROR("Unknown state value!");
       return NS_ERROR_UNEXPECTED;
   }
 
   NS_NOTREACHED("Should never get here!");
   return NS_ERROR_UNEXPECTED;
 }
 
-NS_IMPL_THREADSAFE_ISUPPORTS2(AsyncUsageRunnable,
-                              nsIRunnable,
-                              nsIQuotaRequest)
+NS_IMPL_ISUPPORTS2(AsyncUsageRunnable,
+                   nsIRunnable,
+                   nsIQuotaRequest)
 
 NS_IMETHODIMP
 AsyncUsageRunnable::Run()
 {
   PROFILER_LABEL("Quota", "AsyncUsageRunnable::Run");
 
   nsresult rv = RunInternal();
 
@@ -2173,17 +2173,17 @@ AsyncUsageRunnable::Cancel()
   if (PR_ATOMIC_SET(&mCanceled, 1)) {
     NS_WARNING("Canceled more than once?!");
     return NS_ERROR_UNEXPECTED;
   }
 
   return NS_OK;
 }
 
-NS_IMPL_THREADSAFE_ISUPPORTS1(WaitForTransactionsToFinishRunnable, nsIRunnable)
+NS_IMPL_ISUPPORTS1(WaitForTransactionsToFinishRunnable, nsIRunnable)
 
 NS_IMETHODIMP
 WaitForTransactionsToFinishRunnable::Run()
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
   NS_ASSERTION(mOp, "Null op!");
   NS_ASSERTION(mOp->mListener, "Nothing to run!");
   NS_ASSERTION(mCountdown, "Wrong countdown!");
@@ -2201,17 +2201,17 @@ WaitForTransactionsToFinishRunnable::Run
   nsresult rv = listener->OnExclusiveAccessAcquired();
   NS_ENSURE_SUCCESS(rv, rv);
 
   // The listener is responsible for calling
   // QuotaManager::AllowNextSynchronizedOp.
   return NS_OK;
 }
 
-NS_IMPL_THREADSAFE_ISUPPORTS1(WaitForLockedFilesToFinishRunnable, nsIRunnable)
+NS_IMPL_ISUPPORTS1(WaitForLockedFilesToFinishRunnable, nsIRunnable)
 
 NS_IMETHODIMP
 WaitForLockedFilesToFinishRunnable::Run()
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
 
   mBusy = false;
 
--- a/dom/quota/QuotaObject.cpp
+++ b/dom/quota/QuotaObject.cpp
@@ -12,34 +12,34 @@ USING_QUOTA_NAMESPACE
 
 void
 QuotaObject::AddRef()
 {
   QuotaManager* quotaManager = QuotaManager::Get();
   if (!quotaManager) {
     NS_ERROR("Null quota manager, this shouldn't happen, possible leak!");
 
-    NS_AtomicIncrementRefcnt(mRefCnt);
+    ++mRefCnt;
 
     return;
   }
 
   MutexAutoLock lock(quotaManager->mQuotaMutex);
 
   ++mRefCnt;
 }
 
 void
 QuotaObject::Release()
 {
   QuotaManager* quotaManager = QuotaManager::Get();
   if (!quotaManager) {
     NS_ERROR("Null quota manager, this shouldn't happen, possible leak!");
 
-    nsrefcnt count = NS_AtomicDecrementRefcnt(mRefCnt);
+    nsrefcnt count = --mRefCnt;
     if (count == 0) {
       mRefCnt = 1;
       delete this;
     }
 
     return;
   }
 
--- a/dom/quota/QuotaObject.h
+++ b/dom/quota/QuotaObject.h
@@ -37,17 +37,17 @@ public:
 private:
   QuotaObject(OriginInfo* aOriginInfo, const nsAString& aPath, int64_t aSize)
   : mOriginInfo(aOriginInfo), mPath(aPath), mSize(aSize)
   { }
 
   virtual ~QuotaObject()
   { }
 
-  nsAutoRefCnt mRefCnt;
+  mozilla::ThreadSafeAutoRefCnt mRefCnt;
 
   OriginInfo* mOriginInfo;
   nsString mPath;
   int64_t mSize;
 };
 
 class OriginInfo
 {
--- a/dom/src/geolocation/nsGeoPosition.cpp
+++ b/dom/src/geolocation/nsGeoPosition.cpp
@@ -32,18 +32,18 @@ nsGeoPositionCoords::~nsGeoPositionCoord
 {
 }
 
 NS_INTERFACE_MAP_BEGIN(nsGeoPositionCoords)
 NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMGeoPositionCoords)
 NS_INTERFACE_MAP_ENTRY(nsIDOMGeoPositionCoords)
 NS_INTERFACE_MAP_END
 
-NS_IMPL_THREADSAFE_ADDREF(nsGeoPositionCoords)
-NS_IMPL_THREADSAFE_RELEASE(nsGeoPositionCoords)
+NS_IMPL_ADDREF(nsGeoPositionCoords)
+NS_IMPL_RELEASE(nsGeoPositionCoords)
 
 NS_IMETHODIMP
 nsGeoPositionCoords::GetLatitude(double *aLatitude)
 {
   *aLatitude = mLat;
   return NS_OK;
 }
 
@@ -123,18 +123,18 @@ nsGeoPosition::~nsGeoPosition()
 {
 }
 
 NS_INTERFACE_MAP_BEGIN(nsGeoPosition)
 NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMGeoPosition)
 NS_INTERFACE_MAP_ENTRY(nsIDOMGeoPosition)
 NS_INTERFACE_MAP_END
 
-NS_IMPL_THREADSAFE_ADDREF(nsGeoPosition)
-NS_IMPL_THREADSAFE_RELEASE(nsGeoPosition)
+NS_IMPL_ADDREF(nsGeoPosition)
+NS_IMPL_RELEASE(nsGeoPosition)
 
 NS_IMETHODIMP
 nsGeoPosition::GetTimestamp(DOMTimeStamp* aTimestamp)
 {
   *aTimestamp = mTimestamp;
   return NS_OK;
 }
 
--- a/dom/src/geolocation/nsGeoPosition.h
+++ b/dom/src/geolocation/nsGeoPosition.h
@@ -22,17 +22,17 @@ struct JSContext;
 ////////////////////////////////////////////////////
 
 /**
  * Simple object that holds a single point in space.
  */
 class nsGeoPositionCoords MOZ_FINAL : public nsIDOMGeoPositionCoords
 {
 public:
-  NS_DECL_ISUPPORTS
+  NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIDOMGEOPOSITIONCOORDS
   
   nsGeoPositionCoords(double aLat, double aLong,
                       double aAlt, double aHError,
                       double aVError, double aHeading,
                       double aSpeed);
   ~nsGeoPositionCoords();
 private:
@@ -42,17 +42,17 @@ private:
 
 ////////////////////////////////////////////////////
 // nsGeoPosition
 ////////////////////////////////////////////////////
 
 class nsGeoPosition MOZ_FINAL : public nsIDOMGeoPosition
 {
 public:
-  NS_DECL_ISUPPORTS
+  NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIDOMGEOPOSITION
   
   nsGeoPosition(double aLat, double aLong,
                 double aAlt, double aHError,
                 double aVError, double aHeading,
                 double aSpeed, long long aTimestamp);
   
 
--- a/dom/src/geolocation/nsGeolocation.cpp
+++ b/dom/src/geolocation/nsGeolocation.cpp
@@ -606,18 +606,18 @@ bool nsGeolocationRequest::Recv__delete_
 // nsGeolocationService
 ////////////////////////////////////////////////////
 NS_INTERFACE_MAP_BEGIN(nsGeolocationService)
   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIGeolocationUpdate)
   NS_INTERFACE_MAP_ENTRY(nsIGeolocationUpdate)
   NS_INTERFACE_MAP_ENTRY(nsIObserver)
 NS_INTERFACE_MAP_END
 
-NS_IMPL_THREADSAFE_ADDREF(nsGeolocationService)
-NS_IMPL_THREADSAFE_RELEASE(nsGeolocationService)
+NS_IMPL_ADDREF(nsGeolocationService)
+NS_IMPL_RELEASE(nsGeolocationService)
 
 
 static bool sGeoEnabled = true;
 static bool sGeoInitPending = true;
 static bool sGeoIgnoreLocationFilter = false;
 static int32_t sProviderTimeout = 6000; // Time, in milliseconds, to wait for the location provider to spin up.
 
 nsresult nsGeolocationService::Init()
--- a/dom/src/geolocation/nsGeolocation.h
+++ b/dom/src/geolocation/nsGeolocation.h
@@ -103,17 +103,17 @@ class nsGeolocationRequest
  */
 class nsGeolocationService MOZ_FINAL : public nsIGeolocationUpdate, public nsIObserver
 {
 public:
 
   static already_AddRefed<nsGeolocationService> GetGeolocationService();
   static mozilla::StaticRefPtr<nsGeolocationService> sService;
 
-  NS_DECL_ISUPPORTS
+  NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIGEOLOCATIONUPDATE
   NS_DECL_NSIOBSERVER
 
   nsGeolocationService() {
       mHigherAccuracy = false;
   }
 
   nsresult Init();
--- a/dom/src/jsurl/nsJSProtocolHandler.cpp
+++ b/dom/src/jsurl/nsJSProtocolHandler.cpp
@@ -51,17 +51,17 @@ using mozilla::AutoPushJSContext;
 
 static NS_DEFINE_CID(kJSURICID, NS_JSURI_CID);
 
 class nsJSThunk : public nsIInputStream
 {
 public:
     nsJSThunk();
 
-    NS_DECL_ISUPPORTS
+    NS_DECL_THREADSAFE_ISUPPORTS
     NS_FORWARD_SAFE_NSIINPUTSTREAM(mInnerStream)
 
     nsresult Init(nsIURI* uri);
     nsresult EvaluateScript(nsIChannel *aChannel,
                             PopupControlState aPopupState,
                             uint32_t aExecutionPolicy,
                             nsPIDOMWindow *aOriginalInnerWindow);
 
@@ -71,17 +71,17 @@ protected:
     nsCOMPtr<nsIInputStream>    mInnerStream;
     nsCString                   mScript;
     nsCString                   mURL;
 };
 
 //
 // nsISupports implementation...
 //
-NS_IMPL_THREADSAFE_ISUPPORTS1(nsJSThunk, nsIInputStream)
+NS_IMPL_ISUPPORTS1(nsJSThunk, nsIInputStream)
 
 
 nsJSThunk::nsJSThunk()
 {
 }
 
 nsJSThunk::~nsJSThunk()
 {
--- a/dom/src/storage/DOMStorageCache.cpp
+++ b/dom/src/storage/DOMStorageCache.cpp
@@ -48,25 +48,25 @@ GetDataSetIndex(const DOMStorage* aStora
 {
   return GetDataSetIndex(aStorage->IsPrivate(), aStorage->IsSessionOnly());
 }
 
 } // anon
 
 // DOMStorageCacheBridge
 
-NS_IMPL_THREADSAFE_ADDREF(DOMStorageCacheBridge)
+NS_IMPL_ADDREF(DOMStorageCacheBridge)
 
 // Since there is no consumer of return value of Release, we can turn this 
 // method to void to make implementation of asynchronous DOMStorageCache::Release
 // much simpler.
 NS_IMETHODIMP_(void) DOMStorageCacheBridge::Release(void)
 {
   MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release");
-  nsrefcnt count = NS_AtomicDecrementRefcnt(mRefCnt);
+  nsrefcnt count = --mRefCnt;
   NS_LOG_RELEASE(this, count, "DOMStorageCacheBridge");
   if (0 == count) {
     mRefCnt = 1; /* stabilize */
     /* enable this to find non-threadsafe destructors: */
     /* NS_ASSERT_OWNINGTHREAD(_class); */
     delete (this);
   }
 }
--- a/dom/src/storage/DOMStorageCache.h
+++ b/dom/src/storage/DOMStorageCache.h
@@ -50,17 +50,18 @@ public:
   // to this cache
   virtual void LoadDone(nsresult aRv) = 0;
 
   // Use to synchronously wait until the cache gets fully loaded with data,
   // this method exits after LoadDone has been called
   virtual void LoadWait() = 0;
 
 protected:
-  nsAutoRefCnt mRefCnt;
+  ThreadSafeAutoRefCnt mRefCnt;
+  NS_DECL_OWNINGTHREAD
 };
 
 // Implementation of scope cache that is responsible for preloading data
 // for persistent storage (localStorage) and hold data for non-private,
 // 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
 {
--- a/dom/src/storage/DOMStorageIPC.cpp
+++ b/dom/src/storage/DOMStorageIPC.cpp
@@ -13,17 +13,17 @@
 
 namespace mozilla {
 namespace dom {
 
 // ----------------------------------------------------------------------------
 // Child
 // ----------------------------------------------------------------------------
 
-NS_IMPL_THREADSAFE_ADDREF(DOMStorageDBChild)
+NS_IMPL_ADDREF(DOMStorageDBChild)
 
 NS_IMETHODIMP_(nsrefcnt) DOMStorageDBChild::Release(void)
 {
   NS_PRECONDITION(0 != mRefCnt, "dup release");
   nsrefcnt count = --mRefCnt;
   NS_LOG_RELEASE(this, count, "DOMStorageDBChild");
   if (count == 1 && mIPCOpen) {
     Send__delete__(this);
@@ -269,18 +269,18 @@ DOMStorageDBChild::RecvError(const nsres
   mStatus = aRv;
   return true;
 }
 
 // ----------------------------------------------------------------------------
 // Parent
 // ----------------------------------------------------------------------------
 
-NS_IMPL_THREADSAFE_ADDREF(DOMStorageDBParent)
-NS_IMPL_THREADSAFE_RELEASE(DOMStorageDBParent)
+NS_IMPL_ADDREF(DOMStorageDBParent)
+NS_IMPL_RELEASE(DOMStorageDBParent)
 
 void
 DOMStorageDBParent::AddIPDLReference()
 {
   NS_ABORT_IF_FALSE(!mIPCOpen, "Attempting to retain multiple IPDL references");
   mIPCOpen = true;
   AddRef();
 }
--- a/dom/src/storage/DOMStorageIPC.h
+++ b/dom/src/storage/DOMStorageIPC.h
@@ -71,17 +71,18 @@ private:
                     const nsresult& aRv);
   bool RecvScopesHavingData(const InfallibleTArray<nsCString>& aScopes);
   bool RecvLoadUsage(const nsCString& aScope,
                      const int64_t& aUsage);
   bool RecvError(const nsresult& aRv);
 
   nsTHashtable<nsCStringHashKey>& ScopesHavingData();
 
-  nsAutoRefCnt mRefCnt;
+  ThreadSafeAutoRefCnt mRefCnt;
+  NS_DECL_OWNINGTHREAD
 
   // Held to get caches to forward answers to.
   nsRefPtr<DOMLocalStorageManager> mManager;
 
   // Scopes having data hash, for optimization purposes only
   nsTHashtable<nsCStringHashKey> mScopesHavingData;
 
   // List of caches waiting for preload.  This ensures the contract that
@@ -174,17 +175,18 @@ private:
   bool RecvAsyncFlush();
 
   // DOMStorageObserverSink
   virtual nsresult Observe(const char* aTopic, const nsACString& aScopePrefix);
 
 private:
   CacheParentBridge* NewCache(const nsACString& aScope);
 
-  nsAutoRefCnt mRefCnt;
+  ThreadSafeAutoRefCnt mRefCnt;
+  NS_DECL_OWNINGTHREAD
 	
 	// True when IPC channel is open and Send*() methods are OK to use.
   bool mIPCOpen;
 };
 
 } // ::dom
 } // ::mozilla
 
--- a/dom/system/gonk/AutoMounterSetting.cpp
+++ b/dom/system/gonk/AutoMounterSetting.cpp
@@ -32,17 +32,17 @@
 #define MOZSETTINGS_CHANGED       "mozsettings-changed"
 
 namespace mozilla {
 namespace system {
 
 class SettingsServiceCallback MOZ_FINAL : public nsISettingsServiceCallback
 {
 public:
-  NS_DECL_ISUPPORTS
+  NS_DECL_THREADSAFE_ISUPPORTS
 
   SettingsServiceCallback() {}
 
   NS_IMETHOD Handle(const nsAString& aName, const JS::Value& aResult)
   {
     if (JSVAL_IS_INT(aResult)) {
       int32_t mode = JSVAL_TO_INT(aResult);
       SetAutoMounterMode(mode);
@@ -52,22 +52,22 @@ public:
 
   NS_IMETHOD HandleError(const nsAString& aName)
   {
     ERR("SettingsCallback::HandleError: %s\n", NS_LossyConvertUTF16toASCII(aName).get());
     return NS_OK;
   }
 };
 
-NS_IMPL_THREADSAFE_ISUPPORTS1(SettingsServiceCallback, nsISettingsServiceCallback)
+NS_IMPL_ISUPPORTS1(SettingsServiceCallback, nsISettingsServiceCallback)
 
 class CheckVolumeSettingsCallback MOZ_FINAL : public nsISettingsServiceCallback
 {
 public:
-  NS_DECL_ISUPPORTS
+  NS_DECL_THREADSAFE_ISUPPORTS
 
   CheckVolumeSettingsCallback(const nsACString& aVolumeName)
   : mVolumeName(aVolumeName) {}
 
   NS_IMETHOD Handle(const nsAString& aName, const JS::Value& aResult)
   {
     if (JSVAL_IS_BOOLEAN(aResult)) {
       bool isSharingEnabled = JSVAL_TO_BOOLEAN(aResult);
@@ -80,17 +80,17 @@ public:
   {
     ERR("CheckVolumeSettingsCallback::HandleError: %s\n", NS_LossyConvertUTF16toASCII(aName).get());
     return NS_OK;
   }
 private:
   nsCString mVolumeName;
 };
 
-NS_IMPL_THREADSAFE_ISUPPORTS1(CheckVolumeSettingsCallback, nsISettingsServiceCallback)
+NS_IMPL_ISUPPORTS1(CheckVolumeSettingsCallback, nsISettingsServiceCallback)
 
 AutoMounterSetting::AutoMounterSetting()
 {
   // Setup an observer to watch changes to the setting
   nsCOMPtr<nsIObserverService> observerService =
     mozilla::services::GetObserverService();
   if (!observerService) {
     ERR("GetObserverService failed");
--- a/dom/system/gonk/GonkGPSGeolocationProvider.cpp
+++ b/dom/system/gonk/GonkGPSGeolocationProvider.cpp
@@ -39,20 +39,20 @@
 
 using namespace mozilla;
 
 static const int kDefaultPeriod = 1000; // ms
 
 // While most methods of GonkGPSGeolocationProvider should only be
 // called from main thread, we deliberately put the Init and ShutdownGPS
 // methods off main thread to avoid blocking.
-NS_IMPL_THREADSAFE_ISUPPORTS3(GonkGPSGeolocationProvider,
-                              nsIGeolocationProvider,
-                              nsIRILDataCallback,
-                              nsISettingsServiceCallback)
+NS_IMPL_ISUPPORTS3(GonkGPSGeolocationProvider,
+                   nsIGeolocationProvider,
+                   nsIRILDataCallback,
+                   nsISettingsServiceCallback)
 
 /* static */ GonkGPSGeolocationProvider* GonkGPSGeolocationProvider::sSingleton = nullptr;
 GpsCallbacks GonkGPSGeolocationProvider::mCallbacks = {
   sizeof(GpsCallbacks),
   LocationCallback,
   StatusCallback,
   SvStatusCallback,
   NmeaCallback,
--- a/dom/system/gonk/GonkGPSGeolocationProvider.h
+++ b/dom/system/gonk/GonkGPSGeolocationProvider.h
@@ -32,17 +32,17 @@ class nsIThread;
 #define GONK_GPS_GEOLOCATION_PROVIDER_CONTRACTID \
 "@mozilla.org/gonk-gps-geolocation-provider;1"
 
 class GonkGPSGeolocationProvider : public nsIGeolocationProvider
                                  , public nsIRILDataCallback
                                  , public nsISettingsServiceCallback
 {
 public:
-  NS_DECL_ISUPPORTS
+  NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIGEOLOCATIONPROVIDER
   NS_DECL_NSIRILDATACALLBACK
   NS_DECL_NSISETTINGSSERVICECALLBACK
 
   static already_AddRefed<GonkGPSGeolocationProvider> GetSingleton();
 
 private:
 
--- a/dom/system/gonk/nsVolume.cpp
+++ b/dom/system/gonk/nsVolume.cpp
@@ -38,17 +38,17 @@ NS_VolumeStateStr(int32_t aState)
   return "???";
 }
 
 // While nsVolumes can only be used on the main thread, in the
 // UpdateVolumeRunnable constructor (which is called from IOThread) we
 // allocate an nsVolume which is then passed to MainThread. Since we
 // have a situation where we allocate on one thread and free on another
 // we use a thread safe AddRef implementation.
-NS_IMPL_THREADSAFE_ISUPPORTS1(nsVolume, nsIVolume)
+NS_IMPL_ISUPPORTS1(nsVolume, nsIVolume)
 
 nsVolume::nsVolume(const Volume* aVolume)
   : mName(NS_ConvertUTF8toUTF16(aVolume->Name())),
     mMountPoint(NS_ConvertUTF8toUTF16(aVolume->MountPoint())),
     mState(aVolume->State()),
     mMountGeneration(aVolume->MountGeneration()),
     mMountLocked(aVolume->IsMountLocked()),
     mIsFake(false)
--- a/dom/system/gonk/nsVolume.h
+++ b/dom/system/gonk/nsVolume.h
@@ -14,17 +14,17 @@ namespace mozilla {
 namespace system {
 
 class Volume;
 class VolumeMountLock;
 
 class nsVolume : public nsIVolume
 {
 public:
-  NS_DECL_ISUPPORTS
+  NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIVOLUME
 
   // This constructor is used by the UpdateVolumeRunnable constructor
   nsVolume(const Volume* aVolume);
 
   // This constructor is used by ContentChild::RecvFileSystemUpdate
   nsVolume(const nsAString& aName, const nsAString& aMountPoint,
            const int32_t& aState, const int32_t& aMountGeneration)
--- a/dom/system/gonk/nsVolumeService.cpp
+++ b/dom/system/gonk/nsVolumeService.cpp
@@ -34,19 +34,19 @@
 #include <stdlib.h>
 
 using namespace mozilla::dom;
 using namespace mozilla::services;
 
 namespace mozilla {
 namespace system {
 
-NS_IMPL_THREADSAFE_ISUPPORTS2(nsVolumeService,
-                              nsIVolumeService,
-                              nsIDOMMozWakeLockListener)
+NS_IMPL_ISUPPORTS2(nsVolumeService,
+                   nsIVolumeService,
+                   nsIDOMMozWakeLockListener)
 
 StaticRefPtr<nsVolumeService> nsVolumeService::sSingleton;
 
 // static
 already_AddRefed<nsVolumeService>
 nsVolumeService::GetSingleton()
 {
   MOZ_ASSERT(NS_IsMainThread());
--- a/dom/system/gonk/nsVolumeService.h
+++ b/dom/system/gonk/nsVolumeService.h
@@ -25,17 +25,17 @@ class Volume;
 * on the main thread in order to support the nsIVolume and nsIVolumeService
 * classes.
 */
 
 class nsVolumeService MOZ_FINAL : public nsIVolumeService,
                                   public nsIDOMMozWakeLockListener
 {
 public:
-  NS_DECL_ISUPPORTS
+  NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIVOLUMESERVICE
   NS_DECL_NSIDOMMOZWAKELOCKLISTENER
 
   nsVolumeService();
 
   static already_AddRefed<nsVolumeService> GetSingleton();
   //static nsVolumeService* GetSingleton();
   static void Shutdown();
--- a/dom/workers/ScriptLoader.cpp
+++ b/dom/workers/ScriptLoader.cpp
@@ -128,17 +128,17 @@ class ScriptLoaderRunnable : public Work
   WorkerPrivate* mWorkerPrivate;
   uint32_t mSyncQueueKey;
   nsTArray<ScriptLoadInfo> mLoadInfos;
   bool mIsWorkerScript;
   bool mCanceled;
   bool mCanceledMainThread;
 
 public:
-  NS_DECL_ISUPPORTS
+  NS_DECL_THREADSAFE_ISUPPORTS
 
   ScriptLoaderRunnable(WorkerPrivate* aWorkerPrivate,
                        uint32_t aSyncQueueKey,
                        nsTArray<ScriptLoadInfo>& aLoadInfos,
                        bool aIsWorkerScript)
   : mWorkerPrivate(aWorkerPrivate), mSyncQueueKey(aSyncQueueKey),
     mIsWorkerScript(aIsWorkerScript), mCanceled(false),
     mCanceledMainThread(false)
@@ -515,18 +515,17 @@ public:
         new ScriptExecutorRunnable(*this, mSyncQueueKey, firstIndex, lastIndex);
       if (!runnable->Dispatch(nullptr)) {
         NS_ERROR("This should never fail!");
       }
     }
   }
 };
 
-NS_IMPL_THREADSAFE_ISUPPORTS2(ScriptLoaderRunnable, nsIRunnable,
-                                                    nsIStreamLoaderObserver)
+NS_IMPL_ISUPPORTS2(ScriptLoaderRunnable, nsIRunnable, nsIStreamLoaderObserver)
 
 class StopSyncLoopRunnable MOZ_FINAL : public MainThreadSyncRunnable
 {
 public:
   StopSyncLoopRunnable(WorkerPrivate* aWorkerPrivate,
                        uint32_t aSyncQueueKey)
   : MainThreadSyncRunnable(aWorkerPrivate, SkipWhenClearing, aSyncQueueKey,
                            false)
--- a/dom/workers/WorkerPrivate.cpp
+++ b/dom/workers/WorkerPrivate.cpp
@@ -1179,17 +1179,17 @@ class WorkerRunnableEventTarget MOZ_FINA
 protected:
   nsRefPtr<WorkerRunnable> mWorkerRunnable;
 
 public:
   WorkerRunnableEventTarget(WorkerRunnable* aWorkerRunnable)
   : mWorkerRunnable(aWorkerRunnable)
   { }
 
-  NS_DECL_ISUPPORTS
+  NS_DECL_THREADSAFE_ISUPPORTS
 
   NS_IMETHOD
   Dispatch(nsIRunnable* aRunnable, uint32_t aFlags)
   {
     NS_ASSERTION(aFlags == nsIEventTarget::DISPATCH_NORMAL, "Don't call me!");
 
     nsRefPtr<WorkerRunnableEventTarget> kungFuDeathGrip = this;
 
@@ -1208,17 +1208,17 @@ public:
   NS_IMETHOD
   IsOnCurrentThread(bool* aIsOnCurrentThread)
   {
     *aIsOnCurrentThread = false;
     return NS_OK;
   }
 };
 
-NS_IMPL_THREADSAFE_ISUPPORTS1(WorkerRunnableEventTarget, nsIEventTarget)
+NS_IMPL_ISUPPORTS1(WorkerRunnableEventTarget, nsIEventTarget)
 
 class KillCloseEventRunnable : public WorkerRunnable
 {
   nsCOMPtr<nsITimer> mTimer;
 
   class KillScriptRunnable : public WorkerControlRunnable
   {
   public:
@@ -1534,17 +1534,17 @@ WorkerRunnable::WorkerRunnable(WorkerPri
                                ClearingBehavior aClearingBehavior)
 : mWorkerPrivate(aWorkerPrivate), mTarget(aTarget),
   mBusyBehavior(aBusyBehavior), mClearingBehavior(aClearingBehavior)
 {
   NS_ASSERTION(aWorkerPrivate, "Null worker private!");
 }
 #endif
 
-NS_IMPL_THREADSAFE_ISUPPORTS1(WorkerRunnable, nsIRunnable)
+NS_IMPL_ISUPPORTS1(WorkerRunnable, nsIRunnable)
 
 bool
 WorkerRunnable::PreDispatch(JSContext* aCx, WorkerPrivate* aWorkerPrivate)
 {
 #ifdef DEBUG
   if (mBusyBehavior == ModifyBusyCount) {
     NS_ASSERTION(mTarget == WorkerThread,
                  "Don't set this option unless targeting the worker thread!");
@@ -1779,17 +1779,17 @@ class WorkerPrivate::MemoryReporter MOZ_
   friend class WorkerPrivate;
 
   SharedMutex mMutex;
   WorkerPrivate* mWorkerPrivate;
   nsCString mRtPath;
   bool mAlreadyMappedToAddon;
 
 public:
-  NS_DECL_ISUPPORTS
+  NS_DECL_THREADSAFE_ISUPPORTS
 
   MemoryReporter(WorkerPrivate* aWorkerPrivate)
   : mMutex(aWorkerPrivate->mMutex), mWorkerPrivate(aWorkerPrivate),
     mAlreadyMappedToAddon(false)
   {
     aWorkerPrivate->AssertIsOnWorkerThread();
 
     nsCString escapedDomain(aWorkerPrivate->Domain());
@@ -1886,18 +1886,17 @@ private:
 
     static const size_t explicitLength = strlen("explicit/");
     addonId.Insert(NS_LITERAL_CSTRING("add-ons/"), 0);
     addonId += "/";
     mRtPath.Insert(addonId, explicitLength);
   }
 };
 
-NS_IMPL_THREADSAFE_ISUPPORTS1(WorkerPrivate::MemoryReporter,
-                              nsIMemoryMultiReporter)
+NS_IMPL_ISUPPORTS1(WorkerPrivate::MemoryReporter, nsIMemoryMultiReporter)
 
 template <class Derived>
 WorkerPrivateParent<Derived>::WorkerPrivateParent(
                                      JSContext* aCx,
                                      JS::Handle<JSObject*> aObject,
                                      WorkerPrivate* aParent,
                                      JSContext* aParentJSContext,
                                      const nsAString& aScriptURL,
--- a/dom/workers/WorkerPrivate.h
+++ b/dom/workers/WorkerPrivate.h
@@ -60,17 +60,17 @@ public:
 
 protected:
   WorkerPrivate* mWorkerPrivate;
   Target mTarget;
   BusyBehavior mBusyBehavior;
   ClearingBehavior mClearingBehavior;
 
 public:
-  NS_DECL_ISUPPORTS
+  NS_DECL_THREADSAFE_ISUPPORTS
 
   bool
   Dispatch(JSContext* aCx);
 
   static bool
   DispatchToMainThread(nsIRunnable*);
 
   bool
--- a/dom/workers/XMLHttpRequest.cpp
+++ b/dom/workers/XMLHttpRequest.cpp
@@ -120,17 +120,17 @@ public:
   // Only touched on the main thread.
   uint32_t mSyncQueueKey;
   uint32_t mSyncEventResponseSyncQueueKey;
   bool mUploadEventListenersAttached;
   bool mMainThreadSeenLoadStart;
   bool mInOpen;
 
 public:
-  NS_DECL_ISUPPORTS
+  NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIDOMEVENTLISTENER
 
   Proxy(XMLHttpRequest* aXHRPrivate, bool aMozAnon, bool aMozSystem)
   : mWorkerPrivate(nullptr), mXMLHttpRequestPrivate(aXHRPrivate),
     mMozAnon(aMozAnon), mMozSystem(aMozSystem),
     mInnerEventStreamId(0), mInnerChannelId(0), mOutstandingSendCount(0),
     mOuterEventStreamId(0), mOuterChannelId(0), mLastLoaded(0), mLastTotal(0),
     mLastUploadLoaded(0), mLastUploadTotal(0), mIsSyncXHR(false),
@@ -1340,17 +1340,17 @@ Proxy::AddRemoveEventListeners(bool aUpl
 
   if (aUpload) {
     mUploadEventListenersAttached = aAdd;
   }
 
   return true;
 }
 
-NS_IMPL_THREADSAFE_ISUPPORTS1(Proxy, nsIDOMEventListener)
+NS_IMPL_ISUPPORTS1(Proxy, nsIDOMEventListener)
 
 NS_IMETHODIMP
 Proxy::HandleEvent(nsIDOMEvent* aEvent)
 {
   AssertIsOnMainThread();
 
   if (!mWorkerPrivate || !mXMLHttpRequestPrivate) {
     NS_ERROR("Shouldn't get here!");