diff --git a/dom/media/MediaManager.cpp b/dom/media/MediaManager.cpp index b11787fe5bb1..3723f423e9ba 100644 --- a/dom/media/MediaManager.cpp +++ b/dom/media/MediaManager.cpp @@ -463,10 +463,9 @@ class GetUserMediaWindowListener { NS_INLINE_DECL_THREADSAFE_REFCOUNTING(GetUserMediaWindowListener) // Create in an inactive state - GetUserMediaWindowListener(base::Thread* aThread, uint64_t aWindowID, + GetUserMediaWindowListener(uint64_t aWindowID, const PrincipalHandle& aPrincipalHandle) - : mMediaThread(aThread), - mWindowID(aWindowID), + : mWindowID(aWindowID), mPrincipalHandle(aPrincipalHandle), mChromeNotificationTaskPosted(false) {} @@ -698,12 +697,8 @@ class GetUserMediaWindowListener { "Inactive listeners should already be removed"); MOZ_ASSERT(mActiveListeners.Length() == 0, "Active listeners should already be removed"); - Unused << mMediaThread; } - // Set at construction - base::Thread* mMediaThread; - uint64_t mWindowID; const PrincipalHandle mPrincipalHandle; @@ -1638,25 +1633,6 @@ class GetUserMediaTask : public Runnable { RefPtr mManager; // get ref to this when creating the runnable }; -#if defined(ANDROID) -class GetUserMediaRunnableWrapper : public Runnable { - public: - // This object must take ownership of task - explicit GetUserMediaRunnableWrapper(GetUserMediaTask* task) - : Runnable("GetUserMediaRunnableWrapper"), mTask(task) {} - - ~GetUserMediaRunnableWrapper() {} - - NS_IMETHOD Run() override { - mTask->Run(); - return NS_OK; - } - - private: - nsAutoPtr mTask; -}; -#endif - /* static */ void MediaManager::GuessVideoDeviceGroupIDs(MediaDeviceSet& aDevices, const MediaDeviceSet& aAudios) { @@ -1898,7 +1874,8 @@ RefPtr MediaManager::EnumerateRawDevices( return promise; } -MediaManager::MediaManager() : mMediaThread(nullptr), mBackend(nullptr) { +MediaManager::MediaManager(UniquePtr aMediaThread) + : mMediaThread(std::move(aMediaThread)), mBackend(nullptr) { mPrefs.mFreq = 1000; // 1KHz test tone mPrefs.mWidth = 0; // adaptive default mPrefs.mHeight = 0; // adaptive default @@ -1996,20 +1973,24 @@ MediaManager* MediaManager::Get() { timesCreated++; MOZ_RELEASE_ASSERT(timesCreated == 1); - sSingleton = new MediaManager(); - + { + UniquePtr mediaThread = #ifdef XP_WIN - sSingleton->mMediaThread = new MTAThread("MediaManager"); + MakeUnique("MediaManager"); #else - sSingleton->mMediaThread = new base::Thread("MediaManager"); + MakeUnique("MediaManager"); #endif - base::Thread::Options options; - options.message_loop_type = MessageLoop::TYPE_MOZILLA_NONMAINTHREAD; - if (!sSingleton->mMediaThread->StartWithOptions(options)) { - MOZ_CRASH(); - } - LOG("New Media thread for gum"); + base::Thread::Options options; + options.message_loop_type = MessageLoop::TYPE_MOZILLA_NONMAINTHREAD; + if (!mediaThread->StartWithOptions(options)) { + MOZ_CRASH(); + } + + LOG("New Media thread for gum"); + + sSingleton = new MediaManager(std::move(mediaThread)); + } nsCOMPtr obs = services::GetObserverService(); if (obs) { @@ -2585,7 +2566,7 @@ RefPtr MediaManager::GetUserMedia( MOZ_ASSERT(PrincipalHandleMatches(existingPrincipalHandle, principal)); } else { windowListener = new GetUserMediaWindowListener( - mMediaThread, windowID, MakePrincipalHandle(principal)); + windowID, MakePrincipalHandle(principal)); AddWindowID(windowID, windowListener); } @@ -3184,7 +3165,7 @@ RefPtr MediaManager::EnumerateDevices( MOZ_ASSERT(PrincipalHandleMatches(existingPrincipalHandle, principal)); } else { windowListener = new GetUserMediaWindowListener( - mMediaThread, windowId, MakePrincipalHandle(principal)); + windowId, MakePrincipalHandle(principal)); AddWindowID(windowId, windowListener); } @@ -3292,7 +3273,7 @@ RefPtr MediaManager::GetSinkDevice(nsPIDOMWindowInner* aWindow, MOZ_ASSERT(PrincipalHandleMatches(existingPrincipalHandle, principal)); } else { windowListener = new GetUserMediaWindowListener( - mMediaThread, windowId, MakePrincipalHandle(principal)); + windowId, MakePrincipalHandle(principal)); AddWindowID(windowId, windowListener); } // Create an inactive SourceListener to act as a placeholder, so the diff --git a/dom/media/MediaManager.h b/dom/media/MediaManager.h index 3fe0703e28ce..bd152a741acb 100644 --- a/dom/media/MediaManager.h +++ b/dom/media/MediaManager.h @@ -10,7 +10,6 @@ #include "mozilla/media/DeviceChangeCallback.h" #include "mozilla/dom/GetUserMediaRequest.h" #include "mozilla/Unused.h" -#include "nsAutoPtr.h" #include "nsIMediaManager.h" #include "nsHashKeys.h" @@ -318,7 +317,7 @@ class MediaManager final : public nsIMediaManagerService, void GetPrefs(nsIPrefBranch* aBranch, const char* aData); // Make private because we want only one instance of this class - MediaManager(); + explicit MediaManager(UniquePtr aMediaThread); ~MediaManager() {} void Shutdown(); @@ -343,7 +342,7 @@ class MediaManager final : public nsIMediaManagerService, nsTArray> mPendingGUMRequest; // Always exists - nsAutoPtr mMediaThread; + const UniquePtr mMediaThread; nsCOMPtr mShutdownBlocker; // ONLY accessed from MediaManagerThread