Bug 1145403 - Don't open MediaManager on shutdown. r=jesup
authorJan-Ivar Bruaroey <jib@mozilla.com>
Thu, 19 Mar 2015 18:43:25 -0400
changeset 263605 1b66d8f67cf787406b7cced622755b765693713e
parent 263604 f3988f82aefcca4eb63824a7eef19dc092903beb
child 263606 5dcff2ab60e65cfed5a1dd4856444cfedfbf7574
push id4718
push userraliiev@mozilla.com
push dateMon, 11 May 2015 18:39:53 +0000
treeherdermozilla-beta@c20c4ef55f08 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup
bugs1145403
milestone39.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 1145403 - Don't open MediaManager on shutdown. r=jesup
dom/base/Navigator.cpp
dom/media/MediaManager.cpp
dom/media/MediaManager.h
--- a/dom/base/Navigator.cpp
+++ b/dom/base/Navigator.cpp
@@ -1977,18 +1977,18 @@ Navigator::SetWindow(nsPIDOMWindow *aInn
 void
 Navigator::OnNavigation()
 {
   if (!mWindow) {
     return;
   }
 
 #ifdef MOZ_MEDIA_NAVIGATOR
-  // Inform MediaManager in case there are live streams or pending callbacks.
-  MediaManager *manager = MediaManager::Get();
+  // If MediaManager is open let it inform any live streams or pending callbacks
+  MediaManager *manager = MediaManager::GetIfExists();
   if (manager) {
     manager->OnNavigation(mWindow->WindowID());
   }
 #endif
   if (mCameraManager) {
     mCameraManager->OnNavigation(mWindow->WindowID());
   }
 }
--- a/dom/media/MediaManager.cpp
+++ b/dom/media/MediaManager.cpp
@@ -1413,17 +1413,21 @@ NS_IMPL_ISUPPORTS(MediaManager, nsIMedia
 
 // 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() {
   if (!sSingleton) {
     NS_ASSERTION(NS_IsMainThread(), "Only create MediaManager on main thread");
-
+#ifdef DEBUG
+    static int timesCreated = 0;
+    timesCreated++;
+    MOZ_ASSERT(timesCreated == 1);
+#endif
     sSingleton = new MediaManager();
 
     sSingleton->mMediaThread = new base::Thread("MediaManager");
     base::Thread::Options options;
 #if defined(_WIN32)
     options.message_loop_type = MessageLoop::TYPE_MOZILLA_NONMAINUITHREAD;
 #else
     options.message_loop_type = MessageLoop::TYPE_MOZILLA_NONMAINTHREAD;
@@ -1449,16 +1453,21 @@ MediaManager::Get() {
       prefs->AddObserver("media.navigator.video.default_height", sSingleton, false);
       prefs->AddObserver("media.navigator.video.default_fps", sSingleton, false);
       prefs->AddObserver("media.navigator.video.default_minfps", sSingleton, false);
     }
   }
   return sSingleton;
 }
 
+/* static */  MediaManager*
+MediaManager::GetIfExists() {
+  return sSingleton;
+}
+
 /* static */ already_AddRefed<MediaManager>
 MediaManager::GetInstance()
 {
   // so we can have non-refcounted getters
   nsRefPtr<MediaManager> service = MediaManager::Get();
   return service.forget();
 }
 
--- a/dom/media/MediaManager.h
+++ b/dom/media/MediaManager.h
@@ -549,16 +549,17 @@ class MediaManager MOZ_FINAL : public ns
 {
 public:
   static already_AddRefed<MediaManager> GetInstance();
 
   // 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* Get();
+  static MediaManager* GetIfExists();
   static MessageLoop* GetMessageLoop();
 
   static bool Exists()
   {
     return !!sSingleton;
   }
 
   static nsresult NotifyRecordingStatusChange(nsPIDOMWindow* aWindow,